author | Lars Hjemli <hjemli@gmail.com> | 2007-06-16 18:20:42 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-16 18:20:42 (UTC) |
commit | ffc69736a606fd8f9a10468cce48b9a37b428944 (patch) (unidiff) | |
tree | b080c702391244a525fa0e7c97758f7f7fa0c383 | |
parent | 849f0f0f02f858e21fbe59295846e51628f82915 (diff) | |
download | cgit-ffc69736a606fd8f9a10468cce48b9a37b428944.zip cgit-ffc69736a606fd8f9a10468cce48b9a37b428944.tar.gz cgit-ffc69736a606fd8f9a10468cce48b9a37b428944.tar.bz2 |
ui-tree: unify with ui-view, use path to select tree/blob
This teaches ui-tree to show both trees and blobs, thereby making ui-view
superfluous. At the same time, ui-tree is extended to honour the specified
path instead of requiering a tree/blob sha1.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.css | 16 | ||||
-rw-r--r-- | cgit.h | 8 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-tree.c | 194 | ||||
-rw-r--r-- | ui-view.c | 55 |
8 files changed, 174 insertions, 112 deletions
@@ -1,87 +1,87 @@ | |||
1 | CGIT_VERSION = 0.5 | 1 | CGIT_VERSION = 0.5 |
2 | 2 | ||
3 | prefix = /var/www/htdocs/cgit | 3 | prefix = /var/www/htdocs/cgit |
4 | 4 | ||
5 | SHA1_HEADER = <openssl/sha.h> | 5 | SHA1_HEADER = <openssl/sha.h> |
6 | CACHE_ROOT = /var/cache/cgit | 6 | CACHE_ROOT = /var/cache/cgit |
7 | CGIT_CONFIG = /etc/cgitrc | 7 | CGIT_CONFIG = /etc/cgitrc |
8 | CGIT_SCRIPT_NAME = cgit.cgi | 8 | CGIT_SCRIPT_NAME = cgit.cgi |
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 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 15 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
16 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 16 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
17 | ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ | 17 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
18 | ui-snapshot.o ui-blob.o | 18 | ui-snapshot.o ui-blob.o |
19 | 19 | ||
20 | CFLAGS += -Wall | 20 | CFLAGS += -Wall |
21 | 21 | ||
22 | ifdef DEBUG | 22 | ifdef DEBUG |
23 | CFLAGS += -g | 23 | CFLAGS += -g |
24 | endif | 24 | endif |
25 | 25 | ||
26 | CFLAGS += -Igit | 26 | CFLAGS += -Igit |
27 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 27 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
28 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 28 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
29 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 29 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
30 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 30 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
31 | 31 | ||
32 | 32 | ||
33 | # | 33 | # |
34 | # If make is run on a nongit platform, get the git sources as a tarball. | 34 | # If make is run on a nongit platform, get the git sources as a tarball. |
35 | # | 35 | # |
36 | GITVER = $(shell git version 2>/dev/null || echo nogit) | 36 | GITVER = $(shell git version 2>/dev/null || echo nogit) |
37 | ifeq ($(GITVER),nogit) | 37 | ifeq ($(GITVER),nogit) |
38 | GITURL = http://www.kernel.org/pub/software/scm/git/git-1.5.2.tar.bz2 | 38 | GITURL = http://www.kernel.org/pub/software/scm/git/git-1.5.2.tar.bz2 |
39 | INITGIT = test -e git/git.c || ((curl "$(GITURL)" | tar -xj) && mv git-1.5.2 git) | 39 | INITGIT = test -e git/git.c || ((curl "$(GITURL)" | tar -xj) && mv git-1.5.2 git) |
40 | else | 40 | else |
41 | INITGIT = ./submodules.sh -i | 41 | INITGIT = ./submodules.sh -i |
42 | endif | 42 | endif |
43 | 43 | ||
44 | 44 | ||
45 | # | 45 | # |
46 | # basic build rules | 46 | # basic build rules |
47 | # | 47 | # |
48 | all: cgit | 48 | all: cgit |
49 | 49 | ||
50 | cgit: cgit.c cgit.h $(OBJECTS) | 50 | cgit: cgit.c cgit.h $(OBJECTS) |
51 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 51 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
52 | 52 | ||
53 | $(OBJECTS): cgit.h git/libgit.a | 53 | $(OBJECTS): cgit.h git/libgit.a |
54 | 54 | ||
55 | git/libgit.a: | 55 | git/libgit.a: |
56 | $(INITGIT) | 56 | $(INITGIT) |
57 | $(MAKE) -C git | 57 | $(MAKE) -C git |
58 | 58 | ||
59 | # | 59 | # |
60 | # phony targets | 60 | # phony targets |
61 | # | 61 | # |
62 | install: all clean-cache | 62 | install: all clean-cache |
63 | mkdir -p $(prefix) | 63 | mkdir -p $(prefix) |
64 | install cgit $(prefix)/$(CGIT_SCRIPT_NAME) | 64 | install cgit $(prefix)/$(CGIT_SCRIPT_NAME) |
65 | install cgit.css $(prefix)/cgit.css | 65 | install cgit.css $(prefix)/cgit.css |
66 | 66 | ||
67 | clean-cgit: | 67 | clean-cgit: |
68 | rm -f cgit *.o | 68 | rm -f cgit *.o |
69 | 69 | ||
70 | distclean-cgit: clean-cgit | 70 | distclean-cgit: clean-cgit |
71 | git clean -d -x | 71 | git clean -d -x |
72 | 72 | ||
73 | clean-sub: | 73 | clean-sub: |
74 | $(MAKE) -C git clean | 74 | $(MAKE) -C git clean |
75 | 75 | ||
76 | distclean-sub: clean-sub | 76 | distclean-sub: clean-sub |
77 | $(shell cd git && git clean -d -x) | 77 | $(shell cd git && git clean -d -x) |
78 | 78 | ||
79 | clean-cache: | 79 | clean-cache: |
80 | rm -rf $(CACHE_ROOT)/* | 80 | rm -rf $(CACHE_ROOT)/* |
81 | 81 | ||
82 | clean: clean-cgit clean-sub | 82 | clean: clean-cgit clean-sub |
83 | 83 | ||
84 | distclean: distclean-cgit distclean-sub | 84 | distclean: distclean-cgit distclean-sub |
85 | 85 | ||
86 | .PHONY: all install clean clean-cgit clean-sub clean-cache \ | 86 | .PHONY: all install clean clean-cgit clean-sub clean-cache \ |
87 | distclean distclean-cgit distclean-sub | 87 | distclean distclean-cgit distclean-sub |
@@ -4,200 +4,197 @@ | |||
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | 13 | ||
14 | static int cgit_prepare_cache(struct cacheitem *item) | 14 | static int cgit_prepare_cache(struct cacheitem *item) |
15 | { | 15 | { |
16 | if (!cgit_repo && cgit_query_repo) { | 16 | if (!cgit_repo && cgit_query_repo) { |
17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
18 | cgit_print_docstart(title, item); | 18 | cgit_print_docstart(title, item); |
19 | cgit_print_pageheader(title, 0); | 19 | cgit_print_pageheader(title, 0); |
20 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 20 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
21 | cgit_print_docend(); | 21 | cgit_print_docend(); |
22 | return 0; | 22 | return 0; |
23 | } | 23 | } |
24 | 24 | ||
25 | if (!cgit_repo) { | 25 | if (!cgit_repo) { |
26 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 26 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
27 | item->ttl = cgit_cache_root_ttl; | 27 | item->ttl = cgit_cache_root_ttl; |
28 | return 1; | 28 | return 1; |
29 | } | 29 | } |
30 | 30 | ||
31 | if (!cgit_cmd) { | 31 | if (!cgit_cmd) { |
32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
33 | cache_safe_filename(cgit_repo->url))); | 33 | cache_safe_filename(cgit_repo->url))); |
34 | item->ttl = cgit_cache_repo_ttl; | 34 | item->ttl = cgit_cache_repo_ttl; |
35 | } else { | 35 | } else { |
36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
37 | cache_safe_filename(cgit_repo->url), cgit_query_page, | 37 | cache_safe_filename(cgit_repo->url), cgit_query_page, |
38 | cache_safe_filename(cgit_querystring))); | 38 | cache_safe_filename(cgit_querystring))); |
39 | if (cgit_query_has_symref) | 39 | if (cgit_query_has_symref) |
40 | item->ttl = cgit_cache_dynamic_ttl; | 40 | item->ttl = cgit_cache_dynamic_ttl; |
41 | else if (cgit_query_has_sha1) | 41 | else if (cgit_query_has_sha1) |
42 | item->ttl = cgit_cache_static_ttl; | 42 | item->ttl = cgit_cache_static_ttl; |
43 | else | 43 | else |
44 | item->ttl = cgit_cache_repo_ttl; | 44 | item->ttl = cgit_cache_repo_ttl; |
45 | } | 45 | } |
46 | return 1; | 46 | return 1; |
47 | } | 47 | } |
48 | 48 | ||
49 | static void cgit_print_repo_page(struct cacheitem *item) | 49 | static void cgit_print_repo_page(struct cacheitem *item) |
50 | { | 50 | { |
51 | char *title; | 51 | char *title; |
52 | int show_search; | 52 | int show_search; |
53 | 53 | ||
54 | if (!cgit_query_head) | 54 | if (!cgit_query_head) |
55 | cgit_query_head = cgit_repo->defbranch; | 55 | cgit_query_head = cgit_repo->defbranch; |
56 | 56 | ||
57 | if (chdir(cgit_repo->path)) { | 57 | if (chdir(cgit_repo->path)) { |
58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
59 | cgit_print_docstart(title, item); | 59 | cgit_print_docstart(title, item); |
60 | cgit_print_pageheader(title, 0); | 60 | cgit_print_pageheader(title, 0); |
61 | cgit_print_error(fmt("Unable to scan repository: %s", | 61 | cgit_print_error(fmt("Unable to scan repository: %s", |
62 | strerror(errno))); | 62 | strerror(errno))); |
63 | cgit_print_docend(); | 63 | cgit_print_docend(); |
64 | return; | 64 | return; |
65 | } | 65 | } |
66 | 66 | ||
67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
68 | show_search = 0; | 68 | show_search = 0; |
69 | setenv("GIT_DIR", cgit_repo->path, 1); | 69 | setenv("GIT_DIR", cgit_repo->path, 1); |
70 | 70 | ||
71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
73 | cgit_repo->url, cgit_query_name); | 73 | cgit_repo->url, cgit_query_name); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | 76 | ||
77 | if (cgit_cmd == CMD_BLOB) { | 77 | if (cgit_cmd == CMD_BLOB) { |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | 81 | ||
82 | show_search = (cgit_cmd == CMD_LOG); | 82 | show_search = (cgit_cmd == CMD_LOG); |
83 | cgit_print_docstart(title, item); | 83 | cgit_print_docstart(title, item); |
84 | if (!cgit_cmd) { | 84 | if (!cgit_cmd) { |
85 | cgit_print_pageheader("summary", show_search); | 85 | cgit_print_pageheader("summary", show_search); |
86 | cgit_print_summary(); | 86 | cgit_print_summary(); |
87 | cgit_print_docend(); | 87 | cgit_print_docend(); |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | 90 | ||
91 | cgit_print_pageheader(cgit_query_page, show_search); | 91 | cgit_print_pageheader(cgit_query_page, show_search); |
92 | 92 | ||
93 | switch(cgit_cmd) { | 93 | switch(cgit_cmd) { |
94 | case CMD_LOG: | 94 | case CMD_LOG: |
95 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 95 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
96 | cgit_max_commit_count, cgit_query_search, | 96 | cgit_max_commit_count, cgit_query_search, |
97 | cgit_query_path, 1); | 97 | cgit_query_path, 1); |
98 | break; | 98 | break; |
99 | case CMD_TREE: | 99 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
101 | break; | 101 | break; |
102 | case CMD_COMMIT: | 102 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_head); | 103 | cgit_print_commit(cgit_query_head); |
104 | break; | 104 | break; |
105 | case CMD_VIEW: | ||
106 | cgit_print_view(cgit_query_sha1, cgit_query_path); | ||
107 | break; | ||
108 | case CMD_DIFF: | 105 | case CMD_DIFF: |
109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
110 | cgit_query_path); | 107 | cgit_query_path); |
111 | break; | 108 | break; |
112 | default: | 109 | default: |
113 | cgit_print_error("Invalid request"); | 110 | cgit_print_error("Invalid request"); |
114 | } | 111 | } |
115 | cgit_print_docend(); | 112 | cgit_print_docend(); |
116 | } | 113 | } |
117 | 114 | ||
118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
119 | { | 116 | { |
120 | static char buf[PATH_MAX]; | 117 | static char buf[PATH_MAX]; |
121 | int stdout2; | 118 | int stdout2; |
122 | 119 | ||
123 | getcwd(buf, sizeof(buf)); | 120 | getcwd(buf, sizeof(buf)); |
124 | item->st.st_mtime = time(NULL); | 121 | item->st.st_mtime = time(NULL); |
125 | 122 | ||
126 | if (use_cache) { | 123 | if (use_cache) { |
127 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 124 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
128 | "Preserving STDOUT"); | 125 | "Preserving STDOUT"); |
129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 126 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 127 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
131 | } | 128 | } |
132 | 129 | ||
133 | if (cgit_repo) | 130 | if (cgit_repo) |
134 | cgit_print_repo_page(item); | 131 | cgit_print_repo_page(item); |
135 | else | 132 | else |
136 | cgit_print_repolist(item); | 133 | cgit_print_repolist(item); |
137 | 134 | ||
138 | if (use_cache) { | 135 | if (use_cache) { |
139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 136 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
140 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 137 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
141 | "Restoring original STDOUT"); | 138 | "Restoring original STDOUT"); |
142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 139 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
143 | } | 140 | } |
144 | 141 | ||
145 | chdir(buf); | 142 | chdir(buf); |
146 | } | 143 | } |
147 | 144 | ||
148 | static void cgit_check_cache(struct cacheitem *item) | 145 | static void cgit_check_cache(struct cacheitem *item) |
149 | { | 146 | { |
150 | int i = 0; | 147 | int i = 0; |
151 | 148 | ||
152 | top: | 149 | top: |
153 | if (++i > cgit_max_lock_attempts) { | 150 | if (++i > cgit_max_lock_attempts) { |
154 | die("cgit_refresh_cache: unable to lock %s: %s", | 151 | die("cgit_refresh_cache: unable to lock %s: %s", |
155 | item->name, strerror(errno)); | 152 | item->name, strerror(errno)); |
156 | } | 153 | } |
157 | if (!cache_exist(item)) { | 154 | if (!cache_exist(item)) { |
158 | if (!cache_lock(item)) { | 155 | if (!cache_lock(item)) { |
159 | sleep(1); | 156 | sleep(1); |
160 | goto top; | 157 | goto top; |
161 | } | 158 | } |
162 | if (!cache_exist(item)) { | 159 | if (!cache_exist(item)) { |
163 | cgit_fill_cache(item, 1); | 160 | cgit_fill_cache(item, 1); |
164 | cache_unlock(item); | 161 | cache_unlock(item); |
165 | } else { | 162 | } else { |
166 | cache_cancel_lock(item); | 163 | cache_cancel_lock(item); |
167 | } | 164 | } |
168 | } else if (cache_expired(item) && cache_lock(item)) { | 165 | } else if (cache_expired(item) && cache_lock(item)) { |
169 | if (cache_expired(item)) { | 166 | if (cache_expired(item)) { |
170 | cgit_fill_cache(item, 1); | 167 | cgit_fill_cache(item, 1); |
171 | cache_unlock(item); | 168 | cache_unlock(item); |
172 | } else { | 169 | } else { |
173 | cache_cancel_lock(item); | 170 | cache_cancel_lock(item); |
174 | } | 171 | } |
175 | } | 172 | } |
176 | } | 173 | } |
177 | 174 | ||
178 | static void cgit_print_cache(struct cacheitem *item) | 175 | static void cgit_print_cache(struct cacheitem *item) |
179 | { | 176 | { |
180 | static char buf[4096]; | 177 | static char buf[4096]; |
181 | ssize_t i; | 178 | ssize_t i; |
182 | 179 | ||
183 | int fd = open(item->name, O_RDONLY); | 180 | int fd = open(item->name, O_RDONLY); |
184 | if (fd<0) | 181 | if (fd<0) |
185 | die("Unable to open cached file %s", item->name); | 182 | die("Unable to open cached file %s", item->name); |
186 | 183 | ||
187 | while((i=read(fd, buf, sizeof(buf))) > 0) | 184 | while((i=read(fd, buf, sizeof(buf))) > 0) |
188 | write(STDOUT_FILENO, buf, i); | 185 | write(STDOUT_FILENO, buf, i); |
189 | 186 | ||
190 | close(fd); | 187 | close(fd); |
191 | } | 188 | } |
192 | 189 | ||
193 | static void cgit_parse_args(int argc, const char **argv) | 190 | static void cgit_parse_args(int argc, const char **argv) |
194 | { | 191 | { |
195 | int i; | 192 | int i; |
196 | 193 | ||
197 | for (i = 1; i < argc; i++) { | 194 | for (i = 1; i < argc; i++) { |
198 | if (!strncmp(argv[i], "--cache=", 8)) { | 195 | if (!strncmp(argv[i], "--cache=", 8)) { |
199 | cgit_cache_root = xstrdup(argv[i]+8); | 196 | cgit_cache_root = xstrdup(argv[i]+8); |
200 | } | 197 | } |
201 | if (!strcmp(argv[i], "--nocache")) { | 198 | if (!strcmp(argv[i], "--nocache")) { |
202 | cgit_nocache = 1; | 199 | cgit_nocache = 1; |
203 | } | 200 | } |
@@ -106,196 +106,208 @@ td#crumb, td#search { | |||
106 | border-top: solid 3px #555; | 106 | border-top: solid 3px #555; |
107 | background-color: #666; | 107 | background-color: #666; |
108 | border-bottom: solid 1px #333; | 108 | border-bottom: solid 1px #333; |
109 | padding: 2px 1em; | 109 | padding: 2px 1em; |
110 | } | 110 | } |
111 | 111 | ||
112 | td#crumb { | 112 | td#crumb { |
113 | font-weight: bold; | 113 | font-weight: bold; |
114 | } | 114 | } |
115 | 115 | ||
116 | td#crumb a { | 116 | td#crumb a { |
117 | color: #ccc; | 117 | color: #ccc; |
118 | background-color: #666; | 118 | background-color: #666; |
119 | } | 119 | } |
120 | 120 | ||
121 | td#crumb a:hover { | 121 | td#crumb a:hover { |
122 | color: #eee; | 122 | color: #eee; |
123 | background-color: #666; | 123 | background-color: #666; |
124 | } | 124 | } |
125 | 125 | ||
126 | td#search { | 126 | td#search { |
127 | text-align: right; | 127 | text-align: right; |
128 | vertical-align: middle; | 128 | vertical-align: middle; |
129 | padding-right: 0.5em; | 129 | padding-right: 0.5em; |
130 | } | 130 | } |
131 | 131 | ||
132 | td#search form { | 132 | td#search form { |
133 | margin: 0px; | 133 | margin: 0px; |
134 | padding: 0px; | 134 | padding: 0px; |
135 | } | 135 | } |
136 | 136 | ||
137 | td#search input { | 137 | td#search input { |
138 | font-size: 9pt; | 138 | font-size: 9pt; |
139 | padding: 0px; | 139 | padding: 0px; |
140 | width: 10em; | 140 | width: 10em; |
141 | border: solid 1px #333; | 141 | border: solid 1px #333; |
142 | color: #333; | 142 | color: #333; |
143 | background-color: #fff; | 143 | background-color: #fff; |
144 | } | 144 | } |
145 | 145 | ||
146 | div#summary { | 146 | div#summary { |
147 | vertical-align: top; | 147 | vertical-align: top; |
148 | margin-bottom: 1em; | 148 | margin-bottom: 1em; |
149 | } | 149 | } |
150 | 150 | ||
151 | table#downloads { | 151 | table#downloads { |
152 | float: right; | 152 | float: right; |
153 | border-collapse: collapse; | 153 | border-collapse: collapse; |
154 | border: solid 1px #777; | 154 | border: solid 1px #777; |
155 | margin-left: 0.5em; | 155 | margin-left: 0.5em; |
156 | margin-bottom: 0.5em; | 156 | margin-bottom: 0.5em; |
157 | } | 157 | } |
158 | 158 | ||
159 | table#downloads th { | 159 | table#downloads th { |
160 | background-color: #ccc; | 160 | background-color: #ccc; |
161 | } | 161 | } |
162 | 162 | ||
163 | td#content { | 163 | td#content { |
164 | padding: 1em 0.5em; | 164 | padding: 1em 0.5em; |
165 | } | 165 | } |
166 | 166 | ||
167 | div#blob { | 167 | div#blob { |
168 | border: solid 1px black; | 168 | border: solid 1px black; |
169 | } | 169 | } |
170 | 170 | ||
171 | div.error { | 171 | div.error { |
172 | color: red; | 172 | color: red; |
173 | font-weight: bold; | 173 | font-weight: bold; |
174 | margin: 1em 2em; | 174 | margin: 1em 2em; |
175 | } | 175 | } |
176 | 176 | ||
177 | td.ls-blob, td.ls-dir, td.ls-mod { | 177 | td.ls-blob, td.ls-dir, td.ls-mod { |
178 | font-family: monospace; | 178 | font-family: monospace; |
179 | } | 179 | } |
180 | 180 | ||
181 | div.ls-dir a { | 181 | div.ls-dir a { |
182 | font-weight: bold; | 182 | font-weight: bold; |
183 | } | 183 | } |
184 | 184 | ||
185 | th.filesize, td.filesize { | 185 | th.filesize, td.filesize { |
186 | text-align: right; | 186 | text-align: right; |
187 | } | 187 | } |
188 | 188 | ||
189 | td.filesize { | 189 | td.filesize { |
190 | font-family: monospace; | 190 | font-family: monospace; |
191 | } | 191 | } |
192 | 192 | ||
193 | td.links { | 193 | td.links { |
194 | font-size: 80%; | 194 | font-size: 80%; |
195 | padding-left: 2em; | 195 | padding-left: 2em; |
196 | } | 196 | } |
197 | 197 | ||
198 | td.filemode { | 198 | td.filemode { |
199 | font-family: monospace; | 199 | font-family: monospace; |
200 | } | 200 | } |
201 | 201 | ||
202 | td.blob { | 202 | table.blob { |
203 | margin-top: 0.5em; | ||
204 | border-top: solid 1px black; | ||
205 | } | ||
206 | |||
207 | table.blob td.no { | ||
208 | border-right: solid 1px black; | ||
209 | color: black; | ||
210 | background-color: #eee; | ||
211 | text-align: right; | ||
212 | } | ||
213 | |||
214 | table.blob td.txt { | ||
203 | white-space: pre; | 215 | white-space: pre; |
204 | font-family: monospace; | 216 | font-family: monospace; |
205 | background-color: white; | 217 | padding-left: 0.5em; |
206 | } | 218 | } |
207 | 219 | ||
208 | table.nowrap td { | 220 | table.nowrap td { |
209 | white-space: nowrap; | 221 | white-space: nowrap; |
210 | } | 222 | } |
211 | 223 | ||
212 | table.commit-info { | 224 | table.commit-info { |
213 | border-collapse: collapse; | 225 | border-collapse: collapse; |
214 | margin-top: 1.5em; | 226 | margin-top: 1.5em; |
215 | } | 227 | } |
216 | 228 | ||
217 | table.commit-info th { | 229 | table.commit-info th { |
218 | text-align: left; | 230 | text-align: left; |
219 | font-weight: normal; | 231 | font-weight: normal; |
220 | padding: 0.1em 1em 0.1em 0.1em; | 232 | padding: 0.1em 1em 0.1em 0.1em; |
221 | } | 233 | } |
222 | 234 | ||
223 | table.commit-info td { | 235 | table.commit-info td { |
224 | font-weight: normal; | 236 | font-weight: normal; |
225 | padding: 0.1em 1em 0.1em 0.1em; | 237 | padding: 0.1em 1em 0.1em 0.1em; |
226 | } | 238 | } |
227 | 239 | ||
228 | div.commit-subject { | 240 | div.commit-subject { |
229 | font-weight: bold; | 241 | font-weight: bold; |
230 | font-size: 125%; | 242 | font-size: 125%; |
231 | margin: 1.5em 0em 0.5em 0em; | 243 | margin: 1.5em 0em 0.5em 0em; |
232 | padding: 0em; | 244 | padding: 0em; |
233 | } | 245 | } |
234 | 246 | ||
235 | div.commit-msg { | 247 | div.commit-msg { |
236 | white-space: pre; | 248 | white-space: pre; |
237 | font-family: monospace; | 249 | font-family: monospace; |
238 | } | 250 | } |
239 | 251 | ||
240 | div.diffstat-header { | 252 | div.diffstat-header { |
241 | font-weight: bold; | 253 | font-weight: bold; |
242 | padding-top: 1.5em; | 254 | padding-top: 1.5em; |
243 | } | 255 | } |
244 | 256 | ||
245 | table.diffstat { | 257 | table.diffstat { |
246 | border-collapse: collapse; | 258 | border-collapse: collapse; |
247 | width: 100%; | 259 | width: 100%; |
248 | border: solid 1px #aaa; | 260 | border: solid 1px #aaa; |
249 | background-color: #eee; | 261 | background-color: #eee; |
250 | } | 262 | } |
251 | 263 | ||
252 | table.diffstat tr:hover { | 264 | table.diffstat tr:hover { |
253 | background-color: #ccc; | 265 | background-color: #ccc; |
254 | } | 266 | } |
255 | 267 | ||
256 | table.diffstat th { | 268 | table.diffstat th { |
257 | font-weight: normal; | 269 | font-weight: normal; |
258 | text-align: left; | 270 | text-align: left; |
259 | text-decoration: underline; | 271 | text-decoration: underline; |
260 | padding: 0.1em 1em 0.1em 0.1em; | 272 | padding: 0.1em 1em 0.1em 0.1em; |
261 | font-size: 100%; | 273 | font-size: 100%; |
262 | } | 274 | } |
263 | 275 | ||
264 | table.diffstat td { | 276 | table.diffstat td { |
265 | padding: 0.2em 0.2em 0.1em 0.1em; | 277 | padding: 0.2em 0.2em 0.1em 0.1em; |
266 | font-size: 100%; | 278 | font-size: 100%; |
267 | border: none; | 279 | border: none; |
268 | } | 280 | } |
269 | 281 | ||
270 | table.diffstat td.mode { | 282 | table.diffstat td.mode { |
271 | white-space: nowrap; | 283 | white-space: nowrap; |
272 | } | 284 | } |
273 | 285 | ||
274 | table.diffstat td span.modechange { | 286 | table.diffstat td span.modechange { |
275 | padding-left: 1em; | 287 | padding-left: 1em; |
276 | color: red; | 288 | color: red; |
277 | } | 289 | } |
278 | 290 | ||
279 | table.diffstat td.add a { | 291 | table.diffstat td.add a { |
280 | color: green; | 292 | color: green; |
281 | } | 293 | } |
282 | 294 | ||
283 | table.diffstat td.del a { | 295 | table.diffstat td.del a { |
284 | color: red; | 296 | color: red; |
285 | } | 297 | } |
286 | 298 | ||
287 | table.diffstat td.upd a { | 299 | table.diffstat td.upd a { |
288 | color: blue; | 300 | color: blue; |
289 | } | 301 | } |
290 | 302 | ||
291 | table.diffstat td.graph { | 303 | table.diffstat td.graph { |
292 | width: 75%; | 304 | width: 75%; |
293 | vertical-align: middle; | 305 | vertical-align: middle; |
294 | } | 306 | } |
295 | 307 | ||
296 | table.diffstat td.graph table { | 308 | table.diffstat td.graph table { |
297 | border: none; | 309 | border: none; |
298 | } | 310 | } |
299 | 311 | ||
300 | table.diffstat td.graph td { | 312 | table.diffstat td.graph td { |
301 | padding: 0px; | 313 | padding: 0px; |
@@ -1,228 +1,226 @@ | |||
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 | 19 | ||
20 | 20 | ||
21 | /* | 21 | /* |
22 | * The valid cgit repo-commands | 22 | * The valid cgit repo-commands |
23 | */ | 23 | */ |
24 | #define CMD_LOG 1 | 24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_VIEW 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_BLOB 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | #define CMD_SNAPSHOT 7 | ||
31 | 30 | ||
32 | 31 | ||
33 | /* | 32 | /* |
34 | * Dateformats used on misc. pages | 33 | * Dateformats used on misc. pages |
35 | */ | 34 | */ |
36 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
37 | #define FMT_SHORTDATE "%Y-%m-%d" | 36 | #define FMT_SHORTDATE "%Y-%m-%d" |
38 | 37 | ||
39 | 38 | ||
40 | /* | 39 | /* |
41 | * Limits used for relative dates | 40 | * Limits used for relative dates |
42 | */ | 41 | */ |
43 | #define TM_MIN 60 | 42 | #define TM_MIN 60 |
44 | #define TM_HOUR (TM_MIN * 60) | 43 | #define TM_HOUR (TM_MIN * 60) |
45 | #define TM_DAY (TM_HOUR * 24) | 44 | #define TM_DAY (TM_HOUR * 24) |
46 | #define TM_WEEK (TM_DAY * 7) | 45 | #define TM_WEEK (TM_DAY * 7) |
47 | #define TM_YEAR (TM_DAY * 365) | 46 | #define TM_YEAR (TM_DAY * 365) |
48 | #define TM_MONTH (TM_YEAR / 12.0) | 47 | #define TM_MONTH (TM_YEAR / 12.0) |
49 | 48 | ||
50 | 49 | ||
51 | typedef void (*configfn)(const char *name, const char *value); | 50 | typedef void (*configfn)(const char *name, const char *value); |
52 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 51 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
53 | typedef void (*linediff_fn)(char *line, int len); | 52 | typedef void (*linediff_fn)(char *line, int len); |
54 | 53 | ||
55 | struct cacheitem { | 54 | struct cacheitem { |
56 | char *name; | 55 | char *name; |
57 | struct stat st; | 56 | struct stat st; |
58 | int ttl; | 57 | int ttl; |
59 | int fd; | 58 | int fd; |
60 | }; | 59 | }; |
61 | 60 | ||
62 | struct repoinfo { | 61 | struct repoinfo { |
63 | char *url; | 62 | char *url; |
64 | char *name; | 63 | char *name; |
65 | char *path; | 64 | char *path; |
66 | char *desc; | 65 | char *desc; |
67 | char *owner; | 66 | char *owner; |
68 | char *defbranch; | 67 | char *defbranch; |
69 | char *group; | 68 | char *group; |
70 | char *module_link; | 69 | char *module_link; |
71 | char *readme; | 70 | char *readme; |
72 | int snapshots; | 71 | int snapshots; |
73 | int enable_log_filecount; | 72 | int enable_log_filecount; |
74 | int enable_log_linecount; | 73 | int enable_log_linecount; |
75 | }; | 74 | }; |
76 | 75 | ||
77 | struct repolist { | 76 | struct repolist { |
78 | int length; | 77 | int length; |
79 | int count; | 78 | int count; |
80 | struct repoinfo *repos; | 79 | struct repoinfo *repos; |
81 | }; | 80 | }; |
82 | 81 | ||
83 | struct commitinfo { | 82 | struct commitinfo { |
84 | struct commit *commit; | 83 | struct commit *commit; |
85 | char *author; | 84 | char *author; |
86 | char *author_email; | 85 | char *author_email; |
87 | unsigned long author_date; | 86 | unsigned long author_date; |
88 | char *committer; | 87 | char *committer; |
89 | char *committer_email; | 88 | char *committer_email; |
90 | unsigned long committer_date; | 89 | unsigned long committer_date; |
91 | char *subject; | 90 | char *subject; |
92 | char *msg; | 91 | char *msg; |
93 | }; | 92 | }; |
94 | 93 | ||
95 | struct taginfo { | 94 | struct taginfo { |
96 | char *tagger; | 95 | char *tagger; |
97 | char *tagger_email; | 96 | char *tagger_email; |
98 | int tagger_date; | 97 | int tagger_date; |
99 | char *msg; | 98 | char *msg; |
100 | }; | 99 | }; |
101 | 100 | ||
102 | extern const char cgit_version[]; | 101 | extern const char cgit_version[]; |
103 | 102 | ||
104 | extern struct repolist cgit_repolist; | 103 | extern struct repolist cgit_repolist; |
105 | extern struct repoinfo *cgit_repo; | 104 | extern struct repoinfo *cgit_repo; |
106 | extern int cgit_cmd; | 105 | extern int cgit_cmd; |
107 | 106 | ||
108 | extern char *cgit_root_title; | 107 | extern char *cgit_root_title; |
109 | extern char *cgit_css; | 108 | extern char *cgit_css; |
110 | extern char *cgit_logo; | 109 | extern char *cgit_logo; |
111 | extern char *cgit_index_header; | 110 | extern char *cgit_index_header; |
112 | extern char *cgit_logo_link; | 111 | extern char *cgit_logo_link; |
113 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
114 | extern char *cgit_agefile; | 113 | extern char *cgit_agefile; |
115 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
116 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
117 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
118 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
119 | 118 | ||
120 | extern int cgit_nocache; | 119 | extern int cgit_nocache; |
121 | extern int cgit_snapshots; | 120 | extern int cgit_snapshots; |
122 | extern int cgit_enable_log_filecount; | 121 | extern int cgit_enable_log_filecount; |
123 | extern int cgit_enable_log_linecount; | 122 | extern int cgit_enable_log_linecount; |
124 | extern int cgit_max_lock_attempts; | 123 | extern int cgit_max_lock_attempts; |
125 | extern int cgit_cache_root_ttl; | 124 | extern int cgit_cache_root_ttl; |
126 | extern int cgit_cache_repo_ttl; | 125 | extern int cgit_cache_repo_ttl; |
127 | extern int cgit_cache_dynamic_ttl; | 126 | extern int cgit_cache_dynamic_ttl; |
128 | extern int cgit_cache_static_ttl; | 127 | extern int cgit_cache_static_ttl; |
129 | extern int cgit_cache_max_create_time; | 128 | extern int cgit_cache_max_create_time; |
130 | extern int cgit_summary_log; | 129 | extern int cgit_summary_log; |
131 | 130 | ||
132 | extern int cgit_max_msg_len; | 131 | extern int cgit_max_msg_len; |
133 | extern int cgit_max_repodesc_len; | 132 | extern int cgit_max_repodesc_len; |
134 | extern int cgit_max_commit_count; | 133 | extern int cgit_max_commit_count; |
135 | 134 | ||
136 | extern int cgit_query_has_symref; | 135 | extern int cgit_query_has_symref; |
137 | extern int cgit_query_has_sha1; | 136 | extern int cgit_query_has_sha1; |
138 | 137 | ||
139 | extern char *cgit_querystring; | 138 | extern char *cgit_querystring; |
140 | extern char *cgit_query_repo; | 139 | extern char *cgit_query_repo; |
141 | extern char *cgit_query_page; | 140 | extern char *cgit_query_page; |
142 | extern char *cgit_query_search; | 141 | extern char *cgit_query_search; |
143 | extern char *cgit_query_head; | 142 | extern char *cgit_query_head; |
144 | extern char *cgit_query_sha1; | 143 | extern char *cgit_query_sha1; |
145 | extern char *cgit_query_sha2; | 144 | extern char *cgit_query_sha2; |
146 | extern char *cgit_query_path; | 145 | extern char *cgit_query_path; |
147 | extern char *cgit_query_name; | 146 | extern char *cgit_query_name; |
148 | extern int cgit_query_ofs; | 147 | extern int cgit_query_ofs; |
149 | 148 | ||
150 | extern int htmlfd; | 149 | extern int htmlfd; |
151 | 150 | ||
152 | extern int cgit_get_cmd_index(const char *cmd); | 151 | extern int cgit_get_cmd_index(const char *cmd); |
153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 152 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
154 | extern void cgit_global_config_cb(const char *name, const char *value); | 153 | extern void cgit_global_config_cb(const char *name, const char *value); |
155 | extern void cgit_repo_config_cb(const char *name, const char *value); | 154 | extern void cgit_repo_config_cb(const char *name, const char *value); |
156 | extern void cgit_querystring_cb(const char *name, const char *value); | 155 | extern void cgit_querystring_cb(const char *name, const char *value); |
157 | 156 | ||
158 | extern int chk_zero(int result, char *msg); | 157 | extern int chk_zero(int result, char *msg); |
159 | extern int chk_positive(int result, char *msg); | 158 | extern int chk_positive(int result, char *msg); |
160 | 159 | ||
161 | extern int hextoint(char c); | 160 | extern int hextoint(char c); |
162 | 161 | ||
163 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 162 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
164 | 163 | ||
165 | extern int cgit_diff_files(const unsigned char *old_sha1, | 164 | extern int cgit_diff_files(const unsigned char *old_sha1, |
166 | const unsigned char *new_sha1, | 165 | const unsigned char *new_sha1, |
167 | linediff_fn fn); | 166 | linediff_fn fn); |
168 | 167 | ||
169 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 168 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
170 | const unsigned char *new_sha1, | 169 | const unsigned char *new_sha1, |
171 | filepair_fn fn); | 170 | filepair_fn fn); |
172 | 171 | ||
173 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 172 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
174 | 173 | ||
175 | extern char *fmt(const char *format,...); | 174 | extern char *fmt(const char *format,...); |
176 | 175 | ||
177 | extern void html(const char *txt); | 176 | extern void html(const char *txt); |
178 | extern void htmlf(const char *format,...); | 177 | extern void htmlf(const char *format,...); |
179 | extern void html_txt(char *txt); | 178 | extern void html_txt(char *txt); |
180 | extern void html_ntxt(int len, char *txt); | 179 | extern void html_ntxt(int len, char *txt); |
181 | extern void html_attr(char *txt); | 180 | extern void html_attr(char *txt); |
182 | extern void html_hidden(char *name, char *value); | 181 | extern void html_hidden(char *name, char *value); |
183 | extern void html_link_open(char *url, char *title, char *class); | 182 | extern void html_link_open(char *url, char *title, char *class); |
184 | extern void html_link_close(void); | 183 | extern void html_link_close(void); |
185 | extern void html_filemode(unsigned short mode); | 184 | extern void html_filemode(unsigned short mode); |
186 | extern int html_include(const char *filename); | 185 | extern int html_include(const char *filename); |
187 | 186 | ||
188 | extern int cgit_read_config(const char *filename, configfn fn); | 187 | extern int cgit_read_config(const char *filename, configfn fn); |
189 | extern int cgit_parse_query(char *txt, configfn fn); | 188 | extern int cgit_parse_query(char *txt, configfn fn); |
190 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 189 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
191 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 190 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
192 | extern void cgit_parse_url(const char *url); | 191 | extern void cgit_parse_url(const char *url); |
193 | 192 | ||
194 | extern char *cache_safe_filename(const char *unsafe); | 193 | extern char *cache_safe_filename(const char *unsafe); |
195 | extern int cache_lock(struct cacheitem *item); | 194 | extern int cache_lock(struct cacheitem *item); |
196 | extern int cache_unlock(struct cacheitem *item); | 195 | extern int cache_unlock(struct cacheitem *item); |
197 | extern int cache_cancel_lock(struct cacheitem *item); | 196 | extern int cache_cancel_lock(struct cacheitem *item); |
198 | extern int cache_exist(struct cacheitem *item); | 197 | extern int cache_exist(struct cacheitem *item); |
199 | extern int cache_expired(struct cacheitem *item); | 198 | extern int cache_expired(struct cacheitem *item); |
200 | 199 | ||
201 | extern char *cgit_repourl(const char *reponame); | 200 | extern char *cgit_repourl(const char *reponame); |
202 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
203 | const char *query); | 202 | const char *query); |
204 | 203 | ||
205 | extern void cgit_print_error(char *msg); | 204 | extern void cgit_print_error(char *msg); |
206 | extern void cgit_print_date(time_t secs, char *format); | 205 | extern void cgit_print_date(time_t secs, char *format); |
207 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 206 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
208 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 207 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
209 | extern void cgit_print_docend(); | 208 | extern void cgit_print_docend(); |
210 | extern void cgit_print_pageheader(char *title, int show_search); | 209 | extern void cgit_print_pageheader(char *title, int show_search); |
211 | extern void cgit_print_snapshot_start(const char *mimetype, | 210 | extern void cgit_print_snapshot_start(const char *mimetype, |
212 | const char *filename, | 211 | const char *filename, |
213 | struct cacheitem *item); | 212 | struct cacheitem *item); |
214 | 213 | ||
215 | extern void cgit_print_repolist(struct cacheitem *item); | 214 | extern void cgit_print_repolist(struct cacheitem *item); |
216 | extern void cgit_print_summary(); | 215 | extern void cgit_print_summary(); |
217 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 216 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
218 | extern void cgit_print_view(const char *hex, char *path); | ||
219 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 217 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
220 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); | 218 | extern void cgit_print_tree(const char *rev, char *path); |
221 | extern void cgit_print_commit(const char *hex); | 219 | extern void cgit_print_commit(const char *hex); |
222 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, | 220 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, |
223 | char *path); | 221 | char *path); |
224 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 222 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
225 | const char *format, const char *prefix, | 223 | const char *format, const char *prefix, |
226 | const char *filename); | 224 | const char *filename); |
227 | 225 | ||
228 | #endif /* CGIT_H */ | 226 | #endif /* CGIT_H */ |
@@ -1,158 +1,159 @@ | |||
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 | char *cgit_root_title = "Git repository browser"; | 15 | char *cgit_root_title = "Git repository browser"; |
16 | char *cgit_css = "/cgit.css"; | 16 | char *cgit_css = "/cgit.css"; |
17 | char *cgit_logo = "/git-logo.png"; | 17 | char *cgit_logo = "/git-logo.png"; |
18 | char *cgit_index_header = NULL; | 18 | char *cgit_index_header = NULL; |
19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
21 | char *cgit_agefile = "info/web/last-modified"; | 21 | char *cgit_agefile = "info/web/last-modified"; |
22 | char *cgit_virtual_root = NULL; | 22 | char *cgit_virtual_root = NULL; |
23 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 23 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
24 | char *cgit_cache_root = "/var/cache/cgit"; | 24 | char *cgit_cache_root = "/var/cache/cgit"; |
25 | char *cgit_repo_group = NULL; | 25 | char *cgit_repo_group = NULL; |
26 | 26 | ||
27 | int cgit_nocache = 0; | 27 | int cgit_nocache = 0; |
28 | int cgit_snapshots = 0; | 28 | int cgit_snapshots = 0; |
29 | int cgit_enable_log_filecount = 0; | 29 | int cgit_enable_log_filecount = 0; |
30 | int cgit_enable_log_linecount = 0; | 30 | int cgit_enable_log_linecount = 0; |
31 | int cgit_max_lock_attempts = 5; | 31 | int cgit_max_lock_attempts = 5; |
32 | int cgit_cache_root_ttl = 5; | 32 | int cgit_cache_root_ttl = 5; |
33 | int cgit_cache_repo_ttl = 5; | 33 | int cgit_cache_repo_ttl = 5; |
34 | int cgit_cache_dynamic_ttl = 5; | 34 | int cgit_cache_dynamic_ttl = 5; |
35 | int cgit_cache_static_ttl = -1; | 35 | int cgit_cache_static_ttl = -1; |
36 | int cgit_cache_max_create_time = 5; | 36 | int cgit_cache_max_create_time = 5; |
37 | int cgit_summary_log = 0; | 37 | int cgit_summary_log = 0; |
38 | 38 | ||
39 | int cgit_max_msg_len = 60; | 39 | int cgit_max_msg_len = 60; |
40 | int cgit_max_repodesc_len = 60; | 40 | int cgit_max_repodesc_len = 60; |
41 | int cgit_max_commit_count = 50; | 41 | int cgit_max_commit_count = 50; |
42 | 42 | ||
43 | int cgit_query_has_symref = 0; | 43 | int cgit_query_has_symref = 0; |
44 | int cgit_query_has_sha1 = 0; | 44 | int cgit_query_has_sha1 = 0; |
45 | 45 | ||
46 | char *cgit_querystring = NULL; | 46 | char *cgit_querystring = NULL; |
47 | char *cgit_query_repo = NULL; | 47 | char *cgit_query_repo = NULL; |
48 | char *cgit_query_page = NULL; | 48 | char *cgit_query_page = NULL; |
49 | char *cgit_query_head = NULL; | 49 | char *cgit_query_head = NULL; |
50 | char *cgit_query_search = NULL; | 50 | char *cgit_query_search = NULL; |
51 | char *cgit_query_sha1 = NULL; | 51 | char *cgit_query_sha1 = NULL; |
52 | char *cgit_query_sha2 = NULL; | 52 | char *cgit_query_sha2 = NULL; |
53 | char *cgit_query_path = NULL; | 53 | char *cgit_query_path = NULL; |
54 | char *cgit_query_name = NULL; | 54 | char *cgit_query_name = NULL; |
55 | int cgit_query_ofs = 0; | 55 | int cgit_query_ofs = 0; |
56 | 56 | ||
57 | int htmlfd = 0; | 57 | int htmlfd = 0; |
58 | 58 | ||
59 | 59 | ||
60 | int cgit_get_cmd_index(const char *cmd) | 60 | int cgit_get_cmd_index(const char *cmd) |
61 | { | 61 | { |
62 | static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL}; | 62 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
63 | "snapshot", NULL}; | ||
63 | int i; | 64 | int i; |
64 | 65 | ||
65 | for(i = 0; cmds[i]; i++) | 66 | for(i = 0; cmds[i]; i++) |
66 | if (!strcmp(cmd, cmds[i])) | 67 | if (!strcmp(cmd, cmds[i])) |
67 | return i + 1; | 68 | return i + 1; |
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
70 | 71 | ||
71 | int chk_zero(int result, char *msg) | 72 | int chk_zero(int result, char *msg) |
72 | { | 73 | { |
73 | if (result != 0) | 74 | if (result != 0) |
74 | die("%s: %s", msg, strerror(errno)); | 75 | die("%s: %s", msg, strerror(errno)); |
75 | return result; | 76 | return result; |
76 | } | 77 | } |
77 | 78 | ||
78 | int chk_positive(int result, char *msg) | 79 | int chk_positive(int result, char *msg) |
79 | { | 80 | { |
80 | if (result <= 0) | 81 | if (result <= 0) |
81 | die("%s: %s", msg, strerror(errno)); | 82 | die("%s: %s", msg, strerror(errno)); |
82 | return result; | 83 | return result; |
83 | } | 84 | } |
84 | 85 | ||
85 | struct repoinfo *add_repo(const char *url) | 86 | struct repoinfo *add_repo(const char *url) |
86 | { | 87 | { |
87 | struct repoinfo *ret; | 88 | struct repoinfo *ret; |
88 | 89 | ||
89 | if (++cgit_repolist.count > cgit_repolist.length) { | 90 | if (++cgit_repolist.count > cgit_repolist.length) { |
90 | if (cgit_repolist.length == 0) | 91 | if (cgit_repolist.length == 0) |
91 | cgit_repolist.length = 8; | 92 | cgit_repolist.length = 8; |
92 | else | 93 | else |
93 | cgit_repolist.length *= 2; | 94 | cgit_repolist.length *= 2; |
94 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 95 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
95 | cgit_repolist.length * | 96 | cgit_repolist.length * |
96 | sizeof(struct repoinfo)); | 97 | sizeof(struct repoinfo)); |
97 | } | 98 | } |
98 | 99 | ||
99 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 100 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
100 | ret->url = xstrdup(url); | 101 | ret->url = xstrdup(url); |
101 | ret->name = ret->url; | 102 | ret->name = ret->url; |
102 | ret->path = NULL; | 103 | ret->path = NULL; |
103 | ret->desc = NULL; | 104 | ret->desc = NULL; |
104 | ret->owner = NULL; | 105 | ret->owner = NULL; |
105 | ret->group = cgit_repo_group; | 106 | ret->group = cgit_repo_group; |
106 | ret->defbranch = "master"; | 107 | ret->defbranch = "master"; |
107 | ret->snapshots = cgit_snapshots; | 108 | ret->snapshots = cgit_snapshots; |
108 | ret->enable_log_filecount = cgit_enable_log_filecount; | 109 | ret->enable_log_filecount = cgit_enable_log_filecount; |
109 | ret->enable_log_linecount = cgit_enable_log_linecount; | 110 | ret->enable_log_linecount = cgit_enable_log_linecount; |
110 | ret->module_link = cgit_module_link; | 111 | ret->module_link = cgit_module_link; |
111 | ret->readme = NULL; | 112 | ret->readme = NULL; |
112 | return ret; | 113 | return ret; |
113 | } | 114 | } |
114 | 115 | ||
115 | struct repoinfo *cgit_get_repoinfo(const char *url) | 116 | struct repoinfo *cgit_get_repoinfo(const char *url) |
116 | { | 117 | { |
117 | int i; | 118 | int i; |
118 | struct repoinfo *repo; | 119 | struct repoinfo *repo; |
119 | 120 | ||
120 | for (i=0; i<cgit_repolist.count; i++) { | 121 | for (i=0; i<cgit_repolist.count; i++) { |
121 | repo = &cgit_repolist.repos[i]; | 122 | repo = &cgit_repolist.repos[i]; |
122 | if (!strcmp(repo->url, url)) | 123 | if (!strcmp(repo->url, url)) |
123 | return repo; | 124 | return repo; |
124 | } | 125 | } |
125 | return NULL; | 126 | return NULL; |
126 | } | 127 | } |
127 | 128 | ||
128 | void cgit_global_config_cb(const char *name, const char *value) | 129 | void cgit_global_config_cb(const char *name, const char *value) |
129 | { | 130 | { |
130 | if (!strcmp(name, "root-title")) | 131 | if (!strcmp(name, "root-title")) |
131 | cgit_root_title = xstrdup(value); | 132 | cgit_root_title = xstrdup(value); |
132 | else if (!strcmp(name, "css")) | 133 | else if (!strcmp(name, "css")) |
133 | cgit_css = xstrdup(value); | 134 | cgit_css = xstrdup(value); |
134 | else if (!strcmp(name, "logo")) | 135 | else if (!strcmp(name, "logo")) |
135 | cgit_logo = xstrdup(value); | 136 | cgit_logo = xstrdup(value); |
136 | else if (!strcmp(name, "index-header")) | 137 | else if (!strcmp(name, "index-header")) |
137 | cgit_index_header = xstrdup(value); | 138 | cgit_index_header = xstrdup(value); |
138 | else if (!strcmp(name, "logo-link")) | 139 | else if (!strcmp(name, "logo-link")) |
139 | cgit_logo_link = xstrdup(value); | 140 | cgit_logo_link = xstrdup(value); |
140 | else if (!strcmp(name, "module-link")) | 141 | else if (!strcmp(name, "module-link")) |
141 | cgit_module_link = xstrdup(value); | 142 | cgit_module_link = xstrdup(value); |
142 | else if (!strcmp(name, "virtual-root")) | 143 | else if (!strcmp(name, "virtual-root")) |
143 | cgit_virtual_root = xstrdup(value); | 144 | cgit_virtual_root = xstrdup(value); |
144 | else if (!strcmp(name, "nocache")) | 145 | else if (!strcmp(name, "nocache")) |
145 | cgit_nocache = atoi(value); | 146 | cgit_nocache = atoi(value); |
146 | else if (!strcmp(name, "snapshots")) | 147 | else if (!strcmp(name, "snapshots")) |
147 | cgit_snapshots = atoi(value); | 148 | cgit_snapshots = atoi(value); |
148 | else if (!strcmp(name, "enable-log-filecount")) | 149 | else if (!strcmp(name, "enable-log-filecount")) |
149 | cgit_enable_log_filecount = atoi(value); | 150 | cgit_enable_log_filecount = atoi(value); |
150 | else if (!strcmp(name, "enable-log-linecount")) | 151 | else if (!strcmp(name, "enable-log-linecount")) |
151 | cgit_enable_log_linecount = atoi(value); | 152 | cgit_enable_log_linecount = atoi(value); |
152 | else if (!strcmp(name, "cache-root")) | 153 | else if (!strcmp(name, "cache-root")) |
153 | cgit_cache_root = xstrdup(value); | 154 | cgit_cache_root = xstrdup(value); |
154 | else if (!strcmp(name, "cache-root-ttl")) | 155 | else if (!strcmp(name, "cache-root-ttl")) |
155 | cgit_cache_root_ttl = atoi(value); | 156 | cgit_cache_root_ttl = atoi(value); |
156 | else if (!strcmp(name, "cache-repo-ttl")) | 157 | else if (!strcmp(name, "cache-repo-ttl")) |
157 | cgit_cache_repo_ttl = atoi(value); | 158 | cgit_cache_repo_ttl = atoi(value); |
158 | else if (!strcmp(name, "cache-static-ttl")) | 159 | else if (!strcmp(name, "cache-static-ttl")) |
diff --git a/ui-commit.c b/ui-commit.c index 1d12bbb..ed5384d 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -89,152 +89,151 @@ void print_fileinfo(struct fileinfo *info) | |||
89 | NULL, NULL); | 89 | NULL, NULL); |
90 | html_txt(info->old_path); | 90 | html_txt(info->old_path); |
91 | html("</a>)"); | 91 | html("</a>)"); |
92 | } else { | 92 | } else { |
93 | html_txt(info->new_path); | 93 | html_txt(info->new_path); |
94 | html("</a>"); | 94 | html("</a>"); |
95 | } | 95 | } |
96 | html("</td><td class='right'>"); | 96 | html("</td><td class='right'>"); |
97 | htmlf("%d", info->added + info->removed); | 97 | htmlf("%d", info->added + info->removed); |
98 | html("</td><td class='graph'>"); | 98 | html("</td><td class='graph'>"); |
99 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 99 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
100 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 100 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
101 | info->added * 100.0 / max_changes); | 101 | info->added * 100.0 / max_changes); |
102 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 102 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
103 | info->removed * 100.0 / max_changes); | 103 | info->removed * 100.0 / max_changes); |
104 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 104 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
105 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 105 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
106 | html("</tr></table></td></tr>\n"); | 106 | html("</tr></table></td></tr>\n"); |
107 | } | 107 | } |
108 | 108 | ||
109 | void cgit_count_diff_lines(char *line, int len) | 109 | void cgit_count_diff_lines(char *line, int len) |
110 | { | 110 | { |
111 | if (line && (len > 0)) { | 111 | if (line && (len > 0)) { |
112 | if (line[0] == '+') | 112 | if (line[0] == '+') |
113 | lines_added++; | 113 | lines_added++; |
114 | else if (line[0] == '-') | 114 | else if (line[0] == '-') |
115 | lines_removed++; | 115 | lines_removed++; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | void inspect_filepair(struct diff_filepair *pair) | 119 | void inspect_filepair(struct diff_filepair *pair) |
120 | { | 120 | { |
121 | files++; | 121 | files++; |
122 | lines_added = 0; | 122 | lines_added = 0; |
123 | lines_removed = 0; | 123 | lines_removed = 0; |
124 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 124 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
125 | if (files >= slots) { | 125 | if (files >= slots) { |
126 | if (slots == 0) | 126 | if (slots == 0) |
127 | slots = 4; | 127 | slots = 4; |
128 | else | 128 | else |
129 | slots = slots * 2; | 129 | slots = slots * 2; |
130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
131 | } | 131 | } |
132 | items[files-1].status = pair->status; | 132 | items[files-1].status = pair->status; |
133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
135 | items[files-1].old_mode = pair->one->mode; | 135 | items[files-1].old_mode = pair->one->mode; |
136 | items[files-1].new_mode = pair->two->mode; | 136 | items[files-1].new_mode = pair->two->mode; |
137 | items[files-1].old_path = xstrdup(pair->one->path); | 137 | items[files-1].old_path = xstrdup(pair->one->path); |
138 | items[files-1].new_path = xstrdup(pair->two->path); | 138 | items[files-1].new_path = xstrdup(pair->two->path); |
139 | items[files-1].added = lines_added; | 139 | items[files-1].added = lines_added; |
140 | items[files-1].removed = lines_removed; | 140 | items[files-1].removed = lines_removed; |
141 | if (lines_added + lines_removed > max_changes) | 141 | if (lines_added + lines_removed > max_changes) |
142 | max_changes = lines_added + lines_removed; | 142 | max_changes = lines_added + lines_removed; |
143 | total_adds += lines_added; | 143 | total_adds += lines_added; |
144 | total_rems += lines_removed; | 144 | total_rems += lines_removed; |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void cgit_print_commit(const char *hex) | 148 | void cgit_print_commit(const char *hex) |
149 | { | 149 | { |
150 | struct commit *commit, *parent; | 150 | struct commit *commit, *parent; |
151 | struct commitinfo *info; | 151 | struct commitinfo *info; |
152 | struct commit_list *p; | 152 | struct commit_list *p; |
153 | unsigned char sha1[20]; | 153 | unsigned char sha1[20]; |
154 | char *query; | 154 | char *query; |
155 | char *filename; | 155 | char *filename; |
156 | int i; | 156 | int i; |
157 | 157 | ||
158 | if (get_sha1(hex, sha1)) { | 158 | if (get_sha1(hex, sha1)) { |
159 | cgit_print_error(fmt("Bad object id: %s", hex)); | 159 | cgit_print_error(fmt("Bad object id: %s", hex)); |
160 | return; | 160 | return; |
161 | } | 161 | } |
162 | commit = lookup_commit_reference(sha1); | 162 | commit = lookup_commit_reference(sha1); |
163 | if (!commit) { | 163 | if (!commit) { |
164 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 164 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | info = cgit_parse_commit(commit); | 167 | info = cgit_parse_commit(commit); |
168 | 168 | ||
169 | html("<table class='commit-info'>\n"); | 169 | html("<table class='commit-info'>\n"); |
170 | html("<tr><th>author</th><td>"); | 170 | html("<tr><th>author</th><td>"); |
171 | html_txt(info->author); | 171 | html_txt(info->author); |
172 | html(" "); | 172 | html(" "); |
173 | html_txt(info->author_email); | 173 | html_txt(info->author_email); |
174 | html("</td><td class='right'>"); | 174 | html("</td><td class='right'>"); |
175 | cgit_print_date(info->author_date, FMT_LONGDATE); | 175 | cgit_print_date(info->author_date, FMT_LONGDATE); |
176 | html("</td></tr>\n"); | 176 | html("</td></tr>\n"); |
177 | html("<tr><th>committer</th><td>"); | 177 | html("<tr><th>committer</th><td>"); |
178 | html_txt(info->committer); | 178 | html_txt(info->committer); |
179 | html(" "); | 179 | html(" "); |
180 | html_txt(info->committer_email); | 180 | html_txt(info->committer_email); |
181 | html("</td><td class='right'>"); | 181 | html("</td><td class='right'>"); |
182 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 182 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
183 | html("</td></tr>\n"); | 183 | html("</td></tr>\n"); |
184 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 184 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
185 | query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), | 185 | query = fmt("h=%s", sha1_to_hex(commit->object.sha1)); |
186 | sha1_to_hex(commit->tree->object.sha1)); | ||
187 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); | 186 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
188 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | 187 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
189 | for (p = commit->parents; p ; p = p->next) { | 188 | for (p = commit->parents; p ; p = p->next) { |
190 | parent = lookup_commit_reference(p->item->object.sha1); | 189 | parent = lookup_commit_reference(p->item->object.sha1); |
191 | if (!parent) { | 190 | if (!parent) { |
192 | html("<tr><td colspan='3'>"); | 191 | html("<tr><td colspan='3'>"); |
193 | cgit_print_error("Error reading parent commit"); | 192 | cgit_print_error("Error reading parent commit"); |
194 | html("</td></tr>"); | 193 | html("</td></tr>"); |
195 | continue; | 194 | continue; |
196 | } | 195 | } |
197 | html("<tr><th>parent</th>" | 196 | html("<tr><th>parent</th>" |
198 | "<td colspan='2' class='sha1'>" | 197 | "<td colspan='2' class='sha1'>" |
199 | "<a href='"); | 198 | "<a href='"); |
200 | query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); | 199 | query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); |
201 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); | 200 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); |
202 | htmlf("'>%s</a> (<a href='", | 201 | htmlf("'>%s</a> (<a href='", |
203 | sha1_to_hex(p->item->object.sha1)); | 202 | sha1_to_hex(p->item->object.sha1)); |
204 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), | 203 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), |
205 | sha1_to_hex(commit->tree->object.sha1)); | 204 | sha1_to_hex(commit->tree->object.sha1)); |
206 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); | 205 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); |
207 | html("'>diff</a>)</td></tr>"); | 206 | html("'>diff</a>)</td></tr>"); |
208 | } | 207 | } |
209 | if (cgit_repo->snapshots) { | 208 | if (cgit_repo->snapshots) { |
210 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); | 209 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); |
211 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); | 210 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); |
212 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", | 211 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", |
213 | fmt("id=%s&name=%s", hex, filename))); | 212 | fmt("id=%s&name=%s", hex, filename))); |
214 | htmlf("'>%s</a></td></tr>", filename); | 213 | htmlf("'>%s</a></td></tr>", filename); |
215 | } | 214 | } |
216 | html("</table>\n"); | 215 | html("</table>\n"); |
217 | html("<div class='commit-subject'>"); | 216 | html("<div class='commit-subject'>"); |
218 | html_txt(info->subject); | 217 | html_txt(info->subject); |
219 | html("</div>"); | 218 | html("</div>"); |
220 | html("<div class='commit-msg'>"); | 219 | html("<div class='commit-msg'>"); |
221 | html_txt(info->msg); | 220 | html_txt(info->msg); |
222 | html("</div>"); | 221 | html("</div>"); |
223 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 222 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
224 | html("<div class='diffstat-header'>Diffstat</div>"); | 223 | html("<div class='diffstat-header'>Diffstat</div>"); |
225 | html("<table class='diffstat'>"); | 224 | html("<table class='diffstat'>"); |
226 | max_changes = 0; | 225 | max_changes = 0; |
227 | cgit_diff_commit(commit, inspect_filepair); | 226 | cgit_diff_commit(commit, inspect_filepair); |
228 | for(i = 0; i<files; i++) | 227 | for(i = 0; i<files; i++) |
229 | print_fileinfo(&items[i]); | 228 | print_fileinfo(&items[i]); |
230 | html("</table>"); | 229 | html("</table>"); |
231 | html("<div class='diffstat-summary'>"); | 230 | html("<div class='diffstat-summary'>"); |
232 | htmlf("%d files changed, %d insertions, %d deletions (", | 231 | htmlf("%d files changed, %d insertions, %d deletions (", |
233 | files, total_adds, total_rems); | 232 | files, total_adds, total_rems); |
234 | query = fmt("h=%s", hex); | 233 | query = fmt("h=%s", hex); |
235 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); | 234 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); |
236 | html("show diff</a>)"); | 235 | html("show diff</a>)"); |
237 | html("</div>"); | 236 | html("</div>"); |
238 | } | 237 | } |
239 | cgit_free_commitinfo(info); | 238 | cgit_free_commitinfo(info); |
240 | } | 239 | } |
@@ -1,104 +1,214 @@ | |||
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; | ||
13 | int header = 0; | ||
12 | 14 | ||
13 | static int print_entry(const unsigned char *sha1, const char *base, | 15 | static void print_object(const unsigned char *sha1, char *path) |
14 | int baselen, const char *pathname, unsigned int mode, | 16 | { |
15 | int stage) | 17 | enum object_type type; |
18 | unsigned char *buf; | ||
19 | unsigned long size, lineno, start, idx; | ||
20 | |||
21 | type = sha1_object_info(sha1, &size); | ||
22 | if (type == OBJ_BAD) { | ||
23 | cgit_print_error(fmt("Bad object name: %s", | ||
24 | sha1_to_hex(sha1))); | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | buf = read_sha1_file(sha1, &type, &size); | ||
29 | if (!buf) { | ||
30 | cgit_print_error(fmt("Error reading object %s", | ||
31 | sha1_to_hex(sha1))); | ||
32 | return; | ||
33 | } | ||
34 | |||
35 | html("<table class='blob'>\n"); | ||
36 | idx = 0; | ||
37 | start = 0; | ||
38 | lineno = 0; | ||
39 | while(idx < size) { | ||
40 | if (buf[idx] == '\n') { | ||
41 | buf[idx] = '\0'; | ||
42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", | ||
43 | ++lineno); | ||
44 | html_txt(buf + start); | ||
45 | html("</td></tr>\n"); | ||
46 | start = idx + 1; | ||
47 | } | ||
48 | idx++; | ||
49 | } | ||
50 | html("\n</td></tr>\n"); | ||
51 | html("</table>\n"); | ||
52 | } | ||
53 | |||
54 | |||
55 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | ||
56 | const char *pathname, unsigned int mode, int stage) | ||
16 | { | 57 | { |
17 | char *name; | 58 | char *name; |
18 | enum object_type type; | 59 | enum object_type type; |
19 | unsigned long size = 0; | 60 | unsigned long size = 0; |
61 | char *url, *qry; | ||
20 | 62 | ||
21 | name = xstrdup(pathname); | 63 | name = xstrdup(pathname); |
22 | type = sha1_object_info(sha1, &size); | 64 | type = sha1_object_info(sha1, &size); |
23 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { | 65 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
24 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 66 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
25 | name, | 67 | name, |
26 | sha1_to_hex(sha1)); | 68 | sha1_to_hex(sha1)); |
27 | return 0; | 69 | return 0; |
28 | } | 70 | } |
71 | qry = fmt("h=%s&path=%s%s%s", curr_rev, | ||
72 | cgit_query_path ? cgit_query_path : "", | ||
73 | cgit_query_path ? "/" : "", pathname); | ||
74 | url = cgit_pageurl(cgit_query_repo, "tree", qry); | ||
29 | html("<tr><td class='filemode'>"); | 75 | html("<tr><td class='filemode'>"); |
30 | html_filemode(mode); | 76 | html_filemode(mode); |
31 | html("</td><td "); | 77 | html("</td><td "); |
32 | if (S_ISDIRLNK(mode)) { | 78 | if (S_ISDIRLNK(mode)) { |
33 | htmlf("class='ls-mod'><a href='"); | 79 | htmlf("class='ls-mod'><a href='"); |
34 | html_attr(fmt(cgit_repo->module_link, | 80 | html_attr(fmt(cgit_repo->module_link, |
35 | name, | 81 | name, |
36 | sha1_to_hex(sha1))); | 82 | sha1_to_hex(sha1))); |
37 | } else if (S_ISDIR(mode)) { | 83 | } else if (S_ISDIR(mode)) { |
38 | html("class='ls-dir'><a href='"); | 84 | html("class='ls-dir'><a href='"); |
39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 85 | html_attr(url); |
40 | fmt("h=%s&id=%s&path=%s%s/", | ||
41 | curr_rev, | ||
42 | sha1_to_hex(sha1), | ||
43 | cgit_query_path ? cgit_query_path : "", | ||
44 | pathname))); | ||
45 | } else { | 86 | } else { |
46 | html("class='ls-blob'><a href='"); | 87 | html("class='ls-blob'><a href='"); |
47 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 88 | html_attr(url); |
48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, | ||
49 | sha1_to_hex(sha1), | ||
50 | cgit_query_path ? cgit_query_path : "", | ||
51 | pathname))); | ||
52 | } | 89 | } |
53 | htmlf("'>%s</a></td>", name); | 90 | htmlf("'>%s</a></td>", name); |
54 | htmlf("<td class='filesize'>%li</td>", size); | 91 | htmlf("<td class='filesize'>%li</td>", size); |
55 | 92 | ||
56 | html("<td class='links'><a href='"); | 93 | html("<td class='links'><a href='"); |
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", | 94 | qry = fmt("h=%s&path=%s%s%s", curr_rev, |
58 | fmt("h=%s&path=%s%s", | 95 | cgit_query_path ? cgit_query_path : "", |
59 | curr_rev, | 96 | cgit_query_path ? "/" : "", pathname); |
60 | cgit_query_path ? cgit_query_path : "", | 97 | url = cgit_pageurl(cgit_query_repo, "log", qry); |
61 | pathname))); | 98 | html_attr(url); |
62 | html("'>history</a></td>"); | 99 | html("' class='button'>H</a></td>"); |
63 | html("</tr>\n"); | 100 | html("</tr>\n"); |
64 | free(name); | 101 | free(name); |
65 | return 0; | 102 | return 0; |
66 | } | 103 | } |
67 | 104 | ||
68 | void cgit_print_tree(const char *rev, const char *hex, char *path) | 105 | static void ls_head() |
106 | { | ||
107 | html("<table class='list'>\n"); | ||
108 | html("<tr class='nohover'>"); | ||
109 | html("<th class='left'>Mode</th>"); | ||
110 | html("<th class='left'>Name</th>"); | ||
111 | html("<th class='right'>Size</th>"); | ||
112 | html("<th/>"); | ||
113 | html("</tr>\n"); | ||
114 | header = 1; | ||
115 | } | ||
116 | |||
117 | static void ls_tail() | ||
118 | { | ||
119 | if (!header) | ||
120 | return; | ||
121 | html("</table>\n"); | ||
122 | header = 0; | ||
123 | } | ||
124 | |||
125 | static void ls_tree(const unsigned char *sha1, char *path) | ||
69 | { | 126 | { |
70 | struct tree *tree; | 127 | struct tree *tree; |
128 | |||
129 | tree = parse_tree_indirect(sha1); | ||
130 | if (!tree) { | ||
131 | cgit_print_error(fmt("Not a tree object: %s", | ||
132 | sha1_to_hex(sha1))); | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | ls_head(); | ||
137 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); | ||
138 | ls_tail(); | ||
139 | } | ||
140 | |||
141 | |||
142 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | ||
143 | const char *pathname, unsigned mode, int stage) | ||
144 | { | ||
145 | static int state; | ||
146 | static char buffer[PATH_MAX]; | ||
147 | char *url; | ||
148 | |||
149 | if (state == 0) { | ||
150 | memcpy(buffer, base, baselen); | ||
151 | strcpy(buffer+baselen, pathname); | ||
152 | url = cgit_pageurl(cgit_query_repo, "tree", | ||
153 | fmt("h=%s&path=%s", curr_rev, buffer)); | ||
154 | htmlf(" / <a href='"); | ||
155 | html_attr(url); | ||
156 | html("'>"); | ||
157 | html_txt(xstrdup(pathname)); | ||
158 | html("</a>"); | ||
159 | |||
160 | if (strcmp(match_path, buffer)) | ||
161 | return READ_TREE_RECURSIVE; | ||
162 | |||
163 | if (S_ISDIR(mode)) { | ||
164 | state = 1; | ||
165 | ls_head(); | ||
166 | return READ_TREE_RECURSIVE; | ||
167 | } else { | ||
168 | print_object(sha1, buffer); | ||
169 | return 0; | ||
170 | } | ||
171 | } | ||
172 | ls_item(sha1, base, baselen, pathname, mode, stage); | ||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | |||
177 | /* | ||
178 | * Show a tree or a blob | ||
179 | * rev: the commit pointing at the root tree object | ||
180 | * path: path to tree or blob | ||
181 | */ | ||
182 | void cgit_print_tree(const char *rev, char *path) | ||
183 | { | ||
71 | unsigned char sha1[20]; | 184 | unsigned char sha1[20]; |
72 | struct commit *commit; | 185 | struct commit *commit; |
186 | const char *paths[] = {path, NULL}; | ||
187 | |||
188 | if (!rev) | ||
189 | rev = cgit_query_head; | ||
73 | 190 | ||
74 | curr_rev = xstrdup(rev); | 191 | curr_rev = xstrdup(rev); |
75 | get_sha1(rev, sha1); | 192 | if (get_sha1(rev, sha1)) { |
193 | cgit_print_error(fmt("Invalid revision name: %s", rev)); | ||
194 | return; | ||
195 | } | ||
76 | commit = lookup_commit_reference(sha1); | 196 | commit = lookup_commit_reference(sha1); |
77 | if (!commit || parse_commit(commit)) { | 197 | if (!commit || parse_commit(commit)) { |
78 | cgit_print_error(fmt("Invalid head: %s", rev)); | 198 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
79 | return; | 199 | return; |
80 | } | 200 | } |
81 | if (!hex) | ||
82 | hex = sha1_to_hex(commit->tree->object.sha1); | ||
83 | 201 | ||
84 | if (get_sha1_hex(hex, sha1)) { | 202 | html("path: <a href='"); |
85 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 203 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); |
86 | return; | 204 | html("'>root</a>"); |
87 | } | 205 | |
88 | tree = parse_tree_indirect(sha1); | 206 | if (path == NULL) { |
89 | if (!tree) { | 207 | ls_tree(commit->tree->object.sha1, NULL); |
90 | cgit_print_error(fmt("Not a tree object: %s", hex)); | ||
91 | return; | 208 | return; |
92 | } | 209 | } |
93 | 210 | ||
94 | html_txt(path); | 211 | match_path = path; |
95 | html("<table class='list'>\n"); | 212 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); |
96 | html("<tr class='nohover'>"); | 213 | ls_tail(); |
97 | html("<th class='left'>Mode</th>"); | ||
98 | html("<th class='left'>Name</th>"); | ||
99 | html("<th class='right'>Size</th>"); | ||
100 | html("<th/>"); | ||
101 | html("</tr>\n"); | ||
102 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | ||
103 | html("</table>\n"); | ||
104 | } | 214 | } |
diff --git a/ui-view.c b/ui-view.c deleted file mode 100644 index 8873415..0000000 --- a/ui-view.c +++ b/dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | /* ui-view.c: functions to output _any_ object, given it's sha1 | ||
2 | * | ||
3 | * Copyright (C) 2006 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 | void cgit_print_view(const char *hex, char *path) | ||
12 | { | ||
13 | unsigned char sha1[20]; | ||
14 | enum object_type type; | ||
15 | unsigned char *buf; | ||
16 | unsigned long size; | ||
17 | |||
18 | if (get_sha1_hex(hex, sha1)){ | ||
19 | cgit_print_error(fmt("Bad hex value: %s", hex)); | ||
20 | return; | ||
21 | } | ||
22 | |||
23 | type = sha1_object_info(sha1, &size); | ||
24 | if (type == OBJ_BAD) { | ||
25 | cgit_print_error(fmt("Bad object name: %s", hex)); | ||
26 | return; | ||
27 | } | ||
28 | |||
29 | buf = read_sha1_file(sha1, &type, &size); | ||
30 | if (!buf) { | ||
31 | cgit_print_error(fmt("Error reading object %s", hex)); | ||
32 | return; | ||
33 | } | ||
34 | |||
35 | buf[size] = '\0'; | ||
36 | html("<table class='list'>\n"); | ||
37 | html("<tr class='nohover'><th class='left'>"); | ||
38 | if (path) | ||
39 | htmlf("%s (", path); | ||
40 | htmlf("%s %s, %li bytes", typename(type), hex, size); | ||
41 | if (path) | ||
42 | html(")"); | ||
43 | |||
44 | html(" <a href='"); | ||
45 | html_attr(cgit_pageurl(cgit_query_repo, "blob", | ||
46 | fmt("id=%s&path=%s", | ||
47 | hex, | ||
48 | path))); | ||
49 | html("'>download</a>"); | ||
50 | html("</th></tr>\n"); | ||
51 | html("<tr><td class='blob'>\n"); | ||
52 | html_txt(buf); | ||
53 | html("\n</td></tr>\n"); | ||
54 | html("</table>\n"); | ||
55 | } | ||