author | Michael Krelin <hacker@klever.net> | 2007-07-21 16:00:53 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-21 16:00:53 (UTC) |
commit | dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e (patch) (unidiff) | |
tree | e42607f85bfb3ca33dff761a3966c502cdd6868e | |
parent | 97c025ae8ecf9764fd6996c81c51c3de4adb837c (diff) | |
download | cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.zip cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.tar.gz cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.tar.bz2 |
allow selective enabling of snapshots
snapshot configuration parameter now can be a
space/slash/comma/colon/semicolon/pipe-separated list of snaphot suffixes as
listed in ui-snapshot.c
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 6 | ||||
-rw-r--r-- | cgitrc | 5 | ||||
-rw-r--r-- | shared.c | 4 | ||||
-rw-r--r-- | ui-commit.c | 2 | ||||
-rw-r--r-- | ui-snapshot.c | 43 |
6 files changed, 48 insertions, 15 deletions
@@ -25,97 +25,98 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
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, | 71 | cgit_print_snapshot(item, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_name); | 73 | cgit_query_name, |
74 | cgit_repo->snapshots ); | ||
74 | return; | 75 | return; |
75 | } | 76 | } |
76 | 77 | ||
77 | if (cgit_cmd == CMD_BLOB) { | 78 | if (cgit_cmd == CMD_BLOB) { |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; | 80 | return; |
80 | } | 81 | } |
81 | 82 | ||
82 | show_search = (cgit_cmd == CMD_LOG); | 83 | show_search = (cgit_cmd == CMD_LOG); |
83 | cgit_print_docstart(title, item); | 84 | cgit_print_docstart(title, item); |
84 | if (!cgit_cmd) { | 85 | if (!cgit_cmd) { |
85 | cgit_print_pageheader("summary", show_search); | 86 | cgit_print_pageheader("summary", show_search); |
86 | cgit_print_summary(); | 87 | cgit_print_summary(); |
87 | cgit_print_docend(); | 88 | cgit_print_docend(); |
88 | return; | 89 | return; |
89 | } | 90 | } |
90 | 91 | ||
91 | cgit_print_pageheader(cgit_query_page, show_search); | 92 | cgit_print_pageheader(cgit_query_page, show_search); |
92 | 93 | ||
93 | switch(cgit_cmd) { | 94 | switch(cgit_cmd) { |
94 | case CMD_LOG: | 95 | case CMD_LOG: |
95 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
96 | cgit_max_commit_count, cgit_query_search, | 97 | cgit_max_commit_count, cgit_query_search, |
97 | cgit_query_path, 1); | 98 | cgit_query_path, 1); |
98 | break; | 99 | break; |
99 | case CMD_TREE: | 100 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
101 | break; | 102 | break; |
102 | case CMD_COMMIT: | 103 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_sha1); | 104 | cgit_print_commit(cgit_query_sha1); |
104 | break; | 105 | break; |
105 | case CMD_DIFF: | 106 | case CMD_DIFF: |
106 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 107 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
107 | break; | 108 | break; |
108 | default: | 109 | default: |
109 | cgit_print_error("Invalid request"); | 110 | cgit_print_error("Invalid request"); |
110 | } | 111 | } |
111 | cgit_print_docend(); | 112 | cgit_print_docend(); |
112 | } | 113 | } |
113 | 114 | ||
114 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
115 | { | 116 | { |
116 | static char buf[PATH_MAX]; | 117 | static char buf[PATH_MAX]; |
117 | int stdout2; | 118 | int stdout2; |
118 | 119 | ||
119 | getcwd(buf, sizeof(buf)); | 120 | getcwd(buf, sizeof(buf)); |
120 | item->st.st_mtime = time(NULL); | 121 | item->st.st_mtime = time(NULL); |
121 | 122 | ||
@@ -190,52 +190,54 @@ extern int html_include(const char *filename); | |||
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, | 204 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
205 | const char *filename, const char *query); | 205 | const char *filename, const char *query); |
206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
207 | const char *query); | 207 | const char *query); |
208 | 208 | ||
209 | extern const char *cgit_repobasename(const char *reponame); | 209 | extern const char *cgit_repobasename(const char *reponame); |
210 | 210 | ||
211 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 211 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
212 | char *rev, char *path); | 212 | char *rev, char *path); |
213 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 213 | extern 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); |
215 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 215 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
216 | char *rev); | 216 | char *rev); |
217 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 217 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
218 | char *new_rev, char *old_rev, char *path); | 218 | char *new_rev, char *old_rev, char *path); |
219 | 219 | ||
220 | extern void cgit_print_error(char *msg); | 220 | extern void cgit_print_error(char *msg); |
221 | extern void cgit_print_date(time_t secs, char *format); | 221 | extern void cgit_print_date(time_t secs, char *format); |
222 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 222 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
223 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 223 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
224 | extern void cgit_print_docend(); | 224 | extern void cgit_print_docend(); |
225 | extern void cgit_print_pageheader(char *title, int show_search); | 225 | extern void cgit_print_pageheader(char *title, int show_search); |
226 | extern void cgit_print_snapshot_start(const char *mimetype, | 226 | extern void cgit_print_snapshot_start(const char *mimetype, |
227 | const char *filename, | 227 | const char *filename, |
228 | struct cacheitem *item); | 228 | struct cacheitem *item); |
229 | 229 | ||
230 | extern void cgit_print_repolist(struct cacheitem *item); | 230 | extern void cgit_print_repolist(struct cacheitem *item); |
231 | extern void cgit_print_summary(); | 231 | extern void cgit_print_summary(); |
232 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 232 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
233 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 233 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
234 | extern void cgit_print_tree(const char *rev, char *path); | 234 | extern void cgit_print_tree(const char *rev, char *path); |
235 | extern void cgit_print_commit(char *hex); | 235 | extern void cgit_print_commit(char *hex); |
236 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 236 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
237 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 237 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
238 | const char *prefix, const char *filename); | 238 | const char *prefix, const char *filename, |
239 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); | 239 | int snapshot); |
240 | extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots); | ||
241 | extern int cgit_parse_snapshots_mask(const char *str); | ||
240 | 242 | ||
241 | #endif /* CGIT_H */ | 243 | #endif /* CGIT_H */ |
@@ -1,59 +1,60 @@ | |||
1 | ## | 1 | ## |
2 | ## cgitrc: template for /etc/cgitrc | 2 | ## cgitrc: template for /etc/cgitrc |
3 | ## | 3 | ## |
4 | 4 | ||
5 | 5 | ||
6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly | 6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly |
7 | ## usefull for testing. | 7 | ## usefull for testing. |
8 | #nocache=0 | 8 | #nocache=0 |
9 | 9 | ||
10 | 10 | ||
11 | ## Enable/disable snapshots by default. This can be overridden per repo | 11 | ## Set allowed snapshot types by default. Can be overridden per repo |
12 | # can be any combination of zip/tar.gz/tar.bz2/tar | ||
12 | #snapshots=0 | 13 | #snapshots=0 |
13 | 14 | ||
14 | 15 | ||
15 | ## Enable/disable extra links to summary/log/tree per repo on index page | 16 | ## Enable/disable extra links to summary/log/tree per repo on index page |
16 | #enable-index-links=0 | 17 | #enable-index-links=0 |
17 | 18 | ||
18 | 19 | ||
19 | ## Enable/disable display of 'number of files changed' in log view | 20 | ## Enable/disable display of 'number of files changed' in log view |
20 | #enable-log-filecount=0 | 21 | #enable-log-filecount=0 |
21 | 22 | ||
22 | 23 | ||
23 | ## Enable/disable display of 'number of lines changed' in log view | 24 | ## Enable/disable display of 'number of lines changed' in log view |
24 | #enable-log-linecount=0 | 25 | #enable-log-linecount=0 |
25 | 26 | ||
26 | 27 | ||
27 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum | 28 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum |
28 | ## number of commits that should be displayed | 29 | ## number of commits that should be displayed |
29 | #summary-log=0 | 30 | #summary-log=0 |
30 | 31 | ||
31 | 32 | ||
32 | ## Specify a root for virtual urls. This makes cgit generate urls like | 33 | ## Specify a root for virtual urls. This makes cgit generate urls like |
33 | ## | 34 | ## |
34 | ## http://localhost/git/repo/log/?id=master | 35 | ## http://localhost/git/repo/log/?id=master |
35 | ## | 36 | ## |
36 | ## instead of | 37 | ## instead of |
37 | ## | 38 | ## |
38 | ## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master | 39 | ## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master |
39 | ## | 40 | ## |
40 | ## For this to work with apache, rewrite rules must be added to httpd.conf, | 41 | ## For this to work with apache, rewrite rules must be added to httpd.conf, |
41 | ## possibly looking something like this: | 42 | ## possibly looking something like this: |
42 | ## | 43 | ## |
43 | ## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] | 44 | ## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] |
44 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] | 45 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] |
45 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] | 46 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] |
46 | ## | 47 | ## |
47 | ## This setting is disabled by default. | 48 | ## This setting is disabled by default. |
48 | #virtual-root=/git | 49 | #virtual-root=/git |
49 | 50 | ||
50 | 51 | ||
51 | ## Set the title printed on the root page | 52 | ## Set the title printed on the root page |
52 | #root-title=Git repository browser | 53 | #root-title=Git repository browser |
53 | 54 | ||
54 | 55 | ||
55 | ## Link to css file | 56 | ## Link to css file |
56 | #css=/cgit/cgit.css | 57 | #css=/cgit/cgit.css |
57 | 58 | ||
58 | 59 | ||
59 | ## Link to logo file | 60 | ## Link to logo file |
@@ -68,53 +69,53 @@ | |||
68 | #module-link=./?repo=%s&page=commit&id=%s | 69 | #module-link=./?repo=%s&page=commit&id=%s |
69 | 70 | ||
70 | 71 | ||
71 | ## Number of chars shown of repo description (in repolist view) | 72 | ## Number of chars shown of repo description (in repolist view) |
72 | #max-repodesc-length=60 | 73 | #max-repodesc-length=60 |
73 | 74 | ||
74 | 75 | ||
75 | ## Number of chars shown of commit subject message (in log view) | 76 | ## Number of chars shown of commit subject message (in log view) |
76 | #max-message-length=60 | 77 | #max-message-length=60 |
77 | 78 | ||
78 | 79 | ||
79 | ## Number of commits per page in log view | 80 | ## Number of commits per page in log view |
80 | #max-commit-count=50 | 81 | #max-commit-count=50 |
81 | 82 | ||
82 | 83 | ||
83 | ## Root of cached output | 84 | ## Root of cached output |
84 | #cache-root=/var/cache/cgit | 85 | #cache-root=/var/cache/cgit |
85 | 86 | ||
86 | 87 | ||
87 | ## Include another config-file | 88 | ## Include another config-file |
88 | #include=/var/cgit/repolist | 89 | #include=/var/cgit/repolist |
89 | 90 | ||
90 | ## | 91 | ## |
91 | ## Time-To-Live settings: specifies how long (in minutes) different pages | 92 | ## Time-To-Live settings: specifies how long (in minutes) different pages |
92 | ## should be cached (0 for instant expiration, -1 for immortal pages) | 93 | ## should be cached (0 for instant expiration, -1 for immortal pages) |
93 | ## | 94 | ## |
94 | 95 | ||
95 | ## ttl for root page | 96 | ## ttl for root page |
96 | #cache-root-ttl=5 | 97 | #cache-root-ttl=5 |
97 | 98 | ||
98 | ## ttl for repo summary page | 99 | ## ttl for repo summary page |
99 | #cache-repo-ttl=5 | 100 | #cache-repo-ttl=5 |
100 | 101 | ||
101 | ## ttl for other dynamic pages | 102 | ## ttl for other dynamic pages |
102 | #cache-dynamic-ttl=5 | 103 | #cache-dynamic-ttl=5 |
103 | 104 | ||
104 | ## ttl for static pages (addressed by SHA-1) | 105 | ## ttl for static pages (addressed by SHA-1) |
105 | #cache-static-ttl=-1 | 106 | #cache-static-ttl=-1 |
106 | 107 | ||
107 | 108 | ||
108 | 109 | ||
109 | ## Example repository entry. Required values are repo.url and repo.path (each | 110 | ## Example repository entry. Required values are repo.url and repo.path (each |
110 | ## repository section must start with repo.url). | 111 | ## repository section must start with repo.url). |
111 | #repo.url=cgit | 112 | #repo.url=cgit |
112 | #repo.name=cgit | 113 | #repo.name=cgit |
113 | #repo.desc=the caching cgi for git | 114 | #repo.desc=the caching cgi for git |
114 | #repo.path=/pub/git/cgit | 115 | #repo.path=/pub/git/cgit |
115 | #repo.owner=Lars Hjemli | 116 | #repo.owner=Lars Hjemli |
116 | #repo.snapshots=1 # override a sitewide snapshot-setting | 117 | #repo.snapshots=tar.bz2 # override a sitewide snapshot-setting |
117 | #repo.enable-log-filecount=0 # override the default filecount setting | 118 | #repo.enable-log-filecount=0 # override the default filecount setting |
118 | #repo.enable-log-linecount=0 # override the default linecount setting | 119 | #repo.enable-log-linecount=0 # override the default linecount setting |
119 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link | 120 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link |
120 | #repo.readme=info/web/readme # specify a file to include on summary page | 121 | #repo.readme=info/web/readme # specify a file to include on summary page |
@@ -110,139 +110,139 @@ struct repoinfo *add_repo(const char *url) | |||
110 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 110 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
111 | ret->url = xstrdup(url); | 111 | ret->url = xstrdup(url); |
112 | ret->name = ret->url; | 112 | ret->name = ret->url; |
113 | ret->path = NULL; | 113 | ret->path = NULL; |
114 | ret->desc = NULL; | 114 | ret->desc = NULL; |
115 | ret->owner = NULL; | 115 | ret->owner = NULL; |
116 | ret->group = cgit_repo_group; | 116 | ret->group = cgit_repo_group; |
117 | ret->defbranch = "master"; | 117 | ret->defbranch = "master"; |
118 | ret->snapshots = cgit_snapshots; | 118 | ret->snapshots = cgit_snapshots; |
119 | ret->enable_log_filecount = cgit_enable_log_filecount; | 119 | ret->enable_log_filecount = cgit_enable_log_filecount; |
120 | ret->enable_log_linecount = cgit_enable_log_linecount; | 120 | ret->enable_log_linecount = cgit_enable_log_linecount; |
121 | ret->module_link = cgit_module_link; | 121 | ret->module_link = cgit_module_link; |
122 | ret->readme = NULL; | 122 | ret->readme = NULL; |
123 | return ret; | 123 | return ret; |
124 | } | 124 | } |
125 | 125 | ||
126 | struct repoinfo *cgit_get_repoinfo(const char *url) | 126 | struct repoinfo *cgit_get_repoinfo(const char *url) |
127 | { | 127 | { |
128 | int i; | 128 | int i; |
129 | struct repoinfo *repo; | 129 | struct repoinfo *repo; |
130 | 130 | ||
131 | for (i=0; i<cgit_repolist.count; i++) { | 131 | for (i=0; i<cgit_repolist.count; i++) { |
132 | repo = &cgit_repolist.repos[i]; | 132 | repo = &cgit_repolist.repos[i]; |
133 | if (!strcmp(repo->url, url)) | 133 | if (!strcmp(repo->url, url)) |
134 | return repo; | 134 | return repo; |
135 | } | 135 | } |
136 | return NULL; | 136 | return NULL; |
137 | } | 137 | } |
138 | 138 | ||
139 | void cgit_global_config_cb(const char *name, const char *value) | 139 | void cgit_global_config_cb(const char *name, const char *value) |
140 | { | 140 | { |
141 | if (!strcmp(name, "root-title")) | 141 | if (!strcmp(name, "root-title")) |
142 | cgit_root_title = xstrdup(value); | 142 | cgit_root_title = xstrdup(value); |
143 | else if (!strcmp(name, "css")) | 143 | else if (!strcmp(name, "css")) |
144 | cgit_css = xstrdup(value); | 144 | cgit_css = xstrdup(value); |
145 | else if (!strcmp(name, "logo")) | 145 | else if (!strcmp(name, "logo")) |
146 | cgit_logo = xstrdup(value); | 146 | cgit_logo = xstrdup(value); |
147 | else if (!strcmp(name, "index-header")) | 147 | else if (!strcmp(name, "index-header")) |
148 | cgit_index_header = xstrdup(value); | 148 | cgit_index_header = xstrdup(value); |
149 | else if (!strcmp(name, "logo-link")) | 149 | else if (!strcmp(name, "logo-link")) |
150 | cgit_logo_link = xstrdup(value); | 150 | cgit_logo_link = xstrdup(value); |
151 | else if (!strcmp(name, "module-link")) | 151 | else if (!strcmp(name, "module-link")) |
152 | cgit_module_link = xstrdup(value); | 152 | cgit_module_link = xstrdup(value); |
153 | else if (!strcmp(name, "virtual-root")) | 153 | else if (!strcmp(name, "virtual-root")) |
154 | cgit_virtual_root = xstrdup(value); | 154 | cgit_virtual_root = xstrdup(value); |
155 | else if (!strcmp(name, "nocache")) | 155 | else if (!strcmp(name, "nocache")) |
156 | cgit_nocache = atoi(value); | 156 | cgit_nocache = atoi(value); |
157 | else if (!strcmp(name, "snapshots")) | 157 | else if (!strcmp(name, "snapshots")) |
158 | cgit_snapshots = atoi(value); | 158 | cgit_snapshots = cgit_parse_snapshots_mask(value); |
159 | else if (!strcmp(name, "enable-index-links")) | 159 | else if (!strcmp(name, "enable-index-links")) |
160 | cgit_enable_index_links = atoi(value); | 160 | cgit_enable_index_links = atoi(value); |
161 | else if (!strcmp(name, "enable-log-filecount")) | 161 | else if (!strcmp(name, "enable-log-filecount")) |
162 | cgit_enable_log_filecount = atoi(value); | 162 | cgit_enable_log_filecount = atoi(value); |
163 | else if (!strcmp(name, "enable-log-linecount")) | 163 | else if (!strcmp(name, "enable-log-linecount")) |
164 | cgit_enable_log_linecount = atoi(value); | 164 | cgit_enable_log_linecount = atoi(value); |
165 | else if (!strcmp(name, "cache-root")) | 165 | else if (!strcmp(name, "cache-root")) |
166 | cgit_cache_root = xstrdup(value); | 166 | cgit_cache_root = xstrdup(value); |
167 | else if (!strcmp(name, "cache-root-ttl")) | 167 | else if (!strcmp(name, "cache-root-ttl")) |
168 | cgit_cache_root_ttl = atoi(value); | 168 | cgit_cache_root_ttl = atoi(value); |
169 | else if (!strcmp(name, "cache-repo-ttl")) | 169 | else if (!strcmp(name, "cache-repo-ttl")) |
170 | cgit_cache_repo_ttl = atoi(value); | 170 | cgit_cache_repo_ttl = atoi(value); |
171 | else if (!strcmp(name, "cache-static-ttl")) | 171 | else if (!strcmp(name, "cache-static-ttl")) |
172 | cgit_cache_static_ttl = atoi(value); | 172 | cgit_cache_static_ttl = atoi(value); |
173 | else if (!strcmp(name, "cache-dynamic-ttl")) | 173 | else if (!strcmp(name, "cache-dynamic-ttl")) |
174 | cgit_cache_dynamic_ttl = atoi(value); | 174 | cgit_cache_dynamic_ttl = atoi(value); |
175 | else if (!strcmp(name, "max-message-length")) | 175 | else if (!strcmp(name, "max-message-length")) |
176 | cgit_max_msg_len = atoi(value); | 176 | cgit_max_msg_len = atoi(value); |
177 | else if (!strcmp(name, "max-repodesc-length")) | 177 | else if (!strcmp(name, "max-repodesc-length")) |
178 | cgit_max_repodesc_len = atoi(value); | 178 | cgit_max_repodesc_len = atoi(value); |
179 | else if (!strcmp(name, "max-commit-count")) | 179 | else if (!strcmp(name, "max-commit-count")) |
180 | cgit_max_commit_count = atoi(value); | 180 | cgit_max_commit_count = atoi(value); |
181 | else if (!strcmp(name, "summary-log")) | 181 | else if (!strcmp(name, "summary-log")) |
182 | cgit_summary_log = atoi(value); | 182 | cgit_summary_log = atoi(value); |
183 | else if (!strcmp(name, "agefile")) | 183 | else if (!strcmp(name, "agefile")) |
184 | cgit_agefile = xstrdup(value); | 184 | cgit_agefile = xstrdup(value); |
185 | else if (!strcmp(name, "repo.group")) | 185 | else if (!strcmp(name, "repo.group")) |
186 | cgit_repo_group = xstrdup(value); | 186 | cgit_repo_group = xstrdup(value); |
187 | else if (!strcmp(name, "repo.url")) | 187 | else if (!strcmp(name, "repo.url")) |
188 | cgit_repo = add_repo(value); | 188 | cgit_repo = add_repo(value); |
189 | else if (!strcmp(name, "repo.name")) | 189 | else if (!strcmp(name, "repo.name")) |
190 | cgit_repo->name = xstrdup(value); | 190 | cgit_repo->name = xstrdup(value); |
191 | else if (cgit_repo && !strcmp(name, "repo.path")) | 191 | else if (cgit_repo && !strcmp(name, "repo.path")) |
192 | cgit_repo->path = xstrdup(value); | 192 | cgit_repo->path = xstrdup(value); |
193 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 193 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
194 | cgit_repo->desc = xstrdup(value); | 194 | cgit_repo->desc = xstrdup(value); |
195 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 195 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
196 | cgit_repo->owner = xstrdup(value); | 196 | cgit_repo->owner = xstrdup(value); |
197 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | 197 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
198 | cgit_repo->defbranch = xstrdup(value); | 198 | cgit_repo->defbranch = xstrdup(value); |
199 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 199 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
200 | cgit_repo->snapshots = cgit_snapshots * atoi(value); | 200 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
201 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 201 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
202 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | 202 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
203 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 203 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
204 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | 204 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
205 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 205 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
206 | cgit_repo->module_link= xstrdup(value); | 206 | cgit_repo->module_link= xstrdup(value); |
207 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | 207 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
208 | if (*value == '/') | 208 | if (*value == '/') |
209 | cgit_repo->readme = xstrdup(value); | 209 | cgit_repo->readme = xstrdup(value); |
210 | else | 210 | else |
211 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | 211 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
212 | } else if (!strcmp(name, "include")) | 212 | } else if (!strcmp(name, "include")) |
213 | cgit_read_config(value, cgit_global_config_cb); | 213 | cgit_read_config(value, cgit_global_config_cb); |
214 | } | 214 | } |
215 | 215 | ||
216 | void cgit_querystring_cb(const char *name, const char *value) | 216 | void cgit_querystring_cb(const char *name, const char *value) |
217 | { | 217 | { |
218 | if (!strcmp(name,"r")) { | 218 | if (!strcmp(name,"r")) { |
219 | cgit_query_repo = xstrdup(value); | 219 | cgit_query_repo = xstrdup(value); |
220 | cgit_repo = cgit_get_repoinfo(value); | 220 | cgit_repo = cgit_get_repoinfo(value); |
221 | } else if (!strcmp(name, "p")) { | 221 | } else if (!strcmp(name, "p")) { |
222 | cgit_query_page = xstrdup(value); | 222 | cgit_query_page = xstrdup(value); |
223 | cgit_cmd = cgit_get_cmd_index(value); | 223 | cgit_cmd = cgit_get_cmd_index(value); |
224 | } else if (!strcmp(name, "url")) { | 224 | } else if (!strcmp(name, "url")) { |
225 | cgit_parse_url(value); | 225 | cgit_parse_url(value); |
226 | } else if (!strcmp(name, "q")) { | 226 | } else if (!strcmp(name, "q")) { |
227 | cgit_query_search = xstrdup(value); | 227 | cgit_query_search = xstrdup(value); |
228 | } else if (!strcmp(name, "h")) { | 228 | } else if (!strcmp(name, "h")) { |
229 | cgit_query_head = xstrdup(value); | 229 | cgit_query_head = xstrdup(value); |
230 | cgit_query_has_symref = 1; | 230 | cgit_query_has_symref = 1; |
231 | } else if (!strcmp(name, "id")) { | 231 | } else if (!strcmp(name, "id")) { |
232 | cgit_query_sha1 = xstrdup(value); | 232 | cgit_query_sha1 = xstrdup(value); |
233 | cgit_query_has_sha1 = 1; | 233 | cgit_query_has_sha1 = 1; |
234 | } else if (!strcmp(name, "id2")) { | 234 | } else if (!strcmp(name, "id2")) { |
235 | cgit_query_sha2 = xstrdup(value); | 235 | cgit_query_sha2 = xstrdup(value); |
236 | cgit_query_has_sha1 = 1; | 236 | cgit_query_has_sha1 = 1; |
237 | } else if (!strcmp(name, "ofs")) { | 237 | } else if (!strcmp(name, "ofs")) { |
238 | cgit_query_ofs = atoi(value); | 238 | cgit_query_ofs = atoi(value); |
239 | } else if (!strcmp(name, "path")) { | 239 | } else if (!strcmp(name, "path")) { |
240 | cgit_query_path = trim_end(value, '/'); | 240 | cgit_query_path = trim_end(value, '/'); |
241 | } else if (!strcmp(name, "name")) { | 241 | } else if (!strcmp(name, "name")) { |
242 | cgit_query_name = xstrdup(value); | 242 | cgit_query_name = xstrdup(value); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | void *cgit_free_commitinfo(struct commitinfo *info) | 246 | void *cgit_free_commitinfo(struct commitinfo *info) |
247 | { | 247 | { |
248 | free(info->author); | 248 | free(info->author); |
diff --git a/ui-commit.c b/ui-commit.c index bf5e6dc..50e9e11 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -151,75 +151,75 @@ void cgit_print_commit(char *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); | 199 | cgit_print_snapshot_links(cgit_query_repo,hex,cgit_repo->snapshots); |
200 | html("</td></tr>"); | 200 | html("</td></tr>"); |
201 | } | 201 | } |
202 | html("</table>\n"); | 202 | html("</table>\n"); |
203 | html("<div class='commit-subject'>"); | 203 | html("<div class='commit-subject'>"); |
204 | html_txt(info->subject); | 204 | html_txt(info->subject); |
205 | html("</div>"); | 205 | html("</div>"); |
206 | html("<div class='commit-msg'>"); | 206 | html("<div class='commit-msg'>"); |
207 | html_txt(info->msg); | 207 | html_txt(info->msg); |
208 | html("</div>"); | 208 | html("</div>"); |
209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
210 | html("<div class='diffstat-header'>Diffstat</div>"); | 210 | html("<div class='diffstat-header'>Diffstat</div>"); |
211 | html("<table class='diffstat'>"); | 211 | html("<table class='diffstat'>"); |
212 | max_changes = 0; | 212 | max_changes = 0; |
213 | cgit_diff_commit(commit, inspect_filepair); | 213 | cgit_diff_commit(commit, inspect_filepair); |
214 | for(i = 0; i<files; i++) | 214 | for(i = 0; i<files; i++) |
215 | print_fileinfo(&items[i]); | 215 | print_fileinfo(&items[i]); |
216 | html("</table>"); | 216 | html("</table>"); |
217 | html("<div class='diffstat-summary'>"); | 217 | html("<div class='diffstat-summary'>"); |
218 | htmlf("%d files changed, %d insertions, %d deletions (", | 218 | htmlf("%d files changed, %d insertions, %d deletions (", |
219 | files, total_adds, total_rems); | 219 | files, total_adds, total_rems); |
220 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, | 220 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, |
221 | NULL, NULL); | 221 | NULL, NULL); |
222 | html(")</div>"); | 222 | html(")</div>"); |
223 | } | 223 | } |
224 | cgit_free_commitinfo(info); | 224 | cgit_free_commitinfo(info); |
225 | } | 225 | } |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 053fd48..d6be55b 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -12,105 +12,134 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f | |||
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 | int bit; | ||
60 | }snapshot_archives[] = { | 61 | }snapshot_archives[] = { |
61 | { ".zip", "application/x-zip", write_zip_archive }, | 62 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, |
62 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive }, | 63 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, |
63 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive }, | 64 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, |
64 | { ".tar", "application/x-tar", write_tar_archive } | 65 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } |
65 | }; | 66 | }; |
66 | 67 | ||
67 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 68 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
68 | const char *prefix, const char *filename) | 69 | const char *prefix, const char *filename, |
70 | int snapshots) | ||
69 | { | 71 | { |
70 | int fnl = strlen(filename); | 72 | int fnl = strlen(filename); |
71 | int f; | 73 | int f; |
72 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 74 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
73 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 75 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
74 | int sl = strlen(sat->suffix); | 76 | int sl; |
77 | if(!(snapshots&sat->bit)) continue; | ||
78 | sl = strlen(sat->suffix); | ||
75 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | 79 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) |
76 | continue; | 80 | continue; |
77 | 81 | ||
78 | struct archiver_args args; | 82 | struct archiver_args args; |
79 | struct commit *commit; | 83 | struct commit *commit; |
80 | unsigned char sha1[20]; | 84 | unsigned char sha1[20]; |
81 | 85 | ||
82 | if(get_sha1(hex, sha1)) { | 86 | if(get_sha1(hex, sha1)) { |
83 | cgit_print_error(fmt("Bad object id: %s", hex)); | 87 | cgit_print_error(fmt("Bad object id: %s", hex)); |
84 | return; | 88 | return; |
85 | } | 89 | } |
86 | commit = lookup_commit_reference(sha1); | 90 | commit = lookup_commit_reference(sha1); |
87 | 91 | ||
88 | if(!commit) { | 92 | if(!commit) { |
89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 93 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
90 | return;; | 94 | return;; |
91 | } | 95 | } |
92 | 96 | ||
93 | memset(&args,0,sizeof(args)); | 97 | memset(&args,0,sizeof(args)); |
94 | args.base = fmt("%s/", prefix); | 98 | args.base = fmt("%s/", prefix); |
95 | args.tree = commit->tree; | 99 | args.tree = commit->tree; |
96 | 100 | ||
97 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 101 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
98 | (*sat->write_func)(&args); | 102 | (*sat->write_func)(&args); |
99 | return; | 103 | return; |
100 | } | 104 | } |
101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 105 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
102 | } | 106 | } |
103 | 107 | ||
104 | void cgit_print_snapshot_links(const char *repo,const char *hex) | 108 | void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots) |
105 | { | 109 | { |
106 | char *filename; | 110 | char *filename; |
107 | int f; | 111 | int f; |
108 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 112 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
109 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 113 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
114 | if(!(snapshots&sat->bit)) continue; | ||
110 | filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); | 115 | filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); |
111 | htmlf("<a href='%s'>%s</a><br/>", | 116 | htmlf("<a href='%s'>%s</a><br/>", |
112 | cgit_fileurl(repo,"snapshot",filename, | 117 | cgit_fileurl(repo,"snapshot",filename, |
113 | fmt("id=%s&name=%s",hex,filename)), filename); | 118 | fmt("id=%s&name=%s",hex,filename)), filename); |
114 | } | 119 | } |
115 | } | 120 | } |
121 | |||
122 | int cgit_parse_snapshots_mask(const char *str) | ||
123 | { | ||
124 | static const char *delim = " \t,:/|;"; | ||
125 | int f, tl, rv = 0; | ||
126 | /* favor legacy setting */ | ||
127 | if(atoi(str)) return 1; | ||
128 | for(;;) { | ||
129 | str += strspn(str,delim); | ||
130 | tl = strcspn(str,delim); | ||
131 | if(!tl) | ||
132 | break; | ||
133 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | ||
134 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | ||
135 | if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { | ||
136 | rv |= sat->bit; | ||
137 | break; | ||
138 | } | ||
139 | } | ||
140 | str += tl; | ||
141 | } | ||
142 | return rv; | ||
143 | } | ||
144 | |||
116 | /* vim:set sw=8: */ | 145 | /* vim:set sw=8: */ |