summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h2
-rw-r--r--ui-commit.c3
-rw-r--r--ui-log.c7
-rw-r--r--ui-shared.c16
-rw-r--r--ui-summary.c18
-rw-r--r--ui-tree.c1
7 files changed, 31 insertions, 18 deletions
diff --git a/cgit.c b/cgit.c
index 1c213c7..f5135d9 100644
--- a/cgit.c
+++ b/cgit.c
@@ -55,97 +55,97 @@ static void cgit_print_repo_page(struct cacheitem *item)
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_head, 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_head); 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
115static void cgit_fill_cache(struct cacheitem *item, int use_cache) 115static 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
145static void cgit_check_cache(struct cacheitem *item) 145static 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",
diff --git a/cgit.h b/cgit.h
index b2f6361..c276a24 100644
--- a/cgit.h
+++ b/cgit.h
@@ -160,72 +160,74 @@ extern int chk_positive(int result, char *msg);
160extern int hextoint(char c); 160extern int hextoint(char c);
161 161
162extern void *cgit_free_commitinfo(struct commitinfo *info); 162extern void *cgit_free_commitinfo(struct commitinfo *info);
163 163
164extern int cgit_diff_files(const unsigned char *old_sha1, 164extern int cgit_diff_files(const unsigned char *old_sha1,
165 const unsigned char *new_sha1, 165 const unsigned char *new_sha1,
166 linediff_fn fn); 166 linediff_fn fn);
167 167
168extern void cgit_diff_tree(const unsigned char *old_sha1, 168extern void cgit_diff_tree(const unsigned char *old_sha1,
169 const unsigned char *new_sha1, 169 const unsigned char *new_sha1,
170 filepair_fn fn); 170 filepair_fn fn);
171 171
172extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 172extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
173 173
174extern char *fmt(const char *format,...); 174extern char *fmt(const char *format,...);
175 175
176extern void html(const char *txt); 176extern void html(const char *txt);
177extern void htmlf(const char *format,...); 177extern void htmlf(const char *format,...);
178extern void html_txt(char *txt); 178extern void html_txt(char *txt);
179extern void html_ntxt(int len, char *txt); 179extern void html_ntxt(int len, char *txt);
180extern void html_attr(char *txt); 180extern void html_attr(char *txt);
181extern void html_hidden(char *name, char *value); 181extern void html_hidden(char *name, char *value);
182extern void html_link_open(char *url, char *title, char *class); 182extern void html_link_open(char *url, char *title, char *class);
183extern void html_link_close(void); 183extern void html_link_close(void);
184extern void html_filemode(unsigned short mode); 184extern void html_filemode(unsigned short mode);
185extern int html_include(const char *filename); 185extern int html_include(const char *filename);
186 186
187extern int cgit_read_config(const char *filename, configfn fn); 187extern int cgit_read_config(const char *filename, configfn fn);
188extern int cgit_parse_query(char *txt, configfn fn); 188extern int cgit_parse_query(char *txt, configfn fn);
189extern struct commitinfo *cgit_parse_commit(struct commit *commit); 189extern struct commitinfo *cgit_parse_commit(struct commit *commit);
190extern struct taginfo *cgit_parse_tag(struct tag *tag); 190extern struct taginfo *cgit_parse_tag(struct tag *tag);
191extern void cgit_parse_url(const char *url); 191extern void cgit_parse_url(const char *url);
192 192
193extern char *cache_safe_filename(const char *unsafe); 193extern char *cache_safe_filename(const char *unsafe);
194extern int cache_lock(struct cacheitem *item); 194extern int cache_lock(struct cacheitem *item);
195extern int cache_unlock(struct cacheitem *item); 195extern int cache_unlock(struct cacheitem *item);
196extern int cache_cancel_lock(struct cacheitem *item); 196extern int cache_cancel_lock(struct cacheitem *item);
197extern int cache_exist(struct cacheitem *item); 197extern int cache_exist(struct cacheitem *item);
198extern int cache_expired(struct cacheitem *item); 198extern int cache_expired(struct cacheitem *item);
199 199
200extern char *cgit_repourl(const char *reponame); 200extern char *cgit_repourl(const char *reponame);
201extern char *cgit_pageurl(const char *reponame, const char *pagename, 201extern char *cgit_pageurl(const char *reponame, const char *pagename,
202 const char *query); 202 const char *query);
203 203
204extern void cgit_tree_link(char *name, char *title, char *class, char *head, 204extern void cgit_tree_link(char *name, char *title, char *class, char *head,
205 char *rev, char *path); 205 char *rev, char *path);
206extern void cgit_log_link(char *name, char *title, char *class, char *head, 206extern void cgit_log_link(char *name, char *title, char *class, char *head,
207 char *rev, char *path); 207 char *rev, char *path);
208extern void cgit_commit_link(char *name, char *title, char *class, char *head,
209 char *rev);
208 210
209extern void cgit_print_error(char *msg); 211extern void cgit_print_error(char *msg);
210extern void cgit_print_date(time_t secs, char *format); 212extern void cgit_print_date(time_t secs, char *format);
211extern void cgit_print_age(time_t t, time_t max_relative, char *format); 213extern void cgit_print_age(time_t t, time_t max_relative, char *format);
212extern void cgit_print_docstart(char *title, struct cacheitem *item); 214extern void cgit_print_docstart(char *title, struct cacheitem *item);
213extern void cgit_print_docend(); 215extern void cgit_print_docend();
214extern void cgit_print_pageheader(char *title, int show_search); 216extern void cgit_print_pageheader(char *title, int show_search);
215extern void cgit_print_snapshot_start(const char *mimetype, 217extern void cgit_print_snapshot_start(const char *mimetype,
216 const char *filename, 218 const char *filename,
217 struct cacheitem *item); 219 struct cacheitem *item);
218 220
219extern void cgit_print_repolist(struct cacheitem *item); 221extern void cgit_print_repolist(struct cacheitem *item);
220extern void cgit_print_summary(); 222extern void cgit_print_summary();
221extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 223extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
222extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 224extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
223extern void cgit_print_tree(const char *rev, char *path); 225extern void cgit_print_tree(const char *rev, char *path);
224extern void cgit_print_commit(const char *hex); 226extern void cgit_print_commit(const char *hex);
225extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, 227extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex,
226 char *path); 228 char *path);
227extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 229extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
228 const char *format, const char *prefix, 230 const char *format, const char *prefix,
229 const char *filename); 231 const char *filename);
230 232
231#endif /* CGIT_H */ 233#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index 885f870..8864fc6 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -111,96 +111,99 @@ void cgit_count_diff_lines(char *line, int len)
111 if (line && (len > 0)) { 111 if (line && (len > 0)) {
112 if (line[0] == '+') 112 if (line[0] == '+')
113 lines_added++; 113 lines_added++;
114 else if (line[0] == '-') 114 else if (line[0] == '-')
115 lines_removed++; 115 lines_removed++;
116 } 116 }
117} 117}
118 118
119void inspect_filepair(struct diff_filepair *pair) 119void inspect_filepair(struct diff_filepair *pair)
120{ 120{
121 files++; 121 files++;
122 lines_added = 0; 122 lines_added = 0;
123 lines_removed = 0; 123 lines_removed = 0;
124 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); 124 cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines);
125 if (files >= slots) { 125 if (files >= slots) {
126 if (slots == 0) 126 if (slots == 0)
127 slots = 4; 127 slots = 4;
128 else 128 else
129 slots = slots * 2; 129 slots = slots * 2;
130 items = xrealloc(items, slots * sizeof(struct fileinfo)); 130 items = xrealloc(items, slots * sizeof(struct fileinfo));
131 } 131 }
132 items[files-1].status = pair->status; 132 items[files-1].status = pair->status;
133 hashcpy(items[files-1].old_sha1, pair->one->sha1); 133 hashcpy(items[files-1].old_sha1, pair->one->sha1);
134 hashcpy(items[files-1].new_sha1, pair->two->sha1); 134 hashcpy(items[files-1].new_sha1, pair->two->sha1);
135 items[files-1].old_mode = pair->one->mode; 135 items[files-1].old_mode = pair->one->mode;
136 items[files-1].new_mode = pair->two->mode; 136 items[files-1].new_mode = pair->two->mode;
137 items[files-1].old_path = xstrdup(pair->one->path); 137 items[files-1].old_path = xstrdup(pair->one->path);
138 items[files-1].new_path = xstrdup(pair->two->path); 138 items[files-1].new_path = xstrdup(pair->two->path);
139 items[files-1].added = lines_added; 139 items[files-1].added = lines_added;
140 items[files-1].removed = lines_removed; 140 items[files-1].removed = lines_removed;
141 if (lines_added + lines_removed > max_changes) 141 if (lines_added + lines_removed > max_changes)
142 max_changes = lines_added + lines_removed; 142 max_changes = lines_added + lines_removed;
143 total_adds += lines_added; 143 total_adds += lines_added;
144 total_rems += lines_removed; 144 total_rems += lines_removed;
145} 145}
146 146
147 147
148void cgit_print_commit(const char *hex) 148void cgit_print_commit(const char *hex)
149{ 149{
150 struct commit *commit, *parent; 150 struct commit *commit, *parent;
151 struct commitinfo *info; 151 struct commitinfo *info;
152 struct commit_list *p; 152 struct commit_list *p;
153 unsigned char sha1[20]; 153 unsigned char sha1[20];
154 char *query; 154 char *query;
155 char *filename; 155 char *filename;
156 char *tmp; 156 char *tmp;
157 int i; 157 int i;
158 158
159 if (!hex)
160 hex = cgit_query_head;
161
159 if (get_sha1(hex, sha1)) { 162 if (get_sha1(hex, sha1)) {
160 cgit_print_error(fmt("Bad object id: %s", hex)); 163 cgit_print_error(fmt("Bad object id: %s", hex));
161 return; 164 return;
162 } 165 }
163 commit = lookup_commit_reference(sha1); 166 commit = lookup_commit_reference(sha1);
164 if (!commit) { 167 if (!commit) {
165 cgit_print_error(fmt("Bad commit reference: %s", hex)); 168 cgit_print_error(fmt("Bad commit reference: %s", hex));
166 return; 169 return;
167 } 170 }
168 info = cgit_parse_commit(commit); 171 info = cgit_parse_commit(commit);
169 172
170 html("<table class='commit-info'>\n"); 173 html("<table class='commit-info'>\n");
171 html("<tr><th>author</th><td>"); 174 html("<tr><th>author</th><td>");
172 html_txt(info->author); 175 html_txt(info->author);
173 html(" "); 176 html(" ");
174 html_txt(info->author_email); 177 html_txt(info->author_email);
175 html("</td><td class='right'>"); 178 html("</td><td class='right'>");
176 cgit_print_date(info->author_date, FMT_LONGDATE); 179 cgit_print_date(info->author_date, FMT_LONGDATE);
177 html("</td></tr>\n"); 180 html("</td></tr>\n");
178 html("<tr><th>committer</th><td>"); 181 html("<tr><th>committer</th><td>");
179 html_txt(info->committer); 182 html_txt(info->committer);
180 html(" "); 183 html(" ");
181 html_txt(info->committer_email); 184 html_txt(info->committer_email);
182 html("</td><td class='right'>"); 185 html("</td><td class='right'>");
183 cgit_print_date(info->committer_date, FMT_LONGDATE); 186 cgit_print_date(info->committer_date, FMT_LONGDATE);
184 html("</td></tr>\n"); 187 html("</td></tr>\n");
185 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 188 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
186 tmp = xstrdup(hex); 189 tmp = xstrdup(hex);
187 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 190 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
188 cgit_query_head, tmp, NULL); 191 cgit_query_head, tmp, NULL);
189 html("</td></tr>\n"); 192 html("</td></tr>\n");
190 for (p = commit->parents; p ; p = p->next) { 193 for (p = commit->parents; p ; p = p->next) {
191 parent = lookup_commit_reference(p->item->object.sha1); 194 parent = lookup_commit_reference(p->item->object.sha1);
192 if (!parent) { 195 if (!parent) {
193 html("<tr><td colspan='3'>"); 196 html("<tr><td colspan='3'>");
194 cgit_print_error("Error reading parent commit"); 197 cgit_print_error("Error reading parent commit");
195 html("</td></tr>"); 198 html("</td></tr>");
196 continue; 199 continue;
197 } 200 }
198 html("<tr><th>parent</th>" 201 html("<tr><th>parent</th>"
199 "<td colspan='2' class='sha1'>" 202 "<td colspan='2' class='sha1'>"
200 "<a href='"); 203 "<a href='");
201 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); 204 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1));
202 html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); 205 html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
203 htmlf("'>%s</a> (<a href='", 206 htmlf("'>%s</a> (<a href='",
204 sha1_to_hex(p->item->object.sha1)); 207 sha1_to_hex(p->item->object.sha1));
205 query = fmt("id=%s&amp;id2=%s", sha1_to_hex(parent->tree->object.sha1), 208 query = fmt("id=%s&amp;id2=%s", sha1_to_hex(parent->tree->object.sha1),
206 sha1_to_hex(commit->tree->object.sha1)); 209 sha1_to_hex(commit->tree->object.sha1));
diff --git a/ui-log.c b/ui-log.c
index bb17e1d..8d774b0 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,86 +1,83 @@
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
11int files, lines; 11int files, lines;
12 12
13void count_lines(char *line, int size) 13void 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
19void inspect_files(struct diff_filepair *pair) 19void 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
26void print_commit(struct commit *commit) 26void print_commit(struct commit *commit)
27{ 27{
28 struct commitinfo *info; 28 struct commitinfo *info;
29 29
30 info = cgit_parse_commit(commit); 30 info = cgit_parse_commit(commit);
31 html("<tr><td>"); 31 html("<tr><td>");
32 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 32 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
33 html("</td><td>"); 33 html("</td><td>");
34 char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); 34 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
35 char *url = cgit_pageurl(cgit_query_repo, "commit", qry); 35 sha1_to_hex(commit->object.sha1));
36 html_link_open(url, NULL, NULL);
37 html_ntxt(cgit_max_msg_len, info->subject);
38 html_link_close();
39 if (cgit_repo->enable_log_filecount) { 36 if (cgit_repo->enable_log_filecount) {
40 files = 0; 37 files = 0;
41 lines = 0; 38 lines = 0;
42 cgit_diff_commit(commit, inspect_files); 39 cgit_diff_commit(commit, inspect_files);
43 html("</td><td class='right'>"); 40 html("</td><td class='right'>");
44 htmlf("%d", files); 41 htmlf("%d", files);
45 if (cgit_repo->enable_log_linecount) { 42 if (cgit_repo->enable_log_linecount) {
46 html("</td><td class='right'>"); 43 html("</td><td class='right'>");
47 htmlf("%d", lines); 44 htmlf("%d", lines);
48 } 45 }
49 } 46 }
50 html("</td><td>"); 47 html("</td><td>");
51 html_txt(info->author); 48 html_txt(info->author);
52 html("</td></tr>\n"); 49 html("</td></tr>\n");
53 cgit_free_commitinfo(info); 50 cgit_free_commitinfo(info);
54} 51}
55 52
56 53
57void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) 54void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager)
58{ 55{
59 struct rev_info rev; 56 struct rev_info rev;
60 struct commit *commit; 57 struct commit *commit;
61 const char *argv[] = {NULL, tip, NULL, NULL, NULL}; 58 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
62 int argc = 2; 59 int argc = 2;
63 int i; 60 int i;
64 61
65 if (grep) 62 if (grep)
66 argv[argc++] = fmt("--grep=%s", grep); 63 argv[argc++] = fmt("--grep=%s", grep);
67 if (path) { 64 if (path) {
68 argv[argc++] = "--"; 65 argv[argc++] = "--";
69 argv[argc++] = path; 66 argv[argc++] = path;
70 } 67 }
71 init_revisions(&rev, NULL); 68 init_revisions(&rev, NULL);
72 rev.abbrev = DEFAULT_ABBREV; 69 rev.abbrev = DEFAULT_ABBREV;
73 rev.commit_format = CMIT_FMT_DEFAULT; 70 rev.commit_format = CMIT_FMT_DEFAULT;
74 rev.verbose_header = 1; 71 rev.verbose_header = 1;
75 rev.show_root_diff = 0; 72 rev.show_root_diff = 0;
76 setup_revisions(argc, argv, &rev, NULL); 73 setup_revisions(argc, argv, &rev, NULL);
77 if (rev.grep_filter) { 74 if (rev.grep_filter) {
78 rev.grep_filter->regflags |= REG_ICASE; 75 rev.grep_filter->regflags |= REG_ICASE;
79 compile_grep_patterns(rev.grep_filter); 76 compile_grep_patterns(rev.grep_filter);
80 } 77 }
81 prepare_revision_walk(&rev); 78 prepare_revision_walk(&rev);
82 79
83 html("<table class='list nowrap'>"); 80 html("<table class='list nowrap'>");
84 html("<tr class='nohover'><th class='left'>Age</th>" 81 html("<tr class='nohover'><th class='left'>Age</th>"
85 "<th class='left'>Message</th>"); 82 "<th class='left'>Message</th>");
86 83
diff --git a/ui-shared.c b/ui-shared.c
index 64ee79c..71c899a 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -91,124 +91,136 @@ static char *repolink(char *title, char *class, char *page, char *head,
91 char *path) 91 char *path)
92{ 92{
93 char *delim = "?"; 93 char *delim = "?";
94 94
95 html("<a"); 95 html("<a");
96 if (title) { 96 if (title) {
97 html(" title='"); 97 html(" title='");
98 html_attr(title); 98 html_attr(title);
99 html("'"); 99 html("'");
100 } 100 }
101 if (class) { 101 if (class) {
102 html(" class='"); 102 html(" class='");
103 html_attr(class); 103 html_attr(class);
104 html("'"); 104 html("'");
105 } 105 }
106 html(" href='"); 106 html(" href='");
107 if (cgit_virtual_root) { 107 if (cgit_virtual_root) {
108 html_attr(cgit_virtual_root); 108 html_attr(cgit_virtual_root);
109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
110 html("/"); 110 html("/");
111 html_attr(cgit_repo->url); 111 html_attr(cgit_repo->url);
112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
113 html("/"); 113 html("/");
114 html(page); 114 html(page);
115 html("/"); 115 html("/");
116 if (path) 116 if (path)
117 html_attr(path); 117 html_attr(path);
118 } else { 118 } else {
119 html(cgit_script_name); 119 html(cgit_script_name);
120 html("?url="); 120 html("?url=");
121 html_attr(cgit_repo->url); 121 html_attr(cgit_repo->url);
122 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 122 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
123 html("/"); 123 html("/");
124 html(page); 124 html(page);
125 html("/"); 125 html("/");
126 if (path) 126 if (path)
127 html_attr(path); 127 html_attr(path);
128 delim = "&amp;"; 128 delim = "&amp;";
129 } 129 }
130 if (head && strcmp(head, cgit_repo->defbranch)) { 130 if (head && strcmp(head, cgit_repo->defbranch)) {
131 html(delim); 131 html(delim);
132 html("h="); 132 html("h=");
133 html_attr(head); 133 html_attr(head);
134 delim = "&amp;"; 134 delim = "&amp;";
135 } 135 }
136 return fmt("%s", delim); 136 return fmt("%s", delim);
137} 137}
138 138
139static char *reporevlink(char *page, char *name, char *title, char *class, 139static void reporevlink(char *page, char *name, char *title, char *class,
140 char *head, char *rev, char *path) 140 char *head, char *rev, char *path)
141{ 141{
142 char *delim; 142 char *delim;
143 143
144 delim = repolink(title, class, page, head, path); 144 delim = repolink(title, class, page, head, path);
145 if (rev && strcmp(rev, cgit_query_head)) { 145 if (rev && strcmp(rev, cgit_query_head)) {
146 html(delim); 146 html(delim);
147 html("id="); 147 html("id=");
148 html_attr(rev); 148 html_attr(rev);
149 } 149 }
150 html("'>"); 150 html("'>");
151 html_txt(name); 151 html_txt(name);
152 html("</a>"); 152 html("</a>");
153} 153}
154 154
155void cgit_tree_link(char *name, char *title, char *class, char *head, 155void cgit_tree_link(char *name, char *title, char *class, char *head,
156 char *rev, char *path) 156 char *rev, char *path)
157{ 157{
158 reporevlink("tree", name, title, class, head, rev, path); 158 reporevlink("tree", name, title, class, head, rev, path);
159} 159}
160 160
161void cgit_log_link(char *name, char *title, char *class, char *head, 161void cgit_log_link(char *name, char *title, char *class, char *head,
162 char *rev, char *path) 162 char *rev, char *path)
163{ 163{
164 reporevlink("log", name, title, class, head, rev, path); 164 reporevlink("log", name, title, class, head, rev, path);
165} 165}
166 166
167void cgit_commit_link(char *name, char *title, char *class, char *head,
168 char *rev)
169{
170 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) {
171 name[cgit_max_msg_len] = '\0';
172 name[cgit_max_msg_len - 1] = '.';
173 name[cgit_max_msg_len - 2] = '.';
174 name[cgit_max_msg_len - 3] = '.';
175 }
176 reporevlink("commit", name, title, class, head, rev, NULL);
177}
178
167void cgit_print_date(time_t secs, char *format) 179void cgit_print_date(time_t secs, char *format)
168{ 180{
169 char buf[64]; 181 char buf[64];
170 struct tm *time; 182 struct tm *time;
171 183
172 time = gmtime(&secs); 184 time = gmtime(&secs);
173 strftime(buf, sizeof(buf)-1, format, time); 185 strftime(buf, sizeof(buf)-1, format, time);
174 html_txt(buf); 186 html_txt(buf);
175} 187}
176 188
177void cgit_print_age(time_t t, time_t max_relative, char *format) 189void cgit_print_age(time_t t, time_t max_relative, char *format)
178{ 190{
179 time_t now, secs; 191 time_t now, secs;
180 192
181 time(&now); 193 time(&now);
182 secs = now - t; 194 secs = now - t;
183 195
184 if (secs > max_relative && max_relative >= 0) { 196 if (secs > max_relative && max_relative >= 0) {
185 cgit_print_date(t, format); 197 cgit_print_date(t, format);
186 return; 198 return;
187 } 199 }
188 200
189 if (secs < TM_HOUR * 2) { 201 if (secs < TM_HOUR * 2) {
190 htmlf("<span class='age-mins'>%.0f min.</span>", 202 htmlf("<span class='age-mins'>%.0f min.</span>",
191 secs * 1.0 / TM_MIN); 203 secs * 1.0 / TM_MIN);
192 return; 204 return;
193 } 205 }
194 if (secs < TM_DAY * 2) { 206 if (secs < TM_DAY * 2) {
195 htmlf("<span class='age-hours'>%.0f hours</span>", 207 htmlf("<span class='age-hours'>%.0f hours</span>",
196 secs * 1.0 / TM_HOUR); 208 secs * 1.0 / TM_HOUR);
197 return; 209 return;
198 } 210 }
199 if (secs < TM_WEEK * 2) { 211 if (secs < TM_WEEK * 2) {
200 htmlf("<span class='age-days'>%.0f days</span>", 212 htmlf("<span class='age-days'>%.0f days</span>",
201 secs * 1.0 / TM_DAY); 213 secs * 1.0 / TM_DAY);
202 return; 214 return;
203 } 215 }
204 if (secs < TM_MONTH * 2) { 216 if (secs < TM_MONTH * 2) {
205 htmlf("<span class='age-weeks'>%.0f weeks</span>", 217 htmlf("<span class='age-weeks'>%.0f weeks</span>",
206 secs * 1.0 / TM_WEEK); 218 secs * 1.0 / TM_WEEK);
207 return; 219 return;
208 } 220 }
209 if (secs < TM_YEAR * 2) { 221 if (secs < TM_YEAR * 2) {
210 htmlf("<span class='age-months'>%.0f months</span>", 222 htmlf("<span class='age-months'>%.0f months</span>",
211 secs * 1.0 / TM_MONTH); 223 secs * 1.0 / TM_MONTH);
212 return; 224 return;
213 } 225 }
214 htmlf("<span class='age-years'>%.0f years</span>", 226 htmlf("<span class='age-years'>%.0f years</span>",
diff --git a/ui-summary.c b/ui-summary.c
index 29b76e3..03dd078 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,106 +1,106 @@
1/* ui-summary.c: functions for generating repo summary page 1/* ui-summary.c: functions for generating repo summary page
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11static int header; 11static int header;
12 12
13static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, 13static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
14 int flags, void *cb_data) 14 int flags, void *cb_data)
15{ 15{
16 struct commit *commit; 16 struct commit *commit;
17 struct commitinfo *info; 17 struct commitinfo *info;
18 char buf[256], *url; 18 char buf[256];
19 char *ref;
19 20
21 ref = xstrdup(refname);
20 strncpy(buf, refname, sizeof(buf)); 22 strncpy(buf, refname, sizeof(buf));
21 commit = lookup_commit(sha1); 23 commit = lookup_commit(sha1);
22 // object is not really parsed at this point, because of some fallout 24 // object is not really parsed at this point, because of some fallout
23 // from previous calls to git functions in cgit_print_log() 25 // from previous calls to git functions in cgit_print_log()
24 commit->object.parsed = 0; 26 commit->object.parsed = 0;
25 if (commit && !parse_commit(commit)){ 27 if (commit && !parse_commit(commit)){
26 info = cgit_parse_commit(commit); 28 info = cgit_parse_commit(commit);
27 html("<tr><td>"); 29 html("<tr><td>");
28 cgit_log_link(refname, NULL, NULL, refname, NULL, NULL); 30 cgit_log_link(ref, NULL, NULL, ref, NULL, NULL);
29 html("</td><td>"); 31 html("</td><td>");
30 cgit_print_age(commit->date, -1, NULL); 32 cgit_print_age(commit->date, -1, NULL);
31 html("</td><td>"); 33 html("</td><td>");
32 html_txt(info->author); 34 html_txt(info->author);
33 html("</td><td>"); 35 html("</td><td>");
34 url = cgit_pageurl(cgit_query_repo, "commit", 36 cgit_commit_link(info->subject, NULL, NULL, ref, NULL);
35 fmt("h=%s", sha1_to_hex(sha1)));
36 html_link_open(url, NULL, NULL);
37 html_ntxt(cgit_max_msg_len, info->subject);
38 html_link_close();
39 html("</td></tr>\n"); 37 html("</td></tr>\n");
40 cgit_free_commitinfo(info); 38 cgit_free_commitinfo(info);
41 } else { 39 } else {
42 html("<tr><td>"); 40 html("<tr><td>");
43 html_txt(buf); 41 html_txt(buf);
44 html("</td><td colspan='3'>"); 42 html("</td><td colspan='3'>");
45 htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); 43 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
46 html("</td></tr>\n"); 44 html("</td></tr>\n");
47 } 45 }
46 free(ref);
48 return 0; 47 return 0;
49} 48}
50 49
51 50
52static void cgit_print_object_ref(struct object *obj) 51static void cgit_print_object_ref(struct object *obj)
53{ 52{
54 char *page, *arg, *url; 53 char *page, *arg, *url;
55 54
56 if (obj->type == OBJ_COMMIT) { 55 if (obj->type == OBJ_COMMIT) {
57 page = "commit"; 56 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
58 arg = "h"; 57 cgit_query_head, sha1_to_hex(obj->sha1));
58 return;
59 } else if (obj->type == OBJ_TREE) { 59 } else if (obj->type == OBJ_TREE) {
60 page = "tree"; 60 page = "tree";
61 arg = "id"; 61 arg = "id";
62 } else { 62 } else {
63 page = "view"; 63 page = "view";
64 arg = "id"; 64 arg = "id";
65 } 65 }
66 66
67 url = cgit_pageurl(cgit_query_repo, page, 67 url = cgit_pageurl(cgit_query_repo, page,
68 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 68 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
69 html_link_open(url, NULL, NULL); 69 html_link_open(url, NULL, NULL);
70 htmlf("%s %s", typename(obj->type), 70 htmlf("%s %s", typename(obj->type),
71 sha1_to_hex(obj->sha1)); 71 sha1_to_hex(obj->sha1));
72 html_link_close(); 72 html_link_close();
73} 73}
74 74
75static void print_tag_header() 75static void print_tag_header()
76{ 76{
77 html("<tr class='nohover'><th class='left'>Tag</th>" 77 html("<tr class='nohover'><th class='left'>Tag</th>"
78 "<th class='left'>Age</th>" 78 "<th class='left'>Age</th>"
79 "<th class='left'>Author</th>" 79 "<th class='left'>Author</th>"
80 "<th class='left'>Reference</th></tr>\n"); 80 "<th class='left'>Reference</th></tr>\n");
81 header = 1; 81 header = 1;
82} 82}
83 83
84static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, 84static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
85 int flags, void *cb_data) 85 int flags, void *cb_data)
86{ 86{
87 struct tag *tag; 87 struct tag *tag;
88 struct taginfo *info; 88 struct taginfo *info;
89 struct object *obj; 89 struct object *obj;
90 char buf[256], *url; 90 char buf[256], *url;
91 91
92 strncpy(buf, refname, sizeof(buf)); 92 strncpy(buf, refname, sizeof(buf));
93 obj = parse_object(sha1); 93 obj = parse_object(sha1);
94 if (!obj) 94 if (!obj)
95 return 1; 95 return 1;
96 if (obj->type == OBJ_TAG) { 96 if (obj->type == OBJ_TAG) {
97 tag = lookup_tag(sha1); 97 tag = lookup_tag(sha1);
98 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 98 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
99 return 2; 99 return 2;
100 if (!header) 100 if (!header)
101 print_tag_header(); 101 print_tag_header();
102 html("<tr><td>"); 102 html("<tr><td>");
103 url = cgit_pageurl(cgit_query_repo, "view", 103 url = cgit_pageurl(cgit_query_repo, "view",
104 fmt("id=%s", sha1_to_hex(sha1))); 104 fmt("id=%s", sha1_to_hex(sha1)));
105 html_link_open(url, NULL, NULL); 105 html_link_open(url, NULL, NULL);
106 html_txt(buf); 106 html_txt(buf);
diff --git a/ui-tree.c b/ui-tree.c
index e16b638..1037c82 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -13,97 +13,96 @@ char *match_path;
13int header = 0; 13int header = 0;
14 14
15static void print_object(const unsigned char *sha1, char *path) 15static void print_object(const unsigned char *sha1, char *path)
16{ 16{
17 enum object_type type; 17 enum object_type type;
18 unsigned char *buf; 18 unsigned char *buf;
19 unsigned long size, lineno, start, idx; 19 unsigned long size, lineno, start, idx;
20 20
21 type = sha1_object_info(sha1, &size); 21 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD) { 22 if (type == OBJ_BAD) {
23 cgit_print_error(fmt("Bad object name: %s", 23 cgit_print_error(fmt("Bad object name: %s",
24 sha1_to_hex(sha1))); 24 sha1_to_hex(sha1)));
25 return; 25 return;
26 } 26 }
27 27
28 buf = read_sha1_file(sha1, &type, &size); 28 buf = read_sha1_file(sha1, &type, &size);
29 if (!buf) { 29 if (!buf) {
30 cgit_print_error(fmt("Error reading object %s", 30 cgit_print_error(fmt("Error reading object %s",
31 sha1_to_hex(sha1))); 31 sha1_to_hex(sha1)));
32 return; 32 return;
33 } 33 }
34 34
35 html("<table class='blob'>\n"); 35 html("<table class='blob'>\n");
36 idx = 0; 36 idx = 0;
37 start = 0; 37 start = 0;
38 lineno = 0; 38 lineno = 0;
39 while(idx < size) { 39 while(idx < size) {
40 if (buf[idx] == '\n') { 40 if (buf[idx] == '\n') {
41 buf[idx] = '\0'; 41 buf[idx] = '\0';
42 htmlf("<tr><td class='no'>%d</td><td class='txt'>", 42 htmlf("<tr><td class='no'>%d</td><td class='txt'>",
43 ++lineno); 43 ++lineno);
44 html_txt(buf + start); 44 html_txt(buf + start);
45 html("</td></tr>\n"); 45 html("</td></tr>\n");
46 start = idx + 1; 46 start = idx + 1;
47 } 47 }
48 idx++; 48 idx++;
49 } 49 }
50 html("</table>\n"); 50 html("</table>\n");
51} 51}
52 52
53 53
54static int ls_item(const unsigned char *sha1, const char *base, int baselen, 54static int ls_item(const unsigned char *sha1, const char *base, int baselen,
55 const char *pathname, unsigned int mode, int stage) 55 const char *pathname, unsigned int mode, int stage)
56{ 56{
57 char *name; 57 char *name;
58 char *fullpath; 58 char *fullpath;
59 enum object_type type; 59 enum object_type type;
60 unsigned long size = 0; 60 unsigned long size = 0;
61 char *url, *qry;
62 61
63 name = xstrdup(pathname); 62 name = xstrdup(pathname);
64 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", 63 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
65 cgit_query_path ? "/" : "", name); 64 cgit_query_path ? "/" : "", name);
66 65
67 type = sha1_object_info(sha1, &size); 66 type = sha1_object_info(sha1, &size);
68 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 67 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
69 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 68 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
70 name, 69 name,
71 sha1_to_hex(sha1)); 70 sha1_to_hex(sha1));
72 return 0; 71 return 0;
73 } 72 }
74 73
75 html("<tr><td class='ls-mode'>"); 74 html("<tr><td class='ls-mode'>");
76 html_filemode(mode); 75 html_filemode(mode);
77 html("</td><td>"); 76 html("</td><td>");
78 if (S_ISDIRLNK(mode)) { 77 if (S_ISDIRLNK(mode)) {
79 htmlf("<a class='ls-mod' href='"); 78 htmlf("<a class='ls-mod' href='");
80 html_attr(fmt(cgit_repo->module_link, 79 html_attr(fmt(cgit_repo->module_link,
81 name, 80 name,
82 sha1_to_hex(sha1))); 81 sha1_to_hex(sha1)));
83 html("'>"); 82 html("'>");
84 html_txt(name); 83 html_txt(name);
85 html("</a>"); 84 html("</a>");
86 } else if (S_ISDIR(mode)) { 85 } else if (S_ISDIR(mode)) {
87 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, 86 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head,
88 curr_rev, fullpath); 87 curr_rev, fullpath);
89 } else { 88 } else {
90 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, 89 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head,
91 curr_rev, fullpath); 90 curr_rev, fullpath);
92 } 91 }
93 htmlf("</td><td class='ls-size'>%li</td>", size); 92 htmlf("</td><td class='ls-size'>%li</td>", size);
94 93
95 html("<td>"); 94 html("<td>");
96 cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev, 95 cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev,
97 fullpath); 96 fullpath);
98 html("</td></tr>\n"); 97 html("</td></tr>\n");
99 free(name); 98 free(name);
100 return 0; 99 return 0;
101} 100}
102 101
103static void ls_head() 102static void ls_head()
104{ 103{
105 html("<table class='list'>\n"); 104 html("<table class='list'>\n");
106 html("<tr class='nohover'>"); 105 html("<tr class='nohover'>");
107 html("<th class='left'>Mode</th>"); 106 html("<th class='left'>Mode</th>");
108 html("<th class='left'>Name</th>"); 107 html("<th class='left'>Name</th>");
109 html("<th class='right'>Size</th>"); 108 html("<th class='right'>Size</th>");