author | Lars Hjemli <hjemli@gmail.com> | 2010-06-22 14:16:24 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-06-22 14:16:24 (UTC) |
commit | 6654d5b7bdc1d775cf09ca6690b1fc5ecea4696d (patch) (unidiff) | |
tree | f03c3c3621b343493fb3c834ba3b8e4ebfe09471 | |
parent | 6f92f332e6a9ee3e16051bda9fe148607af67f65 (diff) | |
parent | a579fb02561c98a146c9e707d098d2b10aa02015 (diff) | |
download | cgit-6654d5b7bdc1d775cf09ca6690b1fc5ecea4696d.zip cgit-6654d5b7bdc1d775cf09ca6690b1fc5ecea4696d.tar.gz cgit-6654d5b7bdc1d775cf09ca6690b1fc5ecea4696d.tar.bz2 |
Merge branch 'lh/range-search'
-rw-r--r-- | ui-log.c | 11 | ||||
-rw-r--r-- | ui-shared.c | 1 |
2 files changed, 8 insertions, 4 deletions
@@ -1,237 +1,240 @@ | |||
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 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | int files, add_lines, rem_lines; | 13 | int files, add_lines, rem_lines; |
14 | 14 | ||
15 | void count_lines(char *line, int size) | 15 | void count_lines(char *line, int size) |
16 | { | 16 | { |
17 | if (size <= 0) | 17 | if (size <= 0) |
18 | return; | 18 | return; |
19 | 19 | ||
20 | if (line[0] == '+') | 20 | if (line[0] == '+') |
21 | add_lines++; | 21 | add_lines++; |
22 | 22 | ||
23 | else if (line[0] == '-') | 23 | else if (line[0] == '-') |
24 | rem_lines++; | 24 | rem_lines++; |
25 | } | 25 | } |
26 | 26 | ||
27 | void inspect_files(struct diff_filepair *pair) | 27 | void inspect_files(struct diff_filepair *pair) |
28 | { | 28 | { |
29 | unsigned long old_size = 0; | 29 | unsigned long old_size = 0; |
30 | unsigned long new_size = 0; | 30 | unsigned long new_size = 0; |
31 | int binary = 0; | 31 | int binary = 0; |
32 | 32 | ||
33 | files++; | 33 | files++; |
34 | if (ctx.repo->enable_log_linecount) | 34 | if (ctx.repo->enable_log_linecount) |
35 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 35 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
36 | &new_size, &binary, 0, count_lines); | 36 | &new_size, &binary, 0, count_lines); |
37 | } | 37 | } |
38 | 38 | ||
39 | void show_commit_decorations(struct commit *commit) | 39 | void show_commit_decorations(struct commit *commit) |
40 | { | 40 | { |
41 | struct name_decoration *deco; | 41 | struct name_decoration *deco; |
42 | static char buf[1024]; | 42 | static char buf[1024]; |
43 | 43 | ||
44 | buf[sizeof(buf) - 1] = 0; | 44 | buf[sizeof(buf) - 1] = 0; |
45 | deco = lookup_decoration(&name_decoration, &commit->object); | 45 | deco = lookup_decoration(&name_decoration, &commit->object); |
46 | while (deco) { | 46 | while (deco) { |
47 | if (!prefixcmp(deco->name, "refs/heads/")) { | 47 | if (!prefixcmp(deco->name, "refs/heads/")) { |
48 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); | 48 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); |
49 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, | 49 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, |
50 | ctx.qry.vpath, 0, NULL, NULL, | 50 | ctx.qry.vpath, 0, NULL, NULL, |
51 | ctx.qry.showmsg); | 51 | ctx.qry.showmsg); |
52 | } | 52 | } |
53 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { | 53 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { |
54 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); | 54 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); |
55 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 55 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
56 | } | 56 | } |
57 | else if (!prefixcmp(deco->name, "refs/tags/")) { | 57 | else if (!prefixcmp(deco->name, "refs/tags/")) { |
58 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); | 58 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); |
59 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 59 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
60 | } | 60 | } |
61 | else if (!prefixcmp(deco->name, "refs/remotes/")) { | 61 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
62 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); | 62 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
63 | cgit_log_link(buf, NULL, "remote-deco", NULL, | 63 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
64 | sha1_to_hex(commit->object.sha1), | 64 | sha1_to_hex(commit->object.sha1), |
65 | ctx.qry.vpath, 0, NULL, NULL, | 65 | ctx.qry.vpath, 0, NULL, NULL, |
66 | ctx.qry.showmsg); | 66 | ctx.qry.showmsg); |
67 | } | 67 | } |
68 | else { | 68 | else { |
69 | strncpy(buf, deco->name, sizeof(buf) - 1); | 69 | strncpy(buf, deco->name, sizeof(buf) - 1); |
70 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, | 70 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
71 | sha1_to_hex(commit->object.sha1), | 71 | sha1_to_hex(commit->object.sha1), |
72 | ctx.qry.vpath, 0); | 72 | ctx.qry.vpath, 0); |
73 | } | 73 | } |
74 | deco = deco->next; | 74 | deco = deco->next; |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | void print_commit(struct commit *commit) | 78 | void print_commit(struct commit *commit) |
79 | { | 79 | { |
80 | struct commitinfo *info; | 80 | struct commitinfo *info; |
81 | char *tmp; | 81 | char *tmp; |
82 | int cols = 2; | 82 | int cols = 2; |
83 | 83 | ||
84 | info = cgit_parse_commit(commit); | 84 | info = cgit_parse_commit(commit); |
85 | htmlf("<tr%s><td>", | 85 | htmlf("<tr%s><td>", |
86 | ctx.qry.showmsg ? " class='logheader'" : ""); | 86 | ctx.qry.showmsg ? " class='logheader'" : ""); |
87 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 87 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
88 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); | 88 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); |
89 | html_link_open(tmp, NULL, NULL); | 89 | html_link_open(tmp, NULL, NULL); |
90 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 90 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
91 | html_link_close(); | 91 | html_link_close(); |
92 | htmlf("</td><td%s>", | 92 | htmlf("</td><td%s>", |
93 | ctx.qry.showmsg ? " class='logsubject'" : ""); | 93 | ctx.qry.showmsg ? " class='logsubject'" : ""); |
94 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 94 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
95 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); | 95 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); |
96 | show_commit_decorations(commit); | 96 | show_commit_decorations(commit); |
97 | html("</td><td>"); | 97 | html("</td><td>"); |
98 | html_txt(info->author); | 98 | html_txt(info->author); |
99 | if (ctx.repo->enable_log_filecount) { | 99 | if (ctx.repo->enable_log_filecount) { |
100 | files = 0; | 100 | files = 0; |
101 | add_lines = 0; | 101 | add_lines = 0; |
102 | rem_lines = 0; | 102 | rem_lines = 0; |
103 | cgit_diff_commit(commit, inspect_files); | 103 | cgit_diff_commit(commit, inspect_files); |
104 | html("</td><td>"); | 104 | html("</td><td>"); |
105 | htmlf("%d", files); | 105 | htmlf("%d", files); |
106 | if (ctx.repo->enable_log_linecount) { | 106 | if (ctx.repo->enable_log_linecount) { |
107 | html("</td><td>"); | 107 | html("</td><td>"); |
108 | htmlf("-%d/+%d", rem_lines, add_lines); | 108 | htmlf("-%d/+%d", rem_lines, add_lines); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | html("</td></tr>\n"); | 111 | html("</td></tr>\n"); |
112 | if (ctx.qry.showmsg) { | 112 | if (ctx.qry.showmsg) { |
113 | if (ctx.repo->enable_log_filecount) { | 113 | if (ctx.repo->enable_log_filecount) { |
114 | cols++; | 114 | cols++; |
115 | if (ctx.repo->enable_log_linecount) | 115 | if (ctx.repo->enable_log_linecount) |
116 | cols++; | 116 | cols++; |
117 | } | 117 | } |
118 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", | 118 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", |
119 | cols); | 119 | cols); |
120 | html_txt(info->msg); | 120 | html_txt(info->msg); |
121 | html("</td></tr>\n"); | 121 | html("</td></tr>\n"); |
122 | } | 122 | } |
123 | cgit_free_commitinfo(info); | 123 | cgit_free_commitinfo(info); |
124 | } | 124 | } |
125 | 125 | ||
126 | static const char *disambiguate_ref(const char *ref) | 126 | static const char *disambiguate_ref(const char *ref) |
127 | { | 127 | { |
128 | unsigned char sha1[20]; | 128 | unsigned char sha1[20]; |
129 | const char *longref; | 129 | const char *longref; |
130 | 130 | ||
131 | longref = fmt("refs/heads/%s", ref); | 131 | longref = fmt("refs/heads/%s", ref); |
132 | if (get_sha1(longref, sha1) == 0) | 132 | if (get_sha1(longref, sha1) == 0) |
133 | return longref; | 133 | return longref; |
134 | 134 | ||
135 | return ref; | 135 | return ref; |
136 | } | 136 | } |
137 | 137 | ||
138 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 138 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
139 | char *path, int pager) | 139 | char *path, int pager) |
140 | { | 140 | { |
141 | struct rev_info rev; | 141 | struct rev_info rev; |
142 | struct commit *commit; | 142 | struct commit *commit; |
143 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; | 143 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; |
144 | int argc = 2; | 144 | int argc = 2; |
145 | int i, columns = 3; | 145 | int i, columns = 3; |
146 | 146 | ||
147 | if (!tip) | 147 | if (!tip) |
148 | tip = ctx.qry.head; | 148 | tip = ctx.qry.head; |
149 | 149 | ||
150 | argv[1] = disambiguate_ref(tip); | 150 | argv[1] = disambiguate_ref(tip); |
151 | 151 | ||
152 | if (grep && pattern && (!strcmp(grep, "grep") || | 152 | if (grep && pattern) { |
153 | !strcmp(grep, "author") || | 153 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || |
154 | !strcmp(grep, "committer"))) | 154 | !strcmp(grep, "committer")) |
155 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 155 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
156 | if (!strcmp(grep, "range")) | ||
157 | argv[1] = pattern; | ||
158 | } | ||
156 | 159 | ||
157 | if (path) { | 160 | if (path) { |
158 | argv[argc++] = "--"; | 161 | argv[argc++] = "--"; |
159 | argv[argc++] = path; | 162 | argv[argc++] = path; |
160 | } | 163 | } |
161 | init_revisions(&rev, NULL); | 164 | init_revisions(&rev, NULL); |
162 | rev.abbrev = DEFAULT_ABBREV; | 165 | rev.abbrev = DEFAULT_ABBREV; |
163 | rev.commit_format = CMIT_FMT_DEFAULT; | 166 | rev.commit_format = CMIT_FMT_DEFAULT; |
164 | rev.verbose_header = 1; | 167 | rev.verbose_header = 1; |
165 | rev.show_root_diff = 0; | 168 | rev.show_root_diff = 0; |
166 | setup_revisions(argc, argv, &rev, NULL); | 169 | setup_revisions(argc, argv, &rev, NULL); |
167 | load_ref_decorations(DECORATE_FULL_REFS); | 170 | load_ref_decorations(DECORATE_FULL_REFS); |
168 | rev.show_decorations = 1; | 171 | rev.show_decorations = 1; |
169 | rev.grep_filter.regflags |= REG_ICASE; | 172 | rev.grep_filter.regflags |= REG_ICASE; |
170 | compile_grep_patterns(&rev.grep_filter); | 173 | compile_grep_patterns(&rev.grep_filter); |
171 | prepare_revision_walk(&rev); | 174 | prepare_revision_walk(&rev); |
172 | 175 | ||
173 | if (pager) | 176 | if (pager) |
174 | html("<table class='list nowrap'>"); | 177 | html("<table class='list nowrap'>"); |
175 | 178 | ||
176 | html("<tr class='nohover'><th class='left'>Age</th>" | 179 | html("<tr class='nohover'><th class='left'>Age</th>" |
177 | "<th class='left'>Commit message"); | 180 | "<th class='left'>Commit message"); |
178 | if (pager) { | 181 | if (pager) { |
179 | html(" ("); | 182 | html(" ("); |
180 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, | 183 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
181 | NULL, ctx.qry.head, ctx.qry.sha1, | 184 | NULL, ctx.qry.head, ctx.qry.sha1, |
182 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, | 185 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |
183 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); | 186 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); |
184 | html(")"); | 187 | html(")"); |
185 | } | 188 | } |
186 | html("</th><th class='left'>Author</th>"); | 189 | html("</th><th class='left'>Author</th>"); |
187 | if (ctx.repo->enable_log_filecount) { | 190 | if (ctx.repo->enable_log_filecount) { |
188 | html("<th class='left'>Files</th>"); | 191 | html("<th class='left'>Files</th>"); |
189 | columns++; | 192 | columns++; |
190 | if (ctx.repo->enable_log_linecount) { | 193 | if (ctx.repo->enable_log_linecount) { |
191 | html("<th class='left'>Lines</th>"); | 194 | html("<th class='left'>Lines</th>"); |
192 | columns++; | 195 | columns++; |
193 | } | 196 | } |
194 | } | 197 | } |
195 | html("</tr>\n"); | 198 | html("</tr>\n"); |
196 | 199 | ||
197 | if (ofs<0) | 200 | if (ofs<0) |
198 | ofs = 0; | 201 | ofs = 0; |
199 | 202 | ||
200 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 203 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
201 | free(commit->buffer); | 204 | free(commit->buffer); |
202 | commit->buffer = NULL; | 205 | commit->buffer = NULL; |
203 | free_commit_list(commit->parents); | 206 | free_commit_list(commit->parents); |
204 | commit->parents = NULL; | 207 | commit->parents = NULL; |
205 | } | 208 | } |
206 | 209 | ||
207 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 210 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
208 | print_commit(commit); | 211 | print_commit(commit); |
209 | free(commit->buffer); | 212 | free(commit->buffer); |
210 | commit->buffer = NULL; | 213 | commit->buffer = NULL; |
211 | free_commit_list(commit->parents); | 214 | free_commit_list(commit->parents); |
212 | commit->parents = NULL; | 215 | commit->parents = NULL; |
213 | } | 216 | } |
214 | if (pager) { | 217 | if (pager) { |
215 | htmlf("</table><div class='pager'>", | 218 | htmlf("</table><div class='pager'>", |
216 | columns); | 219 | columns); |
217 | if (ofs > 0) { | 220 | if (ofs > 0) { |
218 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 221 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
219 | ctx.qry.sha1, ctx.qry.vpath, | 222 | ctx.qry.sha1, ctx.qry.vpath, |
220 | ofs - cnt, ctx.qry.grep, | 223 | ofs - cnt, ctx.qry.grep, |
221 | ctx.qry.search, ctx.qry.showmsg); | 224 | ctx.qry.search, ctx.qry.showmsg); |
222 | html(" "); | 225 | html(" "); |
223 | } | 226 | } |
224 | if ((commit = get_revision(&rev)) != NULL) { | 227 | if ((commit = get_revision(&rev)) != NULL) { |
225 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 228 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
226 | ctx.qry.sha1, ctx.qry.vpath, | 229 | ctx.qry.sha1, ctx.qry.vpath, |
227 | ofs + cnt, ctx.qry.grep, | 230 | ofs + cnt, ctx.qry.grep, |
228 | ctx.qry.search, ctx.qry.showmsg); | 231 | ctx.qry.search, ctx.qry.showmsg); |
229 | } | 232 | } |
230 | html("</div>"); | 233 | html("</div>"); |
231 | } else if ((commit = get_revision(&rev)) != NULL) { | 234 | } else if ((commit = get_revision(&rev)) != NULL) { |
232 | html("<tr class='nohover'><td colspan='3'>"); | 235 | html("<tr class='nohover'><td colspan='3'>"); |
233 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, | 236 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, |
234 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); | 237 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); |
235 | html("</td></tr>\n"); | 238 | html("</td></tr>\n"); |
236 | } | 239 | } |
237 | } | 240 | } |
diff --git a/ui-shared.c b/ui-shared.c index c99bcec..c398d7a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -577,322 +577,323 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
577 | exit(0); | 577 | exit(0); |
578 | } | 578 | } |
579 | 579 | ||
580 | void cgit_print_docstart(struct cgit_context *ctx) | 580 | void cgit_print_docstart(struct cgit_context *ctx) |
581 | { | 581 | { |
582 | if (ctx->cfg.embedded) { | 582 | if (ctx->cfg.embedded) { |
583 | if (ctx->cfg.header) | 583 | if (ctx->cfg.header) |
584 | html_include(ctx->cfg.header); | 584 | html_include(ctx->cfg.header); |
585 | return; | 585 | return; |
586 | } | 586 | } |
587 | 587 | ||
588 | char *host = cgit_hosturl(); | 588 | char *host = cgit_hosturl(); |
589 | html(cgit_doctype); | 589 | html(cgit_doctype); |
590 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 590 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
591 | html("<head>\n"); | 591 | html("<head>\n"); |
592 | html("<title>"); | 592 | html("<title>"); |
593 | html_txt(ctx->page.title); | 593 | html_txt(ctx->page.title); |
594 | html("</title>\n"); | 594 | html("</title>\n"); |
595 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 595 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
596 | if (ctx->cfg.robots && *ctx->cfg.robots) | 596 | if (ctx->cfg.robots && *ctx->cfg.robots) |
597 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 597 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
598 | html("<link rel='stylesheet' type='text/css' href='"); | 598 | html("<link rel='stylesheet' type='text/css' href='"); |
599 | html_attr(ctx->cfg.css); | 599 | html_attr(ctx->cfg.css); |
600 | html("'/>\n"); | 600 | html("'/>\n"); |
601 | if (ctx->cfg.favicon) { | 601 | if (ctx->cfg.favicon) { |
602 | html("<link rel='shortcut icon' href='"); | 602 | html("<link rel='shortcut icon' href='"); |
603 | html_attr(ctx->cfg.favicon); | 603 | html_attr(ctx->cfg.favicon); |
604 | html("'/>\n"); | 604 | html("'/>\n"); |
605 | } | 605 | } |
606 | if (host && ctx->repo) { | 606 | if (host && ctx->repo) { |
607 | html("<link rel='alternate' title='Atom feed' href='"); | 607 | html("<link rel='alternate' title='Atom feed' href='"); |
608 | html(cgit_httpscheme()); | 608 | html(cgit_httpscheme()); |
609 | html_attr(cgit_hosturl()); | 609 | html_attr(cgit_hosturl()); |
610 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, | 610 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, |
611 | fmt("h=%s", ctx->qry.head))); | 611 | fmt("h=%s", ctx->qry.head))); |
612 | html("' type='application/atom+xml'/>\n"); | 612 | html("' type='application/atom+xml'/>\n"); |
613 | } | 613 | } |
614 | if (ctx->cfg.head_include) | 614 | if (ctx->cfg.head_include) |
615 | html_include(ctx->cfg.head_include); | 615 | html_include(ctx->cfg.head_include); |
616 | html("</head>\n"); | 616 | html("</head>\n"); |
617 | html("<body>\n"); | 617 | html("<body>\n"); |
618 | if (ctx->cfg.header) | 618 | if (ctx->cfg.header) |
619 | html_include(ctx->cfg.header); | 619 | html_include(ctx->cfg.header); |
620 | } | 620 | } |
621 | 621 | ||
622 | void cgit_print_docend() | 622 | void cgit_print_docend() |
623 | { | 623 | { |
624 | html("</div> <!-- class=content -->\n"); | 624 | html("</div> <!-- class=content -->\n"); |
625 | if (ctx.cfg.embedded) { | 625 | if (ctx.cfg.embedded) { |
626 | html("</div> <!-- id=cgit -->\n"); | 626 | html("</div> <!-- id=cgit -->\n"); |
627 | if (ctx.cfg.footer) | 627 | if (ctx.cfg.footer) |
628 | html_include(ctx.cfg.footer); | 628 | html_include(ctx.cfg.footer); |
629 | return; | 629 | return; |
630 | } | 630 | } |
631 | if (ctx.cfg.footer) | 631 | if (ctx.cfg.footer) |
632 | html_include(ctx.cfg.footer); | 632 | html_include(ctx.cfg.footer); |
633 | else { | 633 | else { |
634 | htmlf("<div class='footer'>generated by cgit %s at ", | 634 | htmlf("<div class='footer'>generated by cgit %s at ", |
635 | cgit_version); | 635 | cgit_version); |
636 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 636 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
637 | html("</div>\n"); | 637 | html("</div>\n"); |
638 | } | 638 | } |
639 | html("</div> <!-- id=cgit -->\n"); | 639 | html("</div> <!-- id=cgit -->\n"); |
640 | html("</body>\n</html>\n"); | 640 | html("</body>\n</html>\n"); |
641 | } | 641 | } |
642 | 642 | ||
643 | int print_branch_option(const char *refname, const unsigned char *sha1, | 643 | int print_branch_option(const char *refname, const unsigned char *sha1, |
644 | int flags, void *cb_data) | 644 | int flags, void *cb_data) |
645 | { | 645 | { |
646 | char *name = (char *)refname; | 646 | char *name = (char *)refname; |
647 | html_option(name, name, ctx.qry.head); | 647 | html_option(name, name, ctx.qry.head); |
648 | return 0; | 648 | return 0; |
649 | } | 649 | } |
650 | 650 | ||
651 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 651 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
652 | int flags, void *cb_data) | 652 | int flags, void *cb_data) |
653 | { | 653 | { |
654 | struct tag *tag; | 654 | struct tag *tag; |
655 | struct taginfo *info; | 655 | struct taginfo *info; |
656 | struct object *obj; | 656 | struct object *obj; |
657 | char buf[256], *url; | 657 | char buf[256], *url; |
658 | unsigned char fileid[20]; | 658 | unsigned char fileid[20]; |
659 | int *header = (int *)cb_data; | 659 | int *header = (int *)cb_data; |
660 | 660 | ||
661 | if (prefixcmp(refname, "refs/archives")) | 661 | if (prefixcmp(refname, "refs/archives")) |
662 | return 0; | 662 | return 0; |
663 | strncpy(buf, refname+14, sizeof(buf)); | 663 | strncpy(buf, refname+14, sizeof(buf)); |
664 | obj = parse_object(sha1); | 664 | obj = parse_object(sha1); |
665 | if (!obj) | 665 | if (!obj) |
666 | return 1; | 666 | return 1; |
667 | if (obj->type == OBJ_TAG) { | 667 | if (obj->type == OBJ_TAG) { |
668 | tag = lookup_tag(sha1); | 668 | tag = lookup_tag(sha1); |
669 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 669 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
670 | return 0; | 670 | return 0; |
671 | hashcpy(fileid, tag->tagged->sha1); | 671 | hashcpy(fileid, tag->tagged->sha1); |
672 | } else if (obj->type != OBJ_BLOB) { | 672 | } else if (obj->type != OBJ_BLOB) { |
673 | return 0; | 673 | return 0; |
674 | } else { | 674 | } else { |
675 | hashcpy(fileid, sha1); | 675 | hashcpy(fileid, sha1); |
676 | } | 676 | } |
677 | if (!*header) { | 677 | if (!*header) { |
678 | html("<h1>download</h1>\n"); | 678 | html("<h1>download</h1>\n"); |
679 | *header = 1; | 679 | *header = 1; |
680 | } | 680 | } |
681 | url = cgit_pageurl(ctx.qry.repo, "blob", | 681 | url = cgit_pageurl(ctx.qry.repo, "blob", |
682 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 682 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
683 | buf)); | 683 | buf)); |
684 | html_link_open(url, NULL, "menu"); | 684 | html_link_open(url, NULL, "menu"); |
685 | html_txt(strlpart(buf, 20)); | 685 | html_txt(strlpart(buf, 20)); |
686 | html_link_close(); | 686 | html_link_close(); |
687 | return 0; | 687 | return 0; |
688 | } | 688 | } |
689 | 689 | ||
690 | void cgit_add_hidden_formfields(int incl_head, int incl_search, | 690 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
691 | const char *page) | 691 | const char *page) |
692 | { | 692 | { |
693 | char *url; | 693 | char *url; |
694 | 694 | ||
695 | if (!ctx.cfg.virtual_root) { | 695 | if (!ctx.cfg.virtual_root) { |
696 | url = fmt("%s/%s", ctx.qry.repo, page); | 696 | url = fmt("%s/%s", ctx.qry.repo, page); |
697 | if (ctx.qry.vpath) | 697 | if (ctx.qry.vpath) |
698 | url = fmt("%s/%s", url, ctx.qry.vpath); | 698 | url = fmt("%s/%s", url, ctx.qry.vpath); |
699 | html_hidden("url", url); | 699 | html_hidden("url", url); |
700 | } | 700 | } |
701 | 701 | ||
702 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 702 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
703 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 703 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
704 | html_hidden("h", ctx.qry.head); | 704 | html_hidden("h", ctx.qry.head); |
705 | 705 | ||
706 | if (ctx.qry.sha1) | 706 | if (ctx.qry.sha1) |
707 | html_hidden("id", ctx.qry.sha1); | 707 | html_hidden("id", ctx.qry.sha1); |
708 | if (ctx.qry.sha2) | 708 | if (ctx.qry.sha2) |
709 | html_hidden("id2", ctx.qry.sha2); | 709 | html_hidden("id2", ctx.qry.sha2); |
710 | if (ctx.qry.showmsg) | 710 | if (ctx.qry.showmsg) |
711 | html_hidden("showmsg", "1"); | 711 | html_hidden("showmsg", "1"); |
712 | 712 | ||
713 | if (incl_search) { | 713 | if (incl_search) { |
714 | if (ctx.qry.grep) | 714 | if (ctx.qry.grep) |
715 | html_hidden("qt", ctx.qry.grep); | 715 | html_hidden("qt", ctx.qry.grep); |
716 | if (ctx.qry.search) | 716 | if (ctx.qry.search) |
717 | html_hidden("q", ctx.qry.search); | 717 | html_hidden("q", ctx.qry.search); |
718 | } | 718 | } |
719 | } | 719 | } |
720 | 720 | ||
721 | static const char *hc(struct cgit_context *ctx, const char *page) | 721 | static const char *hc(struct cgit_context *ctx, const char *page) |
722 | { | 722 | { |
723 | return strcmp(ctx->qry.page, page) ? NULL : "active"; | 723 | return strcmp(ctx->qry.page, page) ? NULL : "active"; |
724 | } | 724 | } |
725 | 725 | ||
726 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) | 726 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) |
727 | { | 727 | { |
728 | char *old_path = ctx->qry.path; | 728 | char *old_path = ctx->qry.path; |
729 | char *p = path, *q, *end = path + strlen(path); | 729 | char *p = path, *q, *end = path + strlen(path); |
730 | 730 | ||
731 | ctx->qry.path = NULL; | 731 | ctx->qry.path = NULL; |
732 | cgit_self_link("root", NULL, NULL, ctx); | 732 | cgit_self_link("root", NULL, NULL, ctx); |
733 | ctx->qry.path = p = path; | 733 | ctx->qry.path = p = path; |
734 | while (p < end) { | 734 | while (p < end) { |
735 | if (!(q = strchr(p, '/'))) | 735 | if (!(q = strchr(p, '/'))) |
736 | q = end; | 736 | q = end; |
737 | *q = '\0'; | 737 | *q = '\0'; |
738 | html_txt("/"); | 738 | html_txt("/"); |
739 | cgit_self_link(p, NULL, NULL, ctx); | 739 | cgit_self_link(p, NULL, NULL, ctx); |
740 | if (q < end) | 740 | if (q < end) |
741 | *q = '/'; | 741 | *q = '/'; |
742 | p = q + 1; | 742 | p = q + 1; |
743 | } | 743 | } |
744 | ctx->qry.path = old_path; | 744 | ctx->qry.path = old_path; |
745 | } | 745 | } |
746 | 746 | ||
747 | static void print_header(struct cgit_context *ctx) | 747 | static void print_header(struct cgit_context *ctx) |
748 | { | 748 | { |
749 | html("<table id='header'>\n"); | 749 | html("<table id='header'>\n"); |
750 | html("<tr>\n"); | 750 | html("<tr>\n"); |
751 | 751 | ||
752 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { | 752 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { |
753 | html("<td class='logo' rowspan='2'><a href='"); | 753 | html("<td class='logo' rowspan='2'><a href='"); |
754 | if (ctx->cfg.logo_link) | 754 | if (ctx->cfg.logo_link) |
755 | html_attr(ctx->cfg.logo_link); | 755 | html_attr(ctx->cfg.logo_link); |
756 | else | 756 | else |
757 | html_attr(cgit_rooturl()); | 757 | html_attr(cgit_rooturl()); |
758 | html("'><img src='"); | 758 | html("'><img src='"); |
759 | html_attr(ctx->cfg.logo); | 759 | html_attr(ctx->cfg.logo); |
760 | html("' alt='cgit logo'/></a></td>\n"); | 760 | html("' alt='cgit logo'/></a></td>\n"); |
761 | } | 761 | } |
762 | 762 | ||
763 | html("<td class='main'>"); | 763 | html("<td class='main'>"); |
764 | if (ctx->repo) { | 764 | if (ctx->repo) { |
765 | cgit_index_link("index", NULL, NULL, NULL, 0); | 765 | cgit_index_link("index", NULL, NULL, NULL, 0); |
766 | html(" : "); | 766 | html(" : "); |
767 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 767 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
768 | html("</td><td class='form'>"); | 768 | html("</td><td class='form'>"); |
769 | html("<form method='get' action=''>\n"); | 769 | html("<form method='get' action=''>\n"); |
770 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); | 770 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); |
771 | html("<select name='h' onchange='this.form.submit();'>\n"); | 771 | html("<select name='h' onchange='this.form.submit();'>\n"); |
772 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 772 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
773 | html("</select> "); | 773 | html("</select> "); |
774 | html("<input type='submit' name='' value='switch'/>"); | 774 | html("<input type='submit' name='' value='switch'/>"); |
775 | html("</form>"); | 775 | html("</form>"); |
776 | } else | 776 | } else |
777 | html_txt(ctx->cfg.root_title); | 777 | html_txt(ctx->cfg.root_title); |
778 | html("</td></tr>\n"); | 778 | html("</td></tr>\n"); |
779 | 779 | ||
780 | html("<tr><td class='sub'>"); | 780 | html("<tr><td class='sub'>"); |
781 | if (ctx->repo) { | 781 | if (ctx->repo) { |
782 | html_txt(ctx->repo->desc); | 782 | html_txt(ctx->repo->desc); |
783 | html("</td><td class='sub right'>"); | 783 | html("</td><td class='sub right'>"); |
784 | html_txt(ctx->repo->owner); | 784 | html_txt(ctx->repo->owner); |
785 | } else { | 785 | } else { |
786 | if (ctx->cfg.root_desc) | 786 | if (ctx->cfg.root_desc) |
787 | html_txt(ctx->cfg.root_desc); | 787 | html_txt(ctx->cfg.root_desc); |
788 | else if (ctx->cfg.index_info) | 788 | else if (ctx->cfg.index_info) |
789 | html_include(ctx->cfg.index_info); | 789 | html_include(ctx->cfg.index_info); |
790 | } | 790 | } |
791 | html("</td></tr></table>\n"); | 791 | html("</td></tr></table>\n"); |
792 | } | 792 | } |
793 | 793 | ||
794 | void cgit_print_pageheader(struct cgit_context *ctx) | 794 | void cgit_print_pageheader(struct cgit_context *ctx) |
795 | { | 795 | { |
796 | html("<div id='cgit'>"); | 796 | html("<div id='cgit'>"); |
797 | if (!ctx->cfg.noheader) | 797 | if (!ctx->cfg.noheader) |
798 | print_header(ctx); | 798 | print_header(ctx); |
799 | 799 | ||
800 | html("<table class='tabs'><tr><td>\n"); | 800 | html("<table class='tabs'><tr><td>\n"); |
801 | if (ctx->repo) { | 801 | if (ctx->repo) { |
802 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), | 802 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), |
803 | ctx->qry.head); | 803 | ctx->qry.head); |
804 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, | 804 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, |
805 | ctx->qry.sha1, NULL); | 805 | ctx->qry.sha1, NULL); |
806 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, | 806 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, |
807 | NULL, ctx->qry.vpath, 0, NULL, NULL, | 807 | NULL, ctx->qry.vpath, 0, NULL, NULL, |
808 | ctx->qry.showmsg); | 808 | ctx->qry.showmsg); |
809 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, | 809 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, |
810 | ctx->qry.sha1, ctx->qry.vpath); | 810 | ctx->qry.sha1, ctx->qry.vpath); |
811 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), | 811 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), |
812 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); | 812 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); |
813 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, | 813 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, |
814 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); | 814 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); |
815 | if (ctx->repo->max_stats) | 815 | if (ctx->repo->max_stats) |
816 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), | 816 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), |
817 | ctx->qry.head, ctx->qry.vpath); | 817 | ctx->qry.head, ctx->qry.vpath); |
818 | if (ctx->repo->readme) | 818 | if (ctx->repo->readme) |
819 | reporevlink("about", "about", NULL, | 819 | reporevlink("about", "about", NULL, |
820 | hc(ctx, "about"), ctx->qry.head, NULL, | 820 | hc(ctx, "about"), ctx->qry.head, NULL, |
821 | NULL); | 821 | NULL); |
822 | html("</td><td class='form'>"); | 822 | html("</td><td class='form'>"); |
823 | html("<form class='right' method='get' action='"); | 823 | html("<form class='right' method='get' action='"); |
824 | if (ctx->cfg.virtual_root) | 824 | if (ctx->cfg.virtual_root) |
825 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 825 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
826 | ctx->qry.vpath, NULL)); | 826 | ctx->qry.vpath, NULL)); |
827 | html("'>\n"); | 827 | html("'>\n"); |
828 | cgit_add_hidden_formfields(1, 0, "log"); | 828 | cgit_add_hidden_formfields(1, 0, "log"); |
829 | html("<select name='qt'>\n"); | 829 | html("<select name='qt'>\n"); |
830 | html_option("grep", "log msg", ctx->qry.grep); | 830 | html_option("grep", "log msg", ctx->qry.grep); |
831 | html_option("author", "author", ctx->qry.grep); | 831 | html_option("author", "author", ctx->qry.grep); |
832 | html_option("committer", "committer", ctx->qry.grep); | 832 | html_option("committer", "committer", ctx->qry.grep); |
833 | html_option("range", "range", ctx->qry.grep); | ||
833 | html("</select>\n"); | 834 | html("</select>\n"); |
834 | html("<input class='txt' type='text' size='10' name='q' value='"); | 835 | html("<input class='txt' type='text' size='10' name='q' value='"); |
835 | html_attr(ctx->qry.search); | 836 | html_attr(ctx->qry.search); |
836 | html("'/>\n"); | 837 | html("'/>\n"); |
837 | html("<input type='submit' value='search'/>\n"); | 838 | html("<input type='submit' value='search'/>\n"); |
838 | html("</form>\n"); | 839 | html("</form>\n"); |
839 | } else { | 840 | } else { |
840 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); | 841 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); |
841 | if (ctx->cfg.root_readme) | 842 | if (ctx->cfg.root_readme) |
842 | site_link("about", "about", NULL, hc(ctx, "about"), | 843 | site_link("about", "about", NULL, hc(ctx, "about"), |
843 | NULL, 0); | 844 | NULL, 0); |
844 | html("</td><td class='form'>"); | 845 | html("</td><td class='form'>"); |
845 | html("<form method='get' action='"); | 846 | html("<form method='get' action='"); |
846 | html_attr(cgit_rooturl()); | 847 | html_attr(cgit_rooturl()); |
847 | html("'>\n"); | 848 | html("'>\n"); |
848 | html("<input type='text' name='q' size='10' value='"); | 849 | html("<input type='text' name='q' size='10' value='"); |
849 | html_attr(ctx->qry.search); | 850 | html_attr(ctx->qry.search); |
850 | html("'/>\n"); | 851 | html("'/>\n"); |
851 | html("<input type='submit' value='search'/>\n"); | 852 | html("<input type='submit' value='search'/>\n"); |
852 | html("</form>"); | 853 | html("</form>"); |
853 | } | 854 | } |
854 | html("</td></tr></table>\n"); | 855 | html("</td></tr></table>\n"); |
855 | if (ctx->qry.vpath) { | 856 | if (ctx->qry.vpath) { |
856 | html("<div class='path'>"); | 857 | html("<div class='path'>"); |
857 | html("path: "); | 858 | html("path: "); |
858 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); | 859 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); |
859 | html("</div>"); | 860 | html("</div>"); |
860 | } | 861 | } |
861 | html("<div class='content'>"); | 862 | html("<div class='content'>"); |
862 | } | 863 | } |
863 | 864 | ||
864 | void cgit_print_filemode(unsigned short mode) | 865 | void cgit_print_filemode(unsigned short mode) |
865 | { | 866 | { |
866 | if (S_ISDIR(mode)) | 867 | if (S_ISDIR(mode)) |
867 | html("d"); | 868 | html("d"); |
868 | else if (S_ISLNK(mode)) | 869 | else if (S_ISLNK(mode)) |
869 | html("l"); | 870 | html("l"); |
870 | else if (S_ISGITLINK(mode)) | 871 | else if (S_ISGITLINK(mode)) |
871 | html("m"); | 872 | html("m"); |
872 | else | 873 | else |
873 | html("-"); | 874 | html("-"); |
874 | html_fileperm(mode >> 6); | 875 | html_fileperm(mode >> 6); |
875 | html_fileperm(mode >> 3); | 876 | html_fileperm(mode >> 3); |
876 | html_fileperm(mode); | 877 | html_fileperm(mode); |
877 | } | 878 | } |
878 | 879 | ||
879 | void cgit_print_snapshot_links(const char *repo, const char *head, | 880 | void cgit_print_snapshot_links(const char *repo, const char *head, |
880 | const char *hex, int snapshots) | 881 | const char *hex, int snapshots) |
881 | { | 882 | { |
882 | const struct cgit_snapshot_format* f; | 883 | const struct cgit_snapshot_format* f; |
883 | char *prefix; | 884 | char *prefix; |
884 | char *filename; | 885 | char *filename; |
885 | unsigned char sha1[20]; | 886 | unsigned char sha1[20]; |
886 | 887 | ||
887 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && | 888 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && |
888 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) | 889 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) |
889 | hex++; | 890 | hex++; |
890 | prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); | 891 | prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); |
891 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 892 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
892 | if (!(snapshots & f->bit)) | 893 | if (!(snapshots & f->bit)) |
893 | continue; | 894 | continue; |
894 | filename = fmt("%s%s", prefix, f->suffix); | 895 | filename = fmt("%s%s", prefix, f->suffix); |
895 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); | 896 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); |
896 | html("<br/>"); | 897 | html("<br/>"); |
897 | } | 898 | } |
898 | } | 899 | } |