-rw-r--r-- | cgit.c | 12 | ||||
-rw-r--r-- | cgit.h | 12 | ||||
-rw-r--r-- | ui-blob.c | 2 | ||||
-rw-r--r-- | ui-patch.c | 2 | ||||
-rw-r--r-- | ui-repolist.c | 2 | ||||
-rw-r--r-- | ui-snapshot.c | 3 |
6 files changed, 16 insertions, 17 deletions
@@ -68,33 +68,33 @@ int find_current_ref(const char *refname, const unsigned char *sha1, | |||
68 | } | 68 | } |
69 | 69 | ||
70 | char *find_default_branch(struct cgit_repo *repo) | 70 | char *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 | ||
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); |
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); |
@@ -119,46 +119,46 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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) { |
@@ -197,35 +197,35 @@ static long ttl_seconds(long ttl) | |||
197 | } | 197 | } |
198 | 198 | ||
199 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 199 | static 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 | ||
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; |
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", |
@@ -265,35 +265,35 @@ extern void cgit_snapshot_link(char *name, char *title, char *class, | |||
265 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 265 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
266 | char *new_rev, char *old_rev, char *path); | 266 | char *new_rev, char *old_rev, char *path); |
267 | 267 | ||
268 | extern void cgit_object_link(struct object *obj); | 268 | extern void cgit_object_link(struct object *obj); |
269 | 269 | ||
270 | extern void cgit_print_error(char *msg); | 270 | extern void cgit_print_error(char *msg); |
271 | extern void cgit_print_date(time_t secs, char *format); | 271 | extern void cgit_print_date(time_t secs, char *format); |
272 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 272 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
273 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 273 | extern void cgit_print_http_headers(struct cgit_context *ctx); |
274 | extern void cgit_print_docstart(struct cgit_context *ctx); | 274 | extern void cgit_print_docstart(struct cgit_context *ctx); |
275 | extern void cgit_print_docend(); | 275 | extern void cgit_print_docend(); |
276 | extern void cgit_print_pageheader(struct cgit_context *ctx); | 276 | extern void cgit_print_pageheader(struct cgit_context *ctx); |
277 | extern void cgit_print_filemode(unsigned short mode); | 277 | extern void cgit_print_filemode(unsigned short mode); |
278 | extern void cgit_print_branches(int maxcount); | 278 | extern void cgit_print_branches(int maxcount); |
279 | extern void cgit_print_tags(int maxcount); | 279 | extern void cgit_print_tags(int maxcount); |
280 | 280 | ||
281 | extern void cgit_print_repolist(struct cacheitem *item); | 281 | extern void cgit_print_repolist(); |
282 | extern void cgit_print_summary(); | 282 | extern void cgit_print_summary(); |
283 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, | 283 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, |
284 | char *pattern, char *path, int pager); | 284 | char *pattern, char *path, int pager); |
285 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 285 | extern void cgit_print_blob(const char *hex, char *path); |
286 | extern void cgit_print_tree(const char *rev, char *path); | 286 | extern void cgit_print_tree(const char *rev, char *path); |
287 | extern void cgit_print_commit(char *hex); | 287 | extern void cgit_print_commit(char *hex); |
288 | extern void cgit_print_refs(); | 288 | extern void cgit_print_refs(); |
289 | extern void cgit_print_tag(char *revname); | 289 | extern void cgit_print_tag(char *revname); |
290 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 290 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
291 | extern void cgit_print_patch(char *hex, struct cacheitem *item); | 291 | extern void cgit_print_patch(char *hex); |
292 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 292 | extern void cgit_print_snapshot(const char *head, const char *hex, |
293 | const char *hex, const char *prefix, | 293 | const char *prefix, const char *filename, |
294 | const char *filename, int snapshot); | 294 | int snapshot); |
295 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 295 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
296 | const char *hex, int snapshots); | 296 | const char *hex, int snapshots); |
297 | extern int cgit_parse_snapshots_mask(const char *str); | 297 | extern int cgit_parse_snapshots_mask(const char *str); |
298 | 298 | ||
299 | #endif /* CGIT_H */ | 299 | #endif /* CGIT_H */ |
@@ -1,28 +1,28 @@ | |||
1 | /* ui-blob.c: show blob content | 1 | /* ui-blob.c: show blob content |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 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 | #include "html.h" | 10 | #include "html.h" |
11 | 11 | ||
12 | void cgit_print_blob(struct cacheitem *item, const char *hex, char *path) | 12 | void cgit_print_blob(const char *hex, char *path) |
13 | { | 13 | { |
14 | 14 | ||
15 | unsigned char sha1[20]; | 15 | unsigned char sha1[20]; |
16 | enum object_type type; | 16 | enum object_type type; |
17 | unsigned char *buf; | 17 | unsigned char *buf; |
18 | unsigned long size; | 18 | unsigned long size; |
19 | 19 | ||
20 | if (get_sha1_hex(hex, sha1)){ | 20 | if (get_sha1_hex(hex, sha1)){ |
21 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 21 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
22 | return; | 22 | return; |
23 | } | 23 | } |
24 | 24 | ||
25 | type = sha1_object_info(sha1, &size); | 25 | type = sha1_object_info(sha1, &size); |
26 | if (type == OBJ_BAD) { | 26 | if (type == OBJ_BAD) { |
27 | cgit_print_error(fmt("Bad object name: %s", hex)); | 27 | cgit_print_error(fmt("Bad object name: %s", hex)); |
28 | return; | 28 | return; |
@@ -56,33 +56,33 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
56 | 56 | ||
57 | static void filepair_cb(struct diff_filepair *pair) | 57 | static void filepair_cb(struct diff_filepair *pair) |
58 | { | 58 | { |
59 | header(pair->one->sha1, pair->one->path, pair->one->mode, | 59 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
60 | pair->two->sha1, pair->two->path, pair->two->mode); | 60 | pair->two->sha1, pair->two->path, pair->two->mode); |
61 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 61 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
62 | if (S_ISGITLINK(pair->one->mode)) | 62 | if (S_ISGITLINK(pair->one->mode)) |
63 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 63 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
64 | if (S_ISGITLINK(pair->two->mode)) | 64 | if (S_ISGITLINK(pair->two->mode)) |
65 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 65 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) | 68 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
69 | html("Error running diff"); | 69 | html("Error running diff"); |
70 | } | 70 | } |
71 | 71 | ||
72 | void cgit_print_patch(char *hex, struct cacheitem *item) | 72 | void cgit_print_patch(char *hex) |
73 | { | 73 | { |
74 | struct commit *commit; | 74 | struct commit *commit; |
75 | struct commitinfo *info; | 75 | struct commitinfo *info; |
76 | unsigned char sha1[20], old_sha1[20]; | 76 | unsigned char sha1[20], old_sha1[20]; |
77 | char *patchname; | 77 | char *patchname; |
78 | 78 | ||
79 | if (!hex) | 79 | if (!hex) |
80 | hex = ctx.qry.head; | 80 | hex = ctx.qry.head; |
81 | 81 | ||
82 | if (get_sha1(hex, sha1)) { | 82 | if (get_sha1(hex, sha1)) { |
83 | cgit_print_error(fmt("Bad object id: %s", hex)); | 83 | cgit_print_error(fmt("Bad object id: %s", hex)); |
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | commit = lookup_commit_reference(sha1); | 86 | commit = lookup_commit_reference(sha1); |
87 | if (!commit) { | 87 | if (!commit) { |
88 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 88 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
diff --git a/ui-repolist.c b/ui-repolist.c index e663585..ad9b1bc 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -30,33 +30,33 @@ static void print_modtime(struct cgit_repo *repo) | |||
30 | { | 30 | { |
31 | char *path; | 31 | char *path; |
32 | struct stat s; | 32 | struct stat s; |
33 | 33 | ||
34 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 34 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
35 | if (stat(path, &s) == 0) { | 35 | if (stat(path, &s) == 0) { |
36 | cgit_print_age(read_agefile(path), -1, NULL); | 36 | cgit_print_age(read_agefile(path), -1, NULL); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | 39 | ||
40 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 40 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
41 | if (stat(path, &s) != 0) | 41 | if (stat(path, &s) != 0) |
42 | return; | 42 | return; |
43 | cgit_print_age(s.st_mtime, -1, NULL); | 43 | cgit_print_age(s.st_mtime, -1, NULL); |
44 | } | 44 | } |
45 | 45 | ||
46 | void cgit_print_repolist(struct cacheitem *item) | 46 | void cgit_print_repolist() |
47 | { | 47 | { |
48 | int i, columns = 4; | 48 | int i, columns = 4; |
49 | char *last_group = NULL; | 49 | char *last_group = NULL; |
50 | 50 | ||
51 | if (ctx.cfg.enable_index_links) | 51 | if (ctx.cfg.enable_index_links) |
52 | columns++; | 52 | columns++; |
53 | 53 | ||
54 | ctx.page.title = ctx.cfg.root_title; | 54 | ctx.page.title = ctx.cfg.root_title; |
55 | cgit_print_http_headers(&ctx); | 55 | cgit_print_http_headers(&ctx); |
56 | cgit_print_docstart(&ctx); | 56 | cgit_print_docstart(&ctx); |
57 | cgit_print_pageheader(&ctx); | 57 | cgit_print_pageheader(&ctx); |
58 | 58 | ||
59 | html("<table summary='repository list' class='list nowrap'>"); | 59 | html("<table summary='repository list' class='list nowrap'>"); |
60 | if (ctx.cfg.index_header) { | 60 | if (ctx.cfg.index_header) { |
61 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 61 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
62 | columns); | 62 | columns); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 4449803..c741469 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -56,34 +56,33 @@ static int write_tar_bzip2_archive(struct archiver_args *args) | |||
56 | } | 56 | } |
57 | 57 | ||
58 | static const struct snapshot_archive_t { | 58 | static const struct snapshot_archive_t { |
59 | const char *suffix; | 59 | const char *suffix; |
60 | const char *mimetype; | 60 | const char *mimetype; |
61 | write_archive_fn_t write_func; | 61 | write_archive_fn_t write_func; |
62 | int bit; | 62 | int bit; |
63 | }snapshot_archives[] = { | 63 | }snapshot_archives[] = { |
64 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, | 64 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, |
65 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, | 65 | { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, |
66 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, | 66 | { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, |
67 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } | 67 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } |
68 | }; | 68 | }; |
69 | 69 | ||
70 | #define snapshot_archives_len (sizeof(snapshot_archives) / sizeof(*snapshot_archives)) | 70 | #define snapshot_archives_len (sizeof(snapshot_archives) / sizeof(*snapshot_archives)) |
71 | 71 | ||
72 | void cgit_print_snapshot(struct cacheitem *item, const char *head, | 72 | void cgit_print_snapshot(const char *head, const char *hex, const char *prefix, |
73 | const char *hex, const char *prefix, | ||
74 | const char *filename, int snapshots) | 73 | const char *filename, int snapshots) |
75 | { | 74 | { |
76 | const struct snapshot_archive_t* sat; | 75 | const struct snapshot_archive_t* sat; |
77 | struct archiver_args args; | 76 | struct archiver_args args; |
78 | struct commit *commit; | 77 | struct commit *commit; |
79 | unsigned char sha1[20]; | 78 | unsigned char sha1[20]; |
80 | int f, sl, fnl = strlen(filename); | 79 | int f, sl, fnl = strlen(filename); |
81 | 80 | ||
82 | for(f=0; f<snapshot_archives_len; f++) { | 81 | for(f=0; f<snapshot_archives_len; f++) { |
83 | sat = &snapshot_archives[f]; | 82 | sat = &snapshot_archives[f]; |
84 | if(!(snapshots & sat->bit)) | 83 | if(!(snapshots & sat->bit)) |
85 | continue; | 84 | continue; |
86 | sl = strlen(sat->suffix); | 85 | sl = strlen(sat->suffix); |
87 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | 86 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) |
88 | continue; | 87 | continue; |
89 | if (!hex) | 88 | if (!hex) |