summaryrefslogtreecommitdiffabout
path: root/cgit.c
authorLars Hjemli <hjemli@gmail.com>2008-03-24 00:00:36 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-03-24 00:01:28 (UTC)
commitb608e88adb6f77328288afb6dd0eddf674fc9b5b (patch) (unidiff)
treee194a466ba00d67bc037c76329ca050e84e1223b /cgit.c
parentf3c1a187fe2bc33f8423cd535d5045899699995b (diff)
downloadcgit-b608e88adb6f77328288afb6dd0eddf674fc9b5b.zip
cgit-b608e88adb6f77328288afb6dd0eddf674fc9b5b.tar.gz
cgit-b608e88adb6f77328288afb6dd0eddf674fc9b5b.tar.bz2
Remove obsolete cacheitem parameter to ui-functions
This parameter hasn't been used for a very long time... Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/cgit.c b/cgit.c
index d0f6905..a83f0be 100644
--- a/cgit.c
+++ b/cgit.c
@@ -36,228 +36,228 @@ static int cgit_prepare_cache(struct cacheitem *item)
36 } else { 36 } else {
37 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, 37 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root,
38 cache_safe_filename(ctx.repo->url), 38 cache_safe_filename(ctx.repo->url),
39 ctx.qry.page, 39 ctx.qry.page,
40 cache_safe_filename(ctx.qry.raw))); 40 cache_safe_filename(ctx.qry.raw)));
41 if (ctx.qry.has_symref) 41 if (ctx.qry.has_symref)
42 item->ttl = ctx.cfg.cache_dynamic_ttl; 42 item->ttl = ctx.cfg.cache_dynamic_ttl;
43 else if (ctx.qry.has_sha1) 43 else if (ctx.qry.has_sha1)
44 item->ttl = ctx.cfg.cache_static_ttl; 44 item->ttl = ctx.cfg.cache_static_ttl;
45 else 45 else
46 item->ttl = ctx.cfg.cache_repo_ttl; 46 item->ttl = ctx.cfg.cache_repo_ttl;
47 } 47 }
48 return 1; 48 return 1;
49} 49}
50 50
51struct refmatch { 51struct refmatch {
52 char *req_ref; 52 char *req_ref;
53 char *first_ref; 53 char *first_ref;
54 int match; 54 int match;
55}; 55};
56 56
57int find_current_ref(const char *refname, const unsigned char *sha1, 57int find_current_ref(const char *refname, const unsigned char *sha1,
58 int flags, void *cb_data) 58 int flags, void *cb_data)
59{ 59{
60 struct refmatch *info; 60 struct refmatch *info;
61 61
62 info = (struct refmatch *)cb_data; 62 info = (struct refmatch *)cb_data;
63 if (!strcmp(refname, info->req_ref)) 63 if (!strcmp(refname, info->req_ref))
64 info->match = 1; 64 info->match = 1;
65 if (!info->first_ref) 65 if (!info->first_ref)
66 info->first_ref = xstrdup(refname); 66 info->first_ref = xstrdup(refname);
67 return info->match; 67 return info->match;
68} 68}
69 69
70char *find_default_branch(struct cgit_repo *repo) 70char *find_default_branch(struct cgit_repo *repo)
71{ 71{
72 struct refmatch info; 72 struct refmatch info;
73 73
74 info.req_ref = repo->defbranch; 74 info.req_ref = repo->defbranch;
75 info.first_ref = NULL; 75 info.first_ref = NULL;
76 info.match = 0; 76 info.match = 0;
77 for_each_branch_ref(find_current_ref, &info); 77 for_each_branch_ref(find_current_ref, &info);
78 if (info.match) 78 if (info.match)
79 return info.req_ref; 79 return info.req_ref;
80 else 80 else
81 return info.first_ref; 81 return info.first_ref;
82} 82}
83 83
84static void cgit_print_repo_page(struct cacheitem *item) 84static void cgit_print_repo_page()
85{ 85{
86 char *tmp; 86 char *tmp;
87 int show_search; 87 int show_search;
88 unsigned char sha1[20]; 88 unsigned char sha1[20];
89 int nongit = 0; 89 int nongit = 0;
90 90
91 setenv("GIT_DIR", ctx.repo->path, 1); 91 setenv("GIT_DIR", ctx.repo->path, 1);
92 setup_git_directory_gently(&nongit); 92 setup_git_directory_gently(&nongit);
93 if (nongit) { 93 if (nongit) {
94 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, 94 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
95 "config error"); 95 "config error");
96 tmp = fmt("Not a git repository: '%s'", ctx.repo->path); 96 tmp = fmt("Not a git repository: '%s'", ctx.repo->path);
97 ctx.repo = NULL; 97 ctx.repo = NULL;
98 cgit_print_http_headers(&ctx); 98 cgit_print_http_headers(&ctx);
99 cgit_print_docstart(&ctx); 99 cgit_print_docstart(&ctx);
100 cgit_print_pageheader(&ctx); 100 cgit_print_pageheader(&ctx);
101 cgit_print_error(tmp); 101 cgit_print_error(tmp);
102 cgit_print_docend(); 102 cgit_print_docend();
103 return; 103 return;
104 } 104 }
105 105
106 ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); 106 ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
107 show_search = 0; 107 show_search = 0;
108 108
109 if (!ctx.qry.head) { 109 if (!ctx.qry.head) {
110 ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); 110 ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
111 ctx.repo->defbranch = ctx.qry.head; 111 ctx.repo->defbranch = ctx.qry.head;
112 } 112 }
113 113
114 if (!ctx.qry.head) { 114 if (!ctx.qry.head) {
115 cgit_print_http_headers(&ctx); 115 cgit_print_http_headers(&ctx);
116 cgit_print_docstart(&ctx); 116 cgit_print_docstart(&ctx);
117 cgit_print_pageheader(&ctx); 117 cgit_print_pageheader(&ctx);
118 cgit_print_error("Repository seems to be empty"); 118 cgit_print_error("Repository seems to be empty");
119 cgit_print_docend(); 119 cgit_print_docend();
120 return; 120 return;
121 } 121 }
122 122
123 if (get_sha1(ctx.qry.head, sha1)) { 123 if (get_sha1(ctx.qry.head, sha1)) {
124 tmp = xstrdup(ctx.qry.head); 124 tmp = xstrdup(ctx.qry.head);
125 ctx.qry.head = ctx.repo->defbranch; 125 ctx.qry.head = ctx.repo->defbranch;
126 cgit_print_http_headers(&ctx); 126 cgit_print_http_headers(&ctx);
127 cgit_print_docstart(&ctx); 127 cgit_print_docstart(&ctx);
128 cgit_print_pageheader(&ctx); 128 cgit_print_pageheader(&ctx);
129 cgit_print_error(fmt("Invalid branch: %s", tmp)); 129 cgit_print_error(fmt("Invalid branch: %s", tmp));
130 cgit_print_docend(); 130 cgit_print_docend();
131 return; 131 return;
132 } 132 }
133 133
134 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { 134 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) {
135 cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, 135 cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1,
136 cgit_repobasename(ctx.repo->url), 136 cgit_repobasename(ctx.repo->url),
137 ctx.qry.path, 137 ctx.qry.path,
138 ctx.repo->snapshots ); 138 ctx.repo->snapshots );
139 return; 139 return;
140 } 140 }
141 141
142 if (cgit_cmd == CMD_PATCH) { 142 if (cgit_cmd == CMD_PATCH) {
143 cgit_print_patch(ctx.qry.sha1, item); 143 cgit_print_patch(ctx.qry.sha1);
144 return; 144 return;
145 } 145 }
146 146
147 if (cgit_cmd == CMD_BLOB) { 147 if (cgit_cmd == CMD_BLOB) {
148 cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); 148 cgit_print_blob(ctx.qry.sha1, ctx.qry.path);
149 return; 149 return;
150 } 150 }
151 151
152 show_search = (cgit_cmd == CMD_LOG); 152 show_search = (cgit_cmd == CMD_LOG);
153 cgit_print_http_headers(&ctx); 153 cgit_print_http_headers(&ctx);
154 cgit_print_docstart(&ctx); 154 cgit_print_docstart(&ctx);
155 if (!cgit_cmd) { 155 if (!cgit_cmd) {
156 cgit_print_pageheader(&ctx); 156 cgit_print_pageheader(&ctx);
157 cgit_print_summary(); 157 cgit_print_summary();
158 cgit_print_docend(); 158 cgit_print_docend();
159 return; 159 return;
160 } 160 }
161 161
162 cgit_print_pageheader(&ctx); 162 cgit_print_pageheader(&ctx);
163 163
164 switch(cgit_cmd) { 164 switch(cgit_cmd) {
165 case CMD_LOG: 165 case CMD_LOG:
166 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, 166 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs,
167 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, 167 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search,
168 ctx.qry.path, 1); 168 ctx.qry.path, 1);
169 break; 169 break;
170 case CMD_TREE: 170 case CMD_TREE:
171 cgit_print_tree(ctx.qry.sha1, ctx.qry.path); 171 cgit_print_tree(ctx.qry.sha1, ctx.qry.path);
172 break; 172 break;
173 case CMD_COMMIT: 173 case CMD_COMMIT:
174 cgit_print_commit(ctx.qry.sha1); 174 cgit_print_commit(ctx.qry.sha1);
175 break; 175 break;
176 case CMD_REFS: 176 case CMD_REFS:
177 cgit_print_refs(); 177 cgit_print_refs();
178 break; 178 break;
179 case CMD_TAG: 179 case CMD_TAG:
180 cgit_print_tag(ctx.qry.sha1); 180 cgit_print_tag(ctx.qry.sha1);
181 break; 181 break;
182 case CMD_DIFF: 182 case CMD_DIFF:
183 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); 183 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path);
184 break; 184 break;
185 default: 185 default:
186 cgit_print_error("Invalid request"); 186 cgit_print_error("Invalid request");
187 } 187 }
188 cgit_print_docend(); 188 cgit_print_docend();
189} 189}
190 190
191static long ttl_seconds(long ttl) 191static long ttl_seconds(long ttl)
192{ 192{
193 if (ttl<0) 193 if (ttl<0)
194 return 60 * 60 * 24 * 365; 194 return 60 * 60 * 24 * 365;
195 else 195 else
196 return ttl * 60; 196 return ttl * 60;
197} 197}
198 198
199static void cgit_fill_cache(struct cacheitem *item, int use_cache) 199static void cgit_fill_cache(struct cacheitem *item, int use_cache)
200{ 200{
201 int stdout2; 201 int stdout2;
202 202
203 if (use_cache) { 203 if (use_cache) {
204 stdout2 = chk_positive(dup(STDOUT_FILENO), 204 stdout2 = chk_positive(dup(STDOUT_FILENO),
205 "Preserving STDOUT"); 205 "Preserving STDOUT");
206 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 206 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
207 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 207 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
208 } 208 }
209 209
210 ctx.page.modified = time(NULL); 210 ctx.page.modified = time(NULL);
211 ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); 211 ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl);
212 if (ctx.repo) 212 if (ctx.repo)
213 cgit_print_repo_page(item); 213 cgit_print_repo_page();
214 else 214 else
215 cgit_print_repolist(item); 215 cgit_print_repolist();
216 216
217 if (use_cache) { 217 if (use_cache) {
218 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 218 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
219 chk_positive(dup2(stdout2, STDOUT_FILENO), 219 chk_positive(dup2(stdout2, STDOUT_FILENO),
220 "Restoring original STDOUT"); 220 "Restoring original STDOUT");
221 chk_zero(close(stdout2), "Closing temporary STDOUT"); 221 chk_zero(close(stdout2), "Closing temporary STDOUT");
222 } 222 }
223} 223}
224 224
225static void cgit_check_cache(struct cacheitem *item) 225static void cgit_check_cache(struct cacheitem *item)
226{ 226{
227 int i = 0; 227 int i = 0;
228 228
229 top: 229 top:
230 if (++i > ctx.cfg.max_lock_attempts) { 230 if (++i > ctx.cfg.max_lock_attempts) {
231 die("cgit_refresh_cache: unable to lock %s: %s", 231 die("cgit_refresh_cache: unable to lock %s: %s",
232 item->name, strerror(errno)); 232 item->name, strerror(errno));
233 } 233 }
234 if (!cache_exist(item)) { 234 if (!cache_exist(item)) {
235 if (!cache_lock(item)) { 235 if (!cache_lock(item)) {
236 sleep(1); 236 sleep(1);
237 goto top; 237 goto top;
238 } 238 }
239 if (!cache_exist(item)) { 239 if (!cache_exist(item)) {
240 cgit_fill_cache(item, 1); 240 cgit_fill_cache(item, 1);
241 cache_unlock(item); 241 cache_unlock(item);
242 } else { 242 } else {
243 cache_cancel_lock(item); 243 cache_cancel_lock(item);
244 } 244 }
245 } else if (cache_expired(item) && cache_lock(item)) { 245 } else if (cache_expired(item) && cache_lock(item)) {
246 if (cache_expired(item)) { 246 if (cache_expired(item)) {
247 cgit_fill_cache(item, 1); 247 cgit_fill_cache(item, 1);
248 cache_unlock(item); 248 cache_unlock(item);
249 } else { 249 } else {
250 cache_cancel_lock(item); 250 cache_cancel_lock(item);
251 } 251 }
252 } 252 }
253} 253}
254 254
255static void cgit_print_cache(struct cacheitem *item) 255static void cgit_print_cache(struct cacheitem *item)
256{ 256{
257 static char buf[4096]; 257 static char buf[4096];
258 ssize_t i; 258 ssize_t i;
259 259
260 int fd = open(item->name, O_RDONLY); 260 int fd = open(item->name, O_RDONLY);
261 if (fd<0) 261 if (fd<0)
262 die("Unable to open cached file %s", item->name); 262 die("Unable to open cached file %s", item->name);
263 263