author | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 22:11:15 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 22:27:32 (UTC) |
commit | eb45342e735818b3c68cbab9b61b23e79ae74418 (patch) (unidiff) | |
tree | 43fed08927a2118a22cf686ee58b8d464233cd5d | |
parent | 1d4aaff696ee1b9085dda0f0f3d84d9d20d96db0 (diff) | |
download | cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.zip cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.tar.gz cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.tar.bz2 |
cgit_print_snapshot_links: use url to specify snapshot name
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 11 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-shared.c | 6 | ||||
-rw-r--r-- | ui-snapshot.c | 38 |
5 files changed, 41 insertions, 21 deletions
@@ -1,201 +1,201 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
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 cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 12 | { |
13 | if (!cgit_repo && cgit_query_repo) { | 13 | if (!cgit_repo && cgit_query_repo) { |
14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
18 | cgit_print_docend(); | 18 | cgit_print_docend(); |
19 | return 0; | 19 | return 0; |
20 | } | 20 | } |
21 | 21 | ||
22 | if (!cgit_repo) { | 22 | if (!cgit_repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
24 | item->ttl = cgit_cache_root_ttl; | 24 | item->ttl = cgit_cache_root_ttl; |
25 | return 1; | 25 | return 1; |
26 | } | 26 | } |
27 | 27 | ||
28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, |
30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(cgit_repo->url), |
31 | cache_safe_filename(cgit_querystring))); | 31 | cache_safe_filename(cgit_querystring))); |
32 | item->ttl = cgit_cache_repo_ttl; | 32 | item->ttl = cgit_cache_repo_ttl; |
33 | } else { | 33 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(cgit_repo->url), |
36 | cgit_query_page, | 36 | cgit_query_page, |
37 | cache_safe_filename(cgit_querystring))); | 37 | cache_safe_filename(cgit_querystring))); |
38 | if (cgit_query_has_symref) | 38 | if (cgit_query_has_symref) |
39 | item->ttl = cgit_cache_dynamic_ttl; | 39 | item->ttl = cgit_cache_dynamic_ttl; |
40 | else if (cgit_query_has_sha1) | 40 | else if (cgit_query_has_sha1) |
41 | item->ttl = cgit_cache_static_ttl; | 41 | item->ttl = cgit_cache_static_ttl; |
42 | else | 42 | else |
43 | item->ttl = cgit_cache_repo_ttl; | 43 | item->ttl = cgit_cache_repo_ttl; |
44 | } | 44 | } |
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
47 | 47 | ||
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_head, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_name, | 73 | cgit_query_path, |
74 | cgit_repo->snapshots ); | 74 | cgit_repo->snapshots ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (cgit_cmd == CMD_BLOB) { | 78 | if (cgit_cmd == CMD_BLOB) { |
79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | 82 | ||
83 | show_search = (cgit_cmd == CMD_LOG); | 83 | show_search = (cgit_cmd == CMD_LOG); |
84 | cgit_print_docstart(title, item); | 84 | cgit_print_docstart(title, item); |
85 | if (!cgit_cmd) { | 85 | if (!cgit_cmd) { |
86 | cgit_print_pageheader("summary", show_search); | 86 | cgit_print_pageheader("summary", show_search); |
87 | cgit_print_summary(); | 87 | cgit_print_summary(); |
88 | cgit_print_docend(); | 88 | cgit_print_docend(); |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | 91 | ||
92 | cgit_print_pageheader(cgit_query_page, show_search); | 92 | cgit_print_pageheader(cgit_query_page, show_search); |
93 | 93 | ||
94 | switch(cgit_cmd) { | 94 | switch(cgit_cmd) { |
95 | case CMD_LOG: | 95 | case CMD_LOG: |
96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
97 | cgit_max_commit_count, cgit_query_search, | 97 | cgit_max_commit_count, cgit_query_search, |
98 | cgit_query_path, 1); | 98 | cgit_query_path, 1); |
99 | break; | 99 | break; |
100 | case CMD_TREE: | 100 | case CMD_TREE: |
101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
102 | break; | 102 | break; |
103 | case CMD_COMMIT: | 103 | case CMD_COMMIT: |
104 | cgit_print_commit(cgit_query_sha1); | 104 | cgit_print_commit(cgit_query_sha1); |
105 | break; | 105 | break; |
106 | case CMD_TAG: | 106 | case CMD_TAG: |
107 | cgit_print_tag(cgit_query_sha1); | 107 | cgit_print_tag(cgit_query_sha1); |
108 | break; | 108 | break; |
109 | case CMD_DIFF: | 109 | case CMD_DIFF: |
110 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 110 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
111 | break; | 111 | break; |
112 | default: | 112 | default: |
113 | cgit_print_error("Invalid request"); | 113 | cgit_print_error("Invalid request"); |
114 | } | 114 | } |
115 | cgit_print_docend(); | 115 | cgit_print_docend(); |
116 | } | 116 | } |
117 | 117 | ||
118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
119 | { | 119 | { |
120 | static char buf[PATH_MAX]; | 120 | static char buf[PATH_MAX]; |
121 | int stdout2; | 121 | int stdout2; |
122 | 122 | ||
123 | getcwd(buf, sizeof(buf)); | 123 | getcwd(buf, sizeof(buf)); |
124 | item->st.st_mtime = time(NULL); | 124 | item->st.st_mtime = time(NULL); |
125 | 125 | ||
126 | if (use_cache) { | 126 | if (use_cache) { |
127 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 127 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
128 | "Preserving STDOUT"); | 128 | "Preserving STDOUT"); |
129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
131 | } | 131 | } |
132 | 132 | ||
133 | if (cgit_repo) | 133 | if (cgit_repo) |
134 | cgit_print_repo_page(item); | 134 | cgit_print_repo_page(item); |
135 | else | 135 | else |
136 | cgit_print_repolist(item); | 136 | cgit_print_repolist(item); |
137 | 137 | ||
138 | if (use_cache) { | 138 | if (use_cache) { |
139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
140 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 140 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
141 | "Restoring original STDOUT"); | 141 | "Restoring original STDOUT"); |
142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
143 | } | 143 | } |
144 | 144 | ||
145 | chdir(buf); | 145 | chdir(buf); |
146 | } | 146 | } |
147 | 147 | ||
148 | static void cgit_check_cache(struct cacheitem *item) | 148 | static void cgit_check_cache(struct cacheitem *item) |
149 | { | 149 | { |
150 | int i = 0; | 150 | int i = 0; |
151 | 151 | ||
152 | top: | 152 | top: |
153 | if (++i > cgit_max_lock_attempts) { | 153 | if (++i > cgit_max_lock_attempts) { |
154 | die("cgit_refresh_cache: unable to lock %s: %s", | 154 | die("cgit_refresh_cache: unable to lock %s: %s", |
155 | item->name, strerror(errno)); | 155 | item->name, strerror(errno)); |
156 | } | 156 | } |
157 | if (!cache_exist(item)) { | 157 | if (!cache_exist(item)) { |
158 | if (!cache_lock(item)) { | 158 | if (!cache_lock(item)) { |
159 | sleep(1); | 159 | sleep(1); |
160 | goto top; | 160 | goto top; |
161 | } | 161 | } |
162 | if (!cache_exist(item)) { | 162 | if (!cache_exist(item)) { |
163 | cgit_fill_cache(item, 1); | 163 | cgit_fill_cache(item, 1); |
164 | cache_unlock(item); | 164 | cache_unlock(item); |
165 | } else { | 165 | } else { |
166 | cache_cancel_lock(item); | 166 | cache_cancel_lock(item); |
167 | } | 167 | } |
168 | } else if (cache_expired(item) && cache_lock(item)) { | 168 | } else if (cache_expired(item) && cache_lock(item)) { |
169 | if (cache_expired(item)) { | 169 | if (cache_expired(item)) { |
170 | cgit_fill_cache(item, 1); | 170 | cgit_fill_cache(item, 1); |
171 | cache_unlock(item); | 171 | cache_unlock(item); |
172 | } else { | 172 | } else { |
173 | cache_cancel_lock(item); | 173 | cache_cancel_lock(item); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | static void cgit_print_cache(struct cacheitem *item) | 178 | static void cgit_print_cache(struct cacheitem *item) |
179 | { | 179 | { |
180 | static char buf[4096]; | 180 | static char buf[4096]; |
181 | ssize_t i; | 181 | ssize_t i; |
182 | 182 | ||
183 | int fd = open(item->name, O_RDONLY); | 183 | int fd = open(item->name, O_RDONLY); |
184 | if (fd<0) | 184 | if (fd<0) |
185 | die("Unable to open cached file %s", item->name); | 185 | die("Unable to open cached file %s", item->name); |
186 | 186 | ||
187 | while((i=read(fd, buf, sizeof(buf))) > 0) | 187 | while((i=read(fd, buf, sizeof(buf))) > 0) |
188 | write(STDOUT_FILENO, buf, i); | 188 | write(STDOUT_FILENO, buf, i); |
189 | 189 | ||
190 | close(fd); | 190 | close(fd); |
191 | } | 191 | } |
192 | 192 | ||
193 | static void cgit_parse_args(int argc, const char **argv) | 193 | static void cgit_parse_args(int argc, const char **argv) |
194 | { | 194 | { |
195 | int i; | 195 | int i; |
196 | 196 | ||
197 | for (i = 1; i < argc; i++) { | 197 | for (i = 1; i < argc; i++) { |
198 | if (!strncmp(argv[i], "--cache=", 8)) { | 198 | if (!strncmp(argv[i], "--cache=", 8)) { |
199 | cgit_cache_root = xstrdup(argv[i]+8); | 199 | cgit_cache_root = xstrdup(argv[i]+8); |
200 | } | 200 | } |
201 | if (!strcmp(argv[i], "--nocache")) { | 201 | if (!strcmp(argv[i], "--nocache")) { |
@@ -89,158 +89,161 @@ struct commitinfo { | |||
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, | 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_snapshot_link(char *name, char *title, char *class, | ||
218 | char *head, char *rev, char *archivename); | ||
217 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 219 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
218 | char *new_rev, char *old_rev, char *path); | 220 | char *new_rev, char *old_rev, char *path); |
219 | 221 | ||
220 | extern void cgit_object_link(struct object *obj); | 222 | extern void cgit_object_link(struct object *obj); |
221 | 223 | ||
222 | extern void cgit_print_error(char *msg); | 224 | extern void cgit_print_error(char *msg); |
223 | extern void cgit_print_date(time_t secs, char *format); | 225 | extern void cgit_print_date(time_t secs, char *format); |
224 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 226 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
225 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 227 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
226 | extern void cgit_print_docend(); | 228 | extern void cgit_print_docend(); |
227 | extern void cgit_print_pageheader(char *title, int show_search); | 229 | extern void cgit_print_pageheader(char *title, int show_search); |
228 | extern void cgit_print_snapshot_start(const char *mimetype, | 230 | extern void cgit_print_snapshot_start(const char *mimetype, |
229 | const char *filename, | 231 | const char *filename, |
230 | struct cacheitem *item); | 232 | struct cacheitem *item); |
231 | 233 | ||
232 | extern void cgit_print_repolist(struct cacheitem *item); | 234 | extern void cgit_print_repolist(struct cacheitem *item); |
233 | extern void cgit_print_summary(); | 235 | extern void cgit_print_summary(); |
234 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 236 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
235 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 237 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
236 | extern void cgit_print_tree(const char *rev, char *path); | 238 | extern void cgit_print_tree(const char *rev, char *path); |
237 | extern void cgit_print_commit(char *hex); | 239 | extern void cgit_print_commit(char *hex); |
238 | extern void cgit_print_tag(char *revname); | 240 | extern void cgit_print_tag(char *revname); |
239 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 241 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
240 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 242 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
241 | const char *prefix, const char *filename, | 243 | const char *hex, const char *prefix, |
242 | int snapshot); | 244 | const char *filename, int snapshot); |
243 | extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots); | 245 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
246 | const char *hex, int snapshots); | ||
244 | extern int cgit_parse_snapshots_mask(const char *str); | 247 | extern int cgit_parse_snapshots_mask(const char *str); |
245 | 248 | ||
246 | #endif /* CGIT_H */ | 249 | #endif /* CGIT_H */ |
diff --git a/ui-commit.c b/ui-commit.c index 50e9e11..90e09ed 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -71,155 +71,156 @@ void print_fileinfo(struct fileinfo *info) | |||
71 | !is_null_sha1(info->old_sha1) && | 71 | !is_null_sha1(info->old_sha1) && |
72 | !is_null_sha1(info->new_sha1)) { | 72 | !is_null_sha1(info->new_sha1)) { |
73 | html("<span class='modechange'>["); | 73 | html("<span class='modechange'>["); |
74 | html_filemode(info->old_mode); | 74 | html_filemode(info->old_mode); |
75 | html("]</span>"); | 75 | html("]</span>"); |
76 | } | 76 | } |
77 | htmlf("</td><td class='%s'>", class); | 77 | htmlf("</td><td class='%s'>", class); |
78 | cgit_tree_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, | 78 | cgit_tree_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, |
79 | info->new_path); | 79 | info->new_path); |
80 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 80 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
81 | htmlf(" (%s from %s)", | 81 | htmlf(" (%s from %s)", |
82 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", | 82 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
83 | info->old_path); | 83 | info->old_path); |
84 | html("</td><td class='right'>"); | 84 | html("</td><td class='right'>"); |
85 | htmlf("%d", info->added + info->removed); | 85 | htmlf("%d", info->added + info->removed); |
86 | html("</td><td class='graph'>"); | 86 | html("</td><td class='graph'>"); |
87 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 87 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
88 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 88 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
89 | info->added * 100.0 / max_changes); | 89 | info->added * 100.0 / max_changes); |
90 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 90 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
91 | info->removed * 100.0 / max_changes); | 91 | info->removed * 100.0 / max_changes); |
92 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 92 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
93 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 93 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
94 | html("</tr></table></td></tr>\n"); | 94 | html("</tr></table></td></tr>\n"); |
95 | } | 95 | } |
96 | 96 | ||
97 | void cgit_count_diff_lines(char *line, int len) | 97 | void cgit_count_diff_lines(char *line, int len) |
98 | { | 98 | { |
99 | if (line && (len > 0)) { | 99 | if (line && (len > 0)) { |
100 | if (line[0] == '+') | 100 | if (line[0] == '+') |
101 | lines_added++; | 101 | lines_added++; |
102 | else if (line[0] == '-') | 102 | else if (line[0] == '-') |
103 | lines_removed++; | 103 | lines_removed++; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | void inspect_filepair(struct diff_filepair *pair) | 107 | void inspect_filepair(struct diff_filepair *pair) |
108 | { | 108 | { |
109 | files++; | 109 | files++; |
110 | lines_added = 0; | 110 | lines_added = 0; |
111 | lines_removed = 0; | 111 | lines_removed = 0; |
112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
113 | if (files >= slots) { | 113 | if (files >= slots) { |
114 | if (slots == 0) | 114 | if (slots == 0) |
115 | slots = 4; | 115 | slots = 4; |
116 | else | 116 | else |
117 | slots = slots * 2; | 117 | slots = slots * 2; |
118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
119 | } | 119 | } |
120 | items[files-1].status = pair->status; | 120 | items[files-1].status = pair->status; |
121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
123 | items[files-1].old_mode = pair->one->mode; | 123 | items[files-1].old_mode = pair->one->mode; |
124 | items[files-1].new_mode = pair->two->mode; | 124 | items[files-1].new_mode = pair->two->mode; |
125 | items[files-1].old_path = xstrdup(pair->one->path); | 125 | items[files-1].old_path = xstrdup(pair->one->path); |
126 | items[files-1].new_path = xstrdup(pair->two->path); | 126 | items[files-1].new_path = xstrdup(pair->two->path); |
127 | items[files-1].added = lines_added; | 127 | items[files-1].added = lines_added; |
128 | items[files-1].removed = lines_removed; | 128 | items[files-1].removed = lines_removed; |
129 | if (lines_added + lines_removed > max_changes) | 129 | if (lines_added + lines_removed > max_changes) |
130 | max_changes = lines_added + lines_removed; | 130 | max_changes = lines_added + lines_removed; |
131 | total_adds += lines_added; | 131 | total_adds += lines_added; |
132 | total_rems += lines_removed; | 132 | total_rems += lines_removed; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void cgit_print_commit(char *hex) | 136 | void cgit_print_commit(char *hex) |
137 | { | 137 | { |
138 | struct commit *commit, *parent; | 138 | struct commit *commit, *parent; |
139 | struct commitinfo *info; | 139 | struct commitinfo *info; |
140 | struct commit_list *p; | 140 | struct commit_list *p; |
141 | unsigned char sha1[20]; | 141 | unsigned char sha1[20]; |
142 | char *tmp; | 142 | char *tmp; |
143 | int i; | 143 | int i; |
144 | 144 | ||
145 | if (!hex) | 145 | if (!hex) |
146 | hex = cgit_query_head; | 146 | hex = cgit_query_head; |
147 | curr_rev = hex; | 147 | curr_rev = hex; |
148 | 148 | ||
149 | if (get_sha1(hex, sha1)) { | 149 | if (get_sha1(hex, sha1)) { |
150 | cgit_print_error(fmt("Bad object id: %s", hex)); | 150 | cgit_print_error(fmt("Bad object id: %s", hex)); |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | commit = lookup_commit_reference(sha1); | 153 | commit = lookup_commit_reference(sha1); |
154 | if (!commit) { | 154 | if (!commit) { |
155 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 155 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
156 | return; | 156 | return; |
157 | } | 157 | } |
158 | info = cgit_parse_commit(commit); | 158 | info = cgit_parse_commit(commit); |
159 | 159 | ||
160 | html("<table class='commit-info'>\n"); | 160 | html("<table class='commit-info'>\n"); |
161 | html("<tr><th>author</th><td>"); | 161 | html("<tr><th>author</th><td>"); |
162 | html_txt(info->author); | 162 | html_txt(info->author); |
163 | html(" "); | 163 | html(" "); |
164 | html_txt(info->author_email); | 164 | html_txt(info->author_email); |
165 | html("</td><td class='right'>"); | 165 | html("</td><td class='right'>"); |
166 | cgit_print_date(info->author_date, FMT_LONGDATE); | 166 | cgit_print_date(info->author_date, FMT_LONGDATE); |
167 | html("</td></tr>\n"); | 167 | html("</td></tr>\n"); |
168 | html("<tr><th>committer</th><td>"); | 168 | html("<tr><th>committer</th><td>"); |
169 | html_txt(info->committer); | 169 | html_txt(info->committer); |
170 | html(" "); | 170 | html(" "); |
171 | html_txt(info->committer_email); | 171 | html_txt(info->committer_email); |
172 | html("</td><td class='right'>"); | 172 | html("</td><td class='right'>"); |
173 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 173 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
174 | html("</td></tr>\n"); | 174 | html("</td></tr>\n"); |
175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
176 | tmp = xstrdup(hex); | 176 | tmp = xstrdup(hex); |
177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
178 | cgit_query_head, tmp, NULL); | 178 | cgit_query_head, tmp, NULL); |
179 | html("</td></tr>\n"); | 179 | html("</td></tr>\n"); |
180 | for (p = commit->parents; p ; p = p->next) { | 180 | for (p = commit->parents; p ; p = p->next) { |
181 | parent = lookup_commit_reference(p->item->object.sha1); | 181 | parent = lookup_commit_reference(p->item->object.sha1); |
182 | if (!parent) { | 182 | if (!parent) { |
183 | html("<tr><td colspan='3'>"); | 183 | html("<tr><td colspan='3'>"); |
184 | cgit_print_error("Error reading parent commit"); | 184 | cgit_print_error("Error reading parent commit"); |
185 | html("</td></tr>"); | 185 | html("</td></tr>"); |
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | html("<tr><th>parent</th>" | 188 | html("<tr><th>parent</th>" |
189 | "<td colspan='2' class='sha1'>"); | 189 | "<td colspan='2' class='sha1'>"); |
190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); | 191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); |
192 | html(" ("); | 192 | html(" ("); |
193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, | 193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, |
194 | sha1_to_hex(p->item->object.sha1), NULL); | 194 | sha1_to_hex(p->item->object.sha1), NULL); |
195 | html(")</td></tr>"); | 195 | html(")</td></tr>"); |
196 | } | 196 | } |
197 | if (cgit_repo->snapshots) { | 197 | if (cgit_repo->snapshots) { |
198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
199 | cgit_print_snapshot_links(cgit_query_repo,hex,cgit_repo->snapshots); | 199 | cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, |
200 | hex, cgit_repo->snapshots); | ||
200 | html("</td></tr>"); | 201 | html("</td></tr>"); |
201 | } | 202 | } |
202 | html("</table>\n"); | 203 | html("</table>\n"); |
203 | html("<div class='commit-subject'>"); | 204 | html("<div class='commit-subject'>"); |
204 | html_txt(info->subject); | 205 | html_txt(info->subject); |
205 | html("</div>"); | 206 | html("</div>"); |
206 | html("<div class='commit-msg'>"); | 207 | html("<div class='commit-msg'>"); |
207 | html_txt(info->msg); | 208 | html_txt(info->msg); |
208 | html("</div>"); | 209 | html("</div>"); |
209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 210 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
210 | html("<div class='diffstat-header'>Diffstat</div>"); | 211 | html("<div class='diffstat-header'>Diffstat</div>"); |
211 | html("<table class='diffstat'>"); | 212 | html("<table class='diffstat'>"); |
212 | max_changes = 0; | 213 | max_changes = 0; |
213 | cgit_diff_commit(commit, inspect_filepair); | 214 | cgit_diff_commit(commit, inspect_filepair); |
214 | for(i = 0; i<files; i++) | 215 | for(i = 0; i<files; i++) |
215 | print_fileinfo(&items[i]); | 216 | print_fileinfo(&items[i]); |
216 | html("</table>"); | 217 | html("</table>"); |
217 | html("<div class='diffstat-summary'>"); | 218 | html("<div class='diffstat-summary'>"); |
218 | htmlf("%d files changed, %d insertions, %d deletions (", | 219 | htmlf("%d files changed, %d insertions, %d deletions (", |
219 | files, total_adds, total_rems); | 220 | files, total_adds, total_rems); |
220 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, | 221 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, |
221 | NULL, NULL); | 222 | NULL, NULL); |
222 | html(")</div>"); | 223 | html(")</div>"); |
223 | } | 224 | } |
224 | cgit_free_commitinfo(info); | 225 | cgit_free_commitinfo(info); |
225 | } | 226 | } |
diff --git a/ui-shared.c b/ui-shared.c index ca2ee82..5c5bcf3 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -102,256 +102,262 @@ const char *cgit_repobasename(const char *reponame) | |||
102 | /* find last slash in the remaining string */ | 102 | /* find last slash in the remaining string */ |
103 | rv = strrchr(rvbuf,'/'); | 103 | rv = strrchr(rvbuf,'/'); |
104 | if(rv) | 104 | if(rv) |
105 | return ++rv; | 105 | return ++rv; |
106 | return rvbuf; | 106 | return rvbuf; |
107 | } | 107 | } |
108 | 108 | ||
109 | char *cgit_currurl() | 109 | char *cgit_currurl() |
110 | { | 110 | { |
111 | if (!cgit_virtual_root) | 111 | if (!cgit_virtual_root) |
112 | return cgit_script_name; | 112 | return cgit_script_name; |
113 | else if (cgit_query_page) | 113 | else if (cgit_query_page) |
114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
115 | else if (cgit_query_repo) | 115 | else if (cgit_query_repo) |
116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
117 | else | 117 | else |
118 | return fmt("%s/", cgit_virtual_root); | 118 | return fmt("%s/", cgit_virtual_root); |
119 | } | 119 | } |
120 | 120 | ||
121 | static char *repolink(char *title, char *class, char *page, char *head, | 121 | static char *repolink(char *title, char *class, char *page, char *head, |
122 | char *path) | 122 | char *path) |
123 | { | 123 | { |
124 | char *delim = "?"; | 124 | char *delim = "?"; |
125 | 125 | ||
126 | html("<a"); | 126 | html("<a"); |
127 | if (title) { | 127 | if (title) { |
128 | html(" title='"); | 128 | html(" title='"); |
129 | html_attr(title); | 129 | html_attr(title); |
130 | html("'"); | 130 | html("'"); |
131 | } | 131 | } |
132 | if (class) { | 132 | if (class) { |
133 | html(" class='"); | 133 | html(" class='"); |
134 | html_attr(class); | 134 | html_attr(class); |
135 | html("'"); | 135 | html("'"); |
136 | } | 136 | } |
137 | html(" href='"); | 137 | html(" href='"); |
138 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
139 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
141 | html("/"); | 141 | html("/"); |
142 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | if (page) { | 145 | if (page) { |
146 | html(page); | 146 | html(page); |
147 | html("/"); | 147 | html("/"); |
148 | if (path) | 148 | if (path) |
149 | html_attr(path); | 149 | html_attr(path); |
150 | } | 150 | } |
151 | } else { | 151 | } else { |
152 | html(cgit_script_name); | 152 | html(cgit_script_name); |
153 | html("?url="); | 153 | html("?url="); |
154 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
156 | html("/"); | 156 | html("/"); |
157 | if (page) { | 157 | if (page) { |
158 | html(page); | 158 | html(page); |
159 | html("/"); | 159 | html("/"); |
160 | if (path) | 160 | if (path) |
161 | html_attr(path); | 161 | html_attr(path); |
162 | } | 162 | } |
163 | delim = "&"; | 163 | delim = "&"; |
164 | } | 164 | } |
165 | if (head && strcmp(head, cgit_repo->defbranch)) { | 165 | if (head && strcmp(head, cgit_repo->defbranch)) { |
166 | html(delim); | 166 | html(delim); |
167 | html("h="); | 167 | html("h="); |
168 | html_attr(head); | 168 | html_attr(head); |
169 | delim = "&"; | 169 | delim = "&"; |
170 | } | 170 | } |
171 | return fmt("%s", delim); | 171 | return fmt("%s", delim); |
172 | } | 172 | } |
173 | 173 | ||
174 | static void reporevlink(char *page, char *name, char *title, char *class, | 174 | static void reporevlink(char *page, char *name, char *title, char *class, |
175 | char *head, char *rev, char *path) | 175 | char *head, char *rev, char *path) |
176 | { | 176 | { |
177 | char *delim; | 177 | char *delim; |
178 | 178 | ||
179 | delim = repolink(title, class, page, head, path); | 179 | delim = repolink(title, class, page, head, path); |
180 | if (rev && strcmp(rev, cgit_query_head)) { | 180 | if (rev && strcmp(rev, cgit_query_head)) { |
181 | html(delim); | 181 | html(delim); |
182 | html("id="); | 182 | html("id="); |
183 | html_attr(rev); | 183 | html_attr(rev); |
184 | } | 184 | } |
185 | html("'>"); | 185 | html("'>"); |
186 | html_txt(name); | 186 | html_txt(name); |
187 | html("</a>"); | 187 | html("</a>"); |
188 | } | 188 | } |
189 | 189 | ||
190 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 190 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
191 | char *rev, char *path) | 191 | char *rev, char *path) |
192 | { | 192 | { |
193 | reporevlink("tree", name, title, class, head, rev, path); | 193 | reporevlink("tree", name, title, class, head, rev, path); |
194 | } | 194 | } |
195 | 195 | ||
196 | void cgit_log_link(char *name, char *title, char *class, char *head, | 196 | void cgit_log_link(char *name, char *title, char *class, char *head, |
197 | char *rev, char *path, int ofs) | 197 | char *rev, char *path, int ofs) |
198 | { | 198 | { |
199 | char *delim; | 199 | char *delim; |
200 | 200 | ||
201 | delim = repolink(title, class, "log", head, path); | 201 | delim = repolink(title, class, "log", head, path); |
202 | if (rev && strcmp(rev, cgit_query_head)) { | 202 | if (rev && strcmp(rev, cgit_query_head)) { |
203 | html(delim); | 203 | html(delim); |
204 | html("id="); | 204 | html("id="); |
205 | html_attr(rev); | 205 | html_attr(rev); |
206 | delim = "&"; | 206 | delim = "&"; |
207 | } | 207 | } |
208 | if (ofs > 0) { | 208 | if (ofs > 0) { |
209 | html(delim); | 209 | html(delim); |
210 | html("ofs="); | 210 | html("ofs="); |
211 | htmlf("%d", ofs); | 211 | htmlf("%d", ofs); |
212 | } | 212 | } |
213 | html("'>"); | 213 | html("'>"); |
214 | html_txt(name); | 214 | html_txt(name); |
215 | html("</a>"); | 215 | html("</a>"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 218 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
219 | char *rev) | 219 | char *rev) |
220 | { | 220 | { |
221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
222 | name[cgit_max_msg_len] = '\0'; | 222 | name[cgit_max_msg_len] = '\0'; |
223 | name[cgit_max_msg_len - 1] = '.'; | 223 | name[cgit_max_msg_len - 1] = '.'; |
224 | name[cgit_max_msg_len - 2] = '.'; | 224 | name[cgit_max_msg_len - 2] = '.'; |
225 | name[cgit_max_msg_len - 3] = '.'; | 225 | name[cgit_max_msg_len - 3] = '.'; |
226 | } | 226 | } |
227 | reporevlink("commit", name, title, class, head, rev, NULL); | 227 | reporevlink("commit", name, title, class, head, rev, NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | ||
231 | char *rev, char *archivename) | ||
232 | { | ||
233 | reporevlink("snapshot", name, title, class, head, rev, archivename); | ||
234 | } | ||
235 | |||
230 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 236 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
231 | char *new_rev, char *old_rev, char *path) | 237 | char *new_rev, char *old_rev, char *path) |
232 | { | 238 | { |
233 | char *delim; | 239 | char *delim; |
234 | 240 | ||
235 | delim = repolink(title, class, "diff", head, path); | 241 | delim = repolink(title, class, "diff", head, path); |
236 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 242 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
237 | html(delim); | 243 | html(delim); |
238 | html("id="); | 244 | html("id="); |
239 | html_attr(new_rev); | 245 | html_attr(new_rev); |
240 | delim = "&"; | 246 | delim = "&"; |
241 | } | 247 | } |
242 | if (old_rev) { | 248 | if (old_rev) { |
243 | html(delim); | 249 | html(delim); |
244 | html("id2="); | 250 | html("id2="); |
245 | html_attr(old_rev); | 251 | html_attr(old_rev); |
246 | } | 252 | } |
247 | html("'>"); | 253 | html("'>"); |
248 | html_txt(name); | 254 | html_txt(name); |
249 | html("</a>"); | 255 | html("</a>"); |
250 | } | 256 | } |
251 | 257 | ||
252 | void cgit_object_link(struct object *obj) | 258 | void cgit_object_link(struct object *obj) |
253 | { | 259 | { |
254 | char *page, *arg, *url; | 260 | char *page, *arg, *url; |
255 | 261 | ||
256 | if (obj->type == OBJ_COMMIT) { | 262 | if (obj->type == OBJ_COMMIT) { |
257 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 263 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
258 | cgit_query_head, sha1_to_hex(obj->sha1)); | 264 | cgit_query_head, sha1_to_hex(obj->sha1)); |
259 | return; | 265 | return; |
260 | } else if (obj->type == OBJ_TREE) { | 266 | } else if (obj->type == OBJ_TREE) { |
261 | page = "tree"; | 267 | page = "tree"; |
262 | arg = "id"; | 268 | arg = "id"; |
263 | } else { | 269 | } else { |
264 | page = "blob"; | 270 | page = "blob"; |
265 | arg = "id"; | 271 | arg = "id"; |
266 | } | 272 | } |
267 | 273 | ||
268 | url = cgit_pageurl(cgit_query_repo, page, | 274 | url = cgit_pageurl(cgit_query_repo, page, |
269 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 275 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
270 | html_link_open(url, NULL, NULL); | 276 | html_link_open(url, NULL, NULL); |
271 | htmlf("%s %s", typename(obj->type), | 277 | htmlf("%s %s", typename(obj->type), |
272 | sha1_to_hex(obj->sha1)); | 278 | sha1_to_hex(obj->sha1)); |
273 | html_link_close(); | 279 | html_link_close(); |
274 | } | 280 | } |
275 | 281 | ||
276 | void cgit_print_date(time_t secs, char *format) | 282 | void cgit_print_date(time_t secs, char *format) |
277 | { | 283 | { |
278 | char buf[64]; | 284 | char buf[64]; |
279 | struct tm *time; | 285 | struct tm *time; |
280 | 286 | ||
281 | time = gmtime(&secs); | 287 | time = gmtime(&secs); |
282 | strftime(buf, sizeof(buf)-1, format, time); | 288 | strftime(buf, sizeof(buf)-1, format, time); |
283 | html_txt(buf); | 289 | html_txt(buf); |
284 | } | 290 | } |
285 | 291 | ||
286 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 292 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
287 | { | 293 | { |
288 | time_t now, secs; | 294 | time_t now, secs; |
289 | 295 | ||
290 | time(&now); | 296 | time(&now); |
291 | secs = now - t; | 297 | secs = now - t; |
292 | 298 | ||
293 | if (secs > max_relative && max_relative >= 0) { | 299 | if (secs > max_relative && max_relative >= 0) { |
294 | cgit_print_date(t, format); | 300 | cgit_print_date(t, format); |
295 | return; | 301 | return; |
296 | } | 302 | } |
297 | 303 | ||
298 | if (secs < TM_HOUR * 2) { | 304 | if (secs < TM_HOUR * 2) { |
299 | htmlf("<span class='age-mins'>%.0f min.</span>", | 305 | htmlf("<span class='age-mins'>%.0f min.</span>", |
300 | secs * 1.0 / TM_MIN); | 306 | secs * 1.0 / TM_MIN); |
301 | return; | 307 | return; |
302 | } | 308 | } |
303 | if (secs < TM_DAY * 2) { | 309 | if (secs < TM_DAY * 2) { |
304 | htmlf("<span class='age-hours'>%.0f hours</span>", | 310 | htmlf("<span class='age-hours'>%.0f hours</span>", |
305 | secs * 1.0 / TM_HOUR); | 311 | secs * 1.0 / TM_HOUR); |
306 | return; | 312 | return; |
307 | } | 313 | } |
308 | if (secs < TM_WEEK * 2) { | 314 | if (secs < TM_WEEK * 2) { |
309 | htmlf("<span class='age-days'>%.0f days</span>", | 315 | htmlf("<span class='age-days'>%.0f days</span>", |
310 | secs * 1.0 / TM_DAY); | 316 | secs * 1.0 / TM_DAY); |
311 | return; | 317 | return; |
312 | } | 318 | } |
313 | if (secs < TM_MONTH * 2) { | 319 | if (secs < TM_MONTH * 2) { |
314 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 320 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
315 | secs * 1.0 / TM_WEEK); | 321 | secs * 1.0 / TM_WEEK); |
316 | return; | 322 | return; |
317 | } | 323 | } |
318 | if (secs < TM_YEAR * 2) { | 324 | if (secs < TM_YEAR * 2) { |
319 | htmlf("<span class='age-months'>%.0f months</span>", | 325 | htmlf("<span class='age-months'>%.0f months</span>", |
320 | secs * 1.0 / TM_MONTH); | 326 | secs * 1.0 / TM_MONTH); |
321 | return; | 327 | return; |
322 | } | 328 | } |
323 | htmlf("<span class='age-years'>%.0f years</span>", | 329 | htmlf("<span class='age-years'>%.0f years</span>", |
324 | secs * 1.0 / TM_YEAR); | 330 | secs * 1.0 / TM_YEAR); |
325 | } | 331 | } |
326 | 332 | ||
327 | void cgit_print_docstart(char *title, struct cacheitem *item) | 333 | void cgit_print_docstart(char *title, struct cacheitem *item) |
328 | { | 334 | { |
329 | html("Content-Type: text/html; charset=utf-8\n"); | 335 | html("Content-Type: text/html; charset=utf-8\n"); |
330 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 336 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
331 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 337 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
332 | ttl_seconds(item->ttl))); | 338 | ttl_seconds(item->ttl))); |
333 | html("\n"); | 339 | html("\n"); |
334 | html(cgit_doctype); | 340 | html(cgit_doctype); |
335 | html("<html>\n"); | 341 | html("<html>\n"); |
336 | html("<head>\n"); | 342 | html("<head>\n"); |
337 | html("<title>"); | 343 | html("<title>"); |
338 | html_txt(title); | 344 | html_txt(title); |
339 | html("</title>\n"); | 345 | html("</title>\n"); |
340 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 346 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
341 | html("<link rel='stylesheet' type='text/css' href='"); | 347 | html("<link rel='stylesheet' type='text/css' href='"); |
342 | html_attr(cgit_css); | 348 | html_attr(cgit_css); |
343 | html("'/>\n"); | 349 | html("'/>\n"); |
344 | html("</head>\n"); | 350 | html("</head>\n"); |
345 | html("<body>\n"); | 351 | html("<body>\n"); |
346 | } | 352 | } |
347 | 353 | ||
348 | void cgit_print_docend() | 354 | void cgit_print_docend() |
349 | { | 355 | { |
350 | html("</td></tr></table>"); | 356 | html("</td></tr></table>"); |
351 | html("</body>\n</html>\n"); | 357 | html("</body>\n</html>\n"); |
352 | } | 358 | } |
353 | 359 | ||
354 | void cgit_print_pageheader(char *title, int show_search) | 360 | void cgit_print_pageheader(char *title, int show_search) |
355 | { | 361 | { |
356 | html("<table id='layout'>"); | 362 | html("<table id='layout'>"); |
357 | html("<tr><td id='header'><a href='"); | 363 | html("<tr><td id='header'><a href='"); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index d6be55b..f9879ed 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -1,145 +1,155 @@ | |||
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 | int bit; | 60 | int bit; |
61 | }snapshot_archives[] = { | 61 | }snapshot_archives[] = { |
62 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, | 62 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, |
63 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, | 63 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, |
64 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, | 64 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, |
65 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } | 65 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } |
66 | }; | 66 | }; |
67 | 67 | ||
68 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 68 | void cgit_print_snapshot(struct cacheitem *item, const char *head, |
69 | const char *prefix, const char *filename, | 69 | const char *hex, const char *prefix, |
70 | int snapshots) | 70 | const char *filename, int snapshots) |
71 | { | 71 | { |
72 | int fnl = strlen(filename); | 72 | int fnl = strlen(filename); |
73 | int f; | 73 | int f, n; |
74 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 74 | |
75 | n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); | ||
76 | for(f=0; f<n; f++) { | ||
75 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 77 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
76 | int sl; | 78 | int sl; |
77 | if(!(snapshots&sat->bit)) continue; | 79 | if(!(snapshots & sat->bit)) |
80 | continue; | ||
78 | sl = strlen(sat->suffix); | 81 | sl = strlen(sat->suffix); |
79 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | 82 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) |
80 | continue; | 83 | continue; |
81 | 84 | ||
82 | struct archiver_args args; | 85 | struct archiver_args args; |
83 | struct commit *commit; | 86 | struct commit *commit; |
84 | unsigned char sha1[20]; | 87 | unsigned char sha1[20]; |
85 | 88 | ||
89 | if (!hex) | ||
90 | hex = head; | ||
86 | if(get_sha1(hex, sha1)) { | 91 | if(get_sha1(hex, sha1)) { |
87 | cgit_print_error(fmt("Bad object id: %s", hex)); | 92 | cgit_print_error(fmt("Bad object id: %s", hex)); |
88 | return; | 93 | return; |
89 | } | 94 | } |
90 | commit = lookup_commit_reference(sha1); | 95 | commit = lookup_commit_reference(sha1); |
91 | 96 | ||
92 | if(!commit) { | 97 | if(!commit) { |
93 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 98 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
94 | return;; | 99 | return;; |
95 | } | 100 | } |
96 | 101 | ||
97 | memset(&args,0,sizeof(args)); | 102 | memset(&args,0,sizeof(args)); |
98 | args.base = fmt("%s/", prefix); | 103 | args.base = fmt("%s/", prefix); |
99 | args.tree = commit->tree; | 104 | args.tree = commit->tree; |
100 | 105 | ||
101 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 106 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
102 | (*sat->write_func)(&args); | 107 | (*sat->write_func)(&args); |
103 | return; | 108 | return; |
104 | } | 109 | } |
105 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 110 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
106 | } | 111 | } |
107 | 112 | ||
108 | void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots) | 113 | void cgit_print_snapshot_links(const char *repo, const char *head, |
114 | const char *hex, int snapshots) | ||
109 | { | 115 | { |
110 | char *filename; | 116 | char *filename; |
111 | int f; | 117 | int f, n; |
112 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 118 | |
119 | n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); | ||
120 | for(f=0; f<n ;f++) { | ||
113 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 121 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
114 | if(!(snapshots&sat->bit)) continue; | 122 | if(!(snapshots & sat->bit)) |
115 | filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); | 123 | continue; |
116 | htmlf("<a href='%s'>%s</a><br/>", | 124 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
117 | cgit_fileurl(repo,"snapshot",filename, | 125 | sat->suffix); |
118 | fmt("id=%s&name=%s",hex,filename)), filename); | 126 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
127 | (char *)hex, filename); | ||
128 | html("<br/>"); | ||
119 | } | 129 | } |
120 | } | 130 | } |
121 | 131 | ||
122 | int cgit_parse_snapshots_mask(const char *str) | 132 | int cgit_parse_snapshots_mask(const char *str) |
123 | { | 133 | { |
124 | static const char *delim = " \t,:/|;"; | 134 | static const char *delim = " \t,:/|;"; |
125 | int f, tl, rv = 0; | 135 | int f, tl, rv = 0; |
126 | /* favor legacy setting */ | 136 | /* favor legacy setting */ |
127 | if(atoi(str)) return 1; | 137 | if(atoi(str)) return 1; |
128 | for(;;) { | 138 | for(;;) { |
129 | str += strspn(str,delim); | 139 | str += strspn(str,delim); |
130 | tl = strcspn(str,delim); | 140 | tl = strcspn(str,delim); |
131 | if(!tl) | 141 | if(!tl) |
132 | break; | 142 | break; |
133 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 143 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
134 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 144 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
135 | if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { | 145 | if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { |
136 | rv |= sat->bit; | 146 | rv |= sat->bit; |
137 | break; | 147 | break; |
138 | } | 148 | } |
139 | } | 149 | } |
140 | str += tl; | 150 | str += tl; |
141 | } | 151 | } |
142 | return rv; | 152 | return rv; |
143 | } | 153 | } |
144 | 154 | ||
145 | /* vim:set sw=8: */ | 155 | /* vim:set sw=8: */ |