|
diff --git a/cgit.c b/cgit.c index 3943a0f..f749b6b 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -120,129 +120,129 @@ static void querystring_cb(const char *name, const char *value) |
120 | ctx.qry.search = xstrdup(value); |
120 | ctx.qry.search = xstrdup(value); |
121 | } else if (!strcmp(name, "h")) { |
121 | } else if (!strcmp(name, "h")) { |
122 | ctx.qry.head = xstrdup(value); |
122 | ctx.qry.head = xstrdup(value); |
123 | ctx.qry.has_symref = 1; |
123 | ctx.qry.has_symref = 1; |
124 | } else if (!strcmp(name, "id")) { |
124 | } else if (!strcmp(name, "id")) { |
125 | ctx.qry.sha1 = xstrdup(value); |
125 | ctx.qry.sha1 = xstrdup(value); |
126 | ctx.qry.has_sha1 = 1; |
126 | ctx.qry.has_sha1 = 1; |
127 | } else if (!strcmp(name, "id2")) { |
127 | } else if (!strcmp(name, "id2")) { |
128 | ctx.qry.sha2 = xstrdup(value); |
128 | ctx.qry.sha2 = xstrdup(value); |
129 | ctx.qry.has_sha1 = 1; |
129 | ctx.qry.has_sha1 = 1; |
130 | } else if (!strcmp(name, "ofs")) { |
130 | } else if (!strcmp(name, "ofs")) { |
131 | ctx.qry.ofs = atoi(value); |
131 | ctx.qry.ofs = atoi(value); |
132 | } else if (!strcmp(name, "path")) { |
132 | } else if (!strcmp(name, "path")) { |
133 | ctx.qry.path = trim_end(value, '/'); |
133 | ctx.qry.path = trim_end(value, '/'); |
134 | } else if (!strcmp(name, "name")) { |
134 | } else if (!strcmp(name, "name")) { |
135 | ctx.qry.name = xstrdup(value); |
135 | ctx.qry.name = xstrdup(value); |
136 | } |
136 | } |
137 | } |
137 | } |
138 | |
138 | |
139 | static void prepare_context(struct cgit_context *ctx) |
139 | static void prepare_context(struct cgit_context *ctx) |
140 | { |
140 | { |
141 | memset(ctx, 0, sizeof(ctx)); |
141 | memset(ctx, 0, sizeof(ctx)); |
142 | ctx->cfg.agefile = "info/web/last-modified"; |
142 | ctx->cfg.agefile = "info/web/last-modified"; |
143 | ctx->cfg.cache_dynamic_ttl = 5; |
143 | ctx->cfg.cache_dynamic_ttl = 5; |
144 | ctx->cfg.cache_max_create_time = 5; |
144 | ctx->cfg.cache_max_create_time = 5; |
145 | ctx->cfg.cache_repo_ttl = 5; |
145 | ctx->cfg.cache_repo_ttl = 5; |
146 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
146 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
147 | ctx->cfg.cache_root_ttl = 5; |
147 | ctx->cfg.cache_root_ttl = 5; |
148 | ctx->cfg.cache_static_ttl = -1; |
148 | ctx->cfg.cache_static_ttl = -1; |
149 | ctx->cfg.css = "/cgit.css"; |
149 | ctx->cfg.css = "/cgit.css"; |
150 | ctx->cfg.logo = "/git-logo.png"; |
150 | ctx->cfg.logo = "/git-logo.png"; |
151 | ctx->cfg.max_commit_count = 50; |
151 | ctx->cfg.max_commit_count = 50; |
152 | ctx->cfg.max_lock_attempts = 5; |
152 | ctx->cfg.max_lock_attempts = 5; |
153 | ctx->cfg.max_msg_len = 60; |
153 | ctx->cfg.max_msg_len = 60; |
154 | ctx->cfg.max_repodesc_len = 60; |
154 | ctx->cfg.max_repodesc_len = 60; |
155 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
155 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
156 | ctx->cfg.renamelimit = -1; |
156 | ctx->cfg.renamelimit = -1; |
157 | ctx->cfg.robots = "index, nofollow"; |
157 | ctx->cfg.robots = "index, nofollow"; |
158 | ctx->cfg.root_title = "Git repository browser"; |
158 | ctx->cfg.root_title = "Git repository browser"; |
159 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
159 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
160 | ctx->page.mimetype = "text/html"; |
160 | ctx->page.mimetype = "text/html"; |
161 | ctx->page.charset = PAGE_ENCODING; |
161 | ctx->page.charset = PAGE_ENCODING; |
162 | ctx->page.filename = NULL; |
162 | ctx->page.filename = NULL; |
163 | } |
163 | } |
164 | |
164 | |
165 | static int cgit_prepare_cache(struct cacheitem *item) |
165 | static int cgit_prepare_cache(struct cacheitem *item) |
166 | { |
166 | { |
167 | if (!ctx.repo && ctx.qry.repo) { |
167 | if (!ctx.repo && ctx.qry.repo) { |
168 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
168 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
169 | "Bad request"); |
169 | "Bad request"); |
170 | cgit_print_http_headers(&ctx); |
170 | cgit_print_http_headers(&ctx); |
171 | cgit_print_docstart(&ctx); |
171 | cgit_print_docstart(&ctx); |
172 | cgit_print_pageheader(&ctx); |
172 | cgit_print_pageheader(&ctx); |
173 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
173 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
174 | cgit_print_docend(); |
174 | cgit_print_docend(); |
175 | return 0; |
175 | return 0; |
176 | } |
176 | } |
177 | |
177 | |
178 | if (!ctx.repo) { |
178 | if (!ctx.repo) { |
179 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
179 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
180 | item->ttl = ctx.cfg.cache_root_ttl; |
180 | item->ttl = ctx.cfg.cache_root_ttl; |
181 | return 1; |
181 | return 1; |
182 | } |
182 | } |
183 | |
183 | |
184 | if (!cgit_cmd) { |
184 | if (!ctx.qry.page) { |
185 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
185 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
186 | cache_safe_filename(ctx.repo->url), |
186 | cache_safe_filename(ctx.repo->url), |
187 | cache_safe_filename(ctx.qry.raw))); |
187 | cache_safe_filename(ctx.qry.raw))); |
188 | item->ttl = ctx.cfg.cache_repo_ttl; |
188 | item->ttl = ctx.cfg.cache_repo_ttl; |
189 | } else { |
189 | } else { |
190 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
190 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
191 | cache_safe_filename(ctx.repo->url), |
191 | cache_safe_filename(ctx.repo->url), |
192 | ctx.qry.page, |
192 | ctx.qry.page, |
193 | cache_safe_filename(ctx.qry.raw))); |
193 | cache_safe_filename(ctx.qry.raw))); |
194 | if (ctx.qry.has_symref) |
194 | if (ctx.qry.has_symref) |
195 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
195 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
196 | else if (ctx.qry.has_sha1) |
196 | else if (ctx.qry.has_sha1) |
197 | item->ttl = ctx.cfg.cache_static_ttl; |
197 | item->ttl = ctx.cfg.cache_static_ttl; |
198 | else |
198 | else |
199 | item->ttl = ctx.cfg.cache_repo_ttl; |
199 | item->ttl = ctx.cfg.cache_repo_ttl; |
200 | } |
200 | } |
201 | return 1; |
201 | return 1; |
202 | } |
202 | } |
203 | |
203 | |
204 | struct refmatch { |
204 | struct refmatch { |
205 | char *req_ref; |
205 | char *req_ref; |
206 | char *first_ref; |
206 | char *first_ref; |
207 | int match; |
207 | int match; |
208 | }; |
208 | }; |
209 | |
209 | |
210 | int find_current_ref(const char *refname, const unsigned char *sha1, |
210 | int find_current_ref(const char *refname, const unsigned char *sha1, |
211 | int flags, void *cb_data) |
211 | int flags, void *cb_data) |
212 | { |
212 | { |
213 | struct refmatch *info; |
213 | struct refmatch *info; |
214 | |
214 | |
215 | info = (struct refmatch *)cb_data; |
215 | info = (struct refmatch *)cb_data; |
216 | if (!strcmp(refname, info->req_ref)) |
216 | if (!strcmp(refname, info->req_ref)) |
217 | info->match = 1; |
217 | info->match = 1; |
218 | if (!info->first_ref) |
218 | if (!info->first_ref) |
219 | info->first_ref = xstrdup(refname); |
219 | info->first_ref = xstrdup(refname); |
220 | return info->match; |
220 | return info->match; |
221 | } |
221 | } |
222 | |
222 | |
223 | char *find_default_branch(struct cgit_repo *repo) |
223 | char *find_default_branch(struct cgit_repo *repo) |
224 | { |
224 | { |
225 | struct refmatch info; |
225 | struct refmatch info; |
226 | |
226 | |
227 | info.req_ref = repo->defbranch; |
227 | info.req_ref = repo->defbranch; |
228 | info.first_ref = NULL; |
228 | info.first_ref = NULL; |
229 | info.match = 0; |
229 | info.match = 0; |
230 | for_each_branch_ref(find_current_ref, &info); |
230 | for_each_branch_ref(find_current_ref, &info); |
231 | if (info.match) |
231 | if (info.match) |
232 | return info.req_ref; |
232 | return info.req_ref; |
233 | else |
233 | else |
234 | return info.first_ref; |
234 | return info.first_ref; |
235 | } |
235 | } |
236 | |
236 | |
237 | static int prepare_repo_cmd(struct cgit_context *ctx) |
237 | static int prepare_repo_cmd(struct cgit_context *ctx) |
238 | { |
238 | { |
239 | char *tmp; |
239 | char *tmp; |
240 | unsigned char sha1[20]; |
240 | unsigned char sha1[20]; |
241 | int nongit = 0; |
241 | int nongit = 0; |
242 | |
242 | |
243 | setenv("GIT_DIR", ctx->repo->path, 1); |
243 | setenv("GIT_DIR", ctx->repo->path, 1); |
244 | setup_git_directory_gently(&nongit); |
244 | setup_git_directory_gently(&nongit); |
245 | if (nongit) { |
245 | if (nongit) { |
246 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
246 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
247 | "config error"); |
247 | "config error"); |
248 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
248 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
|
|
diff --git a/cgit.h b/cgit.h index b58676b..e82e9aa 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -128,115 +128,114 @@ struct cgit_query { |
128 | |
128 | |
129 | struct cgit_config { |
129 | struct cgit_config { |
130 | char *agefile; |
130 | char *agefile; |
131 | char *cache_root; |
131 | char *cache_root; |
132 | char *clone_prefix; |
132 | char *clone_prefix; |
133 | char *css; |
133 | char *css; |
134 | char *index_header; |
134 | char *index_header; |
135 | char *index_info; |
135 | char *index_info; |
136 | char *logo; |
136 | char *logo; |
137 | char *logo_link; |
137 | char *logo_link; |
138 | char *module_link; |
138 | char *module_link; |
139 | char *repo_group; |
139 | char *repo_group; |
140 | char *robots; |
140 | char *robots; |
141 | char *root_title; |
141 | char *root_title; |
142 | char *script_name; |
142 | char *script_name; |
143 | char *virtual_root; |
143 | char *virtual_root; |
144 | int cache_dynamic_ttl; |
144 | int cache_dynamic_ttl; |
145 | int cache_max_create_time; |
145 | int cache_max_create_time; |
146 | int cache_repo_ttl; |
146 | int cache_repo_ttl; |
147 | int cache_root_ttl; |
147 | int cache_root_ttl; |
148 | int cache_static_ttl; |
148 | int cache_static_ttl; |
149 | int enable_index_links; |
149 | int enable_index_links; |
150 | int enable_log_filecount; |
150 | int enable_log_filecount; |
151 | int enable_log_linecount; |
151 | int enable_log_linecount; |
152 | int max_commit_count; |
152 | int max_commit_count; |
153 | int max_lock_attempts; |
153 | int max_lock_attempts; |
154 | int max_msg_len; |
154 | int max_msg_len; |
155 | int max_repodesc_len; |
155 | int max_repodesc_len; |
156 | int nocache; |
156 | int nocache; |
157 | int renamelimit; |
157 | int renamelimit; |
158 | int snapshots; |
158 | int snapshots; |
159 | int summary_branches; |
159 | int summary_branches; |
160 | int summary_log; |
160 | int summary_log; |
161 | int summary_tags; |
161 | int summary_tags; |
162 | }; |
162 | }; |
163 | |
163 | |
164 | struct cgit_page { |
164 | struct cgit_page { |
165 | time_t modified; |
165 | time_t modified; |
166 | time_t expires; |
166 | time_t expires; |
167 | char *mimetype; |
167 | char *mimetype; |
168 | char *charset; |
168 | char *charset; |
169 | char *filename; |
169 | char *filename; |
170 | char *title; |
170 | char *title; |
171 | }; |
171 | }; |
172 | |
172 | |
173 | struct cgit_context { |
173 | struct cgit_context { |
174 | struct cgit_query qry; |
174 | struct cgit_query qry; |
175 | struct cgit_config cfg; |
175 | struct cgit_config cfg; |
176 | struct cgit_repo *repo; |
176 | struct cgit_repo *repo; |
177 | struct cgit_page page; |
177 | struct cgit_page page; |
178 | }; |
178 | }; |
179 | |
179 | |
180 | struct cgit_snapshot_format { |
180 | struct cgit_snapshot_format { |
181 | const char *suffix; |
181 | const char *suffix; |
182 | const char *mimetype; |
182 | const char *mimetype; |
183 | write_archive_fn_t write_func; |
183 | write_archive_fn_t write_func; |
184 | int bit; |
184 | int bit; |
185 | }; |
185 | }; |
186 | |
186 | |
187 | extern const char *cgit_version; |
187 | extern const char *cgit_version; |
188 | |
188 | |
189 | extern struct cgit_repolist cgit_repolist; |
189 | extern struct cgit_repolist cgit_repolist; |
190 | extern struct cgit_context ctx; |
190 | extern struct cgit_context ctx; |
191 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
191 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
192 | extern int cgit_cmd; |
| |
193 | |
192 | |
194 | extern struct cgit_repo *cgit_add_repo(const char *url); |
193 | extern struct cgit_repo *cgit_add_repo(const char *url); |
195 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
194 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
196 | extern void cgit_repo_config_cb(const char *name, const char *value); |
195 | extern void cgit_repo_config_cb(const char *name, const char *value); |
197 | |
196 | |
198 | extern int chk_zero(int result, char *msg); |
197 | extern int chk_zero(int result, char *msg); |
199 | extern int chk_positive(int result, char *msg); |
198 | extern int chk_positive(int result, char *msg); |
200 | extern int chk_non_negative(int result, char *msg); |
199 | extern int chk_non_negative(int result, char *msg); |
201 | |
200 | |
202 | extern int hextoint(char c); |
201 | extern int hextoint(char c); |
203 | extern char *trim_end(const char *str, char c); |
202 | extern char *trim_end(const char *str, char c); |
204 | extern char *strlpart(char *txt, int maxlen); |
203 | extern char *strlpart(char *txt, int maxlen); |
205 | extern char *strrpart(char *txt, int maxlen); |
204 | extern char *strrpart(char *txt, int maxlen); |
206 | |
205 | |
207 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
206 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
208 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
207 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
209 | int flags, void *cb_data); |
208 | int flags, void *cb_data); |
210 | |
209 | |
211 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
210 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
212 | |
211 | |
213 | extern int cgit_diff_files(const unsigned char *old_sha1, |
212 | extern int cgit_diff_files(const unsigned char *old_sha1, |
214 | const unsigned char *new_sha1, |
213 | const unsigned char *new_sha1, |
215 | linediff_fn fn); |
214 | linediff_fn fn); |
216 | |
215 | |
217 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
216 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
218 | const unsigned char *new_sha1, |
217 | const unsigned char *new_sha1, |
219 | filepair_fn fn, const char *prefix); |
218 | filepair_fn fn, const char *prefix); |
220 | |
219 | |
221 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
220 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
222 | |
221 | |
223 | extern char *fmt(const char *format,...); |
222 | extern char *fmt(const char *format,...); |
224 | |
223 | |
225 | extern int cgit_read_config(const char *filename, configfn fn); |
224 | extern int cgit_read_config(const char *filename, configfn fn); |
226 | extern int cgit_parse_query(char *txt, configfn fn); |
225 | extern int cgit_parse_query(char *txt, configfn fn); |
227 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
226 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
228 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
227 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
229 | extern void cgit_parse_url(const char *url); |
228 | extern void cgit_parse_url(const char *url); |
230 | |
229 | |
231 | extern char *cache_safe_filename(const char *unsafe); |
230 | extern char *cache_safe_filename(const char *unsafe); |
232 | extern int cache_lock(struct cacheitem *item); |
231 | extern int cache_lock(struct cacheitem *item); |
233 | extern int cache_unlock(struct cacheitem *item); |
232 | extern int cache_unlock(struct cacheitem *item); |
234 | extern int cache_cancel_lock(struct cacheitem *item); |
233 | extern int cache_cancel_lock(struct cacheitem *item); |
235 | extern int cache_exist(struct cacheitem *item); |
234 | extern int cache_exist(struct cacheitem *item); |
236 | extern int cache_expired(struct cacheitem *item); |
235 | extern int cache_expired(struct cacheitem *item); |
237 | |
236 | |
238 | extern const char *cgit_repobasename(const char *reponame); |
237 | extern const char *cgit_repobasename(const char *reponame); |
239 | |
238 | |
240 | extern int cgit_parse_snapshots_mask(const char *str); |
239 | extern int cgit_parse_snapshots_mask(const char *str); |
241 | |
240 | |
242 | #endif /* CGIT_H */ |
241 | #endif /* CGIT_H */ |
|