|
diff --git a/cgit.c b/cgit.c index f5135d9..b936a70 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -31,129 +31,129 @@ static int cgit_prepare_cache(struct cacheitem *item) |
31 | if (!cgit_cmd) { |
31 | if (!cgit_cmd) { |
32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
33 | cache_safe_filename(cgit_repo->url))); |
33 | cache_safe_filename(cgit_repo->url))); |
34 | item->ttl = cgit_cache_repo_ttl; |
34 | item->ttl = cgit_cache_repo_ttl; |
35 | } else { |
35 | } else { |
36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
37 | cache_safe_filename(cgit_repo->url), cgit_query_page, |
37 | cache_safe_filename(cgit_repo->url), cgit_query_page, |
38 | cache_safe_filename(cgit_querystring))); |
38 | cache_safe_filename(cgit_querystring))); |
39 | if (cgit_query_has_symref) |
39 | if (cgit_query_has_symref) |
40 | item->ttl = cgit_cache_dynamic_ttl; |
40 | item->ttl = cgit_cache_dynamic_ttl; |
41 | else if (cgit_query_has_sha1) |
41 | else if (cgit_query_has_sha1) |
42 | item->ttl = cgit_cache_static_ttl; |
42 | item->ttl = cgit_cache_static_ttl; |
43 | else |
43 | else |
44 | item->ttl = cgit_cache_repo_ttl; |
44 | item->ttl = cgit_cache_repo_ttl; |
45 | } |
45 | } |
46 | return 1; |
46 | return 1; |
47 | } |
47 | } |
48 | |
48 | |
49 | static void cgit_print_repo_page(struct cacheitem *item) |
49 | static void cgit_print_repo_page(struct cacheitem *item) |
50 | { |
50 | { |
51 | char *title; |
51 | char *title; |
52 | int show_search; |
52 | int show_search; |
53 | |
53 | |
54 | if (!cgit_query_head) |
54 | if (!cgit_query_head) |
55 | cgit_query_head = cgit_repo->defbranch; |
55 | cgit_query_head = cgit_repo->defbranch; |
56 | |
56 | |
57 | if (chdir(cgit_repo->path)) { |
57 | if (chdir(cgit_repo->path)) { |
58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
59 | cgit_print_docstart(title, item); |
59 | cgit_print_docstart(title, item); |
60 | cgit_print_pageheader(title, 0); |
60 | cgit_print_pageheader(title, 0); |
61 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | cgit_print_error(fmt("Unable to scan repository: %s", |
62 | strerror(errno))); |
62 | strerror(errno))); |
63 | cgit_print_docend(); |
63 | cgit_print_docend(); |
64 | return; |
64 | return; |
65 | } |
65 | } |
66 | |
66 | |
67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
68 | show_search = 0; |
68 | show_search = 0; |
69 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | setenv("GIT_DIR", cgit_repo->path, 1); |
70 | |
70 | |
71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
73 | cgit_repo->url, cgit_query_name); |
73 | cgit_repo->url, cgit_query_name); |
74 | return; |
74 | return; |
75 | } |
75 | } |
76 | |
76 | |
77 | if (cgit_cmd == CMD_BLOB) { |
77 | if (cgit_cmd == CMD_BLOB) { |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; |
79 | return; |
80 | } |
80 | } |
81 | |
81 | |
82 | show_search = (cgit_cmd == CMD_LOG); |
82 | show_search = (cgit_cmd == CMD_LOG); |
83 | cgit_print_docstart(title, item); |
83 | cgit_print_docstart(title, item); |
84 | if (!cgit_cmd) { |
84 | if (!cgit_cmd) { |
85 | cgit_print_pageheader("summary", show_search); |
85 | cgit_print_pageheader("summary", show_search); |
86 | cgit_print_summary(); |
86 | cgit_print_summary(); |
87 | cgit_print_docend(); |
87 | cgit_print_docend(); |
88 | return; |
88 | return; |
89 | } |
89 | } |
90 | |
90 | |
91 | cgit_print_pageheader(cgit_query_page, show_search); |
91 | cgit_print_pageheader(cgit_query_page, show_search); |
92 | |
92 | |
93 | switch(cgit_cmd) { |
93 | switch(cgit_cmd) { |
94 | case CMD_LOG: |
94 | case CMD_LOG: |
95 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
95 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
96 | cgit_max_commit_count, cgit_query_search, |
96 | cgit_max_commit_count, cgit_query_search, |
97 | cgit_query_path, 1); |
97 | cgit_query_path, 1); |
98 | break; |
98 | break; |
99 | case CMD_TREE: |
99 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
101 | break; |
101 | break; |
102 | case CMD_COMMIT: |
102 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_sha1); |
103 | cgit_print_commit(cgit_query_sha1); |
104 | break; |
104 | break; |
105 | case CMD_DIFF: |
105 | case CMD_DIFF: |
106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
107 | cgit_query_path); |
107 | cgit_query_path); |
108 | break; |
108 | break; |
109 | default: |
109 | default: |
110 | cgit_print_error("Invalid request"); |
110 | cgit_print_error("Invalid request"); |
111 | } |
111 | } |
112 | cgit_print_docend(); |
112 | cgit_print_docend(); |
113 | } |
113 | } |
114 | |
114 | |
115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
116 | { |
116 | { |
117 | static char buf[PATH_MAX]; |
117 | static char buf[PATH_MAX]; |
118 | int stdout2; |
118 | int stdout2; |
119 | |
119 | |
120 | getcwd(buf, sizeof(buf)); |
120 | getcwd(buf, sizeof(buf)); |
121 | item->st.st_mtime = time(NULL); |
121 | item->st.st_mtime = time(NULL); |
122 | |
122 | |
123 | if (use_cache) { |
123 | if (use_cache) { |
124 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
124 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
125 | "Preserving STDOUT"); |
125 | "Preserving STDOUT"); |
126 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
126 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
127 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
127 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
128 | } |
128 | } |
129 | |
129 | |
130 | if (cgit_repo) |
130 | if (cgit_repo) |
131 | cgit_print_repo_page(item); |
131 | cgit_print_repo_page(item); |
132 | else |
132 | else |
133 | cgit_print_repolist(item); |
133 | cgit_print_repolist(item); |
134 | |
134 | |
135 | if (use_cache) { |
135 | if (use_cache) { |
136 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
136 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
137 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
137 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
138 | "Restoring original STDOUT"); |
138 | "Restoring original STDOUT"); |
139 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
139 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
140 | } |
140 | } |
141 | |
141 | |
142 | chdir(buf); |
142 | chdir(buf); |
143 | } |
143 | } |
144 | |
144 | |
145 | static void cgit_check_cache(struct cacheitem *item) |
145 | static void cgit_check_cache(struct cacheitem *item) |
146 | { |
146 | { |
147 | int i = 0; |
147 | int i = 0; |
148 | |
148 | |
149 | top: |
149 | top: |
150 | if (++i > cgit_max_lock_attempts) { |
150 | if (++i > cgit_max_lock_attempts) { |
151 | die("cgit_refresh_cache: unable to lock %s: %s", |
151 | die("cgit_refresh_cache: unable to lock %s: %s", |
152 | item->name, strerror(errno)); |
152 | item->name, strerror(errno)); |
153 | } |
153 | } |
154 | if (!cache_exist(item)) { |
154 | if (!cache_exist(item)) { |
155 | if (!cache_lock(item)) { |
155 | if (!cache_lock(item)) { |
156 | sleep(1); |
156 | sleep(1); |
157 | goto top; |
157 | goto top; |
158 | } |
158 | } |
159 | if (!cache_exist(item)) { |
159 | if (!cache_exist(item)) { |
|
|
diff --git a/ui-log.c b/ui-log.c index 8d774b0..95cb453 100644 --- a/ ui-log.c+++ b/ ui-log.c |
|
@@ -1,125 +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 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, |
34 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, |
35 | sha1_to_hex(commit->object.sha1)); |
35 | sha1_to_hex(commit->object.sha1)); |
36 | if (cgit_repo->enable_log_filecount) { |
36 | if (cgit_repo->enable_log_filecount) { |
37 | files = 0; |
37 | files = 0; |
38 | lines = 0; |
38 | lines = 0; |
39 | cgit_diff_commit(commit, inspect_files); |
39 | cgit_diff_commit(commit, inspect_files); |
40 | html("</td><td class='right'>"); |
40 | html("</td><td class='right'>"); |
41 | htmlf("%d", files); |
41 | htmlf("%d", files); |
42 | if (cgit_repo->enable_log_linecount) { |
42 | if (cgit_repo->enable_log_linecount) { |
43 | html("</td><td class='right'>"); |
43 | html("</td><td class='right'>"); |
44 | htmlf("%d", lines); |
44 | htmlf("%d", lines); |
45 | } |
45 | } |
46 | } |
46 | } |
47 | html("</td><td>"); |
47 | html("</td><td>"); |
48 | html_txt(info->author); |
48 | html_txt(info->author); |
49 | html("</td></tr>\n"); |
49 | html("</td></tr>\n"); |
50 | cgit_free_commitinfo(info); |
50 | cgit_free_commitinfo(info); |
51 | } |
51 | } |
52 | |
52 | |
53 | |
53 | |
54 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) |
54 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) |
55 | { |
55 | { |
56 | struct rev_info rev; |
56 | struct rev_info rev; |
57 | struct commit *commit; |
57 | struct commit *commit; |
58 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
58 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
59 | int argc = 2; |
59 | int argc = 2; |
60 | int i; |
60 | int i; |
61 | |
61 | |
| |
62 | if (!tip) |
| |
63 | argv[1] = cgit_query_head; |
| |
64 | |
62 | if (grep) |
65 | if (grep) |
63 | argv[argc++] = fmt("--grep=%s", grep); |
66 | argv[argc++] = fmt("--grep=%s", grep); |
64 | if (path) { |
67 | if (path) { |
65 | argv[argc++] = "--"; |
68 | argv[argc++] = "--"; |
66 | argv[argc++] = path; |
69 | argv[argc++] = path; |
67 | } |
70 | } |
68 | init_revisions(&rev, NULL); |
71 | init_revisions(&rev, NULL); |
69 | rev.abbrev = DEFAULT_ABBREV; |
72 | rev.abbrev = DEFAULT_ABBREV; |
70 | rev.commit_format = CMIT_FMT_DEFAULT; |
73 | rev.commit_format = CMIT_FMT_DEFAULT; |
71 | rev.verbose_header = 1; |
74 | rev.verbose_header = 1; |
72 | rev.show_root_diff = 0; |
75 | rev.show_root_diff = 0; |
73 | setup_revisions(argc, argv, &rev, NULL); |
76 | setup_revisions(argc, argv, &rev, NULL); |
74 | if (rev.grep_filter) { |
77 | if (rev.grep_filter) { |
75 | rev.grep_filter->regflags |= REG_ICASE; |
78 | rev.grep_filter->regflags |= REG_ICASE; |
76 | compile_grep_patterns(rev.grep_filter); |
79 | compile_grep_patterns(rev.grep_filter); |
77 | } |
80 | } |
78 | prepare_revision_walk(&rev); |
81 | prepare_revision_walk(&rev); |
79 | |
82 | |
80 | html("<table class='list nowrap'>"); |
83 | html("<table class='list nowrap'>"); |
81 | html("<tr class='nohover'><th class='left'>Age</th>" |
84 | html("<tr class='nohover'><th class='left'>Age</th>" |
82 | "<th class='left'>Message</th>"); |
85 | "<th class='left'>Message</th>"); |
83 | |
86 | |
84 | if (cgit_repo->enable_log_filecount) { |
87 | if (cgit_repo->enable_log_filecount) { |
85 | html("<th class='left'>Files</th>"); |
88 | html("<th class='left'>Files</th>"); |
86 | if (cgit_repo->enable_log_linecount) |
89 | if (cgit_repo->enable_log_linecount) |
87 | html("<th class='left'>Lines</th>"); |
90 | html("<th class='left'>Lines</th>"); |
88 | } |
91 | } |
89 | html("<th class='left'>Author</th></tr>\n"); |
92 | html("<th class='left'>Author</th></tr>\n"); |
90 | |
93 | |
91 | if (ofs<0) |
94 | if (ofs<0) |
92 | ofs = 0; |
95 | ofs = 0; |
93 | |
96 | |
94 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
97 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
95 | free(commit->buffer); |
98 | free(commit->buffer); |
96 | commit->buffer = NULL; |
99 | commit->buffer = NULL; |
97 | free_commit_list(commit->parents); |
100 | free_commit_list(commit->parents); |
98 | commit->parents = NULL; |
101 | commit->parents = NULL; |
99 | } |
102 | } |
100 | |
103 | |
101 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
104 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
102 | print_commit(commit); |
105 | print_commit(commit); |
103 | free(commit->buffer); |
106 | free(commit->buffer); |
104 | commit->buffer = NULL; |
107 | commit->buffer = NULL; |
105 | free_commit_list(commit->parents); |
108 | free_commit_list(commit->parents); |
106 | commit->parents = NULL; |
109 | commit->parents = NULL; |
107 | } |
110 | } |
108 | html("</table>\n"); |
111 | html("</table>\n"); |
109 | |
112 | |
110 | if (pager) { |
113 | if (pager) { |
111 | html("<div class='pager'>"); |
114 | html("<div class='pager'>"); |
112 | if (ofs > 0) { |
115 | if (ofs > 0) { |
113 | html(" <a href='"); |
116 | html(" <a href='"); |
114 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
117 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
115 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
118 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
116 | html("'>[prev]</a> "); |
119 | html("'>[prev]</a> "); |
117 | } |
120 | } |
118 | |
121 | |
119 | if ((commit = get_revision(&rev)) != NULL) { |
122 | if ((commit = get_revision(&rev)) != NULL) { |
120 | html(" <a href='"); |
123 | html(" <a href='"); |
121 | html(cgit_pageurl(cgit_query_repo, "log", |
124 | html(cgit_pageurl(cgit_query_repo, "log", |
122 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
125 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
123 | html("'>[next]</a> "); |
126 | html("'>[next]</a> "); |
124 | } |
127 | } |
125 | html("</div>"); |
128 | html("</div>"); |
|