|
diff --git a/ui-diff.c b/ui-diff.c index 4695e3a..0be845f 100644 --- a/ ui-diff.c+++ b/ ui-diff.c |
|
@@ -89,54 +89,52 @@ static void filepair_cb(struct diff_filepair *pair) |
89 | cgit_print_error("Error running diff"); |
89 | cgit_print_error("Error running diff"); |
90 | } |
90 | } |
91 | |
91 | |
92 | void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) |
92 | void cgit_print_diff(const char *new_rev, const char *old_rev) |
93 | { |
93 | { |
94 | unsigned char sha1[20], sha2[20]; |
94 | unsigned char sha1[20], sha2[20]; |
95 | enum object_type type; |
95 | enum object_type type; |
96 | unsigned long size; |
96 | unsigned long size; |
97 | struct commit *commit; |
97 | struct commit *commit, *commit2; |
98 | |
98 | |
99 | if (head && !old_hex && !new_hex) { |
99 | if (!new_rev) |
100 | get_sha1(head, sha1); |
100 | new_rev = cgit_query_head; |
101 | commit = lookup_commit_reference(sha1); |
101 | get_sha1(new_rev, sha1); |
102 | if (commit && !parse_commit(commit)) { |
102 | type = sha1_object_info(sha1, &size); |
103 | html("<table class='diff'>"); |
103 | if (type == OBJ_BAD) { |
104 | html("<tr><td>"); |
104 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
105 | cgit_diff_commit(commit, filepair_cb); |
105 | return; |
106 | html("</td></tr>"); |
106 | } |
107 | html("</table>"); |
107 | if (type != OBJ_COMMIT) { |
108 | } |
108 | cgit_print_error(fmt("Unhandled object type: %s", |
| |
109 | typename(type))); |
109 | return; |
110 | return; |
110 | } |
111 | } |
111 | |
112 | |
112 | get_sha1(old_hex, sha1); |
113 | commit = lookup_commit_reference(sha1); |
113 | get_sha1(new_hex, sha2); |
114 | if (!commit || parse_commit(commit)) |
| |
115 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha1))); |
114 | |
116 | |
115 | type = sha1_object_info(sha1, &size); |
117 | if (old_rev) |
116 | if (type == OBJ_BAD) { |
118 | get_sha1(old_rev, sha2); |
| |
119 | else if (commit->parents && commit->parents->item) |
| |
120 | hashcpy(sha2, commit->parents->item->object.sha1); |
| |
121 | else |
| |
122 | hashclr(sha2); |
| |
123 | |
| |
124 | if (!is_null_sha1(sha2)) { |
117 | type = sha1_object_info(sha2, &size); |
125 | type = sha1_object_info(sha2, &size); |
118 | if (type == OBJ_BAD) { |
126 | if (type == OBJ_BAD) { |
119 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
127 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(sha2))); |
120 | return; |
128 | return; |
121 | } |
129 | } |
| |
130 | commit2 = lookup_commit_reference(sha2); |
| |
131 | if (!commit2 || parse_commit(commit2)) |
| |
132 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha2))); |
122 | } |
133 | } |
123 | |
134 | |
124 | html("<table class='diff'>"); |
135 | html("<table class='diff'>"); |
125 | switch(type) { |
136 | html("<tr><td>"); |
126 | case OBJ_BLOB: |
137 | cgit_diff_tree(sha2, sha1, filepair_cb); |
127 | html("<tr><td>"); |
138 | html("</td></tr>"); |
128 | header(sha1, path, 0644, sha2, path, 0644); |
| |
129 | if (cgit_diff_files(sha1, sha2, print_line)) |
| |
130 | cgit_print_error("Error running diff"); |
| |
131 | html("</td></tr>"); |
| |
132 | break; |
| |
133 | case OBJ_TREE: |
| |
134 | cgit_diff_tree(sha1, sha2, filepair_cb); |
| |
135 | break; |
| |
136 | default: |
| |
137 | cgit_print_error(fmt("Unhandled object type: %s", |
| |
138 | typename(type))); |
| |
139 | break; |
| |
140 | } |
| |
141 | html("</table>"); |
139 | html("</table>"); |
142 | } |
140 | } |
|