diff options
author | Lukas Fleischer | 2013-08-20 18:56:14 +0200 |
---|---|---|
committer | Jason A. Donenfeld | 2013-08-20 19:55:42 +0200 |
commit | 750f6462c9e1e20e87d2bce5ca2e7fd10e0d1ba6 (patch) | |
tree | a3b0e425d5f13e35b2a97d7fdb609bb8ada8ede7 | |
parent | 455b5987780f53ef55ebf6edd4543976763152da (diff) | |
download | cgit-750f6462c9e1e20e87d2bce5ca2e7fd10e0d1ba6.tar.gz |
Allow for creating patch series
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>
Diffstat (limited to '')
-rw-r--r-- | cmd.c | 2 | ||||
-rw-r--r-- | ui-patch.c | 23 | ||||
-rw-r--r-- | ui-patch.h | 2 |
3 files changed, 20 insertions, 7 deletions
@@ -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) @@ -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); @@ -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 */ |