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