]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-diff.c
Add support for commitdiff via h parameter
[ps-cgit] / ui-diff.c
index 7ec5701a4ea668990572b3088cd004f7d2dfc7bd..afe1c90505ade9e52b9e89b92eb39efcd560a26d 100644 (file)
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -35,7 +35,10 @@ static void header(unsigned char *sha1, char *path1,
                   unsigned char *sha2, char *path2)
 {
        char *abbrev1, *abbrev2;
                   unsigned char *sha2, char *path2)
 {
        char *abbrev1, *abbrev2;
-
+       if (is_null_sha1(sha1))
+               path1 = "dev/null";
+       if (is_null_sha1(sha2))
+               path2 = "dev/null";
        html("<tr><td>");
        html("<div class='head'>");
        html("diff --git a/");
        html("<tr><td>");
        html("<div class='head'>");
        html("diff --git a/");
@@ -63,11 +66,23 @@ static void filepair_cb(struct diff_filepair *pair)
        html("</tr></td>");
 }
 
        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;
 {
        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);
 
        get_sha1(old_hex, sha1);
        get_sha1(new_hex, sha2);