2007-12-10 21:47:29 +01:00
|
|
|
/* ui-patch.c: generate patch view
|
|
|
|
*
|
2014-01-08 15:10:49 +01:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2007-12-10 21:47:29 +01:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 12:37:59 +02:00
|
|
|
#include "ui-patch.h"
|
2008-02-23 22:45:33 +01:00
|
|
|
#include "html.h"
|
2008-03-24 16:50:57 +01:00
|
|
|
#include "ui-shared.h"
|
2007-12-10 21:47:29 +01:00
|
|
|
|
2013-08-20 18:56:15 +02:00
|
|
|
void cgit_print_patch(const char *new_rev, const char *old_rev,
|
|
|
|
const char *prefix)
|
2007-12-10 21:47:29 +01:00
|
|
|
{
|
2013-08-20 18:56:13 +02:00
|
|
|
struct rev_info rev;
|
2007-12-10 21:47:29 +01:00
|
|
|
struct commit *commit;
|
2016-09-29 21:51:41 +02:00
|
|
|
struct object_id new_rev_oid, old_rev_oid;
|
2013-08-20 18:56:13 +02:00
|
|
|
char rev_range[2 * 40 + 3];
|
2016-11-24 20:14:54 +01:00
|
|
|
const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL };
|
|
|
|
int rev_argc = ARRAY_SIZE(rev_argv) - 1;
|
2007-12-10 21:47:29 +01:00
|
|
|
char *patchname;
|
|
|
|
|
2016-03-14 23:41:14 +01:00
|
|
|
if (!prefix)
|
|
|
|
rev_argc--;
|
|
|
|
|
2013-08-20 18:56:15 +02:00
|
|
|
if (!new_rev)
|
|
|
|
new_rev = ctx.qry.head;
|
2007-12-10 21:47:29 +01:00
|
|
|
|
2016-09-29 21:51:41 +02:00
|
|
|
if (get_oid(new_rev, &new_rev_oid)) {
|
2015-08-14 13:47:07 +02:00
|
|
|
cgit_print_error_page(404, "Not found",
|
|
|
|
"Bad object id: %s", new_rev);
|
2007-12-10 21:47:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-08-10 02:02:56 +02:00
|
|
|
commit = lookup_commit_reference(&new_rev_oid);
|
2007-12-10 21:47:29 +01:00
|
|
|
if (!commit) {
|
2015-08-14 13:47:07 +02:00
|
|
|
cgit_print_error_page(404, "Not found",
|
|
|
|
"Bad commit reference: %s", new_rev);
|
2007-12-10 21:47:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-03-17 23:13:16 +01:00
|
|
|
|
2013-08-20 18:56:14 +02:00
|
|
|
if (old_rev) {
|
2016-09-29 21:51:41 +02:00
|
|
|
if (get_oid(old_rev, &old_rev_oid)) {
|
2015-08-14 13:47:07 +02:00
|
|
|
cgit_print_error_page(404, "Not found",
|
|
|
|
"Bad object id: %s", old_rev);
|
2013-08-20 18:56:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-10 02:02:56 +02:00
|
|
|
if (!lookup_commit_reference(&old_rev_oid)) {
|
2015-08-14 13:47:07 +02:00
|
|
|
cgit_print_error_page(404, "Not found",
|
|
|
|
"Bad commit reference: %s", old_rev);
|
2013-08-20 18:56:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (commit->parents && commit->parents->item) {
|
2016-09-29 21:51:41 +02:00
|
|
|
oidcpy(&old_rev_oid, &commit->parents->item->object.oid);
|
2013-08-20 18:56:13 +02:00
|
|
|
} else {
|
2016-09-29 21:51:41 +02:00
|
|
|
oidclr(&old_rev_oid);
|
2013-08-20 18:56:14 +02:00
|
|
|
}
|
|
|
|
|
2016-09-29 21:51:41 +02:00
|
|
|
if (is_null_oid(&old_rev_oid)) {
|
|
|
|
memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1);
|
2013-08-20 18:56:14 +02:00
|
|
|
} else {
|
2016-09-29 21:51:41 +02:00
|
|
|
sprintf(rev_range, "%s..%s", oid_to_hex(&old_rev_oid),
|
|
|
|
oid_to_hex(&new_rev_oid));
|
2013-08-20 18:56:13 +02:00
|
|
|
}
|
2007-12-10 21:47:29 +01:00
|
|
|
|
2013-08-20 18:56:14 +02:00
|
|
|
patchname = fmt("%s.patch", rev_range);
|
2008-03-24 00:51:19 +01:00
|
|
|
ctx.page.mimetype = "text/plain";
|
|
|
|
ctx.page.filename = patchname;
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_print_http_headers();
|
2013-08-20 18:56:13 +02:00
|
|
|
|
|
|
|
if (ctx.cfg.noplainemail) {
|
|
|
|
rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
|
|
|
|
"2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: "
|
|
|
|
"%s%n%n%w(0)%b";
|
2009-08-07 14:05:17 +02:00
|
|
|
}
|
2013-08-20 18:56:13 +02:00
|
|
|
|
|
|
|
init_revisions(&rev, NULL);
|
|
|
|
rev.abbrev = DEFAULT_ABBREV;
|
|
|
|
rev.verbose_header = 1;
|
|
|
|
rev.diff = 1;
|
|
|
|
rev.show_root_diff = 1;
|
2013-08-22 14:48:47 +02:00
|
|
|
rev.max_parents = 1;
|
2014-12-28 14:10:33 +01:00
|
|
|
rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT |
|
|
|
|
DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY;
|
2016-03-14 23:41:14 +01:00
|
|
|
if (prefix)
|
|
|
|
rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix);
|
2016-11-24 20:14:54 +01:00
|
|
|
setup_revisions(rev_argc, rev_argv, &rev, NULL);
|
2013-08-20 18:56:13 +02:00
|
|
|
prepare_revision_walk(&rev);
|
|
|
|
|
|
|
|
while ((commit = get_revision(&rev)) != NULL) {
|
|
|
|
log_tree_commit(&rev, commit);
|
2013-08-26 20:38:33 +02:00
|
|
|
printf("-- \ncgit %s\n\n", cgit_version);
|
2007-12-18 09:26:50 +01:00
|
|
|
}
|
2007-12-10 21:47:29 +01:00
|
|
|
}
|