-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-patch.c | 105 | ||||
-rw-r--r-- | ui-shared.c | 8 |
6 files changed, 122 insertions, 2 deletions
@@ -1,83 +1,83 @@ | |||
1 | CGIT_VERSION = v0.7.1 | 1 | CGIT_VERSION = v0.7.1 |
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.5 | 7 | GIT_VER = 1.5.3.5 |
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 | ifdef NEEDS_LIBICONV | 22 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | 23 | EXTLIBS += -liconv |
24 | endif | 24 | endif |
25 | 25 | ||
26 | 26 | ||
27 | .PHONY: all git test install clean distclean emptycache force-version get-git | 27 | .PHONY: all git test install clean distclean emptycache force-version get-git |
28 | 28 | ||
29 | all: cgit git | 29 | all: cgit git |
30 | 30 | ||
31 | VERSION: force-version | 31 | VERSION: force-version |
32 | @./gen-version.sh "$(CGIT_VERSION)" | 32 | @./gen-version.sh "$(CGIT_VERSION)" |
33 | -include VERSION | 33 | -include VERSION |
34 | 34 | ||
35 | 35 | ||
36 | CFLAGS += -g -Wall -Igit | 36 | CFLAGS += -g -Wall -Igit |
37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
42 | 42 | ||
43 | 43 | ||
44 | cgit: cgit.c $(OBJECTS) | 44 | cgit: cgit.c $(OBJECTS) |
45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
46 | 46 | ||
47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION |
48 | 48 | ||
49 | git/xdiff/lib.a: | git | 49 | git/xdiff/lib.a: | git |
50 | 50 | ||
51 | git/libgit.a: | git | 51 | git/libgit.a: | git |
52 | 52 | ||
53 | git: | 53 | git: |
54 | cd git && $(MAKE) xdiff/lib.a | 54 | cd git && $(MAKE) xdiff/lib.a |
55 | cd git && $(MAKE) libgit.a | 55 | cd git && $(MAKE) libgit.a |
56 | 56 | ||
57 | test: all | 57 | test: all |
58 | $(MAKE) -C tests | 58 | $(MAKE) -C tests |
59 | 59 | ||
60 | install: all | 60 | install: all |
61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css | 63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css |
64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png | 64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png |
65 | 65 | ||
66 | uninstall: | 66 | uninstall: |
67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css | 68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css |
69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
70 | 70 | ||
71 | clean: | 71 | clean: |
72 | rm -f cgit VERSION *.o | 72 | rm -f cgit VERSION *.o |
73 | cd git && $(MAKE) clean | 73 | cd git && $(MAKE) clean |
74 | 74 | ||
75 | distclean: clean | 75 | distclean: clean |
76 | git clean -d -x | 76 | git clean -d -x |
77 | cd git && git clean -d -x | 77 | cd git && git clean -d -x |
78 | 78 | ||
79 | emptycache: | 79 | emptycache: |
80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* | 80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* |
81 | 81 | ||
82 | get-git: | 82 | get-git: |
83 | 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,178 @@ | |||
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 | static void cgit_print_repo_page(struct cacheitem *item) | 48 | static void cgit_print_repo_page(struct cacheitem *item) |
49 | { | 49 | { |
50 | char *title; | 50 | char *title; |
51 | int show_search; | 51 | int show_search; |
52 | 52 | ||
53 | if (!cgit_query_head) | 53 | if (!cgit_query_head) |
54 | cgit_query_head = cgit_repo->defbranch; | 54 | cgit_query_head = cgit_repo->defbranch; |
55 | 55 | ||
56 | if (chdir(cgit_repo->path)) { | 56 | if (chdir(cgit_repo->path)) { |
57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | cgit_print_docstart(title, item); | 58 | cgit_print_docstart(title, item); |
59 | cgit_print_pageheader(title, 0); | 59 | cgit_print_pageheader(title, 0); |
60 | cgit_print_error(fmt("Unable to scan repository: %s", | 60 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | strerror(errno))); | 61 | strerror(errno))); |
62 | cgit_print_docend(); | 62 | cgit_print_docend(); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | 65 | ||
66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | show_search = 0; | 67 | show_search = 0; |
68 | setenv("GIT_DIR", cgit_repo->path, 1); | 68 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | 69 | ||
70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, | 71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_path, | 73 | cgit_query_path, |
74 | cgit_repo->snapshots ); | 74 | cgit_repo->snapshots ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (cgit_cmd == CMD_PATCH) { | ||
79 | cgit_print_patch(cgit_query_sha1, item); | ||
80 | return; | ||
81 | } | ||
82 | |||
78 | if (cgit_cmd == CMD_BLOB) { | 83 | if (cgit_cmd == CMD_BLOB) { |
79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 84 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
80 | return; | 85 | return; |
81 | } | 86 | } |
82 | 87 | ||
83 | show_search = (cgit_cmd == CMD_LOG); | 88 | show_search = (cgit_cmd == CMD_LOG); |
84 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
85 | if (!cgit_cmd) { | 90 | if (!cgit_cmd) { |
86 | cgit_print_pageheader("summary", show_search); | 91 | cgit_print_pageheader("summary", show_search); |
87 | cgit_print_summary(); | 92 | cgit_print_summary(); |
88 | cgit_print_docend(); | 93 | cgit_print_docend(); |
89 | return; | 94 | return; |
90 | } | 95 | } |
91 | 96 | ||
92 | cgit_print_pageheader(cgit_query_page, show_search); | 97 | cgit_print_pageheader(cgit_query_page, show_search); |
93 | 98 | ||
94 | switch(cgit_cmd) { | 99 | switch(cgit_cmd) { |
95 | case CMD_LOG: | 100 | case CMD_LOG: |
96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 101 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
97 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, | 102 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, |
98 | cgit_query_path, 1); | 103 | cgit_query_path, 1); |
99 | break; | 104 | break; |
100 | case CMD_TREE: | 105 | case CMD_TREE: |
101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 106 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
102 | break; | 107 | break; |
103 | case CMD_COMMIT: | 108 | case CMD_COMMIT: |
104 | cgit_print_commit(cgit_query_sha1); | 109 | cgit_print_commit(cgit_query_sha1); |
105 | break; | 110 | break; |
106 | case CMD_REFS: | 111 | case CMD_REFS: |
107 | cgit_print_refs(); | 112 | cgit_print_refs(); |
108 | break; | 113 | break; |
109 | case CMD_TAG: | 114 | case CMD_TAG: |
110 | cgit_print_tag(cgit_query_sha1); | 115 | cgit_print_tag(cgit_query_sha1); |
111 | break; | 116 | break; |
112 | case CMD_DIFF: | 117 | case CMD_DIFF: |
113 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | 118 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
114 | break; | 119 | break; |
115 | default: | 120 | default: |
116 | cgit_print_error("Invalid request"); | 121 | cgit_print_error("Invalid request"); |
117 | } | 122 | } |
118 | cgit_print_docend(); | 123 | cgit_print_docend(); |
119 | } | 124 | } |
120 | 125 | ||
121 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 126 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
122 | { | 127 | { |
123 | static char buf[PATH_MAX]; | 128 | static char buf[PATH_MAX]; |
124 | int stdout2; | 129 | int stdout2; |
125 | 130 | ||
126 | getcwd(buf, sizeof(buf)); | 131 | getcwd(buf, sizeof(buf)); |
127 | item->st.st_mtime = time(NULL); | 132 | item->st.st_mtime = time(NULL); |
128 | 133 | ||
129 | if (use_cache) { | 134 | if (use_cache) { |
130 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 135 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
131 | "Preserving STDOUT"); | 136 | "Preserving STDOUT"); |
132 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 137 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
133 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 138 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
134 | } | 139 | } |
135 | 140 | ||
136 | if (cgit_repo) | 141 | if (cgit_repo) |
137 | cgit_print_repo_page(item); | 142 | cgit_print_repo_page(item); |
138 | else | 143 | else |
139 | cgit_print_repolist(item); | 144 | cgit_print_repolist(item); |
140 | 145 | ||
141 | if (use_cache) { | 146 | if (use_cache) { |
142 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 147 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
143 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 148 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
144 | "Restoring original STDOUT"); | 149 | "Restoring original STDOUT"); |
145 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 150 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
146 | } | 151 | } |
147 | 152 | ||
148 | chdir(buf); | 153 | chdir(buf); |
149 | } | 154 | } |
150 | 155 | ||
151 | static void cgit_check_cache(struct cacheitem *item) | 156 | static void cgit_check_cache(struct cacheitem *item) |
152 | { | 157 | { |
153 | int i = 0; | 158 | int i = 0; |
154 | 159 | ||
155 | top: | 160 | top: |
156 | if (++i > cgit_max_lock_attempts) { | 161 | if (++i > cgit_max_lock_attempts) { |
157 | die("cgit_refresh_cache: unable to lock %s: %s", | 162 | die("cgit_refresh_cache: unable to lock %s: %s", |
158 | item->name, strerror(errno)); | 163 | item->name, strerror(errno)); |
159 | } | 164 | } |
160 | if (!cache_exist(item)) { | 165 | if (!cache_exist(item)) { |
161 | if (!cache_lock(item)) { | 166 | if (!cache_lock(item)) { |
162 | sleep(1); | 167 | sleep(1); |
163 | goto top; | 168 | goto top; |
164 | } | 169 | } |
165 | if (!cache_exist(item)) { | 170 | if (!cache_exist(item)) { |
166 | cgit_fill_cache(item, 1); | 171 | cgit_fill_cache(item, 1); |
167 | cache_unlock(item); | 172 | cache_unlock(item); |
168 | } else { | 173 | } else { |
169 | cache_cancel_lock(item); | 174 | cache_cancel_lock(item); |
170 | } | 175 | } |
171 | } else if (cache_expired(item) && cache_lock(item)) { | 176 | } else if (cache_expired(item) && cache_lock(item)) { |
172 | if (cache_expired(item)) { | 177 | if (cache_expired(item)) { |
173 | cgit_fill_cache(item, 1); | 178 | cgit_fill_cache(item, 1); |
@@ -1,128 +1,129 @@ | |||
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 | #include <utf8.h> |
20 | 20 | ||
21 | 21 | ||
22 | /* | 22 | /* |
23 | * The valid cgit repo-commands | 23 | * The valid cgit repo-commands |
24 | */ | 24 | */ |
25 | #define CMD_LOG 1 | 25 | #define CMD_LOG 1 |
26 | #define CMD_COMMIT 2 | 26 | #define CMD_COMMIT 2 |
27 | #define CMD_DIFF 3 | 27 | #define CMD_DIFF 3 |
28 | #define CMD_TREE 4 | 28 | #define CMD_TREE 4 |
29 | #define CMD_BLOB 5 | 29 | #define CMD_BLOB 5 |
30 | #define CMD_SNAPSHOT 6 | 30 | #define CMD_SNAPSHOT 6 |
31 | #define CMD_TAG 7 | 31 | #define CMD_TAG 7 |
32 | #define CMD_REFS 8 | 32 | #define CMD_REFS 8 |
33 | #define CMD_PATCH 9 | ||
33 | 34 | ||
34 | /* | 35 | /* |
35 | * Dateformats used on misc. pages | 36 | * Dateformats used on misc. pages |
36 | */ | 37 | */ |
37 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 38 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
38 | #define FMT_SHORTDATE "%Y-%m-%d" | 39 | #define FMT_SHORTDATE "%Y-%m-%d" |
39 | 40 | ||
40 | 41 | ||
41 | /* | 42 | /* |
42 | * Limits used for relative dates | 43 | * Limits used for relative dates |
43 | */ | 44 | */ |
44 | #define TM_MIN 60 | 45 | #define TM_MIN 60 |
45 | #define TM_HOUR (TM_MIN * 60) | 46 | #define TM_HOUR (TM_MIN * 60) |
46 | #define TM_DAY (TM_HOUR * 24) | 47 | #define TM_DAY (TM_HOUR * 24) |
47 | #define TM_WEEK (TM_DAY * 7) | 48 | #define TM_WEEK (TM_DAY * 7) |
48 | #define TM_YEAR (TM_DAY * 365) | 49 | #define TM_YEAR (TM_DAY * 365) |
49 | #define TM_MONTH (TM_YEAR / 12.0) | 50 | #define TM_MONTH (TM_YEAR / 12.0) |
50 | 51 | ||
51 | 52 | ||
52 | /* | 53 | /* |
53 | * Default encoding | 54 | * Default encoding |
54 | */ | 55 | */ |
55 | #define PAGE_ENCODING "UTF-8" | 56 | #define PAGE_ENCODING "UTF-8" |
56 | 57 | ||
57 | typedef void (*configfn)(const char *name, const char *value); | 58 | typedef void (*configfn)(const char *name, const char *value); |
58 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 59 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
59 | typedef void (*linediff_fn)(char *line, int len); | 60 | typedef void (*linediff_fn)(char *line, int len); |
60 | 61 | ||
61 | struct cacheitem { | 62 | struct cacheitem { |
62 | char *name; | 63 | char *name; |
63 | struct stat st; | 64 | struct stat st; |
64 | int ttl; | 65 | int ttl; |
65 | int fd; | 66 | int fd; |
66 | }; | 67 | }; |
67 | 68 | ||
68 | struct repoinfo { | 69 | struct repoinfo { |
69 | char *url; | 70 | char *url; |
70 | char *name; | 71 | char *name; |
71 | char *path; | 72 | char *path; |
72 | char *desc; | 73 | char *desc; |
73 | char *owner; | 74 | char *owner; |
74 | char *defbranch; | 75 | char *defbranch; |
75 | char *group; | 76 | char *group; |
76 | char *module_link; | 77 | char *module_link; |
77 | char *readme; | 78 | char *readme; |
78 | char *clone_url; | 79 | char *clone_url; |
79 | int snapshots; | 80 | int snapshots; |
80 | int enable_log_filecount; | 81 | int enable_log_filecount; |
81 | int enable_log_linecount; | 82 | int enable_log_linecount; |
82 | }; | 83 | }; |
83 | 84 | ||
84 | struct repolist { | 85 | struct repolist { |
85 | int length; | 86 | int length; |
86 | int count; | 87 | int count; |
87 | struct repoinfo *repos; | 88 | struct repoinfo *repos; |
88 | }; | 89 | }; |
89 | 90 | ||
90 | struct commitinfo { | 91 | struct commitinfo { |
91 | struct commit *commit; | 92 | struct commit *commit; |
92 | char *author; | 93 | char *author; |
93 | char *author_email; | 94 | char *author_email; |
94 | unsigned long author_date; | 95 | unsigned long author_date; |
95 | char *committer; | 96 | char *committer; |
96 | char *committer_email; | 97 | char *committer_email; |
97 | unsigned long committer_date; | 98 | unsigned long committer_date; |
98 | char *subject; | 99 | char *subject; |
99 | char *msg; | 100 | char *msg; |
100 | char *msg_encoding; | 101 | char *msg_encoding; |
101 | }; | 102 | }; |
102 | 103 | ||
103 | struct taginfo { | 104 | struct taginfo { |
104 | char *tagger; | 105 | char *tagger; |
105 | char *tagger_email; | 106 | char *tagger_email; |
106 | int tagger_date; | 107 | int tagger_date; |
107 | char *msg; | 108 | char *msg; |
108 | }; | 109 | }; |
109 | 110 | ||
110 | struct refinfo { | 111 | struct refinfo { |
111 | const char *refname; | 112 | const char *refname; |
112 | struct object *object; | 113 | struct object *object; |
113 | union { | 114 | union { |
114 | struct taginfo *tag; | 115 | struct taginfo *tag; |
115 | struct commitinfo *commit; | 116 | struct commitinfo *commit; |
116 | }; | 117 | }; |
117 | }; | 118 | }; |
118 | 119 | ||
119 | struct reflist { | 120 | struct reflist { |
120 | struct refinfo **refs; | 121 | struct refinfo **refs; |
121 | int alloc; | 122 | int alloc; |
122 | int count; | 123 | int count; |
123 | }; | 124 | }; |
124 | 125 | ||
125 | extern const char *cgit_version; | 126 | extern const char *cgit_version; |
126 | 127 | ||
127 | extern struct repolist cgit_repolist; | 128 | extern struct repolist cgit_repolist; |
128 | extern struct repoinfo *cgit_repo; | 129 | extern struct repoinfo *cgit_repo; |
@@ -190,104 +191,105 @@ extern int chk_positive(int result, char *msg); | |||
190 | extern int chk_non_negative(int result, char *msg); | 191 | extern int chk_non_negative(int result, char *msg); |
191 | 192 | ||
192 | extern int hextoint(char c); | 193 | extern int hextoint(char c); |
193 | extern char *trim_end(const char *str, char c); | 194 | extern char *trim_end(const char *str, char c); |
194 | extern char *strlpart(char *txt, int maxlen); | 195 | extern char *strlpart(char *txt, int maxlen); |
195 | extern char *strrpart(char *txt, int maxlen); | 196 | extern char *strrpart(char *txt, int maxlen); |
196 | 197 | ||
197 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 198 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
198 | 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, |
199 | int flags, void *cb_data); | 200 | int flags, void *cb_data); |
200 | 201 | ||
201 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 202 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
202 | 203 | ||
203 | extern int cgit_diff_files(const unsigned char *old_sha1, | 204 | extern int cgit_diff_files(const unsigned char *old_sha1, |
204 | const unsigned char *new_sha1, | 205 | const unsigned char *new_sha1, |
205 | linediff_fn fn); | 206 | linediff_fn fn); |
206 | 207 | ||
207 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 208 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
208 | const unsigned char *new_sha1, | 209 | const unsigned char *new_sha1, |
209 | filepair_fn fn, const char *prefix); | 210 | filepair_fn fn, const char *prefix); |
210 | 211 | ||
211 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 212 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
212 | 213 | ||
213 | extern char *fmt(const char *format,...); | 214 | extern char *fmt(const char *format,...); |
214 | 215 | ||
215 | extern void html(const char *txt); | 216 | extern void html(const char *txt); |
216 | extern void htmlf(const char *format,...); | 217 | extern void htmlf(const char *format,...); |
217 | extern void html_txt(char *txt); | 218 | extern void html_txt(char *txt); |
218 | extern void html_ntxt(int len, char *txt); | 219 | extern void html_ntxt(int len, char *txt); |
219 | extern void html_attr(char *txt); | 220 | extern void html_attr(char *txt); |
220 | extern void html_hidden(char *name, char *value); | 221 | extern void html_hidden(char *name, char *value); |
221 | extern void html_option(char *value, char *text, char *selected_value); | 222 | extern void html_option(char *value, char *text, char *selected_value); |
222 | extern void html_link_open(char *url, char *title, char *class); | 223 | extern void html_link_open(char *url, char *title, char *class); |
223 | extern void html_link_close(void); | 224 | extern void html_link_close(void); |
224 | extern void html_filemode(unsigned short mode); | 225 | extern void html_filemode(unsigned short mode); |
225 | extern int html_include(const char *filename); | 226 | extern int html_include(const char *filename); |
226 | 227 | ||
227 | extern int cgit_read_config(const char *filename, configfn fn); | 228 | extern int cgit_read_config(const char *filename, configfn fn); |
228 | extern int cgit_parse_query(char *txt, configfn fn); | 229 | extern int cgit_parse_query(char *txt, configfn fn); |
229 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 230 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
230 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 231 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
231 | extern void cgit_parse_url(const char *url); | 232 | extern void cgit_parse_url(const char *url); |
232 | 233 | ||
233 | extern char *cache_safe_filename(const char *unsafe); | 234 | extern char *cache_safe_filename(const char *unsafe); |
234 | extern int cache_lock(struct cacheitem *item); | 235 | extern int cache_lock(struct cacheitem *item); |
235 | extern int cache_unlock(struct cacheitem *item); | 236 | extern int cache_unlock(struct cacheitem *item); |
236 | extern int cache_cancel_lock(struct cacheitem *item); | 237 | extern int cache_cancel_lock(struct cacheitem *item); |
237 | extern int cache_exist(struct cacheitem *item); | 238 | extern int cache_exist(struct cacheitem *item); |
238 | extern int cache_expired(struct cacheitem *item); | 239 | extern int cache_expired(struct cacheitem *item); |
239 | 240 | ||
240 | extern char *cgit_repourl(const char *reponame); | 241 | extern char *cgit_repourl(const char *reponame); |
241 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 242 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
242 | const char *filename, const char *query); | 243 | const char *filename, const char *query); |
243 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 244 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
244 | const char *query); | 245 | const char *query); |
245 | 246 | ||
246 | extern const char *cgit_repobasename(const char *reponame); | 247 | extern const char *cgit_repobasename(const char *reponame); |
247 | 248 | ||
248 | 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, |
249 | char *rev, char *path); | 250 | char *rev, char *path); |
250 | 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, |
251 | char *rev, char *path, int ofs, char *grep, | 252 | char *rev, char *path, int ofs, char *grep, |
252 | char *pattern); | 253 | char *pattern); |
253 | 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, |
254 | char *rev); | 255 | char *rev); |
255 | 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, |
256 | char *rev, char *path); | 257 | char *rev, char *path); |
257 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 258 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
258 | char *head, char *rev, char *archivename); | 259 | char *head, char *rev, char *archivename); |
259 | 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, |
260 | char *new_rev, char *old_rev, char *path); | 261 | char *new_rev, char *old_rev, char *path); |
261 | 262 | ||
262 | extern void cgit_object_link(struct object *obj); | 263 | extern void cgit_object_link(struct object *obj); |
263 | 264 | ||
264 | extern void cgit_print_error(char *msg); | 265 | extern void cgit_print_error(char *msg); |
265 | extern void cgit_print_date(time_t secs, char *format); | 266 | extern void cgit_print_date(time_t secs, char *format); |
266 | 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); |
267 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 268 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
268 | extern void cgit_print_docend(); | 269 | extern void cgit_print_docend(); |
269 | extern void cgit_print_pageheader(char *title, int show_search); | 270 | extern void cgit_print_pageheader(char *title, int show_search); |
270 | extern void cgit_print_snapshot_start(const char *mimetype, | 271 | extern void cgit_print_snapshot_start(const char *mimetype, |
271 | const char *filename, | 272 | const char *filename, |
272 | struct cacheitem *item); | 273 | struct cacheitem *item); |
273 | extern void cgit_print_branches(int maxcount); | 274 | extern void cgit_print_branches(int maxcount); |
274 | extern void cgit_print_tags(int maxcount); | 275 | extern void cgit_print_tags(int maxcount); |
275 | 276 | ||
276 | extern void cgit_print_repolist(struct cacheitem *item); | 277 | extern void cgit_print_repolist(struct cacheitem *item); |
277 | extern void cgit_print_summary(); | 278 | extern void cgit_print_summary(); |
278 | 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, |
279 | char *pattern, char *path, int pager); | 280 | char *pattern, char *path, int pager); |
280 | 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); |
281 | extern void cgit_print_tree(const char *rev, char *path); | 282 | extern void cgit_print_tree(const char *rev, char *path); |
282 | extern void cgit_print_commit(char *hex); | 283 | extern void cgit_print_commit(char *hex); |
283 | extern void cgit_print_refs(); | 284 | extern void cgit_print_refs(); |
284 | extern void cgit_print_tag(char *revname); | 285 | extern void cgit_print_tag(char *revname); |
285 | 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); | ||
286 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 288 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
287 | const char *hex, const char *prefix, | 289 | const char *hex, const char *prefix, |
288 | const char *filename, int snapshot); | 290 | const char *filename, int snapshot); |
289 | 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, |
290 | const char *hex, int snapshots); | 292 | const char *hex, int snapshots); |
291 | extern int cgit_parse_snapshots_mask(const char *str); | 293 | extern int cgit_parse_snapshots_mask(const char *str); |
292 | 294 | ||
293 | #endif /* CGIT_H */ | 295 | #endif /* CGIT_H */ |
@@ -1,169 +1,169 @@ | |||
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"; | 29 | char *cgit_robots = "index, nofollow"; |
30 | char *cgit_clone_prefix = NULL; | 30 | char *cgit_clone_prefix = NULL; |
31 | 31 | ||
32 | int cgit_nocache = 0; | 32 | int cgit_nocache = 0; |
33 | int cgit_snapshots = 0; | 33 | int cgit_snapshots = 0; |
34 | int cgit_enable_index_links = 0; | 34 | int cgit_enable_index_links = 0; |
35 | int cgit_enable_log_filecount = 0; | 35 | int cgit_enable_log_filecount = 0; |
36 | int cgit_enable_log_linecount = 0; | 36 | int cgit_enable_log_linecount = 0; |
37 | int cgit_max_lock_attempts = 5; | 37 | int cgit_max_lock_attempts = 5; |
38 | int cgit_cache_root_ttl = 5; | 38 | int cgit_cache_root_ttl = 5; |
39 | int cgit_cache_repo_ttl = 5; | 39 | int cgit_cache_repo_ttl = 5; |
40 | int cgit_cache_dynamic_ttl = 5; | 40 | int cgit_cache_dynamic_ttl = 5; |
41 | int cgit_cache_static_ttl = -1; | 41 | int cgit_cache_static_ttl = -1; |
42 | int cgit_cache_max_create_time = 5; | 42 | int cgit_cache_max_create_time = 5; |
43 | int cgit_summary_log = 0; | 43 | int cgit_summary_log = 0; |
44 | int cgit_summary_tags = 0; | 44 | int cgit_summary_tags = 0; |
45 | int cgit_summary_branches = 0; | 45 | int cgit_summary_branches = 0; |
46 | int cgit_renamelimit = -1; | 46 | int cgit_renamelimit = -1; |
47 | 47 | ||
48 | int cgit_max_msg_len = 60; | 48 | int cgit_max_msg_len = 60; |
49 | int cgit_max_repodesc_len = 60; | 49 | int cgit_max_repodesc_len = 60; |
50 | int cgit_max_commit_count = 50; | 50 | int cgit_max_commit_count = 50; |
51 | 51 | ||
52 | int cgit_query_has_symref = 0; | 52 | int cgit_query_has_symref = 0; |
53 | int cgit_query_has_sha1 = 0; | 53 | int cgit_query_has_sha1 = 0; |
54 | 54 | ||
55 | char *cgit_querystring = NULL; | 55 | char *cgit_querystring = NULL; |
56 | char *cgit_query_repo = NULL; | 56 | char *cgit_query_repo = NULL; |
57 | char *cgit_query_page = NULL; | 57 | char *cgit_query_page = NULL; |
58 | char *cgit_query_head = NULL; | 58 | char *cgit_query_head = NULL; |
59 | char *cgit_query_search = NULL; | 59 | char *cgit_query_search = NULL; |
60 | char *cgit_query_grep = NULL; | 60 | char *cgit_query_grep = NULL; |
61 | char *cgit_query_sha1 = NULL; | 61 | char *cgit_query_sha1 = NULL; |
62 | char *cgit_query_sha2 = NULL; | 62 | char *cgit_query_sha2 = NULL; |
63 | char *cgit_query_path = NULL; | 63 | char *cgit_query_path = NULL; |
64 | char *cgit_query_name = NULL; | 64 | char *cgit_query_name = NULL; |
65 | int cgit_query_ofs = 0; | 65 | int cgit_query_ofs = 0; |
66 | 66 | ||
67 | int htmlfd = 0; | 67 | int htmlfd = 0; |
68 | 68 | ||
69 | 69 | ||
70 | int cgit_get_cmd_index(const char *cmd) | 70 | int cgit_get_cmd_index(const char *cmd) |
71 | { | 71 | { |
72 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 72 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
73 | "snapshot", "tag", "refs", NULL}; | 73 | "snapshot", "tag", "refs", "patch", NULL}; |
74 | int i; | 74 | int i; |
75 | 75 | ||
76 | for(i = 0; cmds[i]; i++) | 76 | for(i = 0; cmds[i]; i++) |
77 | if (!strcmp(cmd, cmds[i])) | 77 | if (!strcmp(cmd, cmds[i])) |
78 | return i + 1; | 78 | return i + 1; |
79 | return 0; | 79 | return 0; |
80 | } | 80 | } |
81 | 81 | ||
82 | int chk_zero(int result, char *msg) | 82 | int chk_zero(int result, char *msg) |
83 | { | 83 | { |
84 | if (result != 0) | 84 | if (result != 0) |
85 | die("%s: %s", msg, strerror(errno)); | 85 | die("%s: %s", msg, strerror(errno)); |
86 | return result; | 86 | return result; |
87 | } | 87 | } |
88 | 88 | ||
89 | int chk_positive(int result, char *msg) | 89 | int chk_positive(int result, char *msg) |
90 | { | 90 | { |
91 | if (result <= 0) | 91 | if (result <= 0) |
92 | die("%s: %s", msg, strerror(errno)); | 92 | die("%s: %s", msg, strerror(errno)); |
93 | return result; | 93 | return result; |
94 | } | 94 | } |
95 | 95 | ||
96 | int chk_non_negative(int result, char *msg) | 96 | int chk_non_negative(int result, char *msg) |
97 | { | 97 | { |
98 | if (result < 0) | 98 | if (result < 0) |
99 | die("%s: %s",msg, strerror(errno)); | 99 | die("%s: %s",msg, strerror(errno)); |
100 | return result; | 100 | return result; |
101 | } | 101 | } |
102 | 102 | ||
103 | struct repoinfo *add_repo(const char *url) | 103 | struct repoinfo *add_repo(const char *url) |
104 | { | 104 | { |
105 | struct repoinfo *ret; | 105 | struct repoinfo *ret; |
106 | 106 | ||
107 | if (++cgit_repolist.count > cgit_repolist.length) { | 107 | if (++cgit_repolist.count > cgit_repolist.length) { |
108 | if (cgit_repolist.length == 0) | 108 | if (cgit_repolist.length == 0) |
109 | cgit_repolist.length = 8; | 109 | cgit_repolist.length = 8; |
110 | else | 110 | else |
111 | cgit_repolist.length *= 2; | 111 | cgit_repolist.length *= 2; |
112 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 112 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
113 | cgit_repolist.length * | 113 | cgit_repolist.length * |
114 | sizeof(struct repoinfo)); | 114 | sizeof(struct repoinfo)); |
115 | } | 115 | } |
116 | 116 | ||
117 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 117 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
118 | ret->url = trim_end(url, '/'); | 118 | ret->url = trim_end(url, '/'); |
119 | ret->name = ret->url; | 119 | ret->name = ret->url; |
120 | ret->path = NULL; | 120 | ret->path = NULL; |
121 | ret->desc = NULL; | 121 | ret->desc = NULL; |
122 | ret->owner = NULL; | 122 | ret->owner = NULL; |
123 | ret->group = cgit_repo_group; | 123 | ret->group = cgit_repo_group; |
124 | ret->defbranch = "master"; | 124 | ret->defbranch = "master"; |
125 | ret->snapshots = cgit_snapshots; | 125 | ret->snapshots = cgit_snapshots; |
126 | ret->enable_log_filecount = cgit_enable_log_filecount; | 126 | ret->enable_log_filecount = cgit_enable_log_filecount; |
127 | ret->enable_log_linecount = cgit_enable_log_linecount; | 127 | ret->enable_log_linecount = cgit_enable_log_linecount; |
128 | ret->module_link = cgit_module_link; | 128 | ret->module_link = cgit_module_link; |
129 | ret->readme = NULL; | 129 | ret->readme = NULL; |
130 | return ret; | 130 | return ret; |
131 | } | 131 | } |
132 | 132 | ||
133 | struct repoinfo *cgit_get_repoinfo(const char *url) | 133 | struct repoinfo *cgit_get_repoinfo(const char *url) |
134 | { | 134 | { |
135 | int i; | 135 | int i; |
136 | struct repoinfo *repo; | 136 | struct repoinfo *repo; |
137 | 137 | ||
138 | for (i=0; i<cgit_repolist.count; i++) { | 138 | for (i=0; i<cgit_repolist.count; i++) { |
139 | repo = &cgit_repolist.repos[i]; | 139 | repo = &cgit_repolist.repos[i]; |
140 | if (!strcmp(repo->url, url)) | 140 | if (!strcmp(repo->url, url)) |
141 | return repo; | 141 | return repo; |
142 | } | 142 | } |
143 | return NULL; | 143 | return NULL; |
144 | } | 144 | } |
145 | 145 | ||
146 | void cgit_global_config_cb(const char *name, const char *value) | 146 | void cgit_global_config_cb(const char *name, const char *value) |
147 | { | 147 | { |
148 | if (!strcmp(name, "root-title")) | 148 | if (!strcmp(name, "root-title")) |
149 | cgit_root_title = xstrdup(value); | 149 | cgit_root_title = xstrdup(value); |
150 | else if (!strcmp(name, "css")) | 150 | else if (!strcmp(name, "css")) |
151 | cgit_css = xstrdup(value); | 151 | cgit_css = xstrdup(value); |
152 | else if (!strcmp(name, "logo")) | 152 | else if (!strcmp(name, "logo")) |
153 | cgit_logo = xstrdup(value); | 153 | cgit_logo = xstrdup(value); |
154 | else if (!strcmp(name, "index-header")) | 154 | else if (!strcmp(name, "index-header")) |
155 | cgit_index_header = xstrdup(value); | 155 | cgit_index_header = xstrdup(value); |
156 | else if (!strcmp(name, "index-info")) | 156 | else if (!strcmp(name, "index-info")) |
157 | cgit_index_info = xstrdup(value); | 157 | cgit_index_info = xstrdup(value); |
158 | else if (!strcmp(name, "logo-link")) | 158 | else if (!strcmp(name, "logo-link")) |
159 | cgit_logo_link = xstrdup(value); | 159 | cgit_logo_link = xstrdup(value); |
160 | else if (!strcmp(name, "module-link")) | 160 | else if (!strcmp(name, "module-link")) |
161 | cgit_module_link = xstrdup(value); | 161 | cgit_module_link = xstrdup(value); |
162 | else if (!strcmp(name, "virtual-root")) { | 162 | else if (!strcmp(name, "virtual-root")) { |
163 | cgit_virtual_root = trim_end(value, '/'); | 163 | cgit_virtual_root = trim_end(value, '/'); |
164 | if (!cgit_virtual_root && (!strcmp(value, "/"))) | 164 | if (!cgit_virtual_root && (!strcmp(value, "/"))) |
165 | cgit_virtual_root = ""; | 165 | cgit_virtual_root = ""; |
166 | } else if (!strcmp(name, "nocache")) | 166 | } else if (!strcmp(name, "nocache")) |
167 | cgit_nocache = atoi(value); | 167 | cgit_nocache = atoi(value); |
168 | else if (!strcmp(name, "snapshots")) | 168 | else if (!strcmp(name, "snapshots")) |
169 | cgit_snapshots = cgit_parse_snapshots_mask(value); | 169 | cgit_snapshots = cgit_parse_snapshots_mask(value); |
diff --git a/ui-patch.c b/ui-patch.c new file mode 100644 index 0000000..ef79c7c --- a/dev/null +++ b/ui-patch.c | |||
@@ -0,0 +1,105 @@ | |||
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%s", info->subject, info->msg); | ||
100 | html("---\n"); | ||
101 | cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); | ||
102 | html("--\n"); | ||
103 | htmlf("cgit %s\n", CGIT_VERSION); | ||
104 | cgit_free_commitinfo(info); | ||
105 | } | ||
diff --git a/ui-shared.c b/ui-shared.c index ece041c..60aa2e3 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -179,192 +179,198 @@ 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=" PAGE_ENCODING "\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 xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\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); |
@@ -397,166 +403,168 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
397 | struct taginfo *info; | 403 | struct taginfo *info; |
398 | struct object *obj; | 404 | struct object *obj; |
399 | char buf[256], *url; | 405 | char buf[256], *url; |
400 | unsigned char fileid[20]; | 406 | unsigned char fileid[20]; |
401 | int *header = (int *)cb_data; | 407 | int *header = (int *)cb_data; |
402 | 408 | ||
403 | if (prefixcmp(refname, "refs/archives")) | 409 | if (prefixcmp(refname, "refs/archives")) |
404 | return 0; | 410 | return 0; |
405 | strncpy(buf, refname+14, sizeof(buf)); | 411 | strncpy(buf, refname+14, sizeof(buf)); |
406 | obj = parse_object(sha1); | 412 | obj = parse_object(sha1); |
407 | if (!obj) | 413 | if (!obj) |
408 | return 1; | 414 | return 1; |
409 | if (obj->type == OBJ_TAG) { | 415 | if (obj->type == OBJ_TAG) { |
410 | tag = lookup_tag(sha1); | 416 | tag = lookup_tag(sha1); |
411 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 417 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
412 | return 0; | 418 | return 0; |
413 | hashcpy(fileid, tag->tagged->sha1); | 419 | hashcpy(fileid, tag->tagged->sha1); |
414 | } else if (obj->type != OBJ_BLOB) { | 420 | } else if (obj->type != OBJ_BLOB) { |
415 | return 0; | 421 | return 0; |
416 | } else { | 422 | } else { |
417 | hashcpy(fileid, sha1); | 423 | hashcpy(fileid, sha1); |
418 | } | 424 | } |
419 | if (!*header) { | 425 | if (!*header) { |
420 | html("<h1>download</h1>\n"); | 426 | html("<h1>download</h1>\n"); |
421 | *header = 1; | 427 | *header = 1; |
422 | } | 428 | } |
423 | url = cgit_pageurl(cgit_query_repo, "blob", | 429 | url = cgit_pageurl(cgit_query_repo, "blob", |
424 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
425 | buf)); | 431 | buf)); |
426 | html_link_open(url, NULL, "menu"); | 432 | html_link_open(url, NULL, "menu"); |
427 | html_txt(strlpart(buf, 20)); | 433 | html_txt(strlpart(buf, 20)); |
428 | html_link_close(); | 434 | html_link_close(); |
429 | return 0; | 435 | return 0; |
430 | } | 436 | } |
431 | 437 | ||
432 | 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) |
433 | { | 439 | { |
434 | char *url; | 440 | char *url; |
435 | 441 | ||
436 | if (!cgit_virtual_root) { | 442 | if (!cgit_virtual_root) { |
437 | url = fmt("%s/%s", cgit_query_repo, page); | 443 | url = fmt("%s/%s", cgit_query_repo, page); |
438 | if (cgit_query_path) | 444 | if (cgit_query_path) |
439 | url = fmt("%s/%s", url, cgit_query_path); | 445 | url = fmt("%s/%s", url, cgit_query_path); |
440 | html_hidden("url", url); | 446 | html_hidden("url", url); |
441 | } | 447 | } |
442 | 448 | ||
443 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) | 449 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) |
444 | html_hidden("h", cgit_query_head); | 450 | html_hidden("h", cgit_query_head); |
445 | 451 | ||
446 | if (cgit_query_sha1) | 452 | if (cgit_query_sha1) |
447 | html_hidden("id", cgit_query_sha1); | 453 | html_hidden("id", cgit_query_sha1); |
448 | if (cgit_query_sha2) | 454 | if (cgit_query_sha2) |
449 | html_hidden("id2", cgit_query_sha2); | 455 | html_hidden("id2", cgit_query_sha2); |
450 | 456 | ||
451 | if (incl_search) { | 457 | if (incl_search) { |
452 | if (cgit_query_grep) | 458 | if (cgit_query_grep) |
453 | html_hidden("qt", cgit_query_grep); | 459 | html_hidden("qt", cgit_query_grep); |
454 | if (cgit_query_search) | 460 | if (cgit_query_search) |
455 | html_hidden("q", cgit_query_search); | 461 | html_hidden("q", cgit_query_search); |
456 | } | 462 | } |
457 | } | 463 | } |
458 | 464 | ||
459 | void cgit_print_pageheader(char *title, int show_search) | 465 | void cgit_print_pageheader(char *title, int show_search) |
460 | { | 466 | { |
461 | 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"; |
462 | int header = 0; | 468 | int header = 0; |
463 | char *url; | 469 | char *url; |
464 | 470 | ||
465 | html("<table id='layout' summary=''>\n"); | 471 | html("<table id='layout' summary=''>\n"); |
466 | html("<tr><td id='sidebar'>\n"); | 472 | html("<tr><td id='sidebar'>\n"); |
467 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); | 473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); |
468 | html("<tr><td class='sidebar'>\n<a href='"); | 474 | html("<tr><td class='sidebar'>\n<a href='"); |
469 | html_attr(cgit_rooturl()); | 475 | html_attr(cgit_rooturl()); |
470 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
471 | cgit_logo); | 477 | cgit_logo); |
472 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
473 | if (cgit_query_repo) { | 479 | if (cgit_query_repo) { |
474 | html("<h1 class='first'>"); | 480 | html("<h1 class='first'>"); |
475 | html_txt(strrpart(cgit_repo->name, 20)); | 481 | html_txt(strrpart(cgit_repo->name, 20)); |
476 | html("</h1>\n"); | 482 | html("</h1>\n"); |
477 | html_txt(cgit_repo->desc); | 483 | html_txt(cgit_repo->desc); |
478 | if (cgit_repo->owner) { | 484 | if (cgit_repo->owner) { |
479 | html("<h1>owner</h1>\n"); | 485 | html("<h1>owner</h1>\n"); |
480 | html_txt(cgit_repo->owner); | 486 | html_txt(cgit_repo->owner); |
481 | } | 487 | } |
482 | html("<h1>navigate</h1>\n"); | 488 | html("<h1>navigate</h1>\n"); |
483 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, | 489 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, |
484 | NULL, NULL); | 490 | NULL, NULL); |
485 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, | 491 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, |
486 | 0, NULL, NULL); | 492 | 0, NULL, NULL); |
487 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, | 493 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, |
488 | cgit_query_sha1, NULL); | 494 | cgit_query_sha1, NULL); |
489 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, | 495 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, |
490 | cgit_query_sha1); | 496 | cgit_query_sha1); |
491 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, | 497 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, |
492 | 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); | ||
493 | 501 | ||
494 | for_each_ref(print_archive_ref, &header); | 502 | for_each_ref(print_archive_ref, &header); |
495 | 503 | ||
496 | if (cgit_repo->clone_url || cgit_clone_prefix) { | 504 | if (cgit_repo->clone_url || cgit_clone_prefix) { |
497 | html("<h1>clone</h1>\n"); | 505 | html("<h1>clone</h1>\n"); |
498 | if (cgit_repo->clone_url) | 506 | if (cgit_repo->clone_url) |
499 | url = cgit_repo->clone_url; | 507 | url = cgit_repo->clone_url; |
500 | else | 508 | else |
501 | url = fmt("%s%s", cgit_clone_prefix, | 509 | url = fmt("%s%s", cgit_clone_prefix, |
502 | cgit_repo->url); | 510 | cgit_repo->url); |
503 | html("<a class='menu' href='"); | 511 | html("<a class='menu' href='"); |
504 | html_attr(url); | 512 | html_attr(url); |
505 | html("' title='"); | 513 | html("' title='"); |
506 | html_attr(url); | 514 | html_attr(url); |
507 | html("'>\n"); | 515 | html("'>\n"); |
508 | html_txt(strrpart(url, 20)); | 516 | html_txt(strrpart(url, 20)); |
509 | html("</a>\n"); | 517 | html("</a>\n"); |
510 | } | 518 | } |
511 | 519 | ||
512 | html("<h1>branch</h1>\n"); | 520 | html("<h1>branch</h1>\n"); |
513 | html("<form method='get' action=''>\n"); | 521 | html("<form method='get' action=''>\n"); |
514 | add_hidden_formfields(0, 1, cgit_query_page); | 522 | add_hidden_formfields(0, 1, cgit_query_page); |
515 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); | 523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); |
516 | html("<select name='h' onchange='this.form.submit();'>\n"); | 524 | html("<select name='h' onchange='this.form.submit();'>\n"); |
517 | for_each_branch_ref(print_branch_option, cgit_query_head); | 525 | for_each_branch_ref(print_branch_option, cgit_query_head); |
518 | html("</select>\n"); | 526 | html("</select>\n"); |
519 | // html("</td><td>"); | 527 | // html("</td><td>"); |
520 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); | 528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); |
521 | // html("</td></tr></table>"); | 529 | // html("</td></tr></table>"); |
522 | html("</form>\n"); | 530 | html("</form>\n"); |
523 | 531 | ||
524 | html("<h1>search</h1>\n"); | 532 | html("<h1>search</h1>\n"); |
525 | html("<form method='get' action='"); | 533 | html("<form method='get' action='"); |
526 | if (cgit_virtual_root) | 534 | if (cgit_virtual_root) |
527 | html_attr(cgit_fileurl(cgit_query_repo, "log", | 535 | html_attr(cgit_fileurl(cgit_query_repo, "log", |
528 | cgit_query_path, NULL)); | 536 | cgit_query_path, NULL)); |
529 | html("'>\n"); | 537 | html("'>\n"); |
530 | add_hidden_formfields(1, 0, "log"); | 538 | add_hidden_formfields(1, 0, "log"); |
531 | html("<select name='qt'>\n"); | 539 | html("<select name='qt'>\n"); |
532 | html_option("grep", "log msg", cgit_query_grep); | 540 | html_option("grep", "log msg", cgit_query_grep); |
533 | html_option("author", "author", cgit_query_grep); | 541 | html_option("author", "author", cgit_query_grep); |
534 | html_option("committer", "committer", cgit_query_grep); | 542 | html_option("committer", "committer", cgit_query_grep); |
535 | html("</select>\n"); | 543 | html("</select>\n"); |
536 | html("<input class='txt' type='text' name='q' value='"); | 544 | html("<input class='txt' type='text' name='q' value='"); |
537 | html_attr(cgit_query_search); | 545 | html_attr(cgit_query_search); |
538 | html("'/>\n"); | 546 | html("'/>\n"); |
539 | html("</form>\n"); | 547 | html("</form>\n"); |
540 | } else { | 548 | } else { |
541 | if (!cgit_index_info || html_include(cgit_index_info)) | 549 | if (!cgit_index_info || html_include(cgit_index_info)) |
542 | html(default_info); | 550 | html(default_info); |
543 | } | 551 | } |
544 | 552 | ||
545 | html("</td></tr></table></td>\n"); | 553 | html("</td></tr></table></td>\n"); |
546 | 554 | ||
547 | html("<td id='content'>\n"); | 555 | html("<td id='content'>\n"); |
548 | } | 556 | } |
549 | 557 | ||
550 | 558 | ||
551 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 559 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
552 | struct cacheitem *item) | 560 | struct cacheitem *item) |
553 | { | 561 | { |
554 | htmlf("Content-Type: %s\n", mimetype); | 562 | htmlf("Content-Type: %s\n", mimetype); |
555 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 563 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
556 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 564 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
557 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 565 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
558 | ttl_seconds(item->ttl))); | 566 | ttl_seconds(item->ttl))); |
559 | html("\n"); | 567 | html("\n"); |
560 | } | 568 | } |
561 | 569 | ||
562 | /* vim:set sw=8: */ | 570 | /* vim:set sw=8: */ |