summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-10-01 10:30:29 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-01 10:30:29 (UTC)
commite238ebe1874e07865b3f38fe8e256e91a6f734a4 (patch) (unidiff)
treea22a48fb5436f99b61a5769f199054db1c0bcacb
parent97aec64973d572ec98af19383f7fbb8d54bf674e (diff)
downloadcgit-e238ebe1874e07865b3f38fe8e256e91a6f734a4.zip
cgit-e238ebe1874e07865b3f38fe8e256e91a6f734a4.tar.gz
cgit-e238ebe1874e07865b3f38fe8e256e91a6f734a4.tar.bz2
ui-diff: add links to pre- and postversion of blobs
Each diff header now links to the old and new version of each file Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-diff.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/ui-diff.c b/ui-diff.c
index ba0030f..ac9a3fa 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -1,23 +1,26 @@
1/* ui-diff.c: show diff between two blobs 1/* ui-diff.c: show diff between two blobs
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11 11
12unsigned char old_rev_sha1[20];
13unsigned 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 */
15static void print_line(char *line, int len) 18static void print_line(char *line, int len)
16{ 19{
17 char *class = "ctx"; 20 char *class = "ctx";
18 char c = line[len-1]; 21 char c = line[len-1];
19 22
20 if (line[0] == '+') 23 if (line[0] == '+')
21 class = "add"; 24 class = "add";
22 else if (line[0] == '-') 25 else if (line[0] == '-')
23 class = "del"; 26 class = "del";
@@ -58,82 +61,89 @@ static void header(unsigned char *sha1, char *path1, int mode1,
58 if (!subproject) { 61 if (!subproject) {
59 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); 62 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
60 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); 63 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
61 htmlf("<br/>index %s..%s", abbrev1, abbrev2); 64 htmlf("<br/>index %s..%s", abbrev1, abbrev2);
62 free(abbrev1); 65 free(abbrev1);
63 free(abbrev2); 66 free(abbrev2);
64 if (mode1 != 0 && mode2 != 0) { 67 if (mode1 != 0 && mode2 != 0) {
65 htmlf(" %.6o", mode1); 68 htmlf(" %.6o", mode1);
66 if (mode2 != mode1) 69 if (mode2 != 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}
76 87
77static void filepair_cb(struct diff_filepair *pair) 88static void filepair_cb(struct diff_filepair *pair)
78{ 89{
79 header(pair->one->sha1, pair->one->path, pair->one->mode, 90 header(pair->one->sha1, pair->one->path, pair->one->mode,
80 pair->two->sha1, pair->two->path, pair->two->mode); 91 pair->two->sha1, pair->two->path, pair->two->mode);
81 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 92 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
82 if (S_ISGITLINK(pair->one->mode)) 93 if (S_ISGITLINK(pair->one->mode))
83 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 94 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
84 if (S_ISGITLINK(pair->two->mode)) 95 if (S_ISGITLINK(pair->two->mode))
85 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 96 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
86 return; 97 return;
87 } 98 }
88 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) 99 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
89 cgit_print_error("Error running diff"); 100 cgit_print_error("Error running diff");
90} 101}
91 102
92void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 103void 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;
106 } 116 }
107 if (type != OBJ_COMMIT) { 117 if (type != OBJ_COMMIT) {
108 cgit_print_error(fmt("Unhandled object type: %s", 118 cgit_print_error(fmt("Unhandled object type: %s",
109 typename(type))); 119 typename(type)));
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}