author | Lars Hjemli <hjemli@gmail.com> | 2009-02-19 21:38:36 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-02-19 21:38:36 (UTC) |
commit | 488a214a81a25c6397c56822ed1713f51dddc520 (patch) (unidiff) | |
tree | 93b3be74f6c7b3ae6557a9d3c5c2856ff5efe8ed | |
parent | 6063e7b5532481ffaa7a6f080de28547983bbeb7 (diff) | |
download | cgit-488a214a81a25c6397c56822ed1713f51dddc520.zip cgit-488a214a81a25c6397c56822ed1713f51dddc520.tar.gz cgit-488a214a81a25c6397c56822ed1713f51dddc520.tar.bz2 |
Add support for ETag in 'plain' view
When downloading a blob identified by its path, the client might want
to know if the blob has been modified since a previous download of the
same path. To this end, an ETag containing the blob SHA1 seems to be
ideal.
Todo: add support for HEAD requests...
Suggested-by: Owen Taylor <otaylor@redhat.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 1 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | ui-plain.c | 1 | ||||
-rw-r--r-- | ui-shared.c | 2 |
4 files changed, 5 insertions, 0 deletions
@@ -113,192 +113,193 @@ void config_cb(const char *name, const char *value) | |||
113 | ctx.repo->defbranch = xstrdup(value); | 113 | ctx.repo->defbranch = xstrdup(value); |
114 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | 114 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
115 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | 115 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
116 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | 116 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
117 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 117 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
118 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | 118 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
119 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 119 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
120 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) | 120 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) |
121 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); | 121 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); |
122 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | 122 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
123 | ctx.repo->module_link= xstrdup(value); | 123 | ctx.repo->module_link= xstrdup(value); |
124 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | 124 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
125 | if (*value == '/') | 125 | if (*value == '/') |
126 | ctx.repo->readme = xstrdup(value); | 126 | ctx.repo->readme = xstrdup(value); |
127 | else | 127 | else |
128 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | 128 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
129 | } else if (!strcmp(name, "include")) | 129 | } else if (!strcmp(name, "include")) |
130 | parse_configfile(value, config_cb); | 130 | parse_configfile(value, config_cb); |
131 | } | 131 | } |
132 | 132 | ||
133 | static void querystring_cb(const char *name, const char *value) | 133 | static void querystring_cb(const char *name, const char *value) |
134 | { | 134 | { |
135 | if (!strcmp(name,"r")) { | 135 | if (!strcmp(name,"r")) { |
136 | ctx.qry.repo = xstrdup(value); | 136 | ctx.qry.repo = xstrdup(value); |
137 | ctx.repo = cgit_get_repoinfo(value); | 137 | ctx.repo = cgit_get_repoinfo(value); |
138 | } else if (!strcmp(name, "p")) { | 138 | } else if (!strcmp(name, "p")) { |
139 | ctx.qry.page = xstrdup(value); | 139 | ctx.qry.page = xstrdup(value); |
140 | } else if (!strcmp(name, "url")) { | 140 | } else if (!strcmp(name, "url")) { |
141 | ctx.qry.url = xstrdup(value); | 141 | ctx.qry.url = xstrdup(value); |
142 | cgit_parse_url(value); | 142 | cgit_parse_url(value); |
143 | } else if (!strcmp(name, "qt")) { | 143 | } else if (!strcmp(name, "qt")) { |
144 | ctx.qry.grep = xstrdup(value); | 144 | ctx.qry.grep = xstrdup(value); |
145 | } else if (!strcmp(name, "q")) { | 145 | } else if (!strcmp(name, "q")) { |
146 | ctx.qry.search = xstrdup(value); | 146 | ctx.qry.search = xstrdup(value); |
147 | } else if (!strcmp(name, "h")) { | 147 | } else if (!strcmp(name, "h")) { |
148 | ctx.qry.head = xstrdup(value); | 148 | ctx.qry.head = xstrdup(value); |
149 | ctx.qry.has_symref = 1; | 149 | ctx.qry.has_symref = 1; |
150 | } else if (!strcmp(name, "id")) { | 150 | } else if (!strcmp(name, "id")) { |
151 | ctx.qry.sha1 = xstrdup(value); | 151 | ctx.qry.sha1 = xstrdup(value); |
152 | ctx.qry.has_sha1 = 1; | 152 | ctx.qry.has_sha1 = 1; |
153 | } else if (!strcmp(name, "id2")) { | 153 | } else if (!strcmp(name, "id2")) { |
154 | ctx.qry.sha2 = xstrdup(value); | 154 | ctx.qry.sha2 = xstrdup(value); |
155 | ctx.qry.has_sha1 = 1; | 155 | ctx.qry.has_sha1 = 1; |
156 | } else if (!strcmp(name, "ofs")) { | 156 | } else if (!strcmp(name, "ofs")) { |
157 | ctx.qry.ofs = atoi(value); | 157 | ctx.qry.ofs = atoi(value); |
158 | } else if (!strcmp(name, "path")) { | 158 | } else if (!strcmp(name, "path")) { |
159 | ctx.qry.path = trim_end(value, '/'); | 159 | ctx.qry.path = trim_end(value, '/'); |
160 | } else if (!strcmp(name, "name")) { | 160 | } else if (!strcmp(name, "name")) { |
161 | ctx.qry.name = xstrdup(value); | 161 | ctx.qry.name = xstrdup(value); |
162 | } else if (!strcmp(name, "mimetype")) { | 162 | } else if (!strcmp(name, "mimetype")) { |
163 | ctx.qry.mimetype = xstrdup(value); | 163 | ctx.qry.mimetype = xstrdup(value); |
164 | } else if (!strcmp(name, "s")){ | 164 | } else if (!strcmp(name, "s")){ |
165 | ctx.qry.sort = xstrdup(value); | 165 | ctx.qry.sort = xstrdup(value); |
166 | } else if (!strcmp(name, "showmsg")) { | 166 | } else if (!strcmp(name, "showmsg")) { |
167 | ctx.qry.showmsg = atoi(value); | 167 | ctx.qry.showmsg = atoi(value); |
168 | } else if (!strcmp(name, "period")) { | 168 | } else if (!strcmp(name, "period")) { |
169 | ctx.qry.period = xstrdup(value); | 169 | ctx.qry.period = xstrdup(value); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | static void prepare_context(struct cgit_context *ctx) | 173 | static void prepare_context(struct cgit_context *ctx) |
174 | { | 174 | { |
175 | memset(ctx, 0, sizeof(ctx)); | 175 | memset(ctx, 0, sizeof(ctx)); |
176 | ctx->cfg.agefile = "info/web/last-modified"; | 176 | ctx->cfg.agefile = "info/web/last-modified"; |
177 | ctx->cfg.nocache = 0; | 177 | ctx->cfg.nocache = 0; |
178 | ctx->cfg.cache_size = 0; | 178 | ctx->cfg.cache_size = 0; |
179 | ctx->cfg.cache_dynamic_ttl = 5; | 179 | ctx->cfg.cache_dynamic_ttl = 5; |
180 | ctx->cfg.cache_max_create_time = 5; | 180 | ctx->cfg.cache_max_create_time = 5; |
181 | ctx->cfg.cache_repo_ttl = 5; | 181 | ctx->cfg.cache_repo_ttl = 5; |
182 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 182 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
183 | ctx->cfg.cache_root_ttl = 5; | 183 | ctx->cfg.cache_root_ttl = 5; |
184 | ctx->cfg.cache_static_ttl = -1; | 184 | ctx->cfg.cache_static_ttl = -1; |
185 | ctx->cfg.css = "/cgit.css"; | 185 | ctx->cfg.css = "/cgit.css"; |
186 | ctx->cfg.logo = "/git-logo.png"; | 186 | ctx->cfg.logo = "/git-logo.png"; |
187 | ctx->cfg.local_time = 0; | 187 | ctx->cfg.local_time = 0; |
188 | ctx->cfg.max_repo_count = 50; | 188 | ctx->cfg.max_repo_count = 50; |
189 | ctx->cfg.max_commit_count = 50; | 189 | ctx->cfg.max_commit_count = 50; |
190 | ctx->cfg.max_lock_attempts = 5; | 190 | ctx->cfg.max_lock_attempts = 5; |
191 | ctx->cfg.max_msg_len = 80; | 191 | ctx->cfg.max_msg_len = 80; |
192 | ctx->cfg.max_repodesc_len = 80; | 192 | ctx->cfg.max_repodesc_len = 80; |
193 | ctx->cfg.max_stats = 0; | 193 | ctx->cfg.max_stats = 0; |
194 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 194 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
195 | ctx->cfg.renamelimit = -1; | 195 | ctx->cfg.renamelimit = -1; |
196 | ctx->cfg.robots = "index, nofollow"; | 196 | ctx->cfg.robots = "index, nofollow"; |
197 | ctx->cfg.root_title = "Git repository browser"; | 197 | ctx->cfg.root_title = "Git repository browser"; |
198 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 198 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
199 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 199 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
200 | ctx->cfg.summary_branches = 10; | 200 | ctx->cfg.summary_branches = 10; |
201 | ctx->cfg.summary_log = 10; | 201 | ctx->cfg.summary_log = 10; |
202 | ctx->cfg.summary_tags = 10; | 202 | ctx->cfg.summary_tags = 10; |
203 | ctx->page.mimetype = "text/html"; | 203 | ctx->page.mimetype = "text/html"; |
204 | ctx->page.charset = PAGE_ENCODING; | 204 | ctx->page.charset = PAGE_ENCODING; |
205 | ctx->page.filename = NULL; | 205 | ctx->page.filename = NULL; |
206 | ctx->page.size = 0; | 206 | ctx->page.size = 0; |
207 | ctx->page.modified = time(NULL); | 207 | ctx->page.modified = time(NULL); |
208 | ctx->page.expires = ctx->page.modified; | 208 | ctx->page.expires = ctx->page.modified; |
209 | ctx->page.etag = NULL; | ||
209 | } | 210 | } |
210 | 211 | ||
211 | struct refmatch { | 212 | struct refmatch { |
212 | char *req_ref; | 213 | char *req_ref; |
213 | char *first_ref; | 214 | char *first_ref; |
214 | int match; | 215 | int match; |
215 | }; | 216 | }; |
216 | 217 | ||
217 | int find_current_ref(const char *refname, const unsigned char *sha1, | 218 | int find_current_ref(const char *refname, const unsigned char *sha1, |
218 | int flags, void *cb_data) | 219 | int flags, void *cb_data) |
219 | { | 220 | { |
220 | struct refmatch *info; | 221 | struct refmatch *info; |
221 | 222 | ||
222 | info = (struct refmatch *)cb_data; | 223 | info = (struct refmatch *)cb_data; |
223 | if (!strcmp(refname, info->req_ref)) | 224 | if (!strcmp(refname, info->req_ref)) |
224 | info->match = 1; | 225 | info->match = 1; |
225 | if (!info->first_ref) | 226 | if (!info->first_ref) |
226 | info->first_ref = xstrdup(refname); | 227 | info->first_ref = xstrdup(refname); |
227 | return info->match; | 228 | return info->match; |
228 | } | 229 | } |
229 | 230 | ||
230 | char *find_default_branch(struct cgit_repo *repo) | 231 | char *find_default_branch(struct cgit_repo *repo) |
231 | { | 232 | { |
232 | struct refmatch info; | 233 | struct refmatch info; |
233 | char *ref; | 234 | char *ref; |
234 | 235 | ||
235 | info.req_ref = repo->defbranch; | 236 | info.req_ref = repo->defbranch; |
236 | info.first_ref = NULL; | 237 | info.first_ref = NULL; |
237 | info.match = 0; | 238 | info.match = 0; |
238 | for_each_branch_ref(find_current_ref, &info); | 239 | for_each_branch_ref(find_current_ref, &info); |
239 | if (info.match) | 240 | if (info.match) |
240 | ref = info.req_ref; | 241 | ref = info.req_ref; |
241 | else | 242 | else |
242 | ref = info.first_ref; | 243 | ref = info.first_ref; |
243 | if (ref) | 244 | if (ref) |
244 | ref = xstrdup(ref); | 245 | ref = xstrdup(ref); |
245 | return ref; | 246 | return ref; |
246 | } | 247 | } |
247 | 248 | ||
248 | static int prepare_repo_cmd(struct cgit_context *ctx) | 249 | static int prepare_repo_cmd(struct cgit_context *ctx) |
249 | { | 250 | { |
250 | char *tmp; | 251 | char *tmp; |
251 | unsigned char sha1[20]; | 252 | unsigned char sha1[20]; |
252 | int nongit = 0; | 253 | int nongit = 0; |
253 | 254 | ||
254 | setenv("GIT_DIR", ctx->repo->path, 1); | 255 | setenv("GIT_DIR", ctx->repo->path, 1); |
255 | setup_git_directory_gently(&nongit); | 256 | setup_git_directory_gently(&nongit); |
256 | if (nongit) { | 257 | if (nongit) { |
257 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, | 258 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
258 | "config error"); | 259 | "config error"); |
259 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); | 260 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
260 | ctx->repo = NULL; | 261 | ctx->repo = NULL; |
261 | cgit_print_http_headers(ctx); | 262 | cgit_print_http_headers(ctx); |
262 | cgit_print_docstart(ctx); | 263 | cgit_print_docstart(ctx); |
263 | cgit_print_pageheader(ctx); | 264 | cgit_print_pageheader(ctx); |
264 | cgit_print_error(tmp); | 265 | cgit_print_error(tmp); |
265 | cgit_print_docend(); | 266 | cgit_print_docend(); |
266 | return 1; | 267 | return 1; |
267 | } | 268 | } |
268 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 269 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
269 | 270 | ||
270 | if (!ctx->qry.head) { | 271 | if (!ctx->qry.head) { |
271 | ctx->qry.nohead = 1; | 272 | ctx->qry.nohead = 1; |
272 | ctx->qry.head = find_default_branch(ctx->repo); | 273 | ctx->qry.head = find_default_branch(ctx->repo); |
273 | ctx->repo->defbranch = ctx->qry.head; | 274 | ctx->repo->defbranch = ctx->qry.head; |
274 | } | 275 | } |
275 | 276 | ||
276 | if (!ctx->qry.head) { | 277 | if (!ctx->qry.head) { |
277 | cgit_print_http_headers(ctx); | 278 | cgit_print_http_headers(ctx); |
278 | cgit_print_docstart(ctx); | 279 | cgit_print_docstart(ctx); |
279 | cgit_print_pageheader(ctx); | 280 | cgit_print_pageheader(ctx); |
280 | cgit_print_error("Repository seems to be empty"); | 281 | cgit_print_error("Repository seems to be empty"); |
281 | cgit_print_docend(); | 282 | cgit_print_docend(); |
282 | return 1; | 283 | return 1; |
283 | } | 284 | } |
284 | 285 | ||
285 | if (get_sha1(ctx->qry.head, sha1)) { | 286 | if (get_sha1(ctx->qry.head, sha1)) { |
286 | tmp = xstrdup(ctx->qry.head); | 287 | tmp = xstrdup(ctx->qry.head); |
287 | ctx->qry.head = ctx->repo->defbranch; | 288 | ctx->qry.head = ctx->repo->defbranch; |
288 | cgit_print_http_headers(ctx); | 289 | cgit_print_http_headers(ctx); |
289 | cgit_print_docstart(ctx); | 290 | cgit_print_docstart(ctx); |
290 | cgit_print_pageheader(ctx); | 291 | cgit_print_pageheader(ctx); |
291 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 292 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
292 | cgit_print_docend(); | 293 | cgit_print_docend(); |
293 | return 1; | 294 | return 1; |
294 | } | 295 | } |
295 | return 0; | 296 | return 0; |
296 | } | 297 | } |
297 | 298 | ||
298 | static void process_request(void *cbdata) | 299 | static void process_request(void *cbdata) |
299 | { | 300 | { |
300 | struct cgit_context *ctx = cbdata; | 301 | struct cgit_context *ctx = cbdata; |
301 | struct cgit_cmd *cmd; | 302 | struct cgit_cmd *cmd; |
302 | 303 | ||
303 | cmd = cgit_get_cmd(ctx); | 304 | cmd = cgit_get_cmd(ctx); |
304 | if (!cmd) { | 305 | if (!cmd) { |
@@ -87,160 +87,161 @@ struct commitinfo { | |||
87 | 87 | ||
88 | struct taginfo { | 88 | struct taginfo { |
89 | char *tagger; | 89 | char *tagger; |
90 | char *tagger_email; | 90 | char *tagger_email; |
91 | unsigned long tagger_date; | 91 | unsigned long tagger_date; |
92 | char *msg; | 92 | char *msg; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | struct refinfo { | 95 | struct refinfo { |
96 | const char *refname; | 96 | const char *refname; |
97 | struct object *object; | 97 | struct object *object; |
98 | union { | 98 | union { |
99 | struct taginfo *tag; | 99 | struct taginfo *tag; |
100 | struct commitinfo *commit; | 100 | struct commitinfo *commit; |
101 | }; | 101 | }; |
102 | }; | 102 | }; |
103 | 103 | ||
104 | struct reflist { | 104 | struct reflist { |
105 | struct refinfo **refs; | 105 | struct refinfo **refs; |
106 | int alloc; | 106 | int alloc; |
107 | int count; | 107 | int count; |
108 | }; | 108 | }; |
109 | 109 | ||
110 | struct cgit_query { | 110 | struct cgit_query { |
111 | int has_symref; | 111 | int has_symref; |
112 | int has_sha1; | 112 | int has_sha1; |
113 | char *raw; | 113 | char *raw; |
114 | char *repo; | 114 | char *repo; |
115 | char *page; | 115 | char *page; |
116 | char *search; | 116 | char *search; |
117 | char *grep; | 117 | char *grep; |
118 | char *head; | 118 | char *head; |
119 | char *sha1; | 119 | char *sha1; |
120 | char *sha2; | 120 | char *sha2; |
121 | char *path; | 121 | char *path; |
122 | char *name; | 122 | char *name; |
123 | char *mimetype; | 123 | char *mimetype; |
124 | char *url; | 124 | char *url; |
125 | char *period; | 125 | char *period; |
126 | int ofs; | 126 | int ofs; |
127 | int nohead; | 127 | int nohead; |
128 | char *sort; | 128 | char *sort; |
129 | int showmsg; | 129 | int showmsg; |
130 | }; | 130 | }; |
131 | 131 | ||
132 | struct cgit_config { | 132 | struct cgit_config { |
133 | char *agefile; | 133 | char *agefile; |
134 | char *cache_root; | 134 | char *cache_root; |
135 | char *clone_prefix; | 135 | char *clone_prefix; |
136 | char *css; | 136 | char *css; |
137 | char *favicon; | 137 | char *favicon; |
138 | char *footer; | 138 | char *footer; |
139 | char *header; | 139 | char *header; |
140 | char *index_header; | 140 | char *index_header; |
141 | char *index_info; | 141 | char *index_info; |
142 | char *logo; | 142 | char *logo; |
143 | char *logo_link; | 143 | char *logo_link; |
144 | char *module_link; | 144 | char *module_link; |
145 | char *repo_group; | 145 | char *repo_group; |
146 | char *robots; | 146 | char *robots; |
147 | char *root_title; | 147 | char *root_title; |
148 | char *root_desc; | 148 | char *root_desc; |
149 | char *root_readme; | 149 | char *root_readme; |
150 | char *script_name; | 150 | char *script_name; |
151 | char *virtual_root; | 151 | char *virtual_root; |
152 | int cache_size; | 152 | int cache_size; |
153 | int cache_dynamic_ttl; | 153 | int cache_dynamic_ttl; |
154 | int cache_max_create_time; | 154 | int cache_max_create_time; |
155 | int cache_repo_ttl; | 155 | int cache_repo_ttl; |
156 | int cache_root_ttl; | 156 | int cache_root_ttl; |
157 | int cache_static_ttl; | 157 | int cache_static_ttl; |
158 | int enable_index_links; | 158 | int enable_index_links; |
159 | int enable_log_filecount; | 159 | int enable_log_filecount; |
160 | int enable_log_linecount; | 160 | int enable_log_linecount; |
161 | int local_time; | 161 | int local_time; |
162 | int max_repo_count; | 162 | int max_repo_count; |
163 | int max_commit_count; | 163 | int max_commit_count; |
164 | int max_lock_attempts; | 164 | int max_lock_attempts; |
165 | int max_msg_len; | 165 | int max_msg_len; |
166 | int max_repodesc_len; | 166 | int max_repodesc_len; |
167 | int max_stats; | 167 | int max_stats; |
168 | int nocache; | 168 | int nocache; |
169 | int renamelimit; | 169 | int renamelimit; |
170 | int snapshots; | 170 | int snapshots; |
171 | int summary_branches; | 171 | int summary_branches; |
172 | int summary_log; | 172 | int summary_log; |
173 | int summary_tags; | 173 | int summary_tags; |
174 | }; | 174 | }; |
175 | 175 | ||
176 | struct cgit_page { | 176 | struct cgit_page { |
177 | time_t modified; | 177 | time_t modified; |
178 | time_t expires; | 178 | time_t expires; |
179 | size_t size; | 179 | size_t size; |
180 | char *mimetype; | 180 | char *mimetype; |
181 | char *charset; | 181 | char *charset; |
182 | char *filename; | 182 | char *filename; |
183 | char *etag; | ||
183 | char *title; | 184 | char *title; |
184 | }; | 185 | }; |
185 | 186 | ||
186 | struct cgit_context { | 187 | struct cgit_context { |
187 | struct cgit_query qry; | 188 | struct cgit_query qry; |
188 | struct cgit_config cfg; | 189 | struct cgit_config cfg; |
189 | struct cgit_repo *repo; | 190 | struct cgit_repo *repo; |
190 | struct cgit_page page; | 191 | struct cgit_page page; |
191 | }; | 192 | }; |
192 | 193 | ||
193 | struct cgit_snapshot_format { | 194 | struct cgit_snapshot_format { |
194 | const char *suffix; | 195 | const char *suffix; |
195 | const char *mimetype; | 196 | const char *mimetype; |
196 | write_archive_fn_t write_func; | 197 | write_archive_fn_t write_func; |
197 | int bit; | 198 | int bit; |
198 | }; | 199 | }; |
199 | 200 | ||
200 | extern const char *cgit_version; | 201 | extern const char *cgit_version; |
201 | 202 | ||
202 | extern struct cgit_repolist cgit_repolist; | 203 | extern struct cgit_repolist cgit_repolist; |
203 | extern struct cgit_context ctx; | 204 | extern struct cgit_context ctx; |
204 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; | 205 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
205 | 206 | ||
206 | extern struct cgit_repo *cgit_add_repo(const char *url); | 207 | extern struct cgit_repo *cgit_add_repo(const char *url); |
207 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); | 208 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
208 | extern void cgit_repo_config_cb(const char *name, const char *value); | 209 | extern void cgit_repo_config_cb(const char *name, const char *value); |
209 | 210 | ||
210 | extern int chk_zero(int result, char *msg); | 211 | extern int chk_zero(int result, char *msg); |
211 | extern int chk_positive(int result, char *msg); | 212 | extern int chk_positive(int result, char *msg); |
212 | extern int chk_non_negative(int result, char *msg); | 213 | extern int chk_non_negative(int result, char *msg); |
213 | 214 | ||
214 | extern char *trim_end(const char *str, char c); | 215 | extern char *trim_end(const char *str, char c); |
215 | extern char *strlpart(char *txt, int maxlen); | 216 | extern char *strlpart(char *txt, int maxlen); |
216 | extern char *strrpart(char *txt, int maxlen); | 217 | extern char *strrpart(char *txt, int maxlen); |
217 | 218 | ||
218 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 219 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
219 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 220 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
220 | int flags, void *cb_data); | 221 | int flags, void *cb_data); |
221 | 222 | ||
222 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 223 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
223 | 224 | ||
224 | extern int cgit_diff_files(const unsigned char *old_sha1, | 225 | extern int cgit_diff_files(const unsigned char *old_sha1, |
225 | const unsigned char *new_sha1, | 226 | const unsigned char *new_sha1, |
226 | unsigned long *old_size, unsigned long *new_size, | 227 | unsigned long *old_size, unsigned long *new_size, |
227 | int *binary, linediff_fn fn); | 228 | int *binary, linediff_fn fn); |
228 | 229 | ||
229 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 230 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
230 | const unsigned char *new_sha1, | 231 | const unsigned char *new_sha1, |
231 | filepair_fn fn, const char *prefix); | 232 | filepair_fn fn, const char *prefix); |
232 | 233 | ||
233 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 234 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
234 | 235 | ||
235 | extern char *fmt(const char *format,...); | 236 | extern char *fmt(const char *format,...); |
236 | 237 | ||
237 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 238 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
238 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 239 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
239 | extern void cgit_parse_url(const char *url); | 240 | extern void cgit_parse_url(const char *url); |
240 | 241 | ||
241 | extern const char *cgit_repobasename(const char *reponame); | 242 | extern const char *cgit_repobasename(const char *reponame); |
242 | 243 | ||
243 | extern int cgit_parse_snapshots_mask(const char *str); | 244 | extern int cgit_parse_snapshots_mask(const char *str); |
244 | 245 | ||
245 | 246 | ||
246 | #endif /* CGIT_H */ | 247 | #endif /* CGIT_H */ |
@@ -1,79 +1,80 @@ | |||
1 | /* ui-plain.c: functions for output of plain blobs by path | 1 | /* ui-plain.c: functions for output of plain blobs by path |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 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 | char *curr_rev; | 13 | char *curr_rev; |
14 | char *match_path; | 14 | char *match_path; |
15 | int match; | 15 | int match; |
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf; |
21 | unsigned long size; | 21 | unsigned long size; |
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 | html_status(404, "Not found", 0); | 25 | html_status(404, "Not found", 0); |
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 | html_status(404, "Not found", 0); | 31 | html_status(404, "Not found", 0); |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | ctx.page.mimetype = "text/plain"; | 34 | ctx.page.mimetype = "text/plain"; |
35 | ctx.page.filename = fmt("%s", path); | 35 | ctx.page.filename = fmt("%s", path); |
36 | ctx.page.size = size; | 36 | ctx.page.size = size; |
37 | ctx.page.etag = sha1_to_hex(sha1); | ||
37 | cgit_print_http_headers(&ctx); | 38 | cgit_print_http_headers(&ctx); |
38 | html_raw(buf, size); | 39 | html_raw(buf, size); |
39 | match = 1; | 40 | match = 1; |
40 | } | 41 | } |
41 | 42 | ||
42 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 43 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
43 | const char *pathname, unsigned mode, int stage, | 44 | const char *pathname, unsigned mode, int stage, |
44 | void *cbdata) | 45 | void *cbdata) |
45 | { | 46 | { |
46 | if (S_ISDIR(mode)) | 47 | if (S_ISDIR(mode)) |
47 | return READ_TREE_RECURSIVE; | 48 | return READ_TREE_RECURSIVE; |
48 | 49 | ||
49 | if (S_ISREG(mode)) | 50 | if (S_ISREG(mode)) |
50 | print_object(sha1, pathname); | 51 | print_object(sha1, pathname); |
51 | 52 | ||
52 | return 0; | 53 | return 0; |
53 | } | 54 | } |
54 | 55 | ||
55 | void cgit_print_plain(struct cgit_context *ctx) | 56 | void cgit_print_plain(struct cgit_context *ctx) |
56 | { | 57 | { |
57 | const char *rev = ctx->qry.sha1; | 58 | const char *rev = ctx->qry.sha1; |
58 | unsigned char sha1[20]; | 59 | unsigned char sha1[20]; |
59 | struct commit *commit; | 60 | struct commit *commit; |
60 | const char *paths[] = {ctx->qry.path, NULL}; | 61 | const char *paths[] = {ctx->qry.path, NULL}; |
61 | 62 | ||
62 | if (!rev) | 63 | if (!rev) |
63 | rev = ctx->qry.head; | 64 | rev = ctx->qry.head; |
64 | 65 | ||
65 | curr_rev = xstrdup(rev); | 66 | curr_rev = xstrdup(rev); |
66 | if (get_sha1(rev, sha1)) { | 67 | if (get_sha1(rev, sha1)) { |
67 | html_status(404, "Not found", 0); | 68 | html_status(404, "Not found", 0); |
68 | return; | 69 | return; |
69 | } | 70 | } |
70 | commit = lookup_commit_reference(sha1); | 71 | commit = lookup_commit_reference(sha1); |
71 | if (!commit || parse_commit(commit)) { | 72 | if (!commit || parse_commit(commit)) { |
72 | html_status(404, "Not found", 0); | 73 | html_status(404, "Not found", 0); |
73 | return; | 74 | return; |
74 | } | 75 | } |
75 | match_path = ctx->qry.path; | 76 | match_path = ctx->qry.path; |
76 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); | 77 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); |
77 | if (!match) | 78 | if (!match) |
78 | html_status(404, "Not found", 0); | 79 | html_status(404, "Not found", 0); |
79 | } | 80 | } |
diff --git a/ui-shared.c b/ui-shared.c index de77bbf..86a7d29 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -375,192 +375,194 @@ void cgit_stats_link(char *name, char *title, char *class, char *head, | |||
375 | reporevlink("stats", name, title, class, head, NULL, path); | 375 | reporevlink("stats", name, title, class, head, NULL, path); |
376 | } | 376 | } |
377 | 377 | ||
378 | void cgit_object_link(struct object *obj) | 378 | void cgit_object_link(struct object *obj) |
379 | { | 379 | { |
380 | char *page, *shortrev, *fullrev, *name; | 380 | char *page, *shortrev, *fullrev, *name; |
381 | 381 | ||
382 | fullrev = sha1_to_hex(obj->sha1); | 382 | fullrev = sha1_to_hex(obj->sha1); |
383 | shortrev = xstrdup(fullrev); | 383 | shortrev = xstrdup(fullrev); |
384 | shortrev[10] = '\0'; | 384 | shortrev[10] = '\0'; |
385 | if (obj->type == OBJ_COMMIT) { | 385 | if (obj->type == OBJ_COMMIT) { |
386 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 386 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
387 | ctx.qry.head, fullrev); | 387 | ctx.qry.head, fullrev); |
388 | return; | 388 | return; |
389 | } else if (obj->type == OBJ_TREE) | 389 | } else if (obj->type == OBJ_TREE) |
390 | page = "tree"; | 390 | page = "tree"; |
391 | else if (obj->type == OBJ_TAG) | 391 | else if (obj->type == OBJ_TAG) |
392 | page = "tag"; | 392 | page = "tag"; |
393 | else | 393 | else |
394 | page = "blob"; | 394 | page = "blob"; |
395 | name = fmt("%s %s...", typename(obj->type), shortrev); | 395 | name = fmt("%s %s...", typename(obj->type), shortrev); |
396 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 396 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
397 | } | 397 | } |
398 | 398 | ||
399 | void cgit_print_date(time_t secs, char *format, int local_time) | 399 | void cgit_print_date(time_t secs, char *format, int local_time) |
400 | { | 400 | { |
401 | char buf[64]; | 401 | char buf[64]; |
402 | struct tm *time; | 402 | struct tm *time; |
403 | 403 | ||
404 | if (!secs) | 404 | if (!secs) |
405 | return; | 405 | return; |
406 | if(local_time) | 406 | if(local_time) |
407 | time = localtime(&secs); | 407 | time = localtime(&secs); |
408 | else | 408 | else |
409 | time = gmtime(&secs); | 409 | time = gmtime(&secs); |
410 | strftime(buf, sizeof(buf)-1, format, time); | 410 | strftime(buf, sizeof(buf)-1, format, time); |
411 | html_txt(buf); | 411 | html_txt(buf); |
412 | } | 412 | } |
413 | 413 | ||
414 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 414 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
415 | { | 415 | { |
416 | time_t now, secs; | 416 | time_t now, secs; |
417 | 417 | ||
418 | if (!t) | 418 | if (!t) |
419 | return; | 419 | return; |
420 | time(&now); | 420 | time(&now); |
421 | secs = now - t; | 421 | secs = now - t; |
422 | 422 | ||
423 | if (secs > max_relative && max_relative >= 0) { | 423 | if (secs > max_relative && max_relative >= 0) { |
424 | cgit_print_date(t, format, ctx.cfg.local_time); | 424 | cgit_print_date(t, format, ctx.cfg.local_time); |
425 | return; | 425 | return; |
426 | } | 426 | } |
427 | 427 | ||
428 | if (secs < TM_HOUR * 2) { | 428 | if (secs < TM_HOUR * 2) { |
429 | htmlf("<span class='age-mins'>%.0f min.</span>", | 429 | htmlf("<span class='age-mins'>%.0f min.</span>", |
430 | secs * 1.0 / TM_MIN); | 430 | secs * 1.0 / TM_MIN); |
431 | return; | 431 | return; |
432 | } | 432 | } |
433 | if (secs < TM_DAY * 2) { | 433 | if (secs < TM_DAY * 2) { |
434 | htmlf("<span class='age-hours'>%.0f hours</span>", | 434 | htmlf("<span class='age-hours'>%.0f hours</span>", |
435 | secs * 1.0 / TM_HOUR); | 435 | secs * 1.0 / TM_HOUR); |
436 | return; | 436 | return; |
437 | } | 437 | } |
438 | if (secs < TM_WEEK * 2) { | 438 | if (secs < TM_WEEK * 2) { |
439 | htmlf("<span class='age-days'>%.0f days</span>", | 439 | htmlf("<span class='age-days'>%.0f days</span>", |
440 | secs * 1.0 / TM_DAY); | 440 | secs * 1.0 / TM_DAY); |
441 | return; | 441 | return; |
442 | } | 442 | } |
443 | if (secs < TM_MONTH * 2) { | 443 | if (secs < TM_MONTH * 2) { |
444 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 444 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
445 | secs * 1.0 / TM_WEEK); | 445 | secs * 1.0 / TM_WEEK); |
446 | return; | 446 | return; |
447 | } | 447 | } |
448 | if (secs < TM_YEAR * 2) { | 448 | if (secs < TM_YEAR * 2) { |
449 | htmlf("<span class='age-months'>%.0f months</span>", | 449 | htmlf("<span class='age-months'>%.0f months</span>", |
450 | secs * 1.0 / TM_MONTH); | 450 | secs * 1.0 / TM_MONTH); |
451 | return; | 451 | return; |
452 | } | 452 | } |
453 | htmlf("<span class='age-years'>%.0f years</span>", | 453 | htmlf("<span class='age-years'>%.0f years</span>", |
454 | secs * 1.0 / TM_YEAR); | 454 | secs * 1.0 / TM_YEAR); |
455 | } | 455 | } |
456 | 456 | ||
457 | void cgit_print_http_headers(struct cgit_context *ctx) | 457 | void cgit_print_http_headers(struct cgit_context *ctx) |
458 | { | 458 | { |
459 | if (ctx->page.mimetype && ctx->page.charset) | 459 | if (ctx->page.mimetype && ctx->page.charset) |
460 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 460 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
461 | ctx->page.charset); | 461 | ctx->page.charset); |
462 | else if (ctx->page.mimetype) | 462 | else if (ctx->page.mimetype) |
463 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 463 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
464 | if (ctx->page.size) | 464 | if (ctx->page.size) |
465 | htmlf("Content-Length: %ld\n", ctx->page.size); | 465 | htmlf("Content-Length: %ld\n", ctx->page.size); |
466 | if (ctx->page.filename) | 466 | if (ctx->page.filename) |
467 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 467 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
468 | ctx->page.filename); | 468 | ctx->page.filename); |
469 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 469 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
470 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 470 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
471 | if (ctx->page.etag) | ||
472 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | ||
471 | html("\n"); | 473 | html("\n"); |
472 | } | 474 | } |
473 | 475 | ||
474 | void cgit_print_docstart(struct cgit_context *ctx) | 476 | void cgit_print_docstart(struct cgit_context *ctx) |
475 | { | 477 | { |
476 | char *host = cgit_hosturl(); | 478 | char *host = cgit_hosturl(); |
477 | html(cgit_doctype); | 479 | html(cgit_doctype); |
478 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 480 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
479 | html("<head>\n"); | 481 | html("<head>\n"); |
480 | html("<title>"); | 482 | html("<title>"); |
481 | html_txt(ctx->page.title); | 483 | html_txt(ctx->page.title); |
482 | html("</title>\n"); | 484 | html("</title>\n"); |
483 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 485 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
484 | if (ctx->cfg.robots && *ctx->cfg.robots) | 486 | if (ctx->cfg.robots && *ctx->cfg.robots) |
485 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 487 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
486 | html("<link rel='stylesheet' type='text/css' href='"); | 488 | html("<link rel='stylesheet' type='text/css' href='"); |
487 | html_attr(ctx->cfg.css); | 489 | html_attr(ctx->cfg.css); |
488 | html("'/>\n"); | 490 | html("'/>\n"); |
489 | if (ctx->cfg.favicon) { | 491 | if (ctx->cfg.favicon) { |
490 | html("<link rel='shortcut icon' href='"); | 492 | html("<link rel='shortcut icon' href='"); |
491 | html_attr(ctx->cfg.favicon); | 493 | html_attr(ctx->cfg.favicon); |
492 | html("'/>\n"); | 494 | html("'/>\n"); |
493 | } | 495 | } |
494 | if (host && ctx->repo) { | 496 | if (host && ctx->repo) { |
495 | html("<link rel='alternate' title='Atom feed' href='http://"); | 497 | html("<link rel='alternate' title='Atom feed' href='http://"); |
496 | html_attr(cgit_hosturl()); | 498 | html_attr(cgit_hosturl()); |
497 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 499 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
498 | fmt("h=%s", ctx->qry.head))); | 500 | fmt("h=%s", ctx->qry.head))); |
499 | html("' type='application/atom+xml'/>"); | 501 | html("' type='application/atom+xml'/>"); |
500 | } | 502 | } |
501 | html("</head>\n"); | 503 | html("</head>\n"); |
502 | html("<body>\n"); | 504 | html("<body>\n"); |
503 | if (ctx->cfg.header) | 505 | if (ctx->cfg.header) |
504 | html_include(ctx->cfg.header); | 506 | html_include(ctx->cfg.header); |
505 | } | 507 | } |
506 | 508 | ||
507 | void cgit_print_docend() | 509 | void cgit_print_docend() |
508 | { | 510 | { |
509 | html("</div>"); | 511 | html("</div>"); |
510 | if (ctx.cfg.footer) | 512 | if (ctx.cfg.footer) |
511 | html_include(ctx.cfg.footer); | 513 | html_include(ctx.cfg.footer); |
512 | else { | 514 | else { |
513 | htmlf("<div class='footer'>generated by cgit %s at ", | 515 | htmlf("<div class='footer'>generated by cgit %s at ", |
514 | cgit_version); | 516 | cgit_version); |
515 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 517 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
516 | html("</div>\n"); | 518 | html("</div>\n"); |
517 | } | 519 | } |
518 | html("</body>\n</html>\n"); | 520 | html("</body>\n</html>\n"); |
519 | } | 521 | } |
520 | 522 | ||
521 | int print_branch_option(const char *refname, const unsigned char *sha1, | 523 | int print_branch_option(const char *refname, const unsigned char *sha1, |
522 | int flags, void *cb_data) | 524 | int flags, void *cb_data) |
523 | { | 525 | { |
524 | char *name = (char *)refname; | 526 | char *name = (char *)refname; |
525 | html_option(name, name, ctx.qry.head); | 527 | html_option(name, name, ctx.qry.head); |
526 | return 0; | 528 | return 0; |
527 | } | 529 | } |
528 | 530 | ||
529 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 531 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
530 | int flags, void *cb_data) | 532 | int flags, void *cb_data) |
531 | { | 533 | { |
532 | struct tag *tag; | 534 | struct tag *tag; |
533 | struct taginfo *info; | 535 | struct taginfo *info; |
534 | struct object *obj; | 536 | struct object *obj; |
535 | char buf[256], *url; | 537 | char buf[256], *url; |
536 | unsigned char fileid[20]; | 538 | unsigned char fileid[20]; |
537 | int *header = (int *)cb_data; | 539 | int *header = (int *)cb_data; |
538 | 540 | ||
539 | if (prefixcmp(refname, "refs/archives")) | 541 | if (prefixcmp(refname, "refs/archives")) |
540 | return 0; | 542 | return 0; |
541 | strncpy(buf, refname+14, sizeof(buf)); | 543 | strncpy(buf, refname+14, sizeof(buf)); |
542 | obj = parse_object(sha1); | 544 | obj = parse_object(sha1); |
543 | if (!obj) | 545 | if (!obj) |
544 | return 1; | 546 | return 1; |
545 | if (obj->type == OBJ_TAG) { | 547 | if (obj->type == OBJ_TAG) { |
546 | tag = lookup_tag(sha1); | 548 | tag = lookup_tag(sha1); |
547 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 549 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
548 | return 0; | 550 | return 0; |
549 | hashcpy(fileid, tag->tagged->sha1); | 551 | hashcpy(fileid, tag->tagged->sha1); |
550 | } else if (obj->type != OBJ_BLOB) { | 552 | } else if (obj->type != OBJ_BLOB) { |
551 | return 0; | 553 | return 0; |
552 | } else { | 554 | } else { |
553 | hashcpy(fileid, sha1); | 555 | hashcpy(fileid, sha1); |
554 | } | 556 | } |
555 | if (!*header) { | 557 | if (!*header) { |
556 | html("<h1>download</h1>\n"); | 558 | html("<h1>download</h1>\n"); |
557 | *header = 1; | 559 | *header = 1; |
558 | } | 560 | } |
559 | url = cgit_pageurl(ctx.qry.repo, "blob", | 561 | url = cgit_pageurl(ctx.qry.repo, "blob", |
560 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 562 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
561 | buf)); | 563 | buf)); |
562 | html_link_open(url, NULL, "menu"); | 564 | html_link_open(url, NULL, "menu"); |
563 | html_txt(strlpart(buf, 20)); | 565 | html_txt(strlpart(buf, 20)); |
564 | html_link_close(); | 566 | html_link_close(); |
565 | return 0; | 567 | return 0; |
566 | } | 568 | } |