]>
git.cameronkatri.com Git - cgit.git/blob - ui-patch.c
57ca2f8ca7710df8cbea9b3bab09ff576f8a1d7d
1 /* ui-patch.c: generate patch view
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
12 #include "ui-shared.h"
14 void cgit_print_patch(const char *new_rev
, const char *old_rev
,
18 struct commit
*commit
;
19 unsigned char new_rev_sha1
[20], old_rev_sha1
[20];
20 char rev_range
[2 * 40 + 3];
21 char *rev_argv
[] = { NULL
, "--reverse", "--format=email", rev_range
};
25 new_rev
= ctx
.qry
.head
;
27 if (get_sha1(new_rev
, new_rev_sha1
)) {
28 cgit_print_http_headers();
29 cgit_print_error("Bad object id: %s", new_rev
);
32 commit
= lookup_commit_reference(new_rev_sha1
);
34 cgit_print_http_headers();
35 cgit_print_error("Bad commit reference: %s", new_rev
);
40 if (get_sha1(old_rev
, old_rev_sha1
)) {
41 cgit_print_http_headers();
42 cgit_print_error("Bad object id: %s", old_rev
);
45 if (!lookup_commit_reference(old_rev_sha1
)) {
46 cgit_print_http_headers();
47 cgit_print_error("Bad commit reference: %s", old_rev
);
50 } else if (commit
->parents
&& commit
->parents
->item
) {
51 hashcpy(old_rev_sha1
, commit
->parents
->item
->object
.sha1
);
53 hashclr(old_rev_sha1
);
56 if (is_null_sha1(old_rev_sha1
)) {
57 memcpy(rev_range
, sha1_to_hex(new_rev_sha1
), 41);
59 sprintf(rev_range
, "%s..%s", sha1_to_hex(old_rev_sha1
),
60 sha1_to_hex(new_rev_sha1
));
63 patchname
= fmt("%s.patch", rev_range
);
64 ctx
.page
.mimetype
= "text/plain";
65 ctx
.page
.filename
= patchname
;
66 cgit_print_http_headers();
68 if (ctx
.cfg
.noplainemail
) {
69 rev_argv
[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
70 "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: "
74 init_revisions(&rev
, NULL
);
75 rev
.abbrev
= DEFAULT_ABBREV
;
76 rev
.verbose_header
= 1;
78 rev
.show_root_diff
= 1;
80 rev
.diffopt
.output_format
|= DIFF_FORMAT_DIFFSTAT
|
81 DIFF_FORMAT_PATCH
| DIFF_FORMAT_SUMMARY
;
82 setup_revisions(ARRAY_SIZE(rev_argv
), (const char **)rev_argv
, &rev
,
84 prepare_revision_walk(&rev
);
86 while ((commit
= get_revision(&rev
)) != NULL
) {
87 log_tree_commit(&rev
, commit
);
88 printf("-- \ncgit %s\n\n", cgit_version
);