1 /* ui-diff.c: show diff between two blobs
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
13 * print a single line returned from xdiff
15 static void print_line(char *line, int len)
22 else if (line[0] == '-')
24 else if (line[0] == '@')
27 htmlf("<div class='%s'>", class);
34 static void filepair_cb(struct diff_filepair *pair)
37 html_txt(pair->two->path);
40 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
41 cgit_print_error("Error running diff");
45 void cgit_print_diff(const char *old_hex, const char *new_hex, char *path)
47 unsigned char sha1[20], sha2[20];
48 enum object_type type;
51 get_sha1(old_hex, sha1);
52 get_sha1(new_hex, sha2);
54 type = sha1_object_info(sha1, &size);
55 if (type == OBJ_BAD) {
56 type = sha1_object_info(sha2, &size);
57 if (type == OBJ_BAD) {
58 cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex));
63 html("<table class='diff'>");
67 htmlf("<tr><th>%s</th></tr>", path);
69 if (cgit_diff_files(sha1, sha2, print_line))
70 cgit_print_error("Error running diff");
74 cgit_diff_tree(sha1, sha2, filepair_cb);
77 cgit_print_error(fmt("Unhandled object type: %s",
81 html("</td></tr></table>");