author | Ondrej Jirman <ondrej.jirman@zonio.net> | 2007-05-25 23:15:10 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-31 08:18:38 (UTC) |
commit | 1a63cfcc3d83919e790e7e279eb35fc75adb0e3c (patch) (unidiff) | |
tree | a2c613c6ae642dd6a4015142ccf04ed7c5629b8f | |
parent | 0928d8827a714f3908efa7eb9eb4cde28761af26 (diff) | |
download | cgit-1a63cfcc3d83919e790e7e279eb35fc75adb0e3c.zip cgit-1a63cfcc3d83919e790e7e279eb35fc75adb0e3c.tar.gz cgit-1a63cfcc3d83919e790e7e279eb35fc75adb0e3c.tar.bz2 |
Use & instead of & in URLs.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-commit.c | 8 | ||||
-rw-r--r-- | ui-log.c | 4 | ||||
-rw-r--r-- | ui-shared.c | 4 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 6 | ||||
-rw-r--r-- | ui-view.c | 2 |
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 | |||
@@ -1,240 +1,240 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
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 | static int files, slots; | 11 | static int files, slots; |
12 | static int total_adds, total_rems, max_changes; | 12 | static int total_adds, total_rems, max_changes; |
13 | static int lines_added, lines_removed; | 13 | static int lines_added, lines_removed; |
14 | 14 | ||
15 | static struct fileinfo { | 15 | static struct fileinfo { |
16 | char status; | 16 | char status; |
17 | unsigned char old_sha1[20]; | 17 | unsigned char old_sha1[20]; |
18 | unsigned char new_sha1[20]; | 18 | unsigned char new_sha1[20]; |
19 | unsigned short old_mode; | 19 | unsigned short old_mode; |
20 | unsigned short new_mode; | 20 | unsigned short new_mode; |
21 | char *old_path; | 21 | char *old_path; |
22 | char *new_path; | 22 | char *new_path; |
23 | unsigned int added; | 23 | unsigned int added; |
24 | unsigned int removed; | 24 | unsigned int removed; |
25 | } *items; | 25 | } *items; |
26 | 26 | ||
27 | 27 | ||
28 | void print_fileinfo(struct fileinfo *info) | 28 | void print_fileinfo(struct fileinfo *info) |
29 | { | 29 | { |
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&id2=%s&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 | ||
109 | void cgit_count_diff_lines(char *line, int len) | 109 | void 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 | ||
119 | void inspect_filepair(struct diff_filepair *pair) | 119 | void 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) |
127 | slots = 4; | 127 | slots = 4; |
128 | else | 128 | else |
129 | slots = slots * 2; | 129 | slots = slots * 2; |
130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
131 | } | 131 | } |
132 | items[files-1].status = pair->status; | 132 | items[files-1].status = pair->status; |
133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
135 | items[files-1].old_mode = pair->one->mode; | 135 | items[files-1].old_mode = pair->one->mode; |
136 | items[files-1].new_mode = pair->two->mode; | 136 | items[files-1].new_mode = pair->two->mode; |
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 | ||
148 | void cgit_print_commit(const char *hex) | 148 | void 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&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&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&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 | } |
@@ -1,128 +1,128 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log 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 | ||
11 | int files, lines; | 11 | int files, lines; |
12 | 12 | ||
13 | void count_lines(char *line, int size) | 13 | void count_lines(char *line, int size) |
14 | { | 14 | { |
15 | if (size>0 && (line[0] == '+' || line[0] == '-')) | 15 | if (size>0 && (line[0] == '+' || line[0] == '-')) |
16 | lines++; | 16 | lines++; |
17 | } | 17 | } |
18 | 18 | ||
19 | void inspect_files(struct diff_filepair *pair) | 19 | void inspect_files(struct diff_filepair *pair) |
20 | { | 20 | { |
21 | files++; | 21 | files++; |
22 | if (cgit_repo->enable_log_linecount) | 22 | if (cgit_repo->enable_log_linecount) |
23 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 23 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
24 | } | 24 | } |
25 | 25 | ||
26 | void print_commit(struct commit *commit) | 26 | void print_commit(struct commit *commit) |
27 | { | 27 | { |
28 | struct commitinfo *info; | 28 | struct commitinfo *info; |
29 | 29 | ||
30 | info = cgit_parse_commit(commit); | 30 | info = cgit_parse_commit(commit); |
31 | html("<tr><td>"); | 31 | html("<tr><td>"); |
32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
33 | html("</td><td>"); | 33 | html("</td><td>"); |
34 | char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); | 34 | char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); |
35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); |
36 | html_link_open(url, NULL, NULL); | 36 | html_link_open(url, NULL, NULL); |
37 | html_ntxt(cgit_max_msg_len, info->subject); | 37 | html_ntxt(cgit_max_msg_len, info->subject); |
38 | html_link_close(); | 38 | html_link_close(); |
39 | if (cgit_repo->enable_log_filecount) { | 39 | if (cgit_repo->enable_log_filecount) { |
40 | files = 0; | 40 | files = 0; |
41 | lines = 0; | 41 | lines = 0; |
42 | cgit_diff_commit(commit, inspect_files); | 42 | cgit_diff_commit(commit, inspect_files); |
43 | html("</td><td class='right'>"); | 43 | html("</td><td class='right'>"); |
44 | htmlf("%d", files); | 44 | htmlf("%d", files); |
45 | if (cgit_repo->enable_log_linecount) { | 45 | if (cgit_repo->enable_log_linecount) { |
46 | html("</td><td class='right'>"); | 46 | html("</td><td class='right'>"); |
47 | htmlf("%d", lines); | 47 | htmlf("%d", lines); |
48 | } | 48 | } |
49 | } | 49 | } |
50 | html("</td><td>"); | 50 | html("</td><td>"); |
51 | html_txt(info->author); | 51 | html_txt(info->author); |
52 | html("</td></tr>\n"); | 52 | html("</td></tr>\n"); |
53 | cgit_free_commitinfo(info); | 53 | cgit_free_commitinfo(info); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) | 57 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) |
58 | { | 58 | { |
59 | struct rev_info rev; | 59 | struct rev_info rev; |
60 | struct commit *commit; | 60 | struct commit *commit; |
61 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 61 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
62 | int argc = 2; | 62 | int argc = 2; |
63 | int i; | 63 | int i; |
64 | 64 | ||
65 | if (grep) | 65 | if (grep) |
66 | argv[argc++] = fmt("--grep=%s", grep); | 66 | argv[argc++] = fmt("--grep=%s", grep); |
67 | if (path) { | 67 | if (path) { |
68 | argv[argc++] = "--"; | 68 | argv[argc++] = "--"; |
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(" <a href='"); | 115 | html(" <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&ofs=%d", tip, ofs-cnt))); |
118 | html("'>[prev]</a> "); | 118 | html("'>[prev]</a> "); |
119 | } | 119 | } |
120 | 120 | ||
121 | if ((commit = get_revision(&rev)) != NULL) { | 121 | if ((commit = get_revision(&rev)) != NULL) { |
122 | html(" <a href='"); | 122 | html(" <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&ofs=%d", tip, ofs+cnt))); |
125 | html("'>[next]</a> "); | 125 | html("'>[next]</a> "); |
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 | |||
@@ -1,221 +1,221 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
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 | const char cgit_doctype[] = | 11 | const char cgit_doctype[] = |
12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
14 | 14 | ||
15 | static char *http_date(time_t t) | 15 | static char *http_date(time_t t) |
16 | { | 16 | { |
17 | static char day[][4] = | 17 | static char day[][4] = |
18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
19 | static char month[][4] = | 19 | static char month[][4] = |
20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
22 | struct tm *tm = gmtime(&t); | 22 | struct tm *tm = gmtime(&t); |
23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
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 | ||
28 | static long ttl_seconds(long ttl) | 28 | static 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 | ||
36 | void cgit_print_error(char *msg) | 36 | void 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 | ||
43 | char *cgit_rooturl() | 43 | char *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 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *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 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *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&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_currurl() | 78 | char *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 | ||
91 | void cgit_print_date(time_t secs, char *format) | 91 | void 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 | ||
101 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 101 | void 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 | } |
123 | if (secs < TM_WEEK * 2) { | 123 | if (secs < TM_WEEK * 2) { |
124 | htmlf("<span class='age-days'>%.0f days</span>", | 124 | htmlf("<span class='age-days'>%.0f days</span>", |
125 | secs * 1.0 / TM_DAY); | 125 | secs * 1.0 / TM_DAY); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (secs < TM_MONTH * 2) { | 128 | if (secs < TM_MONTH * 2) { |
129 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 129 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
130 | secs * 1.0 / TM_WEEK); | 130 | secs * 1.0 / TM_WEEK); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | if (secs < TM_YEAR * 2) { | 133 | if (secs < TM_YEAR * 2) { |
134 | htmlf("<span class='age-months'>%.0f months</span>", | 134 | htmlf("<span class='age-months'>%.0f months</span>", |
135 | secs * 1.0 / TM_MONTH); | 135 | secs * 1.0 / TM_MONTH); |
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | htmlf("<span class='age-years'>%.0f years</span>", | 138 | htmlf("<span class='age-years'>%.0f years</span>", |
139 | secs * 1.0 / TM_YEAR); | 139 | secs * 1.0 / TM_YEAR); |
140 | } | 140 | } |
141 | 141 | ||
142 | void cgit_print_docstart(char *title, struct cacheitem *item) | 142 | void cgit_print_docstart(char *title, struct cacheitem *item) |
143 | { | 143 | { |
144 | html("Content-Type: text/html; charset=utf-8\n"); | 144 | html("Content-Type: text/html; charset=utf-8\n"); |
145 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 145 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
146 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 146 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
147 | ttl_seconds(item->ttl))); | 147 | ttl_seconds(item->ttl))); |
148 | html("\n"); | 148 | html("\n"); |
149 | html(cgit_doctype); | 149 | html(cgit_doctype); |
150 | html("<html>\n"); | 150 | html("<html>\n"); |
151 | html("<head>\n"); | 151 | html("<head>\n"); |
152 | html("<title>"); | 152 | html("<title>"); |
153 | html_txt(title); | 153 | html_txt(title); |
154 | html("</title>\n"); | 154 | html("</title>\n"); |
155 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); | 155 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); |
156 | html("<link rel='stylesheet' type='text/css' href='"); | 156 | html("<link rel='stylesheet' type='text/css' href='"); |
157 | html_attr(cgit_css); | 157 | html_attr(cgit_css); |
158 | html("'/>\n"); | 158 | html("'/>\n"); |
159 | html("</head>\n"); | 159 | html("</head>\n"); |
160 | html("<body>\n"); | 160 | html("<body>\n"); |
161 | } | 161 | } |
162 | 162 | ||
163 | void cgit_print_docend() | 163 | void cgit_print_docend() |
164 | { | 164 | { |
165 | html("</td></tr></table>"); | 165 | html("</td></tr></table>"); |
166 | html("</body>\n</html>\n"); | 166 | html("</body>\n</html>\n"); |
167 | } | 167 | } |
168 | 168 | ||
169 | void cgit_print_pageheader(char *title, int show_search) | 169 | void cgit_print_pageheader(char *title, int show_search) |
170 | { | 170 | { |
171 | html("<table id='layout'>"); | 171 | html("<table id='layout'>"); |
172 | html("<tr><td id='header'>"); | 172 | html("<tr><td id='header'>"); |
173 | html(cgit_root_title); | 173 | html(cgit_root_title); |
174 | html("</td><td id='logo'>"); | 174 | html("</td><td id='logo'>"); |
175 | html("<a href='"); | 175 | html("<a href='"); |
176 | html_attr(cgit_logo_link); | 176 | html_attr(cgit_logo_link); |
177 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 177 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
178 | html("</td></tr>"); | 178 | html("</td></tr>"); |
179 | html("<tr><td id='crumb'>"); | 179 | html("<tr><td id='crumb'>"); |
180 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); | 180 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); |
181 | if (cgit_query_repo) { | 181 | if (cgit_query_repo) { |
182 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); | 182 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); |
183 | html_txt(cgit_repo->name); | 183 | html_txt(cgit_repo->name); |
184 | htmlf("</a> : %s", title); | 184 | htmlf("</a> : %s", title); |
185 | } | 185 | } |
186 | html("</td>"); | 186 | html("</td>"); |
187 | html("<td id='search'>"); | 187 | html("<td id='search'>"); |
188 | if (show_search) { | 188 | if (show_search) { |
189 | html("<form method='get' action='"); | 189 | html("<form method='get' action='"); |
190 | html_attr(cgit_currurl()); | 190 | html_attr(cgit_currurl()); |
191 | html("'>"); | 191 | html("'>"); |
192 | if (!cgit_virtual_root) { | 192 | if (!cgit_virtual_root) { |
193 | if (cgit_query_repo) | 193 | if (cgit_query_repo) |
194 | html_hidden("r", cgit_query_repo); | 194 | html_hidden("r", cgit_query_repo); |
195 | if (cgit_query_page) | 195 | if (cgit_query_page) |
196 | html_hidden("p", cgit_query_page); | 196 | html_hidden("p", cgit_query_page); |
197 | } | 197 | } |
198 | if (cgit_query_head) | 198 | if (cgit_query_head) |
199 | html_hidden("h", cgit_query_head); | 199 | html_hidden("h", cgit_query_head); |
200 | if (cgit_query_sha1) | 200 | if (cgit_query_sha1) |
201 | html_hidden("id", cgit_query_sha1); | 201 | html_hidden("id", cgit_query_sha1); |
202 | if (cgit_query_sha2) | 202 | if (cgit_query_sha2) |
203 | html_hidden("id2", cgit_query_sha2); | 203 | html_hidden("id2", cgit_query_sha2); |
204 | html("<input type='text' name='q' value='"); | 204 | html("<input type='text' name='q' value='"); |
205 | html_attr(cgit_query_search); | 205 | html_attr(cgit_query_search); |
206 | html("'/></form>"); | 206 | html("'/></form>"); |
207 | } | 207 | } |
208 | html("</td></tr>"); | 208 | html("</td></tr>"); |
209 | html("<tr><td id='content' colspan='2'>"); | 209 | html("<tr><td id='content' colspan='2'>"); |
210 | } | 210 | } |
211 | 211 | ||
212 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 212 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
213 | struct cacheitem *item) | 213 | struct cacheitem *item) |
214 | { | 214 | { |
215 | htmlf("Content-Type: %s\n", mimetype); | 215 | htmlf("Content-Type: %s\n", mimetype); |
216 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 216 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
217 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 217 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
218 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 218 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
219 | ttl_seconds(item->ttl))); | 219 | ttl_seconds(item->ttl))); |
220 | html("\n"); | 220 | html("\n"); |
221 | } | 221 | } |
diff --git a/ui-summary.c b/ui-summary.c index 18608b8..15e8aec 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,212 +1,212 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
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 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
14 | int flags, void *cb_data) | 14 | int flags, void *cb_data) |
15 | { | 15 | { |
16 | struct commit *commit; | 16 | struct commit *commit; |
17 | struct commitinfo *info; | 17 | struct commitinfo *info; |
18 | char buf[256], *url; | 18 | char buf[256], *url; |
19 | 19 | ||
20 | strncpy(buf, refname, sizeof(buf)); | 20 | strncpy(buf, refname, sizeof(buf)); |
21 | commit = lookup_commit(sha1); | 21 | commit = lookup_commit(sha1); |
22 | if (commit && !parse_commit(commit)){ | 22 | if (commit && !parse_commit(commit)){ |
23 | info = cgit_parse_commit(commit); | 23 | info = cgit_parse_commit(commit); |
24 | html("<tr><td>"); | 24 | html("<tr><td>"); |
25 | url = cgit_pageurl(cgit_query_repo, "log", | 25 | url = cgit_pageurl(cgit_query_repo, "log", |
26 | fmt("h=%s", refname)); | 26 | fmt("h=%s", refname)); |
27 | html_link_open(url, NULL, NULL); | 27 | html_link_open(url, NULL, NULL); |
28 | html_txt(buf); | 28 | html_txt(buf); |
29 | html_link_close(); | 29 | html_link_close(); |
30 | html("</td><td>"); | 30 | html("</td><td>"); |
31 | cgit_print_age(commit->date, -1, NULL); | 31 | cgit_print_age(commit->date, -1, NULL); |
32 | html("</td><td>"); | 32 | html("</td><td>"); |
33 | html_txt(info->author); | 33 | html_txt(info->author); |
34 | html("</td><td>"); | 34 | html("</td><td>"); |
35 | url = cgit_pageurl(cgit_query_repo, "commit", | 35 | url = cgit_pageurl(cgit_query_repo, "commit", |
36 | fmt("h=%s", sha1_to_hex(sha1))); | 36 | fmt("h=%s", sha1_to_hex(sha1))); |
37 | html_link_open(url, NULL, NULL); | 37 | html_link_open(url, NULL, NULL); |
38 | html_ntxt(cgit_max_msg_len, info->subject); | 38 | html_ntxt(cgit_max_msg_len, info->subject); |
39 | html_link_close(); | 39 | html_link_close(); |
40 | html("</td></tr>\n"); | 40 | html("</td></tr>\n"); |
41 | cgit_free_commitinfo(info); | 41 | cgit_free_commitinfo(info); |
42 | } else { | 42 | } else { |
43 | html("<tr><td>"); | 43 | html("<tr><td>"); |
44 | html_txt(buf); | 44 | html_txt(buf); |
45 | html("</td><td colspan='3'>"); | 45 | html("</td><td colspan='3'>"); |
46 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 46 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
47 | html("</td></tr>\n"); | 47 | html("</td></tr>\n"); |
48 | } | 48 | } |
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
53 | static void cgit_print_object_ref(struct object *obj) | 53 | static void cgit_print_object_ref(struct object *obj) |
54 | { | 54 | { |
55 | char *page, *arg, *url; | 55 | char *page, *arg, *url; |
56 | 56 | ||
57 | if (obj->type == OBJ_COMMIT) { | 57 | if (obj->type == OBJ_COMMIT) { |
58 | page = "commit"; | 58 | page = "commit"; |
59 | arg = "h"; | 59 | arg = "h"; |
60 | } else if (obj->type == OBJ_TREE) { | 60 | } else if (obj->type == OBJ_TREE) { |
61 | page = "tree"; | 61 | page = "tree"; |
62 | arg = "id"; | 62 | arg = "id"; |
63 | } else { | 63 | } else { |
64 | page = "view"; | 64 | page = "view"; |
65 | arg = "id"; | 65 | arg = "id"; |
66 | } | 66 | } |
67 | 67 | ||
68 | url = cgit_pageurl(cgit_query_repo, page, | 68 | url = cgit_pageurl(cgit_query_repo, page, |
69 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 69 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
70 | html_link_open(url, NULL, NULL); | 70 | html_link_open(url, NULL, NULL); |
71 | htmlf("%s %s", typename(obj->type), | 71 | htmlf("%s %s", typename(obj->type), |
72 | sha1_to_hex(obj->sha1)); | 72 | sha1_to_hex(obj->sha1)); |
73 | html_link_close(); | 73 | html_link_close(); |
74 | } | 74 | } |
75 | 75 | ||
76 | static void print_tag_header() | 76 | static void print_tag_header() |
77 | { | 77 | { |
78 | html("<tr class='nohover'><th class='left'>Tag</th>" | 78 | html("<tr class='nohover'><th class='left'>Tag</th>" |
79 | "<th class='left'>Age</th>" | 79 | "<th class='left'>Age</th>" |
80 | "<th class='left'>Author</th>" | 80 | "<th class='left'>Author</th>" |
81 | "<th class='left'>Reference</th></tr>\n"); | 81 | "<th class='left'>Reference</th></tr>\n"); |
82 | header = 1; | 82 | header = 1; |
83 | } | 83 | } |
84 | 84 | ||
85 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 85 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
86 | int flags, void *cb_data) | 86 | int flags, void *cb_data) |
87 | { | 87 | { |
88 | struct tag *tag; | 88 | struct tag *tag; |
89 | struct taginfo *info; | 89 | struct taginfo *info; |
90 | struct object *obj; | 90 | struct object *obj; |
91 | char buf[256], *url; | 91 | char buf[256], *url; |
92 | 92 | ||
93 | strncpy(buf, refname, sizeof(buf)); | 93 | strncpy(buf, refname, sizeof(buf)); |
94 | obj = parse_object(sha1); | 94 | obj = parse_object(sha1); |
95 | if (!obj) | 95 | if (!obj) |
96 | return 1; | 96 | return 1; |
97 | if (obj->type == OBJ_TAG) { | 97 | if (obj->type == OBJ_TAG) { |
98 | tag = lookup_tag(sha1); | 98 | tag = lookup_tag(sha1); |
99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
100 | return 2; | 100 | return 2; |
101 | if (!header) | 101 | if (!header) |
102 | print_tag_header(); | 102 | print_tag_header(); |
103 | html("<tr><td>"); | 103 | html("<tr><td>"); |
104 | url = cgit_pageurl(cgit_query_repo, "view", | 104 | url = cgit_pageurl(cgit_query_repo, "view", |
105 | fmt("id=%s", sha1_to_hex(sha1))); | 105 | fmt("id=%s", sha1_to_hex(sha1))); |
106 | html_link_open(url, NULL, NULL); | 106 | html_link_open(url, NULL, NULL); |
107 | html_txt(buf); | 107 | html_txt(buf); |
108 | html_link_close(); | 108 | html_link_close(); |
109 | html("</td><td>"); | 109 | html("</td><td>"); |
110 | if (info->tagger_date > 0) | 110 | if (info->tagger_date > 0) |
111 | cgit_print_age(info->tagger_date, -1, NULL); | 111 | cgit_print_age(info->tagger_date, -1, NULL); |
112 | html("</td><td>"); | 112 | html("</td><td>"); |
113 | if (info->tagger) | 113 | if (info->tagger) |
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 | ||
130 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 130 | static 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&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 | ||
171 | static void cgit_print_branches() | 171 | static 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 | ||
180 | static void cgit_print_tags() | 180 | static 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 | ||
186 | static void cgit_print_archives() | 186 | static 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 | ||
194 | void cgit_print_summary() | 194 | void 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'> </td></tr>"); | 209 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
210 | cgit_print_tags(); | 210 | cgit_print_tags(); |
211 | html("</table>"); | 211 | html("</table>"); |
212 | } | 212 | } |
@@ -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 | ||
11 | char *curr_rev; | 11 | char *curr_rev; |
12 | 12 | ||
13 | static int print_entry(const unsigned char *sha1, const char *base, | 13 | static 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&id=%s&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&id=%s&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&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 | ||
68 | void cgit_print_tree(const char *rev, const char *hex, char *path) | 68 | void 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 | } |
@@ -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 | ||
11 | void cgit_print_view(const char *hex, char *path) | 11 | void 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&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 | } |