]>
git.cameronkatri.com Git - cgit.git/blob - ui-diff.c
afe1c90505ade9e52b9e89b92eb39efcd560a26d
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 header(unsigned char *sha1
, char *path1
,
35 unsigned char *sha2
, char *path2
)
37 char *abbrev1
, *abbrev2
;
38 if (is_null_sha1(sha1
))
40 if (is_null_sha1(sha2
))
43 html("<div class='head'>");
44 html("diff --git a/");
48 abbrev1
= xstrdup(find_unique_abbrev(sha1
, DEFAULT_ABBREV
));
49 abbrev2
= xstrdup(find_unique_abbrev(sha2
, DEFAULT_ABBREV
));
50 htmlf("\nindex %s..%s", abbrev1
, abbrev2
);
60 static void filepair_cb(struct diff_filepair
*pair
)
62 header(pair
->one
->sha1
, pair
->one
->path
,
63 pair
->two
->sha1
, pair
->two
->path
);
64 if (cgit_diff_files(pair
->one
->sha1
, pair
->two
->sha1
, print_line
))
65 cgit_print_error("Error running diff");
69 void cgit_print_diff(const char *head
, const char *old_hex
, const char *new_hex
, char *path
)
71 unsigned char sha1
[20], sha2
[20];
72 enum object_type type
;
74 struct commit
*commit
;
76 if (head
&& !old_hex
&& !new_hex
) {
78 commit
= lookup_commit_reference(sha1
);
79 if (commit
&& !parse_commit(commit
)) {
80 html("<table class='diff'>");
81 cgit_diff_commit(commit
, filepair_cb
);
82 html("</td></tr></table>");
87 get_sha1(old_hex
, sha1
);
88 get_sha1(new_hex
, sha2
);
90 type
= sha1_object_info(sha1
, &size
);
91 if (type
== OBJ_BAD
) {
92 type
= sha1_object_info(sha2
, &size
);
93 if (type
== OBJ_BAD
) {
94 cgit_print_error(fmt("Bad object names: %s, %s", old_hex
, new_hex
));
99 html("<table class='diff'>");
103 header(sha1
, path
, sha2
, path
);
104 if (cgit_diff_files(sha1
, sha2
, print_line
))
105 cgit_print_error("Error running diff");
109 cgit_diff_tree(sha1
, sha2
, filepair_cb
);
112 cgit_print_error(fmt("Unhandled object type: %s",
116 html("</td></tr></table>");