diff options
Diffstat (limited to 'ui-commit.c')
| -rw-r--r-- | ui-commit.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/ui-commit.c b/ui-commit.c index 8916212..c5ee8e7 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
| @@ -8,6 +8,111 @@ | |||
| 8 | 8 | ||
| 9 | #include "cgit.h" | 9 | #include "cgit.h" |
| 10 | 10 | ||
| 11 | int files = 0; | ||
| 12 | |||
| 13 | void print_filepair(struct diff_filepair *pair) | ||
| 14 | { | ||
| 15 | char *query; | ||
| 16 | char *class; | ||
| 17 | |||
| 18 | switch (pair->status) { | ||
| 19 | case DIFF_STATUS_ADDED: | ||
| 20 | class = "add"; | ||
| 21 | break; | ||
| 22 | case DIFF_STATUS_COPIED: | ||
| 23 | class = "cpy"; | ||
| 24 | break; | ||
| 25 | case DIFF_STATUS_DELETED: | ||
| 26 | class = "del"; | ||
| 27 | break; | ||
| 28 | case DIFF_STATUS_MODIFIED: | ||
| 29 | class = "upd"; | ||
| 30 | break; | ||
| 31 | case DIFF_STATUS_RENAMED: | ||
| 32 | class = "mov"; | ||
| 33 | break; | ||
| 34 | case DIFF_STATUS_TYPE_CHANGED: | ||
| 35 | class = "typ"; | ||
| 36 | break; | ||
| 37 | case DIFF_STATUS_UNKNOWN: | ||
| 38 | class = "unk"; | ||
| 39 | break; | ||
| 40 | case DIFF_STATUS_UNMERGED: | ||
| 41 | class = "stg"; | ||
| 42 | break; | ||
| 43 | default: | ||
| 44 | die("bug: unhandled diff status %c", pair->status); | ||
| 45 | } | ||
| 46 | |||
| 47 | html("<tr>"); | ||
| 48 | htmlf("<td class='mode'>"); | ||
| 49 | html_filemode(pair->two->mode); | ||
| 50 | if (pair->one->mode != pair->two->mode) { | ||
| 51 | html("<span class='modechange'>["); | ||
| 52 | html_filemode(pair->one->mode); | ||
| 53 | html("]</span>"); | ||
| 54 | } | ||
| 55 | htmlf("</td><td class='%s'>", class); | ||
| 56 | query = fmt("id=%s", sha1_to_hex(pair->two->sha1)); | ||
| 57 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query), | ||
| 58 | NULL, NULL); | ||
| 59 | if (pair->status == DIFF_STATUS_COPIED || | ||
| 60 | pair->status == DIFF_STATUS_RENAMED) { | ||
| 61 | html_txt(pair->two->path); | ||
| 62 | htmlf("</a> (%s from ", pair->status == DIFF_STATUS_COPIED ? | ||
| 63 | "copied" : "renamed"); | ||
| 64 | query = fmt("id=%s", sha1_to_hex(pair->one->sha1)); | ||
| 65 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query), | ||
| 66 | NULL, NULL); | ||
| 67 | html_txt(pair->one->path); | ||
| 68 | html("</a>)"); | ||
| 69 | } else { | ||
| 70 | html_txt(pair->two->path); | ||
| 71 | html("</a>"); | ||
| 72 | } | ||
| 73 | html("<td>"); | ||
| 74 | |||
| 75 | //TODO: diffstat graph | ||
| 76 | |||
| 77 | html("</td></tr>\n"); | ||
| 78 | files++; | ||
| 79 | } | ||
| 80 | |||
| 81 | void diff_format_cb(struct diff_queue_struct *q, | ||
| 82 | struct diff_options *options, void *data) | ||
| 83 | { | ||
| 84 | int i; | ||
| 85 | |||
| 86 | for (i = 0; i < q->nr; i++) { | ||
| 87 | if (q->queue[i]->status == 'U') | ||
| 88 | continue; | ||
| 89 | print_filepair(q->queue[i]); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | void cgit_diffstat(struct commit *commit) | ||
| 94 | { | ||
| 95 | struct diff_options opt; | ||
| 96 | int ret; | ||
| 97 | |||
| 98 | diff_setup(&opt); | ||
| 99 | opt.output_format = DIFF_FORMAT_CALLBACK; | ||
| 100 | opt.detect_rename = 1; | ||
| 101 | opt.recursive = 1; | ||
| 102 | opt.format_callback = diff_format_cb; | ||
| 103 | diff_setup_done(&opt); | ||
| 104 | |||
| 105 | if (commit->parents) | ||
| 106 | ret = diff_tree_sha1(commit->parents->item->object.sha1, | ||
| 107 | commit->object.sha1, | ||
| 108 | "", &opt); | ||
| 109 | else | ||
| 110 | ret = diff_root_tree_sha1(commit->object.sha1, "", &opt); | ||
| 111 | |||
| 112 | diffcore_std(&opt); | ||
| 113 | diff_flush(&opt); | ||
| 114 | } | ||
| 115 | |||
| 11 | void cgit_print_commit(const char *hex) | 116 | void cgit_print_commit(const char *hex) |
| 12 | { | 117 | { |
| 13 | struct commit *commit; | 118 | struct commit *commit; |
| @@ -62,5 +167,11 @@ void cgit_print_commit(const char *hex) | |||
| 62 | html("<div class='commit-msg'>"); | 167 | html("<div class='commit-msg'>"); |
| 63 | html_txt(info->msg); | 168 | html_txt(info->msg); |
| 64 | html("</div>"); | 169 | html("</div>"); |
| 170 | html("<table class='diffstat'>"); | ||
| 171 | html("<tr><th colspan='3'>Affected files</tr>\n"); | ||
| 172 | cgit_diffstat(commit); | ||
| 173 | htmlf("<tr><td colspan='3' class='summary'>" | ||
| 174 | "%d file%s changed</td></tr>\n", files, files > 1 ? "s" : ""); | ||
| 175 | html("</table>"); | ||
| 65 | cgit_free_commitinfo(info); | 176 | cgit_free_commitinfo(info); |
| 66 | } | 177 | } |
