summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.h11
-rw-r--r--ui-commit.c3
-rw-r--r--ui-shared.c6
-rw-r--r--ui-snapshot.c38
5 files changed, 41 insertions, 21 deletions
diff --git a/cgit.c b/cgit.c
index 6597529..c86d290 100644
--- a/cgit.c
+++ b/cgit.c
@@ -7,131 +7,131 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11static int cgit_prepare_cache(struct cacheitem *item) 11static int cgit_prepare_cache(struct cacheitem *item)
12{ 12{
13 if (!cgit_repo && cgit_query_repo) { 13 if (!cgit_repo && cgit_query_repo) {
14 char *title = fmt("%s - %s", cgit_root_title, "Bad request"); 14 char *title = fmt("%s - %s", cgit_root_title, "Bad request");
15 cgit_print_docstart(title, item); 15 cgit_print_docstart(title, item);
16 cgit_print_pageheader(title, 0); 16 cgit_print_pageheader(title, 0);
17 cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); 17 cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo));
18 cgit_print_docend(); 18 cgit_print_docend();
19 return 0; 19 return 0;
20 } 20 }
21 21
22 if (!cgit_repo) { 22 if (!cgit_repo) {
23 item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); 23 item->name = xstrdup(fmt("%s/index.html", cgit_cache_root));
24 item->ttl = cgit_cache_root_ttl; 24 item->ttl = cgit_cache_root_ttl;
25 return 1; 25 return 1;
26 } 26 }
27 27
28 if (!cgit_cmd) { 28 if (!cgit_cmd) {
29 item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, 29 item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root,
30 cache_safe_filename(cgit_repo->url), 30 cache_safe_filename(cgit_repo->url),
31 cache_safe_filename(cgit_querystring))); 31 cache_safe_filename(cgit_querystring)));
32 item->ttl = cgit_cache_repo_ttl; 32 item->ttl = cgit_cache_repo_ttl;
33 } else { 33 } else {
34 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, 34 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
35 cache_safe_filename(cgit_repo->url), 35 cache_safe_filename(cgit_repo->url),
36 cgit_query_page, 36 cgit_query_page,
37 cache_safe_filename(cgit_querystring))); 37 cache_safe_filename(cgit_querystring)));
38 if (cgit_query_has_symref) 38 if (cgit_query_has_symref)
39 item->ttl = cgit_cache_dynamic_ttl; 39 item->ttl = cgit_cache_dynamic_ttl;
40 else if (cgit_query_has_sha1) 40 else if (cgit_query_has_sha1)
41 item->ttl = cgit_cache_static_ttl; 41 item->ttl = cgit_cache_static_ttl;
42 else 42 else
43 item->ttl = cgit_cache_repo_ttl; 43 item->ttl = cgit_cache_repo_ttl;
44 } 44 }
45 return 1; 45 return 1;
46} 46}
47 47
48static void cgit_print_repo_page(struct cacheitem *item) 48static void cgit_print_repo_page(struct cacheitem *item)
49{ 49{
50 char *title; 50 char *title;
51 int show_search; 51 int show_search;
52 52
53 if (!cgit_query_head) 53 if (!cgit_query_head)
54 cgit_query_head = cgit_repo->defbranch; 54 cgit_query_head = cgit_repo->defbranch;
55 55
56 if (chdir(cgit_repo->path)) { 56 if (chdir(cgit_repo->path)) {
57 title = fmt("%s - %s", cgit_root_title, "Bad request"); 57 title = fmt("%s - %s", cgit_root_title, "Bad request");
58 cgit_print_docstart(title, item); 58 cgit_print_docstart(title, item);
59 cgit_print_pageheader(title, 0); 59 cgit_print_pageheader(title, 0);
60 cgit_print_error(fmt("Unable to scan repository: %s", 60 cgit_print_error(fmt("Unable to scan repository: %s",
61 strerror(errno))); 61 strerror(errno)));
62 cgit_print_docend(); 62 cgit_print_docend();
63 return; 63 return;
64 } 64 }
65 65
66 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 66 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
67 show_search = 0; 67 show_search = 0;
68 setenv("GIT_DIR", cgit_repo->path, 1); 68 setenv("GIT_DIR", cgit_repo->path, 1);
69 69
70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { 70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
71 cgit_print_snapshot(item, cgit_query_sha1, 71 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1,
72 cgit_repobasename(cgit_repo->url), 72 cgit_repobasename(cgit_repo->url),
73 cgit_query_name, 73 cgit_query_path,
74 cgit_repo->snapshots ); 74 cgit_repo->snapshots );
75 return; 75 return;
76 } 76 }
77 77
78 if (cgit_cmd == CMD_BLOB) { 78 if (cgit_cmd == CMD_BLOB) {
79 cgit_print_blob(item, cgit_query_sha1, cgit_query_path); 79 cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
80 return; 80 return;
81 } 81 }
82 82
83 show_search = (cgit_cmd == CMD_LOG); 83 show_search = (cgit_cmd == CMD_LOG);
84 cgit_print_docstart(title, item); 84 cgit_print_docstart(title, item);
85 if (!cgit_cmd) { 85 if (!cgit_cmd) {
86 cgit_print_pageheader("summary", show_search); 86 cgit_print_pageheader("summary", show_search);
87 cgit_print_summary(); 87 cgit_print_summary();
88 cgit_print_docend(); 88 cgit_print_docend();
89 return; 89 return;
90 } 90 }
91 91
92 cgit_print_pageheader(cgit_query_page, show_search); 92 cgit_print_pageheader(cgit_query_page, show_search);
93 93
94 switch(cgit_cmd) { 94 switch(cgit_cmd) {
95 case CMD_LOG: 95 case CMD_LOG:
96 cgit_print_log(cgit_query_sha1, cgit_query_ofs, 96 cgit_print_log(cgit_query_sha1, cgit_query_ofs,
97 cgit_max_commit_count, cgit_query_search, 97 cgit_max_commit_count, cgit_query_search,
98 cgit_query_path, 1); 98 cgit_query_path, 1);
99 break; 99 break;
100 case CMD_TREE: 100 case CMD_TREE:
101 cgit_print_tree(cgit_query_sha1, cgit_query_path); 101 cgit_print_tree(cgit_query_sha1, cgit_query_path);
102 break; 102 break;
103 case CMD_COMMIT: 103 case CMD_COMMIT:
104 cgit_print_commit(cgit_query_sha1); 104 cgit_print_commit(cgit_query_sha1);
105 break; 105 break;
106 case CMD_TAG: 106 case CMD_TAG:
107 cgit_print_tag(cgit_query_sha1); 107 cgit_print_tag(cgit_query_sha1);
108 break; 108 break;
109 case CMD_DIFF: 109 case CMD_DIFF:
110 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 110 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
111 break; 111 break;
112 default: 112 default:
113 cgit_print_error("Invalid request"); 113 cgit_print_error("Invalid request");
114 } 114 }
115 cgit_print_docend(); 115 cgit_print_docend();
116} 116}
117 117
118static void cgit_fill_cache(struct cacheitem *item, int use_cache) 118static void cgit_fill_cache(struct cacheitem *item, int use_cache)
119{ 119{
120 static char buf[PATH_MAX]; 120 static char buf[PATH_MAX];
121 int stdout2; 121 int stdout2;
122 122
123 getcwd(buf, sizeof(buf)); 123 getcwd(buf, sizeof(buf));
124 item->st.st_mtime = time(NULL); 124 item->st.st_mtime = time(NULL);
125 125
126 if (use_cache) { 126 if (use_cache) {
127 stdout2 = chk_positive(dup(STDOUT_FILENO), 127 stdout2 = chk_positive(dup(STDOUT_FILENO),
128 "Preserving STDOUT"); 128 "Preserving STDOUT");
129 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 129 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
130 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 130 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
131 } 131 }
132 132
133 if (cgit_repo) 133 if (cgit_repo)
134 cgit_print_repo_page(item); 134 cgit_print_repo_page(item);
135 else 135 else
136 cgit_print_repolist(item); 136 cgit_print_repolist(item);
137 137
diff --git a/cgit.h b/cgit.h
index eddcaa3..e3d9cb8 100644
--- a/cgit.h
+++ b/cgit.h
@@ -153,94 +153,97 @@ extern int cgit_get_cmd_index(const char *cmd);
153extern struct repoinfo *cgit_get_repoinfo(const char *url); 153extern struct repoinfo *cgit_get_repoinfo(const char *url);
154extern void cgit_global_config_cb(const char *name, const char *value); 154extern void cgit_global_config_cb(const char *name, const char *value);
155extern void cgit_repo_config_cb(const char *name, const char *value); 155extern void cgit_repo_config_cb(const char *name, const char *value);
156extern void cgit_querystring_cb(const char *name, const char *value); 156extern void cgit_querystring_cb(const char *name, const char *value);
157 157
158extern int chk_zero(int result, char *msg); 158extern int chk_zero(int result, char *msg);
159extern int chk_positive(int result, char *msg); 159extern int chk_positive(int result, char *msg);
160extern int chk_non_negative(int result, char *msg); 160extern int chk_non_negative(int result, char *msg);
161 161
162extern int hextoint(char c); 162extern int hextoint(char c);
163extern char *trim_end(const char *str, char c); 163extern char *trim_end(const char *str, char c);
164 164
165extern void *cgit_free_commitinfo(struct commitinfo *info); 165extern void *cgit_free_commitinfo(struct commitinfo *info);
166 166
167extern int cgit_diff_files(const unsigned char *old_sha1, 167extern int cgit_diff_files(const unsigned char *old_sha1,
168 const unsigned char *new_sha1, 168 const unsigned char *new_sha1,
169 linediff_fn fn); 169 linediff_fn fn);
170 170
171extern void cgit_diff_tree(const unsigned char *old_sha1, 171extern void cgit_diff_tree(const unsigned char *old_sha1,
172 const unsigned char *new_sha1, 172 const unsigned char *new_sha1,
173 filepair_fn fn); 173 filepair_fn fn);
174 174
175extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 175extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
176 176
177extern char *fmt(const char *format,...); 177extern char *fmt(const char *format,...);
178 178
179extern void html(const char *txt); 179extern void html(const char *txt);
180extern void htmlf(const char *format,...); 180extern void htmlf(const char *format,...);
181extern void html_txt(char *txt); 181extern void html_txt(char *txt);
182extern void html_ntxt(int len, char *txt); 182extern void html_ntxt(int len, char *txt);
183extern void html_attr(char *txt); 183extern void html_attr(char *txt);
184extern void html_hidden(char *name, char *value); 184extern void html_hidden(char *name, char *value);
185extern void html_link_open(char *url, char *title, char *class); 185extern void html_link_open(char *url, char *title, char *class);
186extern void html_link_close(void); 186extern void html_link_close(void);
187extern void html_filemode(unsigned short mode); 187extern void html_filemode(unsigned short mode);
188extern int html_include(const char *filename); 188extern int html_include(const char *filename);
189 189
190extern int cgit_read_config(const char *filename, configfn fn); 190extern int cgit_read_config(const char *filename, configfn fn);
191extern int cgit_parse_query(char *txt, configfn fn); 191extern int cgit_parse_query(char *txt, configfn fn);
192extern struct commitinfo *cgit_parse_commit(struct commit *commit); 192extern struct commitinfo *cgit_parse_commit(struct commit *commit);
193extern struct taginfo *cgit_parse_tag(struct tag *tag); 193extern struct taginfo *cgit_parse_tag(struct tag *tag);
194extern void cgit_parse_url(const char *url); 194extern void cgit_parse_url(const char *url);
195 195
196extern char *cache_safe_filename(const char *unsafe); 196extern char *cache_safe_filename(const char *unsafe);
197extern int cache_lock(struct cacheitem *item); 197extern int cache_lock(struct cacheitem *item);
198extern int cache_unlock(struct cacheitem *item); 198extern int cache_unlock(struct cacheitem *item);
199extern int cache_cancel_lock(struct cacheitem *item); 199extern int cache_cancel_lock(struct cacheitem *item);
200extern int cache_exist(struct cacheitem *item); 200extern int cache_exist(struct cacheitem *item);
201extern int cache_expired(struct cacheitem *item); 201extern int cache_expired(struct cacheitem *item);
202 202
203extern char *cgit_repourl(const char *reponame); 203extern char *cgit_repourl(const char *reponame);
204extern char *cgit_fileurl(const char *reponame, const char *pagename, 204extern char *cgit_fileurl(const char *reponame, const char *pagename,
205 const char *filename, const char *query); 205 const char *filename, const char *query);
206extern char *cgit_pageurl(const char *reponame, const char *pagename, 206extern char *cgit_pageurl(const char *reponame, const char *pagename,
207 const char *query); 207 const char *query);
208 208
209extern const char *cgit_repobasename(const char *reponame); 209extern const char *cgit_repobasename(const char *reponame);
210 210
211extern void cgit_tree_link(char *name, char *title, char *class, char *head, 211extern void cgit_tree_link(char *name, char *title, char *class, char *head,
212 char *rev, char *path); 212 char *rev, char *path);
213extern void cgit_log_link(char *name, char *title, char *class, char *head, 213extern void cgit_log_link(char *name, char *title, char *class, char *head,
214 char *rev, char *path, int ofs); 214 char *rev, char *path, int ofs);
215extern void cgit_commit_link(char *name, char *title, char *class, char *head, 215extern void cgit_commit_link(char *name, char *title, char *class, char *head,
216 char *rev); 216 char *rev);
217extern void cgit_snapshot_link(char *name, char *title, char *class,
218 char *head, char *rev, char *archivename);
217extern void cgit_diff_link(char *name, char *title, char *class, char *head, 219extern void cgit_diff_link(char *name, char *title, char *class, char *head,
218 char *new_rev, char *old_rev, char *path); 220 char *new_rev, char *old_rev, char *path);
219 221
220extern void cgit_object_link(struct object *obj); 222extern void cgit_object_link(struct object *obj);
221 223
222extern void cgit_print_error(char *msg); 224extern void cgit_print_error(char *msg);
223extern void cgit_print_date(time_t secs, char *format); 225extern void cgit_print_date(time_t secs, char *format);
224extern void cgit_print_age(time_t t, time_t max_relative, char *format); 226extern void cgit_print_age(time_t t, time_t max_relative, char *format);
225extern void cgit_print_docstart(char *title, struct cacheitem *item); 227extern void cgit_print_docstart(char *title, struct cacheitem *item);
226extern void cgit_print_docend(); 228extern void cgit_print_docend();
227extern void cgit_print_pageheader(char *title, int show_search); 229extern void cgit_print_pageheader(char *title, int show_search);
228extern void cgit_print_snapshot_start(const char *mimetype, 230extern void cgit_print_snapshot_start(const char *mimetype,
229 const char *filename, 231 const char *filename,
230 struct cacheitem *item); 232 struct cacheitem *item);
231 233
232extern void cgit_print_repolist(struct cacheitem *item); 234extern void cgit_print_repolist(struct cacheitem *item);
233extern void cgit_print_summary(); 235extern void cgit_print_summary();
234extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 236extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
235extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 237extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
236extern void cgit_print_tree(const char *rev, char *path); 238extern void cgit_print_tree(const char *rev, char *path);
237extern void cgit_print_commit(char *hex); 239extern void cgit_print_commit(char *hex);
238extern void cgit_print_tag(char *revname); 240extern void cgit_print_tag(char *revname);
239extern void cgit_print_diff(const char *new_hex, const char *old_hex); 241extern void cgit_print_diff(const char *new_hex, const char *old_hex);
240extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 242extern void cgit_print_snapshot(struct cacheitem *item, const char *head,
241 const char *prefix, const char *filename, 243 const char *hex, const char *prefix,
242 int snapshot); 244 const char *filename, int snapshot);
243extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots); 245extern void cgit_print_snapshot_links(const char *repo, const char *head,
246 const char *hex, int snapshots);
244extern int cgit_parse_snapshots_mask(const char *str); 247extern int cgit_parse_snapshots_mask(const char *str);
245 248
246#endif /* CGIT_H */ 249#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index 50e9e11..90e09ed 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -135,91 +135,92 @@ void inspect_filepair(struct diff_filepair *pair)
135 135
136void cgit_print_commit(char *hex) 136void cgit_print_commit(char *hex)
137{ 137{
138 struct commit *commit, *parent; 138 struct commit *commit, *parent;
139 struct commitinfo *info; 139 struct commitinfo *info;
140 struct commit_list *p; 140 struct commit_list *p;
141 unsigned char sha1[20]; 141 unsigned char sha1[20];
142 char *tmp; 142 char *tmp;
143 int i; 143 int i;
144 144
145 if (!hex) 145 if (!hex)
146 hex = cgit_query_head; 146 hex = cgit_query_head;
147 curr_rev = hex; 147 curr_rev = hex;
148 148
149 if (get_sha1(hex, sha1)) { 149 if (get_sha1(hex, sha1)) {
150 cgit_print_error(fmt("Bad object id: %s", hex)); 150 cgit_print_error(fmt("Bad object id: %s", hex));
151 return; 151 return;
152 } 152 }
153 commit = lookup_commit_reference(sha1); 153 commit = lookup_commit_reference(sha1);
154 if (!commit) { 154 if (!commit) {
155 cgit_print_error(fmt("Bad commit reference: %s", hex)); 155 cgit_print_error(fmt("Bad commit reference: %s", hex));
156 return; 156 return;
157 } 157 }
158 info = cgit_parse_commit(commit); 158 info = cgit_parse_commit(commit);
159 159
160 html("<table class='commit-info'>\n"); 160 html("<table class='commit-info'>\n");
161 html("<tr><th>author</th><td>"); 161 html("<tr><th>author</th><td>");
162 html_txt(info->author); 162 html_txt(info->author);
163 html(" "); 163 html(" ");
164 html_txt(info->author_email); 164 html_txt(info->author_email);
165 html("</td><td class='right'>"); 165 html("</td><td class='right'>");
166 cgit_print_date(info->author_date, FMT_LONGDATE); 166 cgit_print_date(info->author_date, FMT_LONGDATE);
167 html("</td></tr>\n"); 167 html("</td></tr>\n");
168 html("<tr><th>committer</th><td>"); 168 html("<tr><th>committer</th><td>");
169 html_txt(info->committer); 169 html_txt(info->committer);
170 html(" "); 170 html(" ");
171 html_txt(info->committer_email); 171 html_txt(info->committer_email);
172 html("</td><td class='right'>"); 172 html("</td><td class='right'>");
173 cgit_print_date(info->committer_date, FMT_LONGDATE); 173 cgit_print_date(info->committer_date, FMT_LONGDATE);
174 html("</td></tr>\n"); 174 html("</td></tr>\n");
175 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 175 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
176 tmp = xstrdup(hex); 176 tmp = xstrdup(hex);
177 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 177 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
178 cgit_query_head, tmp, NULL); 178 cgit_query_head, tmp, NULL);
179 html("</td></tr>\n"); 179 html("</td></tr>\n");
180 for (p = commit->parents; p ; p = p->next) { 180 for (p = commit->parents; p ; p = p->next) {
181 parent = lookup_commit_reference(p->item->object.sha1); 181 parent = lookup_commit_reference(p->item->object.sha1);
182 if (!parent) { 182 if (!parent) {
183 html("<tr><td colspan='3'>"); 183 html("<tr><td colspan='3'>");
184 cgit_print_error("Error reading parent commit"); 184 cgit_print_error("Error reading parent commit");
185 html("</td></tr>"); 185 html("</td></tr>");
186 continue; 186 continue;
187 } 187 }
188 html("<tr><th>parent</th>" 188 html("<tr><th>parent</th>"
189 "<td colspan='2' class='sha1'>"); 189 "<td colspan='2' class='sha1'>");
190 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, 190 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
191 cgit_query_head, sha1_to_hex(p->item->object.sha1)); 191 cgit_query_head, sha1_to_hex(p->item->object.sha1));
192 html(" ("); 192 html(" (");
193 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, 193 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex,
194 sha1_to_hex(p->item->object.sha1), NULL); 194 sha1_to_hex(p->item->object.sha1), NULL);
195 html(")</td></tr>"); 195 html(")</td></tr>");
196 } 196 }
197 if (cgit_repo->snapshots) { 197 if (cgit_repo->snapshots) {
198 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 198 html("<tr><th>download</th><td colspan='2' class='sha1'>");
199 cgit_print_snapshot_links(cgit_query_repo,hex,cgit_repo->snapshots); 199 cgit_print_snapshot_links(cgit_query_repo, cgit_query_head,
200 hex, cgit_repo->snapshots);
200 html("</td></tr>"); 201 html("</td></tr>");
201 } 202 }
202 html("</table>\n"); 203 html("</table>\n");
203 html("<div class='commit-subject'>"); 204 html("<div class='commit-subject'>");
204 html_txt(info->subject); 205 html_txt(info->subject);
205 html("</div>"); 206 html("</div>");
206 html("<div class='commit-msg'>"); 207 html("<div class='commit-msg'>");
207 html_txt(info->msg); 208 html_txt(info->msg);
208 html("</div>"); 209 html("</div>");
209 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { 210 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) {
210 html("<div class='diffstat-header'>Diffstat</div>"); 211 html("<div class='diffstat-header'>Diffstat</div>");
211 html("<table class='diffstat'>"); 212 html("<table class='diffstat'>");
212 max_changes = 0; 213 max_changes = 0;
213 cgit_diff_commit(commit, inspect_filepair); 214 cgit_diff_commit(commit, inspect_filepair);
214 for(i = 0; i<files; i++) 215 for(i = 0; i<files; i++)
215 print_fileinfo(&items[i]); 216 print_fileinfo(&items[i]);
216 html("</table>"); 217 html("</table>");
217 html("<div class='diffstat-summary'>"); 218 html("<div class='diffstat-summary'>");
218 htmlf("%d files changed, %d insertions, %d deletions (", 219 htmlf("%d files changed, %d insertions, %d deletions (",
219 files, total_adds, total_rems); 220 files, total_adds, total_rems);
220 cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, 221 cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex,
221 NULL, NULL); 222 NULL, NULL);
222 html(")</div>"); 223 html(")</div>");
223 } 224 }
224 cgit_free_commitinfo(info); 225 cgit_free_commitinfo(info);
225} 226}
diff --git a/ui-shared.c b/ui-shared.c
index ca2ee82..5c5bcf3 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -166,128 +166,134 @@ static char *repolink(char *title, char *class, char *page, char *head,
166 html(delim); 166 html(delim);
167 html("h="); 167 html("h=");
168 html_attr(head); 168 html_attr(head);
169 delim = "&amp;"; 169 delim = "&amp;";
170 } 170 }
171 return fmt("%s", delim); 171 return fmt("%s", delim);
172} 172}
173 173
174static void reporevlink(char *page, char *name, char *title, char *class, 174static void reporevlink(char *page, char *name, char *title, char *class,
175 char *head, char *rev, char *path) 175 char *head, char *rev, char *path)
176{ 176{
177 char *delim; 177 char *delim;
178 178
179 delim = repolink(title, class, page, head, path); 179 delim = repolink(title, class, page, head, path);
180 if (rev && strcmp(rev, cgit_query_head)) { 180 if (rev && strcmp(rev, cgit_query_head)) {
181 html(delim); 181 html(delim);
182 html("id="); 182 html("id=");
183 html_attr(rev); 183 html_attr(rev);
184 } 184 }
185 html("'>"); 185 html("'>");
186 html_txt(name); 186 html_txt(name);
187 html("</a>"); 187 html("</a>");
188} 188}
189 189
190void cgit_tree_link(char *name, char *title, char *class, char *head, 190void cgit_tree_link(char *name, char *title, char *class, char *head,
191 char *rev, char *path) 191 char *rev, char *path)
192{ 192{
193 reporevlink("tree", name, title, class, head, rev, path); 193 reporevlink("tree", name, title, class, head, rev, path);
194} 194}
195 195
196void cgit_log_link(char *name, char *title, char *class, char *head, 196void cgit_log_link(char *name, char *title, char *class, char *head,
197 char *rev, char *path, int ofs) 197 char *rev, char *path, int ofs)
198{ 198{
199 char *delim; 199 char *delim;
200 200
201 delim = repolink(title, class, "log", head, path); 201 delim = repolink(title, class, "log", head, path);
202 if (rev && strcmp(rev, cgit_query_head)) { 202 if (rev && strcmp(rev, cgit_query_head)) {
203 html(delim); 203 html(delim);
204 html("id="); 204 html("id=");
205 html_attr(rev); 205 html_attr(rev);
206 delim = "&"; 206 delim = "&";
207 } 207 }
208 if (ofs > 0) { 208 if (ofs > 0) {
209 html(delim); 209 html(delim);
210 html("ofs="); 210 html("ofs=");
211 htmlf("%d", ofs); 211 htmlf("%d", ofs);
212 } 212 }
213 html("'>"); 213 html("'>");
214 html_txt(name); 214 html_txt(name);
215 html("</a>"); 215 html("</a>");
216} 216}
217 217
218void cgit_commit_link(char *name, char *title, char *class, char *head, 218void cgit_commit_link(char *name, char *title, char *class, char *head,
219 char *rev) 219 char *rev)
220{ 220{
221 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { 221 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) {
222 name[cgit_max_msg_len] = '\0'; 222 name[cgit_max_msg_len] = '\0';
223 name[cgit_max_msg_len - 1] = '.'; 223 name[cgit_max_msg_len - 1] = '.';
224 name[cgit_max_msg_len - 2] = '.'; 224 name[cgit_max_msg_len - 2] = '.';
225 name[cgit_max_msg_len - 3] = '.'; 225 name[cgit_max_msg_len - 3] = '.';
226 } 226 }
227 reporevlink("commit", name, title, class, head, rev, NULL); 227 reporevlink("commit", name, title, class, head, rev, NULL);
228} 228}
229 229
230void cgit_snapshot_link(char *name, char *title, char *class, char *head,
231 char *rev, char *archivename)
232{
233 reporevlink("snapshot", name, title, class, head, rev, archivename);
234}
235
230void cgit_diff_link(char *name, char *title, char *class, char *head, 236void cgit_diff_link(char *name, char *title, char *class, char *head,
231 char *new_rev, char *old_rev, char *path) 237 char *new_rev, char *old_rev, char *path)
232{ 238{
233 char *delim; 239 char *delim;
234 240
235 delim = repolink(title, class, "diff", head, path); 241 delim = repolink(title, class, "diff", head, path);
236 if (new_rev && strcmp(new_rev, cgit_query_head)) { 242 if (new_rev && strcmp(new_rev, cgit_query_head)) {
237 html(delim); 243 html(delim);
238 html("id="); 244 html("id=");
239 html_attr(new_rev); 245 html_attr(new_rev);
240 delim = "&amp;"; 246 delim = "&amp;";
241 } 247 }
242 if (old_rev) { 248 if (old_rev) {
243 html(delim); 249 html(delim);
244 html("id2="); 250 html("id2=");
245 html_attr(old_rev); 251 html_attr(old_rev);
246 } 252 }
247 html("'>"); 253 html("'>");
248 html_txt(name); 254 html_txt(name);
249 html("</a>"); 255 html("</a>");
250} 256}
251 257
252void cgit_object_link(struct object *obj) 258void cgit_object_link(struct object *obj)
253{ 259{
254 char *page, *arg, *url; 260 char *page, *arg, *url;
255 261
256 if (obj->type == OBJ_COMMIT) { 262 if (obj->type == OBJ_COMMIT) {
257 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 263 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
258 cgit_query_head, sha1_to_hex(obj->sha1)); 264 cgit_query_head, sha1_to_hex(obj->sha1));
259 return; 265 return;
260 } else if (obj->type == OBJ_TREE) { 266 } else if (obj->type == OBJ_TREE) {
261 page = "tree"; 267 page = "tree";
262 arg = "id"; 268 arg = "id";
263 } else { 269 } else {
264 page = "blob"; 270 page = "blob";
265 arg = "id"; 271 arg = "id";
266 } 272 }
267 273
268 url = cgit_pageurl(cgit_query_repo, page, 274 url = cgit_pageurl(cgit_query_repo, page,
269 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 275 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
270 html_link_open(url, NULL, NULL); 276 html_link_open(url, NULL, NULL);
271 htmlf("%s %s", typename(obj->type), 277 htmlf("%s %s", typename(obj->type),
272 sha1_to_hex(obj->sha1)); 278 sha1_to_hex(obj->sha1));
273 html_link_close(); 279 html_link_close();
274} 280}
275 281
276void cgit_print_date(time_t secs, char *format) 282void cgit_print_date(time_t secs, char *format)
277{ 283{
278 char buf[64]; 284 char buf[64];
279 struct tm *time; 285 struct tm *time;
280 286
281 time = gmtime(&secs); 287 time = gmtime(&secs);
282 strftime(buf, sizeof(buf)-1, format, time); 288 strftime(buf, sizeof(buf)-1, format, time);
283 html_txt(buf); 289 html_txt(buf);
284} 290}
285 291
286void cgit_print_age(time_t t, time_t max_relative, char *format) 292void cgit_print_age(time_t t, time_t max_relative, char *format)
287{ 293{
288 time_t now, secs; 294 time_t now, secs;
289 295
290 time(&now); 296 time(&now);
291 secs = now - t; 297 secs = now - t;
292 298
293 if (secs > max_relative && max_relative >= 0) { 299 if (secs > max_relative && max_relative >= 0) {
diff --git a/ui-snapshot.c b/ui-snapshot.c
index d6be55b..f9879ed 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -4,142 +4,152 @@
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 write_compressed_tar_archive(struct archiver_args *args,const char *filter) 11static int write_compressed_tar_archive(struct archiver_args *args,const char *filter)
12{ 12{
13 int rw[2]; 13 int rw[2];
14 pid_t gzpid; 14 pid_t gzpid;
15 int stdout2; 15 int stdout2;
16 int status; 16 int status;
17 int rv; 17 int rv;
18 18
19 stdout2 = chk_non_negative(dup(STDIN_FILENO), "Preserving STDOUT before compressing"); 19 stdout2 = chk_non_negative(dup(STDIN_FILENO), "Preserving STDOUT before compressing");
20 chk_zero(pipe(rw), "Opening pipe from compressor subprocess"); 20 chk_zero(pipe(rw), "Opening pipe from compressor subprocess");
21 gzpid = chk_non_negative(fork(), "Forking compressor subprocess"); 21 gzpid = chk_non_negative(fork(), "Forking compressor subprocess");
22 if(gzpid==0) { 22 if(gzpid==0) {
23 /* child */ 23 /* child */
24 chk_zero(close(rw[1]), "Closing write end of pipe in child"); 24 chk_zero(close(rw[1]), "Closing write end of pipe in child");
25 chk_zero(close(STDIN_FILENO), "Closing STDIN"); 25 chk_zero(close(STDIN_FILENO), "Closing STDIN");
26 chk_non_negative(dup2(rw[0],STDIN_FILENO), "Redirecting compressor input to stdin"); 26 chk_non_negative(dup2(rw[0],STDIN_FILENO), "Redirecting compressor input to stdin");
27 execlp(filter,filter,NULL); 27 execlp(filter,filter,NULL);
28 _exit(-1); 28 _exit(-1);
29 } 29 }
30 /* parent */ 30 /* parent */
31 chk_zero(close(rw[0]), "Closing read end of pipe"); 31 chk_zero(close(rw[0]), "Closing read end of pipe");
32 chk_non_negative(dup2(rw[1],STDOUT_FILENO), "Redirecting output to compressor"); 32 chk_non_negative(dup2(rw[1],STDOUT_FILENO), "Redirecting output to compressor");
33 33
34 rv = write_tar_archive(args); 34 rv = write_tar_archive(args);
35 35
36 chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor"); 36 chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor");
37 chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT"); 37 chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT");
38 chk_zero(close(stdout2), "Closing uncompressed STDOUT"); 38 chk_zero(close(stdout2), "Closing uncompressed STDOUT");
39 chk_zero(close(rw[1]), "Closing write end of pipe in parent"); 39 chk_zero(close(rw[1]), "Closing write end of pipe in parent");
40 chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process"); 40 chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process");
41 if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) ) 41 if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) )
42 cgit_print_error("Failed to compress archive"); 42 cgit_print_error("Failed to compress archive");
43 43
44 return rv; 44 return rv;
45} 45}
46 46
47static int write_tar_gzip_archive(struct archiver_args *args) 47static int write_tar_gzip_archive(struct archiver_args *args)
48{ 48{
49 return write_compressed_tar_archive(args,"gzip"); 49 return write_compressed_tar_archive(args,"gzip");
50} 50}
51static int write_tar_bzip2_archive(struct archiver_args *args) 51static int write_tar_bzip2_archive(struct archiver_args *args)
52{ 52{
53 return write_compressed_tar_archive(args,"bzip2"); 53 return write_compressed_tar_archive(args,"bzip2");
54} 54}
55 55
56static const struct snapshot_archive_t { 56static const struct snapshot_archive_t {
57 const char *suffix; 57 const char *suffix;
58 const char *mimetype; 58 const char *mimetype;
59 write_archive_fn_t write_func; 59 write_archive_fn_t write_func;
60 int bit; 60 int bit;
61 }snapshot_archives[] = { 61 }snapshot_archives[] = {
62 { ".zip", "application/x-zip", write_zip_archive, 0x1 }, 62 { ".zip", "application/x-zip", write_zip_archive, 0x1 },
63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, 63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, 64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
65 { ".tar", "application/x-tar", write_tar_archive, 0x8 } 65 { ".tar", "application/x-tar", write_tar_archive, 0x8 }
66}; 66};
67 67
68void cgit_print_snapshot(struct cacheitem *item, const char *hex, 68void cgit_print_snapshot(struct cacheitem *item, const char *head,
69 const char *prefix, const char *filename, 69 const char *hex, const char *prefix,
70 int snapshots) 70 const char *filename, int snapshots)
71{ 71{
72 int fnl = strlen(filename); 72 int fnl = strlen(filename);
73 int f; 73 int f, n;
74 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 74
75 n = sizeof(snapshot_archives) / sizeof(*snapshot_archives);
76 for(f=0; f<n; f++) {
75 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 77 const struct snapshot_archive_t* sat = &snapshot_archives[f];
76 int sl; 78 int sl;
77 if(!(snapshots&sat->bit)) continue; 79 if(!(snapshots & sat->bit))
80 continue;
78 sl = strlen(sat->suffix); 81 sl = strlen(sat->suffix);
79 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) 82 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix))
80 continue; 83 continue;
81 84
82 struct archiver_args args; 85 struct archiver_args args;
83 struct commit *commit; 86 struct commit *commit;
84 unsigned char sha1[20]; 87 unsigned char sha1[20];
85 88
89 if (!hex)
90 hex = head;
86 if(get_sha1(hex, sha1)) { 91 if(get_sha1(hex, sha1)) {
87 cgit_print_error(fmt("Bad object id: %s", hex)); 92 cgit_print_error(fmt("Bad object id: %s", hex));
88 return; 93 return;
89 } 94 }
90 commit = lookup_commit_reference(sha1); 95 commit = lookup_commit_reference(sha1);
91 96
92 if(!commit) { 97 if(!commit) {
93 cgit_print_error(fmt("Not a commit reference: %s", hex)); 98 cgit_print_error(fmt("Not a commit reference: %s", hex));
94 return;; 99 return;;
95 } 100 }
96 101
97 memset(&args,0,sizeof(args)); 102 memset(&args,0,sizeof(args));
98 args.base = fmt("%s/", prefix); 103 args.base = fmt("%s/", prefix);
99 args.tree = commit->tree; 104 args.tree = commit->tree;
100 105
101 cgit_print_snapshot_start(sat->mimetype, filename, item); 106 cgit_print_snapshot_start(sat->mimetype, filename, item);
102 (*sat->write_func)(&args); 107 (*sat->write_func)(&args);
103 return; 108 return;
104 } 109 }
105 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 110 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
106} 111}
107 112
108void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots) 113void cgit_print_snapshot_links(const char *repo, const char *head,
114 const char *hex, int snapshots)
109{ 115{
110 char *filename; 116 char *filename;
111 int f; 117 int f, n;
112 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 118
119 n = sizeof(snapshot_archives) / sizeof(*snapshot_archives);
120 for(f=0; f<n ;f++) {
113 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 121 const struct snapshot_archive_t* sat = &snapshot_archives[f];
114 if(!(snapshots&sat->bit)) continue; 122 if(!(snapshots & sat->bit))
115 filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); 123 continue;
116 htmlf("<a href='%s'>%s</a><br/>", 124 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
117 cgit_fileurl(repo,"snapshot",filename, 125 sat->suffix);
118 fmt("id=%s&amp;name=%s",hex,filename)), filename); 126 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
127 (char *)hex, filename);
128 html("<br/>");
119 } 129 }
120} 130}
121 131
122int cgit_parse_snapshots_mask(const char *str) 132int cgit_parse_snapshots_mask(const char *str)
123{ 133{
124 static const char *delim = " \t,:/|;"; 134 static const char *delim = " \t,:/|;";
125 int f, tl, rv = 0; 135 int f, tl, rv = 0;
126 /* favor legacy setting */ 136 /* favor legacy setting */
127 if(atoi(str)) return 1; 137 if(atoi(str)) return 1;
128 for(;;) { 138 for(;;) {
129 str += strspn(str,delim); 139 str += strspn(str,delim);
130 tl = strcspn(str,delim); 140 tl = strcspn(str,delim);
131 if(!tl) 141 if(!tl)
132 break; 142 break;
133 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 143 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
134 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 144 const struct snapshot_archive_t* sat = &snapshot_archives[f];
135 if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { 145 if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) {
136 rv |= sat->bit; 146 rv |= sat->bit;
137 break; 147 break;
138 } 148 }
139 } 149 }
140 str += tl; 150 str += tl;
141 } 151 }
142 return rv; 152 return rv;
143} 153}
144 154
145/* vim:set sw=8: */ 155/* vim:set sw=8: */