cgit

commit 420712ac2531f65a2b94d5ec6d8e03de6942331e

Author: Lars Hjemli <hjemli@gmail.com>

Add simple pager to log page

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

 cgit.c | 2 +-
 cgit.h | 1 +
 shared.c | 9 ++++++---
 ui-log.c | 31 +++++++++++++++++++++++++++++--


diff --git a/cgit.c b/cgit.c
index ada488b66dec98696fe5547287b2957a6d19581f..d7e586d0962d9f7a9c43c89c8ee50bd933c09662 100644
--- a/cgit.c
+++ b/cgit.c
@@ -29,7 +29,7 @@ 	cgit_print_pageheader(title);
 	if (!cgit_query_page) {
 		cgit_print_summary();
 	} else if (!strcmp(cgit_query_page, "log")) {
-		cgit_print_log(cgit_query_head, 0, 100);
+		cgit_print_log(cgit_query_head, cgit_query_ofs, 100);
 	} else if (!strcmp(cgit_query_page, "tree")) {
 		cgit_print_tree(cgit_query_sha1);
 	} else if (!strcmp(cgit_query_page, "view")) {




diff --git a/cgit.h b/cgit.h
index 2fdfab3edf700d3fe8154d44b80c3dbe18394038..82e86811caa859691dd2c0b9b941b10b8c74e888 100644
--- a/cgit.h
+++ b/cgit.h
@@ -44,6 +44,7 @@ extern char *cgit_query_repo;
 extern char *cgit_query_page;
 extern char *cgit_query_head;
 extern char *cgit_query_sha1;
+extern int   cgit_query_ofs;
 
 extern int htmlfd;
 




diff --git a/shared.c b/shared.c
index c58a2ff6ae6f643f7a9d944098374ccaaf55ade1..6b5cfc2af9f2bb4b9e00c2ffb7a6fdf53936a6f9 100644
--- a/shared.c
+++ b/shared.c
@@ -28,6 +28,7 @@ char *cgit_query_repo   = NULL;
 char *cgit_query_page   = NULL;
 char *cgit_query_head   = NULL;
 char *cgit_query_sha1   = NULL;
+int   cgit_query_ofs    = 0;
 
 int htmlfd = 0;
 
@@ -59,16 +60,18 @@ }
 
 void cgit_querystring_cb(const char *name, const char *value)
 {
-	if (!strcmp(name,"r"))
+	if (!strcmp(name,"r")) {
 		cgit_query_repo = xstrdup(value);
-	else if (!strcmp(name, "p"))
+	} else if (!strcmp(name, "p")) {
 		cgit_query_page = xstrdup(value);
-	else if (!strcmp(name, "h")) {
+	} else if (!strcmp(name, "h")) {
 		cgit_query_head = xstrdup(value);
 		cgit_query_has_symref = 1;
 	} else if (!strcmp(name, "id")) {
 		cgit_query_sha1 = xstrdup(value);
 		cgit_query_has_sha1 = 1;
+	} else if (!strcmp(name, "ofs")) {
+		cgit_query_ofs = atoi(value);
 	}
 }
 




diff --git a/ui-log.c b/ui-log.c
index 4d2c2e0dcbc499b0c9db15f41ea3f41aba5ded31..dce50f70ce8e5de1bc860946a338a08b1a783674 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -95,7 +95,7 @@ {
 	struct rev_info rev;
 	struct commit *commit;
 	const char *argv[2] = {NULL, tip};
-	int n = 0;
+	int i;
 	
 	init_revisions(&rev, NULL);
 	rev.abbrev = DEFAULT_ABBREV;
@@ -108,7 +108,18 @@
 	html("<h2>Log</h2>");
 	html("<table class='list'>");
 	html("<tr><th>Date</th><th>Message</th><th>Author</th><th>Link</th></tr>\n");
-	while ((commit = get_revision(&rev)) != NULL && n++ < 100) {
+
+	if (ofs<0)
+		ofs = 0;
+
+	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
+		free(commit->buffer);
+		commit->buffer = NULL;
+		free_commit_list(commit->parents);
+		commit->parents = NULL;
+	}
+
+	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
 		cgit_print_commit_shortlog(commit);
 		free(commit->buffer);
 		commit->buffer = NULL;
@@ -116,5 +127,21 @@ 		free_commit_list(commit->parents);
 		commit->parents = NULL;
 	}
 	html("</table>\n");
+
+	html("<div class='pager'>");
+	if (ofs > 0) {
+		html("&nbsp;<a href='");
+		html(cgit_pageurl(cgit_query_repo, cgit_query_page,
+				  fmt("h=%s&ofs=%d", tip, ofs-cnt)));
+		html("'>[prev]</a>&nbsp;");
+       	}
+
+	if ((commit = get_revision(&rev)) != NULL) {
+		html("&nbsp;<a href='");
+		html(cgit_pageurl(cgit_query_repo, "log",
+				  fmt("h=%s&ofs=%d", tip, ofs+cnt)));
+		html("'>[next]</a>&nbsp;");
+	}
+	html("</div>");
 }