cgit

commit 48c487d72daef7e71683a85f775db8d36ab20341

Author: Lars Hjemli <hjemli@gmail.com>

Add git_log_link() and fix bug in generic repolink function

The generic repolink function compared head with cgit_query_head, which
almost always would be the same pointer. The test now compares with
repo.defbranch, which is the wanted behavour.

Bug discovered while adding cgit_log_link(), so this commit also contain
that change.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>

 cgit.h | 2 ++
 ui-repolist.c | 4 +---
 ui-shared.c | 20 ++++++++++++++++----
 ui-summary.c | 6 +-----
 ui-tree.c | 12 ++++--------


diff --git a/cgit.h b/cgit.h
index 9a19c97d0e70fd25f8ee8e28a5837bf8e374bece..b2f6361d05850ffab5625968cb437c072425eb41 100644
--- a/cgit.h
+++ b/cgit.h
@@ -203,6 +203,8 @@ 			  const char *query);
 
 extern void cgit_tree_link(char *name, char *title, char *class, char *head,
 			   char *rev, char *path);
+extern void cgit_log_link(char *name, char *title, char *class, char *head,
+			  char *rev, char *path);
 
 extern void cgit_print_error(char *msg);
 extern void cgit_print_date(time_t secs, char *format);




diff --git a/ui-repolist.c b/ui-repolist.c
index 8ade91a039773fa5722a9d55658d3f6239035c51..2018dabbeca245192fc022caec4509fcf0ee166a 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -89,9 +89,7 @@ 		html("");
 		html_link_open(cgit_repourl(cgit_repo->url),
 			       "Summary", "button");
 		html("S</a>");
-		html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
-			       "Log", "button");
-		html("L</a>");
+		cgit_log_link("L", "Log", "button", NULL, NULL, NULL);
 		cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
 		html("</td></tr>\n");
 	}




diff --git a/ui-shared.c b/ui-shared.c
index 657e8afef990662badb8d66f10f076f8a64096e9..64ee79c16a87b5feea6b5b9ed3e2a9c96872e762 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -127,7 +127,7 @@ 		if (path)
 			html_attr(path);
 		delim = "&amp;";
 	}
-	if (head && strcmp(head, cgit_query_head)) {
+	if (head && strcmp(head, cgit_repo->defbranch)) {
 		html(delim);
 		html("h=");
 		html_attr(head);
@@ -136,12 +136,12 @@ 	}
 	return fmt("%s", delim);
 }
 
-void cgit_tree_link(char *name, char *title, char *class, char *head,
-		    char *rev, char *path)
+static char *reporevlink(char *page, char *name, char *title, char *class,
+			 char *head, char *rev, char *path)
 {
 	char *delim;
 
-	delim = repolink(title, class, "tree", head, path);
+	delim = repolink(title, class, page, head, path);
 	if (rev && strcmp(rev, cgit_query_head)) {
 		html(delim);
 		html("id=");
@@ -150,6 +150,18 @@ 	}
 	html("'>");
 	html_txt(name);
 	html("</a>");
+}
+
+void cgit_tree_link(char *name, char *title, char *class, char *head,
+		    char *rev, char *path)
+{
+	reporevlink("tree", name, title, class, head, rev, path);
+}
+
+void cgit_log_link(char *name, char *title, char *class, char *head,
+		   char *rev, char *path)
+{
+	reporevlink("log", name, title, class, head, rev, path);
 }
 
 void cgit_print_date(time_t secs, char *format)




diff --git a/ui-summary.c b/ui-summary.c
index 4bda4c2f73f8ed98195e5d0c427c6d85a3a9cb05..29b76e368366469353b311a7a8b2a3cc5cfd333c 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -25,11 +25,7 @@ 	commit->object.parsed = 0;
 	if (commit && !parse_commit(commit)){
 		info = cgit_parse_commit(commit);
 		html("<tr><td>");
-		url = cgit_pageurl(cgit_query_repo, "log",
-				   fmt("h=%s", refname));
-		html_link_open(url, NULL, NULL);
-		html_txt(buf);
-		html_link_close();
+		cgit_log_link(refname, NULL, NULL, refname, NULL, NULL);
 		html("</td><td>");
 		cgit_print_age(commit->date, -1, NULL);
 		html("</td><td>");




diff --git a/ui-tree.c b/ui-tree.c
index d503bee9cc8b316c0ced1ad96f694bc480fa90f7..e16b63828dcf7b29c32da71454276b809174d404 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -92,14 +92,10 @@ 			       curr_rev, fullpath);
 	}
 	htmlf("</td><td class='ls-size'>%li</td>", size);
 
-	html("<td><a href='");
-	qry = fmt("h=%s&amp;path=%s%s%s", curr_rev,
-		  cgit_query_path ? cgit_query_path : "",
-		  cgit_query_path ? "/" : "", pathname);
-	url = cgit_pageurl(cgit_query_repo, "log", qry);
-	html_attr(url);
-	html("' title='Log' class='button'>L</a></td>");
-	html("</tr>\n");
+	html("<td>");
+	cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev,
+		      fullpath);
+	html("</td></tr>\n");
 	free(name);
 	return 0;
 }