summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-11-07 14:35:36 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-11-07 14:35:36 (UTC)
commit4b1fee00ddfbb7bfb48f85bef49b5aff928d0f2e (patch) (unidiff)
tree593616b5bd2e8c662d00478f50ecee86a0002224
parent13032727ffa81a4de8964d4002c359c0983cdeb2 (diff)
parent8cfe4897f01066ae901bdd6ef106faf8e8f2ddf2 (diff)
downloadcgit-4b1fee00ddfbb7bfb48f85bef49b5aff928d0f2e.zip
cgit-4b1fee00ddfbb7bfb48f85bef49b5aff928d0f2e.tar.gz
cgit-4b1fee00ddfbb7bfb48f85bef49b5aff928d0f2e.tar.bz2
Merge branch 'stable'
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c9
-rw-r--r--ui-shared.c2
2 files changed, 8 insertions, 3 deletions
diff --git a/shared.c b/shared.c
index d7b2d5a..a27ab30 100644
--- a/shared.c
+++ b/shared.c
@@ -313,105 +313,110 @@ void cgit_diff_tree(const unsigned char *old_sha1,
313 opt.paths = &prefix; 313 opt.paths = &prefix;
314 prefixlen = strlen(prefix); 314 prefixlen = strlen(prefix);
315 opt.pathlens = &prefixlen; 315 opt.pathlens = &prefixlen;
316 } 316 }
317 diff_setup_done(&opt); 317 diff_setup_done(&opt);
318 318
319 if (old_sha1 && !is_null_sha1(old_sha1)) 319 if (old_sha1 && !is_null_sha1(old_sha1))
320 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); 320 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
321 else 321 else
322 ret = diff_root_tree_sha1(new_sha1, "", &opt); 322 ret = diff_root_tree_sha1(new_sha1, "", &opt);
323 diffcore_std(&opt); 323 diffcore_std(&opt);
324 diff_flush(&opt); 324 diff_flush(&opt);
325} 325}
326 326
327void cgit_diff_commit(struct commit *commit, filepair_fn fn) 327void cgit_diff_commit(struct commit *commit, filepair_fn fn)
328{ 328{
329 unsigned char *old_sha1 = NULL; 329 unsigned char *old_sha1 = NULL;
330 330
331 if (commit->parents) 331 if (commit->parents)
332 old_sha1 = commit->parents->item->object.sha1; 332 old_sha1 = commit->parents->item->object.sha1;
333 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); 333 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
334} 334}
335 335
336int cgit_parse_snapshots_mask(const char *str) 336int cgit_parse_snapshots_mask(const char *str)
337{ 337{
338 const struct cgit_snapshot_format *f; 338 const struct cgit_snapshot_format *f;
339 static const char *delim = " \t,:/|;"; 339 static const char *delim = " \t,:/|;";
340 int tl, sl, rv = 0; 340 int tl, sl, rv = 0;
341 341
342 /* favor legacy setting */ 342 /* favor legacy setting */
343 if(atoi(str)) 343 if(atoi(str))
344 return 1; 344 return 1;
345 for(;;) { 345 for(;;) {
346 str += strspn(str,delim); 346 str += strspn(str,delim);
347 tl = strcspn(str,delim); 347 tl = strcspn(str,delim);
348 if (!tl) 348 if (!tl)
349 break; 349 break;
350 for (f = cgit_snapshot_formats; f->suffix; f++) { 350 for (f = cgit_snapshot_formats; f->suffix; f++) {
351 sl = strlen(f->suffix); 351 sl = strlen(f->suffix);
352 if((tl == sl && !strncmp(f->suffix, str, tl)) || 352 if((tl == sl && !strncmp(f->suffix, str, tl)) ||
353 (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) { 353 (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
354 rv |= f->bit; 354 rv |= f->bit;
355 break; 355 break;
356 } 356 }
357 } 357 }
358 str += tl; 358 str += tl;
359 } 359 }
360 return rv; 360 return rv;
361} 361}
362 362
363int cgit_open_filter(struct cgit_filter *filter) 363int cgit_open_filter(struct cgit_filter *filter)
364{ 364{
365 365
366 filter->old_stdout = chk_positive(dup(STDOUT_FILENO), 366 filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
367 "Unable to duplicate STDOUT"); 367 "Unable to duplicate STDOUT");
368 chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess"); 368 chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess");
369 filter->pid = chk_non_negative(fork(), "Unable to create subprocess"); 369 filter->pid = chk_non_negative(fork(), "Unable to create subprocess");
370 if (filter->pid == 0) { 370 if (filter->pid == 0) {
371 close(filter->pipe_fh[1]); 371 close(filter->pipe_fh[1]);
372 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), 372 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
373 "Unable to use pipe as STDIN"); 373 "Unable to use pipe as STDIN");
374 execvp(filter->cmd, filter->argv); 374 execvp(filter->cmd, filter->argv);
375 die("Unable to exec subprocess %s: %s (%d)", filter->cmd, 375 die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
376 strerror(errno), errno); 376 strerror(errno), errno);
377 } 377 }
378 close(filter->pipe_fh[0]); 378 close(filter->pipe_fh[0]);
379 chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO), 379 chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO),
380 "Unable to use pipe as STDOUT"); 380 "Unable to use pipe as STDOUT");
381 close(filter->pipe_fh[1]); 381 close(filter->pipe_fh[1]);
382 return 0; 382 return 0;
383} 383}
384 384
385int cgit_close_filter(struct cgit_filter *filter) 385int cgit_close_filter(struct cgit_filter *filter)
386{ 386{
387 chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), 387 chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO),
388 "Unable to restore STDOUT"); 388 "Unable to restore STDOUT");
389 close(filter->old_stdout); 389 close(filter->old_stdout);
390 if (filter->pid < 0) 390 if (filter->pid < 0)
391 return 0; 391 return 0;
392 waitpid(filter->pid, &filter->exitstatus, 0); 392 waitpid(filter->pid, &filter->exitstatus, 0);
393 if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus)) 393 if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus))
394 return 0; 394 return 0;
395 die("Subprocess %s exited abnormally", filter->cmd); 395 die("Subprocess %s exited abnormally", filter->cmd);
396} 396}
397 397
398/* Read the content of the specified file into a newly allocated buffer, 398/* Read the content of the specified file into a newly allocated buffer,
399 * zeroterminate the buffer and return 0 on success, errno otherwise. 399 * zeroterminate the buffer and return 0 on success, errno otherwise.
400 */ 400 */
401int readfile(const char *path, char **buf, size_t *size) 401int readfile(const char *path, char **buf, size_t *size)
402{ 402{
403 int fd; 403 int fd;
404 struct stat st; 404 struct stat st;
405 405
406 fd = open(path, O_RDONLY); 406 fd = open(path, O_RDONLY);
407 if (fd == -1) 407 if (fd == -1)
408 return errno; 408 return errno;
409 if (fstat(fd, &st)) 409 if (fstat(fd, &st)) {
410 close(fd);
410 return errno; 411 return errno;
411 if (!S_ISREG(st.st_mode)) 412 }
413 if (!S_ISREG(st.st_mode)) {
414 close(fd);
412 return EISDIR; 415 return EISDIR;
416 }
413 *buf = xmalloc(st.st_size + 1); 417 *buf = xmalloc(st.st_size + 1);
414 *size = read_in_full(fd, *buf, st.st_size); 418 *size = read_in_full(fd, *buf, st.st_size);
415 (*buf)[*size] = '\0'; 419 (*buf)[*size] = '\0';
420 close(fd);
416 return (*size == st.st_size ? 0 : errno); 421 return (*size == st.st_size ? 0 : errno);
417} 422}
diff --git a/ui-shared.c b/ui-shared.c
index 6cb7edb..3a9e67b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,119 +1,119 @@
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#include "cmd.h" 10#include "cmd.h"
11#include "html.h" 11#include "html.h"
12 12
13const char cgit_doctype[] = 13const char cgit_doctype[] =
14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
16 16
17static char *http_date(time_t t) 17static char *http_date(time_t t)
18{ 18{
19 static char day[][4] = 19 static char day[][4] =
20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
21 static char month[][4] = 21 static char month[][4] =
22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 23 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
24 struct tm *tm = gmtime(&t); 24 struct tm *tm = gmtime(&t);
25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
27 tm->tm_hour, tm->tm_min, tm->tm_sec); 27 tm->tm_hour, tm->tm_min, tm->tm_sec);
28} 28}
29 29
30void cgit_print_error(char *msg) 30void cgit_print_error(char *msg)
31{ 31{
32 html("<div class='error'>"); 32 html("<div class='error'>");
33 html_txt(msg); 33 html_txt(msg);
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_httpscheme() 37char *cgit_httpscheme()
38{ 38{
39 if (ctx.env.https && !strcmp(ctx.env.https, "on")) 39 if (ctx.env.https && !strcmp(ctx.env.https, "on"))
40 return "https://"; 40 return "https://";
41 else 41 else
42 return "http://"; 42 return "http://";
43} 43}
44 44
45char *cgit_hosturl() 45char *cgit_hosturl()
46{ 46{
47 if (ctx.env.http_host) 47 if (ctx.env.http_host)
48 return ctx.env.http_host; 48 return ctx.env.http_host;
49 if (!ctx.env.server_name) 49 if (!ctx.env.server_name)
50 return NULL; 50 return NULL;
51 if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) 51 if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
52 return ctx.env.server_name; 52 return ctx.env.server_name;
53 return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); 53 return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port));
54} 54}
55 55
56char *cgit_rooturl() 56char *cgit_rooturl()
57{ 57{
58 if (ctx.cfg.virtual_root) 58 if (ctx.cfg.virtual_root)
59 return fmt("%s/", ctx.cfg.virtual_root); 59 return fmt("%s/", ctx.cfg.virtual_root);
60 else 60 else
61 return ctx.cfg.script_name; 61 return ctx.cfg.script_name;
62} 62}
63 63
64char *cgit_repourl(const char *reponame) 64char *cgit_repourl(const char *reponame)
65{ 65{
66 if (ctx.cfg.virtual_root) { 66 if (ctx.cfg.virtual_root) {
67 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); 67 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
68 } else { 68 } else {
69 return fmt("?r=%s", reponame); 69 return fmt("?r=%s", reponame);
70 } 70 }
71} 71}
72 72
73char *cgit_fileurl(const char *reponame, const char *pagename, 73char *cgit_fileurl(const char *reponame, const char *pagename,
74 const char *filename, const char *query) 74 const char *filename, const char *query)
75{ 75{
76 char *tmp; 76 char *tmp;
77 char *delim; 77 char *delim;
78 78
79 if (ctx.cfg.virtual_root) { 79 if (ctx.cfg.virtual_root) {
80 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, 80 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
81 pagename, (filename ? filename:"")); 81 pagename, (filename ? filename:""));
82 delim = "?"; 82 delim = "?";
83 } else { 83 } else {
84 tmp = fmt("?url=%s/%s/%s", reponame, pagename, 84 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
85 (filename ? filename : "")); 85 (filename ? filename : ""));
86 delim = "&"; 86 delim = "&";
87 } 87 }
88 if (query) 88 if (query)
89 tmp = fmt("%s%s%s", tmp, delim, query); 89 tmp = fmt("%s%s%s", tmp, delim, query);
90 return tmp; 90 return tmp;
91} 91}
92 92
93char *cgit_pageurl(const char *reponame, const char *pagename, 93char *cgit_pageurl(const char *reponame, const char *pagename,
94 const char *query) 94 const char *query)
95{ 95{
96 return cgit_fileurl(reponame,pagename,0,query); 96 return cgit_fileurl(reponame,pagename,0,query);
97} 97}
98 98
99const char *cgit_repobasename(const char *reponame) 99const char *cgit_repobasename(const char *reponame)
100{ 100{
101 /* I assume we don't need to store more than one repo basename */ 101 /* I assume we don't need to store more than one repo basename */
102 static char rvbuf[1024]; 102 static char rvbuf[1024];
103 int p; 103 int p;
104 const char *rv; 104 const char *rv;
105 strncpy(rvbuf,reponame,sizeof(rvbuf)); 105 strncpy(rvbuf,reponame,sizeof(rvbuf));
106 if(rvbuf[sizeof(rvbuf)-1]) 106 if(rvbuf[sizeof(rvbuf)-1])
107 die("cgit_repobasename: truncated repository name '%s'", reponame); 107 die("cgit_repobasename: truncated repository name '%s'", reponame);
108 p = strlen(rvbuf)-1; 108 p = strlen(rvbuf)-1;
109 /* strip trailing slashes */ 109 /* strip trailing slashes */
110 while(p && rvbuf[p]=='/') rvbuf[p--]=0; 110 while(p && rvbuf[p]=='/') rvbuf[p--]=0;
111 /* strip trailing .git */ 111 /* strip trailing .git */
112 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { 112 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
113 p -= 3; rvbuf[p--] = 0; 113 p -= 3; rvbuf[p--] = 0;
114 } 114 }
115 /* strip more trailing slashes if any */ 115 /* strip more trailing slashes if any */
116 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 116 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
117 /* find last slash in the remaining string */ 117 /* find last slash in the remaining string */
118 rv = strrchr(rvbuf,'/'); 118 rv = strrchr(rvbuf,'/');
119 if(rv) 119 if(rv)