author | Michael Krelin <hacker@klever.net> | 2007-07-18 12:40:03 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-18 12:40:03 (UTC) |
commit | f97c707a3b975d32910331f72783ec3044e3c0ee (patch) (unidiff) | |
tree | 632239a8a644036bd08fbb6f202278de068097b5 | |
parent | 71ebcbe23ab548e5c0ad40aa8be5741654ed3201 (diff) | |
download | cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.zip cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.tar.gz cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.tar.bz2 |
add support for snapshot tarballs
- reworked cgit_print_snapshot to use a list of supported archivers and pick
one for the suffix supplied
- moved printing of snaphot links into ui-snapshot and make it iterate through
the said list
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | ui-commit.c | 9 | ||||
-rw-r--r-- | ui-snapshot.c | 77 |
4 files changed, 55 insertions, 37 deletions
@@ -23,97 +23,97 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
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 | ||
48 | static void cgit_print_repo_page(struct cacheitem *item) | 48 | static 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, "zip", | 71 | cgit_print_snapshot(item, cgit_query_sha1, |
72 | cgit_repo->url, cgit_query_name); | 72 | cgit_repo->url, cgit_query_name); |
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | 75 | ||
76 | if (cgit_cmd == CMD_BLOB) { | 76 | if (cgit_cmd == CMD_BLOB) { |
77 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 77 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
78 | return; | 78 | return; |
79 | } | 79 | } |
80 | 80 | ||
81 | show_search = (cgit_cmd == CMD_LOG); | 81 | show_search = (cgit_cmd == CMD_LOG); |
82 | cgit_print_docstart(title, item); | 82 | cgit_print_docstart(title, item); |
83 | if (!cgit_cmd) { | 83 | if (!cgit_cmd) { |
84 | cgit_print_pageheader("summary", show_search); | 84 | cgit_print_pageheader("summary", show_search); |
85 | cgit_print_summary(); | 85 | cgit_print_summary(); |
86 | cgit_print_docend(); | 86 | cgit_print_docend(); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | 89 | ||
90 | cgit_print_pageheader(cgit_query_page, show_search); | 90 | cgit_print_pageheader(cgit_query_page, show_search); |
91 | 91 | ||
92 | switch(cgit_cmd) { | 92 | switch(cgit_cmd) { |
93 | case CMD_LOG: | 93 | case CMD_LOG: |
94 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 94 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
95 | cgit_max_commit_count, cgit_query_search, | 95 | cgit_max_commit_count, cgit_query_search, |
96 | cgit_query_path, 1); | 96 | cgit_query_path, 1); |
97 | break; | 97 | break; |
98 | case CMD_TREE: | 98 | case CMD_TREE: |
99 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 99 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
100 | break; | 100 | break; |
101 | case CMD_COMMIT: | 101 | case CMD_COMMIT: |
102 | cgit_print_commit(cgit_query_sha1); | 102 | cgit_print_commit(cgit_query_sha1); |
103 | break; | 103 | break; |
104 | case CMD_DIFF: | 104 | case CMD_DIFF: |
105 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 105 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
106 | break; | 106 | break; |
107 | default: | 107 | default: |
108 | cgit_print_error("Invalid request"); | 108 | cgit_print_error("Invalid request"); |
109 | } | 109 | } |
110 | cgit_print_docend(); | 110 | cgit_print_docend(); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 113 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
114 | { | 114 | { |
115 | static char buf[PATH_MAX]; | 115 | static char buf[PATH_MAX]; |
116 | int stdout2; | 116 | int stdout2; |
117 | 117 | ||
118 | getcwd(buf, sizeof(buf)); | 118 | getcwd(buf, sizeof(buf)); |
119 | item->st.st_mtime = time(NULL); | 119 | item->st.st_mtime = time(NULL); |
@@ -185,52 +185,52 @@ extern void html_link_open(char *url, char *title, char *class); | |||
185 | extern void html_link_close(void); | 185 | extern void html_link_close(void); |
186 | extern void html_filemode(unsigned short mode); | 186 | extern void html_filemode(unsigned short mode); |
187 | extern int html_include(const char *filename); | 187 | extern int html_include(const char *filename); |
188 | 188 | ||
189 | extern int cgit_read_config(const char *filename, configfn fn); | 189 | extern int cgit_read_config(const char *filename, configfn fn); |
190 | extern int cgit_parse_query(char *txt, configfn fn); | 190 | extern int cgit_parse_query(char *txt, configfn fn); |
191 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 191 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
192 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 192 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
193 | extern void cgit_parse_url(const char *url); | 193 | extern void cgit_parse_url(const char *url); |
194 | 194 | ||
195 | extern char *cache_safe_filename(const char *unsafe); | 195 | extern char *cache_safe_filename(const char *unsafe); |
196 | extern int cache_lock(struct cacheitem *item); | 196 | extern int cache_lock(struct cacheitem *item); |
197 | extern int cache_unlock(struct cacheitem *item); | 197 | extern int cache_unlock(struct cacheitem *item); |
198 | extern int cache_cancel_lock(struct cacheitem *item); | 198 | extern int cache_cancel_lock(struct cacheitem *item); |
199 | extern int cache_exist(struct cacheitem *item); | 199 | extern int cache_exist(struct cacheitem *item); |
200 | extern int cache_expired(struct cacheitem *item); | 200 | extern int cache_expired(struct cacheitem *item); |
201 | 201 | ||
202 | extern char *cgit_repourl(const char *reponame); | 202 | extern char *cgit_repourl(const char *reponame); |
203 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 203 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
204 | const char *query); | 204 | const char *query); |
205 | 205 | ||
206 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 206 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
207 | char *rev, char *path); | 207 | char *rev, char *path); |
208 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 208 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
209 | char *rev, char *path, int ofs); | 209 | char *rev, char *path, int ofs); |
210 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 210 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
211 | char *rev); | 211 | char *rev); |
212 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 212 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
213 | char *new_rev, char *old_rev, char *path); | 213 | char *new_rev, char *old_rev, char *path); |
214 | 214 | ||
215 | extern void cgit_print_error(char *msg); | 215 | extern void cgit_print_error(char *msg); |
216 | extern void cgit_print_date(time_t secs, char *format); | 216 | extern void cgit_print_date(time_t secs, char *format); |
217 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 217 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
218 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 218 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
219 | extern void cgit_print_docend(); | 219 | extern void cgit_print_docend(); |
220 | extern void cgit_print_pageheader(char *title, int show_search); | 220 | extern void cgit_print_pageheader(char *title, int show_search); |
221 | extern void cgit_print_snapshot_start(const char *mimetype, | 221 | extern void cgit_print_snapshot_start(const char *mimetype, |
222 | const char *filename, | 222 | const char *filename, |
223 | struct cacheitem *item); | 223 | struct cacheitem *item); |
224 | 224 | ||
225 | extern void cgit_print_repolist(struct cacheitem *item); | 225 | extern void cgit_print_repolist(struct cacheitem *item); |
226 | extern void cgit_print_summary(); | 226 | extern void cgit_print_summary(); |
227 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 227 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
228 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 228 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
229 | extern void cgit_print_tree(const char *rev, char *path); | 229 | extern void cgit_print_tree(const char *rev, char *path); |
230 | extern void cgit_print_commit(char *hex); | 230 | extern void cgit_print_commit(char *hex); |
231 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 231 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
232 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 232 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
233 | const char *format, const char *prefix, | 233 | const char *prefix, const char *filename); |
234 | const char *filename); | 234 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); |
235 | 235 | ||
236 | #endif /* CGIT_H */ | 236 | #endif /* CGIT_H */ |
diff --git a/ui-commit.c b/ui-commit.c index 2679b59..bf5e6dc 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -94,135 +94,132 @@ void print_fileinfo(struct fileinfo *info) | |||
94 | html("</tr></table></td></tr>\n"); | 94 | html("</tr></table></td></tr>\n"); |
95 | } | 95 | } |
96 | 96 | ||
97 | void cgit_count_diff_lines(char *line, int len) | 97 | void cgit_count_diff_lines(char *line, int len) |
98 | { | 98 | { |
99 | if (line && (len > 0)) { | 99 | if (line && (len > 0)) { |
100 | if (line[0] == '+') | 100 | if (line[0] == '+') |
101 | lines_added++; | 101 | lines_added++; |
102 | else if (line[0] == '-') | 102 | else if (line[0] == '-') |
103 | lines_removed++; | 103 | lines_removed++; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | void inspect_filepair(struct diff_filepair *pair) | 107 | void inspect_filepair(struct diff_filepair *pair) |
108 | { | 108 | { |
109 | files++; | 109 | files++; |
110 | lines_added = 0; | 110 | lines_added = 0; |
111 | lines_removed = 0; | 111 | lines_removed = 0; |
112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
113 | if (files >= slots) { | 113 | if (files >= slots) { |
114 | if (slots == 0) | 114 | if (slots == 0) |
115 | slots = 4; | 115 | slots = 4; |
116 | else | 116 | else |
117 | slots = slots * 2; | 117 | slots = slots * 2; |
118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
119 | } | 119 | } |
120 | items[files-1].status = pair->status; | 120 | items[files-1].status = pair->status; |
121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
123 | items[files-1].old_mode = pair->one->mode; | 123 | items[files-1].old_mode = pair->one->mode; |
124 | items[files-1].new_mode = pair->two->mode; | 124 | items[files-1].new_mode = pair->two->mode; |
125 | items[files-1].old_path = xstrdup(pair->one->path); | 125 | items[files-1].old_path = xstrdup(pair->one->path); |
126 | items[files-1].new_path = xstrdup(pair->two->path); | 126 | items[files-1].new_path = xstrdup(pair->two->path); |
127 | items[files-1].added = lines_added; | 127 | items[files-1].added = lines_added; |
128 | items[files-1].removed = lines_removed; | 128 | items[files-1].removed = lines_removed; |
129 | if (lines_added + lines_removed > max_changes) | 129 | if (lines_added + lines_removed > max_changes) |
130 | max_changes = lines_added + lines_removed; | 130 | max_changes = lines_added + lines_removed; |
131 | total_adds += lines_added; | 131 | total_adds += lines_added; |
132 | total_rems += lines_removed; | 132 | total_rems += lines_removed; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void cgit_print_commit(char *hex) | 136 | void 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 *filename; | ||
143 | char *tmp; | 142 | char *tmp; |
144 | int i; | 143 | int i; |
145 | 144 | ||
146 | if (!hex) | 145 | if (!hex) |
147 | hex = cgit_query_head; | 146 | hex = cgit_query_head; |
148 | curr_rev = hex; | 147 | curr_rev = hex; |
149 | 148 | ||
150 | if (get_sha1(hex, sha1)) { | 149 | if (get_sha1(hex, sha1)) { |
151 | cgit_print_error(fmt("Bad object id: %s", hex)); | 150 | cgit_print_error(fmt("Bad object id: %s", hex)); |
152 | return; | 151 | return; |
153 | } | 152 | } |
154 | commit = lookup_commit_reference(sha1); | 153 | commit = lookup_commit_reference(sha1); |
155 | if (!commit) { | 154 | if (!commit) { |
156 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 155 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
157 | return; | 156 | return; |
158 | } | 157 | } |
159 | info = cgit_parse_commit(commit); | 158 | info = cgit_parse_commit(commit); |
160 | 159 | ||
161 | html("<table class='commit-info'>\n"); | 160 | html("<table class='commit-info'>\n"); |
162 | html("<tr><th>author</th><td>"); | 161 | html("<tr><th>author</th><td>"); |
163 | html_txt(info->author); | 162 | html_txt(info->author); |
164 | html(" "); | 163 | html(" "); |
165 | html_txt(info->author_email); | 164 | html_txt(info->author_email); |
166 | html("</td><td class='right'>"); | 165 | html("</td><td class='right'>"); |
167 | cgit_print_date(info->author_date, FMT_LONGDATE); | 166 | cgit_print_date(info->author_date, FMT_LONGDATE); |
168 | html("</td></tr>\n"); | 167 | html("</td></tr>\n"); |
169 | html("<tr><th>committer</th><td>"); | 168 | html("<tr><th>committer</th><td>"); |
170 | html_txt(info->committer); | 169 | html_txt(info->committer); |
171 | html(" "); | 170 | html(" "); |
172 | html_txt(info->committer_email); | 171 | html_txt(info->committer_email); |
173 | html("</td><td class='right'>"); | 172 | html("</td><td class='right'>"); |
174 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 173 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
175 | html("</td></tr>\n"); | 174 | html("</td></tr>\n"); |
176 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
177 | tmp = xstrdup(hex); | 176 | tmp = xstrdup(hex); |
178 | 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, |
179 | cgit_query_head, tmp, NULL); | 178 | cgit_query_head, tmp, NULL); |
180 | html("</td></tr>\n"); | 179 | html("</td></tr>\n"); |
181 | for (p = commit->parents; p ; p = p->next) { | 180 | for (p = commit->parents; p ; p = p->next) { |
182 | parent = lookup_commit_reference(p->item->object.sha1); | 181 | parent = lookup_commit_reference(p->item->object.sha1); |
183 | if (!parent) { | 182 | if (!parent) { |
184 | html("<tr><td colspan='3'>"); | 183 | html("<tr><td colspan='3'>"); |
185 | cgit_print_error("Error reading parent commit"); | 184 | cgit_print_error("Error reading parent commit"); |
186 | html("</td></tr>"); | 185 | html("</td></tr>"); |
187 | continue; | 186 | continue; |
188 | } | 187 | } |
189 | html("<tr><th>parent</th>" | 188 | html("<tr><th>parent</th>" |
190 | "<td colspan='2' class='sha1'>"); | 189 | "<td colspan='2' class='sha1'>"); |
191 | 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, |
192 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); | 191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); |
193 | html(" ("); | 192 | html(" ("); |
194 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, | 193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, |
195 | sha1_to_hex(p->item->object.sha1), NULL); | 194 | sha1_to_hex(p->item->object.sha1), NULL); |
196 | html(")</td></tr>"); | 195 | html(")</td></tr>"); |
197 | } | 196 | } |
198 | if (cgit_repo->snapshots) { | 197 | if (cgit_repo->snapshots) { |
199 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); | 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
200 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); | 199 | cgit_print_snapshot_links(cgit_query_repo,hex); |
201 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", | 200 | html("</td></tr>"); |
202 | fmt("id=%s&name=%s", hex, filename))); | ||
203 | htmlf("'>%s</a></td></tr>", filename); | ||
204 | } | 201 | } |
205 | html("</table>\n"); | 202 | html("</table>\n"); |
206 | html("<div class='commit-subject'>"); | 203 | html("<div class='commit-subject'>"); |
207 | html_txt(info->subject); | 204 | html_txt(info->subject); |
208 | html("</div>"); | 205 | html("</div>"); |
209 | html("<div class='commit-msg'>"); | 206 | html("<div class='commit-msg'>"); |
210 | html_txt(info->msg); | 207 | html_txt(info->msg); |
211 | html("</div>"); | 208 | html("</div>"); |
212 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
213 | html("<div class='diffstat-header'>Diffstat</div>"); | 210 | html("<div class='diffstat-header'>Diffstat</div>"); |
214 | html("<table class='diffstat'>"); | 211 | html("<table class='diffstat'>"); |
215 | max_changes = 0; | 212 | max_changes = 0; |
216 | cgit_diff_commit(commit, inspect_filepair); | 213 | cgit_diff_commit(commit, inspect_filepair); |
217 | for(i = 0; i<files; i++) | 214 | for(i = 0; i<files; i++) |
218 | print_fileinfo(&items[i]); | 215 | print_fileinfo(&items[i]); |
219 | html("</table>"); | 216 | html("</table>"); |
220 | html("<div class='diffstat-summary'>"); | 217 | html("<div class='diffstat-summary'>"); |
221 | htmlf("%d files changed, %d insertions, %d deletions (", | 218 | htmlf("%d files changed, %d insertions, %d deletions (", |
222 | files, total_adds, total_rems); | 219 | files, total_adds, total_rems); |
223 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, | 220 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, |
224 | NULL, NULL); | 221 | NULL, NULL); |
225 | html(")</div>"); | 222 | html(")</div>"); |
226 | } | 223 | } |
227 | cgit_free_commitinfo(info); | 224 | cgit_free_commitinfo(info); |
228 | } | 225 | } |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 2257d6b..eb5f1cd 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -1,47 +1,68 @@ | |||
1 | /* ui-snapshot.c: generate snapshot of a commit | 1 | /* ui-snapshot.c: generate snapshot of a commit |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static void cgit_print_zip(struct cacheitem *item, const char *hex, | 11 | static const struct snapshot_archive_t { |
12 | const char *prefix, const char *filename) | 12 | const char *suffix; |
13 | const char *mimetype; | ||
14 | write_archive_fn_t write_func; | ||
15 | }snapshot_archives[] = { | ||
16 | { ".zip", "application/x-zip", write_zip_archive }, | ||
17 | { ".tar.gz", "application/x-gzip", write_tar_archive } | ||
18 | }; | ||
19 | |||
20 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | ||
21 | const char *prefix, const char *filename) | ||
13 | { | 22 | { |
14 | struct archiver_args args; | 23 | int fnl = strlen(filename); |
15 | struct commit *commit; | 24 | int f; |
16 | unsigned char sha1[20]; | 25 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
26 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | ||
27 | int sl = strlen(sat->suffix); | ||
28 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | ||
29 | continue; | ||
17 | 30 | ||
18 | if (get_sha1(hex, sha1)) { | 31 | struct archiver_args args; |
19 | cgit_print_error(fmt("Bad object id: %s", hex)); | 32 | struct commit *commit; |
20 | return; | 33 | unsigned char sha1[20]; |
21 | } | 34 | |
22 | commit = lookup_commit_reference(sha1); | 35 | if(get_sha1(hex, sha1)) { |
36 | cgit_print_error(fmt("Bad object id: %s", hex)); | ||
37 | return; | ||
38 | } | ||
39 | commit = lookup_commit_reference(sha1); | ||
40 | |||
41 | if(!commit) { | ||
42 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | ||
43 | return;; | ||
44 | } | ||
23 | 45 | ||
24 | if (!commit) { | 46 | memset(&args,0,sizeof(args)); |
25 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 47 | args.base = fmt("%s/", prefix); |
48 | args.tree = commit->tree; | ||
49 | |||
50 | cgit_print_snapshot_start(sat->mimetype, filename, item); | ||
51 | (*sat->write_func)(&args); | ||
26 | return; | 52 | return; |
27 | } | 53 | } |
28 | 54 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | |
29 | memset(&args, 0, sizeof(args)); | ||
30 | args.base = fmt("%s/", prefix); | ||
31 | args.tree = commit->tree; | ||
32 | |||
33 | cgit_print_snapshot_start("application/x-zip", filename, item); | ||
34 | write_zip_archive(&args); | ||
35 | } | 55 | } |
36 | 56 | ||
37 | 57 | void cgit_print_snapshot_links(const char *repo,const char *hex) | |
38 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | ||
39 | const char *format, const char *prefix, | ||
40 | const char *filename) | ||
41 | { | 58 | { |
42 | if (!strcmp(format, "zip")) | 59 | char *filename; |
43 | cgit_print_zip(item, hex, prefix, filename); | 60 | int f; |
44 | else | 61 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
45 | cgit_print_error(fmt("Unsupported snapshot format: %s", | 62 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
46 | format)); | 63 | filename = fmt("%s-%s%s",repo,hex,sat->suffix); |
64 | htmlf("<a href='%s'>%s</a><br/>", | ||
65 | cgit_pageurl(repo,"snapshot", | ||
66 | fmt("id=%s&name=%s",hex,filename)), filename); | ||
67 | } | ||
47 | } | 68 | } |