Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 1 | /* ui-patch.c: generate patch view |
| 2 | * |
| 3 | * Copyright (C) 2007 Lars Hjemli |
| 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-patch.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 11 | #include "html.h" |
Lars Hjemli | a4d1ca1 | 2008-03-24 16:50:57 +0100 | [diff] [blame] | 12 | #include "ui-shared.h" |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 13 | |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 14 | void cgit_print_patch(char *hex, const char *prefix) |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 15 | { |
| 16 | struct commit *commit; |
| 17 | struct commitinfo *info; |
| 18 | unsigned char sha1[20], old_sha1[20]; |
| 19 | char *patchname; |
| 20 | |
| 21 | if (!hex) |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 22 | hex = ctx.qry.head; |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 23 | |
| 24 | if (get_sha1(hex, sha1)) { |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 25 | cgit_print_error("Bad object id: %s", hex); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 26 | return; |
| 27 | } |
| 28 | commit = lookup_commit_reference(sha1); |
| 29 | if (!commit) { |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 30 | cgit_print_error("Bad commit reference: %s", hex); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 31 | return; |
| 32 | } |
| 33 | info = cgit_parse_commit(commit); |
Lars Hjemli | e01f140 | 2008-03-17 23:13:16 +0100 | [diff] [blame] | 34 | |
| 35 | if (commit->parents && commit->parents->item) |
| 36 | hashcpy(old_sha1, commit->parents->item->object.sha1); |
| 37 | else |
| 38 | hashclr(old_sha1); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 39 | |
| 40 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 41 | ctx.page.mimetype = "text/plain"; |
| 42 | ctx.page.filename = patchname; |
| 43 | cgit_print_http_headers(&ctx); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 44 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); |
Martin Szulecki | 2f56e39 | 2009-08-07 14:05:17 +0200 | [diff] [blame] | 45 | htmlf("From: %s", info->author); |
| 46 | if (!ctx.cfg.noplainemail) { |
| 47 | htmlf(" %s", info->author_email); |
| 48 | } |
| 49 | html("\n"); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 50 | html("Date: "); |
Tomas Carnecky | 03afc5f | 2008-12-30 11:14:52 +0100 | [diff] [blame] | 51 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); |
Lars Hjemli | f39c3c9 | 2007-12-18 08:26:50 +0000 | [diff] [blame] | 52 | htmlf("Subject: %s\n\n", info->subject); |
| 53 | if (info->msg && *info->msg) { |
| 54 | htmlf("%s", info->msg); |
| 55 | if (info->msg[strlen(info->msg) - 1] != '\n') |
| 56 | html("\n"); |
| 57 | } |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 58 | html("---\n"); |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 59 | if (prefix) |
| 60 | htmlf("(limited to '%s')\n\n", prefix); |
Lukas Fleischer | 747b035 | 2013-08-14 10:50:31 +0200 | [diff] [blame] | 61 | cgit_diff_tree(old_sha1, sha1, filepair_cb_raw, prefix, 0); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 62 | html("--\n"); |
John Keeping | 1a6feaf | 2013-03-06 21:22:07 +0000 | [diff] [blame] | 63 | htmlf("cgit %s\n", cgit_version); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 64 | cgit_free_commitinfo(info); |
| 65 | } |