author | Lars Hjemli <hjemli@gmail.com> | 2007-05-18 01:00:54 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-18 20:51:01 (UTC) |
commit | 30ccdcaa74ebc0aab2b7843b0db8251d0ddf56de (patch) (unidiff) | |
tree | efb3eddd091117281d5592c9eab44bc63121edf6 | |
parent | 43d40f2b704151d145a1383b2b964210915ecae4 (diff) | |
download | cgit-30ccdcaa74ebc0aab2b7843b0db8251d0ddf56de.zip cgit-30ccdcaa74ebc0aab2b7843b0db8251d0ddf56de.tar.gz cgit-30ccdcaa74ebc0aab2b7843b0db8251d0ddf56de.tar.bz2 |
Enable url=value querystring parameter
This makes is possible to use repo-urls like '/pub/scm/git/git.git' and
even add path specifications, like '/pub/scm/git/git.git/log/documentation'.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cache.c | 9 | ||||
-rw-r--r-- | cgit.c | 60 | ||||
-rw-r--r-- | cgit.h | 16 | ||||
-rw-r--r-- | parsing.c | 43 | ||||
-rw-r--r-- | shared.c | 5 | ||||
-rw-r--r-- | ui-shared.c | 5 |
6 files changed, 98 insertions, 40 deletions
@@ -30,41 +30,44 @@ int cache_exist(struct cacheitem *item) | |||
30 | { | 30 | { |
31 | if (stat(item->name, &item->st)) { | 31 | if (stat(item->name, &item->st)) { |
32 | item->st.st_mtime = 0; | 32 | item->st.st_mtime = 0; |
33 | return 0; | 33 | return 0; |
34 | } | 34 | } |
35 | return 1; | 35 | return 1; |
36 | } | 36 | } |
37 | 37 | ||
38 | int cache_create_dirs() | 38 | int cache_create_dirs() |
39 | { | 39 | { |
40 | char *path; | 40 | char *path; |
41 | 41 | ||
42 | path = fmt("%s", cgit_cache_root); | 42 | path = fmt("%s", cgit_cache_root); |
43 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 43 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
44 | return 0; | 44 | return 0; |
45 | 45 | ||
46 | if (!cgit_query_repo) | 46 | if (!cgit_repo) |
47 | return 0; | 47 | return 0; |
48 | 48 | ||
49 | path = fmt("%s/%s", cgit_cache_root, cgit_query_repo); | 49 | path = fmt("%s/%s", cgit_cache_root, |
50 | cache_safe_filename(cgit_repo->url)); | ||
51 | |||
50 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 52 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
51 | return 0; | 53 | return 0; |
52 | 54 | ||
53 | if (cgit_query_page) { | 55 | if (cgit_query_page) { |
54 | path = fmt("%s/%s/%s", cgit_cache_root, cgit_query_repo, | 56 | path = fmt("%s/%s/%s", cgit_cache_root, |
57 | cache_safe_filename(cgit_repo->url), | ||
55 | cgit_query_page); | 58 | cgit_query_page); |
56 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 59 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
57 | return 0; | 60 | return 0; |
58 | } | 61 | } |
59 | return 1; | 62 | return 1; |
60 | } | 63 | } |
61 | 64 | ||
62 | int cache_refill_overdue(const char *lockfile) | 65 | int cache_refill_overdue(const char *lockfile) |
63 | { | 66 | { |
64 | struct stat st; | 67 | struct stat st; |
65 | 68 | ||
66 | if (stat(lockfile, &st)) | 69 | if (stat(lockfile, &st)) |
67 | return 0; | 70 | return 0; |
68 | else | 71 | else |
69 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); | 72 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); |
70 | } | 73 | } |
@@ -1,53 +1,53 @@ | |||
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 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | 13 | ||
14 | static int cgit_prepare_cache(struct cacheitem *item) | 14 | static int cgit_prepare_cache(struct cacheitem *item) |
15 | { | 15 | { |
16 | if (!cgit_query_repo) { | 16 | if (!cgit_repo && cgit_query_repo) { |
17 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | ||
18 | item->ttl = cgit_cache_root_ttl; | ||
19 | return 1; | ||
20 | } | ||
21 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); | ||
22 | if (!cgit_repo) { | ||
23 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
24 | cgit_print_docstart(title, item); | 18 | cgit_print_docstart(title, item); |
25 | cgit_print_pageheader(title, 0); | 19 | cgit_print_pageheader(title, 0); |
26 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 20 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
27 | cgit_print_docend(); | 21 | cgit_print_docend(); |
28 | return 0; | 22 | return 0; |
29 | } | 23 | } |
30 | 24 | ||
31 | if (!cgit_query_page) { | 25 | if (!cgit_repo) { |
26 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | ||
27 | item->ttl = cgit_cache_root_ttl; | ||
28 | return 1; | ||
29 | } | ||
30 | |||
31 | if (!cgit_cmd) { | ||
32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
33 | cgit_repo->url)); | 33 | cache_safe_filename(cgit_repo->url))); |
34 | item->ttl = cgit_cache_repo_ttl; | 34 | item->ttl = cgit_cache_repo_ttl; |
35 | } else { | 35 | } else { |
36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
37 | cgit_repo->url, cgit_query_page, | 37 | cache_safe_filename(cgit_repo->url), cgit_query_page, |
38 | cache_safe_filename(cgit_querystring))); | 38 | cache_safe_filename(cgit_querystring))); |
39 | if (cgit_query_has_symref) | 39 | if (cgit_query_has_symref) |
40 | item->ttl = cgit_cache_dynamic_ttl; | 40 | item->ttl = cgit_cache_dynamic_ttl; |
41 | else if (cgit_query_has_sha1) | 41 | else if (cgit_query_has_sha1) |
42 | item->ttl = cgit_cache_static_ttl; | 42 | item->ttl = cgit_cache_static_ttl; |
43 | else | 43 | else |
44 | item->ttl = cgit_cache_repo_ttl; | 44 | item->ttl = cgit_cache_repo_ttl; |
45 | } | 45 | } |
46 | return 1; | 46 | return 1; |
47 | } | 47 | } |
48 | 48 | ||
49 | static void cgit_print_repo_page(struct cacheitem *item) | 49 | static void cgit_print_repo_page(struct cacheitem *item) |
50 | { | 50 | { |
51 | char *title; | 51 | char *title; |
52 | int show_search; | 52 | int show_search; |
53 | 53 | ||
@@ -55,94 +55,95 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
55 | cgit_query_head = cgit_repo->defbranch; | 55 | cgit_query_head = cgit_repo->defbranch; |
56 | 56 | ||
57 | if (chdir(cgit_repo->path)) { | 57 | if (chdir(cgit_repo->path)) { |
58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
59 | cgit_print_docstart(title, item); | 59 | cgit_print_docstart(title, item); |
60 | cgit_print_pageheader(title, 0); | 60 | cgit_print_pageheader(title, 0); |
61 | cgit_print_error(fmt("Unable to scan repository: %s", | 61 | cgit_print_error(fmt("Unable to scan repository: %s", |
62 | strerror(errno))); | 62 | strerror(errno))); |
63 | cgit_print_docend(); | 63 | cgit_print_docend(); |
64 | return; | 64 | return; |
65 | } | 65 | } |
66 | 66 | ||
67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
68 | show_search = 0; | 68 | show_search = 0; |
69 | setenv("GIT_DIR", cgit_repo->path, 1); | 69 | setenv("GIT_DIR", cgit_repo->path, 1); |
70 | 70 | ||
71 | if (cgit_query_page) { | 71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
72 | if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { | ||
73 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
74 | cgit_repo->url, cgit_query_name); | 73 | cgit_repo->url, cgit_query_name); |
75 | return; | 74 | return; |
76 | } | ||
77 | if (!strcmp(cgit_query_page, "blob")) { | ||
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | ||
79 | return; | ||
80 | } | ||
81 | } | 75 | } |
82 | 76 | ||
83 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 77 | if (cgit_cmd == CMD_BLOB) { |
84 | show_search = 1; | 78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; | ||
80 | } | ||
85 | 81 | ||
82 | show_search = (cgit_cmd == CMD_LOG); | ||
86 | cgit_print_docstart(title, item); | 83 | cgit_print_docstart(title, item); |
87 | 84 | if (!cgit_cmd) { | |
88 | |||
89 | if (!cgit_query_page) { | ||
90 | cgit_print_pageheader("summary", show_search); | 85 | cgit_print_pageheader("summary", show_search); |
91 | cgit_print_summary(); | 86 | cgit_print_summary(); |
92 | cgit_print_docend(); | 87 | cgit_print_docend(); |
93 | return; | 88 | return; |
94 | } | 89 | } |
95 | 90 | ||
96 | cgit_print_pageheader(cgit_query_page, show_search); | 91 | cgit_print_pageheader(cgit_query_page, show_search); |
97 | 92 | ||
98 | if (!strcmp(cgit_query_page, "log")) { | 93 | switch(cgit_cmd) { |
94 | case CMD_LOG: | ||
99 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 95 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
100 | cgit_max_commit_count, cgit_query_search, | 96 | cgit_max_commit_count, cgit_query_search, |
101 | cgit_query_path); | 97 | cgit_query_path); |
102 | } else if (!strcmp(cgit_query_page, "tree")) { | 98 | break; |
99 | case CMD_TREE: | ||
103 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
104 | } else if (!strcmp(cgit_query_page, "commit")) { | 101 | break; |
102 | case CMD_COMMIT: | ||
105 | cgit_print_commit(cgit_query_head); | 103 | cgit_print_commit(cgit_query_head); |
106 | } else if (!strcmp(cgit_query_page, "view")) { | 104 | break; |
105 | case CMD_VIEW: | ||
107 | cgit_print_view(cgit_query_sha1, cgit_query_path); | 106 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
108 | } else if (!strcmp(cgit_query_page, "diff")) { | 107 | break; |
108 | case CMD_DIFF: | ||
109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
110 | cgit_query_path); | 110 | cgit_query_path); |
111 | } else { | 111 | break; |
112 | default: | ||
112 | cgit_print_error("Invalid request"); | 113 | cgit_print_error("Invalid request"); |
113 | } | 114 | } |
114 | cgit_print_docend(); | 115 | cgit_print_docend(); |
115 | } | 116 | } |
116 | 117 | ||
117 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
118 | { | 119 | { |
119 | static char buf[PATH_MAX]; | 120 | static char buf[PATH_MAX]; |
120 | int stdout2; | 121 | int stdout2; |
121 | 122 | ||
122 | getcwd(buf, sizeof(buf)); | 123 | getcwd(buf, sizeof(buf)); |
123 | item->st.st_mtime = time(NULL); | 124 | item->st.st_mtime = time(NULL); |
124 | 125 | ||
125 | if (use_cache) { | 126 | if (use_cache) { |
126 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 127 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
127 | "Preserving STDOUT"); | 128 | "Preserving STDOUT"); |
128 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
129 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
130 | } | 131 | } |
131 | 132 | ||
132 | if (cgit_query_repo) | 133 | if (cgit_repo) |
133 | cgit_print_repo_page(item); | 134 | cgit_print_repo_page(item); |
134 | else | 135 | else |
135 | cgit_print_repolist(item); | 136 | cgit_print_repolist(item); |
136 | 137 | ||
137 | if (use_cache) { | 138 | if (use_cache) { |
138 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
139 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 140 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
140 | "Restoring original STDOUT"); | 141 | "Restoring original STDOUT"); |
141 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
142 | } | 143 | } |
143 | 144 | ||
144 | chdir(buf); | 145 | chdir(buf); |
145 | } | 146 | } |
146 | 147 | ||
147 | static void cgit_check_cache(struct cacheitem *item) | 148 | static void cgit_check_cache(struct cacheitem *item) |
148 | { | 149 | { |
@@ -221,32 +222,33 @@ static void cgit_parse_args(int argc, const char **argv) | |||
221 | cgit_query_ofs = atoi(argv[i]+6); | 222 | cgit_query_ofs = atoi(argv[i]+6); |
222 | } | 223 | } |
223 | } | 224 | } |
224 | } | 225 | } |
225 | 226 | ||
226 | int main(int argc, const char **argv) | 227 | int main(int argc, const char **argv) |
227 | { | 228 | { |
228 | struct cacheitem item; | 229 | struct cacheitem item; |
229 | 230 | ||
230 | htmlfd = STDOUT_FILENO; | 231 | htmlfd = STDOUT_FILENO; |
231 | item.st.st_mtime = time(NULL); | 232 | item.st.st_mtime = time(NULL); |
232 | cgit_repolist.length = 0; | 233 | cgit_repolist.length = 0; |
233 | cgit_repolist.count = 0; | 234 | cgit_repolist.count = 0; |
234 | cgit_repolist.repos = NULL; | 235 | cgit_repolist.repos = NULL; |
235 | 236 | ||
236 | cgit_read_config(CGIT_CONFIG, cgit_global_config_cb); | 237 | cgit_read_config(CGIT_CONFIG, cgit_global_config_cb); |
238 | cgit_repo = NULL; | ||
237 | if (getenv("SCRIPT_NAME")) | 239 | if (getenv("SCRIPT_NAME")) |
238 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); | 240 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); |
239 | if (getenv("QUERY_STRING")) | 241 | if (getenv("QUERY_STRING")) |
240 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 242 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
241 | cgit_parse_args(argc, argv); | 243 | cgit_parse_args(argc, argv); |
242 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 244 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
243 | if (!cgit_prepare_cache(&item)) | 245 | if (!cgit_prepare_cache(&item)) |
244 | return 0; | 246 | return 0; |
245 | if (cgit_nocache) { | 247 | if (cgit_nocache) { |
246 | cgit_fill_cache(&item, 0); | 248 | cgit_fill_cache(&item, 0); |
247 | } else { | 249 | } else { |
248 | cgit_check_cache(&item); | 250 | cgit_check_cache(&item); |
249 | cgit_print_cache(&item); | 251 | cgit_print_cache(&item); |
250 | } | 252 | } |
251 | return 0; | 253 | return 0; |
252 | } | 254 | } |
@@ -8,39 +8,39 @@ | |||
8 | #include <object.h> | 8 | #include <object.h> |
9 | #include <tree.h> | 9 | #include <tree.h> |
10 | #include <commit.h> | 10 | #include <commit.h> |
11 | #include <tag.h> | 11 | #include <tag.h> |
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> | 18 | #include <xdiff/xdiff.h> |
19 | 19 | ||
20 | 20 | ||
21 | /* | 21 | /* |
22 | * The valid cgit repo-commands | 22 | * The valid cgit repo-commands |
23 | */ | 23 | */ |
24 | #define CMD_LOG = 1; | 24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT = 1; | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF = 1; | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE = 1; | 27 | #define CMD_TREE 4 |
28 | #define CMD_VIEW = 1; | 28 | #define CMD_VIEW 5 |
29 | #define CMD_BLOB = 1; | 29 | #define CMD_BLOB 6 |
30 | #define CMD_SNAPSHOT = 1; | 30 | #define CMD_SNAPSHOT 7 |
31 | 31 | ||
32 | typedef void (*configfn)(const char *name, const char *value); | 32 | typedef void (*configfn)(const char *name, const char *value); |
33 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 33 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
34 | typedef void (*linediff_fn)(char *line, int len); | 34 | typedef void (*linediff_fn)(char *line, int len); |
35 | 35 | ||
36 | struct cacheitem { | 36 | struct cacheitem { |
37 | char *name; | 37 | char *name; |
38 | struct stat st; | 38 | struct stat st; |
39 | int ttl; | 39 | int ttl; |
40 | int fd; | 40 | int fd; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct repoinfo { | 43 | struct repoinfo { |
44 | char *url; | 44 | char *url; |
45 | char *name; | 45 | char *name; |
46 | char *path; | 46 | char *path; |
@@ -69,32 +69,33 @@ struct commitinfo { | |||
69 | unsigned long committer_date; | 69 | unsigned long committer_date; |
70 | char *subject; | 70 | char *subject; |
71 | char *msg; | 71 | char *msg; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | struct taginfo { | 74 | struct taginfo { |
75 | char *tagger; | 75 | char *tagger; |
76 | char *tagger_email; | 76 | char *tagger_email; |
77 | int tagger_date; | 77 | int tagger_date; |
78 | char *msg; | 78 | char *msg; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | extern const char cgit_version[]; | 81 | extern const char cgit_version[]; |
82 | 82 | ||
83 | extern struct repolist cgit_repolist; | 83 | extern struct repolist cgit_repolist; |
84 | extern struct repoinfo *cgit_repo; | 84 | extern struct repoinfo *cgit_repo; |
85 | extern int cgit_cmd; | ||
85 | 86 | ||
86 | extern char *cgit_root_title; | 87 | extern char *cgit_root_title; |
87 | extern char *cgit_css; | 88 | extern char *cgit_css; |
88 | extern char *cgit_logo; | 89 | extern char *cgit_logo; |
89 | extern char *cgit_logo_link; | 90 | extern char *cgit_logo_link; |
90 | extern char *cgit_module_link; | 91 | extern char *cgit_module_link; |
91 | extern char *cgit_virtual_root; | 92 | extern char *cgit_virtual_root; |
92 | extern char *cgit_script_name; | 93 | extern char *cgit_script_name; |
93 | extern char *cgit_cache_root; | 94 | extern char *cgit_cache_root; |
94 | 95 | ||
95 | extern int cgit_nocache; | 96 | extern int cgit_nocache; |
96 | extern int cgit_snapshots; | 97 | extern int cgit_snapshots; |
97 | extern int cgit_enable_log_filecount; | 98 | extern int cgit_enable_log_filecount; |
98 | extern int cgit_enable_log_linecount; | 99 | extern int cgit_enable_log_linecount; |
99 | extern int cgit_max_lock_attempts; | 100 | extern int cgit_max_lock_attempts; |
100 | extern int cgit_cache_root_ttl; | 101 | extern int cgit_cache_root_ttl; |
@@ -149,32 +150,33 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | |||
149 | extern char *fmt(const char *format,...); | 150 | extern char *fmt(const char *format,...); |
150 | 151 | ||
151 | extern void html(const char *txt); | 152 | extern void html(const char *txt); |
152 | extern void htmlf(const char *format,...); | 153 | extern void htmlf(const char *format,...); |
153 | extern void html_txt(char *txt); | 154 | extern void html_txt(char *txt); |
154 | extern void html_ntxt(int len, char *txt); | 155 | extern void html_ntxt(int len, char *txt); |
155 | extern void html_attr(char *txt); | 156 | extern void html_attr(char *txt); |
156 | extern void html_hidden(char *name, char *value); | 157 | extern void html_hidden(char *name, char *value); |
157 | extern void html_link_open(char *url, char *title, char *class); | 158 | extern void html_link_open(char *url, char *title, char *class); |
158 | extern void html_link_close(void); | 159 | extern void html_link_close(void); |
159 | extern void html_filemode(unsigned short mode); | 160 | extern void html_filemode(unsigned short mode); |
160 | 161 | ||
161 | extern int cgit_read_config(const char *filename, configfn fn); | 162 | extern int cgit_read_config(const char *filename, configfn fn); |
162 | extern int cgit_parse_query(char *txt, configfn fn); | 163 | extern int cgit_parse_query(char *txt, configfn fn); |
163 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 164 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
164 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 165 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
166 | extern void cgit_parse_url(const char *url); | ||
165 | 167 | ||
166 | extern char *cache_safe_filename(const char *unsafe); | 168 | extern char *cache_safe_filename(const char *unsafe); |
167 | extern int cache_lock(struct cacheitem *item); | 169 | extern int cache_lock(struct cacheitem *item); |
168 | extern int cache_unlock(struct cacheitem *item); | 170 | extern int cache_unlock(struct cacheitem *item); |
169 | extern int cache_cancel_lock(struct cacheitem *item); | 171 | extern int cache_cancel_lock(struct cacheitem *item); |
170 | extern int cache_exist(struct cacheitem *item); | 172 | extern int cache_exist(struct cacheitem *item); |
171 | extern int cache_expired(struct cacheitem *item); | 173 | extern int cache_expired(struct cacheitem *item); |
172 | 174 | ||
173 | extern char *cgit_repourl(const char *reponame); | 175 | extern char *cgit_repourl(const char *reponame); |
174 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 176 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
175 | const char *query); | 177 | const char *query); |
176 | 178 | ||
177 | extern void cgit_print_error(char *msg); | 179 | extern void cgit_print_error(char *msg); |
178 | extern void cgit_print_date(unsigned long secs); | 180 | extern void cgit_print_date(unsigned long secs); |
179 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 181 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
180 | extern void cgit_print_docend(); | 182 | extern void cgit_print_docend(); |
@@ -119,32 +119,75 @@ int cgit_parse_query(char *txt, configfn fn) | |||
119 | *t = ' '; | 119 | *t = ' '; |
120 | } else if (c=='%') { | 120 | } else if (c=='%') { |
121 | t = convert_query_hexchar(t); | 121 | t = convert_query_hexchar(t); |
122 | } else if (c=='&') { | 122 | } else if (c=='&') { |
123 | *t = '\0'; | 123 | *t = '\0'; |
124 | (*fn)(txt, value); | 124 | (*fn)(txt, value); |
125 | txt = t+1; | 125 | txt = t+1; |
126 | value = NULL; | 126 | value = NULL; |
127 | } | 127 | } |
128 | t++; | 128 | t++; |
129 | } | 129 | } |
130 | if (t!=txt) | 130 | if (t!=txt) |
131 | (*fn)(txt, value); | 131 | (*fn)(txt, value); |
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
134 | 134 | ||
135 | /* | ||
136 | * url syntax: [repo ['/' cmd [ '/' path]]] | ||
137 | * repo: any valid repo url, may contain '/' | ||
138 | * cmd: log | commit | diff | tree | view | blob | snapshot | ||
139 | * path: any valid path, may contain '/' | ||
140 | * | ||
141 | */ | ||
142 | void cgit_parse_url(const char *url) | ||
143 | { | ||
144 | char *cmd, *p; | ||
145 | |||
146 | cgit_repo = NULL; | ||
147 | if (!url || url[0] == '\0') | ||
148 | return; | ||
149 | |||
150 | cgit_repo = cgit_get_repoinfo(url); | ||
151 | if (cgit_repo) { | ||
152 | cgit_query_repo = cgit_repo->url; | ||
153 | return; | ||
154 | } | ||
155 | |||
156 | cmd = strchr(url, '/'); | ||
157 | while (!cgit_repo && cmd) { | ||
158 | cmd[0] = '\0'; | ||
159 | cgit_repo = cgit_get_repoinfo(url); | ||
160 | if (cgit_repo == NULL) { | ||
161 | cmd[0] = '/'; | ||
162 | cmd = strchr(cmd + 1, '/'); | ||
163 | continue; | ||
164 | } | ||
165 | |||
166 | cgit_query_repo = cgit_repo->url; | ||
167 | p = strchr(cmd + 1, '/'); | ||
168 | if (p) { | ||
169 | p[0] = '\0'; | ||
170 | cgit_query_path = xstrdup(p + 1); | ||
171 | } | ||
172 | cgit_cmd = cgit_get_cmd_index(cmd + 1); | ||
173 | cgit_query_page = xstrdup(cmd + 1); | ||
174 | return; | ||
175 | } | ||
176 | } | ||
177 | |||
135 | char *substr(const char *head, const char *tail) | 178 | char *substr(const char *head, const char *tail) |
136 | { | 179 | { |
137 | char *buf; | 180 | char *buf; |
138 | 181 | ||
139 | buf = xmalloc(tail - head + 1); | 182 | buf = xmalloc(tail - head + 1); |
140 | strncpy(buf, head, tail - head); | 183 | strncpy(buf, head, tail - head); |
141 | buf[tail - head] = '\0'; | 184 | buf[tail - head] = '\0'; |
142 | return buf; | 185 | return buf; |
143 | } | 186 | } |
144 | 187 | ||
145 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 188 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
146 | { | 189 | { |
147 | struct commitinfo *ret; | 190 | struct commitinfo *ret; |
148 | char *p = commit->buffer, *t = commit->buffer; | 191 | char *p = commit->buffer, *t = commit->buffer; |
149 | 192 | ||
150 | ret = xmalloc(sizeof(*ret)); | 193 | ret = xmalloc(sizeof(*ret)); |
@@ -1,28 +1,29 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
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 | struct repolist cgit_repolist; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | 12 | struct repoinfo *cgit_repo; |
13 | int cgit_cmd; | ||
13 | 14 | ||
14 | char *cgit_root_title = "Git repository browser"; | 15 | char *cgit_root_title = "Git repository browser"; |
15 | char *cgit_css = "/cgit.css"; | 16 | char *cgit_css = "/cgit.css"; |
16 | char *cgit_logo = "/git-logo.png"; | 17 | char *cgit_logo = "/git-logo.png"; |
17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 18 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
18 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 19 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
19 | char *cgit_virtual_root = NULL; | 20 | char *cgit_virtual_root = NULL; |
20 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 21 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
21 | char *cgit_cache_root = "/var/cache/cgit"; | 22 | char *cgit_cache_root = "/var/cache/cgit"; |
22 | 23 | ||
23 | int cgit_nocache = 0; | 24 | int cgit_nocache = 0; |
24 | int cgit_snapshots = 0; | 25 | int cgit_snapshots = 0; |
25 | int cgit_enable_log_filecount = 0; | 26 | int cgit_enable_log_filecount = 0; |
26 | int cgit_enable_log_linecount = 0; | 27 | int cgit_enable_log_linecount = 0; |
27 | int cgit_max_lock_attempts = 5; | 28 | int cgit_max_lock_attempts = 5; |
28 | int cgit_cache_root_ttl = 5; | 29 | int cgit_cache_root_ttl = 5; |
@@ -171,34 +172,38 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
171 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 172 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
172 | cgit_repo->snapshots = cgit_snapshots * atoi(value); | 173 | cgit_repo->snapshots = cgit_snapshots * atoi(value); |
173 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 174 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
174 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | 175 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
175 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 176 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
176 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | 177 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
177 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 178 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
178 | cgit_repo->module_link= xstrdup(value); | 179 | cgit_repo->module_link= xstrdup(value); |
179 | else if (!strcmp(name, "include")) | 180 | else if (!strcmp(name, "include")) |
180 | cgit_read_config(value, cgit_global_config_cb); | 181 | cgit_read_config(value, cgit_global_config_cb); |
181 | } | 182 | } |
182 | 183 | ||
183 | void cgit_querystring_cb(const char *name, const char *value) | 184 | void cgit_querystring_cb(const char *name, const char *value) |
184 | { | 185 | { |
185 | if (!strcmp(name,"r")) { | 186 | if (!strcmp(name,"r")) { |
186 | cgit_query_repo = xstrdup(value); | 187 | cgit_query_repo = xstrdup(value); |
188 | cgit_repo = cgit_get_repoinfo(value); | ||
187 | } else if (!strcmp(name, "p")) { | 189 | } else if (!strcmp(name, "p")) { |
188 | cgit_query_page = xstrdup(value); | 190 | cgit_query_page = xstrdup(value); |
191 | cgit_cmd = cgit_get_cmd_index(value); | ||
192 | } else if (!strcmp(name, "url")) { | ||
193 | cgit_parse_url(value); | ||
189 | } else if (!strcmp(name, "q")) { | 194 | } else if (!strcmp(name, "q")) { |
190 | cgit_query_search = xstrdup(value); | 195 | cgit_query_search = xstrdup(value); |
191 | } else if (!strcmp(name, "h")) { | 196 | } else if (!strcmp(name, "h")) { |
192 | cgit_query_head = xstrdup(value); | 197 | cgit_query_head = xstrdup(value); |
193 | cgit_query_has_symref = 1; | 198 | cgit_query_has_symref = 1; |
194 | } else if (!strcmp(name, "id")) { | 199 | } else if (!strcmp(name, "id")) { |
195 | cgit_query_sha1 = xstrdup(value); | 200 | cgit_query_sha1 = xstrdup(value); |
196 | cgit_query_has_sha1 = 1; | 201 | cgit_query_has_sha1 = 1; |
197 | } else if (!strcmp(name, "id2")) { | 202 | } else if (!strcmp(name, "id2")) { |
198 | cgit_query_sha2 = xstrdup(value); | 203 | cgit_query_sha2 = xstrdup(value); |
199 | cgit_query_has_sha1 = 1; | 204 | cgit_query_has_sha1 = 1; |
200 | } else if (!strcmp(name, "ofs")) { | 205 | } else if (!strcmp(name, "ofs")) { |
201 | cgit_query_ofs = atoi(value); | 206 | cgit_query_ofs = atoi(value); |
202 | } else if (!strcmp(name, "path")) { | 207 | } else if (!strcmp(name, "path")) { |
203 | cgit_query_path = xstrdup(value); | 208 | cgit_query_path = xstrdup(value); |
204 | } else if (!strcmp(name, "name")) { | 209 | } else if (!strcmp(name, "name")) { |
diff --git a/ui-shared.c b/ui-shared.c index 6211056..c7fbc5e 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -55,33 +55,36 @@ char *cgit_repourl(const char *reponame) | |||
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_pageurl(const char *reponame, const char *pagename, |
61 | const char *query) | 61 | const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, |
66 | pagename, query); | 66 | pagename, query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | ||
73 | else | ||
74 | return fmt("?r=%s&p=%s", reponame, pagename); | ||
72 | } | 75 | } |
73 | } | 76 | } |
74 | 77 | ||
75 | char *cgit_currurl() | 78 | char *cgit_currurl() |
76 | { | 79 | { |
77 | if (!cgit_virtual_root) | 80 | if (!cgit_virtual_root) |
78 | return cgit_script_name; | 81 | return cgit_script_name; |
79 | else if (cgit_query_page) | 82 | else if (cgit_query_page) |
80 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
81 | else if (cgit_query_repo) | 84 | else if (cgit_query_repo) |
82 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
83 | else | 86 | else |
84 | return fmt("%s/", cgit_virtual_root); | 87 | return fmt("%s/", cgit_virtual_root); |
85 | } | 88 | } |
86 | 89 | ||
87 | 90 | ||