2007-12-11 05:47:29 +09:00
|
|
|
/* ui-patch.c: generate patch view
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Lars Hjemli
|
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 19:37:59 +09:00
|
|
|
#include "ui-patch.h"
|
2008-02-24 06:45:33 +09:00
|
|
|
#include "html.h"
|
2008-03-25 00:50:57 +09:00
|
|
|
#include "ui-shared.h"
|
2007-12-11 05:47:29 +09:00
|
|
|
|
2010-06-10 08:09:33 +09:00
|
|
|
void cgit_print_patch(char *hex, const char *prefix)
|
2007-12-11 05:47:29 +09:00
|
|
|
{
|
|
|
|
struct commit *commit;
|
|
|
|
struct commitinfo *info;
|
|
|
|
unsigned char sha1[20], old_sha1[20];
|
|
|
|
char *patchname;
|
|
|
|
|
|
|
|
if (!hex)
|
2008-02-16 19:53:40 +09:00
|
|
|
hex = ctx.qry.head;
|
2007-12-11 05:47:29 +09:00
|
|
|
|
|
|
|
if (get_sha1(hex, sha1)) {
|
2013-04-06 19:23:52 +09:00
|
|
|
cgit_print_error("Bad object id: %s", hex);
|
2007-12-11 05:47:29 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
commit = lookup_commit_reference(sha1);
|
|
|
|
if (!commit) {
|
2013-04-06 19:23:52 +09:00
|
|
|
cgit_print_error("Bad commit reference: %s", hex);
|
2007-12-11 05:47:29 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
info = cgit_parse_commit(commit);
|
2008-03-18 07:13:16 +09:00
|
|
|
|
|
|
|
if (commit->parents && commit->parents->item)
|
|
|
|
hashcpy(old_sha1, commit->parents->item->object.sha1);
|
|
|
|
else
|
|
|
|
hashclr(old_sha1);
|
2007-12-11 05:47:29 +09:00
|
|
|
|
|
|
|
patchname = fmt("%s.patch", sha1_to_hex(sha1));
|
2008-03-24 08:51:19 +09:00
|
|
|
ctx.page.mimetype = "text/plain";
|
|
|
|
ctx.page.filename = patchname;
|
|
|
|
cgit_print_http_headers(&ctx);
|
2007-12-11 05:47:29 +09:00
|
|
|
htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
|
2009-08-07 21:05:17 +09:00
|
|
|
htmlf("From: %s", info->author);
|
|
|
|
if (!ctx.cfg.noplainemail) {
|
|
|
|
htmlf(" %s", info->author_email);
|
|
|
|
}
|
|
|
|
html("\n");
|
2007-12-11 05:47:29 +09:00
|
|
|
html("Date: ");
|
2008-12-30 19:14:52 +09:00
|
|
|
cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
|
2007-12-18 17:26:50 +09:00
|
|
|
htmlf("Subject: %s\n\n", info->subject);
|
|
|
|
if (info->msg && *info->msg) {
|
|
|
|
htmlf("%s", info->msg);
|
|
|
|
if (info->msg[strlen(info->msg) - 1] != '\n')
|
|
|
|
html("\n");
|
|
|
|
}
|
2007-12-11 05:47:29 +09:00
|
|
|
html("---\n");
|
2010-06-10 08:09:33 +09:00
|
|
|
if (prefix)
|
|
|
|
htmlf("(limited to '%s')\n\n", prefix);
|
2013-08-14 17:50:31 +09:00
|
|
|
cgit_diff_tree(old_sha1, sha1, filepair_cb_raw, prefix, 0);
|
2007-12-11 05:47:29 +09:00
|
|
|
html("--\n");
|
2013-03-07 06:22:07 +09:00
|
|
|
htmlf("cgit %s\n", cgit_version);
|
2007-12-11 05:47:29 +09:00
|
|
|
cgit_free_commitinfo(info);
|
|
|
|
}
|