]>
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 struct object_id new_rev_oid
, old_rev_oid
;
20 char rev_range
[2 * 40 + 3];
21 const char *rev_argv
[] = { NULL
, "--reverse", "--format=email", rev_range
, "--", prefix
, NULL
};
22 int rev_argc
= ARRAY_SIZE(rev_argv
) - 1;
29 new_rev
= ctx
.qry
.head
;
31 if (get_oid(new_rev
, &new_rev_oid
)) {
32 cgit_print_error_page(404, "Not found",
33 "Bad object id: %s", new_rev
);
36 commit
= lookup_commit_reference(new_rev_oid
.hash
);
38 cgit_print_error_page(404, "Not found",
39 "Bad commit reference: %s", new_rev
);
44 if (get_oid(old_rev
, &old_rev_oid
)) {
45 cgit_print_error_page(404, "Not found",
46 "Bad object id: %s", old_rev
);
49 if (!lookup_commit_reference(old_rev_oid
.hash
)) {
50 cgit_print_error_page(404, "Not found",
51 "Bad commit reference: %s", old_rev
);
54 } else if (commit
->parents
&& commit
->parents
->item
) {
55 oidcpy(&old_rev_oid
, &commit
->parents
->item
->object
.oid
);
60 if (is_null_oid(&old_rev_oid
)) {
61 memcpy(rev_range
, oid_to_hex(&new_rev_oid
), GIT_SHA1_HEXSZ
+ 1);
63 sprintf(rev_range
, "%s..%s", oid_to_hex(&old_rev_oid
),
64 oid_to_hex(&new_rev_oid
));
67 patchname
= fmt("%s.patch", rev_range
);
68 ctx
.page
.mimetype
= "text/plain";
69 ctx
.page
.filename
= patchname
;
70 cgit_print_http_headers();
72 if (ctx
.cfg
.noplainemail
) {
73 rev_argv
[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
74 "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: "
78 init_revisions(&rev
, NULL
);
79 rev
.abbrev
= DEFAULT_ABBREV
;
80 rev
.verbose_header
= 1;
82 rev
.show_root_diff
= 1;
84 rev
.diffopt
.output_format
|= DIFF_FORMAT_DIFFSTAT
|
85 DIFF_FORMAT_PATCH
| DIFF_FORMAT_SUMMARY
;
87 rev
.diffopt
.stat_sep
= fmt("(limited to '%s')\n\n", prefix
);
88 setup_revisions(rev_argc
, rev_argv
, &rev
, NULL
);
89 prepare_revision_walk(&rev
);
91 while ((commit
= get_revision(&rev
)) != NULL
) {
92 log_tree_commit(&rev
, commit
);
93 printf("-- \ncgit %s\n\n", cgit_version
);