]> granicus.if.org Git - cgit/commitdiff
Allow for creating patch series
authorLukas Fleischer <cgit@cryptocrack.de>
Tue, 20 Aug 2013 16:56:14 +0000 (18:56 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 20 Aug 2013 17:55:42 +0000 (19:55 +0200)
This allows for specifying a revision range using the id2 parameter of
/patch/. The output that is produced is similar to

    $ git format-patch --stdout id2..id

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
cmd.c
ui-patch.c
ui-patch.h

diff --git a/cmd.c b/cmd.c
index 9893710b70bb4d5bee8ec0f968cac02a49729fe3..0202917e6c7366fdd6e95e3cde3c39198e6968f6 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -98,7 +98,7 @@ static void repolist_fn(struct cgit_context *ctx)
 
 static void patch_fn(struct cgit_context *ctx)
 {
-       cgit_print_patch(ctx->qry.sha1, ctx->qry.path);
+       cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
 }
 
 static void plain_fn(struct cgit_context *ctx)
index 72c9749831bf167f1ad38330b8f04058dcc141bd..bb3929437d38cfb1cee1a3bc9189890419f8eccb 100644 (file)
@@ -11,7 +11,7 @@
 #include "html.h"
 #include "ui-shared.h"
 
-void cgit_print_patch(char *hex, const char *prefix)
+void cgit_print_patch(char *hex, const char *old_rev, const char *prefix)
 {
        struct rev_info rev;
        struct commit *commit;
@@ -33,16 +33,29 @@ void cgit_print_patch(char *hex, const char *prefix)
                return;
        }
 
-       if (commit->parents && commit->parents->item) {
+       if (old_rev) {
+               if (get_sha1(old_rev, old_sha1)) {
+                       cgit_print_error("Bad object id: %s", old_rev);
+                       return;
+               }
+               if (!lookup_commit_reference(old_sha1)) {
+                       cgit_print_error("Bad commit reference: %s", old_rev);
+                       return;
+               }
+       } else if (commit->parents && commit->parents->item) {
                hashcpy(old_sha1, commit->parents->item->object.sha1);
-               sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
-                       sha1_to_hex(sha1));
        } else {
                hashclr(old_sha1);
+       }
+
+       if (is_null_sha1(old_sha1)) {
                memcpy(rev_range, sha1_to_hex(sha1), 41);
+       } else {
+               sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
+                       sha1_to_hex(sha1));
        }
 
-       patchname = fmt("%s.patch", sha1_to_hex(sha1));
+       patchname = fmt("%s.patch", rev_range);
        ctx.page.mimetype = "text/plain";
        ctx.page.filename = patchname;
        cgit_print_http_headers(&ctx);
index 1641cea252a67428eae079e34fb6f871118c1d83..acd37fd14b9d55a0f8afe1a429fc8317db42272f 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef UI_PATCH_H
 #define UI_PATCH_H
 
-extern void cgit_print_patch(char *hex, const char *prefix);
+extern void cgit_print_patch(char *hex, const char *old_rev, const char *prefix);
 
 #endif /* UI_PATCH_H */