summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-05-15 22:58:35 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-15 22:58:35 (UTC)
commitf9ff7df613b4ee86fe5914c4ae3400650882c03d (patch) (unidiff)
treec26fde3a4d3485943c275232f18359bebd133f1a
parenta2ddc10479ec463708e422ca5ce7ec02c22a7d02 (diff)
downloadcgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.zip
cgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.tar.gz
cgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.tar.bz2
Add support for commitdiff via h parameter
The commitdiff will be generated against the first parent, and the diff page also gets the benefit of repo.defbranch. Cleaned up some bad whitespace in cgit.h while at it. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h3
-rw-r--r--ui-diff.c14
3 files changed, 17 insertions, 3 deletions
diff --git a/cgit.c b/cgit.c
index 9b4815d..3e7e595 100644
--- a/cgit.c
+++ b/cgit.c
@@ -115,17 +115,18 @@ static void cgit_print_repo_page(struct cacheitem *item)
115 cgit_query_path); 115 cgit_query_path);
116 } else if (!strcmp(cgit_query_page, "tree")) { 116 } else if (!strcmp(cgit_query_page, "tree")) {
117 cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); 117 cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path);
118 } else if (!strcmp(cgit_query_page, "commit")) { 118 } else if (!strcmp(cgit_query_page, "commit")) {
119 cgit_print_commit(cgit_query_head); 119 cgit_print_commit(cgit_query_head);
120 } else if (!strcmp(cgit_query_page, "view")) { 120 } else if (!strcmp(cgit_query_page, "view")) {
121 cgit_print_view(cgit_query_sha1, cgit_query_path); 121 cgit_print_view(cgit_query_sha1, cgit_query_path);
122 } else if (!strcmp(cgit_query_page, "diff")) { 122 } else if (!strcmp(cgit_query_page, "diff")) {
123 cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); 123 cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2,
124 cgit_query_path);
124 } else { 125 } else {
125 cgit_print_error("Invalid request"); 126 cgit_print_error("Invalid request");
126 } 127 }
127 cgit_print_docend(); 128 cgit_print_docend();
128} 129}
129 130
130static void cgit_fill_cache(struct cacheitem *item, int use_cache) 131static void cgit_fill_cache(struct cacheitem *item, int use_cache)
131{ 132{
diff --git a/cgit.h b/cgit.h
index ac710a6..764225d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -171,14 +171,15 @@ extern void cgit_print_snapshot_start(const char *mimetype,
171 171
172extern void cgit_print_repolist(struct cacheitem *item); 172extern void cgit_print_repolist(struct cacheitem *item);
173extern void cgit_print_summary(); 173extern void cgit_print_summary();
174extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); 174extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path);
175extern void cgit_print_view(const char *hex, char *path); 175extern void cgit_print_view(const char *hex, char *path);
176extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 176extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
177extern void cgit_print_tree(const char *rev, const char *hex, char *path); 177extern void cgit_print_tree(const char *rev, const char *hex, char *path);
178extern void cgit_print_commit(const char *hex); 178extern void cgit_print_commit(const char *hex);
179extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); 179extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex,
180 char *path);
180extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 181extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
181 const char *format, const char *prefix, 182 const char *format, const char *prefix,
182 const char *filename); 183 const char *filename);
183 184
184#endif /* CGIT_H */ 185#endif /* CGIT_H */
diff --git a/ui-diff.c b/ui-diff.c
index 999b6f3..afe1c90 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -61,21 +61,33 @@ static void filepair_cb(struct diff_filepair *pair)
61{ 61{
62 header(pair->one->sha1, pair->one->path, 62 header(pair->one->sha1, pair->one->path,
63 pair->two->sha1, pair->two->path); 63 pair->two->sha1, pair->two->path);
64 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) 64 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
65 cgit_print_error("Error running diff"); 65 cgit_print_error("Error running diff");
66 html("</tr></td>"); 66 html("</tr></td>");
67} 67}
68 68
69void cgit_print_diff(const char *old_hex, const char *new_hex, char *path) 69void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path)
70{ 70{
71 unsigned char sha1[20], sha2[20]; 71 unsigned char sha1[20], sha2[20];
72 enum object_type type; 72 enum object_type type;
73 unsigned long size; 73 unsigned long size;
74 struct commit *commit;
75
76 if (head && !old_hex && !new_hex) {
77 get_sha1(head, sha1);
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>");
83 }
84 return;
85 }
74 86
75 get_sha1(old_hex, sha1); 87 get_sha1(old_hex, sha1);
76 get_sha1(new_hex, sha2); 88 get_sha1(new_hex, sha2);
77 89
78 type = sha1_object_info(sha1, &size); 90 type = sha1_object_info(sha1, &size);
79 if (type == OBJ_BAD) { 91 if (type == OBJ_BAD) {
80 type = sha1_object_info(sha2, &size); 92 type = sha1_object_info(sha2, &size);
81 if (type == OBJ_BAD) { 93 if (type == OBJ_BAD) {