summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-commit.c8
-rw-r--r--ui-log.c4
-rw-r--r--ui-shared.c4
-rw-r--r--ui-summary.c2
-rw-r--r--ui-tree.c6
-rw-r--r--ui-view.c2
6 files changed, 13 insertions, 13 deletions
diff --git a/ui-commit.c b/ui-commit.c
index 6b135aa..1d12bbb 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -30,97 +30,97 @@ void print_fileinfo(struct fileinfo *info)
30 char *query, *query2; 30 char *query, *query2;
31 char *class; 31 char *class;
32 32
33 switch (info->status) { 33 switch (info->status) {
34 case DIFF_STATUS_ADDED: 34 case DIFF_STATUS_ADDED:
35 class = "add"; 35 class = "add";
36 break; 36 break;
37 case DIFF_STATUS_COPIED: 37 case DIFF_STATUS_COPIED:
38 class = "cpy"; 38 class = "cpy";
39 break; 39 break;
40 case DIFF_STATUS_DELETED: 40 case DIFF_STATUS_DELETED:
41 class = "del"; 41 class = "del";
42 break; 42 break;
43 case DIFF_STATUS_MODIFIED: 43 case DIFF_STATUS_MODIFIED:
44 class = "upd"; 44 class = "upd";
45 break; 45 break;
46 case DIFF_STATUS_RENAMED: 46 case DIFF_STATUS_RENAMED:
47 class = "mov"; 47 class = "mov";
48 break; 48 break;
49 case DIFF_STATUS_TYPE_CHANGED: 49 case DIFF_STATUS_TYPE_CHANGED:
50 class = "typ"; 50 class = "typ";
51 break; 51 break;
52 case DIFF_STATUS_UNKNOWN: 52 case DIFF_STATUS_UNKNOWN:
53 class = "unk"; 53 class = "unk";
54 break; 54 break;
55 case DIFF_STATUS_UNMERGED: 55 case DIFF_STATUS_UNMERGED:
56 class = "stg"; 56 class = "stg";
57 break; 57 break;
58 default: 58 default:
59 die("bug: unhandled diff status %c", info->status); 59 die("bug: unhandled diff status %c", info->status);
60 } 60 }
61 61
62 html("<tr>"); 62 html("<tr>");
63 htmlf("<td class='mode'>"); 63 htmlf("<td class='mode'>");
64 if (is_null_sha1(info->new_sha1)) { 64 if (is_null_sha1(info->new_sha1)) {
65 html_filemode(info->old_mode); 65 html_filemode(info->old_mode);
66 } else { 66 } else {
67 html_filemode(info->new_mode); 67 html_filemode(info->new_mode);
68 } 68 }
69 69
70 if (info->old_mode != info->new_mode && 70 if (info->old_mode != info->new_mode &&
71 !is_null_sha1(info->old_sha1) && 71 !is_null_sha1(info->old_sha1) &&
72 !is_null_sha1(info->new_sha1)) { 72 !is_null_sha1(info->new_sha1)) {
73 html("<span class='modechange'>["); 73 html("<span class='modechange'>[");
74 html_filemode(info->old_mode); 74 html_filemode(info->old_mode);
75 html("]</span>"); 75 html("]</span>");
76 } 76 }
77 htmlf("</td><td class='%s'>", class); 77 htmlf("</td><td class='%s'>", class);
78 query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), 78 query = fmt("id=%s&amp;id2=%s&amp;path=%s", sha1_to_hex(info->old_sha1),
79 sha1_to_hex(info->new_sha1), info->new_path); 79 sha1_to_hex(info->new_sha1), info->new_path);
80 html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), 80 html_link_open(cgit_pageurl(cgit_query_repo, "diff", query),
81 NULL, NULL); 81 NULL, NULL);
82 if (info->status == DIFF_STATUS_COPIED || 82 if (info->status == DIFF_STATUS_COPIED ||
83 info->status == DIFF_STATUS_RENAMED) { 83 info->status == DIFF_STATUS_RENAMED) {
84 html_txt(info->new_path); 84 html_txt(info->new_path);
85 htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ? 85 htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ?
86 "copied" : "renamed"); 86 "copied" : "renamed");
87 query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); 87 query2 = fmt("id=%s", sha1_to_hex(info->old_sha1));
88 html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), 88 html_link_open(cgit_pageurl(cgit_query_repo, "view", query2),
89 NULL, NULL); 89 NULL, NULL);
90 html_txt(info->old_path); 90 html_txt(info->old_path);
91 html("</a>)"); 91 html("</a>)");
92 } else { 92 } else {
93 html_txt(info->new_path); 93 html_txt(info->new_path);
94 html("</a>"); 94 html("</a>");
95 } 95 }
96 html("</td><td class='right'>"); 96 html("</td><td class='right'>");
97 htmlf("%d", info->added + info->removed); 97 htmlf("%d", info->added + info->removed);
98 html("</td><td class='graph'>"); 98 html("</td><td class='graph'>");
99 htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); 99 htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
100 htmlf("<td class='add' style='width: %.1f%%;'/>", 100 htmlf("<td class='add' style='width: %.1f%%;'/>",
101 info->added * 100.0 / max_changes); 101 info->added * 100.0 / max_changes);
102 htmlf("<td class='rem' style='width: %.1f%%;'/>", 102 htmlf("<td class='rem' style='width: %.1f%%;'/>",
103 info->removed * 100.0 / max_changes); 103 info->removed * 100.0 / max_changes);
104 htmlf("<td class='none' style='width: %.1f%%;'/>", 104 htmlf("<td class='none' style='width: %.1f%%;'/>",
105 (max_changes - info->removed - info->added) * 100.0 / max_changes); 105 (max_changes - info->removed - info->added) * 100.0 / max_changes);
106 html("</tr></table></td></tr>\n"); 106 html("</tr></table></td></tr>\n");
107} 107}
108 108
109void cgit_count_diff_lines(char *line, int len) 109void cgit_count_diff_lines(char *line, int len)
110{ 110{
111 if (line && (len > 0)) { 111 if (line && (len > 0)) {
112 if (line[0] == '+') 112 if (line[0] == '+')
113 lines_added++; 113 lines_added++;
114 else if (line[0] == '-') 114 else if (line[0] == '-')
115 lines_removed++; 115 lines_removed++;
116 } 116 }
117} 117}
118 118
119void inspect_filepair(struct diff_filepair *pair) 119void inspect_filepair(struct diff_filepair *pair)
120{ 120{
121 files++; 121 files++;
122 lines_added = 0; 122 lines_added = 0;
123 lines_removed = 0; 123 lines_removed = 0;
124 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); 124 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines);
125 if (files >= slots) { 125 if (files >= slots) {
126 if (slots == 0) 126 if (slots == 0)
@@ -137,104 +137,104 @@ void inspect_filepair(struct diff_filepair *pair)
137 items[files-1].old_path = xstrdup(pair->one->path); 137 items[files-1].old_path = xstrdup(pair->one->path);
138 items[files-1].new_path = xstrdup(pair->two->path); 138 items[files-1].new_path = xstrdup(pair->two->path);
139 items[files-1].added = lines_added; 139 items[files-1].added = lines_added;
140 items[files-1].removed = lines_removed; 140 items[files-1].removed = lines_removed;
141 if (lines_added + lines_removed > max_changes) 141 if (lines_added + lines_removed > max_changes)
142 max_changes = lines_added + lines_removed; 142 max_changes = lines_added + lines_removed;
143 total_adds += lines_added; 143 total_adds += lines_added;
144 total_rems += lines_removed; 144 total_rems += lines_removed;
145} 145}
146 146
147 147
148void cgit_print_commit(const char *hex) 148void cgit_print_commit(const char *hex)
149{ 149{
150 struct commit *commit, *parent; 150 struct commit *commit, *parent;
151 struct commitinfo *info; 151 struct commitinfo *info;
152 struct commit_list *p; 152 struct commit_list *p;
153 unsigned char sha1[20]; 153 unsigned char sha1[20];
154 char *query; 154 char *query;
155 char *filename; 155 char *filename;
156 int i; 156 int i;
157 157
158 if (get_sha1(hex, sha1)) { 158 if (get_sha1(hex, sha1)) {
159 cgit_print_error(fmt("Bad object id: %s", hex)); 159 cgit_print_error(fmt("Bad object id: %s", hex));
160 return; 160 return;
161 } 161 }
162 commit = lookup_commit_reference(sha1); 162 commit = lookup_commit_reference(sha1);
163 if (!commit) { 163 if (!commit) {
164 cgit_print_error(fmt("Bad commit reference: %s", hex)); 164 cgit_print_error(fmt("Bad commit reference: %s", hex));
165 return; 165 return;
166 } 166 }
167 info = cgit_parse_commit(commit); 167 info = cgit_parse_commit(commit);
168 168
169 html("<table class='commit-info'>\n"); 169 html("<table class='commit-info'>\n");
170 html("<tr><th>author</th><td>"); 170 html("<tr><th>author</th><td>");
171 html_txt(info->author); 171 html_txt(info->author);
172 html(" "); 172 html(" ");
173 html_txt(info->author_email); 173 html_txt(info->author_email);
174 html("</td><td class='right'>"); 174 html("</td><td class='right'>");
175 cgit_print_date(info->author_date, FMT_LONGDATE); 175 cgit_print_date(info->author_date, FMT_LONGDATE);
176 html("</td></tr>\n"); 176 html("</td></tr>\n");
177 html("<tr><th>committer</th><td>"); 177 html("<tr><th>committer</th><td>");
178 html_txt(info->committer); 178 html_txt(info->committer);
179 html(" "); 179 html(" ");
180 html_txt(info->committer_email); 180 html_txt(info->committer_email);
181 html("</td><td class='right'>"); 181 html("</td><td class='right'>");
182 cgit_print_date(info->committer_date, FMT_LONGDATE); 182 cgit_print_date(info->committer_date, FMT_LONGDATE);
183 html("</td></tr>\n"); 183 html("</td></tr>\n");
184 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); 184 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
185 query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), 185 query = fmt("h=%s&amp;id=%s", sha1_to_hex(commit->object.sha1),
186 sha1_to_hex(commit->tree->object.sha1)); 186 sha1_to_hex(commit->tree->object.sha1));
187 html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); 187 html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
188 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); 188 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
189 for (p = commit->parents; p ; p = p->next) { 189 for (p = commit->parents; p ; p = p->next) {
190 parent = lookup_commit_reference(p->item->object.sha1); 190 parent = lookup_commit_reference(p->item->object.sha1);
191 if (!parent) { 191 if (!parent) {
192 html("<tr><td colspan='3'>"); 192 html("<tr><td colspan='3'>");
193 cgit_print_error("Error reading parent commit"); 193 cgit_print_error("Error reading parent commit");
194 html("</td></tr>"); 194 html("</td></tr>");
195 continue; 195 continue;
196 } 196 }
197 html("<tr><th>parent</th>" 197 html("<tr><th>parent</th>"
198 "<td colspan='2' class='sha1'>" 198 "<td colspan='2' class='sha1'>"
199 "<a href='"); 199 "<a href='");
200 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); 200 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1));
201 html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); 201 html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
202 htmlf("'>%s</a> (<a href='", 202 htmlf("'>%s</a> (<a href='",
203 sha1_to_hex(p->item->object.sha1)); 203 sha1_to_hex(p->item->object.sha1));
204 query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), 204 query = fmt("id=%s&amp;id2=%s", sha1_to_hex(parent->tree->object.sha1),
205 sha1_to_hex(commit->tree->object.sha1)); 205 sha1_to_hex(commit->tree->object.sha1));
206 html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); 206 html_attr(cgit_pageurl(cgit_query_repo, "diff", query));
207 html("'>diff</a>)</td></tr>"); 207 html("'>diff</a>)</td></tr>");
208 } 208 }
209 if (cgit_repo->snapshots) { 209 if (cgit_repo->snapshots) {
210 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); 210 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
211 filename = fmt("%s-%s.zip", cgit_query_repo, hex); 211 filename = fmt("%s-%s.zip", cgit_query_repo, hex);
212 html_attr(cgit_pageurl(cgit_query_repo, "snapshot", 212 html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
213 fmt("id=%s&name=%s", hex, filename))); 213 fmt("id=%s&amp;name=%s", hex, filename)));
214 htmlf("'>%s</a></td></tr>", filename); 214 htmlf("'>%s</a></td></tr>", filename);
215 } 215 }
216 html("</table>\n"); 216 html("</table>\n");
217 html("<div class='commit-subject'>"); 217 html("<div class='commit-subject'>");
218 html_txt(info->subject); 218 html_txt(info->subject);
219 html("</div>"); 219 html("</div>");
220 html("<div class='commit-msg'>"); 220 html("<div class='commit-msg'>");
221 html_txt(info->msg); 221 html_txt(info->msg);
222 html("</div>"); 222 html("</div>");
223 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { 223 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) {
224 html("<div class='diffstat-header'>Diffstat</div>"); 224 html("<div class='diffstat-header'>Diffstat</div>");
225 html("<table class='diffstat'>"); 225 html("<table class='diffstat'>");
226 max_changes = 0; 226 max_changes = 0;
227 cgit_diff_commit(commit, inspect_filepair); 227 cgit_diff_commit(commit, inspect_filepair);
228 for(i = 0; i<files; i++) 228 for(i = 0; i<files; i++)
229 print_fileinfo(&items[i]); 229 print_fileinfo(&items[i]);
230 html("</table>"); 230 html("</table>");
231 html("<div class='diffstat-summary'>"); 231 html("<div class='diffstat-summary'>");
232 htmlf("%d files changed, %d insertions, %d deletions (", 232 htmlf("%d files changed, %d insertions, %d deletions (",
233 files, total_adds, total_rems); 233 files, total_adds, total_rems);
234 query = fmt("h=%s", hex); 234 query = fmt("h=%s", hex);
235 html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); 235 html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL);
236 html("show diff</a>)"); 236 html("show diff</a>)");
237 html("</div>"); 237 html("</div>");
238 } 238 }
239 cgit_free_commitinfo(info); 239 cgit_free_commitinfo(info);
240} 240}
diff --git a/ui-log.c b/ui-log.c
index c80fd73..75bbbe4 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -69,60 +69,60 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path)
69 argv[argc++] = path; 69 argv[argc++] = path;
70 } 70 }
71 init_revisions(&rev, NULL); 71 init_revisions(&rev, NULL);
72 rev.abbrev = DEFAULT_ABBREV; 72 rev.abbrev = DEFAULT_ABBREV;
73 rev.commit_format = CMIT_FMT_DEFAULT; 73 rev.commit_format = CMIT_FMT_DEFAULT;
74 rev.verbose_header = 1; 74 rev.verbose_header = 1;
75 rev.show_root_diff = 0; 75 rev.show_root_diff = 0;
76 setup_revisions(argc, argv, &rev, NULL); 76 setup_revisions(argc, argv, &rev, NULL);
77 if (rev.grep_filter) { 77 if (rev.grep_filter) {
78 rev.grep_filter->regflags |= REG_ICASE; 78 rev.grep_filter->regflags |= REG_ICASE;
79 compile_grep_patterns(rev.grep_filter); 79 compile_grep_patterns(rev.grep_filter);
80 } 80 }
81 prepare_revision_walk(&rev); 81 prepare_revision_walk(&rev);
82 82
83 html("<table class='list nowrap'>"); 83 html("<table class='list nowrap'>");
84 html("<tr class='nohover'><th class='left'>Age</th>" 84 html("<tr class='nohover'><th class='left'>Age</th>"
85 "<th class='left'>Message</th>"); 85 "<th class='left'>Message</th>");
86 86
87 if (cgit_repo->enable_log_filecount) { 87 if (cgit_repo->enable_log_filecount) {
88 html("<th class='left'>Files</th>"); 88 html("<th class='left'>Files</th>");
89 if (cgit_repo->enable_log_linecount) 89 if (cgit_repo->enable_log_linecount)
90 html("<th class='left'>Lines</th>"); 90 html("<th class='left'>Lines</th>");
91 } 91 }
92 html("<th class='left'>Author</th></tr>\n"); 92 html("<th class='left'>Author</th></tr>\n");
93 93
94 if (ofs<0) 94 if (ofs<0)
95 ofs = 0; 95 ofs = 0;
96 96
97 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 97 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
98 free(commit->buffer); 98 free(commit->buffer);
99 commit->buffer = NULL; 99 commit->buffer = NULL;
100 free_commit_list(commit->parents); 100 free_commit_list(commit->parents);
101 commit->parents = NULL; 101 commit->parents = NULL;
102 } 102 }
103 103
104 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 104 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
105 print_commit(commit); 105 print_commit(commit);
106 free(commit->buffer); 106 free(commit->buffer);
107 commit->buffer = NULL; 107 commit->buffer = NULL;
108 free_commit_list(commit->parents); 108 free_commit_list(commit->parents);
109 commit->parents = NULL; 109 commit->parents = NULL;
110 } 110 }
111 html("</table>\n"); 111 html("</table>\n");
112 112
113 html("<div class='pager'>"); 113 html("<div class='pager'>");
114 if (ofs > 0) { 114 if (ofs > 0) {
115 html("&nbsp;<a href='"); 115 html("&nbsp;<a href='");
116 html(cgit_pageurl(cgit_query_repo, cgit_query_page, 116 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
117 fmt("h=%s&ofs=%d", tip, ofs-cnt))); 117 fmt("h=%s&amp;ofs=%d", tip, ofs-cnt)));
118 html("'>[prev]</a>&nbsp;"); 118 html("'>[prev]</a>&nbsp;");
119 } 119 }
120 120
121 if ((commit = get_revision(&rev)) != NULL) { 121 if ((commit = get_revision(&rev)) != NULL) {
122 html("&nbsp;<a href='"); 122 html("&nbsp;<a href='");
123 html(cgit_pageurl(cgit_query_repo, "log", 123 html(cgit_pageurl(cgit_query_repo, "log",
124 fmt("h=%s&ofs=%d", tip, ofs+cnt))); 124 fmt("h=%s&amp;ofs=%d", tip, ofs+cnt)));
125 html("'>[next]</a>&nbsp;"); 125 html("'>[next]</a>&nbsp;");
126 } 126 }
127 html("</div>"); 127 html("</div>");
128} 128}
diff --git a/ui-shared.c b/ui-shared.c
index c8c1c21..aba93e8 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -24,99 +24,99 @@ static char *http_date(time_t t)
24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
25 tm->tm_hour, tm->tm_min, tm->tm_sec); 25 tm->tm_hour, tm->tm_min, tm->tm_sec);
26} 26}
27 27
28static long ttl_seconds(long ttl) 28static long ttl_seconds(long ttl)
29{ 29{
30 if (ttl<0) 30 if (ttl<0)
31 return 60 * 60 * 24 * 365; 31 return 60 * 60 * 24 * 365;
32 else 32 else
33 return ttl * 60; 33 return ttl * 60;
34} 34}
35 35
36void cgit_print_error(char *msg) 36void cgit_print_error(char *msg)
37{ 37{
38 html("<div class='error'>"); 38 html("<div class='error'>");
39 html_txt(msg); 39 html_txt(msg);
40 html("</div>\n"); 40 html("</div>\n");
41} 41}
42 42
43char *cgit_rooturl() 43char *cgit_rooturl()
44{ 44{
45 if (cgit_virtual_root) 45 if (cgit_virtual_root)
46 return fmt("%s/", cgit_virtual_root); 46 return fmt("%s/", cgit_virtual_root);
47 else 47 else
48 return cgit_script_name; 48 return cgit_script_name;
49} 49}
50 50
51char *cgit_repourl(const char *reponame) 51char *cgit_repourl(const char *reponame)
52{ 52{
53 if (cgit_virtual_root) { 53 if (cgit_virtual_root) {
54 return fmt("%s/%s/", cgit_virtual_root, reponame); 54 return fmt("%s/%s/", cgit_virtual_root, reponame);
55 } else { 55 } else {
56 return fmt("?r=%s", reponame); 56 return fmt("?r=%s", reponame);
57 } 57 }
58} 58}
59 59
60char *cgit_pageurl(const char *reponame, const char *pagename, 60char *cgit_pageurl(const char *reponame, const char *pagename,
61 const char *query) 61 const char *query)
62{ 62{
63 if (cgit_virtual_root) { 63 if (cgit_virtual_root) {
64 if (query) 64 if (query)
65 return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, 65 return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame,
66 pagename, query); 66 pagename, query);
67 else 67 else
68 return fmt("%s/%s/%s/", cgit_virtual_root, reponame, 68 return fmt("%s/%s/%s/", cgit_virtual_root, reponame,
69 pagename); 69 pagename);
70 } else { 70 } else {
71 if (query) 71 if (query)
72 return fmt("?r=%s&p=%s&%s", reponame, pagename, query); 72 return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
73 else 73 else
74 return fmt("?r=%s&p=%s", reponame, pagename); 74 return fmt("?r=%s&amp;p=%s", reponame, pagename);
75 } 75 }
76} 76}
77 77
78char *cgit_currurl() 78char *cgit_currurl()
79{ 79{
80 if (!cgit_virtual_root) 80 if (!cgit_virtual_root)
81 return cgit_script_name; 81 return cgit_script_name;
82 else if (cgit_query_page) 82 else if (cgit_query_page)
83 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); 83 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
84 else if (cgit_query_repo) 84 else if (cgit_query_repo)
85 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); 85 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
86 else 86 else
87 return fmt("%s/", cgit_virtual_root); 87 return fmt("%s/", cgit_virtual_root);
88} 88}
89 89
90 90
91void cgit_print_date(time_t secs, char *format) 91void cgit_print_date(time_t secs, char *format)
92{ 92{
93 char buf[64]; 93 char buf[64];
94 struct tm *time; 94 struct tm *time;
95 95
96 time = gmtime(&secs); 96 time = gmtime(&secs);
97 strftime(buf, sizeof(buf)-1, format, time); 97 strftime(buf, sizeof(buf)-1, format, time);
98 html_txt(buf); 98 html_txt(buf);
99} 99}
100 100
101void cgit_print_age(time_t t, time_t max_relative, char *format) 101void cgit_print_age(time_t t, time_t max_relative, char *format)
102{ 102{
103 time_t now, secs; 103 time_t now, secs;
104 104
105 time(&now); 105 time(&now);
106 secs = now - t; 106 secs = now - t;
107 107
108 if (secs > max_relative && max_relative >= 0) { 108 if (secs > max_relative && max_relative >= 0) {
109 cgit_print_date(t, format); 109 cgit_print_date(t, format);
110 return; 110 return;
111 } 111 }
112 112
113 if (secs < TM_HOUR * 2) { 113 if (secs < TM_HOUR * 2) {
114 htmlf("<span class='age-mins'>%.0f min.</span>", 114 htmlf("<span class='age-mins'>%.0f min.</span>",
115 secs * 1.0 / TM_MIN); 115 secs * 1.0 / TM_MIN);
116 return; 116 return;
117 } 117 }
118 if (secs < TM_DAY * 2) { 118 if (secs < TM_DAY * 2) {
119 htmlf("<span class='age-hours'>%.0f hours</span>", 119 htmlf("<span class='age-hours'>%.0f hours</span>",
120 secs * 1.0 / TM_HOUR); 120 secs * 1.0 / TM_HOUR);
121 return; 121 return;
122 } 122 }
diff --git a/ui-summary.c b/ui-summary.c
index 18608b8..15e8aec 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -114,97 +114,97 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
114 html(info->tagger); 114 html(info->tagger);
115 html("</td><td>"); 115 html("</td><td>");
116 cgit_print_object_ref(tag->tagged); 116 cgit_print_object_ref(tag->tagged);
117 html("</td></tr>\n"); 117 html("</td></tr>\n");
118 } else { 118 } else {
119 if (!header) 119 if (!header)
120 print_tag_header(); 120 print_tag_header();
121 html("<tr><td>"); 121 html("<tr><td>");
122 html_txt(buf); 122 html_txt(buf);
123 html("</td><td colspan='2'/><td>"); 123 html("</td><td colspan='2'/><td>");
124 cgit_print_object_ref(obj); 124 cgit_print_object_ref(obj);
125 html("</td></tr>\n"); 125 html("</td></tr>\n");
126 } 126 }
127 return 0; 127 return 0;
128} 128}
129 129
130static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, 130static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
131 int flags, void *cb_data) 131 int flags, void *cb_data)
132{ 132{
133 struct tag *tag; 133 struct tag *tag;
134 struct taginfo *info; 134 struct taginfo *info;
135 struct object *obj; 135 struct object *obj;
136 char buf[256], *url; 136 char buf[256], *url;
137 unsigned char fileid[20]; 137 unsigned char fileid[20];
138 138
139 if (prefixcmp(refname, "refs/archives")) 139 if (prefixcmp(refname, "refs/archives"))
140 return 0; 140 return 0;
141 strncpy(buf, refname+14, sizeof(buf)); 141 strncpy(buf, refname+14, sizeof(buf));
142 obj = parse_object(sha1); 142 obj = parse_object(sha1);
143 if (!obj) 143 if (!obj)
144 return 1; 144 return 1;
145 if (obj->type == OBJ_TAG) { 145 if (obj->type == OBJ_TAG) {
146 tag = lookup_tag(sha1); 146 tag = lookup_tag(sha1);
147 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 147 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
148 return 0; 148 return 0;
149 hashcpy(fileid, tag->tagged->sha1); 149 hashcpy(fileid, tag->tagged->sha1);
150 } else if (obj->type != OBJ_BLOB) { 150 } else if (obj->type != OBJ_BLOB) {
151 return 0; 151 return 0;
152 } else { 152 } else {
153 hashcpy(fileid, sha1); 153 hashcpy(fileid, sha1);
154 } 154 }
155 if (!header) { 155 if (!header) {
156 html("<table id='downloads'>"); 156 html("<table id='downloads'>");
157 html("<tr><th>Downloads</th></tr>"); 157 html("<tr><th>Downloads</th></tr>");
158 header = 1; 158 header = 1;
159 } 159 }
160 html("<tr><td>"); 160 html("<tr><td>");
161 url = cgit_pageurl(cgit_query_repo, "blob", 161 url = cgit_pageurl(cgit_query_repo, "blob",
162 fmt("id=%s&path=%s", sha1_to_hex(fileid), 162 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
163 buf)); 163 buf));
164 html_link_open(url, NULL, NULL); 164 html_link_open(url, NULL, NULL);
165 html_txt(buf); 165 html_txt(buf);
166 html_link_close(); 166 html_link_close();
167 html("</td></tr>"); 167 html("</td></tr>");
168 return 0; 168 return 0;
169} 169}
170 170
171static void cgit_print_branches() 171static void cgit_print_branches()
172{ 172{
173 html("<tr class='nohover'><th class='left'>Branch</th>" 173 html("<tr class='nohover'><th class='left'>Branch</th>"
174 "<th class='left'>Idle</th>" 174 "<th class='left'>Idle</th>"
175 "<th class='left'>Author</th>" 175 "<th class='left'>Author</th>"
176 "<th class='left'>Head commit</th></tr>\n"); 176 "<th class='left'>Head commit</th></tr>\n");
177 for_each_branch_ref(cgit_print_branch_cb, NULL); 177 for_each_branch_ref(cgit_print_branch_cb, NULL);
178} 178}
179 179
180static void cgit_print_tags() 180static void cgit_print_tags()
181{ 181{
182 header = 0; 182 header = 0;
183 for_each_tag_ref(cgit_print_tag_cb, NULL); 183 for_each_tag_ref(cgit_print_tag_cb, NULL);
184} 184}
185 185
186static void cgit_print_archives() 186static void cgit_print_archives()
187{ 187{
188 header = 0; 188 header = 0;
189 for_each_ref(cgit_print_archive_cb, NULL); 189 for_each_ref(cgit_print_archive_cb, NULL);
190 if (header) 190 if (header)
191 html("</table>"); 191 html("</table>");
192} 192}
193 193
194void cgit_print_summary() 194void cgit_print_summary()
195{ 195{
196 html("<div id='summary'>"); 196 html("<div id='summary'>");
197 cgit_print_archives(); 197 cgit_print_archives();
198 html("<h2>"); 198 html("<h2>");
199 html_txt(cgit_repo->name); 199 html_txt(cgit_repo->name);
200 html(" - "); 200 html(" - ");
201 html_txt(cgit_repo->desc); 201 html_txt(cgit_repo->desc);
202 html("</h2>"); 202 html("</h2>");
203 if (cgit_repo->readme) 203 if (cgit_repo->readme)
204 html_include(cgit_repo->readme); 204 html_include(cgit_repo->readme);
205 html("</div>"); 205 html("</div>");
206 206
207 html("<table class='list nowrap'>"); 207 html("<table class='list nowrap'>");
208 cgit_print_branches(); 208 cgit_print_branches();
209 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 209 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
210 cgit_print_tags(); 210 cgit_print_tags();
diff --git a/ui-tree.c b/ui-tree.c
index 006ca47..cb57d8d 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,104 +1,104 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
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
11char *curr_rev; 11char *curr_rev;
12 12
13static int print_entry(const unsigned char *sha1, const char *base, 13static int print_entry(const unsigned char *sha1, const char *base,
14 int baselen, const char *pathname, unsigned int mode, 14 int baselen, const char *pathname, unsigned int mode,
15 int stage) 15 int stage)
16{ 16{
17 char *name; 17 char *name;
18 enum object_type type; 18 enum object_type type;
19 unsigned long size = 0; 19 unsigned long size = 0;
20 20
21 name = xstrdup(pathname); 21 name = xstrdup(pathname);
22 type = sha1_object_info(sha1, &size); 22 type = sha1_object_info(sha1, &size);
23 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 23 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
24 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 24 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
25 name, 25 name,
26 sha1_to_hex(sha1)); 26 sha1_to_hex(sha1));
27 return 0; 27 return 0;
28 } 28 }
29 html("<tr><td class='filemode'>"); 29 html("<tr><td class='filemode'>");
30 html_filemode(mode); 30 html_filemode(mode);
31 html("</td><td "); 31 html("</td><td ");
32 if (S_ISDIRLNK(mode)) { 32 if (S_ISDIRLNK(mode)) {
33 htmlf("class='ls-mod'><a href='"); 33 htmlf("class='ls-mod'><a href='");
34 html_attr(fmt(cgit_repo->module_link, 34 html_attr(fmt(cgit_repo->module_link,
35 name, 35 name,
36 sha1_to_hex(sha1))); 36 sha1_to_hex(sha1)));
37 } else if (S_ISDIR(mode)) { 37 } else if (S_ISDIR(mode)) {
38 html("class='ls-dir'><a href='"); 38 html("class='ls-dir'><a href='");
39 html_attr(cgit_pageurl(cgit_query_repo, "tree", 39 html_attr(cgit_pageurl(cgit_query_repo, "tree",
40 fmt("h=%s&id=%s&path=%s%s/", 40 fmt("h=%s&amp;id=%s&amp;path=%s%s/",
41 curr_rev, 41 curr_rev,
42 sha1_to_hex(sha1), 42 sha1_to_hex(sha1),
43 cgit_query_path ? cgit_query_path : "", 43 cgit_query_path ? cgit_query_path : "",
44 pathname))); 44 pathname)));
45 } else { 45 } else {
46 html("class='ls-blob'><a href='"); 46 html("class='ls-blob'><a href='");
47 html_attr(cgit_pageurl(cgit_query_repo, "view", 47 html_attr(cgit_pageurl(cgit_query_repo, "view",
48 fmt("h=%s&id=%s&path=%s%s", curr_rev, 48 fmt("h=%s&amp;id=%s&amp;path=%s%s", curr_rev,
49 sha1_to_hex(sha1), 49 sha1_to_hex(sha1),
50 cgit_query_path ? cgit_query_path : "", 50 cgit_query_path ? cgit_query_path : "",
51 pathname))); 51 pathname)));
52 } 52 }
53 htmlf("'>%s</a></td>", name); 53 htmlf("'>%s</a></td>", name);
54 htmlf("<td class='filesize'>%li</td>", size); 54 htmlf("<td class='filesize'>%li</td>", size);
55 55
56 html("<td class='links'><a href='"); 56 html("<td class='links'><a href='");
57 html_attr(cgit_pageurl(cgit_query_repo, "log", 57 html_attr(cgit_pageurl(cgit_query_repo, "log",
58 fmt("h=%s&path=%s%s", 58 fmt("h=%s&amp;path=%s%s",
59 curr_rev, 59 curr_rev,
60 cgit_query_path ? cgit_query_path : "", 60 cgit_query_path ? cgit_query_path : "",
61 pathname))); 61 pathname)));
62 html("'>history</a></td>"); 62 html("'>history</a></td>");
63 html("</tr>\n"); 63 html("</tr>\n");
64 free(name); 64 free(name);
65 return 0; 65 return 0;
66} 66}
67 67
68void cgit_print_tree(const char *rev, const char *hex, char *path) 68void cgit_print_tree(const char *rev, const char *hex, char *path)
69{ 69{
70 struct tree *tree; 70 struct tree *tree;
71 unsigned char sha1[20]; 71 unsigned char sha1[20];
72 struct commit *commit; 72 struct commit *commit;
73 73
74 curr_rev = xstrdup(rev); 74 curr_rev = xstrdup(rev);
75 get_sha1(rev, sha1); 75 get_sha1(rev, sha1);
76 commit = lookup_commit_reference(sha1); 76 commit = lookup_commit_reference(sha1);
77 if (!commit || parse_commit(commit)) { 77 if (!commit || parse_commit(commit)) {
78 cgit_print_error(fmt("Invalid head: %s", rev)); 78 cgit_print_error(fmt("Invalid head: %s", rev));
79 return; 79 return;
80 } 80 }
81 if (!hex) 81 if (!hex)
82 hex = sha1_to_hex(commit->tree->object.sha1); 82 hex = sha1_to_hex(commit->tree->object.sha1);
83 83
84 if (get_sha1_hex(hex, sha1)) { 84 if (get_sha1_hex(hex, sha1)) {
85 cgit_print_error(fmt("Invalid object id: %s", hex)); 85 cgit_print_error(fmt("Invalid object id: %s", hex));
86 return; 86 return;
87 } 87 }
88 tree = parse_tree_indirect(sha1); 88 tree = parse_tree_indirect(sha1);
89 if (!tree) { 89 if (!tree) {
90 cgit_print_error(fmt("Not a tree object: %s", hex)); 90 cgit_print_error(fmt("Not a tree object: %s", hex));
91 return; 91 return;
92 } 92 }
93 93
94 html_txt(path); 94 html_txt(path);
95 html("<table class='list'>\n"); 95 html("<table class='list'>\n");
96 html("<tr class='nohover'>"); 96 html("<tr class='nohover'>");
97 html("<th class='left'>Mode</th>"); 97 html("<th class='left'>Mode</th>");
98 html("<th class='left'>Name</th>"); 98 html("<th class='left'>Name</th>");
99 html("<th class='right'>Size</th>"); 99 html("<th class='right'>Size</th>");
100 html("<th/>"); 100 html("<th/>");
101 html("</tr>\n"); 101 html("</tr>\n");
102 read_tree_recursive(tree, "", 0, 1, NULL, print_entry); 102 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
103 html("</table>\n"); 103 html("</table>\n");
104} 104}
diff --git a/ui-view.c b/ui-view.c
index dbe4b29..8873415 100644
--- a/ui-view.c
+++ b/ui-view.c
@@ -1,55 +1,55 @@
1/* ui-view.c: functions to output _any_ object, given it's sha1 1/* ui-view.c: functions to output _any_ object, given it's sha1
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
11void cgit_print_view(const char *hex, char *path) 11void cgit_print_view(const char *hex, char *path)
12{ 12{
13 unsigned char sha1[20]; 13 unsigned char sha1[20];
14 enum object_type type; 14 enum object_type type;
15 unsigned char *buf; 15 unsigned char *buf;
16 unsigned long size; 16 unsigned long size;
17 17
18 if (get_sha1_hex(hex, sha1)){ 18 if (get_sha1_hex(hex, sha1)){
19 cgit_print_error(fmt("Bad hex value: %s", hex)); 19 cgit_print_error(fmt("Bad hex value: %s", hex));
20 return; 20 return;
21 } 21 }
22 22
23 type = sha1_object_info(sha1, &size); 23 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) { 24 if (type == OBJ_BAD) {
25 cgit_print_error(fmt("Bad object name: %s", hex)); 25 cgit_print_error(fmt("Bad object name: %s", hex));
26 return; 26 return;
27 } 27 }
28 28
29 buf = read_sha1_file(sha1, &type, &size); 29 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) { 30 if (!buf) {
31 cgit_print_error(fmt("Error reading object %s", hex)); 31 cgit_print_error(fmt("Error reading object %s", hex));
32 return; 32 return;
33 } 33 }
34 34
35 buf[size] = '\0'; 35 buf[size] = '\0';
36 html("<table class='list'>\n"); 36 html("<table class='list'>\n");
37 html("<tr class='nohover'><th class='left'>"); 37 html("<tr class='nohover'><th class='left'>");
38 if (path) 38 if (path)
39 htmlf("%s (", path); 39 htmlf("%s (", path);
40 htmlf("%s %s, %li bytes", typename(type), hex, size); 40 htmlf("%s %s, %li bytes", typename(type), hex, size);
41 if (path) 41 if (path)
42 html(")"); 42 html(")");
43 43
44 html(" <a href='"); 44 html(" <a href='");
45 html_attr(cgit_pageurl(cgit_query_repo, "blob", 45 html_attr(cgit_pageurl(cgit_query_repo, "blob",
46 fmt("id=%s&path=%s", 46 fmt("id=%s&amp;path=%s",
47 hex, 47 hex,
48 path))); 48 path)));
49 html("'>download</a>"); 49 html("'>download</a>");
50 html("</th></tr>\n"); 50 html("</th></tr>\n");
51 html("<tr><td class='blob'>\n"); 51 html("<tr><td class='blob'>\n");
52 html_txt(buf); 52 html_txt(buf);
53 html("\n</td></tr>\n"); 53 html("\n</td></tr>\n");
54 html("</table>\n"); 54 html("</table>\n");
55} 55}