cgit

commit 103940fe6b0914dc42b8b033d1d328f38135ca5f

Author: Lars Hjemli <hjemli@gmail.com>

Add ofs argument to cgit_log_link and use it in ui-log.c

This fixes a bug in the prev/next links on the log page: when on the default
branch the links to prev/next page would contain h=(null).

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

 cgit.h | 2 +-
 ui-log.c | 16 +++++++---------
 ui-repolist.c | 2 +-
 ui-shared.c | 22 +++++++++++++++++++---
 ui-summary.c | 2 +-
 ui-tree.c | 2 +-


diff --git a/cgit.h b/cgit.h
index ddb2fffeb493b440d9886ebb6c06b0739389f8ab..a59a3706f35c64a4cd5b412ab93703ba0963f29a 100644
--- a/cgit.h
+++ b/cgit.h
@@ -206,7 +206,7 @@
 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);
+			  char *rev, char *path, int ofs);
 extern void cgit_commit_link(char *name, char *title, char *class, char *head,
 			     char *rev);
 extern void cgit_diff_link(char *name, char *title, char *class, char *head,




diff --git a/ui-log.c b/ui-log.c
index 95cb453c958611521cb54378933ecb6892905d52..d38e40a17423cd507f63f3e4b0bfa5d77fb9c0f8 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -113,17 +113,15 @@
 	if (pager) {
 		html("<div class='pager'>");
 		if (ofs > 0) {
-			html("&nbsp;<a href='");
-			html(cgit_pageurl(cgit_query_repo, cgit_query_page,
-					  fmt("h=%s&amp;ofs=%d", tip, ofs-cnt)));
-			html("'>[prev]</a>&nbsp;");
+			cgit_log_link("[prev]", NULL, NULL, cgit_query_head,
+				      cgit_query_sha1, cgit_query_path,
+				      ofs - cnt);
+			html("&nbsp;");
 		}
-
 		if ((commit = get_revision(&rev)) != NULL) {
-			html("&nbsp;<a href='");
-			html(cgit_pageurl(cgit_query_repo, "log",
-					  fmt("h=%s&amp;ofs=%d", tip, ofs+cnt)));
-			html("'>[next]</a>&nbsp;");
+			cgit_log_link("[next]", NULL, NULL, cgit_query_head,
+				      cgit_query_sha1, cgit_query_path,
+				      ofs + cnt);
 		}
 		html("</div>");
 	}




diff --git a/ui-repolist.c b/ui-repolist.c
index c735368d78108725e9177cb87de691306060cda5..4c86543673855e40adf43a33d32bfcf1297f899e 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -98,7 +98,7 @@ 			html("");
 			html_link_open(cgit_repourl(cgit_repo->url),
 				       NULL, "button");
 			html("summary</a>");
-			cgit_log_link("log", NULL, "button", NULL, NULL, NULL);
+			cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0);
 			cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
 			html("</td>");
 		}




diff --git a/ui-shared.c b/ui-shared.c
index 64c237fe0145230d18b34e8dbb6ecb96d87bf160..bfcc2ac5a880cf5a27ac8d0c227cea562b1956a9 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -163,9 +163,25 @@ 	reporevlink("tree", name, title, class, head, rev, path);
 }
 
 void cgit_log_link(char *name, char *title, char *class, char *head,
-		   char *rev, char *path)
+		   char *rev, char *path, int ofs)
 {
-	reporevlink("log", name, title, class, head, rev, path);
+	char *delim;
+
+	delim = repolink(title, class, "log", head, path);
+	if (rev && strcmp(rev, cgit_query_head)) {
+		html(delim);
+		html("id=");
+		html_attr(rev);
+		delim = "&";
+	}
+	if (ofs > 0) {
+		html(delim);
+		html("ofs=");
+		htmlf("%d", ofs);
+	}
+	html("'>");
+	html_txt(name);
+	html("</a>");
 }
 
 void cgit_commit_link(char *name, char *title, char *class, char *head,
@@ -302,7 +318,7 @@ 		reporevlink(NULL, "summary", NULL, NULL, cgit_query_head,
 			    NULL, NULL);
 		html(" ");
 		cgit_log_link("log", NULL, NULL, cgit_query_head,
-			      cgit_query_sha1, cgit_query_path);
+			      cgit_query_sha1, cgit_query_path, 0);
 		html(" ");
 		cgit_tree_link("tree", NULL, NULL, cgit_query_head,
 			       cgit_query_sha1, NULL);




diff --git a/ui-summary.c b/ui-summary.c
index 03dd078d992e1968be6ff389969f8897589af478..b4bc6d874375da0938e7ac8674e80c9c46a5fb73 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -27,7 +27,7 @@ 	commit->object.parsed = 0;
 	if (commit && !parse_commit(commit)){
 		info = cgit_parse_commit(commit);
 		html("<tr><td>");
-		cgit_log_link(ref, NULL, NULL, ref, NULL, NULL);
+		cgit_log_link(ref, NULL, NULL, ref, NULL, NULL, 0);
 		html("</td><td>");
 		cgit_print_age(commit->date, -1, NULL);
 		html("</td><td>");




diff --git a/ui-tree.c b/ui-tree.c
index b6cb81336a12d7939a260a8231ef5b09b1c96bee..c5d64ffe81246cd6fbf937b8ae1fe9dfd84bfdd9 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -93,7 +93,7 @@ 	htmlf("%li", size);
 
 	html("<td>");
 	cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev,
-		      fullpath);
+		      fullpath, 0);
 	html("</td></tr>\n");
 	free(name);
 	return 0;