about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ui-patch.c33
-rw-r--r--ui-patch.h3
2 files changed, 19 insertions, 17 deletions
diff --git a/ui-patch.c b/ui-patch.c index bb39294..1dbb39d 100644 --- a/ui-patch.c +++ b/ui-patch.c
@@ -11,48 +11,49 @@
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14void cgit_print_patch(char *hex, const char *old_rev, const char *prefix) 14void cgit_print_patch(const char *new_rev, const char *old_rev,
15 const char *prefix)
15{ 16{
16 struct rev_info rev; 17 struct rev_info rev;
17 struct commit *commit; 18 struct commit *commit;
18 unsigned char sha1[20], old_sha1[20]; 19 unsigned char new_rev_sha1[20], old_rev_sha1[20];
19 char rev_range[2 * 40 + 3]; 20 char rev_range[2 * 40 + 3];
20 char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range }; 21 char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range };
21 char *patchname; 22 char *patchname;
22 23
23 if (!hex) 24 if (!new_rev)
24 hex = ctx.qry.head; 25 new_rev = ctx.qry.head;
25 26
26 if (get_sha1(hex, sha1)) { 27 if (get_sha1(new_rev, new_rev_sha1)) {
27 cgit_print_error("Bad object id: %s", hex); 28 cgit_print_error("Bad object id: %s", new_rev);
28 return; 29 return;
29 } 30 }
30 commit = lookup_commit_reference(sha1); 31 commit = lookup_commit_reference(new_rev_sha1);
31 if (!commit) { 32 if (!commit) {
32 cgit_print_error("Bad commit reference: %s", hex); 33 cgit_print_error("Bad commit reference: %s", new_rev);
33 return; 34 return;
34 } 35 }
35 36
36 if (old_rev) { 37 if (old_rev) {
37 if (get_sha1(old_rev, old_sha1)) { 38 if (get_sha1(old_rev, old_rev_sha1)) {
38 cgit_print_error("Bad object id: %s", old_rev); 39 cgit_print_error("Bad object id: %s", old_rev);
39 return; 40 return;
40 } 41 }
41 if (!lookup_commit_reference(old_sha1)) { 42 if (!lookup_commit_reference(old_rev_sha1)) {
42 cgit_print_error("Bad commit reference: %s", old_rev); 43 cgit_print_error("Bad commit reference: %s", old_rev);
43 return; 44 return;
44 } 45 }
45 } else if (commit->parents && commit->parents->item) { 46 } else if (commit->parents && commit->parents->item) {
46 hashcpy(old_sha1, commit->parents->item->object.sha1); 47 hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
47 } else { 48 } else {
48 hashclr(old_sha1); 49 hashclr(old_rev_sha1);
49 } 50 }
50 51
51 if (is_null_sha1(old_sha1)) { 52 if (is_null_sha1(old_rev_sha1)) {
52 memcpy(rev_range, sha1_to_hex(sha1), 41); 53 memcpy(rev_range, sha1_to_hex(new_rev_sha1), 41);
53 } else { 54 } else {
54 sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1), 55 sprintf(rev_range, "%s..%s", sha1_to_hex(old_rev_sha1),
55 sha1_to_hex(sha1)); 56 sha1_to_hex(new_rev_sha1));
56 } 57 }
57 58
58 patchname = fmt("%s.patch", rev_range); 59 patchname = fmt("%s.patch", rev_range);
diff --git a/ui-patch.h b/ui-patch.h index acd37fd..7a6cacd 100644 --- a/ui-patch.h +++ b/ui-patch.h
@@ -1,6 +1,7 @@
1#ifndef UI_PATCH_H 1#ifndef UI_PATCH_H
2#define UI_PATCH_H 2#define UI_PATCH_H
3 3
4extern void cgit_print_patch(char *hex, const char *old_rev, const char *prefix); 4extern void cgit_print_patch(const char *new_rev, const char *old_rev,
5 const char *prefix);
5 6
6#endif /* UI_PATCH_H */ 7#endif /* UI_PATCH_H */