diff options
author | Lukas Fleischer <cgit@cryptocrack.de> | 2013-08-21 01:56:14 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-08-21 02:55:42 (JST) |
commit | 750f6462c9e1e20e87d2bce5ca2e7fd10e0d1ba6 (patch) | |
tree | a3b0e425d5f13e35b2a97d7fdb609bb8ada8ede7 | |
parent | 455b5987780f53ef55ebf6edd4543976763152da (diff) | |
download | cgit-750f6462c9e1e20e87d2bce5ca2e7fd10e0d1ba6.zip 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>
-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) | |||
98 | 98 | ||
99 | static void patch_fn(struct cgit_context *ctx) | 99 | static void patch_fn(struct cgit_context *ctx) |
100 | { | 100 | { |
101 | cgit_print_patch(ctx->qry.sha1, ctx->qry.path); | 101 | cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); |
102 | } | 102 | } |
103 | 103 | ||
104 | static void plain_fn(struct cgit_context *ctx) | 104 | static void plain_fn(struct cgit_context *ctx) |
@@ -11,7 +11,7 @@ | |||
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | void cgit_print_patch(char *hex, const char *prefix) | 14 | void cgit_print_patch(char *hex, const char *old_rev, const char *prefix) |
15 | { | 15 | { |
16 | struct rev_info rev; | 16 | struct rev_info rev; |
17 | struct commit *commit; | 17 | struct commit *commit; |
@@ -33,16 +33,29 @@ void cgit_print_patch(char *hex, const char *prefix) | |||
33 | return; | 33 | return; |
34 | } | 34 | } |
35 | 35 | ||
36 | if (commit->parents && commit->parents->item) { | 36 | if (old_rev) { |
37 | if (get_sha1(old_rev, old_sha1)) { | ||
38 | cgit_print_error("Bad object id: %s", old_rev); | ||
39 | return; | ||
40 | } | ||
41 | if (!lookup_commit_reference(old_sha1)) { | ||
42 | cgit_print_error("Bad commit reference: %s", old_rev); | ||
43 | return; | ||
44 | } | ||
45 | } else if (commit->parents && commit->parents->item) { | ||
37 | hashcpy(old_sha1, commit->parents->item->object.sha1); | 46 | hashcpy(old_sha1, commit->parents->item->object.sha1); |
38 | sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1), | ||
39 | sha1_to_hex(sha1)); | ||
40 | } else { | 47 | } else { |
41 | hashclr(old_sha1); | 48 | hashclr(old_sha1); |
49 | } | ||
50 | |||
51 | if (is_null_sha1(old_sha1)) { | ||
42 | memcpy(rev_range, sha1_to_hex(sha1), 41); | 52 | memcpy(rev_range, sha1_to_hex(sha1), 41); |
53 | } else { | ||
54 | sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1), | ||
55 | sha1_to_hex(sha1)); | ||
43 | } | 56 | } |
44 | 57 | ||
45 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); | 58 | patchname = fmt("%s.patch", rev_range); |
46 | ctx.page.mimetype = "text/plain"; | 59 | ctx.page.mimetype = "text/plain"; |
47 | ctx.page.filename = patchname; | 60 | ctx.page.filename = patchname; |
48 | cgit_print_http_headers(&ctx); | 61 | cgit_print_http_headers(&ctx); |
@@ -1,6 +1,6 @@ | |||
1 | #ifndef UI_PATCH_H | 1 | #ifndef UI_PATCH_H |
2 | #define UI_PATCH_H | 2 | #define UI_PATCH_H |
3 | 3 | ||
4 | extern void cgit_print_patch(char *hex, const char *prefix); | 4 | extern void cgit_print_patch(char *hex, const char *old_rev, const char *prefix); |
5 | 5 | ||
6 | #endif /* UI_PATCH_H */ | 6 | #endif /* UI_PATCH_H */ |