]>
git.cameronkatri.com Git - cgit.git/blob - ui-patch.c
5a964108e51e5f553536899cb6b79922e25e1288
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 /* two commit hashes with two dots in between and termination */
15 #define REV_RANGE_LEN 2 * GIT_MAX_HEXSZ + 3
17 void cgit_print_patch(const char *new_rev
, const char *old_rev
,
21 struct commit
*commit
;
22 struct object_id new_rev_oid
, old_rev_oid
;
23 char rev_range
[REV_RANGE_LEN
];
24 const char *rev_argv
[] = { NULL
, "--reverse", "--format=email", rev_range
, "--", prefix
, NULL
};
25 int rev_argc
= ARRAY_SIZE(rev_argv
) - 1;
32 new_rev
= ctx
.qry
.head
;
34 if (get_oid(new_rev
, &new_rev_oid
)) {
35 cgit_print_error_page(404, "Not found",
36 "Bad object id: %s", new_rev
);
39 commit
= lookup_commit_reference(the_repository
, &new_rev_oid
);
41 cgit_print_error_page(404, "Not found",
42 "Bad commit reference: %s", new_rev
);
47 if (get_oid(old_rev
, &old_rev_oid
)) {
48 cgit_print_error_page(404, "Not found",
49 "Bad object id: %s", old_rev
);
52 if (!lookup_commit_reference(the_repository
, &old_rev_oid
)) {
53 cgit_print_error_page(404, "Not found",
54 "Bad commit reference: %s", old_rev
);
57 } else if (commit
->parents
&& commit
->parents
->item
) {
58 oidcpy(&old_rev_oid
, &commit
->parents
->item
->object
.oid
);
63 if (is_null_oid(&old_rev_oid
)) {
64 memcpy(rev_range
, oid_to_hex(&new_rev_oid
), GIT_SHA1_HEXSZ
+ 1);
66 xsnprintf(rev_range
, REV_RANGE_LEN
, "%s..%s", oid_to_hex(&old_rev_oid
),
67 oid_to_hex(&new_rev_oid
));
70 patchname
= fmt("%s.patch", rev_range
);
71 ctx
.page
.mimetype
= "text/plain";
72 ctx
.page
.filename
= patchname
;
73 cgit_print_http_headers();
75 if (ctx
.cfg
.noplainemail
) {
76 rev_argv
[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
77 "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: "
81 init_revisions(&rev
, NULL
);
82 rev
.abbrev
= DEFAULT_ABBREV
;
83 rev
.verbose_header
= 1;
85 rev
.show_root_diff
= 1;
87 rev
.diffopt
.output_format
|= DIFF_FORMAT_DIFFSTAT
|
88 DIFF_FORMAT_PATCH
| DIFF_FORMAT_SUMMARY
;
90 rev
.diffopt
.stat_sep
= fmt("(limited to '%s')\n\n", prefix
);
91 setup_revisions(rev_argc
, rev_argv
, &rev
, NULL
);
92 prepare_revision_walk(&rev
);
94 while ((commit
= get_revision(&rev
)) != NULL
) {
95 log_tree_commit(&rev
, commit
);
96 printf("-- \ncgit %s\n\n", cgit_version
);