]>
git.cameronkatri.com Git - cgit.git/blob - ui-patch.c
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_error("Bad object id: %s", new_rev
);
31 commit
= lookup_commit_reference(new_rev_sha1
);
33 cgit_print_error("Bad commit reference: %s", new_rev
);
38 if (get_sha1(old_rev
, old_rev_sha1
)) {
39 cgit_print_error("Bad object id: %s", old_rev
);
42 if (!lookup_commit_reference(old_rev_sha1
)) {
43 cgit_print_error("Bad commit reference: %s", old_rev
);
46 } else if (commit
->parents
&& commit
->parents
->item
) {
47 hashcpy(old_rev_sha1
, commit
->parents
->item
->object
.sha1
);
49 hashclr(old_rev_sha1
);
52 if (is_null_sha1(old_rev_sha1
)) {
53 memcpy(rev_range
, sha1_to_hex(new_rev_sha1
), 41);
55 sprintf(rev_range
, "%s..%s", sha1_to_hex(old_rev_sha1
),
56 sha1_to_hex(new_rev_sha1
));
59 patchname
= fmt("%s.patch", rev_range
);
60 ctx
.page
.mimetype
= "text/plain";
61 ctx
.page
.filename
= patchname
;
62 cgit_print_http_headers();
64 if (ctx
.cfg
.noplainemail
) {
65 rev_argv
[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
66 "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: "
70 init_revisions(&rev
, NULL
);
71 rev
.abbrev
= DEFAULT_ABBREV
;
72 rev
.verbose_header
= 1;
74 rev
.show_root_diff
= 1;
76 rev
.diffopt
.output_format
|= DIFF_FORMAT_DIFFSTAT
|
77 DIFF_FORMAT_PATCH
| DIFF_FORMAT_SUMMARY
;
78 setup_revisions(ARRAY_SIZE(rev_argv
), (const char **)rev_argv
, &rev
,
80 prepare_revision_walk(&rev
);
82 while ((commit
= get_revision(&rev
)) != NULL
) {
83 log_tree_commit(&rev
, commit
);
84 printf("-- \ncgit %s\n\n", cgit_version
);