summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c5
-rw-r--r--cgit.css5
-rw-r--r--cgit.h4
-rw-r--r--ui-commit.c3
-rw-r--r--ui-log.c8
-rw-r--r--ui-tree.c25
6 files changed, 37 insertions, 13 deletions
diff --git a/cgit.c b/cgit.c
index 3d85a08..9e63d18 100644
--- a/cgit.c
+++ b/cgit.c
@@ -63,99 +63,100 @@ static int cgit_prepare_cache(struct cacheitem *item)
63static void cgit_print_repo_page(struct cacheitem *item) 63static void cgit_print_repo_page(struct cacheitem *item)
64{ 64{
65 char *title; 65 char *title;
66 int show_search; 66 int show_search;
67 67
68 if (chdir(cgit_repo->path)) { 68 if (chdir(cgit_repo->path)) {
69 title = fmt("%s - %s", cgit_root_title, "Bad request"); 69 title = fmt("%s - %s", cgit_root_title, "Bad request");
70 cgit_print_docstart(title, item); 70 cgit_print_docstart(title, item);
71 cgit_print_pageheader(title, 0); 71 cgit_print_pageheader(title, 0);
72 cgit_print_error(fmt("Unable to scan repository: %s", 72 cgit_print_error(fmt("Unable to scan repository: %s",
73 strerror(errno))); 73 strerror(errno)));
74 cgit_print_docend(); 74 cgit_print_docend();
75 return; 75 return;
76 } 76 }
77 77
78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
79 show_search = 0; 79 show_search = 0;
80 setenv("GIT_DIR", cgit_repo->path, 1); 80 setenv("GIT_DIR", cgit_repo->path, 1);
81 81
82 if (cgit_query_page) { 82 if (cgit_query_page) {
83 if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { 83 if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) {
84 cgit_print_snapshot(item, cgit_query_sha1, "zip", 84 cgit_print_snapshot(item, cgit_query_sha1, "zip",
85 cgit_repo->url, cgit_query_name); 85 cgit_repo->url, cgit_query_name);
86 return; 86 return;
87 } 87 }
88 if (!strcmp(cgit_query_page, "blob")) { 88 if (!strcmp(cgit_query_page, "blob")) {
89 cgit_print_blob(item, cgit_query_sha1, cgit_query_path); 89 cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
90 return; 90 return;
91 } 91 }
92 } 92 }
93 93
94 if (cgit_query_page && !strcmp(cgit_query_page, "log")) 94 if (cgit_query_page && !strcmp(cgit_query_page, "log"))
95 show_search = 1; 95 show_search = 1;
96 96
97 cgit_print_docstart(title, item); 97 cgit_print_docstart(title, item);
98 98
99 99
100 if (!cgit_query_page) { 100 if (!cgit_query_page) {
101 cgit_print_pageheader("summary", show_search); 101 cgit_print_pageheader("summary", show_search);
102 cgit_print_summary(); 102 cgit_print_summary();
103 cgit_print_docend(); 103 cgit_print_docend();
104 return; 104 return;
105 } 105 }
106 106
107 cgit_print_pageheader(cgit_query_page, show_search); 107 cgit_print_pageheader(cgit_query_page, show_search);
108 108
109 if (!strcmp(cgit_query_page, "log")) { 109 if (!strcmp(cgit_query_page, "log")) {
110 cgit_print_log(cgit_query_head, cgit_query_ofs, 110 cgit_print_log(cgit_query_head, cgit_query_ofs,
111 cgit_max_commit_count, cgit_query_search); 111 cgit_max_commit_count, cgit_query_search,
112 cgit_query_path);
112 } else if (!strcmp(cgit_query_page, "tree")) { 113 } else if (!strcmp(cgit_query_page, "tree")) {
113 cgit_print_tree(cgit_query_sha1, cgit_query_path); 114 cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path);
114 } else if (!strcmp(cgit_query_page, "commit")) { 115 } else if (!strcmp(cgit_query_page, "commit")) {
115 cgit_print_commit(cgit_query_sha1); 116 cgit_print_commit(cgit_query_sha1);
116 } else if (!strcmp(cgit_query_page, "view")) { 117 } else if (!strcmp(cgit_query_page, "view")) {
117 cgit_print_view(cgit_query_sha1, cgit_query_path); 118 cgit_print_view(cgit_query_sha1, cgit_query_path);
118 } else if (!strcmp(cgit_query_page, "diff")) { 119 } else if (!strcmp(cgit_query_page, "diff")) {
119 cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); 120 cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path);
120 } else { 121 } else {
121 cgit_print_error("Invalid request"); 122 cgit_print_error("Invalid request");
122 } 123 }
123 cgit_print_docend(); 124 cgit_print_docend();
124} 125}
125 126
126static void cgit_fill_cache(struct cacheitem *item, int use_cache) 127static void cgit_fill_cache(struct cacheitem *item, int use_cache)
127{ 128{
128 static char buf[PATH_MAX]; 129 static char buf[PATH_MAX];
129 int stdout2; 130 int stdout2;
130 131
131 getcwd(buf, sizeof(buf)); 132 getcwd(buf, sizeof(buf));
132 item->st.st_mtime = time(NULL); 133 item->st.st_mtime = time(NULL);
133 134
134 if (use_cache) { 135 if (use_cache) {
135 stdout2 = chk_positive(dup(STDOUT_FILENO), 136 stdout2 = chk_positive(dup(STDOUT_FILENO),
136 "Preserving STDOUT"); 137 "Preserving STDOUT");
137 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 138 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
138 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 139 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
139 } 140 }
140 141
141 if (cgit_query_repo) 142 if (cgit_query_repo)
142 cgit_print_repo_page(item); 143 cgit_print_repo_page(item);
143 else 144 else
144 cgit_print_repolist(item); 145 cgit_print_repolist(item);
145 146
146 if (use_cache) { 147 if (use_cache) {
147 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 148 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
148 chk_positive(dup2(stdout2, STDOUT_FILENO), 149 chk_positive(dup2(stdout2, STDOUT_FILENO),
149 "Restoring original STDOUT"); 150 "Restoring original STDOUT");
150 chk_zero(close(stdout2), "Closing temporary STDOUT"); 151 chk_zero(close(stdout2), "Closing temporary STDOUT");
151 } 152 }
152 153
153 chdir(buf); 154 chdir(buf);
154} 155}
155 156
156static void cgit_check_cache(struct cacheitem *item) 157static void cgit_check_cache(struct cacheitem *item)
157{ 158{
158 int i = 0; 159 int i = 0;
159 160
160 top: 161 top:
161 if (++i > cgit_max_lock_attempts) { 162 if (++i > cgit_max_lock_attempts) {
diff --git a/cgit.css b/cgit.css
index fe0ba50..6231e28 100644
--- a/cgit.css
+++ b/cgit.css
@@ -144,96 +144,101 @@ td#summary {
144 vertical-align: top; 144 vertical-align: top;
145 padding-bottom: 1em; 145 padding-bottom: 1em;
146} 146}
147 147
148td#archivelist { 148td#archivelist {
149 padding-bottom: 1em; 149 padding-bottom: 1em;
150} 150}
151 151
152td#archivelist table { 152td#archivelist table {
153 float: right; 153 float: right;
154 border-collapse: collapse; 154 border-collapse: collapse;
155 border: solid 1px #777; 155 border: solid 1px #777;
156} 156}
157 157
158td#archivelist table th { 158td#archivelist table th {
159 background-color: #ccc; 159 background-color: #ccc;
160} 160}
161 161
162td#content { 162td#content {
163 padding: 1em 0.5em; 163 padding: 1em 0.5em;
164} 164}
165 165
166div#blob { 166div#blob {
167 border: solid 1px black; 167 border: solid 1px black;
168} 168}
169 169
170div.error { 170div.error {
171 color: red; 171 color: red;
172 font-weight: bold; 172 font-weight: bold;
173 margin: 1em 2em; 173 margin: 1em 2em;
174} 174}
175 175
176td.ls-blob, td.ls-dir, td.ls-mod { 176td.ls-blob, td.ls-dir, td.ls-mod {
177 font-family: monospace; 177 font-family: monospace;
178} 178}
179 179
180div.ls-dir a { 180div.ls-dir a {
181 font-weight: bold; 181 font-weight: bold;
182} 182}
183 183
184th.filesize, td.filesize { 184th.filesize, td.filesize {
185 text-align: right; 185 text-align: right;
186} 186}
187 187
188td.filesize { 188td.filesize {
189 font-family: monospace; 189 font-family: monospace;
190} 190}
191 191
192td.links {
193 font-size: 80%;
194 padding-left: 2em;
195}
196
192td.filemode { 197td.filemode {
193 font-family: monospace; 198 font-family: monospace;
194} 199}
195 200
196td.blob { 201td.blob {
197 white-space: pre; 202 white-space: pre;
198 font-family: monospace; 203 font-family: monospace;
199 background-color: white; 204 background-color: white;
200} 205}
201 206
202table.nowrap td { 207table.nowrap td {
203 white-space: nowrap; 208 white-space: nowrap;
204} 209}
205 210
206table.commit-info { 211table.commit-info {
207 border-collapse: collapse; 212 border-collapse: collapse;
208 margin-top: 1.5em; 213 margin-top: 1.5em;
209} 214}
210 215
211table.commit-info th { 216table.commit-info th {
212 text-align: left; 217 text-align: left;
213 font-weight: normal; 218 font-weight: normal;
214 padding: 0.1em 1em 0.1em 0.1em; 219 padding: 0.1em 1em 0.1em 0.1em;
215} 220}
216 221
217table.commit-info td { 222table.commit-info td {
218 font-weight: normal; 223 font-weight: normal;
219 padding: 0.1em 1em 0.1em 0.1em; 224 padding: 0.1em 1em 0.1em 0.1em;
220} 225}
221 226
222div.commit-subject { 227div.commit-subject {
223 font-weight: bold; 228 font-weight: bold;
224 font-size: 125%; 229 font-size: 125%;
225 margin: 1.5em 0em 0.5em 0em; 230 margin: 1.5em 0em 0.5em 0em;
226 padding: 0em; 231 padding: 0em;
227} 232}
228 233
229div.commit-msg { 234div.commit-msg {
230 white-space: pre; 235 white-space: pre;
231 font-family: monospace; 236 font-family: monospace;
232} 237}
233 238
234table.diffstat { 239table.diffstat {
235 border-collapse: collapse; 240 border-collapse: collapse;
236 margin-top: 1.5em; 241 margin-top: 1.5em;
237 width: 100%; 242 width: 100%;
238 border: solid 1px #aaa; 243 border: solid 1px #aaa;
239} 244}
diff --git a/cgit.h b/cgit.h
index 93699b5..0fff7b0 100644
--- a/cgit.h
+++ b/cgit.h
@@ -124,59 +124,59 @@ extern int cgit_diff_files(const unsigned char *old_sha1,
124 const unsigned char *new_sha1, 124 const unsigned char *new_sha1,
125 linediff_fn fn); 125 linediff_fn fn);
126 126
127extern void cgit_diff_tree(const unsigned char *old_sha1, 127extern void cgit_diff_tree(const unsigned char *old_sha1,
128 const unsigned char *new_sha1, 128 const unsigned char *new_sha1,
129 filepair_fn fn); 129 filepair_fn fn);
130 130
131extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 131extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
132 132
133extern char *fmt(const char *format,...); 133extern char *fmt(const char *format,...);
134 134
135extern void html(const char *txt); 135extern void html(const char *txt);
136extern void htmlf(const char *format,...); 136extern void htmlf(const char *format,...);
137extern void html_txt(char *txt); 137extern void html_txt(char *txt);
138extern void html_ntxt(int len, char *txt); 138extern void html_ntxt(int len, char *txt);
139extern void html_attr(char *txt); 139extern void html_attr(char *txt);
140extern void html_hidden(char *name, char *value); 140extern void html_hidden(char *name, char *value);
141extern void html_link_open(char *url, char *title, char *class); 141extern void html_link_open(char *url, char *title, char *class);
142extern void html_link_close(void); 142extern void html_link_close(void);
143extern void html_filemode(unsigned short mode); 143extern void html_filemode(unsigned short mode);
144 144
145extern int cgit_read_config(const char *filename, configfn fn); 145extern int cgit_read_config(const char *filename, configfn fn);
146extern int cgit_parse_query(char *txt, configfn fn); 146extern int cgit_parse_query(char *txt, configfn fn);
147extern struct commitinfo *cgit_parse_commit(struct commit *commit); 147extern struct commitinfo *cgit_parse_commit(struct commit *commit);
148extern struct taginfo *cgit_parse_tag(struct tag *tag); 148extern struct taginfo *cgit_parse_tag(struct tag *tag);
149 149
150extern char *cache_safe_filename(const char *unsafe); 150extern char *cache_safe_filename(const char *unsafe);
151extern int cache_lock(struct cacheitem *item); 151extern int cache_lock(struct cacheitem *item);
152extern int cache_unlock(struct cacheitem *item); 152extern int cache_unlock(struct cacheitem *item);
153extern int cache_cancel_lock(struct cacheitem *item); 153extern int cache_cancel_lock(struct cacheitem *item);
154extern int cache_exist(struct cacheitem *item); 154extern int cache_exist(struct cacheitem *item);
155extern int cache_expired(struct cacheitem *item); 155extern int cache_expired(struct cacheitem *item);
156 156
157extern char *cgit_repourl(const char *reponame); 157extern char *cgit_repourl(const char *reponame);
158extern char *cgit_pageurl(const char *reponame, const char *pagename, 158extern char *cgit_pageurl(const char *reponame, const char *pagename,
159 const char *query); 159 const char *query);
160 160
161extern void cgit_print_error(char *msg); 161extern void cgit_print_error(char *msg);
162extern void cgit_print_date(unsigned long secs); 162extern void cgit_print_date(unsigned long secs);
163extern void cgit_print_docstart(char *title, struct cacheitem *item); 163extern void cgit_print_docstart(char *title, struct cacheitem *item);
164extern void cgit_print_docend(); 164extern void cgit_print_docend();
165extern void cgit_print_pageheader(char *title, int show_search); 165extern void cgit_print_pageheader(char *title, int show_search);
166extern void cgit_print_snapshot_start(const char *mimetype, 166extern void cgit_print_snapshot_start(const char *mimetype,
167 const char *filename, 167 const char *filename,
168 struct cacheitem *item); 168 struct cacheitem *item);
169 169
170extern void cgit_print_repolist(struct cacheitem *item); 170extern void cgit_print_repolist(struct cacheitem *item);
171extern void cgit_print_summary(); 171extern void cgit_print_summary();
172extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); 172extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path);
173extern void cgit_print_view(const char *hex, char *path); 173extern void cgit_print_view(const char *hex, char *path);
174extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 174extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
175extern void cgit_print_tree(const char *hex, char *path); 175extern void cgit_print_tree(const char *rev, const char *hex, char *path);
176extern void cgit_print_commit(const char *hex); 176extern void cgit_print_commit(const char *hex);
177extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); 177extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path);
178extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 178extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
179 const char *format, const char *prefix, 179 const char *format, const char *prefix,
180 const char *filename); 180 const char *filename);
181 181
182#endif /* CGIT_H */ 182#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index b3d1c28..20a7cb2 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -141,97 +141,98 @@ void inspect_filepair(struct diff_filepair *pair)
141 items[files-1].old_path = xstrdup(pair->one->path); 141 items[files-1].old_path = xstrdup(pair->one->path);
142 items[files-1].new_path = xstrdup(pair->two->path); 142 items[files-1].new_path = xstrdup(pair->two->path);
143 items[files-1].added = lines_added; 143 items[files-1].added = lines_added;
144 items[files-1].removed = lines_removed; 144 items[files-1].removed = lines_removed;
145 if (lines_added + lines_removed > max_changes) 145 if (lines_added + lines_removed > max_changes)
146 max_changes = lines_added + lines_removed; 146 max_changes = lines_added + lines_removed;
147 total_adds += lines_added; 147 total_adds += lines_added;
148 total_rems += lines_removed; 148 total_rems += lines_removed;
149} 149}
150 150
151 151
152void cgit_print_commit(const char *hex) 152void cgit_print_commit(const char *hex)
153{ 153{
154 struct commit *commit, *parent; 154 struct commit *commit, *parent;
155 struct commitinfo *info; 155 struct commitinfo *info;
156 struct commit_list *p; 156 struct commit_list *p;
157 unsigned char sha1[20]; 157 unsigned char sha1[20];
158 char *query; 158 char *query;
159 char *filename; 159 char *filename;
160 int i; 160 int i;
161 161
162 if (get_sha1(hex, sha1)) { 162 if (get_sha1(hex, sha1)) {
163 cgit_print_error(fmt("Bad object id: %s", hex)); 163 cgit_print_error(fmt("Bad object id: %s", hex));
164 return; 164 return;
165 } 165 }
166 commit = lookup_commit_reference(sha1); 166 commit = lookup_commit_reference(sha1);
167 if (!commit) { 167 if (!commit) {
168 cgit_print_error(fmt("Bad commit reference: %s", hex)); 168 cgit_print_error(fmt("Bad commit reference: %s", hex));
169 return; 169 return;
170 } 170 }
171 info = cgit_parse_commit(commit); 171 info = cgit_parse_commit(commit);
172 172
173 html("<table class='commit-info'>\n"); 173 html("<table class='commit-info'>\n");
174 html("<tr><th>author</th><td>"); 174 html("<tr><th>author</th><td>");
175 html_txt(info->author); 175 html_txt(info->author);
176 html(" "); 176 html(" ");
177 html_txt(info->author_email); 177 html_txt(info->author_email);
178 html("</td><td class='right'>"); 178 html("</td><td class='right'>");
179 cgit_print_date(info->author_date); 179 cgit_print_date(info->author_date);
180 html("</td></tr>\n"); 180 html("</td></tr>\n");
181 html("<tr><th>committer</th><td>"); 181 html("<tr><th>committer</th><td>");
182 html_txt(info->committer); 182 html_txt(info->committer);
183 html(" "); 183 html(" ");
184 html_txt(info->committer_email); 184 html_txt(info->committer_email);
185 html("</td><td class='right'>"); 185 html("</td><td class='right'>");
186 cgit_print_date(info->committer_date); 186 cgit_print_date(info->committer_date);
187 html("</td></tr>\n"); 187 html("</td></tr>\n");
188 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); 188 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
189 query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); 189 query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1),
190 sha1_to_hex(commit->tree->object.sha1));
190 html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); 191 html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
191 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); 192 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
192 for (p = commit->parents; p ; p = p->next) { 193 for (p = commit->parents; p ; p = p->next) {
193 parent = lookup_commit_reference(p->item->object.sha1); 194 parent = lookup_commit_reference(p->item->object.sha1);
194 if (!parent) { 195 if (!parent) {
195 html("<tr><td colspan='3'>"); 196 html("<tr><td colspan='3'>");
196 cgit_print_error("Error reading parent commit"); 197 cgit_print_error("Error reading parent commit");
197 html("</td></tr>"); 198 html("</td></tr>");
198 continue; 199 continue;
199 } 200 }
200 html("<tr><th>parent</th>" 201 html("<tr><th>parent</th>"
201 "<td colspan='2' class='sha1'>" 202 "<td colspan='2' class='sha1'>"
202 "<a href='"); 203 "<a href='");
203 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); 204 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1));
204 html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); 205 html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
205 htmlf("'>%s</a> (<a href='", 206 htmlf("'>%s</a> (<a href='",
206 sha1_to_hex(p->item->object.sha1)); 207 sha1_to_hex(p->item->object.sha1));
207 query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), 208 query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1),
208 sha1_to_hex(commit->tree->object.sha1)); 209 sha1_to_hex(commit->tree->object.sha1));
209 html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); 210 html_attr(cgit_pageurl(cgit_query_repo, "diff", query));
210 html("'>diff</a>)</td></tr>"); 211 html("'>diff</a>)</td></tr>");
211 } 212 }
212 if (cgit_repo->snapshots) { 213 if (cgit_repo->snapshots) {
213 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); 214 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
214 filename = fmt("%s-%s.zip", cgit_query_repo, hex); 215 filename = fmt("%s-%s.zip", cgit_query_repo, hex);
215 html_attr(cgit_pageurl(cgit_query_repo, "snapshot", 216 html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
216 fmt("id=%s&name=%s", hex, filename))); 217 fmt("id=%s&name=%s", hex, filename)));
217 htmlf("'>%s</a></td></tr>", filename); 218 htmlf("'>%s</a></td></tr>", filename);
218 } 219 }
219 html("</table>\n"); 220 html("</table>\n");
220 html("<div class='commit-subject'>"); 221 html("<div class='commit-subject'>");
221 html_txt(info->subject); 222 html_txt(info->subject);
222 html("</div>"); 223 html("</div>");
223 html("<div class='commit-msg'>"); 224 html("<div class='commit-msg'>");
224 html_txt(info->msg); 225 html_txt(info->msg);
225 html("</div>"); 226 html("</div>");
226 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { 227 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) {
227 html("<table class='diffstat'>"); 228 html("<table class='diffstat'>");
228 max_changes = 0; 229 max_changes = 0;
229 cgit_diff_commit(commit, inspect_filepair); 230 cgit_diff_commit(commit, inspect_filepair);
230 for(i = 0; i<files; i++) 231 for(i = 0; i<files; i++)
231 print_fileinfo(&items[i]); 232 print_fileinfo(&items[i]);
232 html("</table>"); 233 html("</table>");
233 html("<div class='diffstat-summary'>"); 234 html("<div class='diffstat-summary'>");
234 htmlf("%d files changed, %d insertions, %d deletions\n", 235 htmlf("%d files changed, %d insertions, %d deletions\n",
235 files, total_adds, total_rems); 236 files, total_adds, total_rems);
236 html("</div>"); 237 html("</div>");
237 } 238 }
diff --git a/ui-log.c b/ui-log.c
index 7d1985e..6d5509b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -8,106 +8,110 @@
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 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); 22 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
23} 23}
24 24
25void print_commit(struct commit *commit) 25void print_commit(struct commit *commit)
26{ 26{
27 char buf[32]; 27 char buf[32];
28 struct commitinfo *info; 28 struct commitinfo *info;
29 struct tm *time; 29 struct tm *time;
30 30
31 info = cgit_parse_commit(commit); 31 info = cgit_parse_commit(commit);
32 time = gmtime(&commit->date); 32 time = gmtime(&commit->date);
33 html("<tr><td>"); 33 html("<tr><td>");
34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); 34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
35 html_txt(buf); 35 html_txt(buf);
36 html("</td><td>"); 36 html("</td><td>");
37 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 37 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
38 char *url = cgit_pageurl(cgit_query_repo, "commit", qry); 38 char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
39 html_link_open(url, NULL, NULL); 39 html_link_open(url, NULL, NULL);
40 html_ntxt(cgit_max_msg_len, info->subject); 40 html_ntxt(cgit_max_msg_len, info->subject);
41 html_link_close(); 41 html_link_close();
42 files = 0; 42 files = 0;
43 lines = 0; 43 lines = 0;
44 cgit_diff_commit(commit, inspect_files); 44 cgit_diff_commit(commit, inspect_files);
45 html("</td><td class='right'>"); 45 html("</td><td class='right'>");
46 htmlf("%d", files); 46 htmlf("%d", files);
47 html("</td><td class='right'>"); 47 html("</td><td class='right'>");
48 htmlf("%d", lines); 48 htmlf("%d", lines);
49 html("</td><td>"); 49 html("</td><td>");
50 html_txt(info->author); 50 html_txt(info->author);
51 html("</td></tr>\n"); 51 html("</td></tr>\n");
52 cgit_free_commitinfo(info); 52 cgit_free_commitinfo(info);
53} 53}
54 54
55 55
56void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) 56void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path)
57{ 57{
58 struct rev_info rev; 58 struct rev_info rev;
59 struct commit *commit; 59 struct commit *commit;
60 const char *argv[3] = {NULL, tip, NULL}; 60 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
61 int argc = 2; 61 int argc = 2;
62 int i; 62 int i;
63 63
64 if (grep) 64 if (grep)
65 argv[argc++] = fmt("--grep=%s", grep); 65 argv[argc++] = fmt("--grep=%s", grep);
66 if (path) {
67 argv[argc++] = "--";
68 argv[argc++] = path;
69 }
66 init_revisions(&rev, NULL); 70 init_revisions(&rev, NULL);
67 rev.abbrev = DEFAULT_ABBREV; 71 rev.abbrev = DEFAULT_ABBREV;
68 rev.commit_format = CMIT_FMT_DEFAULT; 72 rev.commit_format = CMIT_FMT_DEFAULT;
69 rev.verbose_header = 1; 73 rev.verbose_header = 1;
70 rev.show_root_diff = 0; 74 rev.show_root_diff = 0;
71 setup_revisions(argc, argv, &rev, NULL); 75 setup_revisions(argc, argv, &rev, NULL);
72 if (rev.grep_filter) { 76 if (rev.grep_filter) {
73 rev.grep_filter->regflags |= REG_ICASE; 77 rev.grep_filter->regflags |= REG_ICASE;
74 compile_grep_patterns(rev.grep_filter); 78 compile_grep_patterns(rev.grep_filter);
75 } 79 }
76 prepare_revision_walk(&rev); 80 prepare_revision_walk(&rev);
77 81
78 html("<table class='list nowrap'>"); 82 html("<table class='list nowrap'>");
79 html("<tr class='nohover'><th class='left'>Date</th>" 83 html("<tr class='nohover'><th class='left'>Date</th>"
80 "<th class='left'>Message</th>" 84 "<th class='left'>Message</th>"
81 "<th class='left'>Files</th>" 85 "<th class='left'>Files</th>"
82 "<th class='left'>Lines</th>" 86 "<th class='left'>Lines</th>"
83 "<th class='left'>Author</th></tr>\n"); 87 "<th class='left'>Author</th></tr>\n");
84 88
85 if (ofs<0) 89 if (ofs<0)
86 ofs = 0; 90 ofs = 0;
87 91
88 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 92 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
89 free(commit->buffer); 93 free(commit->buffer);
90 commit->buffer = NULL; 94 commit->buffer = NULL;
91 free_commit_list(commit->parents); 95 free_commit_list(commit->parents);
92 commit->parents = NULL; 96 commit->parents = NULL;
93 } 97 }
94 98
95 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 99 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
96 print_commit(commit); 100 print_commit(commit);
97 free(commit->buffer); 101 free(commit->buffer);
98 commit->buffer = NULL; 102 commit->buffer = NULL;
99 free_commit_list(commit->parents); 103 free_commit_list(commit->parents);
100 commit->parents = NULL; 104 commit->parents = NULL;
101 } 105 }
102 html("</table>\n"); 106 html("</table>\n");
103 107
104 html("<div class='pager'>"); 108 html("<div class='pager'>");
105 if (ofs > 0) { 109 if (ofs > 0) {
106 html("&nbsp;<a href='"); 110 html("&nbsp;<a href='");
107 html(cgit_pageurl(cgit_query_repo, cgit_query_page, 111 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
108 fmt("h=%s&ofs=%d", tip, ofs-cnt))); 112 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
109 html("'>[prev]</a>&nbsp;"); 113 html("'>[prev]</a>&nbsp;");
110 } 114 }
111 115
112 if ((commit = get_revision(&rev)) != NULL) { 116 if ((commit = get_revision(&rev)) != NULL) {
113 html("&nbsp;<a href='"); 117 html("&nbsp;<a href='");
diff --git a/ui-tree.c b/ui-tree.c
index dee8309..db63e13 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,81 +1,94 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree 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
11char *curr_rev;
11 12
12static int print_entry(const unsigned char *sha1, const char *base, 13static int print_entry(const unsigned char *sha1, const char *base,
13 int baselen, const char *pathname, unsigned int mode, 14 int baselen, const char *pathname, unsigned int mode,
14 int stage) 15 int stage)
15{ 16{
16 char *name; 17 char *name;
17 enum object_type type; 18 enum object_type type;
18 unsigned long size = 0; 19 unsigned long size = 0;
19 20
20 name = xstrdup(pathname); 21 name = xstrdup(pathname);
21 type = sha1_object_info(sha1, &size); 22 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 23 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 24 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
24 name, 25 name,
25 sha1_to_hex(sha1)); 26 sha1_to_hex(sha1));
26 return 0; 27 return 0;
27 } 28 }
28 html("<tr><td class='filemode'>"); 29 html("<tr><td class='filemode'>");
29 html_filemode(mode); 30 html_filemode(mode);
30 html("</td><td "); 31 html("</td><td ");
31 if (S_ISDIRLNK(mode)) { 32 if (S_ISDIRLNK(mode)) {
32 htmlf("class='ls-mod'><a href='"); 33 htmlf("class='ls-mod'><a href='");
33 html_attr(fmt(cgit_repo->module_link, 34 html_attr(fmt(cgit_repo->module_link,
34 name, 35 name,
35 sha1_to_hex(sha1))); 36 sha1_to_hex(sha1)));
36 } else if (S_ISDIR(mode)) { 37 } else if (S_ISDIR(mode)) {
37 html("class='ls-dir'><a href='"); 38 html("class='ls-dir'><a href='");
38 html_attr(cgit_pageurl(cgit_query_repo, "tree", 39 html_attr(cgit_pageurl(cgit_query_repo, "tree",
39 fmt("id=%s&path=%s%s/", 40 fmt("h=%s&id=%s&path=%s%s/",
41 curr_rev,
40 sha1_to_hex(sha1), 42 sha1_to_hex(sha1),
41 cgit_query_path ? cgit_query_path : "", 43 cgit_query_path ? cgit_query_path : "",
42 pathname))); 44 pathname)));
43 } else { 45 } else {
44 html("class='ls-blob'><a href='"); 46 html("class='ls-blob'><a href='");
45 html_attr(cgit_pageurl(cgit_query_repo, "view", 47 html_attr(cgit_pageurl(cgit_query_repo, "view",
46 fmt("id=%s&path=%s%s", sha1_to_hex(sha1), 48 fmt("h=%s&id=%s&path=%s%s", curr_rev,
49 sha1_to_hex(sha1),
47 cgit_query_path ? cgit_query_path : "", 50 cgit_query_path ? cgit_query_path : "",
48 pathname))); 51 pathname)));
49 } 52 }
50 htmlf("'>%s</a></div></td>", name); 53 htmlf("'>%s</a></div></td>", name);
51 htmlf("<td class='filesize'>%li</td>", size); 54 htmlf("<td class='filesize'>%li</td>", size);
55
56 html("<td class='links'><a href='");
57 html_attr(cgit_pageurl(cgit_query_repo, "log",
58 fmt("h=%s&path=%s%s",
59 curr_rev,
60 cgit_query_path ? cgit_query_path : "",
61 pathname)));
62 html("'>history</a></td>");
52 html("</tr>\n"); 63 html("</tr>\n");
53 free(name); 64 free(name);
54 return 0; 65 return 0;
55} 66}
56 67
57void cgit_print_tree(const char *hex, char *path) 68void cgit_print_tree(const char *rev, const char *hex, char *path)
58{ 69{
59 struct tree *tree; 70 struct tree *tree;
60 unsigned char sha1[20]; 71 unsigned char sha1[20];
61 72
73 curr_rev = xstrdup(rev);
62 if (get_sha1_hex(hex, sha1)) { 74 if (get_sha1_hex(hex, sha1)) {
63 cgit_print_error(fmt("Invalid object id: %s", hex)); 75 cgit_print_error(fmt("Invalid object id: %s", hex));
64 return; 76 return;
65 } 77 }
66 tree = parse_tree_indirect(sha1); 78 tree = parse_tree_indirect(sha1);
67 if (!tree) { 79 if (!tree) {
68 cgit_print_error(fmt("Not a tree object: %s", hex)); 80 cgit_print_error(fmt("Not a tree object: %s", hex));
69 return; 81 return;
70 } 82 }
71 83
72 html_txt(path); 84 html_txt(path);
73 html("<table class='list'>\n"); 85 html("<table class='list'>\n");
74 html("<tr class='nohover'>"); 86 html("<tr class='nohover'>");
75 html("<th class='left'>Mode</th>"); 87 html("<th class='left'>Mode</th>");
76 html("<th class='left'>Name</th>"); 88 html("<th class='left'>Name</th>");
77 html("<th class='right'>Size</th>"); 89 html("<th class='right'>Size</th>");
90 html("<th/>");
78 html("</tr>\n"); 91 html("</tr>\n");
79 read_tree_recursive(tree, "", 0, 1, NULL, print_entry); 92 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
80 html("</table>\n"); 93 html("</table>\n");
81} 94}