Author: Lars Hjemli <hjemli@gmail.com>
Add support for commitdiff via h parameter The commitdiff will be generated against the first parent, and the diff page also gets the benefit of repo.defbranch. Cleaned up some bad whitespace in cgit.h while at it. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c | 3 ++- cgit.h | 11 ++++++----- ui-diff.c | 14 +++++++++++++-
diff --git a/cgit.c b/cgit.c index 9b4815d9acdf155a44d2b0c5bb4e9de7dabf098f..3e7e5950ebc9eca6cf4c9f5402024ab8d1a92eb1 100644 --- a/cgit.c +++ b/cgit.c @@ -120,7 +120,8 @@ cgit_print_commit(cgit_query_head); } else if (!strcmp(cgit_query_page, "view")) { cgit_print_view(cgit_query_sha1, cgit_query_path); } else if (!strcmp(cgit_query_page, "diff")) { - cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); + cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, + cgit_query_path); } else { cgit_print_error("Invalid request"); } diff --git a/cgit.h b/cgit.h index ac710a6d2a74fa6feb20d8cff918070ac38a4464..764225d22e819e60946f886ee2f5c997ffa75611 100644 --- a/cgit.h +++ b/cgit.h @@ -157,7 +157,7 @@ extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); -extern char *cgit_pageurl(const char *reponame, const char *pagename, +extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern void cgit_print_error(char *msg); @@ -165,8 +165,8 @@ extern void cgit_print_date(unsigned long secs); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); extern void cgit_print_pageheader(char *title, int show_search); -extern void cgit_print_snapshot_start(const char *mimetype, - const char *filename, +extern void cgit_print_snapshot_start(const char *mimetype, + const char *filename, struct cacheitem *item); extern void cgit_print_repolist(struct cacheitem *item); @@ -176,8 +176,9 @@ extern void cgit_print_view(const char *hex, char *path); extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); extern void cgit_print_tree(const char *rev, const char *hex, char *path); extern void cgit_print_commit(const char *hex); -extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); -extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, +extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, + char *path); +extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, const char *format, const char *prefix, const char *filename); diff --git a/ui-diff.c b/ui-diff.c index 999b6f39f9f2aced54ecb3622ee5db211559343c..afe1c90505ade9e52b9e89b92eb39efcd560a26d 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -66,11 +66,23 @@ cgit_print_error("Error running diff"); html("</tr></td>"); } -void cgit_print_diff(const char *old_hex, const char *new_hex, char *path) +void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) { unsigned char sha1[20], sha2[20]; enum object_type type; unsigned long size; + struct commit *commit; + + if (head && !old_hex && !new_hex) { + get_sha1(head, sha1); + commit = lookup_commit_reference(sha1); + if (commit && !parse_commit(commit)) { + html("<table class='diff'>"); + cgit_diff_commit(commit, filepair_cb); + html("</td></tr></table>"); + } + return; + } get_sha1(old_hex, sha1); get_sha1(new_hex, sha2);