diff options
-rw-r--r-- | ui-diff.c | 42 |
1 files changed, 26 insertions, 16 deletions
@@ -9,6 +9,9 @@ | |||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | 11 | ||
12 | unsigned char old_rev_sha1[20]; | ||
13 | unsigned char new_rev_sha1[20]; | ||
14 | |||
12 | /* | 15 | /* |
13 | * print a single line returned from xdiff | 16 | * print a single line returned from xdiff |
14 | */ | 17 | */ |
@@ -67,9 +70,17 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
67 | htmlf("..%.6o", mode2); | 70 | htmlf("..%.6o", mode2); |
68 | } | 71 | } |
69 | html("<br/>--- a/"); | 72 | html("<br/>--- a/"); |
70 | html_txt(path1); | 73 | if (mode1 != 0) |
74 | cgit_tree_link(path1, NULL, NULL, cgit_query_head, | ||
75 | sha1_to_hex(old_rev_sha1), path1); | ||
76 | else | ||
77 | html_txt(path1); | ||
71 | html("<br/>+++ b/"); | 78 | html("<br/>+++ b/"); |
72 | html_txt(path2); | 79 | if (mode2 != 0) |
80 | cgit_tree_link(path2, NULL, NULL, cgit_query_head, | ||
81 | sha1_to_hex(new_rev_sha1), path2); | ||
82 | else | ||
83 | html_txt(path2); | ||
73 | } | 84 | } |
74 | html("</div>"); | 85 | html("</div>"); |
75 | } | 86 | } |
@@ -91,15 +102,14 @@ static void filepair_cb(struct diff_filepair *pair) | |||
91 | 102 | ||
92 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 103 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
93 | { | 104 | { |
94 | unsigned char sha1[20], sha2[20]; | ||
95 | enum object_type type; | 105 | enum object_type type; |
96 | unsigned long size; | 106 | unsigned long size; |
97 | struct commit *commit, *commit2; | 107 | struct commit *commit, *commit2; |
98 | 108 | ||
99 | if (!new_rev) | 109 | if (!new_rev) |
100 | new_rev = cgit_query_head; | 110 | new_rev = cgit_query_head; |
101 | get_sha1(new_rev, sha1); | 111 | get_sha1(new_rev, new_rev_sha1); |
102 | type = sha1_object_info(sha1, &size); | 112 | type = sha1_object_info(new_rev_sha1, &size); |
103 | if (type == OBJ_BAD) { | 113 | if (type == OBJ_BAD) { |
104 | cgit_print_error(fmt("Bad object name: %s", new_rev)); | 114 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
105 | return; | 115 | return; |
@@ -110,30 +120,30 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
110 | return; | 120 | return; |
111 | } | 121 | } |
112 | 122 | ||
113 | commit = lookup_commit_reference(sha1); | 123 | commit = lookup_commit_reference(new_rev_sha1); |
114 | if (!commit || parse_commit(commit)) | 124 | if (!commit || parse_commit(commit)) |
115 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha1))); | 125 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
116 | 126 | ||
117 | if (old_rev) | 127 | if (old_rev) |
118 | get_sha1(old_rev, sha2); | 128 | get_sha1(old_rev, old_rev_sha1); |
119 | else if (commit->parents && commit->parents->item) | 129 | else if (commit->parents && commit->parents->item) |
120 | hashcpy(sha2, commit->parents->item->object.sha1); | 130 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
121 | else | 131 | else |
122 | hashclr(sha2); | 132 | hashclr(old_rev_sha1); |
123 | 133 | ||
124 | if (!is_null_sha1(sha2)) { | 134 | if (!is_null_sha1(old_rev_sha1)) { |
125 | type = sha1_object_info(sha2, &size); | 135 | type = sha1_object_info(old_rev_sha1, &size); |
126 | if (type == OBJ_BAD) { | 136 | if (type == OBJ_BAD) { |
127 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(sha2))); | 137 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
128 | return; | 138 | return; |
129 | } | 139 | } |
130 | commit2 = lookup_commit_reference(sha2); | 140 | commit2 = lookup_commit_reference(old_rev_sha1); |
131 | if (!commit2 || parse_commit(commit2)) | 141 | if (!commit2 || parse_commit(commit2)) |
132 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha2))); | 142 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
133 | } | 143 | } |
134 | html("<table class='diff'>"); | 144 | html("<table class='diff'>"); |
135 | html("<tr><td>"); | 145 | html("<tr><td>"); |
136 | cgit_diff_tree(sha2, sha1, filepair_cb, prefix); | 146 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
137 | html("</td></tr>"); | 147 | html("</td></tr>"); |
138 | html("</table>"); | 148 | html("</table>"); |
139 | } | 149 | } |