author | Michael Krelin <hacker@klever.net> | 2007-07-21 11:13:40 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-21 11:13:40 (UTC) |
commit | 0df096f6e146187e55e2203ea1c017442cc2c8c6 (patch) (unidiff) | |
tree | c3daea456db5424bbddee326c1479a2b759d551a | |
parent | 86ca02231fc42a629c50abebcae3ea9d4d692979 (diff) | |
download | cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.zip cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.gz cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.bz2 |
added snapshot filename to the link
- changed cgit_pageurl into cgit_fileurl with the filename parameter
- rewritten cgit_pageurl as a wrapper around cgit_fileurl
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 17 | ||||
-rw-r--r-- | ui-snapshot.c | 2 |
3 files changed, 16 insertions, 5 deletions
@@ -12,226 +12,228 @@ | |||
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> | 18 | #include <xdiff/xdiff.h> |
19 | 19 | ||
20 | 20 | ||
21 | /* | 21 | /* |
22 | * The valid cgit repo-commands | 22 | * The valid cgit repo-commands |
23 | */ | 23 | */ |
24 | #define CMD_LOG 1 | 24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | 30 | ||
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Dateformats used on misc. pages | 33 | * Dateformats used on misc. pages |
34 | */ | 34 | */ |
35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
36 | #define FMT_SHORTDATE "%Y-%m-%d" | 36 | #define FMT_SHORTDATE "%Y-%m-%d" |
37 | 37 | ||
38 | 38 | ||
39 | /* | 39 | /* |
40 | * Limits used for relative dates | 40 | * Limits used for relative dates |
41 | */ | 41 | */ |
42 | #define TM_MIN 60 | 42 | #define TM_MIN 60 |
43 | #define TM_HOUR (TM_MIN * 60) | 43 | #define TM_HOUR (TM_MIN * 60) |
44 | #define TM_DAY (TM_HOUR * 24) | 44 | #define TM_DAY (TM_HOUR * 24) |
45 | #define TM_WEEK (TM_DAY * 7) | 45 | #define TM_WEEK (TM_DAY * 7) |
46 | #define TM_YEAR (TM_DAY * 365) | 46 | #define TM_YEAR (TM_DAY * 365) |
47 | #define TM_MONTH (TM_YEAR / 12.0) | 47 | #define TM_MONTH (TM_YEAR / 12.0) |
48 | 48 | ||
49 | 49 | ||
50 | typedef void (*configfn)(const char *name, const char *value); | 50 | typedef void (*configfn)(const char *name, const char *value); |
51 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 51 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
52 | typedef void (*linediff_fn)(char *line, int len); | 52 | typedef void (*linediff_fn)(char *line, int len); |
53 | 53 | ||
54 | struct cacheitem { | 54 | struct cacheitem { |
55 | char *name; | 55 | char *name; |
56 | struct stat st; | 56 | struct stat st; |
57 | int ttl; | 57 | int ttl; |
58 | int fd; | 58 | int fd; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | struct repoinfo { | 61 | struct repoinfo { |
62 | char *url; | 62 | char *url; |
63 | char *name; | 63 | char *name; |
64 | char *path; | 64 | char *path; |
65 | char *desc; | 65 | char *desc; |
66 | char *owner; | 66 | char *owner; |
67 | char *defbranch; | 67 | char *defbranch; |
68 | char *group; | 68 | char *group; |
69 | char *module_link; | 69 | char *module_link; |
70 | char *readme; | 70 | char *readme; |
71 | int snapshots; | 71 | int snapshots; |
72 | int enable_log_filecount; | 72 | int enable_log_filecount; |
73 | int enable_log_linecount; | 73 | int enable_log_linecount; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | struct repolist { | 76 | struct repolist { |
77 | int length; | 77 | int length; |
78 | int count; | 78 | int count; |
79 | struct repoinfo *repos; | 79 | struct repoinfo *repos; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | struct commitinfo { | 82 | struct commitinfo { |
83 | struct commit *commit; | 83 | struct commit *commit; |
84 | char *author; | 84 | char *author; |
85 | char *author_email; | 85 | char *author_email; |
86 | unsigned long author_date; | 86 | unsigned long author_date; |
87 | char *committer; | 87 | char *committer; |
88 | char *committer_email; | 88 | char *committer_email; |
89 | unsigned long committer_date; | 89 | unsigned long committer_date; |
90 | char *subject; | 90 | char *subject; |
91 | char *msg; | 91 | char *msg; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | struct taginfo { | 94 | struct taginfo { |
95 | char *tagger; | 95 | char *tagger; |
96 | char *tagger_email; | 96 | char *tagger_email; |
97 | int tagger_date; | 97 | int tagger_date; |
98 | char *msg; | 98 | char *msg; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | extern const char *cgit_version; | 101 | extern const char *cgit_version; |
102 | 102 | ||
103 | extern struct repolist cgit_repolist; | 103 | extern struct repolist cgit_repolist; |
104 | extern struct repoinfo *cgit_repo; | 104 | extern struct repoinfo *cgit_repo; |
105 | extern int cgit_cmd; | 105 | extern int cgit_cmd; |
106 | 106 | ||
107 | extern char *cgit_root_title; | 107 | extern char *cgit_root_title; |
108 | extern char *cgit_css; | 108 | extern char *cgit_css; |
109 | extern char *cgit_logo; | 109 | extern char *cgit_logo; |
110 | extern char *cgit_index_header; | 110 | extern char *cgit_index_header; |
111 | extern char *cgit_logo_link; | 111 | extern char *cgit_logo_link; |
112 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
113 | extern char *cgit_agefile; | 113 | extern char *cgit_agefile; |
114 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
115 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
116 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
117 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
118 | 118 | ||
119 | extern int cgit_nocache; | 119 | extern int cgit_nocache; |
120 | extern int cgit_snapshots; | 120 | extern int cgit_snapshots; |
121 | extern int cgit_enable_index_links; | 121 | extern int cgit_enable_index_links; |
122 | extern int cgit_enable_log_filecount; | 122 | extern int cgit_enable_log_filecount; |
123 | extern int cgit_enable_log_linecount; | 123 | extern int cgit_enable_log_linecount; |
124 | extern int cgit_max_lock_attempts; | 124 | extern int cgit_max_lock_attempts; |
125 | extern int cgit_cache_root_ttl; | 125 | extern int cgit_cache_root_ttl; |
126 | extern int cgit_cache_repo_ttl; | 126 | extern int cgit_cache_repo_ttl; |
127 | extern int cgit_cache_dynamic_ttl; | 127 | extern int cgit_cache_dynamic_ttl; |
128 | extern int cgit_cache_static_ttl; | 128 | extern int cgit_cache_static_ttl; |
129 | extern int cgit_cache_max_create_time; | 129 | extern int cgit_cache_max_create_time; |
130 | extern int cgit_summary_log; | 130 | extern int cgit_summary_log; |
131 | 131 | ||
132 | extern int cgit_max_msg_len; | 132 | extern int cgit_max_msg_len; |
133 | extern int cgit_max_repodesc_len; | 133 | extern int cgit_max_repodesc_len; |
134 | extern int cgit_max_commit_count; | 134 | extern int cgit_max_commit_count; |
135 | 135 | ||
136 | extern int cgit_query_has_symref; | 136 | extern int cgit_query_has_symref; |
137 | extern int cgit_query_has_sha1; | 137 | extern int cgit_query_has_sha1; |
138 | 138 | ||
139 | extern char *cgit_querystring; | 139 | extern char *cgit_querystring; |
140 | extern char *cgit_query_repo; | 140 | extern char *cgit_query_repo; |
141 | extern char *cgit_query_page; | 141 | extern char *cgit_query_page; |
142 | extern char *cgit_query_search; | 142 | extern char *cgit_query_search; |
143 | extern char *cgit_query_head; | 143 | extern char *cgit_query_head; |
144 | extern char *cgit_query_sha1; | 144 | extern char *cgit_query_sha1; |
145 | extern char *cgit_query_sha2; | 145 | extern char *cgit_query_sha2; |
146 | extern char *cgit_query_path; | 146 | extern char *cgit_query_path; |
147 | extern char *cgit_query_name; | 147 | extern char *cgit_query_name; |
148 | extern int cgit_query_ofs; | 148 | extern int cgit_query_ofs; |
149 | 149 | ||
150 | extern int htmlfd; | 150 | extern int htmlfd; |
151 | 151 | ||
152 | extern int cgit_get_cmd_index(const char *cmd); | 152 | extern int cgit_get_cmd_index(const char *cmd); |
153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
154 | extern void cgit_global_config_cb(const char *name, const char *value); | 154 | extern void cgit_global_config_cb(const char *name, const char *value); |
155 | extern void cgit_repo_config_cb(const char *name, const char *value); | 155 | extern void cgit_repo_config_cb(const char *name, const char *value); |
156 | extern void cgit_querystring_cb(const char *name, const char *value); | 156 | extern void cgit_querystring_cb(const char *name, const char *value); |
157 | 157 | ||
158 | extern int chk_zero(int result, char *msg); | 158 | extern int chk_zero(int result, char *msg); |
159 | extern int chk_positive(int result, char *msg); | 159 | extern int chk_positive(int result, char *msg); |
160 | extern int chk_non_negative(int result, char *msg); | 160 | extern int chk_non_negative(int result, char *msg); |
161 | 161 | ||
162 | extern int hextoint(char c); | 162 | extern int hextoint(char c); |
163 | extern char *trim_end(const char *str, char c); | 163 | extern char *trim_end(const char *str, char c); |
164 | 164 | ||
165 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 165 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
166 | 166 | ||
167 | extern int cgit_diff_files(const unsigned char *old_sha1, | 167 | extern 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 | ||
171 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 171 | extern 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 | ||
175 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 175 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
176 | 176 | ||
177 | extern char *fmt(const char *format,...); | 177 | extern char *fmt(const char *format,...); |
178 | 178 | ||
179 | extern void html(const char *txt); | 179 | extern void html(const char *txt); |
180 | extern void htmlf(const char *format,...); | 180 | extern void htmlf(const char *format,...); |
181 | extern void html_txt(char *txt); | 181 | extern void html_txt(char *txt); |
182 | extern void html_ntxt(int len, char *txt); | 182 | extern void html_ntxt(int len, char *txt); |
183 | extern void html_attr(char *txt); | 183 | extern void html_attr(char *txt); |
184 | extern void html_hidden(char *name, char *value); | 184 | extern void html_hidden(char *name, char *value); |
185 | extern void html_link_open(char *url, char *title, char *class); | 185 | extern void html_link_open(char *url, char *title, char *class); |
186 | extern void html_link_close(void); | 186 | extern void html_link_close(void); |
187 | extern void html_filemode(unsigned short mode); | 187 | extern void html_filemode(unsigned short mode); |
188 | extern int html_include(const char *filename); | 188 | extern int html_include(const char *filename); |
189 | 189 | ||
190 | extern int cgit_read_config(const char *filename, configfn fn); | 190 | extern int cgit_read_config(const char *filename, configfn fn); |
191 | extern int cgit_parse_query(char *txt, configfn fn); | 191 | extern int cgit_parse_query(char *txt, configfn fn); |
192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
194 | extern void cgit_parse_url(const char *url); | 194 | extern void cgit_parse_url(const char *url); |
195 | 195 | ||
196 | extern char *cache_safe_filename(const char *unsafe); | 196 | extern char *cache_safe_filename(const char *unsafe); |
197 | extern int cache_lock(struct cacheitem *item); | 197 | extern int cache_lock(struct cacheitem *item); |
198 | extern int cache_unlock(struct cacheitem *item); | 198 | extern int cache_unlock(struct cacheitem *item); |
199 | extern int cache_cancel_lock(struct cacheitem *item); | 199 | extern int cache_cancel_lock(struct cacheitem *item); |
200 | extern int cache_exist(struct cacheitem *item); | 200 | extern int cache_exist(struct cacheitem *item); |
201 | extern int cache_expired(struct cacheitem *item); | 201 | extern int cache_expired(struct cacheitem *item); |
202 | 202 | ||
203 | extern char *cgit_repourl(const char *reponame); | 203 | extern char *cgit_repourl(const char *reponame); |
204 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | ||
205 | const char *filename, const char *query); | ||
204 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
205 | const char *query); | 207 | const char *query); |
206 | 208 | ||
207 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 209 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
208 | char *rev, char *path); | 210 | char *rev, char *path); |
209 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 211 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
210 | char *rev, char *path, int ofs); | 212 | char *rev, char *path, int ofs); |
211 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 213 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
212 | char *rev); | 214 | char *rev); |
213 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 215 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
214 | char *new_rev, char *old_rev, char *path); | 216 | char *new_rev, char *old_rev, char *path); |
215 | 217 | ||
216 | extern void cgit_print_error(char *msg); | 218 | extern void cgit_print_error(char *msg); |
217 | extern void cgit_print_date(time_t secs, char *format); | 219 | extern void cgit_print_date(time_t secs, char *format); |
218 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 220 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
219 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 221 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
220 | extern void cgit_print_docend(); | 222 | extern void cgit_print_docend(); |
221 | extern void cgit_print_pageheader(char *title, int show_search); | 223 | extern void cgit_print_pageheader(char *title, int show_search); |
222 | extern void cgit_print_snapshot_start(const char *mimetype, | 224 | extern void cgit_print_snapshot_start(const char *mimetype, |
223 | const char *filename, | 225 | const char *filename, |
224 | struct cacheitem *item); | 226 | struct cacheitem *item); |
225 | 227 | ||
226 | extern void cgit_print_repolist(struct cacheitem *item); | 228 | extern void cgit_print_repolist(struct cacheitem *item); |
227 | extern void cgit_print_summary(); | 229 | extern void cgit_print_summary(); |
228 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 230 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
229 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 231 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
230 | extern void cgit_print_tree(const char *rev, char *path); | 232 | extern void cgit_print_tree(const char *rev, char *path); |
231 | extern void cgit_print_commit(char *hex); | 233 | extern void cgit_print_commit(char *hex); |
232 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 234 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
233 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 235 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
234 | const char *prefix, const char *filename); | 236 | const char *prefix, const char *filename); |
235 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); | 237 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); |
236 | 238 | ||
237 | #endif /* CGIT_H */ | 239 | #endif /* CGIT_H */ |
diff --git a/ui-shared.c b/ui-shared.c index d4376ce..1c1415e 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,370 +1,379 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
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 | const char cgit_doctype[] = | 11 | const char cgit_doctype[] = |
12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
14 | 14 | ||
15 | static char *http_date(time_t t) | 15 | static char *http_date(time_t t) |
16 | { | 16 | { |
17 | static char day[][4] = | 17 | static char day[][4] = |
18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
19 | static char month[][4] = | 19 | static char month[][4] = |
20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
22 | struct tm *tm = gmtime(&t); | 22 | struct tm *tm = gmtime(&t); |
23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 25 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
26 | } | 26 | } |
27 | 27 | ||
28 | static long ttl_seconds(long ttl) | 28 | static long ttl_seconds(long ttl) |
29 | { | 29 | { |
30 | if (ttl<0) | 30 | if (ttl<0) |
31 | return 60 * 60 * 24 * 365; | 31 | return 60 * 60 * 24 * 365; |
32 | else | 32 | else |
33 | return ttl * 60; | 33 | return ttl * 60; |
34 | } | 34 | } |
35 | 35 | ||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | ||
79 | const char *query) | ||
80 | { | ||
81 | return cgit_fileurl(reponame,pagename,0,query); | ||
82 | } | ||
83 | |||
84 | |||
78 | char *cgit_currurl() | 85 | char *cgit_currurl() |
79 | { | 86 | { |
80 | if (!cgit_virtual_root) | 87 | if (!cgit_virtual_root) |
81 | return cgit_script_name; | 88 | return cgit_script_name; |
82 | else if (cgit_query_page) | 89 | else if (cgit_query_page) |
83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 90 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
84 | else if (cgit_query_repo) | 91 | else if (cgit_query_repo) |
85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 92 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
86 | else | 93 | else |
87 | return fmt("%s/", cgit_virtual_root); | 94 | return fmt("%s/", cgit_virtual_root); |
88 | } | 95 | } |
89 | 96 | ||
90 | static char *repolink(char *title, char *class, char *page, char *head, | 97 | static char *repolink(char *title, char *class, char *page, char *head, |
91 | char *path) | 98 | char *path) |
92 | { | 99 | { |
93 | char *delim = "?"; | 100 | char *delim = "?"; |
94 | 101 | ||
95 | html("<a"); | 102 | html("<a"); |
96 | if (title) { | 103 | if (title) { |
97 | html(" title='"); | 104 | html(" title='"); |
98 | html_attr(title); | 105 | html_attr(title); |
99 | html("'"); | 106 | html("'"); |
100 | } | 107 | } |
101 | if (class) { | 108 | if (class) { |
102 | html(" class='"); | 109 | html(" class='"); |
103 | html_attr(class); | 110 | html_attr(class); |
104 | html("'"); | 111 | html("'"); |
105 | } | 112 | } |
106 | html(" href='"); | 113 | html(" href='"); |
107 | if (cgit_virtual_root) { | 114 | if (cgit_virtual_root) { |
108 | html_attr(cgit_virtual_root); | 115 | html_attr(cgit_virtual_root); |
109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 116 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
110 | html("/"); | 117 | html("/"); |
111 | html_attr(cgit_repo->url); | 118 | html_attr(cgit_repo->url); |
112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 119 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
113 | html("/"); | 120 | html("/"); |
114 | if (page) { | 121 | if (page) { |
115 | html(page); | 122 | html(page); |
116 | html("/"); | 123 | html("/"); |
117 | if (path) | 124 | if (path) |
118 | html_attr(path); | 125 | html_attr(path); |
119 | } | 126 | } |
120 | } else { | 127 | } else { |
121 | html(cgit_script_name); | 128 | html(cgit_script_name); |
122 | html("?url="); | 129 | html("?url="); |
123 | html_attr(cgit_repo->url); | 130 | html_attr(cgit_repo->url); |
124 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 131 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
125 | html("/"); | 132 | html("/"); |
126 | if (page) { | 133 | if (page) { |
127 | html(page); | 134 | html(page); |
128 | html("/"); | 135 | html("/"); |
129 | if (path) | 136 | if (path) |
130 | html_attr(path); | 137 | html_attr(path); |
131 | } | 138 | } |
132 | delim = "&"; | 139 | delim = "&"; |
133 | } | 140 | } |
134 | if (head && strcmp(head, cgit_repo->defbranch)) { | 141 | if (head && strcmp(head, cgit_repo->defbranch)) { |
135 | html(delim); | 142 | html(delim); |
136 | html("h="); | 143 | html("h="); |
137 | html_attr(head); | 144 | html_attr(head); |
138 | delim = "&"; | 145 | delim = "&"; |
139 | } | 146 | } |
140 | return fmt("%s", delim); | 147 | return fmt("%s", delim); |
141 | } | 148 | } |
142 | 149 | ||
143 | static void reporevlink(char *page, char *name, char *title, char *class, | 150 | static void reporevlink(char *page, char *name, char *title, char *class, |
144 | char *head, char *rev, char *path) | 151 | char *head, char *rev, char *path) |
145 | { | 152 | { |
146 | char *delim; | 153 | char *delim; |
147 | 154 | ||
148 | delim = repolink(title, class, page, head, path); | 155 | delim = repolink(title, class, page, head, path); |
149 | if (rev && strcmp(rev, cgit_query_head)) { | 156 | if (rev && strcmp(rev, cgit_query_head)) { |
150 | html(delim); | 157 | html(delim); |
151 | html("id="); | 158 | html("id="); |
152 | html_attr(rev); | 159 | html_attr(rev); |
153 | } | 160 | } |
154 | html("'>"); | 161 | html("'>"); |
155 | html_txt(name); | 162 | html_txt(name); |
156 | html("</a>"); | 163 | html("</a>"); |
157 | } | 164 | } |
158 | 165 | ||
159 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 166 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
160 | char *rev, char *path) | 167 | char *rev, char *path) |
161 | { | 168 | { |
162 | reporevlink("tree", name, title, class, head, rev, path); | 169 | reporevlink("tree", name, title, class, head, rev, path); |
163 | } | 170 | } |
164 | 171 | ||
165 | void cgit_log_link(char *name, char *title, char *class, char *head, | 172 | void cgit_log_link(char *name, char *title, char *class, char *head, |
166 | char *rev, char *path, int ofs) | 173 | char *rev, char *path, int ofs) |
167 | { | 174 | { |
168 | char *delim; | 175 | char *delim; |
169 | 176 | ||
170 | delim = repolink(title, class, "log", head, path); | 177 | delim = repolink(title, class, "log", head, path); |
171 | if (rev && strcmp(rev, cgit_query_head)) { | 178 | if (rev && strcmp(rev, cgit_query_head)) { |
172 | html(delim); | 179 | html(delim); |
173 | html("id="); | 180 | html("id="); |
174 | html_attr(rev); | 181 | html_attr(rev); |
175 | delim = "&"; | 182 | delim = "&"; |
176 | } | 183 | } |
177 | if (ofs > 0) { | 184 | if (ofs > 0) { |
178 | html(delim); | 185 | html(delim); |
179 | html("ofs="); | 186 | html("ofs="); |
180 | htmlf("%d", ofs); | 187 | htmlf("%d", ofs); |
181 | } | 188 | } |
182 | html("'>"); | 189 | html("'>"); |
183 | html_txt(name); | 190 | html_txt(name); |
184 | html("</a>"); | 191 | html("</a>"); |
185 | } | 192 | } |
186 | 193 | ||
187 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 194 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
188 | char *rev) | 195 | char *rev) |
189 | { | 196 | { |
190 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 197 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
191 | name[cgit_max_msg_len] = '\0'; | 198 | name[cgit_max_msg_len] = '\0'; |
192 | name[cgit_max_msg_len - 1] = '.'; | 199 | name[cgit_max_msg_len - 1] = '.'; |
193 | name[cgit_max_msg_len - 2] = '.'; | 200 | name[cgit_max_msg_len - 2] = '.'; |
194 | name[cgit_max_msg_len - 3] = '.'; | 201 | name[cgit_max_msg_len - 3] = '.'; |
195 | } | 202 | } |
196 | reporevlink("commit", name, title, class, head, rev, NULL); | 203 | reporevlink("commit", name, title, class, head, rev, NULL); |
197 | } | 204 | } |
198 | 205 | ||
199 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 206 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
200 | char *new_rev, char *old_rev, char *path) | 207 | char *new_rev, char *old_rev, char *path) |
201 | { | 208 | { |
202 | char *delim; | 209 | char *delim; |
203 | 210 | ||
204 | delim = repolink(title, class, "diff", head, path); | 211 | delim = repolink(title, class, "diff", head, path); |
205 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 212 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
206 | html(delim); | 213 | html(delim); |
207 | html("id="); | 214 | html("id="); |
208 | html_attr(new_rev); | 215 | html_attr(new_rev); |
209 | delim = "&"; | 216 | delim = "&"; |
210 | } | 217 | } |
211 | if (old_rev) { | 218 | if (old_rev) { |
212 | html(delim); | 219 | html(delim); |
213 | html("id2="); | 220 | html("id2="); |
214 | html_attr(old_rev); | 221 | html_attr(old_rev); |
215 | } | 222 | } |
216 | html("'>"); | 223 | html("'>"); |
217 | html_txt(name); | 224 | html_txt(name); |
218 | html("</a>"); | 225 | html("</a>"); |
219 | } | 226 | } |
220 | 227 | ||
221 | void cgit_print_date(time_t secs, char *format) | 228 | void cgit_print_date(time_t secs, char *format) |
222 | { | 229 | { |
223 | char buf[64]; | 230 | char buf[64]; |
224 | struct tm *time; | 231 | struct tm *time; |
225 | 232 | ||
226 | time = gmtime(&secs); | 233 | time = gmtime(&secs); |
227 | strftime(buf, sizeof(buf)-1, format, time); | 234 | strftime(buf, sizeof(buf)-1, format, time); |
228 | html_txt(buf); | 235 | html_txt(buf); |
229 | } | 236 | } |
230 | 237 | ||
231 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 238 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
232 | { | 239 | { |
233 | time_t now, secs; | 240 | time_t now, secs; |
234 | 241 | ||
235 | time(&now); | 242 | time(&now); |
236 | secs = now - t; | 243 | secs = now - t; |
237 | 244 | ||
238 | if (secs > max_relative && max_relative >= 0) { | 245 | if (secs > max_relative && max_relative >= 0) { |
239 | cgit_print_date(t, format); | 246 | cgit_print_date(t, format); |
240 | return; | 247 | return; |
241 | } | 248 | } |
242 | 249 | ||
243 | if (secs < TM_HOUR * 2) { | 250 | if (secs < TM_HOUR * 2) { |
244 | htmlf("<span class='age-mins'>%.0f min.</span>", | 251 | htmlf("<span class='age-mins'>%.0f min.</span>", |
245 | secs * 1.0 / TM_MIN); | 252 | secs * 1.0 / TM_MIN); |
246 | return; | 253 | return; |
247 | } | 254 | } |
248 | if (secs < TM_DAY * 2) { | 255 | if (secs < TM_DAY * 2) { |
249 | htmlf("<span class='age-hours'>%.0f hours</span>", | 256 | htmlf("<span class='age-hours'>%.0f hours</span>", |
250 | secs * 1.0 / TM_HOUR); | 257 | secs * 1.0 / TM_HOUR); |
251 | return; | 258 | return; |
252 | } | 259 | } |
253 | if (secs < TM_WEEK * 2) { | 260 | if (secs < TM_WEEK * 2) { |
254 | htmlf("<span class='age-days'>%.0f days</span>", | 261 | htmlf("<span class='age-days'>%.0f days</span>", |
255 | secs * 1.0 / TM_DAY); | 262 | secs * 1.0 / TM_DAY); |
256 | return; | 263 | return; |
257 | } | 264 | } |
258 | if (secs < TM_MONTH * 2) { | 265 | if (secs < TM_MONTH * 2) { |
259 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 266 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
260 | secs * 1.0 / TM_WEEK); | 267 | secs * 1.0 / TM_WEEK); |
261 | return; | 268 | return; |
262 | } | 269 | } |
263 | if (secs < TM_YEAR * 2) { | 270 | if (secs < TM_YEAR * 2) { |
264 | htmlf("<span class='age-months'>%.0f months</span>", | 271 | htmlf("<span class='age-months'>%.0f months</span>", |
265 | secs * 1.0 / TM_MONTH); | 272 | secs * 1.0 / TM_MONTH); |
266 | return; | 273 | return; |
267 | } | 274 | } |
268 | htmlf("<span class='age-years'>%.0f years</span>", | 275 | htmlf("<span class='age-years'>%.0f years</span>", |
269 | secs * 1.0 / TM_YEAR); | 276 | secs * 1.0 / TM_YEAR); |
270 | } | 277 | } |
271 | 278 | ||
272 | void cgit_print_docstart(char *title, struct cacheitem *item) | 279 | void cgit_print_docstart(char *title, struct cacheitem *item) |
273 | { | 280 | { |
274 | html("Content-Type: text/html; charset=utf-8\n"); | 281 | html("Content-Type: text/html; charset=utf-8\n"); |
275 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 282 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
276 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 283 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
277 | ttl_seconds(item->ttl))); | 284 | ttl_seconds(item->ttl))); |
278 | html("\n"); | 285 | html("\n"); |
279 | html(cgit_doctype); | 286 | html(cgit_doctype); |
280 | html("<html>\n"); | 287 | html("<html>\n"); |
281 | html("<head>\n"); | 288 | html("<head>\n"); |
282 | html("<title>"); | 289 | html("<title>"); |
283 | html_txt(title); | 290 | html_txt(title); |
284 | html("</title>\n"); | 291 | html("</title>\n"); |
285 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 292 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
286 | html("<link rel='stylesheet' type='text/css' href='"); | 293 | html("<link rel='stylesheet' type='text/css' href='"); |
287 | html_attr(cgit_css); | 294 | html_attr(cgit_css); |
288 | html("'/>\n"); | 295 | html("'/>\n"); |
289 | html("</head>\n"); | 296 | html("</head>\n"); |
290 | html("<body>\n"); | 297 | html("<body>\n"); |
291 | } | 298 | } |
292 | 299 | ||
293 | void cgit_print_docend() | 300 | void cgit_print_docend() |
294 | { | 301 | { |
295 | html("</td></tr></table>"); | 302 | html("</td></tr></table>"); |
296 | html("</body>\n</html>\n"); | 303 | html("</body>\n</html>\n"); |
297 | } | 304 | } |
298 | 305 | ||
299 | void cgit_print_pageheader(char *title, int show_search) | 306 | void cgit_print_pageheader(char *title, int show_search) |
300 | { | 307 | { |
301 | html("<table id='layout'>"); | 308 | html("<table id='layout'>"); |
302 | html("<tr><td id='header'><a href='"); | 309 | html("<tr><td id='header'><a href='"); |
303 | html_attr(cgit_rooturl()); | 310 | html_attr(cgit_rooturl()); |
304 | html("'>"); | 311 | html("'>"); |
305 | html_txt(cgit_root_title); | 312 | html_txt(cgit_root_title); |
306 | html("</a></td><td id='logo'>"); | 313 | html("</a></td><td id='logo'>"); |
307 | html("<a href='"); | 314 | html("<a href='"); |
308 | html_attr(cgit_logo_link); | 315 | html_attr(cgit_logo_link); |
309 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 316 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
310 | html("</td></tr>"); | 317 | html("</td></tr>"); |
311 | html("<tr><td id='crumb'>"); | 318 | html("<tr><td id='crumb'>"); |
312 | if (cgit_query_repo) { | 319 | if (cgit_query_repo) { |
313 | html_txt(cgit_repo->name); | 320 | html_txt(cgit_repo->name); |
314 | html(" ("); | 321 | html(" ("); |
315 | html_txt(cgit_query_head); | 322 | html_txt(cgit_query_head); |
316 | html(") : "); | 323 | html(") : "); |
317 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, | 324 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, |
318 | NULL, NULL); | 325 | NULL, NULL); |
319 | html(" "); | 326 | html(" "); |
320 | cgit_log_link("log", NULL, NULL, cgit_query_head, | 327 | cgit_log_link("log", NULL, NULL, cgit_query_head, |
321 | cgit_query_sha1, cgit_query_path, 0); | 328 | cgit_query_sha1, cgit_query_path, 0); |
322 | html(" "); | 329 | html(" "); |
323 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, | 330 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, |
324 | cgit_query_sha1, NULL); | 331 | cgit_query_sha1, NULL); |
325 | html(" "); | 332 | html(" "); |
326 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, | 333 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, |
327 | cgit_query_sha1); | 334 | cgit_query_sha1); |
328 | html(" "); | 335 | html(" "); |
329 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, | 336 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, |
330 | cgit_query_sha1, cgit_query_sha2, | 337 | cgit_query_sha1, cgit_query_sha2, |
331 | cgit_query_path); | 338 | cgit_query_path); |
332 | } else { | 339 | } else { |
333 | html_txt("Index of repositories"); | 340 | html_txt("Index of repositories"); |
334 | } | 341 | } |
335 | html("</td>"); | 342 | html("</td>"); |
336 | html("<td id='search'>"); | 343 | html("<td id='search'>"); |
337 | if (show_search) { | 344 | if (show_search) { |
338 | html("<form method='get' action='"); | 345 | html("<form method='get' action='"); |
339 | html_attr(cgit_currurl()); | 346 | html_attr(cgit_currurl()); |
340 | html("'>"); | 347 | html("'>"); |
341 | if (!cgit_virtual_root) { | 348 | if (!cgit_virtual_root) { |
342 | if (cgit_query_repo) | 349 | if (cgit_query_repo) |
343 | html_hidden("r", cgit_query_repo); | 350 | html_hidden("r", cgit_query_repo); |
344 | if (cgit_query_page) | 351 | if (cgit_query_page) |
345 | html_hidden("p", cgit_query_page); | 352 | html_hidden("p", cgit_query_page); |
346 | } | 353 | } |
347 | if (cgit_query_head) | 354 | if (cgit_query_head) |
348 | html_hidden("h", cgit_query_head); | 355 | html_hidden("h", cgit_query_head); |
349 | if (cgit_query_sha1) | 356 | if (cgit_query_sha1) |
350 | html_hidden("id", cgit_query_sha1); | 357 | html_hidden("id", cgit_query_sha1); |
351 | if (cgit_query_sha2) | 358 | if (cgit_query_sha2) |
352 | html_hidden("id2", cgit_query_sha2); | 359 | html_hidden("id2", cgit_query_sha2); |
353 | html("<input type='text' name='q' value='"); | 360 | html("<input type='text' name='q' value='"); |
354 | html_attr(cgit_query_search); | 361 | html_attr(cgit_query_search); |
355 | html("'/></form>"); | 362 | html("'/></form>"); |
356 | } | 363 | } |
357 | html("</td></tr>"); | 364 | html("</td></tr>"); |
358 | html("<tr><td id='content' colspan='2'>"); | 365 | html("<tr><td id='content' colspan='2'>"); |
359 | } | 366 | } |
360 | 367 | ||
361 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 368 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
362 | struct cacheitem *item) | 369 | struct cacheitem *item) |
363 | { | 370 | { |
364 | htmlf("Content-Type: %s\n", mimetype); | 371 | htmlf("Content-Type: %s\n", mimetype); |
365 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 372 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 373 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 374 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
368 | ttl_seconds(item->ttl))); | 375 | ttl_seconds(item->ttl))); |
369 | html("\n"); | 376 | html("\n"); |
370 | } | 377 | } |
378 | |||
379 | /* vim:set sw=8: */ | ||
diff --git a/ui-snapshot.c b/ui-snapshot.c index 84bf8f7..7076b50 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -1,116 +1,116 @@ | |||
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 int write_compressed_tar_archive(struct archiver_args *args,const char *filter) | 11 | static 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 | ||
47 | static int write_tar_gzip_archive(struct archiver_args *args) | 47 | static 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 | } |
51 | static int write_tar_bzip2_archive(struct archiver_args *args) | 51 | static 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 | ||
56 | static const struct snapshot_archive_t { | 56 | static 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 | }snapshot_archives[] = { | 60 | }snapshot_archives[] = { |
61 | { ".zip", "application/x-zip", write_zip_archive }, | 61 | { ".zip", "application/x-zip", write_zip_archive }, |
62 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive }, | 62 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive }, |
63 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive }, | 63 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive }, |
64 | { ".tar", "application/x-tar", write_tar_archive } | 64 | { ".tar", "application/x-tar", write_tar_archive } |
65 | }; | 65 | }; |
66 | 66 | ||
67 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 67 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
68 | const char *prefix, const char *filename) | 68 | const char *prefix, const char *filename) |
69 | { | 69 | { |
70 | int fnl = strlen(filename); | 70 | int fnl = strlen(filename); |
71 | int f; | 71 | int f; |
72 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 72 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
73 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 73 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
74 | int sl = strlen(sat->suffix); | 74 | int sl = strlen(sat->suffix); |
75 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | 75 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) |
76 | continue; | 76 | continue; |
77 | 77 | ||
78 | struct archiver_args args; | 78 | struct archiver_args args; |
79 | struct commit *commit; | 79 | struct commit *commit; |
80 | unsigned char sha1[20]; | 80 | unsigned char sha1[20]; |
81 | 81 | ||
82 | if(get_sha1(hex, sha1)) { | 82 | if(get_sha1(hex, sha1)) { |
83 | cgit_print_error(fmt("Bad object id: %s", hex)); | 83 | cgit_print_error(fmt("Bad object id: %s", hex)); |
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | commit = lookup_commit_reference(sha1); | 86 | commit = lookup_commit_reference(sha1); |
87 | 87 | ||
88 | if(!commit) { | 88 | if(!commit) { |
89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
90 | return;; | 90 | return;; |
91 | } | 91 | } |
92 | 92 | ||
93 | memset(&args,0,sizeof(args)); | 93 | memset(&args,0,sizeof(args)); |
94 | args.base = fmt("%s/", prefix); | 94 | args.base = fmt("%s/", prefix); |
95 | args.tree = commit->tree; | 95 | args.tree = commit->tree; |
96 | 96 | ||
97 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 97 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
98 | (*sat->write_func)(&args); | 98 | (*sat->write_func)(&args); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
102 | } | 102 | } |
103 | 103 | ||
104 | void cgit_print_snapshot_links(const char *repo,const char *hex) | 104 | void cgit_print_snapshot_links(const char *repo,const char *hex) |
105 | { | 105 | { |
106 | char *filename; | 106 | char *filename; |
107 | int f; | 107 | int f; |
108 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 108 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
109 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 109 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
110 | filename = fmt("%s-%s%s",repo,hex,sat->suffix); | 110 | filename = fmt("%s-%s%s",repo,hex,sat->suffix); |
111 | htmlf("<a href='%s'>%s</a><br/>", | 111 | htmlf("<a href='%s'>%s</a><br/>", |
112 | cgit_pageurl(repo,"snapshot", | 112 | cgit_fileurl(repo,"snapshot",filename, |
113 | fmt("id=%s&name=%s",hex,filename)), filename); | 113 | fmt("id=%s&name=%s",hex,filename)), filename); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | /* vim:set sw=8: */ | 116 | /* vim:set sw=8: */ |