-rw-r--r-- | ui-commit.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/ui-commit.c b/ui-commit.c index ed25824..8019e36 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -1,227 +1,228 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | ||
11 | 12 | ||
12 | static int files, slots; | 13 | static int files, slots; |
13 | static int total_adds, total_rems, max_changes; | 14 | static int total_adds, total_rems, max_changes; |
14 | static int lines_added, lines_removed; | 15 | static int lines_added, lines_removed; |
15 | static char *curr_rev; | 16 | static char *curr_rev; |
16 | 17 | ||
17 | static struct fileinfo { | 18 | static struct fileinfo { |
18 | char status; | 19 | char status; |
19 | unsigned char old_sha1[20]; | 20 | unsigned char old_sha1[20]; |
20 | unsigned char new_sha1[20]; | 21 | unsigned char new_sha1[20]; |
21 | unsigned short old_mode; | 22 | unsigned short old_mode; |
22 | unsigned short new_mode; | 23 | unsigned short new_mode; |
23 | char *old_path; | 24 | char *old_path; |
24 | char *new_path; | 25 | char *new_path; |
25 | unsigned int added; | 26 | unsigned int added; |
26 | unsigned int removed; | 27 | unsigned int removed; |
27 | } *items; | 28 | } *items; |
28 | 29 | ||
29 | 30 | ||
30 | void print_fileinfo(struct fileinfo *info) | 31 | void print_fileinfo(struct fileinfo *info) |
31 | { | 32 | { |
32 | char *class; | 33 | char *class; |
33 | 34 | ||
34 | switch (info->status) { | 35 | switch (info->status) { |
35 | case DIFF_STATUS_ADDED: | 36 | case DIFF_STATUS_ADDED: |
36 | class = "add"; | 37 | class = "add"; |
37 | break; | 38 | break; |
38 | case DIFF_STATUS_COPIED: | 39 | case DIFF_STATUS_COPIED: |
39 | class = "cpy"; | 40 | class = "cpy"; |
40 | break; | 41 | break; |
41 | case DIFF_STATUS_DELETED: | 42 | case DIFF_STATUS_DELETED: |
42 | class = "del"; | 43 | class = "del"; |
43 | break; | 44 | break; |
44 | case DIFF_STATUS_MODIFIED: | 45 | case DIFF_STATUS_MODIFIED: |
45 | class = "upd"; | 46 | class = "upd"; |
46 | break; | 47 | break; |
47 | case DIFF_STATUS_RENAMED: | 48 | case DIFF_STATUS_RENAMED: |
48 | class = "mov"; | 49 | class = "mov"; |
49 | break; | 50 | break; |
50 | case DIFF_STATUS_TYPE_CHANGED: | 51 | case DIFF_STATUS_TYPE_CHANGED: |
51 | class = "typ"; | 52 | class = "typ"; |
52 | break; | 53 | break; |
53 | case DIFF_STATUS_UNKNOWN: | 54 | case DIFF_STATUS_UNKNOWN: |
54 | class = "unk"; | 55 | class = "unk"; |
55 | break; | 56 | break; |
56 | case DIFF_STATUS_UNMERGED: | 57 | case DIFF_STATUS_UNMERGED: |
57 | class = "stg"; | 58 | class = "stg"; |
58 | break; | 59 | break; |
59 | default: | 60 | default: |
60 | die("bug: unhandled diff status %c", info->status); | 61 | die("bug: unhandled diff status %c", info->status); |
61 | } | 62 | } |
62 | 63 | ||
63 | html("<tr>"); | 64 | html("<tr>"); |
64 | htmlf("<td class='mode'>"); | 65 | htmlf("<td class='mode'>"); |
65 | if (is_null_sha1(info->new_sha1)) { | 66 | if (is_null_sha1(info->new_sha1)) { |
66 | cgit_print_filemode(info->old_mode); | 67 | cgit_print_filemode(info->old_mode); |
67 | } else { | 68 | } else { |
68 | cgit_print_filemode(info->new_mode); | 69 | cgit_print_filemode(info->new_mode); |
69 | } | 70 | } |
70 | 71 | ||
71 | if (info->old_mode != info->new_mode && | 72 | if (info->old_mode != info->new_mode && |
72 | !is_null_sha1(info->old_sha1) && | 73 | !is_null_sha1(info->old_sha1) && |
73 | !is_null_sha1(info->new_sha1)) { | 74 | !is_null_sha1(info->new_sha1)) { |
74 | html("<span class='modechange'>["); | 75 | html("<span class='modechange'>["); |
75 | cgit_print_filemode(info->old_mode); | 76 | cgit_print_filemode(info->old_mode); |
76 | html("]</span>"); | 77 | html("]</span>"); |
77 | } | 78 | } |
78 | htmlf("</td><td class='%s'>", class); | 79 | htmlf("</td><td class='%s'>", class); |
79 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, curr_rev, | 80 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, curr_rev, |
80 | NULL, info->new_path); | 81 | NULL, info->new_path); |
81 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 82 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
82 | htmlf(" (%s from %s)", | 83 | htmlf(" (%s from %s)", |
83 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", | 84 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
84 | info->old_path); | 85 | info->old_path); |
85 | html("</td><td class='right'>"); | 86 | html("</td><td class='right'>"); |
86 | htmlf("%d", info->added + info->removed); | 87 | htmlf("%d", info->added + info->removed); |
87 | html("</td><td class='graph'>"); | 88 | html("</td><td class='graph'>"); |
88 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 89 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
89 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 90 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
90 | info->added * 100.0 / max_changes); | 91 | info->added * 100.0 / max_changes); |
91 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 92 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
92 | info->removed * 100.0 / max_changes); | 93 | info->removed * 100.0 / max_changes); |
93 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 94 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
94 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 95 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
95 | html("</tr></table></td></tr>\n"); | 96 | html("</tr></table></td></tr>\n"); |
96 | } | 97 | } |
97 | 98 | ||
98 | void cgit_count_diff_lines(char *line, int len) | 99 | void cgit_count_diff_lines(char *line, int len) |
99 | { | 100 | { |
100 | if (line && (len > 0)) { | 101 | if (line && (len > 0)) { |
101 | if (line[0] == '+') | 102 | if (line[0] == '+') |
102 | lines_added++; | 103 | lines_added++; |
103 | else if (line[0] == '-') | 104 | else if (line[0] == '-') |
104 | lines_removed++; | 105 | lines_removed++; |
105 | } | 106 | } |
106 | } | 107 | } |
107 | 108 | ||
108 | void inspect_filepair(struct diff_filepair *pair) | 109 | void inspect_filepair(struct diff_filepair *pair) |
109 | { | 110 | { |
110 | files++; | 111 | files++; |
111 | lines_added = 0; | 112 | lines_added = 0; |
112 | lines_removed = 0; | 113 | lines_removed = 0; |
113 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 114 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
114 | if (files >= slots) { | 115 | if (files >= slots) { |
115 | if (slots == 0) | 116 | if (slots == 0) |
116 | slots = 4; | 117 | slots = 4; |
117 | else | 118 | else |
118 | slots = slots * 2; | 119 | slots = slots * 2; |
119 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 120 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
120 | } | 121 | } |
121 | items[files-1].status = pair->status; | 122 | items[files-1].status = pair->status; |
122 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 123 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
123 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 124 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
124 | items[files-1].old_mode = pair->one->mode; | 125 | items[files-1].old_mode = pair->one->mode; |
125 | items[files-1].new_mode = pair->two->mode; | 126 | items[files-1].new_mode = pair->two->mode; |
126 | items[files-1].old_path = xstrdup(pair->one->path); | 127 | items[files-1].old_path = xstrdup(pair->one->path); |
127 | items[files-1].new_path = xstrdup(pair->two->path); | 128 | items[files-1].new_path = xstrdup(pair->two->path); |
128 | items[files-1].added = lines_added; | 129 | items[files-1].added = lines_added; |
129 | items[files-1].removed = lines_removed; | 130 | items[files-1].removed = lines_removed; |
130 | if (lines_added + lines_removed > max_changes) | 131 | if (lines_added + lines_removed > max_changes) |
131 | max_changes = lines_added + lines_removed; | 132 | max_changes = lines_added + lines_removed; |
132 | total_adds += lines_added; | 133 | total_adds += lines_added; |
133 | total_rems += lines_removed; | 134 | total_rems += lines_removed; |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | void cgit_print_commit(char *hex) | 138 | void cgit_print_commit(char *hex) |
138 | { | 139 | { |
139 | struct commit *commit, *parent; | 140 | struct commit *commit, *parent; |
140 | struct commitinfo *info; | 141 | struct commitinfo *info; |
141 | struct commit_list *p; | 142 | struct commit_list *p; |
142 | unsigned char sha1[20]; | 143 | unsigned char sha1[20]; |
143 | char *tmp; | 144 | char *tmp; |
144 | int i; | 145 | int i; |
145 | 146 | ||
146 | if (!hex) | 147 | if (!hex) |
147 | hex = ctx.qry.head; | 148 | hex = ctx.qry.head; |
148 | curr_rev = hex; | 149 | curr_rev = hex; |
149 | 150 | ||
150 | if (get_sha1(hex, sha1)) { | 151 | if (get_sha1(hex, sha1)) { |
151 | cgit_print_error(fmt("Bad object id: %s", hex)); | 152 | cgit_print_error(fmt("Bad object id: %s", hex)); |
152 | return; | 153 | return; |
153 | } | 154 | } |
154 | commit = lookup_commit_reference(sha1); | 155 | commit = lookup_commit_reference(sha1); |
155 | if (!commit) { | 156 | if (!commit) { |
156 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 157 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
157 | return; | 158 | return; |
158 | } | 159 | } |
159 | info = cgit_parse_commit(commit); | 160 | info = cgit_parse_commit(commit); |
160 | 161 | ||
161 | html("<table summary='commit info' class='commit-info'>\n"); | 162 | html("<table summary='commit info' class='commit-info'>\n"); |
162 | html("<tr><th>author</th><td>"); | 163 | html("<tr><th>author</th><td>"); |
163 | html_txt(info->author); | 164 | html_txt(info->author); |
164 | html(" "); | 165 | html(" "); |
165 | html_txt(info->author_email); | 166 | html_txt(info->author_email); |
166 | html("</td><td class='right'>"); | 167 | html("</td><td class='right'>"); |
167 | cgit_print_date(info->author_date, FMT_LONGDATE); | 168 | cgit_print_date(info->author_date, FMT_LONGDATE); |
168 | html("</td></tr>\n"); | 169 | html("</td></tr>\n"); |
169 | html("<tr><th>committer</th><td>"); | 170 | html("<tr><th>committer</th><td>"); |
170 | html_txt(info->committer); | 171 | html_txt(info->committer); |
171 | html(" "); | 172 | html(" "); |
172 | html_txt(info->committer_email); | 173 | html_txt(info->committer_email); |
173 | html("</td><td class='right'>"); | 174 | html("</td><td class='right'>"); |
174 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 175 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
175 | html("</td></tr>\n"); | 176 | html("</td></tr>\n"); |
176 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 177 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
177 | tmp = xstrdup(hex); | 178 | tmp = xstrdup(hex); |
178 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 179 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
179 | ctx.qry.head, tmp, NULL); | 180 | ctx.qry.head, tmp, NULL); |
180 | html("</td></tr>\n"); | 181 | html("</td></tr>\n"); |
181 | for (p = commit->parents; p ; p = p->next) { | 182 | for (p = commit->parents; p ; p = p->next) { |
182 | parent = lookup_commit_reference(p->item->object.sha1); | 183 | parent = lookup_commit_reference(p->item->object.sha1); |
183 | if (!parent) { | 184 | if (!parent) { |
184 | html("<tr><td colspan='3'>"); | 185 | html("<tr><td colspan='3'>"); |
185 | cgit_print_error("Error reading parent commit"); | 186 | cgit_print_error("Error reading parent commit"); |
186 | html("</td></tr>"); | 187 | html("</td></tr>"); |
187 | continue; | 188 | continue; |
188 | } | 189 | } |
189 | html("<tr><th>parent</th>" | 190 | html("<tr><th>parent</th>" |
190 | "<td colspan='2' class='sha1'>"); | 191 | "<td colspan='2' class='sha1'>"); |
191 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 192 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
192 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); | 193 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); |
193 | html(" ("); | 194 | html(" ("); |
194 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, | 195 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
195 | sha1_to_hex(p->item->object.sha1), NULL); | 196 | sha1_to_hex(p->item->object.sha1), NULL); |
196 | html(")</td></tr>"); | 197 | html(")</td></tr>"); |
197 | } | 198 | } |
198 | if (ctx.repo->snapshots) { | 199 | if (ctx.repo->snapshots) { |
199 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 200 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
200 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, | 201 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, |
201 | hex, ctx.repo->snapshots); | 202 | hex, ctx.repo->snapshots); |
202 | html("</td></tr>"); | 203 | html("</td></tr>"); |
203 | } | 204 | } |
204 | html("</table>\n"); | 205 | html("</table>\n"); |
205 | html("<div class='commit-subject'>"); | 206 | html("<div class='commit-subject'>"); |
206 | html_txt(info->subject); | 207 | html_txt(info->subject); |
207 | html("</div>"); | 208 | html("</div>"); |
208 | html("<div class='commit-msg'>"); | 209 | html("<div class='commit-msg'>"); |
209 | html_txt(info->msg); | 210 | html_txt(info->msg); |
210 | html("</div>"); | 211 | html("</div>"); |
211 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 212 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
212 | html("<div class='diffstat-header'>Diffstat</div>"); | 213 | html("<div class='diffstat-header'>Diffstat</div>"); |
213 | html("<table summary='diffstat' class='diffstat'>"); | 214 | html("<table summary='diffstat' class='diffstat'>"); |
214 | max_changes = 0; | 215 | max_changes = 0; |
215 | cgit_diff_commit(commit, inspect_filepair); | 216 | cgit_diff_commit(commit, inspect_filepair); |
216 | for(i = 0; i<files; i++) | 217 | for(i = 0; i<files; i++) |
217 | print_fileinfo(&items[i]); | 218 | print_fileinfo(&items[i]); |
218 | html("</table>"); | 219 | html("</table>"); |
219 | html("<div class='diffstat-summary'>"); | 220 | html("<div class='diffstat-summary'>"); |
220 | htmlf("%d files changed, %d insertions, %d deletions (", | 221 | htmlf("%d files changed, %d insertions, %d deletions (", |
221 | files, total_adds, total_rems); | 222 | files, total_adds, total_rems); |
222 | cgit_diff_link("show diff", NULL, NULL, ctx.qry.head, hex, | 223 | cgit_diff_link("show diff", NULL, NULL, ctx.qry.head, hex, |
223 | NULL, NULL); | 224 | NULL, NULL); |
224 | html(")</div>"); | 225 | html(")</div>"); |
225 | } | 226 | } |
226 | cgit_free_commitinfo(info); | 227 | cgit_free_commitinfo(info); |
227 | } | 228 | } |