[PATCH 10/17] diff: move layout to page function

John Keeping john at keeping.me.uk
Sun Apr 5 17:54:56 CEST 2015


The existing "show_ctrls" flag is used to control whether we are running
in an existing page or control the page ourselves.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cmd.c     |  2 +-
 ui-diff.c | 19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/cmd.c b/cmd.c
index 73c5e40..f26ae0b 100644
--- a/cmd.c
+++ b/cmd.c
@@ -147,7 +147,7 @@ struct cgit_cmd *cgit_get_cmd(void)
 		def_cmd(about, 0, 0, 0, 0),
 		def_cmd(blob, 1, 0, 0, 0),
 		def_cmd(commit, 1, 0, 1, 0),
-		def_cmd(diff, 1, 1, 1, 0),
+		def_cmd(diff, 1, 0, 1, 0),
 		def_cmd(info, 1, 0, 0, 1),
 		def_cmd(log, 1, 1, 1, 0),
 		def_cmd(ls_cache, 0, 0, 0, 0),
diff --git a/ui-diff.c b/ui-diff.c
index 1cf2ce0..5066429 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -368,19 +368,22 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
 	if (!new_rev)
 		new_rev = ctx.qry.head;
 	if (get_sha1(new_rev, new_rev_sha1)) {
-		cgit_print_error("Bad object name: %s", new_rev);
+		cgit_print_error_page(404, "Not found",
+			"Bad object name: %s", new_rev);
 		return;
 	}
 	commit = lookup_commit_reference(new_rev_sha1);
 	if (!commit || parse_commit(commit)) {
-		cgit_print_error("Bad commit: %s", sha1_to_hex(new_rev_sha1));
+		cgit_print_error_page(404, "Not found",
+			"Bad commit: %s", sha1_to_hex(new_rev_sha1));
 		return;
 	}
 	new_tree_sha1 = commit->tree->object.sha1;
 
 	if (old_rev) {
 		if (get_sha1(old_rev, old_rev_sha1)) {
-			cgit_print_error("Bad object name: %s", old_rev);
+			cgit_print_error_page(404, "Not found",
+				"Bad object name: %s", old_rev);
 			return;
 		}
 	} else if (commit->parents && commit->parents->item) {
@@ -392,7 +395,8 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
 	if (!is_null_sha1(old_rev_sha1)) {
 		commit2 = lookup_commit_reference(old_rev_sha1);
 		if (!commit2 || parse_commit(commit2)) {
-			cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1));
+			cgit_print_error_page(404, "Not found",
+				"Bad commit: %s", sha1_to_hex(old_rev_sha1));
 			return;
 		}
 		old_tree_sha1 = commit2->tree->object.sha1;
@@ -425,8 +429,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
 	difftype = ctx.qry.has_difftype ? ctx.qry.difftype : ctx.cfg.difftype;
 	use_ssdiff = difftype == DIFF_SSDIFF;
 
-	if (show_ctrls)
+	if (show_ctrls) {
+		cgit_print_layout_start();
 		cgit_print_diff_ctrls();
+	}
 
 	/*
 	 * Clicking on a link to a file in the diff stat should show a diff
@@ -454,4 +460,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
 	if (!use_ssdiff)
 		html("</td></tr>");
 	html("</table>");
+
+	if (show_ctrls)
+		cgit_print_layout_end();
 }
-- 
2.4.0.rc0.173.gb1cefcc



More information about the CGit mailing list