aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/ui-diff.c b/ui-diff.c
index edee793..173d351 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -12,8 +12,8 @@
12#include "ui-shared.h" 12#include "ui-shared.h"
13#include "ui-ssdiff.h" 13#include "ui-ssdiff.h"
14 14
15unsigned char old_rev_sha1[20]; 15struct object_id old_rev_oid[1];
16unsigned char new_rev_sha1[20]; 16struct object_id new_rev_oid[1];
17 17
18static int files, slots; 18static int files, slots;
19static int total_adds, total_rems, max_changes; 19static int total_adds, total_rems, max_changes;
@@ -21,8 +21,8 @@ static int lines_added, lines_removed;
21 21
22static struct fileinfo { 22static struct fileinfo {
23 char status; 23 char status;
24 unsigned char old_sha1[20]; 24 struct object_id old_oid[1];
25 unsigned char new_sha1[20]; 25 struct object_id new_oid[1];
26 unsigned short old_mode; 26 unsigned short old_mode;
27 unsigned short new_mode; 27 unsigned short new_mode;
28 char *old_path; 28 char *old_path;
@@ -83,15 +83,15 @@ static void print_fileinfo(struct fileinfo *info)
83 83
84 html("<tr>"); 84 html("<tr>");
85 htmlf("<td class='mode'>"); 85 htmlf("<td class='mode'>");
86 if (is_null_sha1(info->new_sha1)) { 86 if (is_null_oid(info->new_oid)) {
87 cgit_print_filemode(info->old_mode); 87 cgit_print_filemode(info->old_mode);
88 } else { 88 } else {
89 cgit_print_filemode(info->new_mode); 89 cgit_print_filemode(info->new_mode);
90 } 90 }
91 91
92 if (info->old_mode != info->new_mode && 92 if (info->old_mode != info->new_mode &&
93 !is_null_sha1(info->old_sha1) && 93 !is_null_oid(info->old_oid) &&
94 !is_null_sha1(info->new_sha1)) { 94 !is_null_oid(info->new_oid)) {
95 html("<span class='modechange'>["); 95 html("<span class='modechange'>[");
96 cgit_print_filemode(info->old_mode); 96 cgit_print_filemode(info->old_mode);
97 html("]</span>"); 97 html("]</span>");
@@ -160,7 +160,7 @@ static void inspect_filepair(struct diff_filepair *pair)
160 files++; 160 files++;
161 lines_added = 0; 161 lines_added = 0;
162 lines_removed = 0; 162 lines_removed = 0;
163 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, 163 cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size,
164 &binary, 0, ctx.qry.ignorews, count_diff_lines); 164 &binary, 0, ctx.qry.ignorews, count_diff_lines);
165 if (files >= slots) { 165 if (files >= slots) {
166 if (slots == 0) 166 if (slots == 0)
@@ -170,8 +170,8 @@ static void inspect_filepair(struct diff_filepair *pair)
170 items = xrealloc(items, slots * sizeof(struct fileinfo)); 170 items = xrealloc(items, slots * sizeof(struct fileinfo));
171 } 171 }
172 items[files-1].status = pair->status; 172 items[files-1].status = pair->status;
173 hashcpy(items[files-1].old_sha1, pair->one->sha1); 173 oidcpy(items[files-1].old_oid, &pair->one->oid);
174 hashcpy(items[files-1].new_sha1, pair->two->sha1); 174 oidcpy(items[files-1].new_oid, &pair->two->oid);
175 items[files-1].old_mode = pair->one->mode; 175 items[files-1].old_mode = pair->one->mode;
176 items[files-1].new_mode = pair->two->mode; 176 items[files-1].new_mode = pair->two->mode;
177 items[files-1].old_path = xstrdup(pair->one->path); 177 items[files-1].old_path = xstrdup(pair->one->path);
@@ -187,8 +187,8 @@ static void inspect_filepair(struct diff_filepair *pair)
187 total_rems += lines_removed; 187 total_rems += lines_removed;
188} 188}
189 189
190static void cgit_print_diffstat(const unsigned char *old_sha1, 190static void cgit_print_diffstat(const struct object_id *old_oid,
191 const unsigned char *new_sha1, 191 const struct object_id *new_oid,
192 const char *prefix) 192 const char *prefix)
193{ 193{
194 int i; 194 int i;
@@ -204,7 +204,7 @@ static void cgit_print_diffstat(const unsigned char *old_sha1,
204 html("</div>"); 204 html("</div>");
205 html("<table summary='diffstat' class='diffstat'>"); 205 html("<table summary='diffstat' class='diffstat'>");
206 max_changes = 0; 206 max_changes = 0;
207 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, 207 cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix,
208 ctx.qry.ignorews); 208 ctx.qry.ignorews);
209 for (i = 0; i<files; i++) 209 for (i = 0; i<files; i++)
210 print_fileinfo(&items[i]); 210 print_fileinfo(&items[i]);
@@ -238,8 +238,8 @@ static void print_line(char *line, int len)
238 line[len-1] = c; 238 line[len-1] = c;
239} 239}
240 240
241static void header(unsigned char *sha1, char *path1, int mode1, 241static void header(const struct object_id *oid1, char *path1, int mode1,
242 unsigned char *sha2, char *path2, int mode2) 242 const struct object_id *oid2, char *path2, int mode2)
243{ 243{
244 char *abbrev1, *abbrev2; 244 char *abbrev1, *abbrev2;
245 int subproject; 245 int subproject;
@@ -258,8 +258,8 @@ static void header(unsigned char *sha1, char *path1, int mode1,
258 htmlf("<br/>deleted file mode %.6o", mode1); 258 htmlf("<br/>deleted file mode %.6o", mode1);
259 259
260 if (!subproject) { 260 if (!subproject) {
261 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); 261 abbrev1 = xstrdup(find_unique_abbrev(oid1->hash, DEFAULT_ABBREV));
262 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); 262 abbrev2 = xstrdup(find_unique_abbrev(oid2->hash, DEFAULT_ABBREV));
263 htmlf("<br/>index %s..%s", abbrev1, abbrev2); 263 htmlf("<br/>index %s..%s", abbrev1, abbrev2);
264 free(abbrev1); 264 free(abbrev1);
265 free(abbrev2); 265 free(abbrev2);
@@ -268,24 +268,24 @@ static void header(unsigned char *sha1, char *path1, int mode1,
268 if (mode2 != mode1) 268 if (mode2 != mode1)
269 htmlf("..%.6o", mode2); 269 htmlf("..%.6o", mode2);
270 } 270 }
271 if (is_null_sha1(sha1)) { 271 if (is_null_oid(oid1)) {
272 path1 = "dev/null"; 272 path1 = "dev/null";
273 html("<br/>--- /"); 273 html("<br/>--- /");
274 } else 274 } else
275 html("<br/>--- a/"); 275 html("<br/>--- a/");
276 if (mode1 != 0) 276 if (mode1 != 0)
277 cgit_tree_link(path1, NULL, NULL, ctx.qry.head, 277 cgit_tree_link(path1, NULL, NULL, ctx.qry.head,
278 sha1_to_hex(old_rev_sha1), path1); 278 oid_to_hex(old_rev_oid), path1);
279 else 279 else
280 html_txt(path1); 280 html_txt(path1);
281 if (is_null_sha1(sha2)) { 281 if (is_null_oid(oid2)) {
282 path2 = "dev/null"; 282 path2 = "dev/null";
283 html("<br/>+++ /"); 283 html("<br/>+++ /");
284 } else 284 } else
285 html("<br/>+++ b/"); 285 html("<br/>+++ b/");
286 if (mode2 != 0) 286 if (mode2 != 0)
287 cgit_tree_link(path2, NULL, NULL, ctx.qry.head, 287 cgit_tree_link(path2, NULL, NULL, ctx.qry.head,
288 sha1_to_hex(new_rev_sha1), path2); 288 oid_to_hex(new_rev_oid), path2);
289 else 289 else
290 html_txt(path2); 290 html_txt(path2);
291 } 291 }
@@ -307,20 +307,20 @@ static void filepair_cb(struct diff_filepair *pair)
307 cgit_ssdiff_header_begin(); 307 cgit_ssdiff_header_begin();
308 print_line_fn = cgit_ssdiff_line_cb; 308 print_line_fn = cgit_ssdiff_line_cb;
309 } 309 }
310 header(pair->one->sha1, pair->one->path, pair->one->mode, 310 header(&pair->one->oid, pair->one->path, pair->one->mode,
311 pair->two->sha1, pair->two->path, pair->two->mode); 311 &pair->two->oid, pair->two->path, pair->two->mode);
312 if (use_ssdiff) 312 if (use_ssdiff)
313 cgit_ssdiff_header_end(); 313 cgit_ssdiff_header_end();
314 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 314 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
315 if (S_ISGITLINK(pair->one->mode)) 315 if (S_ISGITLINK(pair->one->mode))
316 print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 316 print_line_fn(fmt("-Subproject %s", oid_to_hex(&pair->one->oid)), 52);
317 if (S_ISGITLINK(pair->two->mode)) 317 if (S_ISGITLINK(pair->two->mode))
318 print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 318 print_line_fn(fmt("+Subproject %s", oid_to_hex(&pair->two->oid)), 52);
319 if (use_ssdiff) 319 if (use_ssdiff)
320 cgit_ssdiff_footer(); 320 cgit_ssdiff_footer();
321 return; 321 return;
322 } 322 }
323 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 323 if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size,
324 &new_size, &binary, ctx.qry.context, 324 &new_size, &binary, ctx.qry.context,
325 ctx.qry.ignorews, print_line_fn)) 325 ctx.qry.ignorews, print_line_fn))
326 cgit_print_error("Error running diff"); 326 cgit_print_error("Error running diff");
@@ -402,36 +402,36 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
402 402
403 if (!new_rev) 403 if (!new_rev)
404 new_rev = ctx.qry.head; 404 new_rev = ctx.qry.head;
405 if (get_sha1(new_rev, new_rev_sha1)) { 405 if (get_oid(new_rev, new_rev_oid)) {
406 cgit_print_error_page(404, "Not found", 406 cgit_print_error_page(404, "Not found",
407 "Bad object name: %s", new_rev); 407 "Bad object name: %s", new_rev);
408 return; 408 return;
409 } 409 }
410 commit = lookup_commit_reference(new_rev_sha1); 410 commit = lookup_commit_reference(new_rev_oid->hash);
411 if (!commit || parse_commit(commit)) { 411 if (!commit || parse_commit(commit)) {
412 cgit_print_error_page(404, "Not found", 412 cgit_print_error_page(404, "Not found",
413 "Bad commit: %s", sha1_to_hex(new_rev_sha1)); 413 "Bad commit: %s", oid_to_hex(new_rev_oid));
414 return; 414 return;
415 } 415 }
416 new_tree_sha1 = commit->tree->object.oid.hash; 416 new_tree_sha1 = commit->tree->object.oid.hash;
417 417
418 if (old_rev) { 418 if (old_rev) {
419 if (get_sha1(old_rev, old_rev_sha1)) { 419 if (get_oid(old_rev, old_rev_oid)) {
420 cgit_print_error_page(404, "Not found", 420 cgit_print_error_page(404, "Not found",
421 "Bad object name: %s", old_rev); 421 "Bad object name: %s", old_rev);
422 return; 422 return;
423 } 423 }
424 } else if (commit->parents && commit->parents->item) { 424 } else if (commit->parents && commit->parents->item) {
425 hashcpy(old_rev_sha1, commit->parents->item->object.oid.hash); 425 oidcpy(old_rev_oid, &commit->parents->item->object.oid);
426 } else { 426 } else {
427 hashclr(old_rev_sha1); 427 oidclr(old_rev_oid);
428 } 428 }
429 429
430 if (!is_null_sha1(old_rev_sha1)) { 430 if (!is_null_oid(old_rev_oid)) {
431 commit2 = lookup_commit_reference(old_rev_sha1); 431 commit2 = lookup_commit_reference(old_rev_oid->hash);
432 if (!commit2 || parse_commit(commit2)) { 432 if (!commit2 || parse_commit(commit2)) {
433 cgit_print_error_page(404, "Not found", 433 cgit_print_error_page(404, "Not found",
434 "Bad commit: %s", sha1_to_hex(old_rev_sha1)); 434 "Bad commit: %s", oid_to_hex(old_rev_oid));
435 return; 435 return;
436 } 436 }
437 old_tree_sha1 = commit2->tree->object.oid.hash; 437 old_tree_sha1 = commit2->tree->object.oid.hash;
@@ -479,7 +479,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
479 if (difftype == DIFF_STATONLY) 479 if (difftype == DIFF_STATONLY)
480 ctx.qry.difftype = ctx.cfg.difftype; 480 ctx.qry.difftype = ctx.cfg.difftype;
481 481
482 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); 482 cgit_print_diffstat(old_rev_oid, new_rev_oid, prefix);
483 483
484 if (difftype == DIFF_STATONLY) 484 if (difftype == DIFF_STATONLY)
485 return; 485 return;
@@ -490,7 +490,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
490 html("<table summary='diff' class='diff'>"); 490 html("<table summary='diff' class='diff'>");
491 html("<tr><td>"); 491 html("<tr><td>");
492 } 492 }
493 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix, 493 cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix,
494 ctx.qry.ignorews); 494 ctx.qry.ignorews);
495 if (!use_ssdiff) 495 if (!use_ssdiff)
496 html("</td></tr>"); 496 html("</td></tr>");