|
diff --git a/cgit.c b/cgit.c index d0f6905..a83f0be 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -72,25 +72,25 @@ char *find_default_branch(struct cgit_repo *repo) |
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 | |
84 | static void cgit_print_repo_page(struct cacheitem *item) |
84 | static 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); |
@@ -123,38 +123,38 @@ static void cgit_print_repo_page(struct cacheitem *item) |
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 | } |
@@ -201,27 +201,27 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
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 | |
225 | static void cgit_check_cache(struct cacheitem *item) |
225 | static void cgit_check_cache(struct cacheitem *item) |
226 | { |
226 | { |
227 | int i = 0; |
227 | int i = 0; |
|