summaryrefslogtreecommitdiffabout
path: root/ui-diff.c
authorLars Hjemli <hjemli@gmail.com>2007-06-17 16:12:03 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-06-17 16:12:03 (UTC)
commit4a0be586662843382ecfa53af34a13b291312bc0 (patch) (unidiff)
tree01e0cd725fe249df3449bb089aad9f8d58081f89 /ui-diff.c
parentfaaca447b071592c9a1e1f14b4d0d2a39b4c795a (diff)
downloadcgit-4a0be586662843382ecfa53af34a13b291312bc0.zip
cgit-4a0be586662843382ecfa53af34a13b291312bc0.tar.gz
cgit-4a0be586662843382ecfa53af34a13b291312bc0.tar.bz2
Add cgit_diff_link()
This adds a new function used to generate links to the diff page and uses it everywhere such links appear (expect for single files in the diffstat displayed on the commit page: this is now a link to the tree page). The updated diff-page now expects zero, one or two revision specifiers, in parameters head, id and id2. Id defaults to head unless otherwise specified, while head (as usual) defaults to repo.defbranch. If id2 isn't specified, it defaults to the first parent of id1. The most important change is of course that now all repo pages (summary, log, tree, commit and diff) has support for passing on the current branch and revision, i.e. the road is now open for a 'static' menu with links to all of these pages. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-diff.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-diff.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 5c864d9..a76a234 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
92void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) 92void 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 html("<table class='diff'>"); 99 if (!new_rev)
100 html("<tr><td>"); 100 new_rev = cgit_query_head;
101 101 get_sha1(new_rev, sha1);
102 if (head && !old_hex && !new_hex) { 102 type = sha1_object_info(sha1, &size);
103 get_sha1(head, sha1); 103 if (type == OBJ_BAD) {
104 commit = lookup_commit_reference(sha1); 104 cgit_print_error(fmt("Bad object name: %s", new_rev));
105 if (commit && !parse_commit(commit)) 105 return;
106 cgit_diff_commit(commit, filepair_cb); 106 }
107 else 107 if (type != OBJ_COMMIT) {
108 cgit_print_error(fmt("Bad commit: %s", head)); 108 cgit_print_error(fmt("Unhandled object type: %s",
109 html("</td></tr>"); 109 typename(type)));
110 html("</table>");
111 return; 110 return;
112 } 111 }
113 112
114 get_sha1(old_hex, sha1); 113 commit = lookup_commit_reference(sha1);
115 get_sha1(new_hex, sha2); 114 if (!commit || parse_commit(commit))
115 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha1)));
116 116
117 type = sha1_object_info(sha1, &size); 117 if (old_rev)
118 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)) {
119 type = sha1_object_info(sha2, &size); 125 type = sha1_object_info(sha2, &size);
120 if (type == OBJ_BAD) { 126 if (type == OBJ_BAD) {
121 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)));
122 return; 128 return;
123 } 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)));
124 } 133 }
125 134
126 switch(type) { 135 html("<table class='diff'>");
127 case OBJ_BLOB: 136 html("<tr><td>");
128 header(sha1, path, 0644, sha2, path, 0644); 137 cgit_diff_tree(sha2, sha1, filepair_cb);
129 if (cgit_diff_files(sha1, sha2, print_line))
130 cgit_print_error("Error running diff");
131 break;
132 case OBJ_TREE:
133 cgit_diff_tree(sha1, sha2, filepair_cb);
134 break;
135 default:
136 cgit_print_error(fmt("Unhandled object type: %s",
137 typename(type)));
138 break;
139 }
140 html("</td></tr>"); 138 html("</td></tr>");
141 html("</table>"); 139 html("</table>");
142} 140}