-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | cgit.c | 67 | ||||
-rw-r--r-- | cgit.css | 64 | ||||
-rw-r--r-- | cgit.h | 12 | ||||
-rw-r--r-- | cgit.png | bin | 3790 -> 5406 bytes | |||
-rw-r--r-- | cgitrc | 12 | ||||
-rw-r--r-- | html.c | 2 | ||||
-rw-r--r-- | parsing.c | 25 | ||||
-rw-r--r-- | shared.c | 12 | ||||
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile | 13 | ||||
-rwxr-xr-x | tests/setup.sh | 108 | ||||
-rwxr-xr-x | tests/t0010-validate-html.sh | 31 | ||||
-rwxr-xr-x | tests/t0101-index.sh | 13 | ||||
-rwxr-xr-x | tests/t0102-summary.sh | 20 | ||||
-rwxr-xr-x | tests/t0103-log.sh | 15 | ||||
-rwxr-xr-x | tests/t0104-tree.sh | 21 | ||||
-rwxr-xr-x | tests/t0105-commit.sh | 22 | ||||
-rwxr-xr-x | tests/t0106-diff.sh | 20 | ||||
-rwxr-xr-x | tests/t0107-snapshot.sh | 36 | ||||
-rw-r--r-- | ui-commit.c | 6 | ||||
-rw-r--r-- | ui-diff.c | 2 | ||||
-rw-r--r-- | ui-log.c | 23 | ||||
-rw-r--r-- | ui-patch.c | 110 | ||||
-rw-r--r-- | ui-repolist.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 67 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 6 |
28 files changed, 651 insertions, 74 deletions
@@ -1,75 +1,83 @@ | |||
1 | CGIT_VERSION = v0.7.2 | 1 | CGIT_VERSION = v0.7.2 |
2 | CGIT_SCRIPT_NAME = cgit.cgi | 2 | CGIT_SCRIPT_NAME = cgit.cgi |
3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
4 | CGIT_CONFIG = /etc/cgitrc | 4 | CGIT_CONFIG = /etc/cgitrc |
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | SHA1_HEADER = <openssl/sha.h> | 6 | SHA1_HEADER = <openssl/sha.h> |
7 | GIT_VER = 1.5.3.8 | 7 | GIT_VER = 1.5.3.8 |
8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
9 | 9 | ||
10 | # | 10 | # |
11 | # Let the user override the above settings. | 11 | # Let the user override the above settings. |
12 | # | 12 | # |
13 | -include cgit.conf | 13 | -include cgit.conf |
14 | 14 | ||
15 | 15 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o | 19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o |
20 | 20 | ||
21 | 21 | ||
22 | .PHONY: all git install clean distclean emptycache force-version get-git | 22 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | ||
24 | endif | ||
25 | |||
26 | |||
27 | .PHONY: all git test install clean distclean emptycache force-version get-git | ||
23 | 28 | ||
24 | all: cgit git | 29 | all: cgit git |
25 | 30 | ||
26 | VERSION: force-version | 31 | VERSION: force-version |
27 | @./gen-version.sh "$(CGIT_VERSION)" | 32 | @./gen-version.sh "$(CGIT_VERSION)" |
28 | -include VERSION | 33 | -include VERSION |
29 | 34 | ||
30 | 35 | ||
31 | CFLAGS += -g -Wall -Igit | 36 | CFLAGS += -g -Wall -Igit |
32 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
33 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
34 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
35 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
36 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
37 | 42 | ||
38 | 43 | ||
39 | cgit: cgit.c $(OBJECTS) | 44 | cgit: cgit.c $(OBJECTS) |
40 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
41 | 46 | ||
42 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION |
43 | 48 | ||
44 | git/xdiff/lib.a: | git | 49 | git/xdiff/lib.a: | git |
45 | 50 | ||
46 | git/libgit.a: | git | 51 | git/libgit.a: | git |
47 | 52 | ||
48 | git: | 53 | git: |
49 | cd git && $(MAKE) xdiff/lib.a | 54 | cd git && $(MAKE) xdiff/lib.a |
50 | cd git && $(MAKE) libgit.a | 55 | cd git && $(MAKE) libgit.a |
51 | 56 | ||
57 | test: all | ||
58 | $(MAKE) -C tests | ||
59 | |||
52 | install: all | 60 | install: all |
53 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
54 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
55 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css | 63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css |
56 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png | 64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png |
57 | 65 | ||
58 | uninstall: | 66 | uninstall: |
59 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
60 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css | 68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css |
61 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
62 | 70 | ||
63 | clean: | 71 | clean: |
64 | rm -f cgit VERSION *.o | 72 | rm -f cgit VERSION *.o |
65 | cd git && $(MAKE) clean | 73 | cd git && $(MAKE) clean |
66 | 74 | ||
67 | distclean: clean | 75 | distclean: clean |
68 | git clean -d -x | 76 | git clean -d -x |
69 | cd git && git clean -d -x | 77 | cd git && git clean -d -x |
70 | 78 | ||
71 | emptycache: | 79 | emptycache: |
72 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* | 80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* |
73 | 81 | ||
74 | get-git: | 82 | get-git: |
75 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 83 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
@@ -1,173 +1,232 @@ | |||
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 | static int cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 12 | { |
13 | if (!cgit_repo && cgit_query_repo) { | 13 | if (!cgit_repo && cgit_query_repo) { |
14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
18 | cgit_print_docend(); | 18 | cgit_print_docend(); |
19 | return 0; | 19 | return 0; |
20 | } | 20 | } |
21 | 21 | ||
22 | if (!cgit_repo) { | 22 | if (!cgit_repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
24 | item->ttl = cgit_cache_root_ttl; | 24 | item->ttl = cgit_cache_root_ttl; |
25 | return 1; | 25 | return 1; |
26 | } | 26 | } |
27 | 27 | ||
28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, |
30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(cgit_repo->url), |
31 | cache_safe_filename(cgit_querystring))); | 31 | cache_safe_filename(cgit_querystring))); |
32 | item->ttl = cgit_cache_repo_ttl; | 32 | item->ttl = cgit_cache_repo_ttl; |
33 | } else { | 33 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(cgit_repo->url), |
36 | cgit_query_page, | 36 | cgit_query_page, |
37 | cache_safe_filename(cgit_querystring))); | 37 | cache_safe_filename(cgit_querystring))); |
38 | if (cgit_query_has_symref) | 38 | if (cgit_query_has_symref) |
39 | item->ttl = cgit_cache_dynamic_ttl; | 39 | item->ttl = cgit_cache_dynamic_ttl; |
40 | else if (cgit_query_has_sha1) | 40 | else if (cgit_query_has_sha1) |
41 | item->ttl = cgit_cache_static_ttl; | 41 | item->ttl = cgit_cache_static_ttl; |
42 | else | 42 | else |
43 | item->ttl = cgit_cache_repo_ttl; | 43 | item->ttl = cgit_cache_repo_ttl; |
44 | } | 44 | } |
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
47 | 47 | ||
48 | struct refmatch { | ||
49 | char *req_ref; | ||
50 | char *first_ref; | ||
51 | int match; | ||
52 | }; | ||
53 | |||
54 | int find_current_ref(const char *refname, const unsigned char *sha1, | ||
55 | int flags, void *cb_data) | ||
56 | { | ||
57 | struct refmatch *info; | ||
58 | |||
59 | info = (struct refmatch *)cb_data; | ||
60 | if (!strcmp(refname, info->req_ref)) | ||
61 | info->match = 1; | ||
62 | if (!info->first_ref) | ||
63 | info->first_ref = xstrdup(refname); | ||
64 | return info->match; | ||
65 | } | ||
66 | |||
67 | char *find_default_branch(struct repoinfo *repo) | ||
68 | { | ||
69 | struct refmatch info; | ||
70 | |||
71 | info.req_ref = repo->defbranch; | ||
72 | info.first_ref = NULL; | ||
73 | info.match = 0; | ||
74 | for_each_branch_ref(find_current_ref, &info); | ||
75 | if (info.match) | ||
76 | return info.req_ref; | ||
77 | else | ||
78 | return info.first_ref; | ||
79 | } | ||
80 | |||
48 | static void cgit_print_repo_page(struct cacheitem *item) | 81 | static void cgit_print_repo_page(struct cacheitem *item) |
49 | { | 82 | { |
50 | char *title; | 83 | char *title, *tmp; |
51 | int show_search; | 84 | int show_search; |
52 | 85 | unsigned char sha1[20]; | |
53 | if (!cgit_query_head) | ||
54 | cgit_query_head = cgit_repo->defbranch; | ||
55 | 86 | ||
56 | if (chdir(cgit_repo->path)) { | 87 | if (chdir(cgit_repo->path)) { |
57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 88 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
59 | cgit_print_pageheader(title, 0); | 90 | cgit_print_pageheader(title, 0); |
60 | cgit_print_error(fmt("Unable to scan repository: %s", | 91 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | strerror(errno))); | 92 | strerror(errno))); |
62 | cgit_print_docend(); | 93 | cgit_print_docend(); |
63 | return; | 94 | return; |
64 | } | 95 | } |
65 | 96 | ||
66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | show_search = 0; | 98 | show_search = 0; |
68 | setenv("GIT_DIR", cgit_repo->path, 1); | 99 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | 100 | ||
101 | if (!cgit_query_head) { | ||
102 | cgit_query_head = xstrdup(find_default_branch(cgit_repo)); | ||
103 | cgit_repo->defbranch = cgit_query_head; | ||
104 | } | ||
105 | |||
106 | if (!cgit_query_head) { | ||
107 | cgit_print_docstart(title, item); | ||
108 | cgit_print_pageheader(title, 0); | ||
109 | cgit_print_error("Repository seems to be empty"); | ||
110 | cgit_print_docend(); | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | if (get_sha1(cgit_query_head, sha1)) { | ||
115 | tmp = xstrdup(cgit_query_head); | ||
116 | cgit_query_head = cgit_repo->defbranch; | ||
117 | cgit_print_docstart(title, item); | ||
118 | cgit_print_pageheader(title, 0); | ||
119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | ||
120 | cgit_print_docend(); | ||
121 | return; | ||
122 | } | ||
123 | |||
70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, | 125 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 126 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_path, | 127 | cgit_query_path, |
74 | cgit_repo->snapshots ); | 128 | cgit_repo->snapshots ); |
75 | return; | 129 | return; |
76 | } | 130 | } |
77 | 131 | ||
132 | if (cgit_cmd == CMD_PATCH) { | ||
133 | cgit_print_patch(cgit_query_sha1, item); | ||
134 | return; | ||
135 | } | ||
136 | |||
78 | if (cgit_cmd == CMD_BLOB) { | 137 | if (cgit_cmd == CMD_BLOB) { |
79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 138 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
80 | return; | 139 | return; |
81 | } | 140 | } |
82 | 141 | ||
83 | show_search = (cgit_cmd == CMD_LOG); | 142 | show_search = (cgit_cmd == CMD_LOG); |
84 | cgit_print_docstart(title, item); | 143 | cgit_print_docstart(title, item); |
85 | if (!cgit_cmd) { | 144 | if (!cgit_cmd) { |
86 | cgit_print_pageheader("summary", show_search); | 145 | cgit_print_pageheader("summary", show_search); |
87 | cgit_print_summary(); | 146 | cgit_print_summary(); |
88 | cgit_print_docend(); | 147 | cgit_print_docend(); |
89 | return; | 148 | return; |
90 | } | 149 | } |
91 | 150 | ||
92 | cgit_print_pageheader(cgit_query_page, show_search); | 151 | cgit_print_pageheader(cgit_query_page, show_search); |
93 | 152 | ||
94 | switch(cgit_cmd) { | 153 | switch(cgit_cmd) { |
95 | case CMD_LOG: | 154 | case CMD_LOG: |
96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 155 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
97 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, | 156 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, |
98 | cgit_query_path, 1); | 157 | cgit_query_path, 1); |
99 | break; | 158 | break; |
100 | case CMD_TREE: | 159 | case CMD_TREE: |
101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 160 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
102 | break; | 161 | break; |
103 | case CMD_COMMIT: | 162 | case CMD_COMMIT: |
104 | cgit_print_commit(cgit_query_sha1); | 163 | cgit_print_commit(cgit_query_sha1); |
105 | break; | 164 | break; |
106 | case CMD_REFS: | 165 | case CMD_REFS: |
107 | cgit_print_refs(); | 166 | cgit_print_refs(); |
108 | break; | 167 | break; |
109 | case CMD_TAG: | 168 | case CMD_TAG: |
110 | cgit_print_tag(cgit_query_sha1); | 169 | cgit_print_tag(cgit_query_sha1); |
111 | break; | 170 | break; |
112 | case CMD_DIFF: | 171 | case CMD_DIFF: |
113 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | 172 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
114 | break; | 173 | break; |
115 | default: | 174 | default: |
116 | cgit_print_error("Invalid request"); | 175 | cgit_print_error("Invalid request"); |
117 | } | 176 | } |
118 | cgit_print_docend(); | 177 | cgit_print_docend(); |
119 | } | 178 | } |
120 | 179 | ||
121 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 180 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
122 | { | 181 | { |
123 | static char buf[PATH_MAX]; | 182 | static char buf[PATH_MAX]; |
124 | int stdout2; | 183 | int stdout2; |
125 | 184 | ||
126 | getcwd(buf, sizeof(buf)); | 185 | getcwd(buf, sizeof(buf)); |
127 | item->st.st_mtime = time(NULL); | 186 | item->st.st_mtime = time(NULL); |
128 | 187 | ||
129 | if (use_cache) { | 188 | if (use_cache) { |
130 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 189 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
131 | "Preserving STDOUT"); | 190 | "Preserving STDOUT"); |
132 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 191 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
133 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
134 | } | 193 | } |
135 | 194 | ||
136 | if (cgit_repo) | 195 | if (cgit_repo) |
137 | cgit_print_repo_page(item); | 196 | cgit_print_repo_page(item); |
138 | else | 197 | else |
139 | cgit_print_repolist(item); | 198 | cgit_print_repolist(item); |
140 | 199 | ||
141 | if (use_cache) { | 200 | if (use_cache) { |
142 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 201 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
143 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 202 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
144 | "Restoring original STDOUT"); | 203 | "Restoring original STDOUT"); |
145 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 204 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
146 | } | 205 | } |
147 | 206 | ||
148 | chdir(buf); | 207 | chdir(buf); |
149 | } | 208 | } |
150 | 209 | ||
151 | static void cgit_check_cache(struct cacheitem *item) | 210 | static void cgit_check_cache(struct cacheitem *item) |
152 | { | 211 | { |
153 | int i = 0; | 212 | int i = 0; |
154 | 213 | ||
155 | top: | 214 | top: |
156 | if (++i > cgit_max_lock_attempts) { | 215 | if (++i > cgit_max_lock_attempts) { |
157 | die("cgit_refresh_cache: unable to lock %s: %s", | 216 | die("cgit_refresh_cache: unable to lock %s: %s", |
158 | item->name, strerror(errno)); | 217 | item->name, strerror(errno)); |
159 | } | 218 | } |
160 | if (!cache_exist(item)) { | 219 | if (!cache_exist(item)) { |
161 | if (!cache_lock(item)) { | 220 | if (!cache_lock(item)) { |
162 | sleep(1); | 221 | sleep(1); |
163 | goto top; | 222 | goto top; |
164 | } | 223 | } |
165 | if (!cache_exist(item)) { | 224 | if (!cache_exist(item)) { |
166 | cgit_fill_cache(item, 1); | 225 | cgit_fill_cache(item, 1); |
167 | cache_unlock(item); | 226 | cache_unlock(item); |
168 | } else { | 227 | } else { |
169 | cache_cancel_lock(item); | 228 | cache_cancel_lock(item); |
170 | } | 229 | } |
171 | } else if (cache_expired(item) && cache_lock(item)) { | 230 | } else if (cache_expired(item) && cache_lock(item)) { |
172 | if (cache_expired(item)) { | 231 | if (cache_expired(item)) { |
173 | cgit_fill_cache(item, 1); | 232 | cgit_fill_cache(item, 1); |
@@ -1,250 +1,254 @@ | |||
1 | body, table { | 1 | body, table { |
2 | padding: 0em; | 2 | padding: 0em; |
3 | margin: 0em; | 3 | margin: 0em; |
4 | } | 4 | } |
5 | 5 | ||
6 | body { | 6 | body { |
7 | font-family: sans; | 7 | font-family: sans; |
8 | font-size: 10pt; | 8 | font-size: 10pt; |
9 | color: #333; | 9 | color: #333; |
10 | background: white; | 10 | background: white; |
11 | padding-left: 4px; | 11 | padding: 4px; |
12 | } | 12 | } |
13 | 13 | ||
14 | table { | 14 | table { |
15 | border-collapse: collapse; | 15 | border-collapse: collapse; |
16 | } | 16 | } |
17 | 17 | ||
18 | h2 { | 18 | h2 { |
19 | font-size: 120%; | 19 | font-size: 120%; |
20 | font-weight: bold; | 20 | font-weight: bold; |
21 | margin-top: 0em; | 21 | margin-top: 0em; |
22 | margin-bottom: 0.25em; | 22 | margin-bottom: 0.25em; |
23 | } | 23 | } |
24 | 24 | ||
25 | h3 { | 25 | h3 { |
26 | margin-top: 0em; | 26 | margin-top: 0em; |
27 | font-size: 100%; | 27 | font-size: 100%; |
28 | font-weight: normal; | 28 | font-weight: normal; |
29 | } | 29 | } |
30 | 30 | ||
31 | h4 { | 31 | h4 { |
32 | margin-top: 1.5em; | 32 | margin-top: 1.5em; |
33 | margin-bottom: 0.1em; | 33 | margin-bottom: 0.1em; |
34 | font-size: 100%; | 34 | font-size: 100%; |
35 | font-weight: bold; | 35 | font-weight: bold; |
36 | } | 36 | } |
37 | 37 | ||
38 | a { | 38 | a { |
39 | color: #600; | 39 | color: #600; |
40 | text-decoration: none; | 40 | text-decoration: none; |
41 | } | 41 | } |
42 | 42 | ||
43 | a:hover { | 43 | a:hover { |
44 | background-color: #ddd; | 44 | background-color: #ddd; |
45 | text-decoration: none; | 45 | text-decoration: none; |
46 | } | 46 | } |
47 | 47 | ||
48 | table.list { | 48 | table.list { |
49 | border: none; | 49 | border: none; |
50 | border-collapse: collapse; | 50 | border-collapse: collapse; |
51 | } | 51 | } |
52 | 52 | ||
53 | table.list tr { | 53 | table.list tr { |
54 | background: white; | 54 | background: white; |
55 | } | 55 | } |
56 | 56 | ||
57 | table.list tr:hover { | 57 | table.list tr:hover { |
58 | background: #f8f8f8; | 58 | background: #f8f8f8; |
59 | } | 59 | } |
60 | 60 | ||
61 | table.list tr.nohover:hover { | 61 | table.list tr.nohover:hover { |
62 | background: white; | 62 | background: white; |
63 | } | 63 | } |
64 | 64 | ||
65 | table.list th { | 65 | table.list th { |
66 | font-weight: bold; | 66 | font-weight: bold; |
67 | border-bottom: solid 1px #777; | 67 | border-bottom: solid 1px #777; |
68 | padding: 0.1em 0.5em 0.1em 0.5em; | 68 | padding: 0.1em 0.5em 0.1em 0.5em; |
69 | vertical-align: baseline; | 69 | vertical-align: baseline; |
70 | } | 70 | } |
71 | 71 | ||
72 | table.list td { | 72 | table.list td { |
73 | border: none; | 73 | border: none; |
74 | padding: 0.1em 0.5em 0.1em 0.5em; | 74 | padding: 0.1em 0.5em 0.1em 0.5em; |
75 | } | 75 | } |
76 | 76 | ||
77 | img { | 77 | img { |
78 | border: none; | 78 | border: none; |
79 | } | 79 | } |
80 | 80 | ||
81 | div#sidebar { | 81 | table#layout { |
82 | border-collapse: collapse; | ||
83 | border: none; | ||
84 | margin: 0px; | ||
85 | } | ||
86 | |||
87 | td#sidebar { | ||
82 | vertical-align: top; | 88 | vertical-align: top; |
83 | width: 162px; | 89 | width: 162px; |
84 | padding: 0px 0px 0px 0px; | 90 | padding: 0px 0px 0px 0px; |
85 | margin: 4px; | 91 | margin: 0px; |
86 | float: left; | ||
87 | } | 92 | } |
88 | 93 | ||
89 | div#logo { | 94 | td#sidebar table { |
95 | border-collapse: separate; | ||
96 | border-spacing: 0px; | ||
90 | margin: 0px; | 97 | margin: 0px; |
91 | padding: 4px 0px 4px 0px; | 98 | padding: 0px; |
92 | text-align: center; | ||
93 | background-color: #ccc; | 99 | background-color: #ccc; |
100 | } | ||
101 | |||
102 | td#sidebar table.sidebar td.sidebar { | ||
103 | padding: 4px; | ||
94 | border-top: solid 1px #eee; | 104 | border-top: solid 1px #eee; |
95 | border-left: solid 1px #eee; | 105 | border-left: solid 1px #eee; |
96 | border-right: solid 1px #aaa; | 106 | border-right: solid 1px #aaa; |
97 | border-bottom: solid 1px #aaa; | 107 | border-bottom: solid 1px #aaa; |
98 | } | 108 | } |
99 | 109 | ||
100 | div#sidebar div.infobox { | 110 | div#logo { |
101 | margin: 0px 0px 0px 0px; | 111 | margin: 0px; |
102 | padding: 0.5em; | 112 | padding: 4px 0px 4px 0px; |
103 | text-align: left; | 113 | text-align: center; |
104 | background-color: #ccc; | 114 | background-color: #ccc; |
105 | border-top: solid 1px #eee; | 115 | border-top: solid 1px #eee; |
106 | border-left: solid 1px #eee; | 116 | border-left: solid 1px #eee; |
107 | border-right: solid 1px #aaa; | 117 | border-right: solid 1px #aaa; |
108 | border-bottom: solid 1px #aaa; | 118 | border-bottom: solid 1px #aaa; |
109 | } | 119 | } |
110 | 120 | ||
111 | div#sidebar div.infobox h1 { | 121 | td#sidebar h1 { |
112 | font-size: 11pt; | 122 | font-size: 10pt; |
113 | font-weight: bold; | 123 | font-weight: bold; |
114 | margin: 0px; | 124 | margin: 8px 0px 0px 0px; |
115 | } | 125 | } |
116 | 126 | ||
117 | div#sidebar div.infobox a.menu { | 127 | td#sidebar h1.first { |
128 | margin-top: 0px; | ||
129 | } | ||
130 | |||
131 | td#sidebar a.menu { | ||
118 | display: block; | 132 | display: block; |
119 | background-color: #ccc; | 133 | background-color: #ccc; |
120 | padding: 0.1em 0.5em; | 134 | padding: 0.1em 0.5em; |
121 | text-decoration: none; | 135 | text-decoration: none; |
122 | } | 136 | } |
123 | 137 | ||
124 | div#sidebar div.infobox a.menu:hover { | 138 | td#sidebar a.menu:hover { |
125 | background-color: #bbb; | 139 | background-color: #bbb; |
126 | text-decoration: none; | 140 | text-decoration: none; |
127 | } | 141 | } |
128 | 142 | ||
129 | div#sidebar div.infobox select { | 143 | td#sidebar select { |
130 | width: 100%; | 144 | width: 100%; |
131 | border: solid 1px #aaa; | ||
132 | background-color: #bbb; | ||
133 | margin: 2px 0px 0px 0px; | 145 | margin: 2px 0px 0px 0px; |
134 | padding: 0px; | ||
135 | } | 146 | } |
136 | 147 | ||
137 | td#branch-dropdown-cell { | 148 | td#sidebar form { |
138 | width: 99%; | 149 | text-align: right; |
139 | } | 150 | } |
140 | 151 | ||
141 | input#switch-btn { | 152 | input#switch-btn { |
142 | width: 20px; | ||
143 | border: solid 1px #aaa; | ||
144 | background-color: #bbb; | ||
145 | margin: 2px 0px 0px 0px; | 153 | margin: 2px 0px 0px 0px; |
146 | padding: 0px; | ||
147 | } | 154 | } |
148 | 155 | ||
149 | div#sidebar div.infobox input.txt { | 156 | td#sidebar input.txt { |
150 | width: 100%; | 157 | width: 100%; |
151 | border: solid 1px #aaa; | ||
152 | background-color: #bbb; | ||
153 | margin: 2px 0px 0px 0px; | 158 | margin: 2px 0px 0px 0px; |
154 | padding: 0; | ||
155 | } | 159 | } |
156 | 160 | ||
157 | table#grid { | 161 | table#grid { |
158 | margin: 0px; | 162 | margin: 0px; |
159 | } | 163 | } |
160 | 164 | ||
161 | td#content { | 165 | td#content { |
162 | vertical-align: top; | 166 | vertical-align: top; |
163 | padding: 1em 2em 1em 1em; | 167 | padding: 1em 2em 1em 1em; |
164 | border: none; | 168 | border: none; |
165 | } | 169 | } |
166 | 170 | ||
167 | div#summary { | 171 | div#summary { |
168 | vertical-align: top; | 172 | vertical-align: top; |
169 | margin-bottom: 1em; | 173 | margin-bottom: 1em; |
170 | } | 174 | } |
171 | 175 | ||
172 | table#downloads { | 176 | table#downloads { |
173 | float: right; | 177 | float: right; |
174 | border-collapse: collapse; | 178 | border-collapse: collapse; |
175 | border: solid 1px #777; | 179 | border: solid 1px #777; |
176 | margin-left: 0.5em; | 180 | margin-left: 0.5em; |
177 | margin-bottom: 0.5em; | 181 | margin-bottom: 0.5em; |
178 | } | 182 | } |
179 | 183 | ||
180 | table#downloads th { | 184 | table#downloads th { |
181 | background-color: #ccc; | 185 | background-color: #ccc; |
182 | } | 186 | } |
183 | 187 | ||
184 | div#blob { | 188 | div#blob { |
185 | border: solid 1px black; | 189 | border: solid 1px black; |
186 | } | 190 | } |
187 | 191 | ||
188 | div.error { | 192 | div.error { |
189 | color: red; | 193 | color: red; |
190 | font-weight: bold; | 194 | font-weight: bold; |
191 | margin: 1em 2em; | 195 | margin: 1em 2em; |
192 | } | 196 | } |
193 | 197 | ||
194 | a.ls-blob, a.ls-dir, a.ls-mod { | 198 | a.ls-blob, a.ls-dir, a.ls-mod { |
195 | font-family: monospace; | 199 | font-family: monospace; |
196 | } | 200 | } |
197 | 201 | ||
198 | td.ls-size { | 202 | td.ls-size { |
199 | text-align: right; | 203 | text-align: right; |
200 | } | 204 | } |
201 | 205 | ||
202 | td.ls-size { | 206 | td.ls-size { |
203 | font-family: monospace; | 207 | font-family: monospace; |
204 | } | 208 | } |
205 | 209 | ||
206 | td.ls-mode { | 210 | td.ls-mode { |
207 | font-family: monospace; | 211 | font-family: monospace; |
208 | } | 212 | } |
209 | 213 | ||
210 | table.blob { | 214 | table.blob { |
211 | margin-top: 0.5em; | 215 | margin-top: 0.5em; |
212 | border-top: solid 1px black; | 216 | border-top: solid 1px black; |
213 | } | 217 | } |
214 | 218 | ||
215 | table.blob td.no { | 219 | table.blob td.no { |
216 | border-right: solid 1px black; | 220 | border-right: solid 1px black; |
217 | color: black; | 221 | color: black; |
218 | background-color: #eee; | 222 | background-color: #eee; |
219 | text-align: right; | 223 | text-align: right; |
220 | } | 224 | } |
221 | 225 | ||
222 | table.blob td.no a { | 226 | table.blob td.no a { |
223 | color: black; | 227 | color: black; |
224 | } | 228 | } |
225 | 229 | ||
226 | table.blob td.no a:hover { | 230 | table.blob td.no a:hover { |
227 | color: black; | 231 | color: black; |
228 | text-decoration: none; | 232 | text-decoration: none; |
229 | } | 233 | } |
230 | 234 | ||
231 | table.blob td.txt { | 235 | table.blob td.txt { |
232 | white-space: pre; | 236 | white-space: pre; |
233 | font-family: monospace; | 237 | font-family: monospace; |
234 | padding-left: 0.5em; | 238 | padding-left: 0.5em; |
235 | } | 239 | } |
236 | 240 | ||
237 | table.nowrap td { | 241 | table.nowrap td { |
238 | white-space: nowrap; | 242 | white-space: nowrap; |
239 | } | 243 | } |
240 | 244 | ||
241 | table.commit-info { | 245 | table.commit-info { |
242 | border-collapse: collapse; | 246 | border-collapse: collapse; |
243 | margin-top: 1.5em; | 247 | margin-top: 1.5em; |
244 | } | 248 | } |
245 | 249 | ||
246 | table.commit-info th { | 250 | table.commit-info th { |
247 | text-align: left; | 251 | text-align: left; |
248 | font-weight: normal; | 252 | font-weight: normal; |
249 | padding: 0.1em 1em 0.1em 0.1em; | 253 | padding: 0.1em 1em 0.1em 0.1em; |
250 | vertical-align: top; | 254 | vertical-align: top; |
@@ -1,283 +1,295 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | 4 | ||
5 | #include <git-compat-util.h> | 5 | #include <git-compat-util.h> |
6 | #include <cache.h> | 6 | #include <cache.h> |
7 | #include <grep.h> | 7 | #include <grep.h> |
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 | #include <utf8.h> | ||
19 | 20 | ||
20 | 21 | ||
21 | /* | 22 | /* |
22 | * The valid cgit repo-commands | 23 | * The valid cgit repo-commands |
23 | */ | 24 | */ |
24 | #define CMD_LOG 1 | 25 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 | 26 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 27 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 28 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 | 29 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 | 30 | #define CMD_SNAPSHOT 6 |
30 | #define CMD_TAG 7 | 31 | #define CMD_TAG 7 |
31 | #define CMD_REFS 8 | 32 | #define CMD_REFS 8 |
33 | #define CMD_PATCH 9 | ||
32 | 34 | ||
33 | /* | 35 | /* |
34 | * Dateformats used on misc. pages | 36 | * Dateformats used on misc. pages |
35 | */ | 37 | */ |
36 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 38 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
37 | #define FMT_SHORTDATE "%Y-%m-%d" | 39 | #define FMT_SHORTDATE "%Y-%m-%d" |
38 | 40 | ||
39 | 41 | ||
40 | /* | 42 | /* |
41 | * Limits used for relative dates | 43 | * Limits used for relative dates |
42 | */ | 44 | */ |
43 | #define TM_MIN 60 | 45 | #define TM_MIN 60 |
44 | #define TM_HOUR (TM_MIN * 60) | 46 | #define TM_HOUR (TM_MIN * 60) |
45 | #define TM_DAY (TM_HOUR * 24) | 47 | #define TM_DAY (TM_HOUR * 24) |
46 | #define TM_WEEK (TM_DAY * 7) | 48 | #define TM_WEEK (TM_DAY * 7) |
47 | #define TM_YEAR (TM_DAY * 365) | 49 | #define TM_YEAR (TM_DAY * 365) |
48 | #define TM_MONTH (TM_YEAR / 12.0) | 50 | #define TM_MONTH (TM_YEAR / 12.0) |
49 | 51 | ||
50 | 52 | ||
53 | /* | ||
54 | * Default encoding | ||
55 | */ | ||
56 | #define PAGE_ENCODING "UTF-8" | ||
57 | |||
51 | typedef void (*configfn)(const char *name, const char *value); | 58 | typedef void (*configfn)(const char *name, const char *value); |
52 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 59 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
53 | typedef void (*linediff_fn)(char *line, int len); | 60 | typedef void (*linediff_fn)(char *line, int len); |
54 | 61 | ||
55 | struct cacheitem { | 62 | struct cacheitem { |
56 | char *name; | 63 | char *name; |
57 | struct stat st; | 64 | struct stat st; |
58 | int ttl; | 65 | int ttl; |
59 | int fd; | 66 | int fd; |
60 | }; | 67 | }; |
61 | 68 | ||
62 | struct repoinfo { | 69 | struct repoinfo { |
63 | char *url; | 70 | char *url; |
64 | char *name; | 71 | char *name; |
65 | char *path; | 72 | char *path; |
66 | char *desc; | 73 | char *desc; |
67 | char *owner; | 74 | char *owner; |
68 | char *defbranch; | 75 | char *defbranch; |
69 | char *group; | 76 | char *group; |
70 | char *module_link; | 77 | char *module_link; |
71 | char *readme; | 78 | char *readme; |
79 | char *clone_url; | ||
72 | int snapshots; | 80 | int snapshots; |
73 | int enable_log_filecount; | 81 | int enable_log_filecount; |
74 | int enable_log_linecount; | 82 | int enable_log_linecount; |
75 | }; | 83 | }; |
76 | 84 | ||
77 | struct repolist { | 85 | struct repolist { |
78 | int length; | 86 | int length; |
79 | int count; | 87 | int count; |
80 | struct repoinfo *repos; | 88 | struct repoinfo *repos; |
81 | }; | 89 | }; |
82 | 90 | ||
83 | struct commitinfo { | 91 | struct commitinfo { |
84 | struct commit *commit; | 92 | struct commit *commit; |
85 | char *author; | 93 | char *author; |
86 | char *author_email; | 94 | char *author_email; |
87 | unsigned long author_date; | 95 | unsigned long author_date; |
88 | char *committer; | 96 | char *committer; |
89 | char *committer_email; | 97 | char *committer_email; |
90 | unsigned long committer_date; | 98 | unsigned long committer_date; |
91 | char *subject; | 99 | char *subject; |
92 | char *msg; | 100 | char *msg; |
101 | char *msg_encoding; | ||
93 | }; | 102 | }; |
94 | 103 | ||
95 | struct taginfo { | 104 | struct taginfo { |
96 | char *tagger; | 105 | char *tagger; |
97 | char *tagger_email; | 106 | char *tagger_email; |
98 | int tagger_date; | 107 | int tagger_date; |
99 | char *msg; | 108 | char *msg; |
100 | }; | 109 | }; |
101 | 110 | ||
102 | struct refinfo { | 111 | struct refinfo { |
103 | const char *refname; | 112 | const char *refname; |
104 | struct object *object; | 113 | struct object *object; |
105 | union { | 114 | union { |
106 | struct taginfo *tag; | 115 | struct taginfo *tag; |
107 | struct commitinfo *commit; | 116 | struct commitinfo *commit; |
108 | }; | 117 | }; |
109 | }; | 118 | }; |
110 | 119 | ||
111 | struct reflist { | 120 | struct reflist { |
112 | struct refinfo **refs; | 121 | struct refinfo **refs; |
113 | int alloc; | 122 | int alloc; |
114 | int count; | 123 | int count; |
115 | }; | 124 | }; |
116 | 125 | ||
117 | extern const char *cgit_version; | 126 | extern const char *cgit_version; |
118 | 127 | ||
119 | extern struct repolist cgit_repolist; | 128 | extern struct repolist cgit_repolist; |
120 | extern struct repoinfo *cgit_repo; | 129 | extern struct repoinfo *cgit_repo; |
121 | extern int cgit_cmd; | 130 | extern int cgit_cmd; |
122 | 131 | ||
123 | extern char *cgit_root_title; | 132 | extern char *cgit_root_title; |
124 | extern char *cgit_css; | 133 | extern char *cgit_css; |
125 | extern char *cgit_logo; | 134 | extern char *cgit_logo; |
126 | extern char *cgit_index_header; | 135 | extern char *cgit_index_header; |
127 | extern char *cgit_index_info; | 136 | extern char *cgit_index_info; |
128 | extern char *cgit_logo_link; | 137 | extern char *cgit_logo_link; |
129 | extern char *cgit_module_link; | 138 | extern char *cgit_module_link; |
130 | extern char *cgit_agefile; | 139 | extern char *cgit_agefile; |
131 | extern char *cgit_virtual_root; | 140 | extern char *cgit_virtual_root; |
132 | extern char *cgit_script_name; | 141 | extern char *cgit_script_name; |
133 | extern char *cgit_cache_root; | 142 | extern char *cgit_cache_root; |
134 | extern char *cgit_repo_group; | 143 | extern char *cgit_repo_group; |
144 | extern char *cgit_robots; | ||
145 | extern char *cgit_clone_prefix; | ||
135 | 146 | ||
136 | extern int cgit_nocache; | 147 | extern int cgit_nocache; |
137 | extern int cgit_snapshots; | 148 | extern int cgit_snapshots; |
138 | extern int cgit_enable_index_links; | 149 | extern int cgit_enable_index_links; |
139 | extern int cgit_enable_log_filecount; | 150 | extern int cgit_enable_log_filecount; |
140 | extern int cgit_enable_log_linecount; | 151 | extern int cgit_enable_log_linecount; |
141 | extern int cgit_max_lock_attempts; | 152 | extern int cgit_max_lock_attempts; |
142 | extern int cgit_cache_root_ttl; | 153 | extern int cgit_cache_root_ttl; |
143 | extern int cgit_cache_repo_ttl; | 154 | extern int cgit_cache_repo_ttl; |
144 | extern int cgit_cache_dynamic_ttl; | 155 | extern int cgit_cache_dynamic_ttl; |
145 | extern int cgit_cache_static_ttl; | 156 | extern int cgit_cache_static_ttl; |
146 | extern int cgit_cache_max_create_time; | 157 | extern int cgit_cache_max_create_time; |
147 | extern int cgit_summary_log; | 158 | extern int cgit_summary_log; |
148 | extern int cgit_summary_tags; | 159 | extern int cgit_summary_tags; |
149 | extern int cgit_summary_branches; | 160 | extern int cgit_summary_branches; |
150 | 161 | ||
151 | extern int cgit_max_msg_len; | 162 | extern int cgit_max_msg_len; |
152 | extern int cgit_max_repodesc_len; | 163 | extern int cgit_max_repodesc_len; |
153 | extern int cgit_max_commit_count; | 164 | extern int cgit_max_commit_count; |
154 | 165 | ||
155 | extern int cgit_query_has_symref; | 166 | extern int cgit_query_has_symref; |
156 | extern int cgit_query_has_sha1; | 167 | extern int cgit_query_has_sha1; |
157 | 168 | ||
158 | extern char *cgit_querystring; | 169 | extern char *cgit_querystring; |
159 | extern char *cgit_query_repo; | 170 | extern char *cgit_query_repo; |
160 | extern char *cgit_query_page; | 171 | extern char *cgit_query_page; |
161 | extern char *cgit_query_search; | 172 | extern char *cgit_query_search; |
162 | extern char *cgit_query_grep; | 173 | extern char *cgit_query_grep; |
163 | extern char *cgit_query_head; | 174 | extern char *cgit_query_head; |
164 | extern char *cgit_query_sha1; | 175 | extern char *cgit_query_sha1; |
165 | extern char *cgit_query_sha2; | 176 | extern char *cgit_query_sha2; |
166 | extern char *cgit_query_path; | 177 | extern char *cgit_query_path; |
167 | extern char *cgit_query_name; | 178 | extern char *cgit_query_name; |
168 | extern int cgit_query_ofs; | 179 | extern int cgit_query_ofs; |
169 | 180 | ||
170 | extern int htmlfd; | 181 | extern int htmlfd; |
171 | 182 | ||
172 | extern int cgit_get_cmd_index(const char *cmd); | 183 | extern int cgit_get_cmd_index(const char *cmd); |
173 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 184 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
174 | extern void cgit_global_config_cb(const char *name, const char *value); | 185 | extern void cgit_global_config_cb(const char *name, const char *value); |
175 | extern void cgit_repo_config_cb(const char *name, const char *value); | 186 | extern void cgit_repo_config_cb(const char *name, const char *value); |
176 | extern void cgit_querystring_cb(const char *name, const char *value); | 187 | extern void cgit_querystring_cb(const char *name, const char *value); |
177 | 188 | ||
178 | extern int chk_zero(int result, char *msg); | 189 | extern int chk_zero(int result, char *msg); |
179 | extern int chk_positive(int result, char *msg); | 190 | extern int chk_positive(int result, char *msg); |
180 | extern int chk_non_negative(int result, char *msg); | 191 | extern int chk_non_negative(int result, char *msg); |
181 | 192 | ||
182 | extern int hextoint(char c); | 193 | extern int hextoint(char c); |
183 | extern char *trim_end(const char *str, char c); | 194 | extern char *trim_end(const char *str, char c); |
184 | extern char *strlpart(char *txt, int maxlen); | 195 | extern char *strlpart(char *txt, int maxlen); |
185 | extern char *strrpart(char *txt, int maxlen); | 196 | extern char *strrpart(char *txt, int maxlen); |
186 | 197 | ||
187 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 198 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
188 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 199 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
189 | int flags, void *cb_data); | 200 | int flags, void *cb_data); |
190 | 201 | ||
191 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 202 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
192 | 203 | ||
193 | extern int cgit_diff_files(const unsigned char *old_sha1, | 204 | extern int cgit_diff_files(const unsigned char *old_sha1, |
194 | const unsigned char *new_sha1, | 205 | const unsigned char *new_sha1, |
195 | linediff_fn fn); | 206 | linediff_fn fn); |
196 | 207 | ||
197 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 208 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
198 | const unsigned char *new_sha1, | 209 | const unsigned char *new_sha1, |
199 | filepair_fn fn, const char *prefix); | 210 | filepair_fn fn, const char *prefix); |
200 | 211 | ||
201 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 212 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
202 | 213 | ||
203 | extern char *fmt(const char *format,...); | 214 | extern char *fmt(const char *format,...); |
204 | 215 | ||
205 | extern void html(const char *txt); | 216 | extern void html(const char *txt); |
206 | extern void htmlf(const char *format,...); | 217 | extern void htmlf(const char *format,...); |
207 | extern void html_txt(char *txt); | 218 | extern void html_txt(char *txt); |
208 | extern void html_ntxt(int len, char *txt); | 219 | extern void html_ntxt(int len, char *txt); |
209 | extern void html_attr(char *txt); | 220 | extern void html_attr(char *txt); |
210 | extern void html_hidden(char *name, char *value); | 221 | extern void html_hidden(char *name, char *value); |
211 | extern void html_option(char *value, char *text, char *selected_value); | 222 | extern void html_option(char *value, char *text, char *selected_value); |
212 | extern void html_link_open(char *url, char *title, char *class); | 223 | extern void html_link_open(char *url, char *title, char *class); |
213 | extern void html_link_close(void); | 224 | extern void html_link_close(void); |
214 | extern void html_filemode(unsigned short mode); | 225 | extern void html_filemode(unsigned short mode); |
215 | extern int html_include(const char *filename); | 226 | extern int html_include(const char *filename); |
216 | 227 | ||
217 | extern int cgit_read_config(const char *filename, configfn fn); | 228 | extern int cgit_read_config(const char *filename, configfn fn); |
218 | extern int cgit_parse_query(char *txt, configfn fn); | 229 | extern int cgit_parse_query(char *txt, configfn fn); |
219 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 230 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
220 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 231 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
221 | extern void cgit_parse_url(const char *url); | 232 | extern void cgit_parse_url(const char *url); |
222 | 233 | ||
223 | extern char *cache_safe_filename(const char *unsafe); | 234 | extern char *cache_safe_filename(const char *unsafe); |
224 | extern int cache_lock(struct cacheitem *item); | 235 | extern int cache_lock(struct cacheitem *item); |
225 | extern int cache_unlock(struct cacheitem *item); | 236 | extern int cache_unlock(struct cacheitem *item); |
226 | extern int cache_cancel_lock(struct cacheitem *item); | 237 | extern int cache_cancel_lock(struct cacheitem *item); |
227 | extern int cache_exist(struct cacheitem *item); | 238 | extern int cache_exist(struct cacheitem *item); |
228 | extern int cache_expired(struct cacheitem *item); | 239 | extern int cache_expired(struct cacheitem *item); |
229 | 240 | ||
230 | extern char *cgit_repourl(const char *reponame); | 241 | extern char *cgit_repourl(const char *reponame); |
231 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 242 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
232 | const char *filename, const char *query); | 243 | const char *filename, const char *query); |
233 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 244 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
234 | const char *query); | 245 | const char *query); |
235 | 246 | ||
236 | extern const char *cgit_repobasename(const char *reponame); | 247 | extern const char *cgit_repobasename(const char *reponame); |
237 | 248 | ||
238 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 249 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
239 | char *rev, char *path); | 250 | char *rev, char *path); |
240 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 251 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
241 | char *rev, char *path, int ofs, char *grep, | 252 | char *rev, char *path, int ofs, char *grep, |
242 | char *pattern); | 253 | char *pattern); |
243 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 254 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
244 | char *rev); | 255 | char *rev); |
245 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | 256 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
246 | char *rev, char *path); | 257 | char *rev, char *path); |
247 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 258 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
248 | char *head, char *rev, char *archivename); | 259 | char *head, char *rev, char *archivename); |
249 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 260 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
250 | char *new_rev, char *old_rev, char *path); | 261 | char *new_rev, char *old_rev, char *path); |
251 | 262 | ||
252 | extern void cgit_object_link(struct object *obj); | 263 | extern void cgit_object_link(struct object *obj); |
253 | 264 | ||
254 | extern void cgit_print_error(char *msg); | 265 | extern void cgit_print_error(char *msg); |
255 | extern void cgit_print_date(time_t secs, char *format); | 266 | extern void cgit_print_date(time_t secs, char *format); |
256 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 267 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
257 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 268 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
258 | extern void cgit_print_docend(); | 269 | extern void cgit_print_docend(); |
259 | extern void cgit_print_pageheader(char *title, int show_search); | 270 | extern void cgit_print_pageheader(char *title, int show_search); |
260 | extern void cgit_print_snapshot_start(const char *mimetype, | 271 | extern void cgit_print_snapshot_start(const char *mimetype, |
261 | const char *filename, | 272 | const char *filename, |
262 | struct cacheitem *item); | 273 | struct cacheitem *item); |
263 | extern void cgit_print_branches(int maxcount); | 274 | extern void cgit_print_branches(int maxcount); |
264 | extern void cgit_print_tags(int maxcount); | 275 | extern void cgit_print_tags(int maxcount); |
265 | 276 | ||
266 | extern void cgit_print_repolist(struct cacheitem *item); | 277 | extern void cgit_print_repolist(struct cacheitem *item); |
267 | extern void cgit_print_summary(); | 278 | extern void cgit_print_summary(); |
268 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, | 279 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, |
269 | char *pattern, char *path, int pager); | 280 | char *pattern, char *path, int pager); |
270 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 281 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
271 | extern void cgit_print_tree(const char *rev, char *path); | 282 | extern void cgit_print_tree(const char *rev, char *path); |
272 | extern void cgit_print_commit(char *hex); | 283 | extern void cgit_print_commit(char *hex); |
273 | extern void cgit_print_refs(); | 284 | extern void cgit_print_refs(); |
274 | extern void cgit_print_tag(char *revname); | 285 | extern void cgit_print_tag(char *revname); |
275 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 286 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
287 | extern void cgit_print_patch(char *hex, struct cacheitem *item); | ||
276 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 288 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
277 | const char *hex, const char *prefix, | 289 | const char *hex, const char *prefix, |
278 | const char *filename, int snapshot); | 290 | const char *filename, int snapshot); |
279 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 291 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
280 | const char *hex, int snapshots); | 292 | const char *hex, int snapshots); |
281 | extern int cgit_parse_snapshots_mask(const char *str); | 293 | extern int cgit_parse_snapshots_mask(const char *str); |
282 | 294 | ||
283 | #endif /* CGIT_H */ | 295 | #endif /* CGIT_H */ |
Binary files differ | |||
@@ -1,182 +1,194 @@ | |||
1 | ## | 1 | ## |
2 | ## cgitrc: template for /etc/cgitrc | 2 | ## cgitrc: template for /etc/cgitrc |
3 | ## | 3 | ## |
4 | 4 | ||
5 | 5 | ||
6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly | 6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly |
7 | ## usefull for testing. | 7 | ## usefull for testing. |
8 | #nocache=0 | 8 | #nocache=0 |
9 | 9 | ||
10 | 10 | ||
11 | ## This variable can be used to override the default value for "robots" | ||
12 | ## meta-tag. If unset, the meta-tag isn't generated. | ||
13 | #robots=index, nofollow | ||
14 | |||
15 | |||
11 | ## Set allowed snapshot types by default. Can be overridden per repo | 16 | ## Set allowed snapshot types by default. Can be overridden per repo |
12 | # can be any combination of zip/tar.gz/tar.bz2/tar | 17 | # can be any combination of zip/tar.gz/tar.bz2/tar |
13 | #snapshots=0 | 18 | #snapshots=0 |
14 | 19 | ||
15 | 20 | ||
16 | ## Enable/disable extra links to summary/log/tree per repo on index page | 21 | ## Enable/disable extra links to summary/log/tree per repo on index page |
17 | #enable-index-links=0 | 22 | #enable-index-links=0 |
18 | 23 | ||
19 | 24 | ||
20 | ## Enable/disable display of 'number of files changed' in log view | 25 | ## Enable/disable display of 'number of files changed' in log view |
21 | #enable-log-filecount=0 | 26 | #enable-log-filecount=0 |
22 | 27 | ||
23 | 28 | ||
24 | ## Enable/disable display of 'number of lines changed' in log view | 29 | ## Enable/disable display of 'number of lines changed' in log view |
25 | #enable-log-linecount=0 | 30 | #enable-log-linecount=0 |
26 | 31 | ||
27 | 32 | ||
28 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum | 33 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum |
29 | ## number of commits that should be displayed | 34 | ## number of commits that should be displayed |
30 | #summary-log=0 | 35 | #summary-log=0 |
31 | 36 | ||
32 | 37 | ||
33 | ## Restrict the number of branches printed in summary view. Set to 0 to | 38 | ## Restrict the number of branches printed in summary view. Set to 0 to |
34 | ## print all branches. | 39 | ## print all branches. |
35 | #summary-branches=0 | 40 | #summary-branches=0 |
36 | 41 | ||
37 | 42 | ||
38 | ## Restrict the number of tags printed in summary view. Set to 0 to | 43 | ## Restrict the number of tags printed in summary view. Set to 0 to |
39 | ## print all tags. | 44 | ## print all tags. |
40 | #summary-tags=0 | 45 | #summary-tags=0 |
41 | 46 | ||
42 | 47 | ||
43 | ## The "Idle" column on the repository index page can read a timestamp | 48 | ## The "Idle" column on the repository index page can read a timestamp |
44 | ## from the specified agefile (if this file cannot be found, the mtime | 49 | ## from the specified agefile (if this file cannot be found, the mtime |
45 | ## of HEAD is used). | 50 | ## of HEAD is used). |
46 | ## The cgit repo on hjemli.net uses the the following command in it's | 51 | ## The cgit repo on hjemli.net uses the the following command in it's |
47 | ## post-receive hook to update the age-file: | 52 | ## post-receive hook to update the age-file: |
48 | ## git-for-each-ref --format="%(committerdate)" --sort=-committerdate \ | 53 | ## git-for-each-ref --format="%(committerdate)" --sort=-committerdate \ |
49 | ## --count=1 > $GIT_DIR/info/web/last-modifie | 54 | ## --count=1 > $GIT_DIR/info/web/last-modifie |
50 | ## | 55 | ## |
51 | #agefile=info/web/last-modified | 56 | #agefile=info/web/last-modified |
52 | 57 | ||
53 | 58 | ||
54 | ## Git detects renames, but with a limit on the number of files to | 59 | ## Git detects renames, but with a limit on the number of files to |
55 | ## consider. This option can be used to specify another limit (or -1 to | 60 | ## consider. This option can be used to specify another limit (or -1 to |
56 | ## use the default limit). | 61 | ## use the default limit). |
57 | ## | 62 | ## |
58 | #renamelimit=-1 | 63 | #renamelimit=-1 |
59 | 64 | ||
60 | 65 | ||
61 | ## Specify a root for virtual urls. This makes cgit generate urls like | 66 | ## Specify a root for virtual urls. This makes cgit generate urls like |
62 | ## | 67 | ## |
63 | ## http://localhost/git/repo/log/?h=branch | 68 | ## http://localhost/git/repo/log/?h=branch |
64 | ## | 69 | ## |
65 | ## instead of | 70 | ## instead of |
66 | ## | 71 | ## |
67 | ## http://localhost/cgit/cgit.cgi?url=repo/log&h=branch | 72 | ## http://localhost/cgit/cgit.cgi?url=repo/log&h=branch |
68 | ## | 73 | ## |
69 | ## For this to work with apache, a rewrite rule must be added to httpd.conf, | 74 | ## For this to work with apache, a rewrite rule must be added to httpd.conf, |
70 | ## possibly looking something like this: | 75 | ## possibly looking something like this: |
71 | ## | 76 | ## |
72 | ## RewriteRule ^/git/(.*)$ /cgit/cgit.cgi?url=$1 [L,QSA] | 77 | ## RewriteRule ^/git/(.*)$ /cgit/cgit.cgi?url=$1 [L,QSA] |
73 | ## | 78 | ## |
74 | ## For this to work with lighttpd, the rewrite rule should look more like this: | 79 | ## For this to work with lighttpd, the rewrite rule should look more like this: |
75 | ## | 80 | ## |
76 | ## url.rewrite = ( | 81 | ## url.rewrite = ( |
77 | ## "^/git/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2" | 82 | ## "^/git/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2" |
78 | ## ) | 83 | ## ) |
79 | ## | 84 | ## |
80 | ## This setting is disabled by default. | 85 | ## This setting is disabled by default. |
81 | #virtual-root=/git | 86 | #virtual-root=/git |
82 | 87 | ||
83 | 88 | ||
84 | ## Set the title printed on the root page | 89 | ## Set the title printed on the root page |
85 | #root-title=Git repository browser | 90 | #root-title=Git repository browser |
86 | 91 | ||
87 | 92 | ||
88 | ## If specified, the file at this path will be included as HTML in the | 93 | ## If specified, the file at this path will be included as HTML in the |
89 | ## sidebar on the repository index page | 94 | ## sidebar on the repository index page |
90 | #index-info= | 95 | #index-info= |
91 | 96 | ||
92 | 97 | ||
93 | ## If specified, the file at this path will be included as HTML above | 98 | ## If specified, the file at this path will be included as HTML above |
94 | ## the repository index | 99 | ## the repository index |
95 | #index-header= | 100 | #index-header= |
96 | 101 | ||
97 | 102 | ||
98 | ## Link to css file | 103 | ## Link to css file |
99 | #css=/cgit/cgit.css | 104 | #css=/cgit/cgit.css |
100 | 105 | ||
101 | 106 | ||
102 | ## Link to logo file | 107 | ## Link to logo file |
103 | #logo=/cgit/git-logo.png | 108 | #logo=/cgit/git-logo.png |
104 | 109 | ||
105 | 110 | ||
106 | ## Url loaded when clicking the logo | 111 | ## Url loaded when clicking the logo |
107 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ | 112 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ |
108 | 113 | ||
109 | 114 | ||
110 | ## Url loaded when clicking a submodule link | 115 | ## Url loaded when clicking a submodule link |
111 | #module-link=./?repo=%s&page=commit&id=%s | 116 | #module-link=./?repo=%s&page=commit&id=%s |
112 | 117 | ||
113 | 118 | ||
119 | ## Shared prefix which, when combined with repo url, becomes the url used | ||
120 | ## to clone the repo | ||
121 | #clone-prefix= | ||
122 | |||
123 | |||
114 | ## Number of chars shown of repo description (in repolist view) | 124 | ## Number of chars shown of repo description (in repolist view) |
115 | #max-repodesc-length=60 | 125 | #max-repodesc-length=60 |
116 | 126 | ||
117 | 127 | ||
118 | ## Number of chars shown of commit subject message (in log view) | 128 | ## Number of chars shown of commit subject message (in log view) |
119 | #max-message-length=60 | 129 | #max-message-length=60 |
120 | 130 | ||
121 | 131 | ||
122 | ## Number of commits per page in log view | 132 | ## Number of commits per page in log view |
123 | #max-commit-count=50 | 133 | #max-commit-count=50 |
124 | 134 | ||
125 | 135 | ||
126 | ## Root of cached output | 136 | ## Root of cached output |
127 | #cache-root=/var/cache/cgit | 137 | #cache-root=/var/cache/cgit |
128 | 138 | ||
129 | 139 | ||
130 | ## Include another config-file | 140 | ## Include another config-file |
131 | #include=/var/cgit/repolist | 141 | #include=/var/cgit/repolist |
132 | 142 | ||
133 | ## | 143 | ## |
134 | ## Time-To-Live settings: specifies how long (in minutes) different pages | 144 | ## Time-To-Live settings: specifies how long (in minutes) different pages |
135 | ## should be cached (0 for instant expiration, -1 for immortal pages) | 145 | ## should be cached (0 for instant expiration, -1 for immortal pages) |
136 | ## | 146 | ## |
137 | 147 | ||
138 | ## ttl for root page | 148 | ## ttl for root page |
139 | #cache-root-ttl=5 | 149 | #cache-root-ttl=5 |
140 | 150 | ||
141 | ## ttl for repo summary page | 151 | ## ttl for repo summary page |
142 | #cache-repo-ttl=5 | 152 | #cache-repo-ttl=5 |
143 | 153 | ||
144 | ## ttl for other dynamic pages | 154 | ## ttl for other dynamic pages |
145 | #cache-dynamic-ttl=5 | 155 | #cache-dynamic-ttl=5 |
146 | 156 | ||
147 | ## ttl for static pages (addressed by SHA-1) | 157 | ## ttl for static pages (addressed by SHA-1) |
148 | #cache-static-ttl=-1 | 158 | #cache-static-ttl=-1 |
149 | 159 | ||
150 | 160 | ||
151 | 161 | ||
152 | ## Example repository entry. Required values are repo.url and repo.path (each | 162 | ## Example repository entry. Required values are repo.url and repo.path (each |
153 | ## repository section must start with repo.url). | 163 | ## repository section must start with repo.url). |
154 | #repo.url=cgit | 164 | #repo.url=cgit |
155 | #repo.name=cgit | 165 | #repo.name=cgit |
156 | #repo.desc=the caching cgi for git | 166 | #repo.desc=the caching cgi for git |
157 | #repo.path=/pub/git/cgit ## this is the path to $GIT_DIR | 167 | #repo.path=/pub/git/cgit ## this is the path to $GIT_DIR |
158 | #repo.owner=Lars Hjemli | 168 | #repo.owner=Lars Hjemli |
159 | #repo.defbranch=master ## define a default branch | 169 | #repo.defbranch=master ## define a default branch |
160 | #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting | 170 | #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting |
161 | #repo.enable-log-filecount=0 ## override the default filecount setting | 171 | #repo.enable-log-filecount=0 ## override the default filecount setting |
162 | #repo.enable-log-linecount=0 ## override the default linecount setting | 172 | #repo.enable-log-linecount=0 ## override the default linecount setting |
163 | #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link | 173 | #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link |
164 | #repo.readme=info/web/readme ## specify a file to include on summary page | 174 | #repo.readme=info/web/readme ## specify a file to include on summary page |
175 | #repo.clone-url=git://hjemli.net/pub/git/cgit | ||
165 | 176 | ||
166 | ## Additional repositories grouped under "mirrors" | 177 | ## Additional repositories grouped under "mirrors" |
167 | #repo.group=mirrors | 178 | #repo.group=mirrors |
168 | 179 | ||
169 | #repo.url=git | 180 | #repo.url=git |
170 | #repo.path=/pub/git/git | 181 | #repo.path=/pub/git/git |
182 | #repo.clone-url=git://hjemli.net/pub/git/git | ||
171 | # | 183 | # |
172 | #repo.url=linux | 184 | #repo.url=linux |
173 | #repo.path=/pub/git/linux | 185 | #repo.path=/pub/git/linux |
174 | 186 | ||
175 | ## A group of private repositories (with a working directory) | 187 | ## A group of private repositories (with a working directory) |
176 | #repo.group=private | 188 | #repo.group=private |
177 | 189 | ||
178 | #repo.url=larsh/cgit | 190 | #repo.url=larsh/cgit |
179 | #repo.path=/home/larsh/src/cgit/.git | 191 | #repo.path=/home/larsh/src/cgit/.git |
180 | 192 | ||
181 | #repo.url=larsh/git | 193 | #repo.url=larsh/git |
182 | #repo.path=/home/larsh/src/git/.git | 194 | #repo.path=/home/larsh/src/git/.git |
@@ -39,156 +39,156 @@ void htmlf(const char *format, ...) | |||
39 | va_start(args, format); | 39 | va_start(args, format); |
40 | vsnprintf(buf, sizeof(buf), format, args); | 40 | vsnprintf(buf, sizeof(buf), format, args); |
41 | va_end(args); | 41 | va_end(args); |
42 | html(buf); | 42 | html(buf); |
43 | } | 43 | } |
44 | 44 | ||
45 | void html_txt(char *txt) | 45 | void html_txt(char *txt) |
46 | { | 46 | { |
47 | char *t = txt; | 47 | char *t = txt; |
48 | while(t && *t){ | 48 | while(t && *t){ |
49 | int c = *t; | 49 | int c = *t; |
50 | if (c=='<' || c=='>' || c=='&') { | 50 | if (c=='<' || c=='>' || c=='&') { |
51 | *t = '\0'; | 51 | *t = '\0'; |
52 | html(txt); | 52 | html(txt); |
53 | *t = c; | 53 | *t = c; |
54 | if (c=='>') | 54 | if (c=='>') |
55 | html(">"); | 55 | html(">"); |
56 | else if (c=='<') | 56 | else if (c=='<') |
57 | html("<"); | 57 | html("<"); |
58 | else if (c=='&') | 58 | else if (c=='&') |
59 | html("&"); | 59 | html("&"); |
60 | txt = t+1; | 60 | txt = t+1; |
61 | } | 61 | } |
62 | t++; | 62 | t++; |
63 | } | 63 | } |
64 | if (t!=txt) | 64 | if (t!=txt) |
65 | html(txt); | 65 | html(txt); |
66 | } | 66 | } |
67 | 67 | ||
68 | void html_ntxt(int len, char *txt) | 68 | void html_ntxt(int len, char *txt) |
69 | { | 69 | { |
70 | char *t = txt; | 70 | char *t = txt; |
71 | while(t && *t && len--){ | 71 | while(t && *t && len--){ |
72 | int c = *t; | 72 | int c = *t; |
73 | if (c=='<' || c=='>' || c=='&') { | 73 | if (c=='<' || c=='>' || c=='&') { |
74 | *t = '\0'; | 74 | *t = '\0'; |
75 | html(txt); | 75 | html(txt); |
76 | *t = c; | 76 | *t = c; |
77 | if (c=='>') | 77 | if (c=='>') |
78 | html(">"); | 78 | html(">"); |
79 | else if (c=='<') | 79 | else if (c=='<') |
80 | html("<"); | 80 | html("<"); |
81 | else if (c=='&') | 81 | else if (c=='&') |
82 | html("&"); | 82 | html("&"); |
83 | txt = t+1; | 83 | txt = t+1; |
84 | } | 84 | } |
85 | t++; | 85 | t++; |
86 | } | 86 | } |
87 | if (t!=txt) { | 87 | if (t!=txt) { |
88 | char c = *t; | 88 | char c = *t; |
89 | *t = '\0'; | 89 | *t = '\0'; |
90 | html(txt); | 90 | html(txt); |
91 | *t = c; | 91 | *t = c; |
92 | } | 92 | } |
93 | if (len<0) | 93 | if (len<0) |
94 | html("..."); | 94 | html("..."); |
95 | } | 95 | } |
96 | 96 | ||
97 | void html_attr(char *txt) | 97 | void html_attr(char *txt) |
98 | { | 98 | { |
99 | char *t = txt; | 99 | char *t = txt; |
100 | while(t && *t){ | 100 | while(t && *t){ |
101 | int c = *t; | 101 | int c = *t; |
102 | if (c=='<' || c=='>' || c=='\'') { | 102 | if (c=='<' || c=='>' || c=='\'') { |
103 | *t = '\0'; | 103 | *t = '\0'; |
104 | html(txt); | 104 | html(txt); |
105 | *t = c; | 105 | *t = c; |
106 | if (c=='>') | 106 | if (c=='>') |
107 | html(">"); | 107 | html(">"); |
108 | else if (c=='<') | 108 | else if (c=='<') |
109 | html("<"); | 109 | html("<"); |
110 | else if (c=='\'') | 110 | else if (c=='\'') |
111 | html(""e;"); | 111 | html(""e;"); |
112 | txt = t+1; | 112 | txt = t+1; |
113 | } | 113 | } |
114 | t++; | 114 | t++; |
115 | } | 115 | } |
116 | if (t!=txt) | 116 | if (t!=txt) |
117 | html(txt); | 117 | html(txt); |
118 | } | 118 | } |
119 | 119 | ||
120 | void html_hidden(char *name, char *value) | 120 | void html_hidden(char *name, char *value) |
121 | { | 121 | { |
122 | html("<input type='hidden' name='"); | 122 | html("<input type='hidden' name='"); |
123 | html_attr(name); | 123 | html_attr(name); |
124 | html("' value='"); | 124 | html("' value='"); |
125 | html_attr(value); | 125 | html_attr(value); |
126 | html("'/>"); | 126 | html("'/>"); |
127 | } | 127 | } |
128 | 128 | ||
129 | void html_option(char *value, char *text, char *selected_value) | 129 | void html_option(char *value, char *text, char *selected_value) |
130 | { | 130 | { |
131 | html("<option value='"); | 131 | html("<option value='"); |
132 | html_attr(value); | 132 | html_attr(value); |
133 | html("'"); | 133 | html("'"); |
134 | if (selected_value && !strcmp(selected_value, value)) | 134 | if (selected_value && !strcmp(selected_value, value)) |
135 | html(" selected"); | 135 | html(" selected='selected'"); |
136 | html(">"); | 136 | html(">"); |
137 | html_txt(text); | 137 | html_txt(text); |
138 | html("</option>\n"); | 138 | html("</option>\n"); |
139 | } | 139 | } |
140 | 140 | ||
141 | void html_link_open(char *url, char *title, char *class) | 141 | void html_link_open(char *url, char *title, char *class) |
142 | { | 142 | { |
143 | html("<a href='"); | 143 | html("<a href='"); |
144 | html_attr(url); | 144 | html_attr(url); |
145 | if (title) { | 145 | if (title) { |
146 | html("' title='"); | 146 | html("' title='"); |
147 | html_attr(title); | 147 | html_attr(title); |
148 | } | 148 | } |
149 | if (class) { | 149 | if (class) { |
150 | html("' class='"); | 150 | html("' class='"); |
151 | html_attr(class); | 151 | html_attr(class); |
152 | } | 152 | } |
153 | html("'>"); | 153 | html("'>"); |
154 | } | 154 | } |
155 | 155 | ||
156 | void html_link_close(void) | 156 | void html_link_close(void) |
157 | { | 157 | { |
158 | html("</a>"); | 158 | html("</a>"); |
159 | } | 159 | } |
160 | 160 | ||
161 | void html_fileperm(unsigned short mode) | 161 | void html_fileperm(unsigned short mode) |
162 | { | 162 | { |
163 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 163 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
164 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 164 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
165 | } | 165 | } |
166 | 166 | ||
167 | void html_filemode(unsigned short mode) | 167 | void html_filemode(unsigned short mode) |
168 | { | 168 | { |
169 | if (S_ISDIR(mode)) | 169 | if (S_ISDIR(mode)) |
170 | html("d"); | 170 | html("d"); |
171 | else if (S_ISLNK(mode)) | 171 | else if (S_ISLNK(mode)) |
172 | html("l"); | 172 | html("l"); |
173 | else if (S_ISGITLINK(mode)) | 173 | else if (S_ISGITLINK(mode)) |
174 | html("m"); | 174 | html("m"); |
175 | else | 175 | else |
176 | html("-"); | 176 | html("-"); |
177 | html_fileperm(mode >> 6); | 177 | html_fileperm(mode >> 6); |
178 | html_fileperm(mode >> 3); | 178 | html_fileperm(mode >> 3); |
179 | html_fileperm(mode); | 179 | html_fileperm(mode); |
180 | } | 180 | } |
181 | 181 | ||
182 | int html_include(const char *filename) | 182 | int html_include(const char *filename) |
183 | { | 183 | { |
184 | FILE *f; | 184 | FILE *f; |
185 | char buf[4096]; | 185 | char buf[4096]; |
186 | size_t len; | 186 | size_t len; |
187 | 187 | ||
188 | if (!(f = fopen(filename, "r"))) | 188 | if (!(f = fopen(filename, "r"))) |
189 | return -1; | 189 | return -1; |
190 | while((len = fread(buf, 1, 4096, f)) > 0) | 190 | while((len = fread(buf, 1, 4096, f)) > 0) |
191 | write(htmlfd, buf, len); | 191 | write(htmlfd, buf, len); |
192 | fclose(f); | 192 | fclose(f); |
193 | return 0; | 193 | return 0; |
194 | } | 194 | } |
@@ -106,202 +106,227 @@ int cgit_parse_query(char *txt, configfn fn) | |||
106 | { | 106 | { |
107 | char *t, *value = NULL, c; | 107 | char *t, *value = NULL, c; |
108 | 108 | ||
109 | if (!txt) | 109 | if (!txt) |
110 | return 0; | 110 | return 0; |
111 | 111 | ||
112 | t = txt = xstrdup(txt); | 112 | t = txt = xstrdup(txt); |
113 | 113 | ||
114 | while((c=*t) != '\0') { | 114 | while((c=*t) != '\0') { |
115 | if (c=='=') { | 115 | if (c=='=') { |
116 | *t = '\0'; | 116 | *t = '\0'; |
117 | value = t+1; | 117 | value = t+1; |
118 | } else if (c=='+') { | 118 | } else if (c=='+') { |
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 | /* | 135 | /* |
136 | * url syntax: [repo ['/' cmd [ '/' path]]] | 136 | * url syntax: [repo ['/' cmd [ '/' path]]] |
137 | * repo: any valid repo url, may contain '/' | 137 | * repo: any valid repo url, may contain '/' |
138 | * cmd: log | commit | diff | tree | view | blob | snapshot | 138 | * cmd: log | commit | diff | tree | view | blob | snapshot |
139 | * path: any valid path, may contain '/' | 139 | * path: any valid path, may contain '/' |
140 | * | 140 | * |
141 | */ | 141 | */ |
142 | void cgit_parse_url(const char *url) | 142 | void cgit_parse_url(const char *url) |
143 | { | 143 | { |
144 | char *cmd, *p; | 144 | char *cmd, *p; |
145 | 145 | ||
146 | cgit_repo = NULL; | 146 | cgit_repo = NULL; |
147 | if (!url || url[0] == '\0') | 147 | if (!url || url[0] == '\0') |
148 | return; | 148 | return; |
149 | 149 | ||
150 | cgit_repo = cgit_get_repoinfo(url); | 150 | cgit_repo = cgit_get_repoinfo(url); |
151 | if (cgit_repo) { | 151 | if (cgit_repo) { |
152 | cgit_query_repo = cgit_repo->url; | 152 | cgit_query_repo = cgit_repo->url; |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | 155 | ||
156 | cmd = strchr(url, '/'); | 156 | cmd = strchr(url, '/'); |
157 | while (!cgit_repo && cmd) { | 157 | while (!cgit_repo && cmd) { |
158 | cmd[0] = '\0'; | 158 | cmd[0] = '\0'; |
159 | cgit_repo = cgit_get_repoinfo(url); | 159 | cgit_repo = cgit_get_repoinfo(url); |
160 | if (cgit_repo == NULL) { | 160 | if (cgit_repo == NULL) { |
161 | cmd[0] = '/'; | 161 | cmd[0] = '/'; |
162 | cmd = strchr(cmd + 1, '/'); | 162 | cmd = strchr(cmd + 1, '/'); |
163 | continue; | 163 | continue; |
164 | } | 164 | } |
165 | 165 | ||
166 | cgit_query_repo = cgit_repo->url; | 166 | cgit_query_repo = cgit_repo->url; |
167 | p = strchr(cmd + 1, '/'); | 167 | p = strchr(cmd + 1, '/'); |
168 | if (p) { | 168 | if (p) { |
169 | p[0] = '\0'; | 169 | p[0] = '\0'; |
170 | if (p[1]) | 170 | if (p[1]) |
171 | cgit_query_path = trim_end(p + 1, '/'); | 171 | cgit_query_path = trim_end(p + 1, '/'); |
172 | } | 172 | } |
173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); | 173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); |
174 | cgit_query_page = xstrdup(cmd + 1); | 174 | cgit_query_page = xstrdup(cmd + 1); |
175 | return; | 175 | return; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | char *substr(const char *head, const char *tail) | 179 | char *substr(const char *head, const char *tail) |
180 | { | 180 | { |
181 | char *buf; | 181 | char *buf; |
182 | 182 | ||
183 | buf = xmalloc(tail - head + 1); | 183 | buf = xmalloc(tail - head + 1); |
184 | strncpy(buf, head, tail - head); | 184 | strncpy(buf, head, tail - head); |
185 | buf[tail - head] = '\0'; | 185 | buf[tail - head] = '\0'; |
186 | return buf; | 186 | return buf; |
187 | } | 187 | } |
188 | 188 | ||
189 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 189 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
190 | { | 190 | { |
191 | struct commitinfo *ret; | 191 | struct commitinfo *ret; |
192 | char *p = commit->buffer, *t = commit->buffer; | 192 | char *p = commit->buffer, *t = commit->buffer; |
193 | 193 | ||
194 | ret = xmalloc(sizeof(*ret)); | 194 | ret = xmalloc(sizeof(*ret)); |
195 | ret->commit = commit; | 195 | ret->commit = commit; |
196 | ret->author = NULL; | 196 | ret->author = NULL; |
197 | ret->author_email = NULL; | 197 | ret->author_email = NULL; |
198 | ret->committer = NULL; | 198 | ret->committer = NULL; |
199 | ret->committer_email = NULL; | 199 | ret->committer_email = NULL; |
200 | ret->subject = NULL; | 200 | ret->subject = NULL; |
201 | ret->msg = NULL; | 201 | ret->msg = NULL; |
202 | ret->msg_encoding = NULL; | ||
202 | 203 | ||
203 | if (p == NULL) | 204 | if (p == NULL) |
204 | return ret; | 205 | return ret; |
205 | 206 | ||
206 | if (strncmp(p, "tree ", 5)) | 207 | if (strncmp(p, "tree ", 5)) |
207 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); | 208 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); |
208 | else | 209 | else |
209 | p += 46; // "tree " + hex[40] + "\n" | 210 | p += 46; // "tree " + hex[40] + "\n" |
210 | 211 | ||
211 | while (!strncmp(p, "parent ", 7)) | 212 | while (!strncmp(p, "parent ", 7)) |
212 | p += 48; // "parent " + hex[40] + "\n" | 213 | p += 48; // "parent " + hex[40] + "\n" |
213 | 214 | ||
214 | if (!strncmp(p, "author ", 7)) { | 215 | if (!strncmp(p, "author ", 7)) { |
215 | p += 7; | 216 | p += 7; |
216 | t = strchr(p, '<') - 1; | 217 | t = strchr(p, '<') - 1; |
217 | ret->author = substr(p, t); | 218 | ret->author = substr(p, t); |
218 | p = t; | 219 | p = t; |
219 | t = strchr(t, '>') + 1; | 220 | t = strchr(t, '>') + 1; |
220 | ret->author_email = substr(p, t); | 221 | ret->author_email = substr(p, t); |
221 | ret->author_date = atol(t+1); | 222 | ret->author_date = atol(t+1); |
222 | p = strchr(t, '\n') + 1; | 223 | p = strchr(t, '\n') + 1; |
223 | } | 224 | } |
224 | 225 | ||
225 | if (!strncmp(p, "committer ", 9)) { | 226 | if (!strncmp(p, "committer ", 9)) { |
226 | p += 9; | 227 | p += 9; |
227 | t = strchr(p, '<') - 1; | 228 | t = strchr(p, '<') - 1; |
228 | ret->committer = substr(p, t); | 229 | ret->committer = substr(p, t); |
229 | p = t; | 230 | p = t; |
230 | t = strchr(t, '>') + 1; | 231 | t = strchr(t, '>') + 1; |
231 | ret->committer_email = substr(p, t); | 232 | ret->committer_email = substr(p, t); |
232 | ret->committer_date = atol(t+1); | 233 | ret->committer_date = atol(t+1); |
233 | p = strchr(t, '\n') + 1; | 234 | p = strchr(t, '\n') + 1; |
234 | } | 235 | } |
235 | 236 | ||
237 | if (!strncmp(p, "encoding ", 9)) { | ||
238 | p += 9; | ||
239 | t = strchr(p, '\n') + 1; | ||
240 | ret->msg_encoding = substr(p, t); | ||
241 | p = t; | ||
242 | } else | ||
243 | ret->msg_encoding = xstrdup(PAGE_ENCODING); | ||
244 | |||
236 | while (*p && (*p != '\n')) | 245 | while (*p && (*p != '\n')) |
237 | p = strchr(p, '\n') + 1; // skip unknown header fields | 246 | p = strchr(p, '\n') + 1; // skip unknown header fields |
238 | 247 | ||
239 | while (*p == '\n') | 248 | while (*p == '\n') |
240 | p = strchr(p, '\n') + 1; | 249 | p = strchr(p, '\n') + 1; |
241 | 250 | ||
242 | t = strchr(p, '\n'); | 251 | t = strchr(p, '\n'); |
243 | if (t) { | 252 | if (t) { |
244 | if (*t == '\0') | 253 | if (*t == '\0') |
245 | ret->subject = "** empty **"; | 254 | ret->subject = "** empty **"; |
246 | else | 255 | else |
247 | ret->subject = substr(p, t); | 256 | ret->subject = substr(p, t); |
248 | p = t + 1; | 257 | p = t + 1; |
249 | 258 | ||
250 | while (*p == '\n') | 259 | while (*p == '\n') |
251 | p = strchr(p, '\n') + 1; | 260 | p = strchr(p, '\n') + 1; |
252 | ret->msg = xstrdup(p); | 261 | ret->msg = xstrdup(p); |
253 | } else | 262 | } else |
254 | ret->subject = substr(p, p+strlen(p)); | 263 | ret->subject = substr(p, p+strlen(p)); |
255 | 264 | ||
265 | if(strcmp(ret->msg_encoding, PAGE_ENCODING)) { | ||
266 | t = reencode_string(ret->subject, PAGE_ENCODING, | ||
267 | ret->msg_encoding); | ||
268 | if(t) { | ||
269 | free(ret->subject); | ||
270 | ret->subject = t; | ||
271 | } | ||
272 | |||
273 | t = reencode_string(ret->msg, PAGE_ENCODING, | ||
274 | ret->msg_encoding); | ||
275 | if(t) { | ||
276 | free(ret->msg); | ||
277 | ret->msg = t; | ||
278 | } | ||
279 | } | ||
280 | |||
256 | return ret; | 281 | return ret; |
257 | } | 282 | } |
258 | 283 | ||
259 | 284 | ||
260 | struct taginfo *cgit_parse_tag(struct tag *tag) | 285 | struct taginfo *cgit_parse_tag(struct tag *tag) |
261 | { | 286 | { |
262 | void *data; | 287 | void *data; |
263 | enum object_type type; | 288 | enum object_type type; |
264 | unsigned long size; | 289 | unsigned long size; |
265 | char *p, *t; | 290 | char *p, *t; |
266 | struct taginfo *ret; | 291 | struct taginfo *ret; |
267 | 292 | ||
268 | data = read_sha1_file(tag->object.sha1, &type, &size); | 293 | data = read_sha1_file(tag->object.sha1, &type, &size); |
269 | if (!data || type != OBJ_TAG) { | 294 | if (!data || type != OBJ_TAG) { |
270 | free(data); | 295 | free(data); |
271 | return 0; | 296 | return 0; |
272 | } | 297 | } |
273 | 298 | ||
274 | ret = xmalloc(sizeof(*ret)); | 299 | ret = xmalloc(sizeof(*ret)); |
275 | ret->tagger = NULL; | 300 | ret->tagger = NULL; |
276 | ret->tagger_email = NULL; | 301 | ret->tagger_email = NULL; |
277 | ret->tagger_date = 0; | 302 | ret->tagger_date = 0; |
278 | ret->msg = NULL; | 303 | ret->msg = NULL; |
279 | 304 | ||
280 | p = data; | 305 | p = data; |
281 | 306 | ||
282 | while (p && *p) { | 307 | while (p && *p) { |
283 | if (*p == '\n') | 308 | if (*p == '\n') |
284 | break; | 309 | break; |
285 | 310 | ||
286 | if (!strncmp(p, "tagger ", 7)) { | 311 | if (!strncmp(p, "tagger ", 7)) { |
287 | p += 7; | 312 | p += 7; |
288 | t = strchr(p, '<') - 1; | 313 | t = strchr(p, '<') - 1; |
289 | ret->tagger = substr(p, t); | 314 | ret->tagger = substr(p, t); |
290 | p = t; | 315 | p = t; |
291 | t = strchr(t, '>') + 1; | 316 | t = strchr(t, '>') + 1; |
292 | ret->tagger_email = substr(p, t); | 317 | ret->tagger_email = substr(p, t); |
293 | ret->tagger_date = atol(t+1); | 318 | ret->tagger_date = atol(t+1); |
294 | } | 319 | } |
295 | p = strchr(p, '\n') + 1; | 320 | p = strchr(p, '\n') + 1; |
296 | } | 321 | } |
297 | 322 | ||
298 | while (p && *p && (*p != '\n')) | 323 | while (p && *p && (*p != '\n')) |
299 | p = strchr(p, '\n') + 1; // skip unknown tag fields | 324 | p = strchr(p, '\n') + 1; // skip unknown tag fields |
300 | 325 | ||
301 | while (p && (*p == '\n')) | 326 | while (p && (*p == '\n')) |
302 | p = strchr(p, '\n') + 1; | 327 | p = strchr(p, '\n') + 1; |
303 | if (p && *p) | 328 | if (p && *p) |
304 | ret->msg = xstrdup(p); | 329 | ret->msg = xstrdup(p); |
305 | free(data); | 330 | free(data); |
306 | return ret; | 331 | return ret; |
307 | } | 332 | } |
@@ -1,365 +1,375 @@ | |||
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 | int cgit_cmd; |
14 | 14 | ||
15 | const char *cgit_version = CGIT_VERSION; | 15 | const char *cgit_version = CGIT_VERSION; |
16 | 16 | ||
17 | char *cgit_root_title = "Git repository browser"; | 17 | char *cgit_root_title = "Git repository browser"; |
18 | char *cgit_css = "/cgit.css"; | 18 | char *cgit_css = "/cgit.css"; |
19 | char *cgit_logo = "/git-logo.png"; | 19 | char *cgit_logo = "/git-logo.png"; |
20 | char *cgit_index_header = NULL; | 20 | char *cgit_index_header = NULL; |
21 | char *cgit_index_info = NULL; | 21 | char *cgit_index_info = NULL; |
22 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 22 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
23 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 23 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
24 | char *cgit_agefile = "info/web/last-modified"; | 24 | char *cgit_agefile = "info/web/last-modified"; |
25 | char *cgit_virtual_root = NULL; | 25 | char *cgit_virtual_root = NULL; |
26 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 26 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
27 | char *cgit_cache_root = CGIT_CACHE_ROOT; | 27 | char *cgit_cache_root = CGIT_CACHE_ROOT; |
28 | char *cgit_repo_group = NULL; | 28 | char *cgit_repo_group = NULL; |
29 | char *cgit_robots = "index, nofollow"; | ||
30 | char *cgit_clone_prefix = NULL; | ||
29 | 31 | ||
30 | int cgit_nocache = 0; | 32 | int cgit_nocache = 0; |
31 | int cgit_snapshots = 0; | 33 | int cgit_snapshots = 0; |
32 | int cgit_enable_index_links = 0; | 34 | int cgit_enable_index_links = 0; |
33 | int cgit_enable_log_filecount = 0; | 35 | int cgit_enable_log_filecount = 0; |
34 | int cgit_enable_log_linecount = 0; | 36 | int cgit_enable_log_linecount = 0; |
35 | int cgit_max_lock_attempts = 5; | 37 | int cgit_max_lock_attempts = 5; |
36 | int cgit_cache_root_ttl = 5; | 38 | int cgit_cache_root_ttl = 5; |
37 | int cgit_cache_repo_ttl = 5; | 39 | int cgit_cache_repo_ttl = 5; |
38 | int cgit_cache_dynamic_ttl = 5; | 40 | int cgit_cache_dynamic_ttl = 5; |
39 | int cgit_cache_static_ttl = -1; | 41 | int cgit_cache_static_ttl = -1; |
40 | int cgit_cache_max_create_time = 5; | 42 | int cgit_cache_max_create_time = 5; |
41 | int cgit_summary_log = 0; | 43 | int cgit_summary_log = 0; |
42 | int cgit_summary_tags = 0; | 44 | int cgit_summary_tags = 0; |
43 | int cgit_summary_branches = 0; | 45 | int cgit_summary_branches = 0; |
44 | int cgit_renamelimit = -1; | 46 | int cgit_renamelimit = -1; |
45 | 47 | ||
46 | int cgit_max_msg_len = 60; | 48 | int cgit_max_msg_len = 60; |
47 | int cgit_max_repodesc_len = 60; | 49 | int cgit_max_repodesc_len = 60; |
48 | int cgit_max_commit_count = 50; | 50 | int cgit_max_commit_count = 50; |
49 | 51 | ||
50 | int cgit_query_has_symref = 0; | 52 | int cgit_query_has_symref = 0; |
51 | int cgit_query_has_sha1 = 0; | 53 | int cgit_query_has_sha1 = 0; |
52 | 54 | ||
53 | char *cgit_querystring = NULL; | 55 | char *cgit_querystring = NULL; |
54 | char *cgit_query_repo = NULL; | 56 | char *cgit_query_repo = NULL; |
55 | char *cgit_query_page = NULL; | 57 | char *cgit_query_page = NULL; |
56 | char *cgit_query_head = NULL; | 58 | char *cgit_query_head = NULL; |
57 | char *cgit_query_search = NULL; | 59 | char *cgit_query_search = NULL; |
58 | char *cgit_query_grep = NULL; | 60 | char *cgit_query_grep = NULL; |
59 | char *cgit_query_sha1 = NULL; | 61 | char *cgit_query_sha1 = NULL; |
60 | char *cgit_query_sha2 = NULL; | 62 | char *cgit_query_sha2 = NULL; |
61 | char *cgit_query_path = NULL; | 63 | char *cgit_query_path = NULL; |
62 | char *cgit_query_name = NULL; | 64 | char *cgit_query_name = NULL; |
63 | int cgit_query_ofs = 0; | 65 | int cgit_query_ofs = 0; |
64 | 66 | ||
65 | int htmlfd = 0; | 67 | int htmlfd = 0; |
66 | 68 | ||
67 | 69 | ||
68 | int cgit_get_cmd_index(const char *cmd) | 70 | int cgit_get_cmd_index(const char *cmd) |
69 | { | 71 | { |
70 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 72 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
71 | "snapshot", "tag", "refs", NULL}; | 73 | "snapshot", "tag", "refs", "patch", NULL}; |
72 | int i; | 74 | int i; |
73 | 75 | ||
74 | for(i = 0; cmds[i]; i++) | 76 | for(i = 0; cmds[i]; i++) |
75 | if (!strcmp(cmd, cmds[i])) | 77 | if (!strcmp(cmd, cmds[i])) |
76 | return i + 1; | 78 | return i + 1; |
77 | return 0; | 79 | return 0; |
78 | } | 80 | } |
79 | 81 | ||
80 | int chk_zero(int result, char *msg) | 82 | int chk_zero(int result, char *msg) |
81 | { | 83 | { |
82 | if (result != 0) | 84 | if (result != 0) |
83 | die("%s: %s", msg, strerror(errno)); | 85 | die("%s: %s", msg, strerror(errno)); |
84 | return result; | 86 | return result; |
85 | } | 87 | } |
86 | 88 | ||
87 | int chk_positive(int result, char *msg) | 89 | int chk_positive(int result, char *msg) |
88 | { | 90 | { |
89 | if (result <= 0) | 91 | if (result <= 0) |
90 | die("%s: %s", msg, strerror(errno)); | 92 | die("%s: %s", msg, strerror(errno)); |
91 | return result; | 93 | return result; |
92 | } | 94 | } |
93 | 95 | ||
94 | int chk_non_negative(int result, char *msg) | 96 | int chk_non_negative(int result, char *msg) |
95 | { | 97 | { |
96 | if (result < 0) | 98 | if (result < 0) |
97 | die("%s: %s",msg, strerror(errno)); | 99 | die("%s: %s",msg, strerror(errno)); |
98 | return result; | 100 | return result; |
99 | } | 101 | } |
100 | 102 | ||
101 | struct repoinfo *add_repo(const char *url) | 103 | struct repoinfo *add_repo(const char *url) |
102 | { | 104 | { |
103 | struct repoinfo *ret; | 105 | struct repoinfo *ret; |
104 | 106 | ||
105 | if (++cgit_repolist.count > cgit_repolist.length) { | 107 | if (++cgit_repolist.count > cgit_repolist.length) { |
106 | if (cgit_repolist.length == 0) | 108 | if (cgit_repolist.length == 0) |
107 | cgit_repolist.length = 8; | 109 | cgit_repolist.length = 8; |
108 | else | 110 | else |
109 | cgit_repolist.length *= 2; | 111 | cgit_repolist.length *= 2; |
110 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 112 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
111 | cgit_repolist.length * | 113 | cgit_repolist.length * |
112 | sizeof(struct repoinfo)); | 114 | sizeof(struct repoinfo)); |
113 | } | 115 | } |
114 | 116 | ||
115 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 117 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
116 | ret->url = trim_end(url, '/'); | 118 | ret->url = trim_end(url, '/'); |
117 | ret->name = ret->url; | 119 | ret->name = ret->url; |
118 | ret->path = NULL; | 120 | ret->path = NULL; |
119 | ret->desc = "[no description]"; | 121 | ret->desc = "[no description]"; |
120 | ret->owner = NULL; | 122 | ret->owner = NULL; |
121 | ret->group = cgit_repo_group; | 123 | ret->group = cgit_repo_group; |
122 | ret->defbranch = "master"; | 124 | ret->defbranch = "master"; |
123 | ret->snapshots = cgit_snapshots; | 125 | ret->snapshots = cgit_snapshots; |
124 | ret->enable_log_filecount = cgit_enable_log_filecount; | 126 | ret->enable_log_filecount = cgit_enable_log_filecount; |
125 | ret->enable_log_linecount = cgit_enable_log_linecount; | 127 | ret->enable_log_linecount = cgit_enable_log_linecount; |
126 | ret->module_link = cgit_module_link; | 128 | ret->module_link = cgit_module_link; |
127 | ret->readme = NULL; | 129 | ret->readme = NULL; |
128 | return ret; | 130 | return ret; |
129 | } | 131 | } |
130 | 132 | ||
131 | struct repoinfo *cgit_get_repoinfo(const char *url) | 133 | struct repoinfo *cgit_get_repoinfo(const char *url) |
132 | { | 134 | { |
133 | int i; | 135 | int i; |
134 | struct repoinfo *repo; | 136 | struct repoinfo *repo; |
135 | 137 | ||
136 | for (i=0; i<cgit_repolist.count; i++) { | 138 | for (i=0; i<cgit_repolist.count; i++) { |
137 | repo = &cgit_repolist.repos[i]; | 139 | repo = &cgit_repolist.repos[i]; |
138 | if (!strcmp(repo->url, url)) | 140 | if (!strcmp(repo->url, url)) |
139 | return repo; | 141 | return repo; |
140 | } | 142 | } |
141 | return NULL; | 143 | return NULL; |
142 | } | 144 | } |
143 | 145 | ||
144 | void cgit_global_config_cb(const char *name, const char *value) | 146 | void cgit_global_config_cb(const char *name, const char *value) |
145 | { | 147 | { |
146 | if (!strcmp(name, "root-title")) | 148 | if (!strcmp(name, "root-title")) |
147 | cgit_root_title = xstrdup(value); | 149 | cgit_root_title = xstrdup(value); |
148 | else if (!strcmp(name, "css")) | 150 | else if (!strcmp(name, "css")) |
149 | cgit_css = xstrdup(value); | 151 | cgit_css = xstrdup(value); |
150 | else if (!strcmp(name, "logo")) | 152 | else if (!strcmp(name, "logo")) |
151 | cgit_logo = xstrdup(value); | 153 | cgit_logo = xstrdup(value); |
152 | else if (!strcmp(name, "index-header")) | 154 | else if (!strcmp(name, "index-header")) |
153 | cgit_index_header = xstrdup(value); | 155 | cgit_index_header = xstrdup(value); |
154 | else if (!strcmp(name, "index-info")) | 156 | else if (!strcmp(name, "index-info")) |
155 | cgit_index_info = xstrdup(value); | 157 | cgit_index_info = xstrdup(value); |
156 | else if (!strcmp(name, "logo-link")) | 158 | else if (!strcmp(name, "logo-link")) |
157 | cgit_logo_link = xstrdup(value); | 159 | cgit_logo_link = xstrdup(value); |
158 | else if (!strcmp(name, "module-link")) | 160 | else if (!strcmp(name, "module-link")) |
159 | cgit_module_link = xstrdup(value); | 161 | cgit_module_link = xstrdup(value); |
160 | else if (!strcmp(name, "virtual-root")) { | 162 | else if (!strcmp(name, "virtual-root")) { |
161 | cgit_virtual_root = trim_end(value, '/'); | 163 | cgit_virtual_root = trim_end(value, '/'); |
162 | if (!cgit_virtual_root && (!strcmp(value, "/"))) | 164 | if (!cgit_virtual_root && (!strcmp(value, "/"))) |
163 | cgit_virtual_root = ""; | 165 | cgit_virtual_root = ""; |
164 | } else if (!strcmp(name, "nocache")) | 166 | } else if (!strcmp(name, "nocache")) |
165 | cgit_nocache = atoi(value); | 167 | cgit_nocache = atoi(value); |
166 | else if (!strcmp(name, "snapshots")) | 168 | else if (!strcmp(name, "snapshots")) |
167 | cgit_snapshots = cgit_parse_snapshots_mask(value); | 169 | cgit_snapshots = cgit_parse_snapshots_mask(value); |
168 | else if (!strcmp(name, "enable-index-links")) | 170 | else if (!strcmp(name, "enable-index-links")) |
169 | cgit_enable_index_links = atoi(value); | 171 | cgit_enable_index_links = atoi(value); |
170 | else if (!strcmp(name, "enable-log-filecount")) | 172 | else if (!strcmp(name, "enable-log-filecount")) |
171 | cgit_enable_log_filecount = atoi(value); | 173 | cgit_enable_log_filecount = atoi(value); |
172 | else if (!strcmp(name, "enable-log-linecount")) | 174 | else if (!strcmp(name, "enable-log-linecount")) |
173 | cgit_enable_log_linecount = atoi(value); | 175 | cgit_enable_log_linecount = atoi(value); |
174 | else if (!strcmp(name, "cache-root")) | 176 | else if (!strcmp(name, "cache-root")) |
175 | cgit_cache_root = xstrdup(value); | 177 | cgit_cache_root = xstrdup(value); |
176 | else if (!strcmp(name, "cache-root-ttl")) | 178 | else if (!strcmp(name, "cache-root-ttl")) |
177 | cgit_cache_root_ttl = atoi(value); | 179 | cgit_cache_root_ttl = atoi(value); |
178 | else if (!strcmp(name, "cache-repo-ttl")) | 180 | else if (!strcmp(name, "cache-repo-ttl")) |
179 | cgit_cache_repo_ttl = atoi(value); | 181 | cgit_cache_repo_ttl = atoi(value); |
180 | else if (!strcmp(name, "cache-static-ttl")) | 182 | else if (!strcmp(name, "cache-static-ttl")) |
181 | cgit_cache_static_ttl = atoi(value); | 183 | cgit_cache_static_ttl = atoi(value); |
182 | else if (!strcmp(name, "cache-dynamic-ttl")) | 184 | else if (!strcmp(name, "cache-dynamic-ttl")) |
183 | cgit_cache_dynamic_ttl = atoi(value); | 185 | cgit_cache_dynamic_ttl = atoi(value); |
184 | else if (!strcmp(name, "max-message-length")) | 186 | else if (!strcmp(name, "max-message-length")) |
185 | cgit_max_msg_len = atoi(value); | 187 | cgit_max_msg_len = atoi(value); |
186 | else if (!strcmp(name, "max-repodesc-length")) | 188 | else if (!strcmp(name, "max-repodesc-length")) |
187 | cgit_max_repodesc_len = atoi(value); | 189 | cgit_max_repodesc_len = atoi(value); |
188 | else if (!strcmp(name, "max-commit-count")) | 190 | else if (!strcmp(name, "max-commit-count")) |
189 | cgit_max_commit_count = atoi(value); | 191 | cgit_max_commit_count = atoi(value); |
190 | else if (!strcmp(name, "summary-log")) | 192 | else if (!strcmp(name, "summary-log")) |
191 | cgit_summary_log = atoi(value); | 193 | cgit_summary_log = atoi(value); |
192 | else if (!strcmp(name, "summary-branches")) | 194 | else if (!strcmp(name, "summary-branches")) |
193 | cgit_summary_branches = atoi(value); | 195 | cgit_summary_branches = atoi(value); |
194 | else if (!strcmp(name, "summary-tags")) | 196 | else if (!strcmp(name, "summary-tags")) |
195 | cgit_summary_tags = atoi(value); | 197 | cgit_summary_tags = atoi(value); |
196 | else if (!strcmp(name, "agefile")) | 198 | else if (!strcmp(name, "agefile")) |
197 | cgit_agefile = xstrdup(value); | 199 | cgit_agefile = xstrdup(value); |
198 | else if (!strcmp(name, "renamelimit")) | 200 | else if (!strcmp(name, "renamelimit")) |
199 | cgit_renamelimit = atoi(value); | 201 | cgit_renamelimit = atoi(value); |
202 | else if (!strcmp(name, "robots")) | ||
203 | cgit_robots = xstrdup(value); | ||
204 | else if (!strcmp(name, "clone-prefix")) | ||
205 | cgit_clone_prefix = xstrdup(value); | ||
200 | else if (!strcmp(name, "repo.group")) | 206 | else if (!strcmp(name, "repo.group")) |
201 | cgit_repo_group = xstrdup(value); | 207 | cgit_repo_group = xstrdup(value); |
202 | else if (!strcmp(name, "repo.url")) | 208 | else if (!strcmp(name, "repo.url")) |
203 | cgit_repo = add_repo(value); | 209 | cgit_repo = add_repo(value); |
204 | else if (!strcmp(name, "repo.name")) | 210 | else if (!strcmp(name, "repo.name")) |
205 | cgit_repo->name = xstrdup(value); | 211 | cgit_repo->name = xstrdup(value); |
206 | else if (cgit_repo && !strcmp(name, "repo.path")) | 212 | else if (cgit_repo && !strcmp(name, "repo.path")) |
207 | cgit_repo->path = trim_end(value, '/'); | 213 | cgit_repo->path = trim_end(value, '/'); |
214 | else if (cgit_repo && !strcmp(name, "repo.clone-url")) | ||
215 | cgit_repo->clone_url = xstrdup(value); | ||
208 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 216 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
209 | cgit_repo->desc = xstrdup(value); | 217 | cgit_repo->desc = xstrdup(value); |
210 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 218 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
211 | cgit_repo->owner = xstrdup(value); | 219 | cgit_repo->owner = xstrdup(value); |
212 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | 220 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
213 | cgit_repo->defbranch = xstrdup(value); | 221 | cgit_repo->defbranch = xstrdup(value); |
214 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 222 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
215 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | 223 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
216 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 224 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
217 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | 225 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
218 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 226 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
219 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | 227 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
220 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 228 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
221 | cgit_repo->module_link= xstrdup(value); | 229 | cgit_repo->module_link= xstrdup(value); |
222 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | 230 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
223 | if (*value == '/') | 231 | if (*value == '/') |
224 | cgit_repo->readme = xstrdup(value); | 232 | cgit_repo->readme = xstrdup(value); |
225 | else | 233 | else |
226 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | 234 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
227 | } else if (!strcmp(name, "include")) | 235 | } else if (!strcmp(name, "include")) |
228 | cgit_read_config(value, cgit_global_config_cb); | 236 | cgit_read_config(value, cgit_global_config_cb); |
229 | } | 237 | } |
230 | 238 | ||
231 | void cgit_querystring_cb(const char *name, const char *value) | 239 | void cgit_querystring_cb(const char *name, const char *value) |
232 | { | 240 | { |
233 | if (!strcmp(name,"r")) { | 241 | if (!strcmp(name,"r")) { |
234 | cgit_query_repo = xstrdup(value); | 242 | cgit_query_repo = xstrdup(value); |
235 | cgit_repo = cgit_get_repoinfo(value); | 243 | cgit_repo = cgit_get_repoinfo(value); |
236 | } else if (!strcmp(name, "p")) { | 244 | } else if (!strcmp(name, "p")) { |
237 | cgit_query_page = xstrdup(value); | 245 | cgit_query_page = xstrdup(value); |
238 | cgit_cmd = cgit_get_cmd_index(value); | 246 | cgit_cmd = cgit_get_cmd_index(value); |
239 | } else if (!strcmp(name, "url")) { | 247 | } else if (!strcmp(name, "url")) { |
240 | cgit_parse_url(value); | 248 | cgit_parse_url(value); |
241 | } else if (!strcmp(name, "qt")) { | 249 | } else if (!strcmp(name, "qt")) { |
242 | cgit_query_grep = xstrdup(value); | 250 | cgit_query_grep = xstrdup(value); |
243 | } else if (!strcmp(name, "q")) { | 251 | } else if (!strcmp(name, "q")) { |
244 | cgit_query_search = xstrdup(value); | 252 | cgit_query_search = xstrdup(value); |
245 | } else if (!strcmp(name, "h")) { | 253 | } else if (!strcmp(name, "h")) { |
246 | cgit_query_head = xstrdup(value); | 254 | cgit_query_head = xstrdup(value); |
247 | cgit_query_has_symref = 1; | 255 | cgit_query_has_symref = 1; |
248 | } else if (!strcmp(name, "id")) { | 256 | } else if (!strcmp(name, "id")) { |
249 | cgit_query_sha1 = xstrdup(value); | 257 | cgit_query_sha1 = xstrdup(value); |
250 | cgit_query_has_sha1 = 1; | 258 | cgit_query_has_sha1 = 1; |
251 | } else if (!strcmp(name, "id2")) { | 259 | } else if (!strcmp(name, "id2")) { |
252 | cgit_query_sha2 = xstrdup(value); | 260 | cgit_query_sha2 = xstrdup(value); |
253 | cgit_query_has_sha1 = 1; | 261 | cgit_query_has_sha1 = 1; |
254 | } else if (!strcmp(name, "ofs")) { | 262 | } else if (!strcmp(name, "ofs")) { |
255 | cgit_query_ofs = atoi(value); | 263 | cgit_query_ofs = atoi(value); |
256 | } else if (!strcmp(name, "path")) { | 264 | } else if (!strcmp(name, "path")) { |
257 | cgit_query_path = trim_end(value, '/'); | 265 | cgit_query_path = trim_end(value, '/'); |
258 | } else if (!strcmp(name, "name")) { | 266 | } else if (!strcmp(name, "name")) { |
259 | cgit_query_name = xstrdup(value); | 267 | cgit_query_name = xstrdup(value); |
260 | } | 268 | } |
261 | } | 269 | } |
262 | 270 | ||
263 | void *cgit_free_commitinfo(struct commitinfo *info) | 271 | void *cgit_free_commitinfo(struct commitinfo *info) |
264 | { | 272 | { |
265 | free(info->author); | 273 | free(info->author); |
266 | free(info->author_email); | 274 | free(info->author_email); |
267 | free(info->committer); | 275 | free(info->committer); |
268 | free(info->committer_email); | 276 | free(info->committer_email); |
269 | free(info->subject); | 277 | free(info->subject); |
278 | free(info->msg); | ||
279 | free(info->msg_encoding); | ||
270 | free(info); | 280 | free(info); |
271 | return NULL; | 281 | return NULL; |
272 | } | 282 | } |
273 | 283 | ||
274 | int hextoint(char c) | 284 | int hextoint(char c) |
275 | { | 285 | { |
276 | if (c >= 'a' && c <= 'f') | 286 | if (c >= 'a' && c <= 'f') |
277 | return 10 + c - 'a'; | 287 | return 10 + c - 'a'; |
278 | else if (c >= 'A' && c <= 'F') | 288 | else if (c >= 'A' && c <= 'F') |
279 | return 10 + c - 'A'; | 289 | return 10 + c - 'A'; |
280 | else if (c >= '0' && c <= '9') | 290 | else if (c >= '0' && c <= '9') |
281 | return c - '0'; | 291 | return c - '0'; |
282 | else | 292 | else |
283 | return -1; | 293 | return -1; |
284 | } | 294 | } |
285 | 295 | ||
286 | char *trim_end(const char *str, char c) | 296 | char *trim_end(const char *str, char c) |
287 | { | 297 | { |
288 | int len; | 298 | int len; |
289 | char *s, *t; | 299 | char *s, *t; |
290 | 300 | ||
291 | if (str == NULL) | 301 | if (str == NULL) |
292 | return NULL; | 302 | return NULL; |
293 | t = (char *)str; | 303 | t = (char *)str; |
294 | len = strlen(t); | 304 | len = strlen(t); |
295 | while(len > 0 && t[len - 1] == c) | 305 | while(len > 0 && t[len - 1] == c) |
296 | len--; | 306 | len--; |
297 | 307 | ||
298 | if (len == 0) | 308 | if (len == 0) |
299 | return NULL; | 309 | return NULL; |
300 | 310 | ||
301 | c = t[len]; | 311 | c = t[len]; |
302 | t[len] = '\0'; | 312 | t[len] = '\0'; |
303 | s = xstrdup(t); | 313 | s = xstrdup(t); |
304 | t[len] = c; | 314 | t[len] = c; |
305 | return s; | 315 | return s; |
306 | } | 316 | } |
307 | 317 | ||
308 | char *strlpart(char *txt, int maxlen) | 318 | char *strlpart(char *txt, int maxlen) |
309 | { | 319 | { |
310 | char *result; | 320 | char *result; |
311 | 321 | ||
312 | if (!txt) | 322 | if (!txt) |
313 | return txt; | 323 | return txt; |
314 | 324 | ||
315 | if (strlen(txt) <= maxlen) | 325 | if (strlen(txt) <= maxlen) |
316 | return txt; | 326 | return txt; |
317 | result = xmalloc(maxlen + 1); | 327 | result = xmalloc(maxlen + 1); |
318 | memcpy(result, txt, maxlen - 3); | 328 | memcpy(result, txt, maxlen - 3); |
319 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; | 329 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; |
320 | result[maxlen] = '\0'; | 330 | result[maxlen] = '\0'; |
321 | return result; | 331 | return result; |
322 | } | 332 | } |
323 | 333 | ||
324 | char *strrpart(char *txt, int maxlen) | 334 | char *strrpart(char *txt, int maxlen) |
325 | { | 335 | { |
326 | char *result; | 336 | char *result; |
327 | 337 | ||
328 | if (!txt) | 338 | if (!txt) |
329 | return txt; | 339 | return txt; |
330 | 340 | ||
331 | if (strlen(txt) <= maxlen) | 341 | if (strlen(txt) <= maxlen) |
332 | return txt; | 342 | return txt; |
333 | result = xmalloc(maxlen + 1); | 343 | result = xmalloc(maxlen + 1); |
334 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); | 344 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); |
335 | result[0] = result[1] = result[2] = '.'; | 345 | result[0] = result[1] = result[2] = '.'; |
336 | return result; | 346 | return result; |
337 | } | 347 | } |
338 | 348 | ||
339 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) | 349 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
340 | { | 350 | { |
341 | size_t size; | 351 | size_t size; |
342 | 352 | ||
343 | if (list->count >= list->alloc) { | 353 | if (list->count >= list->alloc) { |
344 | list->alloc += (list->alloc ? list->alloc : 4); | 354 | list->alloc += (list->alloc ? list->alloc : 4); |
345 | size = list->alloc * sizeof(struct refinfo *); | 355 | size = list->alloc * sizeof(struct refinfo *); |
346 | list->refs = xrealloc(list->refs, size); | 356 | list->refs = xrealloc(list->refs, size); |
347 | } | 357 | } |
348 | list->refs[list->count++] = ref; | 358 | list->refs[list->count++] = ref; |
349 | } | 359 | } |
350 | 360 | ||
351 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) | 361 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
352 | { | 362 | { |
353 | struct refinfo *ref; | 363 | struct refinfo *ref; |
354 | 364 | ||
355 | ref = xmalloc(sizeof (struct refinfo)); | 365 | ref = xmalloc(sizeof (struct refinfo)); |
356 | ref->refname = xstrdup(refname); | 366 | ref->refname = xstrdup(refname); |
357 | ref->object = parse_object(sha1); | 367 | ref->object = parse_object(sha1); |
358 | switch (ref->object->type) { | 368 | switch (ref->object->type) { |
359 | case OBJ_TAG: | 369 | case OBJ_TAG: |
360 | ref->tag = cgit_parse_tag((struct tag *)ref->object); | 370 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
361 | break; | 371 | break; |
362 | case OBJ_COMMIT: | 372 | case OBJ_COMMIT: |
363 | ref->commit = cgit_parse_commit((struct commit *)ref->object); | 373 | ref->commit = cgit_parse_commit((struct commit *)ref->object); |
364 | break; | 374 | break; |
365 | } | 375 | } |
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c1c1c0b --- a/dev/null +++ b/tests/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | trash | ||
2 | test-output.log | ||
diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..697e5a1 --- a/dev/null +++ b/tests/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | |||
2 | |||
3 | T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) | ||
4 | |||
5 | all: $(T) | ||
6 | |||
7 | $(T): | ||
8 | @$@ | ||
9 | |||
10 | clean: | ||
11 | $(RM) -rf trash | ||
12 | |||
13 | .PHONY: $(T) clean | ||
diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100755 index 0000000..51d5a75 --- a/dev/null +++ b/tests/setup.sh | |||
@@ -0,0 +1,108 @@ | |||
1 | # This file should be sourced by all test-scripts | ||
2 | # | ||
3 | # Main functions: | ||
4 | # prepare_tests(description) - setup for testing, i.e. create repos+config | ||
5 | # run_test(description, script) - run one test, i.e. eval script | ||
6 | # | ||
7 | # Helper functions | ||
8 | # cgit_query(querystring) - call cgit with the specified querystring | ||
9 | # cgit_url(url) - call cgit with the specified virtual url | ||
10 | # | ||
11 | # Example script: | ||
12 | # | ||
13 | # . setup.sh | ||
14 | # prepare_tests "html validation" | ||
15 | # run_test 'repo index' 'cgit_url "/" | tidy -e' | ||
16 | # run_test 'repo summary' 'cgit_url "/foo" | tidy -e' | ||
17 | |||
18 | |||
19 | mkrepo() { | ||
20 | name=$1 | ||
21 | count=$2 | ||
22 | dir=$PWD | ||
23 | test -d $name && return | ||
24 | printf "Creating testrepo %s\n" $name | ||
25 | mkdir -p $name | ||
26 | cd $name | ||
27 | git init | ||
28 | for ((n=1; n<=count; n++)) | ||
29 | do | ||
30 | echo $n >file-$n | ||
31 | git add file-$n | ||
32 | git commit -m "commit $n" | ||
33 | done | ||
34 | cd $dir | ||
35 | } | ||
36 | |||
37 | setup_repos() | ||
38 | { | ||
39 | rm -rf trash/cache | ||
40 | mkdir -p trash/cache | ||
41 | mkrepo trash/repos/foo 5 >/dev/null | ||
42 | mkrepo trash/repos/bar 50 >/dev/null | ||
43 | cat >trash/cgitrc <<EOF | ||
44 | virtual-root=/ | ||
45 | cache-root=$PWD/trash/cache | ||
46 | |||
47 | nocache=0 | ||
48 | snapshots=tar.gz tar.bz zip | ||
49 | enable-log-filecount=1 | ||
50 | enable-log-linecount=1 | ||
51 | summary-log=5 | ||
52 | summary-branches=5 | ||
53 | summary-tags=5 | ||
54 | |||
55 | repo.url=foo | ||
56 | repo.path=$PWD/trash/repos/foo/.git | ||
57 | repo.desc=the foo repo | ||
58 | |||
59 | repo.url=bar | ||
60 | repo.path=$PWD/trash/repos/bar/.git | ||
61 | repo.desc=the bar repo | ||
62 | EOF | ||
63 | } | ||
64 | |||
65 | prepare_tests() | ||
66 | { | ||
67 | setup_repos | ||
68 | test_count=0 | ||
69 | test_failed=0 | ||
70 | echo "$@" "($0)" | ||
71 | } | ||
72 | |||
73 | tests_done() | ||
74 | { | ||
75 | printf "\n" | ||
76 | if test $test_failed -gt 0 | ||
77 | then | ||
78 | printf "[%s of %s tests failed]\n" $test_failed $test_count | ||
79 | false | ||
80 | fi | ||
81 | } | ||
82 | |||
83 | run_test() | ||
84 | { | ||
85 | desc=$1 | ||
86 | script=$2 | ||
87 | ((test_count++)) | ||
88 | eval "$2" >test-output.log | ||
89 | res=$? | ||
90 | if test $res = 0 | ||
91 | then | ||
92 | printf " %s: ok - %s\n" $test_count "$desc" | ||
93 | else | ||
94 | ((test_failed++)) | ||
95 | printf " %s: fail - %s\n" $test_count "$desc" | ||
96 | fi | ||
97 | } | ||
98 | |||
99 | cgit_query() | ||
100 | { | ||
101 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit" | ||
102 | } | ||
103 | |||
104 | cgit_url() | ||
105 | { | ||
106 | CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit" | ||
107 | } | ||
108 | |||
diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh new file mode 100755 index 0000000..907a415 --- a/dev/null +++ b/tests/t0010-validate-html.sh | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | |||
6 | test_url() | ||
7 | { | ||
8 | tidy_opt="-eq" | ||
9 | test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no" | ||
10 | cgit_url "$1" | sed -e "1,4d" >trash/tidy-$test_count | ||
11 | tidy $tidy_opt trash/tidy-$test_count | ||
12 | rc=$? | ||
13 | if test $rc = 2 | ||
14 | then | ||
15 | false | ||
16 | else | ||
17 | : | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | prepare_tests 'Validate html with tidy' | ||
22 | |||
23 | run_test 'index page' 'test_url ""' | ||
24 | run_test 'foo' 'test_url "foo"' | ||
25 | run_test 'foo/log' 'test_url "foo/log"' | ||
26 | run_test 'foo/tree' 'test_url "foo/tree"' | ||
27 | run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"' | ||
28 | run_test 'foo/commit' 'test_url "foo/commit"' | ||
29 | run_test 'foo/diff' 'test_url "foo/diff"' | ||
30 | |||
31 | tests_done | ||
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh new file mode 100755 index 0000000..12ed00c --- a/dev/null +++ b/tests/t0101-index.sh | |||
@@ -0,0 +1,13 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on index page" | ||
6 | |||
7 | run_test 'generate index page' 'cgit_url "" >trash/tmp' | ||
8 | run_test 'find foo repo' 'grep -e "foo" trash/tmp' | ||
9 | run_test 'find bar repo' 'grep -e "bar" trash/tmp' | ||
10 | run_test 'no tree-link' 'grep -ve "foo/tree" trash/tmp' | ||
11 | run_test 'no log-link' 'grep -ve "foo/log" trash/tmp' | ||
12 | |||
13 | tests_done | ||
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh new file mode 100755 index 0000000..7edd675 --- a/dev/null +++ b/tests/t0102-summary.sh | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on summary page" | ||
6 | |||
7 | run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp' | ||
8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
10 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
11 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
12 | |||
13 | run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp' | ||
14 | run_test 'no commit 45' 'grep -ve "commit 45" trash/tmp' | ||
15 | run_test 'find commit 46' 'grep -e "commit 46" trash/tmp' | ||
16 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
17 | run_test 'find branch master' 'grep -e "master" trash/tmp' | ||
18 | run_test 'no tags' 'grep -ve "tags" trash/tmp' | ||
19 | |||
20 | tests_done | ||
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh new file mode 100755 index 0000000..b08cd29 --- a/dev/null +++ b/tests/t0103-log.sh | |||
@@ -0,0 +1,15 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on log page" | ||
6 | |||
7 | run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp' | ||
8 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
9 | run_test 'find commit 5' 'grep -e "commit 5" trash/tmp' | ||
10 | |||
11 | run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' | ||
12 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
13 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | ||
14 | |||
15 | tests_done | ||
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh new file mode 100755 index 0000000..2516c72 --- a/dev/null +++ b/tests/t0104-tree.sh | |||
@@ -0,0 +1,21 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on tree page" | ||
6 | |||
7 | run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp' | ||
8 | run_test 'find file-1' 'grep -e "file-1" trash/tmp' | ||
9 | run_test 'find file-50' 'grep -e "file-50" trash/tmp' | ||
10 | |||
11 | run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp' | ||
12 | |||
13 | run_test 'find line 1' ' | ||
14 | grep -e "<a id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp | ||
15 | ' | ||
16 | |||
17 | run_test 'no line 2' ' | ||
18 | grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp | ||
19 | ' | ||
20 | |||
21 | tests_done | ||
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh new file mode 100755 index 0000000..aa2bf33 --- a/dev/null +++ b/tests/t0105-commit.sh | |||
@@ -0,0 +1,22 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on commit page" | ||
6 | |||
7 | run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' | ||
8 | run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp' | ||
9 | run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp' | ||
10 | |||
11 | run_test 'find commit subject' ' | ||
12 | grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp | ||
13 | ' | ||
14 | |||
15 | run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp' | ||
16 | run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp' | ||
17 | |||
18 | run_test 'find diff summary' ' | ||
19 | grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp | ||
20 | ' | ||
21 | |||
22 | tests_done | ||
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh new file mode 100755 index 0000000..e140bcc --- a/dev/null +++ b/tests/t0106-diff.sh | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Check content on diff page" | ||
6 | |||
7 | run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp' | ||
8 | run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp' | ||
9 | run_test 'find blob link' 'grep -e "<a href=./foo/tree/file-5?id=" trash/tmp' | ||
10 | run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp' | ||
11 | |||
12 | run_test 'find hunk header' ' | ||
13 | grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp | ||
14 | ' | ||
15 | |||
16 | run_test 'find added line' ' | ||
17 | grep -e "<div class=.add.>+5</div>" trash/tmp | ||
18 | ' | ||
19 | |||
20 | tests_done | ||
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh new file mode 100755 index 0000000..8e90e10 --- a/dev/null +++ b/tests/t0107-snapshot.sh | |||
@@ -0,0 +1,36 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./setup.sh | ||
4 | |||
5 | prepare_tests "Verify snapshot" | ||
6 | |||
7 | run_test 'get foo/snapshot/test.tar.gz' ' | ||
8 | cgit_url "foo/snapshot/test.tar.gz" >trash/tmp | ||
9 | ' | ||
10 | |||
11 | run_test 'check html headers' ' | ||
12 | head -n 1 trash/tmp | | ||
13 | grep -e "Content-Type: application/x-tar" && | ||
14 | |||
15 | head -n 2 trash/tmp | | ||
16 | grep -e "Content-Disposition: inline; filename=.test.tar.gz." | ||
17 | ' | ||
18 | |||
19 | run_test 'strip off the header lines' ' | ||
20 | tail -n +6 trash/tmp > trash/test.tar.gz | ||
21 | ' | ||
22 | |||
23 | run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz' | ||
24 | run_test 'untar' 'tar -xf trash/test.tar.gz -C trash' | ||
25 | |||
26 | run_test 'count files' ' | ||
27 | c=$(ls -1 trash/foo/ | wc -l) && | ||
28 | test $c = 5 | ||
29 | ' | ||
30 | |||
31 | run_test 'verify untarred file-5' ' | ||
32 | grep -e "^5$" trash/foo/file-5 && | ||
33 | test $(cat trash/foo/file-5 | wc -l) = 1 | ||
34 | ' | ||
35 | |||
36 | tests_done | ||
diff --git a/ui-commit.c b/ui-commit.c index 4ac8955..bd55a33 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -1,226 +1,226 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
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 | static int files, slots; | 11 | static int files, slots; |
12 | static int total_adds, total_rems, max_changes; | 12 | static int total_adds, total_rems, max_changes; |
13 | static int lines_added, lines_removed; | 13 | static int lines_added, lines_removed; |
14 | static char *curr_rev; | 14 | static char *curr_rev; |
15 | 15 | ||
16 | static struct fileinfo { | 16 | static struct fileinfo { |
17 | char status; | 17 | char status; |
18 | unsigned char old_sha1[20]; | 18 | unsigned char old_sha1[20]; |
19 | unsigned char new_sha1[20]; | 19 | unsigned char new_sha1[20]; |
20 | unsigned short old_mode; | 20 | unsigned short old_mode; |
21 | unsigned short new_mode; | 21 | unsigned short new_mode; |
22 | char *old_path; | 22 | char *old_path; |
23 | char *new_path; | 23 | char *new_path; |
24 | unsigned int added; | 24 | unsigned int added; |
25 | unsigned int removed; | 25 | unsigned int removed; |
26 | } *items; | 26 | } *items; |
27 | 27 | ||
28 | 28 | ||
29 | void print_fileinfo(struct fileinfo *info) | 29 | void print_fileinfo(struct fileinfo *info) |
30 | { | 30 | { |
31 | char *class; | 31 | char *class; |
32 | 32 | ||
33 | switch (info->status) { | 33 | switch (info->status) { |
34 | case DIFF_STATUS_ADDED: | 34 | case DIFF_STATUS_ADDED: |
35 | class = "add"; | 35 | class = "add"; |
36 | break; | 36 | break; |
37 | case DIFF_STATUS_COPIED: | 37 | case DIFF_STATUS_COPIED: |
38 | class = "cpy"; | 38 | class = "cpy"; |
39 | break; | 39 | break; |
40 | case DIFF_STATUS_DELETED: | 40 | case DIFF_STATUS_DELETED: |
41 | class = "del"; | 41 | class = "del"; |
42 | break; | 42 | break; |
43 | case DIFF_STATUS_MODIFIED: | 43 | case DIFF_STATUS_MODIFIED: |
44 | class = "upd"; | 44 | class = "upd"; |
45 | break; | 45 | break; |
46 | case DIFF_STATUS_RENAMED: | 46 | case DIFF_STATUS_RENAMED: |
47 | class = "mov"; | 47 | class = "mov"; |
48 | break; | 48 | break; |
49 | case DIFF_STATUS_TYPE_CHANGED: | 49 | case DIFF_STATUS_TYPE_CHANGED: |
50 | class = "typ"; | 50 | class = "typ"; |
51 | break; | 51 | break; |
52 | case DIFF_STATUS_UNKNOWN: | 52 | case DIFF_STATUS_UNKNOWN: |
53 | class = "unk"; | 53 | class = "unk"; |
54 | break; | 54 | break; |
55 | case DIFF_STATUS_UNMERGED: | 55 | case DIFF_STATUS_UNMERGED: |
56 | class = "stg"; | 56 | class = "stg"; |
57 | break; | 57 | break; |
58 | default: | 58 | default: |
59 | die("bug: unhandled diff status %c", info->status); | 59 | die("bug: unhandled diff status %c", info->status); |
60 | } | 60 | } |
61 | 61 | ||
62 | html("<tr>"); | 62 | html("<tr>"); |
63 | htmlf("<td class='mode'>"); | 63 | htmlf("<td class='mode'>"); |
64 | if (is_null_sha1(info->new_sha1)) { | 64 | if (is_null_sha1(info->new_sha1)) { |
65 | html_filemode(info->old_mode); | 65 | html_filemode(info->old_mode); |
66 | } else { | 66 | } else { |
67 | html_filemode(info->new_mode); | 67 | html_filemode(info->new_mode); |
68 | } | 68 | } |
69 | 69 | ||
70 | if (info->old_mode != info->new_mode && | 70 | if (info->old_mode != info->new_mode && |
71 | !is_null_sha1(info->old_sha1) && | 71 | !is_null_sha1(info->old_sha1) && |
72 | !is_null_sha1(info->new_sha1)) { | 72 | !is_null_sha1(info->new_sha1)) { |
73 | html("<span class='modechange'>["); | 73 | html("<span class='modechange'>["); |
74 | html_filemode(info->old_mode); | 74 | html_filemode(info->old_mode); |
75 | html("]</span>"); | 75 | html("]</span>"); |
76 | } | 76 | } |
77 | htmlf("</td><td class='%s'>", class); | 77 | htmlf("</td><td class='%s'>", class); |
78 | cgit_diff_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, | 78 | cgit_diff_link(info->new_path, NULL, NULL, cgit_query_head, curr_rev, |
79 | NULL, info->new_path); | 79 | NULL, info->new_path); |
80 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 80 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
81 | htmlf(" (%s from %s)", | 81 | htmlf(" (%s from %s)", |
82 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", | 82 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
83 | info->old_path); | 83 | info->old_path); |
84 | html("</td><td class='right'>"); | 84 | html("</td><td class='right'>"); |
85 | htmlf("%d", info->added + info->removed); | 85 | htmlf("%d", info->added + info->removed); |
86 | html("</td><td class='graph'>"); | 86 | html("</td><td class='graph'>"); |
87 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 87 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
88 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 88 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
89 | info->added * 100.0 / max_changes); | 89 | info->added * 100.0 / max_changes); |
90 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 90 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
91 | info->removed * 100.0 / max_changes); | 91 | info->removed * 100.0 / max_changes); |
92 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 92 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
93 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 93 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
94 | html("</tr></table></td></tr>\n"); | 94 | html("</tr></table></td></tr>\n"); |
95 | } | 95 | } |
96 | 96 | ||
97 | void cgit_count_diff_lines(char *line, int len) | 97 | void cgit_count_diff_lines(char *line, int len) |
98 | { | 98 | { |
99 | if (line && (len > 0)) { | 99 | if (line && (len > 0)) { |
100 | if (line[0] == '+') | 100 | if (line[0] == '+') |
101 | lines_added++; | 101 | lines_added++; |
102 | else if (line[0] == '-') | 102 | else if (line[0] == '-') |
103 | lines_removed++; | 103 | lines_removed++; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | void inspect_filepair(struct diff_filepair *pair) | 107 | void inspect_filepair(struct diff_filepair *pair) |
108 | { | 108 | { |
109 | files++; | 109 | files++; |
110 | lines_added = 0; | 110 | lines_added = 0; |
111 | lines_removed = 0; | 111 | lines_removed = 0; |
112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 112 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
113 | if (files >= slots) { | 113 | if (files >= slots) { |
114 | if (slots == 0) | 114 | if (slots == 0) |
115 | slots = 4; | 115 | slots = 4; |
116 | else | 116 | else |
117 | slots = slots * 2; | 117 | slots = slots * 2; |
118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 118 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
119 | } | 119 | } |
120 | items[files-1].status = pair->status; | 120 | items[files-1].status = pair->status; |
121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 121 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 122 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
123 | items[files-1].old_mode = pair->one->mode; | 123 | items[files-1].old_mode = pair->one->mode; |
124 | items[files-1].new_mode = pair->two->mode; | 124 | items[files-1].new_mode = pair->two->mode; |
125 | items[files-1].old_path = xstrdup(pair->one->path); | 125 | items[files-1].old_path = xstrdup(pair->one->path); |
126 | items[files-1].new_path = xstrdup(pair->two->path); | 126 | items[files-1].new_path = xstrdup(pair->two->path); |
127 | items[files-1].added = lines_added; | 127 | items[files-1].added = lines_added; |
128 | items[files-1].removed = lines_removed; | 128 | items[files-1].removed = lines_removed; |
129 | if (lines_added + lines_removed > max_changes) | 129 | if (lines_added + lines_removed > max_changes) |
130 | max_changes = lines_added + lines_removed; | 130 | max_changes = lines_added + lines_removed; |
131 | total_adds += lines_added; | 131 | total_adds += lines_added; |
132 | total_rems += lines_removed; | 132 | total_rems += lines_removed; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void cgit_print_commit(char *hex) | 136 | void cgit_print_commit(char *hex) |
137 | { | 137 | { |
138 | struct commit *commit, *parent; | 138 | struct commit *commit, *parent; |
139 | struct commitinfo *info; | 139 | struct commitinfo *info; |
140 | struct commit_list *p; | 140 | struct commit_list *p; |
141 | unsigned char sha1[20]; | 141 | unsigned char sha1[20]; |
142 | char *tmp; | 142 | char *tmp; |
143 | int i; | 143 | int i; |
144 | 144 | ||
145 | if (!hex) | 145 | if (!hex) |
146 | hex = cgit_query_head; | 146 | hex = cgit_query_head; |
147 | curr_rev = hex; | 147 | curr_rev = hex; |
148 | 148 | ||
149 | if (get_sha1(hex, sha1)) { | 149 | if (get_sha1(hex, sha1)) { |
150 | cgit_print_error(fmt("Bad object id: %s", hex)); | 150 | cgit_print_error(fmt("Bad object id: %s", hex)); |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | commit = lookup_commit_reference(sha1); | 153 | commit = lookup_commit_reference(sha1); |
154 | if (!commit) { | 154 | if (!commit) { |
155 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 155 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
156 | return; | 156 | return; |
157 | } | 157 | } |
158 | info = cgit_parse_commit(commit); | 158 | info = cgit_parse_commit(commit); |
159 | 159 | ||
160 | html("<table class='commit-info'>\n"); | 160 | html("<table summary='commit info' class='commit-info'>\n"); |
161 | html("<tr><th>author</th><td>"); | 161 | html("<tr><th>author</th><td>"); |
162 | html_txt(info->author); | 162 | html_txt(info->author); |
163 | html(" "); | 163 | html(" "); |
164 | html_txt(info->author_email); | 164 | html_txt(info->author_email); |
165 | html("</td><td class='right'>"); | 165 | html("</td><td class='right'>"); |
166 | cgit_print_date(info->author_date, FMT_LONGDATE); | 166 | cgit_print_date(info->author_date, FMT_LONGDATE); |
167 | html("</td></tr>\n"); | 167 | html("</td></tr>\n"); |
168 | html("<tr><th>committer</th><td>"); | 168 | html("<tr><th>committer</th><td>"); |
169 | html_txt(info->committer); | 169 | html_txt(info->committer); |
170 | html(" "); | 170 | html(" "); |
171 | html_txt(info->committer_email); | 171 | html_txt(info->committer_email); |
172 | html("</td><td class='right'>"); | 172 | html("</td><td class='right'>"); |
173 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 173 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
174 | html("</td></tr>\n"); | 174 | html("</td></tr>\n"); |
175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
176 | tmp = xstrdup(hex); | 176 | tmp = xstrdup(hex); |
177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
178 | cgit_query_head, tmp, NULL); | 178 | cgit_query_head, tmp, NULL); |
179 | html("</td></tr>\n"); | 179 | html("</td></tr>\n"); |
180 | for (p = commit->parents; p ; p = p->next) { | 180 | for (p = commit->parents; p ; p = p->next) { |
181 | parent = lookup_commit_reference(p->item->object.sha1); | 181 | parent = lookup_commit_reference(p->item->object.sha1); |
182 | if (!parent) { | 182 | if (!parent) { |
183 | html("<tr><td colspan='3'>"); | 183 | html("<tr><td colspan='3'>"); |
184 | cgit_print_error("Error reading parent commit"); | 184 | cgit_print_error("Error reading parent commit"); |
185 | html("</td></tr>"); | 185 | html("</td></tr>"); |
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | html("<tr><th>parent</th>" | 188 | html("<tr><th>parent</th>" |
189 | "<td colspan='2' class='sha1'>"); | 189 | "<td colspan='2' class='sha1'>"); |
190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); | 191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); |
192 | html(" ("); | 192 | html(" ("); |
193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, | 193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, |
194 | sha1_to_hex(p->item->object.sha1), NULL); | 194 | sha1_to_hex(p->item->object.sha1), NULL); |
195 | html(")</td></tr>"); | 195 | html(")</td></tr>"); |
196 | } | 196 | } |
197 | if (cgit_repo->snapshots) { | 197 | if (cgit_repo->snapshots) { |
198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
199 | cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, | 199 | cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, |
200 | hex, cgit_repo->snapshots); | 200 | hex, cgit_repo->snapshots); |
201 | html("</td></tr>"); | 201 | html("</td></tr>"); |
202 | } | 202 | } |
203 | html("</table>\n"); | 203 | html("</table>\n"); |
204 | html("<div class='commit-subject'>"); | 204 | html("<div class='commit-subject'>"); |
205 | html_txt(info->subject); | 205 | html_txt(info->subject); |
206 | html("</div>"); | 206 | html("</div>"); |
207 | html("<div class='commit-msg'>"); | 207 | html("<div class='commit-msg'>"); |
208 | html_txt(info->msg); | 208 | html_txt(info->msg); |
209 | html("</div>"); | 209 | html("</div>"); |
210 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 210 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
211 | html("<div class='diffstat-header'>Diffstat</div>"); | 211 | html("<div class='diffstat-header'>Diffstat</div>"); |
212 | html("<table class='diffstat'>"); | 212 | html("<table summary='diffstat' class='diffstat'>"); |
213 | max_changes = 0; | 213 | max_changes = 0; |
214 | cgit_diff_commit(commit, inspect_filepair); | 214 | cgit_diff_commit(commit, inspect_filepair); |
215 | for(i = 0; i<files; i++) | 215 | for(i = 0; i<files; i++) |
216 | print_fileinfo(&items[i]); | 216 | print_fileinfo(&items[i]); |
217 | html("</table>"); | 217 | html("</table>"); |
218 | html("<div class='diffstat-summary'>"); | 218 | html("<div class='diffstat-summary'>"); |
219 | htmlf("%d files changed, %d insertions, %d deletions (", | 219 | htmlf("%d files changed, %d insertions, %d deletions (", |
220 | files, total_adds, total_rems); | 220 | files, total_adds, total_rems); |
221 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, | 221 | cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, |
222 | NULL, NULL); | 222 | NULL, NULL); |
223 | html(")</div>"); | 223 | html(")</div>"); |
224 | } | 224 | } |
225 | cgit_free_commitinfo(info); | 225 | cgit_free_commitinfo(info); |
226 | } | 226 | } |
@@ -48,102 +48,102 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
48 | html_txt(path2); | 48 | html_txt(path2); |
49 | 49 | ||
50 | if (is_null_sha1(sha1)) | 50 | if (is_null_sha1(sha1)) |
51 | path1 = "dev/null"; | 51 | path1 = "dev/null"; |
52 | if (is_null_sha1(sha2)) | 52 | if (is_null_sha1(sha2)) |
53 | path2 = "dev/null"; | 53 | path2 = "dev/null"; |
54 | 54 | ||
55 | if (mode1 == 0) | 55 | if (mode1 == 0) |
56 | htmlf("<br/>new file mode %.6o", mode2); | 56 | htmlf("<br/>new file mode %.6o", mode2); |
57 | 57 | ||
58 | if (mode2 == 0) | 58 | if (mode2 == 0) |
59 | htmlf("<br/>deleted file mode %.6o", mode1); | 59 | htmlf("<br/>deleted file mode %.6o", mode1); |
60 | 60 | ||
61 | if (!subproject) { | 61 | if (!subproject) { |
62 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | 62 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
63 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | 63 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
64 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); | 64 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
65 | free(abbrev1); | 65 | free(abbrev1); |
66 | free(abbrev2); | 66 | free(abbrev2); |
67 | if (mode1 != 0 && mode2 != 0) { | 67 | if (mode1 != 0 && mode2 != 0) { |
68 | htmlf(" %.6o", mode1); | 68 | htmlf(" %.6o", mode1); |
69 | if (mode2 != mode1) | 69 | if (mode2 != mode1) |
70 | htmlf("..%.6o", mode2); | 70 | htmlf("..%.6o", mode2); |
71 | } | 71 | } |
72 | html("<br/>--- a/"); | 72 | html("<br/>--- a/"); |
73 | if (mode1 != 0) | 73 | if (mode1 != 0) |
74 | cgit_tree_link(path1, NULL, NULL, cgit_query_head, | 74 | cgit_tree_link(path1, NULL, NULL, cgit_query_head, |
75 | sha1_to_hex(old_rev_sha1), path1); | 75 | sha1_to_hex(old_rev_sha1), path1); |
76 | else | 76 | else |
77 | html_txt(path1); | 77 | html_txt(path1); |
78 | html("<br/>+++ b/"); | 78 | html("<br/>+++ b/"); |
79 | if (mode2 != 0) | 79 | if (mode2 != 0) |
80 | cgit_tree_link(path2, NULL, NULL, cgit_query_head, | 80 | cgit_tree_link(path2, NULL, NULL, cgit_query_head, |
81 | sha1_to_hex(new_rev_sha1), path2); | 81 | sha1_to_hex(new_rev_sha1), path2); |
82 | else | 82 | else |
83 | html_txt(path2); | 83 | html_txt(path2); |
84 | } | 84 | } |
85 | html("</div>"); | 85 | html("</div>"); |
86 | } | 86 | } |
87 | 87 | ||
88 | static void filepair_cb(struct diff_filepair *pair) | 88 | static void filepair_cb(struct diff_filepair *pair) |
89 | { | 89 | { |
90 | header(pair->one->sha1, pair->one->path, pair->one->mode, | 90 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
91 | pair->two->sha1, pair->two->path, pair->two->mode); | 91 | pair->two->sha1, pair->two->path, pair->two->mode); |
92 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 92 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
93 | if (S_ISGITLINK(pair->one->mode)) | 93 | if (S_ISGITLINK(pair->one->mode)) |
94 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 94 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
95 | if (S_ISGITLINK(pair->two->mode)) | 95 | if (S_ISGITLINK(pair->two->mode)) |
96 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 96 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
97 | return; | 97 | return; |
98 | } | 98 | } |
99 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) | 99 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
100 | cgit_print_error("Error running diff"); | 100 | cgit_print_error("Error running diff"); |
101 | } | 101 | } |
102 | 102 | ||
103 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 103 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
104 | { | 104 | { |
105 | enum object_type type; | 105 | enum object_type type; |
106 | unsigned long size; | 106 | unsigned long size; |
107 | struct commit *commit, *commit2; | 107 | struct commit *commit, *commit2; |
108 | 108 | ||
109 | if (!new_rev) | 109 | if (!new_rev) |
110 | new_rev = cgit_query_head; | 110 | new_rev = cgit_query_head; |
111 | get_sha1(new_rev, new_rev_sha1); | 111 | get_sha1(new_rev, new_rev_sha1); |
112 | type = sha1_object_info(new_rev_sha1, &size); | 112 | type = sha1_object_info(new_rev_sha1, &size); |
113 | if (type == OBJ_BAD) { | 113 | if (type == OBJ_BAD) { |
114 | cgit_print_error(fmt("Bad object name: %s", new_rev)); | 114 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | if (type != OBJ_COMMIT) { | 117 | if (type != OBJ_COMMIT) { |
118 | cgit_print_error(fmt("Unhandled object type: %s", | 118 | cgit_print_error(fmt("Unhandled object type: %s", |
119 | typename(type))); | 119 | typename(type))); |
120 | return; | 120 | return; |
121 | } | 121 | } |
122 | 122 | ||
123 | commit = lookup_commit_reference(new_rev_sha1); | 123 | commit = lookup_commit_reference(new_rev_sha1); |
124 | if (!commit || parse_commit(commit)) | 124 | if (!commit || parse_commit(commit)) |
125 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); | 125 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
126 | 126 | ||
127 | if (old_rev) | 127 | if (old_rev) |
128 | get_sha1(old_rev, old_rev_sha1); | 128 | get_sha1(old_rev, old_rev_sha1); |
129 | else if (commit->parents && commit->parents->item) | 129 | else if (commit->parents && commit->parents->item) |
130 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); | 130 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
131 | else | 131 | else |
132 | hashclr(old_rev_sha1); | 132 | hashclr(old_rev_sha1); |
133 | 133 | ||
134 | if (!is_null_sha1(old_rev_sha1)) { | 134 | if (!is_null_sha1(old_rev_sha1)) { |
135 | type = sha1_object_info(old_rev_sha1, &size); | 135 | type = sha1_object_info(old_rev_sha1, &size); |
136 | if (type == OBJ_BAD) { | 136 | if (type == OBJ_BAD) { |
137 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); | 137 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | commit2 = lookup_commit_reference(old_rev_sha1); | 140 | commit2 = lookup_commit_reference(old_rev_sha1); |
141 | if (!commit2 || parse_commit(commit2)) | 141 | if (!commit2 || parse_commit(commit2)) |
142 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); | 142 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
143 | } | 143 | } |
144 | html("<table class='diff'>"); | 144 | html("<table summary='diff' class='diff'>"); |
145 | html("<tr><td>"); | 145 | html("<tr><td>"); |
146 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); | 146 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
147 | html("</td></tr>"); | 147 | html("</td></tr>"); |
148 | html("</table>"); | 148 | html("</table>"); |
149 | } | 149 | } |
@@ -1,133 +1,140 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
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 | int files, lines; | 11 | int files, add_lines, rem_lines; |
12 | 12 | ||
13 | void count_lines(char *line, int size) | 13 | void count_lines(char *line, int size) |
14 | { | 14 | { |
15 | if (size>0 && (line[0] == '+' || line[0] == '-')) | 15 | if (size <= 0) |
16 | lines++; | 16 | return; |
17 | |||
18 | if (line[0] == '+') | ||
19 | add_lines++; | ||
20 | |||
21 | else if (line[0] == '-') | ||
22 | rem_lines++; | ||
17 | } | 23 | } |
18 | 24 | ||
19 | void inspect_files(struct diff_filepair *pair) | 25 | void inspect_files(struct diff_filepair *pair) |
20 | { | 26 | { |
21 | files++; | 27 | files++; |
22 | if (cgit_repo->enable_log_linecount) | 28 | if (cgit_repo->enable_log_linecount) |
23 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 29 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
24 | } | 30 | } |
25 | 31 | ||
26 | void print_commit(struct commit *commit) | 32 | void print_commit(struct commit *commit) |
27 | { | 33 | { |
28 | struct commitinfo *info; | 34 | struct commitinfo *info; |
29 | 35 | ||
30 | info = cgit_parse_commit(commit); | 36 | info = cgit_parse_commit(commit); |
31 | html("<tr><td>"); | 37 | html("<tr><td>"); |
32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 38 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
33 | html("</td><td>"); | 39 | html("</td><td>"); |
34 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, | 40 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, |
35 | sha1_to_hex(commit->object.sha1)); | 41 | sha1_to_hex(commit->object.sha1)); |
36 | if (cgit_repo->enable_log_filecount) { | 42 | if (cgit_repo->enable_log_filecount) { |
37 | files = 0; | 43 | files = 0; |
38 | lines = 0; | 44 | add_lines = 0; |
45 | rem_lines = 0; | ||
39 | cgit_diff_commit(commit, inspect_files); | 46 | cgit_diff_commit(commit, inspect_files); |
40 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
41 | htmlf("%d", files); | 48 | htmlf("%d", files); |
42 | if (cgit_repo->enable_log_linecount) { | 49 | if (cgit_repo->enable_log_linecount) { |
43 | html("</td><td class='right'>"); | 50 | html("</td><td class='right'>"); |
44 | htmlf("%d", lines); | 51 | htmlf("-%d/+%d", rem_lines, add_lines); |
45 | } | 52 | } |
46 | } | 53 | } |
47 | html("</td><td>"); | 54 | html("</td><td>"); |
48 | html_txt(info->author); | 55 | html_txt(info->author); |
49 | html("</td></tr>\n"); | 56 | html("</td></tr>\n"); |
50 | cgit_free_commitinfo(info); | 57 | cgit_free_commitinfo(info); |
51 | } | 58 | } |
52 | 59 | ||
53 | 60 | ||
54 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) | 61 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) |
55 | { | 62 | { |
56 | struct rev_info rev; | 63 | struct rev_info rev; |
57 | struct commit *commit; | 64 | struct commit *commit; |
58 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 65 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
59 | int argc = 2; | 66 | int argc = 2; |
60 | int i; | 67 | int i; |
61 | 68 | ||
62 | if (!tip) | 69 | if (!tip) |
63 | argv[1] = cgit_query_head; | 70 | argv[1] = cgit_query_head; |
64 | 71 | ||
65 | if (grep && pattern && (!strcmp(grep, "grep") || | 72 | if (grep && pattern && (!strcmp(grep, "grep") || |
66 | !strcmp(grep, "author") || | 73 | !strcmp(grep, "author") || |
67 | !strcmp(grep, "committer"))) | 74 | !strcmp(grep, "committer"))) |
68 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 75 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
69 | 76 | ||
70 | if (path) { | 77 | if (path) { |
71 | argv[argc++] = "--"; | 78 | argv[argc++] = "--"; |
72 | argv[argc++] = path; | 79 | argv[argc++] = path; |
73 | } | 80 | } |
74 | init_revisions(&rev, NULL); | 81 | init_revisions(&rev, NULL); |
75 | rev.abbrev = DEFAULT_ABBREV; | 82 | rev.abbrev = DEFAULT_ABBREV; |
76 | rev.commit_format = CMIT_FMT_DEFAULT; | 83 | rev.commit_format = CMIT_FMT_DEFAULT; |
77 | rev.verbose_header = 1; | 84 | rev.verbose_header = 1; |
78 | rev.show_root_diff = 0; | 85 | rev.show_root_diff = 0; |
79 | setup_revisions(argc, argv, &rev, NULL); | 86 | setup_revisions(argc, argv, &rev, NULL); |
80 | if (rev.grep_filter) { | 87 | if (rev.grep_filter) { |
81 | rev.grep_filter->regflags |= REG_ICASE; | 88 | rev.grep_filter->regflags |= REG_ICASE; |
82 | compile_grep_patterns(rev.grep_filter); | 89 | compile_grep_patterns(rev.grep_filter); |
83 | } | 90 | } |
84 | prepare_revision_walk(&rev); | 91 | prepare_revision_walk(&rev); |
85 | 92 | ||
86 | html("<table class='list nowrap'>"); | 93 | html("<table summary='log' class='list nowrap'>"); |
87 | html("<tr class='nohover'><th class='left'>Age</th>" | 94 | html("<tr class='nohover'><th class='left'>Age</th>" |
88 | "<th class='left'>Message</th>"); | 95 | "<th class='left'>Message</th>"); |
89 | 96 | ||
90 | if (cgit_repo->enable_log_filecount) { | 97 | if (cgit_repo->enable_log_filecount) { |
91 | html("<th class='left'>Files</th>"); | 98 | html("<th class='right'>Files</th>"); |
92 | if (cgit_repo->enable_log_linecount) | 99 | if (cgit_repo->enable_log_linecount) |
93 | html("<th class='left'>Lines</th>"); | 100 | html("<th class='right'>Lines</th>"); |
94 | } | 101 | } |
95 | html("<th class='left'>Author</th></tr>\n"); | 102 | html("<th class='left'>Author</th></tr>\n"); |
96 | 103 | ||
97 | if (ofs<0) | 104 | if (ofs<0) |
98 | ofs = 0; | 105 | ofs = 0; |
99 | 106 | ||
100 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 107 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
101 | free(commit->buffer); | 108 | free(commit->buffer); |
102 | commit->buffer = NULL; | 109 | commit->buffer = NULL; |
103 | free_commit_list(commit->parents); | 110 | free_commit_list(commit->parents); |
104 | commit->parents = NULL; | 111 | commit->parents = NULL; |
105 | } | 112 | } |
106 | 113 | ||
107 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 114 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
108 | print_commit(commit); | 115 | print_commit(commit); |
109 | free(commit->buffer); | 116 | free(commit->buffer); |
110 | commit->buffer = NULL; | 117 | commit->buffer = NULL; |
111 | free_commit_list(commit->parents); | 118 | free_commit_list(commit->parents); |
112 | commit->parents = NULL; | 119 | commit->parents = NULL; |
113 | } | 120 | } |
114 | html("</table>\n"); | 121 | html("</table>\n"); |
115 | 122 | ||
116 | if (pager) { | 123 | if (pager) { |
117 | html("<div class='pager'>"); | 124 | html("<div class='pager'>"); |
118 | if (ofs > 0) { | 125 | if (ofs > 0) { |
119 | cgit_log_link("[prev]", NULL, NULL, cgit_query_head, | 126 | cgit_log_link("[prev]", NULL, NULL, cgit_query_head, |
120 | cgit_query_sha1, cgit_query_path, | 127 | cgit_query_sha1, cgit_query_path, |
121 | ofs - cnt, cgit_query_grep, | 128 | ofs - cnt, cgit_query_grep, |
122 | cgit_query_search); | 129 | cgit_query_search); |
123 | html(" "); | 130 | html(" "); |
124 | } | 131 | } |
125 | if ((commit = get_revision(&rev)) != NULL) { | 132 | if ((commit = get_revision(&rev)) != NULL) { |
126 | cgit_log_link("[next]", NULL, NULL, cgit_query_head, | 133 | cgit_log_link("[next]", NULL, NULL, cgit_query_head, |
127 | cgit_query_sha1, cgit_query_path, | 134 | cgit_query_sha1, cgit_query_path, |
128 | ofs + cnt, cgit_query_grep, | 135 | ofs + cnt, cgit_query_grep, |
129 | cgit_query_search); | 136 | cgit_query_search); |
130 | } | 137 | } |
131 | html("</div>"); | 138 | html("</div>"); |
132 | } | 139 | } |
133 | } | 140 | } |
diff --git a/ui-patch.c b/ui-patch.c new file mode 100644 index 0000000..e7a010a --- a/dev/null +++ b/ui-patch.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* ui-patch.c: generate patch view | ||
2 | * | ||
3 | * Copyright (C) 2007 Lars Hjemli | ||
4 | * | ||
5 | * Licensed under GNU General Public License v2 | ||
6 | * (see COPYING for full license text) | ||
7 | */ | ||
8 | |||
9 | #include "cgit.h" | ||
10 | |||
11 | static void print_line(char *line, int len) | ||
12 | { | ||
13 | char c = line[len-1]; | ||
14 | |||
15 | line[len-1] = '\0'; | ||
16 | htmlf("%s\n", line); | ||
17 | line[len-1] = c; | ||
18 | } | ||
19 | |||
20 | static void header(unsigned char *sha1, char *path1, int mode1, | ||
21 | unsigned char *sha2, char *path2, int mode2) | ||
22 | { | ||
23 | char *abbrev1, *abbrev2; | ||
24 | int subproject; | ||
25 | |||
26 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | ||
27 | htmlf("diff --git a/%s b/%s\n", path1, path2); | ||
28 | |||
29 | if (is_null_sha1(sha1)) | ||
30 | path1 = "dev/null"; | ||
31 | if (is_null_sha1(sha2)) | ||
32 | path2 = "dev/null"; | ||
33 | |||
34 | if (mode1 == 0) | ||
35 | htmlf("new file mode %.6o\n", mode2); | ||
36 | |||
37 | if (mode2 == 0) | ||
38 | htmlf("deleted file mode %.6o\n", mode1); | ||
39 | |||
40 | if (!subproject) { | ||
41 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | ||
42 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | ||
43 | htmlf("index %s..%s", abbrev1, abbrev2); | ||
44 | free(abbrev1); | ||
45 | free(abbrev2); | ||
46 | if (mode1 != 0 && mode2 != 0) { | ||
47 | htmlf(" %.6o", mode1); | ||
48 | if (mode2 != mode1) | ||
49 | htmlf("..%.6o", mode2); | ||
50 | } | ||
51 | htmlf("\n--- a/%s\n", path1); | ||
52 | htmlf("+++ b/%s\n", path2); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | static void filepair_cb(struct diff_filepair *pair) | ||
57 | { | ||
58 | header(pair->one->sha1, pair->one->path, pair->one->mode, | ||
59 | pair->two->sha1, pair->two->path, pair->two->mode); | ||
60 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | ||
61 | if (S_ISGITLINK(pair->one->mode)) | ||
62 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | ||
63 | if (S_ISGITLINK(pair->two->mode)) | ||
64 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | ||
65 | return; | ||
66 | } | ||
67 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) | ||
68 | html("Error running diff"); | ||
69 | } | ||
70 | |||
71 | void cgit_print_patch(char *hex, struct cacheitem *item) | ||
72 | { | ||
73 | struct commit *commit; | ||
74 | struct commitinfo *info; | ||
75 | unsigned char sha1[20], old_sha1[20]; | ||
76 | char *patchname; | ||
77 | |||
78 | if (!hex) | ||
79 | hex = cgit_query_head; | ||
80 | |||
81 | if (get_sha1(hex, sha1)) { | ||
82 | cgit_print_error(fmt("Bad object id: %s", hex)); | ||
83 | return; | ||
84 | } | ||
85 | commit = lookup_commit_reference(sha1); | ||
86 | if (!commit) { | ||
87 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | ||
88 | return; | ||
89 | } | ||
90 | info = cgit_parse_commit(commit); | ||
91 | hashcpy(old_sha1, commit->parents->item->object.sha1); | ||
92 | |||
93 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); | ||
94 | cgit_print_snapshot_start("text/plain", patchname, item); | ||
95 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); | ||
96 | htmlf("From: %s%s\n", info->author, info->author_email); | ||
97 | html("Date: "); | ||
98 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n"); | ||
99 | htmlf("Subject: %s\n\n", info->subject); | ||
100 | if (info->msg && *info->msg) { | ||
101 | htmlf("%s", info->msg); | ||
102 | if (info->msg[strlen(info->msg) - 1] != '\n') | ||
103 | html("\n"); | ||
104 | } | ||
105 | html("---\n"); | ||
106 | cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); | ||
107 | html("--\n"); | ||
108 | htmlf("cgit %s\n", CGIT_VERSION); | ||
109 | cgit_free_commitinfo(info); | ||
110 | } | ||
diff --git a/ui-repolist.c b/ui-repolist.c index 9aa5c1e..3e97ca9 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,110 +1,110 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
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 | #include <time.h> | 10 | #include <time.h> |
11 | 11 | ||
12 | 12 | ||
13 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
14 | { | 14 | { |
15 | FILE *f; | 15 | FILE *f; |
16 | static char buf[64], buf2[64]; | 16 | static char buf[64], buf2[64]; |
17 | 17 | ||
18 | if (!(f = fopen(path, "r"))) | 18 | if (!(f = fopen(path, "r"))) |
19 | return -1; | 19 | return -1; |
20 | fgets(buf, sizeof(buf), f); | 20 | fgets(buf, sizeof(buf), f); |
21 | fclose(f); | 21 | fclose(f); |
22 | if (parse_date(buf, buf2, sizeof(buf2))) | 22 | if (parse_date(buf, buf2, sizeof(buf2))) |
23 | return strtoul(buf2, NULL, 10); | 23 | return strtoul(buf2, NULL, 10); |
24 | else | 24 | else |
25 | return 0; | 25 | return 0; |
26 | } | 26 | } |
27 | 27 | ||
28 | static void print_modtime(struct repoinfo *repo) | 28 | static void print_modtime(struct repoinfo *repo) |
29 | { | 29 | { |
30 | char *path; | 30 | char *path; |
31 | struct stat s; | 31 | struct stat s; |
32 | 32 | ||
33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 33 | path = fmt("%s/%s", repo->path, cgit_agefile); |
34 | if (stat(path, &s) == 0) { | 34 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 35 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
40 | if (stat(path, &s) != 0) | 40 | if (stat(path, &s) != 0) |
41 | return; | 41 | return; |
42 | cgit_print_age(s.st_mtime, -1, NULL); | 42 | cgit_print_age(s.st_mtime, -1, NULL); |
43 | } | 43 | } |
44 | 44 | ||
45 | void cgit_print_repolist(struct cacheitem *item) | 45 | void cgit_print_repolist(struct cacheitem *item) |
46 | { | 46 | { |
47 | int i, columns = 4; | 47 | int i, columns = 4; |
48 | char *last_group = NULL; | 48 | char *last_group = NULL; |
49 | 49 | ||
50 | if (cgit_enable_index_links) | 50 | if (cgit_enable_index_links) |
51 | columns++; | 51 | columns++; |
52 | 52 | ||
53 | cgit_print_docstart(cgit_root_title, item); | 53 | cgit_print_docstart(cgit_root_title, item); |
54 | cgit_print_pageheader(cgit_root_title, 0); | 54 | cgit_print_pageheader(cgit_root_title, 0); |
55 | 55 | ||
56 | html("<table class='list nowrap'>"); | 56 | html("<table summary='repository list' class='list nowrap'>"); |
57 | if (cgit_index_header) { | 57 | if (cgit_index_header) { |
58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
59 | columns); | 59 | columns); |
60 | html_include(cgit_index_header); | 60 | html_include(cgit_index_header); |
61 | html("</td></tr>"); | 61 | html("</td></tr>"); |
62 | } | 62 | } |
63 | html("<tr class='nohover'>" | 63 | html("<tr class='nohover'>" |
64 | "<th class='left'>Name</th>" | 64 | "<th class='left'>Name</th>" |
65 | "<th class='left'>Description</th>" | 65 | "<th class='left'>Description</th>" |
66 | "<th class='left'>Owner</th>" | 66 | "<th class='left'>Owner</th>" |
67 | "<th class='left'>Idle</th>"); | 67 | "<th class='left'>Idle</th>"); |
68 | if (cgit_enable_index_links) | 68 | if (cgit_enable_index_links) |
69 | html("<th>Links</th>"); | 69 | html("<th>Links</th>"); |
70 | html("</tr>\n"); | 70 | html("</tr>\n"); |
71 | 71 | ||
72 | for (i=0; i<cgit_repolist.count; i++) { | 72 | for (i=0; i<cgit_repolist.count; i++) { |
73 | cgit_repo = &cgit_repolist.repos[i]; | 73 | cgit_repo = &cgit_repolist.repos[i]; |
74 | if ((last_group == NULL && cgit_repo->group != NULL) || | 74 | if ((last_group == NULL && cgit_repo->group != NULL) || |
75 | (last_group != NULL && cgit_repo->group == NULL) || | 75 | (last_group != NULL && cgit_repo->group == NULL) || |
76 | (last_group != NULL && cgit_repo->group != NULL && | 76 | (last_group != NULL && cgit_repo->group != NULL && |
77 | strcmp(cgit_repo->group, last_group))) { | 77 | strcmp(cgit_repo->group, last_group))) { |
78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
79 | columns); | 79 | columns); |
80 | html_txt(cgit_repo->group); | 80 | html_txt(cgit_repo->group); |
81 | html("</td></tr>"); | 81 | html("</td></tr>"); |
82 | last_group = cgit_repo->group; | 82 | last_group = cgit_repo->group; |
83 | } | 83 | } |
84 | htmlf("<tr><td class='%s'>", | 84 | htmlf("<tr><td class='%s'>", |
85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); | 85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); |
86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); | 86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); |
87 | html_txt(cgit_repo->name); | 87 | html_txt(cgit_repo->name); |
88 | html_link_close(); | 88 | html_link_close(); |
89 | html("</td><td>"); | 89 | html("</td><td>"); |
90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); | 90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); |
91 | html("</td><td>"); | 91 | html("</td><td>"); |
92 | html_txt(cgit_repo->owner); | 92 | html_txt(cgit_repo->owner); |
93 | html("</td><td>"); | 93 | html("</td><td>"); |
94 | print_modtime(cgit_repo); | 94 | print_modtime(cgit_repo); |
95 | html("</td>"); | 95 | html("</td>"); |
96 | if (cgit_enable_index_links) { | 96 | if (cgit_enable_index_links) { |
97 | html("<td>"); | 97 | html("<td>"); |
98 | html_link_open(cgit_repourl(cgit_repo->url), | 98 | html_link_open(cgit_repourl(cgit_repo->url), |
99 | NULL, "button"); | 99 | NULL, "button"); |
100 | html("summary</a>"); | 100 | html("summary</a>"); |
101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, | 101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
102 | 0, NULL, NULL); | 102 | 0, NULL, NULL); |
103 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | 103 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); |
104 | html("</td>"); | 104 | html("</td>"); |
105 | } | 105 | } |
106 | html("</tr>\n"); | 106 | html("</tr>\n"); |
107 | } | 107 | } |
108 | html("</table>"); | 108 | html("</table>"); |
109 | cgit_print_docend(); | 109 | cgit_print_docend(); |
110 | } | 110 | } |
diff --git a/ui-shared.c b/ui-shared.c index 4944dfd..60aa2e3 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -179,363 +179,392 @@ static void reporevlink(char *page, char *name, char *title, char *class, | |||
179 | char *delim; | 179 | char *delim; |
180 | 180 | ||
181 | delim = repolink(title, class, page, head, path); | 181 | delim = repolink(title, class, page, head, path); |
182 | if (rev && strcmp(rev, cgit_query_head)) { | 182 | if (rev && strcmp(rev, cgit_query_head)) { |
183 | html(delim); | 183 | html(delim); |
184 | html("id="); | 184 | html("id="); |
185 | html_attr(rev); | 185 | html_attr(rev); |
186 | } | 186 | } |
187 | html("'>"); | 187 | html("'>"); |
188 | html_txt(name); | 188 | html_txt(name); |
189 | html("</a>"); | 189 | html("</a>"); |
190 | } | 190 | } |
191 | 191 | ||
192 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 192 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
193 | char *rev, char *path) | 193 | char *rev, char *path) |
194 | { | 194 | { |
195 | reporevlink("tree", name, title, class, head, rev, path); | 195 | reporevlink("tree", name, title, class, head, rev, path); |
196 | } | 196 | } |
197 | 197 | ||
198 | void cgit_log_link(char *name, char *title, char *class, char *head, | 198 | void cgit_log_link(char *name, char *title, char *class, char *head, |
199 | char *rev, char *path, int ofs, char *grep, char *pattern) | 199 | char *rev, char *path, int ofs, char *grep, char *pattern) |
200 | { | 200 | { |
201 | char *delim; | 201 | char *delim; |
202 | 202 | ||
203 | delim = repolink(title, class, "log", head, path); | 203 | delim = repolink(title, class, "log", head, path); |
204 | if (rev && strcmp(rev, cgit_query_head)) { | 204 | if (rev && strcmp(rev, cgit_query_head)) { |
205 | html(delim); | 205 | html(delim); |
206 | html("id="); | 206 | html("id="); |
207 | html_attr(rev); | 207 | html_attr(rev); |
208 | delim = "&"; | 208 | delim = "&"; |
209 | } | 209 | } |
210 | if (grep && pattern) { | 210 | if (grep && pattern) { |
211 | html(delim); | 211 | html(delim); |
212 | html("qt="); | 212 | html("qt="); |
213 | html_attr(grep); | 213 | html_attr(grep); |
214 | delim = "&"; | 214 | delim = "&"; |
215 | html(delim); | 215 | html(delim); |
216 | html("q="); | 216 | html("q="); |
217 | html_attr(pattern); | 217 | html_attr(pattern); |
218 | } | 218 | } |
219 | if (ofs > 0) { | 219 | if (ofs > 0) { |
220 | html(delim); | 220 | html(delim); |
221 | html("ofs="); | 221 | html("ofs="); |
222 | htmlf("%d", ofs); | 222 | htmlf("%d", ofs); |
223 | } | 223 | } |
224 | html("'>"); | 224 | html("'>"); |
225 | html_txt(name); | 225 | html_txt(name); |
226 | html("</a>"); | 226 | html("</a>"); |
227 | } | 227 | } |
228 | 228 | ||
229 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 229 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
230 | char *rev) | 230 | char *rev) |
231 | { | 231 | { |
232 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 232 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
233 | name[cgit_max_msg_len] = '\0'; | 233 | name[cgit_max_msg_len] = '\0'; |
234 | name[cgit_max_msg_len - 1] = '.'; | 234 | name[cgit_max_msg_len - 1] = '.'; |
235 | name[cgit_max_msg_len - 2] = '.'; | 235 | name[cgit_max_msg_len - 2] = '.'; |
236 | name[cgit_max_msg_len - 3] = '.'; | 236 | name[cgit_max_msg_len - 3] = '.'; |
237 | } | 237 | } |
238 | reporevlink("commit", name, title, class, head, rev, NULL); | 238 | reporevlink("commit", name, title, class, head, rev, NULL); |
239 | } | 239 | } |
240 | 240 | ||
241 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 241 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
242 | char *rev, char *path) | 242 | char *rev, char *path) |
243 | { | 243 | { |
244 | reporevlink("refs", name, title, class, head, rev, path); | 244 | reporevlink("refs", name, title, class, head, rev, path); |
245 | } | 245 | } |
246 | 246 | ||
247 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 247 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
248 | char *rev, char *archivename) | 248 | char *rev, char *archivename) |
249 | { | 249 | { |
250 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 250 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
251 | } | 251 | } |
252 | 252 | ||
253 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 253 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
254 | char *new_rev, char *old_rev, char *path) | 254 | char *new_rev, char *old_rev, char *path) |
255 | { | 255 | { |
256 | char *delim; | 256 | char *delim; |
257 | 257 | ||
258 | delim = repolink(title, class, "diff", head, path); | 258 | delim = repolink(title, class, "diff", head, path); |
259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
260 | html(delim); | 260 | html(delim); |
261 | html("id="); | 261 | html("id="); |
262 | html_attr(new_rev); | 262 | html_attr(new_rev); |
263 | delim = "&"; | 263 | delim = "&"; |
264 | } | 264 | } |
265 | if (old_rev) { | 265 | if (old_rev) { |
266 | html(delim); | 266 | html(delim); |
267 | html("id2="); | 267 | html("id2="); |
268 | html_attr(old_rev); | 268 | html_attr(old_rev); |
269 | } | 269 | } |
270 | html("'>"); | 270 | html("'>"); |
271 | html_txt(name); | 271 | html_txt(name); |
272 | html("</a>"); | 272 | html("</a>"); |
273 | } | 273 | } |
274 | 274 | ||
275 | void cgit_patch_link(char *name, char *title, char *class, char *head, | ||
276 | char *rev) | ||
277 | { | ||
278 | reporevlink("patch", name, title, class, head, rev, NULL); | ||
279 | } | ||
280 | |||
275 | void cgit_object_link(struct object *obj) | 281 | void cgit_object_link(struct object *obj) |
276 | { | 282 | { |
277 | char *page, *arg, *url; | 283 | char *page, *arg, *url; |
278 | 284 | ||
279 | if (obj->type == OBJ_COMMIT) { | 285 | if (obj->type == OBJ_COMMIT) { |
280 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 286 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
281 | cgit_query_head, sha1_to_hex(obj->sha1)); | 287 | cgit_query_head, sha1_to_hex(obj->sha1)); |
282 | return; | 288 | return; |
283 | } else if (obj->type == OBJ_TREE) { | 289 | } else if (obj->type == OBJ_TREE) { |
284 | page = "tree"; | 290 | page = "tree"; |
285 | arg = "id"; | 291 | arg = "id"; |
286 | } else if (obj->type == OBJ_TAG) { | 292 | } else if (obj->type == OBJ_TAG) { |
287 | page = "tag"; | 293 | page = "tag"; |
288 | arg = "id"; | 294 | arg = "id"; |
289 | } else { | 295 | } else { |
290 | page = "blob"; | 296 | page = "blob"; |
291 | arg = "id"; | 297 | arg = "id"; |
292 | } | 298 | } |
293 | 299 | ||
294 | url = cgit_pageurl(cgit_query_repo, page, | 300 | url = cgit_pageurl(cgit_query_repo, page, |
295 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 301 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
296 | html_link_open(url, NULL, NULL); | 302 | html_link_open(url, NULL, NULL); |
297 | htmlf("%s %s", typename(obj->type), | 303 | htmlf("%s %s", typename(obj->type), |
298 | sha1_to_hex(obj->sha1)); | 304 | sha1_to_hex(obj->sha1)); |
299 | html_link_close(); | 305 | html_link_close(); |
300 | } | 306 | } |
301 | 307 | ||
302 | void cgit_print_date(time_t secs, char *format) | 308 | void cgit_print_date(time_t secs, char *format) |
303 | { | 309 | { |
304 | char buf[64]; | 310 | char buf[64]; |
305 | struct tm *time; | 311 | struct tm *time; |
306 | 312 | ||
307 | if (!secs) | 313 | if (!secs) |
308 | return; | 314 | return; |
309 | time = gmtime(&secs); | 315 | time = gmtime(&secs); |
310 | strftime(buf, sizeof(buf)-1, format, time); | 316 | strftime(buf, sizeof(buf)-1, format, time); |
311 | html_txt(buf); | 317 | html_txt(buf); |
312 | } | 318 | } |
313 | 319 | ||
314 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 320 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
315 | { | 321 | { |
316 | time_t now, secs; | 322 | time_t now, secs; |
317 | 323 | ||
318 | if (!t) | 324 | if (!t) |
319 | return; | 325 | return; |
320 | time(&now); | 326 | time(&now); |
321 | secs = now - t; | 327 | secs = now - t; |
322 | 328 | ||
323 | if (secs > max_relative && max_relative >= 0) { | 329 | if (secs > max_relative && max_relative >= 0) { |
324 | cgit_print_date(t, format); | 330 | cgit_print_date(t, format); |
325 | return; | 331 | return; |
326 | } | 332 | } |
327 | 333 | ||
328 | if (secs < TM_HOUR * 2) { | 334 | if (secs < TM_HOUR * 2) { |
329 | htmlf("<span class='age-mins'>%.0f min.</span>", | 335 | htmlf("<span class='age-mins'>%.0f min.</span>", |
330 | secs * 1.0 / TM_MIN); | 336 | secs * 1.0 / TM_MIN); |
331 | return; | 337 | return; |
332 | } | 338 | } |
333 | if (secs < TM_DAY * 2) { | 339 | if (secs < TM_DAY * 2) { |
334 | htmlf("<span class='age-hours'>%.0f hours</span>", | 340 | htmlf("<span class='age-hours'>%.0f hours</span>", |
335 | secs * 1.0 / TM_HOUR); | 341 | secs * 1.0 / TM_HOUR); |
336 | return; | 342 | return; |
337 | } | 343 | } |
338 | if (secs < TM_WEEK * 2) { | 344 | if (secs < TM_WEEK * 2) { |
339 | htmlf("<span class='age-days'>%.0f days</span>", | 345 | htmlf("<span class='age-days'>%.0f days</span>", |
340 | secs * 1.0 / TM_DAY); | 346 | secs * 1.0 / TM_DAY); |
341 | return; | 347 | return; |
342 | } | 348 | } |
343 | if (secs < TM_MONTH * 2) { | 349 | if (secs < TM_MONTH * 2) { |
344 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 350 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
345 | secs * 1.0 / TM_WEEK); | 351 | secs * 1.0 / TM_WEEK); |
346 | return; | 352 | return; |
347 | } | 353 | } |
348 | if (secs < TM_YEAR * 2) { | 354 | if (secs < TM_YEAR * 2) { |
349 | htmlf("<span class='age-months'>%.0f months</span>", | 355 | htmlf("<span class='age-months'>%.0f months</span>", |
350 | secs * 1.0 / TM_MONTH); | 356 | secs * 1.0 / TM_MONTH); |
351 | return; | 357 | return; |
352 | } | 358 | } |
353 | htmlf("<span class='age-years'>%.0f years</span>", | 359 | htmlf("<span class='age-years'>%.0f years</span>", |
354 | secs * 1.0 / TM_YEAR); | 360 | secs * 1.0 / TM_YEAR); |
355 | } | 361 | } |
356 | 362 | ||
357 | void cgit_print_docstart(char *title, struct cacheitem *item) | 363 | void cgit_print_docstart(char *title, struct cacheitem *item) |
358 | { | 364 | { |
359 | html("Content-Type: text/html; charset=utf-8\n"); | 365 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); |
360 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
361 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
362 | ttl_seconds(item->ttl))); | 368 | ttl_seconds(item->ttl))); |
363 | html("\n"); | 369 | html("\n"); |
364 | html(cgit_doctype); | 370 | html(cgit_doctype); |
365 | html("<html>\n"); | 371 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
366 | html("<head>\n"); | 372 | html("<head>\n"); |
367 | html("<title>"); | 373 | html("<title>"); |
368 | html_txt(title); | 374 | html_txt(title); |
369 | html("</title>\n"); | 375 | html("</title>\n"); |
370 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
377 | if (cgit_robots && *cgit_robots) | ||
378 | htmlf("<meta name='robots' content='%s'/>\n", cgit_robots); | ||
371 | html("<link rel='stylesheet' type='text/css' href='"); | 379 | html("<link rel='stylesheet' type='text/css' href='"); |
372 | html_attr(cgit_css); | 380 | html_attr(cgit_css); |
373 | html("'/>\n"); | 381 | html("'/>\n"); |
374 | html("</head>\n"); | 382 | html("</head>\n"); |
375 | html("<body>\n"); | 383 | html("<body>\n"); |
376 | } | 384 | } |
377 | 385 | ||
378 | void cgit_print_docend() | 386 | void cgit_print_docend() |
379 | { | 387 | { |
380 | html("</td>\n</tr>\n<table>\n</body>\n</html>\n"); | 388 | html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); |
381 | } | 389 | } |
382 | 390 | ||
383 | int print_branch_option(const char *refname, const unsigned char *sha1, | 391 | int print_branch_option(const char *refname, const unsigned char *sha1, |
384 | int flags, void *cb_data) | 392 | int flags, void *cb_data) |
385 | { | 393 | { |
386 | char *name = (char *)refname; | 394 | char *name = (char *)refname; |
387 | html_option(name, name, cgit_query_head); | 395 | html_option(name, name, cgit_query_head); |
388 | return 0; | 396 | return 0; |
389 | } | 397 | } |
390 | 398 | ||
391 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 399 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
392 | int flags, void *cb_data) | 400 | int flags, void *cb_data) |
393 | { | 401 | { |
394 | struct tag *tag; | 402 | struct tag *tag; |
395 | struct taginfo *info; | 403 | struct taginfo *info; |
396 | struct object *obj; | 404 | struct object *obj; |
397 | char buf[256], *url; | 405 | char buf[256], *url; |
398 | unsigned char fileid[20]; | 406 | unsigned char fileid[20]; |
399 | int *header = (int *)cb_data; | 407 | int *header = (int *)cb_data; |
400 | 408 | ||
401 | if (prefixcmp(refname, "refs/archives")) | 409 | if (prefixcmp(refname, "refs/archives")) |
402 | return 0; | 410 | return 0; |
403 | strncpy(buf, refname+14, sizeof(buf)); | 411 | strncpy(buf, refname+14, sizeof(buf)); |
404 | obj = parse_object(sha1); | 412 | obj = parse_object(sha1); |
405 | if (!obj) | 413 | if (!obj) |
406 | return 1; | 414 | return 1; |
407 | if (obj->type == OBJ_TAG) { | 415 | if (obj->type == OBJ_TAG) { |
408 | tag = lookup_tag(sha1); | 416 | tag = lookup_tag(sha1); |
409 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 417 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
410 | return 0; | 418 | return 0; |
411 | hashcpy(fileid, tag->tagged->sha1); | 419 | hashcpy(fileid, tag->tagged->sha1); |
412 | } else if (obj->type != OBJ_BLOB) { | 420 | } else if (obj->type != OBJ_BLOB) { |
413 | return 0; | 421 | return 0; |
414 | } else { | 422 | } else { |
415 | hashcpy(fileid, sha1); | 423 | hashcpy(fileid, sha1); |
416 | } | 424 | } |
417 | if (!*header) { | 425 | if (!*header) { |
418 | html("<p><h1>download</h1>"); | 426 | html("<h1>download</h1>\n"); |
419 | *header = 1; | 427 | *header = 1; |
420 | } | 428 | } |
421 | url = cgit_pageurl(cgit_query_repo, "blob", | 429 | url = cgit_pageurl(cgit_query_repo, "blob", |
422 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
423 | buf)); | 431 | buf)); |
424 | html_link_open(url, NULL, "menu"); | 432 | html_link_open(url, NULL, "menu"); |
425 | html_txt(strlpart(buf, 20)); | 433 | html_txt(strlpart(buf, 20)); |
426 | html_link_close(); | 434 | html_link_close(); |
427 | return 0; | 435 | return 0; |
428 | } | 436 | } |
429 | 437 | ||
430 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 438 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
431 | { | 439 | { |
432 | char *url; | 440 | char *url; |
433 | 441 | ||
434 | if (!cgit_virtual_root) { | 442 | if (!cgit_virtual_root) { |
435 | url = fmt("%s/%s", cgit_query_repo, page); | 443 | url = fmt("%s/%s", cgit_query_repo, page); |
436 | if (cgit_query_path) | 444 | if (cgit_query_path) |
437 | url = fmt("%s/%s", url, cgit_query_path); | 445 | url = fmt("%s/%s", url, cgit_query_path); |
438 | html_hidden("url", url); | 446 | html_hidden("url", url); |
439 | } | 447 | } |
440 | 448 | ||
441 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) | 449 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) |
442 | html_hidden("h", cgit_query_head); | 450 | html_hidden("h", cgit_query_head); |
443 | 451 | ||
444 | if (cgit_query_sha1) | 452 | if (cgit_query_sha1) |
445 | html_hidden("id", cgit_query_sha1); | 453 | html_hidden("id", cgit_query_sha1); |
446 | if (cgit_query_sha2) | 454 | if (cgit_query_sha2) |
447 | html_hidden("id2", cgit_query_sha2); | 455 | html_hidden("id2", cgit_query_sha2); |
448 | 456 | ||
449 | if (incl_search) { | 457 | if (incl_search) { |
450 | if (cgit_query_grep) | 458 | if (cgit_query_grep) |
451 | html_hidden("qt", cgit_query_grep); | 459 | html_hidden("qt", cgit_query_grep); |
452 | if (cgit_query_search) | 460 | if (cgit_query_search) |
453 | html_hidden("q", cgit_query_search); | 461 | html_hidden("q", cgit_query_search); |
454 | } | 462 | } |
455 | } | 463 | } |
456 | 464 | ||
457 | void cgit_print_pageheader(char *title, int show_search) | 465 | void cgit_print_pageheader(char *title, int show_search) |
458 | { | 466 | { |
459 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; |
460 | int header = 0; | 468 | int header = 0; |
469 | char *url; | ||
461 | 470 | ||
462 | html("<div id='sidebar'>\n"); | 471 | html("<table id='layout' summary=''>\n"); |
463 | html("<a href='"); | 472 | html("<tr><td id='sidebar'>\n"); |
473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); | ||
474 | html("<tr><td class='sidebar'>\n<a href='"); | ||
464 | html_attr(cgit_rooturl()); | 475 | html_attr(cgit_rooturl()); |
465 | htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", | 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
466 | cgit_logo); | 477 | cgit_logo); |
467 | html("<div class='infobox'>"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
468 | if (cgit_query_repo) { | 479 | if (cgit_query_repo) { |
469 | html("<h1>"); | 480 | html("<h1 class='first'>"); |
470 | html_txt(strrpart(cgit_repo->name, 20)); | 481 | html_txt(strrpart(cgit_repo->name, 20)); |
471 | html("</h1>\n"); | 482 | html("</h1>\n"); |
472 | html_txt(cgit_repo->desc); | 483 | html_txt(cgit_repo->desc); |
473 | if (cgit_repo->owner) { | 484 | if (cgit_repo->owner) { |
474 | html("<p>\n<h1>owner</h1>\n"); | 485 | html("<h1>owner</h1>\n"); |
475 | html_txt(cgit_repo->owner); | 486 | html_txt(cgit_repo->owner); |
476 | } | 487 | } |
477 | html("<p>\n<h1>navigate</h1>\n"); | 488 | html("<h1>navigate</h1>\n"); |
478 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, | 489 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, |
479 | NULL, NULL); | 490 | NULL, NULL); |
480 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, | 491 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, |
481 | 0, NULL, NULL); | 492 | 0, NULL, NULL); |
482 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, | 493 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, |
483 | cgit_query_sha1, NULL); | 494 | cgit_query_sha1, NULL); |
484 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, | 495 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, |
485 | cgit_query_sha1); | 496 | cgit_query_sha1); |
486 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, | 497 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, |
487 | cgit_query_sha1, cgit_query_sha2, NULL); | 498 | cgit_query_sha1, cgit_query_sha2, NULL); |
499 | cgit_patch_link("patch", NULL, "menu", cgit_query_head, | ||
500 | cgit_query_sha1); | ||
488 | 501 | ||
489 | for_each_ref(print_archive_ref, &header); | 502 | for_each_ref(print_archive_ref, &header); |
490 | 503 | ||
491 | html("<p>\n<h1>branch</h1>\n"); | 504 | if (cgit_repo->clone_url || cgit_clone_prefix) { |
505 | html("<h1>clone</h1>\n"); | ||
506 | if (cgit_repo->clone_url) | ||
507 | url = cgit_repo->clone_url; | ||
508 | else | ||
509 | url = fmt("%s%s", cgit_clone_prefix, | ||
510 | cgit_repo->url); | ||
511 | html("<a class='menu' href='"); | ||
512 | html_attr(url); | ||
513 | html("' title='"); | ||
514 | html_attr(url); | ||
515 | html("'>\n"); | ||
516 | html_txt(strrpart(url, 20)); | ||
517 | html("</a>\n"); | ||
518 | } | ||
519 | |||
520 | html("<h1>branch</h1>\n"); | ||
492 | html("<form method='get' action=''>\n"); | 521 | html("<form method='get' action=''>\n"); |
493 | add_hidden_formfields(0, 1, cgit_query_page); | 522 | add_hidden_formfields(0, 1, cgit_query_page); |
494 | html("<table class='grid'><tr><td id='branch-dropdown-cell'>"); | 523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); |
495 | html("<select name='h' onchange='this.form.submit();'>\n"); | 524 | html("<select name='h' onchange='this.form.submit();'>\n"); |
496 | for_each_branch_ref(print_branch_option, cgit_query_head); | 525 | for_each_branch_ref(print_branch_option, cgit_query_head); |
497 | html("</select>\n"); | 526 | html("</select>\n"); |
498 | html("</td><td>"); | 527 | // html("</td><td>"); |
499 | html("<noscript><input type='submit' id='switch-btn' value='..'></noscript>\n"); | 528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); |
500 | html("</td></tr></table>"); | 529 | // html("</td></tr></table>"); |
501 | html("</form>\n"); | 530 | html("</form>\n"); |
502 | 531 | ||
503 | html("<p>\n<h1>search</h1>\n"); | 532 | html("<h1>search</h1>\n"); |
504 | html("<form method='get' action='"); | 533 | html("<form method='get' action='"); |
505 | if (cgit_virtual_root) | 534 | if (cgit_virtual_root) |
506 | html_attr(cgit_fileurl(cgit_query_repo, "log", | 535 | html_attr(cgit_fileurl(cgit_query_repo, "log", |
507 | cgit_query_path, NULL)); | 536 | cgit_query_path, NULL)); |
508 | html("'>\n"); | 537 | html("'>\n"); |
509 | add_hidden_formfields(1, 0, "log"); | 538 | add_hidden_formfields(1, 0, "log"); |
510 | html("<select name='qt'>\n"); | 539 | html("<select name='qt'>\n"); |
511 | html_option("grep", "log msg", cgit_query_grep); | 540 | html_option("grep", "log msg", cgit_query_grep); |
512 | html_option("author", "author", cgit_query_grep); | 541 | html_option("author", "author", cgit_query_grep); |
513 | html_option("committer", "committer", cgit_query_grep); | 542 | html_option("committer", "committer", cgit_query_grep); |
514 | html("</select>\n"); | 543 | html("</select>\n"); |
515 | html("<input class='txt' type='text' name='q' value='"); | 544 | html("<input class='txt' type='text' name='q' value='"); |
516 | html_attr(cgit_query_search); | 545 | html_attr(cgit_query_search); |
517 | html("'/>\n"); | 546 | html("'/>\n"); |
518 | html("</form>\n"); | 547 | html("</form>\n"); |
519 | } else { | 548 | } else { |
520 | if (!cgit_index_info || html_include(cgit_index_info)) | 549 | if (!cgit_index_info || html_include(cgit_index_info)) |
521 | html(default_info); | 550 | html(default_info); |
522 | } | 551 | } |
523 | 552 | ||
524 | html("</div>\n"); | 553 | html("</td></tr></table></td>\n"); |
525 | 554 | ||
526 | html("</div>\n<table class='grid'><tr><td id='content'>\n"); | 555 | html("<td id='content'>\n"); |
527 | } | 556 | } |
528 | 557 | ||
529 | 558 | ||
530 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 559 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
531 | struct cacheitem *item) | 560 | struct cacheitem *item) |
532 | { | 561 | { |
533 | htmlf("Content-Type: %s\n", mimetype); | 562 | htmlf("Content-Type: %s\n", mimetype); |
534 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 563 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
535 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 564 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
536 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 565 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
537 | ttl_seconds(item->ttl))); | 566 | ttl_seconds(item->ttl))); |
538 | html("\n"); | 567 | html("\n"); |
539 | } | 568 | } |
540 | 569 | ||
541 | /* vim:set sw=8: */ | 570 | /* vim:set sw=8: */ |
diff --git a/ui-summary.c b/ui-summary.c index c856793..b96414e 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -97,104 +97,104 @@ static int print_tag(struct refinfo *ref) | |||
97 | url = cgit_pageurl(cgit_query_repo, "tag", | 97 | url = cgit_pageurl(cgit_query_repo, "tag", |
98 | fmt("id=%s", name)); | 98 | fmt("id=%s", name)); |
99 | html_link_open(url, NULL, NULL); | 99 | html_link_open(url, NULL, NULL); |
100 | html_txt(name); | 100 | html_txt(name); |
101 | html_link_close(); | 101 | html_link_close(); |
102 | html("</td><td>"); | 102 | html("</td><td>"); |
103 | if (info->tagger_date > 0) | 103 | if (info->tagger_date > 0) |
104 | cgit_print_age(info->tagger_date, -1, NULL); | 104 | cgit_print_age(info->tagger_date, -1, NULL); |
105 | html("</td><td>"); | 105 | html("</td><td>"); |
106 | if (info->tagger) | 106 | if (info->tagger) |
107 | html(info->tagger); | 107 | html(info->tagger); |
108 | html("</td><td>"); | 108 | html("</td><td>"); |
109 | cgit_object_link(tag->tagged); | 109 | cgit_object_link(tag->tagged); |
110 | html("</td></tr>\n"); | 110 | html("</td></tr>\n"); |
111 | } else { | 111 | } else { |
112 | if (!header) | 112 | if (!header) |
113 | print_tag_header(); | 113 | print_tag_header(); |
114 | html("<tr><td>"); | 114 | html("<tr><td>"); |
115 | html_txt(name); | 115 | html_txt(name); |
116 | html("</td><td colspan='2'/><td>"); | 116 | html("</td><td colspan='2'/><td>"); |
117 | cgit_object_link(ref->object); | 117 | cgit_object_link(ref->object); |
118 | html("</td></tr>\n"); | 118 | html("</td></tr>\n"); |
119 | } | 119 | } |
120 | return 0; | 120 | return 0; |
121 | } | 121 | } |
122 | 122 | ||
123 | static void print_refs_link(char *path) | 123 | static void print_refs_link(char *path) |
124 | { | 124 | { |
125 | html("<tr class='nohover'><td colspan='4'>"); | 125 | html("<tr class='nohover'><td colspan='4'>"); |
126 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | 126 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); |
127 | html("</td></tr>"); | 127 | html("</td></tr>"); |
128 | } | 128 | } |
129 | 129 | ||
130 | void cgit_print_branches(int maxcount) | 130 | void cgit_print_branches(int maxcount) |
131 | { | 131 | { |
132 | struct reflist list; | 132 | struct reflist list; |
133 | int i; | 133 | int i; |
134 | 134 | ||
135 | html("<tr class='nohover'><th class='left'>Branch</th>" | 135 | html("<tr class='nohover'><th class='left'>Branch</th>" |
136 | "<th class='left'>Idle</th>" | 136 | "<th class='left'>Idle</th>" |
137 | "<th class='left'>Author</th>" | 137 | "<th class='left'>Author</th>" |
138 | "<th class='left'>Head commit</th></tr>\n"); | 138 | "<th class='left'>Head commit</th></tr>\n"); |
139 | 139 | ||
140 | list.refs = NULL; | 140 | list.refs = NULL; |
141 | list.alloc = list.count = 0; | 141 | list.alloc = list.count = 0; |
142 | for_each_branch_ref(cgit_refs_cb, &list); | 142 | for_each_branch_ref(cgit_refs_cb, &list); |
143 | 143 | ||
144 | if (maxcount == 0 || maxcount > list.count) | 144 | if (maxcount == 0 || maxcount > list.count) |
145 | maxcount = list.count; | 145 | maxcount = list.count; |
146 | 146 | ||
147 | if (maxcount < list.count) { | 147 | if (maxcount < list.count) { |
148 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 148 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
149 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 149 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
150 | } | 150 | } |
151 | 151 | ||
152 | for(i=0; i<maxcount; i++) | 152 | for(i=0; i<maxcount; i++) |
153 | print_branch(list.refs[i]); | 153 | print_branch(list.refs[i]); |
154 | 154 | ||
155 | if (maxcount < list.count) | 155 | if (maxcount < list.count) |
156 | print_refs_link("heads"); | 156 | print_refs_link("heads"); |
157 | } | 157 | } |
158 | 158 | ||
159 | void cgit_print_tags(int maxcount) | 159 | void cgit_print_tags(int maxcount) |
160 | { | 160 | { |
161 | struct reflist list; | 161 | struct reflist list; |
162 | int i; | 162 | int i; |
163 | 163 | ||
164 | header = 0; | 164 | header = 0; |
165 | list.refs = NULL; | 165 | list.refs = NULL; |
166 | list.alloc = list.count = 0; | 166 | list.alloc = list.count = 0; |
167 | for_each_tag_ref(cgit_refs_cb, &list); | 167 | for_each_tag_ref(cgit_refs_cb, &list); |
168 | if (list.count == 0) | 168 | if (list.count == 0) |
169 | return; | 169 | return; |
170 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 170 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
171 | if (!maxcount) | 171 | if (!maxcount) |
172 | maxcount = list.count; | 172 | maxcount = list.count; |
173 | else if (maxcount > list.count) | 173 | else if (maxcount > list.count) |
174 | maxcount = list.count; | 174 | maxcount = list.count; |
175 | print_tag_header(); | 175 | print_tag_header(); |
176 | for(i=0; i<maxcount; i++) | 176 | for(i=0; i<maxcount; i++) |
177 | print_tag(list.refs[i]); | 177 | print_tag(list.refs[i]); |
178 | 178 | ||
179 | if (maxcount < list.count) | 179 | if (maxcount < list.count) |
180 | print_refs_link("tags"); | 180 | print_refs_link("tags"); |
181 | } | 181 | } |
182 | 182 | ||
183 | void cgit_print_summary() | 183 | void cgit_print_summary() |
184 | { | 184 | { |
185 | if (cgit_repo->readme) { | 185 | if (cgit_repo->readme) { |
186 | html("<div id='summary'>"); | 186 | html("<div id='summary'>"); |
187 | html_include(cgit_repo->readme); | 187 | html_include(cgit_repo->readme); |
188 | html("</div>"); | 188 | html("</div>"); |
189 | } | 189 | } |
190 | if (cgit_summary_log > 0) | 190 | if (cgit_summary_log > 0) |
191 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, | 191 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, |
192 | NULL, NULL, 0); | 192 | NULL, NULL, 0); |
193 | html("<table class='list nowrap'>"); | 193 | html("<table summary='repository info' class='list nowrap'>"); |
194 | if (cgit_summary_log > 0) | 194 | if (cgit_summary_log > 0) |
195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
196 | cgit_print_branches(cgit_summary_branches); | 196 | cgit_print_branches(cgit_summary_branches); |
197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
198 | cgit_print_tags(cgit_summary_tags); | 198 | cgit_print_tags(cgit_summary_tags); |
199 | html("</table>"); | 199 | html("</table>"); |
200 | } | 200 | } |
@@ -1,207 +1,207 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
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 | char *curr_rev; | 11 | char *curr_rev; |
12 | char *match_path; | 12 | char *match_path; |
13 | int header = 0; | 13 | int header = 0; |
14 | 14 | ||
15 | static void print_object(const unsigned char *sha1, char *path) | 15 | static void print_object(const unsigned char *sha1, char *path) |
16 | { | 16 | { |
17 | enum object_type type; | 17 | enum object_type type; |
18 | char *buf; | 18 | char *buf; |
19 | unsigned long size, lineno, start, idx; | 19 | unsigned long size, lineno, start, idx; |
20 | const char *linefmt = "<tr><td class='no'><a name='%1$d'>%1$d</a></td><td class='txt'>"; | 20 | const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>"; |
21 | 21 | ||
22 | type = sha1_object_info(sha1, &size); | 22 | type = sha1_object_info(sha1, &size); |
23 | if (type == OBJ_BAD) { | 23 | if (type == OBJ_BAD) { |
24 | cgit_print_error(fmt("Bad object name: %s", | 24 | cgit_print_error(fmt("Bad object name: %s", |
25 | sha1_to_hex(sha1))); | 25 | sha1_to_hex(sha1))); |
26 | return; | 26 | return; |
27 | } | 27 | } |
28 | 28 | ||
29 | buf = read_sha1_file(sha1, &type, &size); | 29 | buf = read_sha1_file(sha1, &type, &size); |
30 | if (!buf) { | 30 | if (!buf) { |
31 | cgit_print_error(fmt("Error reading object %s", | 31 | cgit_print_error(fmt("Error reading object %s", |
32 | sha1_to_hex(sha1))); | 32 | sha1_to_hex(sha1))); |
33 | return; | 33 | return; |
34 | } | 34 | } |
35 | 35 | ||
36 | html(" blob: <a href='"); | 36 | html(" blob: <a href='"); |
37 | html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); | 37 | html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); |
38 | htmlf("'>%s</a>",sha1_to_hex(sha1)); | 38 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
39 | 39 | ||
40 | html("<table class='blob'>\n"); | 40 | html("<table summary='blob content' class='blob'>\n"); |
41 | idx = 0; | 41 | idx = 0; |
42 | start = 0; | 42 | start = 0; |
43 | lineno = 0; | 43 | lineno = 0; |
44 | while(idx < size) { | 44 | while(idx < size) { |
45 | if (buf[idx] == '\n') { | 45 | if (buf[idx] == '\n') { |
46 | buf[idx] = '\0'; | 46 | buf[idx] = '\0'; |
47 | htmlf(linefmt, ++lineno); | 47 | htmlf(linefmt, ++lineno); |
48 | html_txt(buf + start); | 48 | html_txt(buf + start); |
49 | html("</td></tr>\n"); | 49 | html("</td></tr>\n"); |
50 | start = idx + 1; | 50 | start = idx + 1; |
51 | } | 51 | } |
52 | idx++; | 52 | idx++; |
53 | } | 53 | } |
54 | htmlf(linefmt, ++lineno); | 54 | htmlf(linefmt, ++lineno); |
55 | html_txt(buf + start); | 55 | html_txt(buf + start); |
56 | html("</td></tr>\n"); | 56 | html("</td></tr>\n"); |
57 | html("</table>\n"); | 57 | html("</table>\n"); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 61 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
62 | const char *pathname, unsigned int mode, int stage) | 62 | const char *pathname, unsigned int mode, int stage) |
63 | { | 63 | { |
64 | char *name; | 64 | char *name; |
65 | char *fullpath; | 65 | char *fullpath; |
66 | enum object_type type; | 66 | enum object_type type; |
67 | unsigned long size = 0; | 67 | unsigned long size = 0; |
68 | 68 | ||
69 | name = xstrdup(pathname); | 69 | name = xstrdup(pathname); |
70 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", | 70 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |
71 | cgit_query_path ? "/" : "", name); | 71 | cgit_query_path ? "/" : "", name); |
72 | 72 | ||
73 | type = sha1_object_info(sha1, &size); | 73 | type = sha1_object_info(sha1, &size); |
74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { | 74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
76 | name, | 76 | name, |
77 | sha1_to_hex(sha1)); | 77 | sha1_to_hex(sha1)); |
78 | return 0; | 78 | return 0; |
79 | } | 79 | } |
80 | 80 | ||
81 | html("<tr><td class='ls-mode'>"); | 81 | html("<tr><td class='ls-mode'>"); |
82 | html_filemode(mode); | 82 | html_filemode(mode); |
83 | html("</td><td>"); | 83 | html("</td><td>"); |
84 | if (S_ISGITLINK(mode)) { | 84 | if (S_ISGITLINK(mode)) { |
85 | htmlf("<a class='ls-mod' href='"); | 85 | htmlf("<a class='ls-mod' href='"); |
86 | html_attr(fmt(cgit_repo->module_link, | 86 | html_attr(fmt(cgit_repo->module_link, |
87 | name, | 87 | name, |
88 | sha1_to_hex(sha1))); | 88 | sha1_to_hex(sha1))); |
89 | html("'>"); | 89 | html("'>"); |
90 | html_txt(name); | 90 | html_txt(name); |
91 | html("</a>"); | 91 | html("</a>"); |
92 | } else if (S_ISDIR(mode)) { | 92 | } else if (S_ISDIR(mode)) { |
93 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, | 93 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, |
94 | curr_rev, fullpath); | 94 | curr_rev, fullpath); |
95 | } else { | 95 | } else { |
96 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, | 96 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, |
97 | curr_rev, fullpath); | 97 | curr_rev, fullpath); |
98 | } | 98 | } |
99 | htmlf("</td><td class='ls-size'>%li</td>", size); | 99 | htmlf("</td><td class='ls-size'>%li</td>", size); |
100 | 100 | ||
101 | html("<td>"); | 101 | html("<td>"); |
102 | cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, | 102 | cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, |
103 | fullpath, 0, NULL, NULL); | 103 | fullpath, 0, NULL, NULL); |
104 | html("</td></tr>\n"); | 104 | html("</td></tr>\n"); |
105 | free(name); | 105 | free(name); |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | static void ls_head() | 109 | static void ls_head() |
110 | { | 110 | { |
111 | html("<table class='list'>\n"); | 111 | html("<table summary='tree listing' class='list'>\n"); |
112 | html("<tr class='nohover'>"); | 112 | html("<tr class='nohover'>"); |
113 | html("<th class='left'>Mode</th>"); | 113 | html("<th class='left'>Mode</th>"); |
114 | html("<th class='left'>Name</th>"); | 114 | html("<th class='left'>Name</th>"); |
115 | html("<th class='right'>Size</th>"); | 115 | html("<th class='right'>Size</th>"); |
116 | html("<th/>"); | 116 | html("<th/>"); |
117 | html("</tr>\n"); | 117 | html("</tr>\n"); |
118 | header = 1; | 118 | header = 1; |
119 | } | 119 | } |
120 | 120 | ||
121 | static void ls_tail() | 121 | static void ls_tail() |
122 | { | 122 | { |
123 | if (!header) | 123 | if (!header) |
124 | return; | 124 | return; |
125 | html("</table>\n"); | 125 | html("</table>\n"); |
126 | header = 0; | 126 | header = 0; |
127 | } | 127 | } |
128 | 128 | ||
129 | static void ls_tree(const unsigned char *sha1, char *path) | 129 | static void ls_tree(const unsigned char *sha1, char *path) |
130 | { | 130 | { |
131 | struct tree *tree; | 131 | struct tree *tree; |
132 | 132 | ||
133 | tree = parse_tree_indirect(sha1); | 133 | tree = parse_tree_indirect(sha1); |
134 | if (!tree) { | 134 | if (!tree) { |
135 | cgit_print_error(fmt("Not a tree object: %s", | 135 | cgit_print_error(fmt("Not a tree object: %s", |
136 | sha1_to_hex(sha1))); | 136 | sha1_to_hex(sha1))); |
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | 139 | ||
140 | ls_head(); | 140 | ls_head(); |
141 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); | 141 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
142 | ls_tail(); | 142 | ls_tail(); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 146 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
147 | const char *pathname, unsigned mode, int stage) | 147 | const char *pathname, unsigned mode, int stage) |
148 | { | 148 | { |
149 | static int state; | 149 | static int state; |
150 | static char buffer[PATH_MAX]; | 150 | static char buffer[PATH_MAX]; |
151 | char *url; | 151 | char *url; |
152 | 152 | ||
153 | if (state == 0) { | 153 | if (state == 0) { |
154 | memcpy(buffer, base, baselen); | 154 | memcpy(buffer, base, baselen); |
155 | strcpy(buffer+baselen, pathname); | 155 | strcpy(buffer+baselen, pathname); |
156 | url = cgit_pageurl(cgit_query_repo, "tree", | 156 | url = cgit_pageurl(cgit_query_repo, "tree", |
157 | fmt("h=%s&path=%s", curr_rev, buffer)); | 157 | fmt("h=%s&path=%s", curr_rev, buffer)); |
158 | html("/"); | 158 | html("/"); |
159 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, | 159 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, |
160 | curr_rev, buffer); | 160 | curr_rev, buffer); |
161 | 161 | ||
162 | if (strcmp(match_path, buffer)) | 162 | if (strcmp(match_path, buffer)) |
163 | return READ_TREE_RECURSIVE; | 163 | return READ_TREE_RECURSIVE; |
164 | 164 | ||
165 | if (S_ISDIR(mode)) { | 165 | if (S_ISDIR(mode)) { |
166 | state = 1; | 166 | state = 1; |
167 | ls_head(); | 167 | ls_head(); |
168 | return READ_TREE_RECURSIVE; | 168 | return READ_TREE_RECURSIVE; |
169 | } else { | 169 | } else { |
170 | print_object(sha1, buffer); | 170 | print_object(sha1, buffer); |
171 | return 0; | 171 | return 0; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | ls_item(sha1, base, baselen, pathname, mode, stage); | 174 | ls_item(sha1, base, baselen, pathname, mode, stage); |
175 | return 0; | 175 | return 0; |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | /* | 179 | /* |
180 | * Show a tree or a blob | 180 | * Show a tree or a blob |
181 | * rev: the commit pointing at the root tree object | 181 | * rev: the commit pointing at the root tree object |
182 | * path: path to tree or blob | 182 | * path: path to tree or blob |
183 | */ | 183 | */ |
184 | void cgit_print_tree(const char *rev, char *path) | 184 | void cgit_print_tree(const char *rev, char *path) |
185 | { | 185 | { |
186 | unsigned char sha1[20]; | 186 | unsigned char sha1[20]; |
187 | struct commit *commit; | 187 | struct commit *commit; |
188 | const char *paths[] = {path, NULL}; | 188 | const char *paths[] = {path, NULL}; |
189 | 189 | ||
190 | if (!rev) | 190 | if (!rev) |
191 | rev = cgit_query_head; | 191 | rev = cgit_query_head; |
192 | 192 | ||
193 | curr_rev = xstrdup(rev); | 193 | curr_rev = xstrdup(rev); |
194 | if (get_sha1(rev, sha1)) { | 194 | if (get_sha1(rev, sha1)) { |
195 | cgit_print_error(fmt("Invalid revision name: %s", rev)); | 195 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | commit = lookup_commit_reference(sha1); | 198 | commit = lookup_commit_reference(sha1); |
199 | if (!commit || parse_commit(commit)) { | 199 | if (!commit || parse_commit(commit)) { |
200 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); | 200 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | 203 | ||
204 | html("path: <a href='"); | 204 | html("path: <a href='"); |
205 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); | 205 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); |
206 | html("'>root</a>"); | 206 | html("'>root</a>"); |
207 | 207 | ||