-rw-r--r-- | Makefile | 97 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | cache.h | 1 | ||||
-rw-r--r-- | cgit.c | 99 | ||||
-rw-r--r-- | cgit.css | 184 | ||||
-rw-r--r-- | cgit.h | 36 | ||||
-rw-r--r-- | cgit.png | bin | 1840 -> 1488 bytes | |||
-rw-r--r-- | cgitrc.5.txt | 115 | ||||
-rw-r--r-- | cmd.c | 51 | ||||
-rw-r--r-- | cmd.h | 3 | ||||
-rwxr-xr-x | filters/commit-links.sh | 16 | ||||
-rwxr-xr-x | filters/syntax-highlighting.sh | 29 | ||||
m--------- | git | 0 | ||||
-rw-r--r-- | html.c | 84 | ||||
-rw-r--r-- | html.h | 21 | ||||
-rw-r--r-- | scan-tree.c | 141 | ||||
-rw-r--r-- | scan-tree.h | 3 | ||||
-rw-r--r-- | shared.c | 93 | ||||
-rw-r--r-- | ui-atom.c | 14 | ||||
-rw-r--r-- | ui-blob.c | 37 | ||||
-rw-r--r-- | ui-blob.h | 1 | ||||
-rw-r--r-- | ui-commit.c | 46 | ||||
-rw-r--r-- | ui-commit.h | 2 | ||||
-rw-r--r-- | ui-diff.c | 96 | ||||
-rw-r--r-- | ui-diff.h | 6 | ||||
-rw-r--r-- | ui-log.c | 282 | ||||
-rw-r--r-- | ui-log.h | 3 | ||||
-rw-r--r-- | ui-patch.c | 8 | ||||
-rw-r--r-- | ui-patch.h | 2 | ||||
-rw-r--r-- | ui-plain.c | 68 | ||||
-rw-r--r-- | ui-refs.c | 4 | ||||
-rw-r--r-- | ui-repolist.c | 6 | ||||
-rw-r--r-- | ui-shared.c | 288 | ||||
-rw-r--r-- | ui-shared.h | 71 | ||||
-rw-r--r-- | ui-snapshot.c | 14 | ||||
-rw-r--r-- | ui-ssdiff.c | 383 | ||||
-rw-r--r-- | ui-ssdiff.h | 13 | ||||
-rw-r--r-- | ui-stats.c | 20 | ||||
-rw-r--r-- | ui-summary.c | 40 | ||||
-rw-r--r-- | ui-tag.c | 24 | ||||
-rw-r--r-- | ui-tree.c | 27 | ||||
-rw-r--r-- | vector.c | 38 | ||||
-rw-r--r-- | vector.h | 17 |
43 files changed, 2097 insertions, 388 deletions
@@ -1,171 +1,244 @@ | |||
1 | CGIT_VERSION = v0.8.3.5 | 1 | CGIT_VERSION = v0.8.3.5 |
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_DATA_PATH = $(CGIT_SCRIPT_PATH) | 4 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) |
5 | CGIT_CONFIG = /etc/cgitrc | 5 | CGIT_CONFIG = /etc/cgitrc |
6 | CACHE_ROOT = /var/cache/cgit | 6 | CACHE_ROOT = /var/cache/cgit |
7 | prefix = /usr | ||
8 | libdir = $(prefix)/lib | ||
9 | filterdir = $(libdir)/cgit/filters | ||
10 | docdir = $(prefix)/share/doc/cgit | ||
11 | htmldir = $(docdir) | ||
12 | pdfdir = $(docdir) | ||
13 | mandir = $(prefix)/share/man | ||
7 | SHA1_HEADER = <openssl/sha.h> | 14 | SHA1_HEADER = <openssl/sha.h> |
8 | GIT_VER = 1.7.3 | 15 | GIT_VER = 1.7.4 |
9 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 16 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
10 | INSTALL = install | 17 | INSTALL = install |
18 | MAN5_TXT = $(wildcard *.5.txt) | ||
19 | MAN_TXT = $(MAN5_TXT) | ||
20 | DOC_MAN5 = $(patsubst %.txt,%,$(MAN5_TXT)) | ||
21 | DOC_HTML = $(patsubst %.txt,%.html,$(MAN_TXT)) | ||
22 | DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) | ||
11 | 23 | ||
12 | # Define NO_STRCASESTR if you don't have strcasestr. | 24 | # Define NO_STRCASESTR if you don't have strcasestr. |
13 | # | 25 | # |
26 | # Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 | ||
27 | # implementation (slower). | ||
28 | # | ||
14 | # Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). | 29 | # Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). |
15 | # | 30 | # |
31 | # Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.) | ||
32 | # do not support the 'size specifiers' introduced by C99, namely ll, hh, | ||
33 | # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t). | ||
34 | # some C compilers supported these specifiers prior to C99 as an extension. | ||
35 | # | ||
16 | 36 | ||
17 | #-include config.mak | 37 | #-include config.mak |
18 | 38 | ||
19 | # | 39 | # |
20 | # Platform specific tweaks | 40 | # Platform specific tweaks |
21 | # | 41 | # |
22 | 42 | ||
23 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | 43 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
24 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') | 44 | uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') |
25 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') | 45 | uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') |
26 | 46 | ||
27 | ifeq ($(uname_O),Cygwin) | 47 | ifeq ($(uname_O),Cygwin) |
28 | NO_STRCASESTR = YesPlease | 48 | NO_STRCASESTR = YesPlease |
29 | NEEDS_LIBICONV = YesPlease | 49 | NEEDS_LIBICONV = YesPlease |
30 | endif | 50 | endif |
31 | 51 | ||
32 | # | 52 | # |
33 | # Let the user override the above settings. | 53 | # Let the user override the above settings. |
34 | # | 54 | # |
35 | -include cgit.conf | 55 | -include cgit.conf |
36 | 56 | ||
37 | # | 57 | # |
38 | # Define a way to invoke make in subdirs quietly, shamelessly ripped | 58 | # Define a way to invoke make in subdirs quietly, shamelessly ripped |
39 | # from git.git | 59 | # from git.git |
40 | # | 60 | # |
41 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | 61 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir |
42 | QUIET_SUBDIR1 = | 62 | QUIET_SUBDIR1 = |
43 | 63 | ||
44 | ifneq ($(findstring $(MAKEFLAGS),w),w) | 64 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
45 | PRINT_DIR = --no-print-directory | 65 | PRINT_DIR = --no-print-directory |
46 | else # "make -w" | 66 | else # "make -w" |
47 | NO_SUBDIR = : | 67 | NO_SUBDIR = : |
48 | endif | 68 | endif |
49 | 69 | ||
50 | ifndef V | 70 | ifndef V |
51 | QUIET_CC = @echo ' ' CC $@; | 71 | QUIET_CC = @echo ' ' CC $@; |
52 | QUIET_MM = @echo ' ' MM $@; | 72 | QUIET_MM = @echo ' ' MM $@; |
53 | QUIET_SUBDIR0 = +@subdir= | 73 | QUIET_SUBDIR0 = +@subdir= |
54 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ | 74 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ |
55 | $(MAKE) $(PRINT_DIR) -C $$subdir | 75 | $(MAKE) $(PRINT_DIR) -C $$subdir |
56 | endif | 76 | endif |
57 | 77 | ||
58 | # | 78 | # |
59 | # Define a pattern rule for automatic dependency building | 79 | # Define a pattern rule for automatic dependency building |
60 | # | 80 | # |
61 | %.d: %.c | 81 | %.d: %.c |
62 | $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ | 82 | $(QUIET_MM)$(CC) $(CFLAGS) -MM -MP $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ |
63 | 83 | ||
64 | # | 84 | # |
65 | # Define a pattern rule for silent object building | 85 | # Define a pattern rule for silent object building |
66 | # | 86 | # |
67 | %.o: %.c | 87 | %.o: %.c |
68 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< | 88 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< |
69 | 89 | ||
70 | 90 | ||
71 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto -lpthread | 91 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread |
72 | OBJECTS = | 92 | OBJECTS = |
73 | OBJECTS += cache.o | 93 | OBJECTS += cache.o |
74 | OBJECTS += cgit.o | 94 | OBJECTS += cgit.o |
75 | OBJECTS += cmd.o | 95 | OBJECTS += cmd.o |
76 | OBJECTS += configfile.o | 96 | OBJECTS += configfile.o |
77 | OBJECTS += html.o | 97 | OBJECTS += html.o |
78 | OBJECTS += parsing.o | 98 | OBJECTS += parsing.o |
79 | OBJECTS += scan-tree.o | 99 | OBJECTS += scan-tree.o |
80 | OBJECTS += shared.o | 100 | OBJECTS += shared.o |
81 | OBJECTS += ui-atom.o | 101 | OBJECTS += ui-atom.o |
82 | OBJECTS += ui-blob.o | 102 | OBJECTS += ui-blob.o |
83 | OBJECTS += ui-clone.o | 103 | OBJECTS += ui-clone.o |
84 | OBJECTS += ui-commit.o | 104 | OBJECTS += ui-commit.o |
85 | OBJECTS += ui-diff.o | 105 | OBJECTS += ui-diff.o |
86 | OBJECTS += ui-log.o | 106 | OBJECTS += ui-log.o |
87 | OBJECTS += ui-patch.o | 107 | OBJECTS += ui-patch.o |
88 | OBJECTS += ui-plain.o | 108 | OBJECTS += ui-plain.o |
89 | OBJECTS += ui-refs.o | 109 | OBJECTS += ui-refs.o |
90 | OBJECTS += ui-repolist.o | 110 | OBJECTS += ui-repolist.o |
91 | OBJECTS += ui-shared.o | 111 | OBJECTS += ui-shared.o |
92 | OBJECTS += ui-snapshot.o | 112 | OBJECTS += ui-snapshot.o |
113 | OBJECTS += ui-ssdiff.o | ||
93 | OBJECTS += ui-stats.o | 114 | OBJECTS += ui-stats.o |
94 | OBJECTS += ui-summary.o | 115 | OBJECTS += ui-summary.o |
95 | OBJECTS += ui-tag.o | 116 | OBJECTS += ui-tag.o |
96 | OBJECTS += ui-tree.o | 117 | OBJECTS += ui-tree.o |
118 | OBJECTS += vector.o | ||
97 | 119 | ||
98 | ifdef NEEDS_LIBICONV | 120 | ifdef NEEDS_LIBICONV |
99 | EXTLIBS += -liconv | 121 | EXTLIBS += -liconv |
100 | endif | 122 | endif |
101 | 123 | ||
102 | 124 | ||
103 | .PHONY: all libgit test install uninstall clean force-version get-git \ | 125 | .PHONY: all libgit test install uninstall clean force-version get-git \ |
104 | doc man-doc html-doc clean-doc | 126 | doc clean-doc install-doc install-man install-html install-pdf \ |
127 | uninstall-doc uninstall-man uninstall-html uninstall-pdf | ||
105 | 128 | ||
106 | all: cgit | 129 | all: cgit |
107 | 130 | ||
108 | VERSION: force-version | 131 | VERSION: force-version |
109 | @./gen-version.sh "$(CGIT_VERSION)" | 132 | @./gen-version.sh "$(CGIT_VERSION)" |
110 | -include VERSION | 133 | -include VERSION |
111 | 134 | ||
112 | 135 | ||
113 | CFLAGS += -g -Wall -Igit | 136 | CFLAGS += -g -Wall -Igit |
114 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 137 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
115 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 138 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
116 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 139 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
117 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 140 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
118 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 141 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
119 | 142 | ||
143 | GIT_OPTIONS = prefix=/usr | ||
144 | |||
120 | ifdef NO_ICONV | 145 | ifdef NO_ICONV |
121 | CFLAGS += -DNO_ICONV | 146 | CFLAGS += -DNO_ICONV |
122 | endif | 147 | endif |
123 | ifdef NO_STRCASESTR | 148 | ifdef NO_STRCASESTR |
124 | CFLAGS += -DNO_STRCASESTR | 149 | CFLAGS += -DNO_STRCASESTR |
125 | endif | 150 | endif |
151 | ifdef NO_C99_FORMAT | ||
152 | CFLAGS += -DNO_C99_FORMAT | ||
153 | endif | ||
154 | ifdef NO_OPENSSL | ||
155 | CFLAGS += -DNO_OPENSSL | ||
156 | GIT_OPTIONS += NO_OPENSSL=1 | ||
157 | else | ||
158 | EXTLIBS += -lcrypto | ||
159 | endif | ||
126 | 160 | ||
127 | cgit: $(OBJECTS) libgit | 161 | cgit: $(OBJECTS) libgit |
128 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) | 162 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
129 | 163 | ||
130 | cgit.o: VERSION | 164 | cgit.o: VERSION |
131 | 165 | ||
166 | ifneq "$(MAKECMDGOALS)" "clean" | ||
132 | -include $(OBJECTS:.o=.d) | 167 | -include $(OBJECTS:.o=.d) |
168 | endif | ||
133 | 169 | ||
134 | libgit: | 170 | libgit: |
135 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a | 171 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a |
136 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a | 172 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a |
137 | 173 | ||
138 | test: all | 174 | test: all |
139 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all | 175 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
140 | 176 | ||
141 | install: all | 177 | install: all |
142 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) | 178 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) |
143 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 179 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
144 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) | 180 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) |
145 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css | 181 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css |
146 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png | 182 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png |
183 | $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) | ||
184 | $(INSTALL) -m 0755 filters/* $(DESTDIR)$(filterdir) | ||
185 | |||
186 | install-doc: install-man install-html install-pdf | ||
187 | |||
188 | install-man: doc-man | ||
189 | $(INSTALL) -m 0755 -d $(DESTDIR)$(mandir)/man5 | ||
190 | $(INSTALL) -m 0644 $(DOC_MAN5) $(DESTDIR)$(mandir)/man5 | ||
191 | |||
192 | install-html: doc-html | ||
193 | $(INSTALL) -m 0755 -d $(DESTDIR)$(htmldir) | ||
194 | $(INSTALL) -m 0644 $(DOC_HTML) $(DESTDIR)$(htmldir) | ||
195 | |||
196 | install-pdf: doc-pdf | ||
197 | $(INSTALL) -m 0755 -d $(DESTDIR)$(pdfdir) | ||
198 | $(INSTALL) -m 0644 $(DOC_PDF) $(DESTDIR)$(pdfdir) | ||
147 | 199 | ||
148 | uninstall: | 200 | uninstall: |
149 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 201 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
150 | rm -f $(CGIT_DATA_PATH)/cgit.css | 202 | rm -f $(CGIT_DATA_PATH)/cgit.css |
151 | rm -f $(CGIT_DATA_PATH)/cgit.png | 203 | rm -f $(CGIT_DATA_PATH)/cgit.png |
152 | 204 | ||
153 | doc: man-doc html-doc pdf-doc | 205 | uninstall-doc: uninstall-man uninstall-html uninstall-pdf |
206 | |||
207 | uninstall-man: | ||
208 | @for i in $(DOC_MAN5); do \ | ||
209 | rm -fv $(DESTDIR)$(mandir)/man5/$$i; \ | ||
210 | done | ||
211 | |||
212 | uninstall-html: | ||
213 | @for i in $(DOC_HTML); do \ | ||
214 | rm -fv $(DESTDIR)$(htmldir)/$$i; \ | ||
215 | done | ||
216 | |||
217 | uninstall-pdf: | ||
218 | @for i in $(DOC_PDF); do \ | ||
219 | rm -fv $(DESTDIR)$(pdfdir)/$$i; \ | ||
220 | done | ||
221 | |||
222 | doc: doc-man doc-html doc-pdf | ||
223 | doc-man: doc-man5 | ||
224 | doc-man5: $(DOC_MAN5) | ||
225 | doc-html: $(DOC_HTML) | ||
226 | doc-pdf: $(DOC_PDF) | ||
154 | 227 | ||
155 | man-doc: cgitrc.5.txt | 228 | %.5 : %.5.txt |
156 | a2x -f manpage cgitrc.5.txt | 229 | a2x -f manpage $< |
157 | 230 | ||
158 | html-doc: cgitrc.5.txt | 231 | $(DOC_HTML): %.html : %.txt |
159 | a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt | 232 | a2x -f xhtml --stylesheet=cgit-doc.css $< |
160 | 233 | ||
161 | pdf-doc: cgitrc.5.txt | 234 | $(DOC_PDF): %.pdf : %.txt |
162 | a2x -f pdf cgitrc.5.txt | 235 | a2x -f pdf cgitrc.5.txt |
163 | 236 | ||
164 | clean: clean-doc | 237 | clean: clean-doc |
165 | rm -f cgit VERSION *.o *.d | 238 | rm -f cgit VERSION *.o *.d |
166 | 239 | ||
167 | clean-doc: | 240 | clean-doc: |
168 | rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo | 241 | rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo |
169 | 242 | ||
170 | get-git: | 243 | get-git: |
171 | curl $(GIT_URL) | tar -xjf - && rm -rf git && mv git-$(GIT_VER) git | 244 | curl $(GIT_URL) | tar -xjf - && rm -rf git && mv git-$(GIT_VER) git |
@@ -4,97 +4,97 @@ | |||
4 | 4 | ||
5 | This is an attempt to create a fast web interface for the git scm, using a | 5 | This is an attempt to create a fast web interface for the git scm, using a |
6 | builtin cache to decrease server io-pressure. | 6 | builtin cache to decrease server io-pressure. |
7 | 7 | ||
8 | 8 | ||
9 | Installation | 9 | Installation |
10 | 10 | ||
11 | Building cgit involves building a proper version of git. How to do this | 11 | Building cgit involves building a proper version of git. How to do this |
12 | depends on how you obtained the cgit sources: | 12 | depends on how you obtained the cgit sources: |
13 | 13 | ||
14 | a) If you're working in a cloned cgit repository, you first need to | 14 | a) If you're working in a cloned cgit repository, you first need to |
15 | initialize and update the git submodule: | 15 | initialize and update the git submodule: |
16 | 16 | ||
17 | $ git submodule init # register the git submodule in .git/config | 17 | $ git submodule init # register the git submodule in .git/config |
18 | $ $EDITOR .git/config # if you want to specify a different url for git | 18 | $ $EDITOR .git/config # if you want to specify a different url for git |
19 | $ git submodule update # clone/fetch and checkout correct git version | 19 | $ git submodule update # clone/fetch and checkout correct git version |
20 | 20 | ||
21 | b) If you're building from a cgit tarball, you can download a proper git | 21 | b) If you're building from a cgit tarball, you can download a proper git |
22 | version like this: | 22 | version like this: |
23 | 23 | ||
24 | $ make get-git | 24 | $ make get-git |
25 | 25 | ||
26 | 26 | ||
27 | When either a) or b) has been performed, you can build and install cgit like | 27 | When either a) or b) has been performed, you can build and install cgit like |
28 | this: | 28 | this: |
29 | 29 | ||
30 | $ make | 30 | $ make |
31 | $ sudo make install | 31 | $ sudo make install |
32 | 32 | ||
33 | This will install cgit.cgi and cgit.css into "/var/www/htdocs/cgit". You can | 33 | This will install cgit.cgi and cgit.css into "/var/www/htdocs/cgit". You can |
34 | configure this location (and a few other things) by providing a "cgit.conf" | 34 | configure this location (and a few other things) by providing a "cgit.conf" |
35 | file (see the Makefile for details). | 35 | file (see the Makefile for details). |
36 | 36 | ||
37 | 37 | ||
38 | Dependencies: | 38 | Dependencies: |
39 | -git 1.5.3 | 39 | -git 1.5.3 |
40 | -zip lib | 40 | -zip lib |
41 | -crypto lib | 41 | -crypto lib |
42 | -openssl lib | 42 | -openssl lib |
43 | 43 | ||
44 | 44 | ||
45 | Apache configuration | 45 | Apache configuration |
46 | 46 | ||
47 | A new Directory-section must probably be added for cgit, possibly something | 47 | A new Directory-section must probably be added for cgit, possibly something |
48 | like this: | 48 | like this: |
49 | 49 | ||
50 | <Directory "/var/www/htdocs/cgit/"> | 50 | <Directory "/var/www/htdocs/cgit/"> |
51 | AllowOverride None | 51 | AllowOverride None |
52 | Options ExecCGI | 52 | Options +ExecCGI |
53 | Order allow,deny | 53 | Order allow,deny |
54 | Allow from all | 54 | Allow from all |
55 | </Directory> | 55 | </Directory> |
56 | 56 | ||
57 | 57 | ||
58 | Runtime configuration | 58 | Runtime configuration |
59 | 59 | ||
60 | The file /etc/cgitrc is read by cgit before handling a request. In addition | 60 | The file /etc/cgitrc is read by cgit before handling a request. In addition |
61 | to runtime parameters, this file also contains a list of the repositories | 61 | to runtime parameters, this file also contains a list of the repositories |
62 | displayed by cgit. | 62 | displayed by cgit. |
63 | 63 | ||
64 | A template cgitrc is shipped with the sources, and all parameters and default | 64 | A template cgitrc is shipped with the sources, and all parameters and default |
65 | values are documented in this file. | 65 | values are documented in this file. |
66 | 66 | ||
67 | 67 | ||
68 | The cache | 68 | The cache |
69 | 69 | ||
70 | When cgit is invoked it looks for a cachefile matching the request and | 70 | When cgit is invoked it looks for a cachefile matching the request and |
71 | returns it to the client. If no such cachefile exist (or if it has expired), | 71 | returns it to the client. If no such cachefile exist (or if it has expired), |
72 | the content for the request is written into the proper cachefile before the | 72 | the content for the request is written into the proper cachefile before the |
73 | file is returned. | 73 | file is returned. |
74 | 74 | ||
75 | If the cachefile has expired but cgit is unable to obtain a lock for it, the | 75 | If the cachefile has expired but cgit is unable to obtain a lock for it, the |
76 | stale cachefile is returned to the client. This is done to favour page | 76 | stale cachefile is returned to the client. This is done to favour page |
77 | throughput over page freshness. | 77 | throughput over page freshness. |
78 | 78 | ||
79 | The generated content contains the complete response to the client, including | 79 | The generated content contains the complete response to the client, including |
80 | the http-headers "Modified" and "Expires". | 80 | the http-headers "Modified" and "Expires". |
81 | 81 | ||
82 | 82 | ||
83 | The missing features | 83 | The missing features |
84 | 84 | ||
85 | * Submodule links in the directory listing page have a fixed format per | 85 | * Submodule links in the directory listing page have a fixed format per |
86 | repository. This should probably be extended to a generic map between | 86 | repository. This should probably be extended to a generic map between |
87 | submodule path and url. | 87 | submodule path and url. |
88 | 88 | ||
89 | * Branch- and tag-lists in the summary page can get very long, they should | 89 | * Branch- and tag-lists in the summary page can get very long, they should |
90 | probably only show something like the ten "latest modified" branches and | 90 | probably only show something like the ten "latest modified" branches and |
91 | a similar number of "most recent" tags. | 91 | a similar number of "most recent" tags. |
92 | 92 | ||
93 | * There should be a new page for browsing refs/heads and refs/tags, with links | 93 | * There should be a new page for browsing refs/heads and refs/tags, with links |
94 | from the summary page whenever the branch/tag lists overflow. | 94 | from the summary page whenever the branch/tag lists overflow. |
95 | 95 | ||
96 | * The log-page should have more/better search options (author, committer, | 96 | * The log-page should have more/better search options (author, committer, |
97 | pickaxe, paths) and possibly support arbitrary revision specifiers. | 97 | pickaxe, paths) and possibly support arbitrary revision specifiers. |
98 | 98 | ||
99 | * A set of test-scripts is required before cgit-1.0 can be released. | 99 | * A set of test-scripts is required before cgit-1.0 can be released. |
100 | 100 | ||
@@ -1,37 +1,38 @@ | |||
1 | /* | 1 | /* |
2 | * Since git has it's own cache.h which we include, | 2 | * Since git has it's own cache.h which we include, |
3 | * lets test on CGIT_CACHE_H to avoid confusion | 3 | * lets test on CGIT_CACHE_H to avoid confusion |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef CGIT_CACHE_H | 6 | #ifndef CGIT_CACHE_H |
7 | #define CGIT_CACHE_H | 7 | #define CGIT_CACHE_H |
8 | 8 | ||
9 | typedef void (*cache_fill_fn)(void *cbdata); | 9 | typedef void (*cache_fill_fn)(void *cbdata); |
10 | 10 | ||
11 | 11 | ||
12 | /* Print cached content to stdout, generate the content if necessary. | 12 | /* Print cached content to stdout, generate the content if necessary. |
13 | * | 13 | * |
14 | * Parameters | 14 | * Parameters |
15 | * size max number of cache files | 15 | * size max number of cache files |
16 | * path directory used to store cache files | 16 | * path directory used to store cache files |
17 | * key the key used to lookup cache files | 17 | * key the key used to lookup cache files |
18 | * ttl max cache time in seconds for this key | 18 | * ttl max cache time in seconds for this key |
19 | * fn content generator function for this key | 19 | * fn content generator function for this key |
20 | * cbdata user-supplied data to the content generator function | 20 | * cbdata user-supplied data to the content generator function |
21 | * | 21 | * |
22 | * Return value | 22 | * Return value |
23 | * 0 indicates success, everyting else is an error | 23 | * 0 indicates success, everyting else is an error |
24 | */ | 24 | */ |
25 | extern int cache_process(int size, const char *path, const char *key, int ttl, | 25 | extern int cache_process(int size, const char *path, const char *key, int ttl, |
26 | cache_fill_fn fn, void *cbdata); | 26 | cache_fill_fn fn, void *cbdata); |
27 | 27 | ||
28 | 28 | ||
29 | /* List info about all cache entries on stdout */ | 29 | /* List info about all cache entries on stdout */ |
30 | extern int cache_ls(const char *path); | 30 | extern int cache_ls(const char *path); |
31 | 31 | ||
32 | /* Print a message to stdout */ | 32 | /* Print a message to stdout */ |
33 | __attribute__((format (printf,1,2))) | ||
33 | extern void cache_log(const char *format, ...); | 34 | extern void cache_log(const char *format, ...); |
34 | 35 | ||
35 | extern unsigned long hash_str(const char *str); | 36 | extern unsigned long hash_str(const char *str); |
36 | 37 | ||
37 | #endif /* CGIT_CACHE_H */ | 38 | #endif /* CGIT_CACHE_H */ |
@@ -1,329 +1,383 @@ | |||
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 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
4 | * | 5 | * |
5 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
7 | */ | 8 | */ |
8 | 9 | ||
9 | #include "cgit.h" | 10 | #include "cgit.h" |
10 | #include "cache.h" | 11 | #include "cache.h" |
11 | #include "cmd.h" | 12 | #include "cmd.h" |
12 | #include "configfile.h" | 13 | #include "configfile.h" |
13 | #include "html.h" | 14 | #include "html.h" |
14 | #include "ui-shared.h" | 15 | #include "ui-shared.h" |
15 | #include "ui-stats.h" | 16 | #include "ui-stats.h" |
16 | #include "scan-tree.h" | 17 | #include "scan-tree.h" |
17 | 18 | ||
18 | const char *cgit_version = CGIT_VERSION; | 19 | const char *cgit_version = CGIT_VERSION; |
19 | 20 | ||
20 | void add_mimetype(const char *name, const char *value) | 21 | void add_mimetype(const char *name, const char *value) |
21 | { | 22 | { |
22 | struct string_list_item *item; | 23 | struct string_list_item *item; |
23 | 24 | ||
24 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); | 25 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); |
25 | item->util = xstrdup(value); | 26 | item->util = xstrdup(value); |
26 | } | 27 | } |
27 | 28 | ||
28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 29 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
29 | { | 30 | { |
30 | struct cgit_filter *f; | 31 | struct cgit_filter *f; |
31 | 32 | ||
32 | if (!cmd || !cmd[0]) | 33 | if (!cmd || !cmd[0]) |
33 | return NULL; | 34 | return NULL; |
34 | 35 | ||
35 | f = xmalloc(sizeof(struct cgit_filter)); | 36 | f = xmalloc(sizeof(struct cgit_filter)); |
36 | f->cmd = xstrdup(cmd); | 37 | f->cmd = xstrdup(cmd); |
37 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); | 38 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); |
38 | f->argv[0] = f->cmd; | 39 | f->argv[0] = f->cmd; |
39 | f->argv[1] = NULL; | 40 | f->argv[1] = NULL; |
40 | return f; | 41 | return f; |
41 | } | 42 | } |
42 | 43 | ||
43 | static void process_cached_repolist(const char *path); | 44 | static void process_cached_repolist(const char *path); |
44 | 45 | ||
45 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) | 46 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
46 | { | 47 | { |
47 | if (!strcmp(name, "name")) | 48 | if (!strcmp(name, "name")) |
48 | repo->name = xstrdup(value); | 49 | repo->name = xstrdup(value); |
49 | else if (!strcmp(name, "clone-url")) | 50 | else if (!strcmp(name, "clone-url")) |
50 | repo->clone_url = xstrdup(value); | 51 | repo->clone_url = xstrdup(value); |
51 | else if (!strcmp(name, "desc")) | 52 | else if (!strcmp(name, "desc")) |
52 | repo->desc = xstrdup(value); | 53 | repo->desc = xstrdup(value); |
53 | else if (!strcmp(name, "owner")) | 54 | else if (!strcmp(name, "owner")) |
54 | repo->owner = xstrdup(value); | 55 | repo->owner = xstrdup(value); |
55 | else if (!strcmp(name, "defbranch")) | 56 | else if (!strcmp(name, "defbranch")) |
56 | repo->defbranch = xstrdup(value); | 57 | repo->defbranch = xstrdup(value); |
57 | else if (!strcmp(name, "snapshots")) | 58 | else if (!strcmp(name, "snapshots")) |
58 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); | 59 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); |
60 | else if (!strcmp(name, "enable-commit-graph")) | ||
61 | repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value); | ||
59 | else if (!strcmp(name, "enable-log-filecount")) | 62 | else if (!strcmp(name, "enable-log-filecount")) |
60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 63 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
61 | else if (!strcmp(name, "enable-log-linecount")) | 64 | else if (!strcmp(name, "enable-log-linecount")) |
62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 65 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
66 | else if (!strcmp(name, "enable-remote-branches")) | ||
67 | repo->enable_remote_branches = atoi(value); | ||
68 | else if (!strcmp(name, "enable-subject-links")) | ||
69 | repo->enable_subject_links = atoi(value); | ||
63 | else if (!strcmp(name, "max-stats")) | 70 | else if (!strcmp(name, "max-stats")) |
64 | repo->max_stats = cgit_find_stats_period(value, NULL); | 71 | repo->max_stats = cgit_find_stats_period(value, NULL); |
65 | else if (!strcmp(name, "module-link")) | 72 | else if (!strcmp(name, "module-link")) |
66 | repo->module_link= xstrdup(value); | 73 | repo->module_link= xstrdup(value); |
67 | else if (!strcmp(name, "section")) | 74 | else if (!strcmp(name, "section")) |
68 | repo->section = xstrdup(value); | 75 | repo->section = xstrdup(value); |
69 | else if (!strcmp(name, "readme") && value != NULL) { | 76 | else if (!strcmp(name, "readme") && value != NULL) |
70 | if (*value == '/') | ||
71 | repo->readme = xstrdup(value); | 77 | repo->readme = xstrdup(value); |
72 | else | 78 | else if (!strcmp(name, "logo") && value != NULL) |
73 | repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); | 79 | repo->logo = xstrdup(value); |
74 | } else if (ctx.cfg.enable_filter_overrides) { | 80 | else if (!strcmp(name, "logo-link") && value != NULL) |
81 | repo->logo_link = xstrdup(value); | ||
82 | else if (ctx.cfg.enable_filter_overrides) { | ||
75 | if (!strcmp(name, "about-filter")) | 83 | if (!strcmp(name, "about-filter")) |
76 | repo->about_filter = new_filter(value, 0); | 84 | repo->about_filter = new_filter(value, 0); |
77 | else if (!strcmp(name, "commit-filter")) | 85 | else if (!strcmp(name, "commit-filter")) |
78 | repo->commit_filter = new_filter(value, 0); | 86 | repo->commit_filter = new_filter(value, 0); |
79 | else if (!strcmp(name, "source-filter")) | 87 | else if (!strcmp(name, "source-filter")) |
80 | repo->source_filter = new_filter(value, 1); | 88 | repo->source_filter = new_filter(value, 1); |
81 | } | 89 | } |
82 | } | 90 | } |
83 | 91 | ||
84 | void config_cb(const char *name, const char *value) | 92 | void config_cb(const char *name, const char *value) |
85 | { | 93 | { |
86 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) | 94 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) |
87 | ctx.cfg.section = xstrdup(value); | 95 | ctx.cfg.section = xstrdup(value); |
88 | else if (!strcmp(name, "repo.url")) | 96 | else if (!strcmp(name, "repo.url")) |
89 | ctx.repo = cgit_add_repo(value); | 97 | ctx.repo = cgit_add_repo(value); |
90 | else if (ctx.repo && !strcmp(name, "repo.path")) | 98 | else if (ctx.repo && !strcmp(name, "repo.path")) |
91 | ctx.repo->path = trim_end(value, '/'); | 99 | ctx.repo->path = trim_end(value, '/'); |
92 | else if (ctx.repo && !prefixcmp(name, "repo.")) | 100 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
93 | repo_config(ctx.repo, name + 5, value); | 101 | repo_config(ctx.repo, name + 5, value); |
102 | else if (!strcmp(name, "readme")) | ||
103 | ctx.cfg.readme = xstrdup(value); | ||
94 | else if (!strcmp(name, "root-title")) | 104 | else if (!strcmp(name, "root-title")) |
95 | ctx.cfg.root_title = xstrdup(value); | 105 | ctx.cfg.root_title = xstrdup(value); |
96 | else if (!strcmp(name, "root-desc")) | 106 | else if (!strcmp(name, "root-desc")) |
97 | ctx.cfg.root_desc = xstrdup(value); | 107 | ctx.cfg.root_desc = xstrdup(value); |
98 | else if (!strcmp(name, "root-readme")) | 108 | else if (!strcmp(name, "root-readme")) |
99 | ctx.cfg.root_readme = xstrdup(value); | 109 | ctx.cfg.root_readme = xstrdup(value); |
100 | else if (!strcmp(name, "css")) | 110 | else if (!strcmp(name, "css")) |
101 | ctx.cfg.css = xstrdup(value); | 111 | ctx.cfg.css = xstrdup(value); |
102 | else if (!strcmp(name, "favicon")) | 112 | else if (!strcmp(name, "favicon")) |
103 | ctx.cfg.favicon = xstrdup(value); | 113 | ctx.cfg.favicon = xstrdup(value); |
104 | else if (!strcmp(name, "footer")) | 114 | else if (!strcmp(name, "footer")) |
105 | ctx.cfg.footer = xstrdup(value); | 115 | ctx.cfg.footer = xstrdup(value); |
106 | else if (!strcmp(name, "head-include")) | 116 | else if (!strcmp(name, "head-include")) |
107 | ctx.cfg.head_include = xstrdup(value); | 117 | ctx.cfg.head_include = xstrdup(value); |
108 | else if (!strcmp(name, "header")) | 118 | else if (!strcmp(name, "header")) |
109 | ctx.cfg.header = xstrdup(value); | 119 | ctx.cfg.header = xstrdup(value); |
110 | else if (!strcmp(name, "logo")) | 120 | else if (!strcmp(name, "logo")) |
111 | ctx.cfg.logo = xstrdup(value); | 121 | ctx.cfg.logo = xstrdup(value); |
112 | else if (!strcmp(name, "index-header")) | 122 | else if (!strcmp(name, "index-header")) |
113 | ctx.cfg.index_header = xstrdup(value); | 123 | ctx.cfg.index_header = xstrdup(value); |
114 | else if (!strcmp(name, "index-info")) | 124 | else if (!strcmp(name, "index-info")) |
115 | ctx.cfg.index_info = xstrdup(value); | 125 | ctx.cfg.index_info = xstrdup(value); |
116 | else if (!strcmp(name, "logo-link")) | 126 | else if (!strcmp(name, "logo-link")) |
117 | ctx.cfg.logo_link = xstrdup(value); | 127 | ctx.cfg.logo_link = xstrdup(value); |
118 | else if (!strcmp(name, "module-link")) | 128 | else if (!strcmp(name, "module-link")) |
119 | ctx.cfg.module_link = xstrdup(value); | 129 | ctx.cfg.module_link = xstrdup(value); |
130 | else if (!strcmp(name, "strict-export")) | ||
131 | ctx.cfg.strict_export = xstrdup(value); | ||
120 | else if (!strcmp(name, "virtual-root")) { | 132 | else if (!strcmp(name, "virtual-root")) { |
121 | ctx.cfg.virtual_root = trim_end(value, '/'); | 133 | ctx.cfg.virtual_root = trim_end(value, '/'); |
122 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 134 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
123 | ctx.cfg.virtual_root = ""; | 135 | ctx.cfg.virtual_root = ""; |
124 | } else if (!strcmp(name, "nocache")) | 136 | } else if (!strcmp(name, "nocache")) |
125 | ctx.cfg.nocache = atoi(value); | 137 | ctx.cfg.nocache = atoi(value); |
126 | else if (!strcmp(name, "noplainemail")) | 138 | else if (!strcmp(name, "noplainemail")) |
127 | ctx.cfg.noplainemail = atoi(value); | 139 | ctx.cfg.noplainemail = atoi(value); |
128 | else if (!strcmp(name, "noheader")) | 140 | else if (!strcmp(name, "noheader")) |
129 | ctx.cfg.noheader = atoi(value); | 141 | ctx.cfg.noheader = atoi(value); |
130 | else if (!strcmp(name, "snapshots")) | 142 | else if (!strcmp(name, "snapshots")) |
131 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | 143 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
132 | else if (!strcmp(name, "enable-filter-overrides")) | 144 | else if (!strcmp(name, "enable-filter-overrides")) |
133 | ctx.cfg.enable_filter_overrides = atoi(value); | 145 | ctx.cfg.enable_filter_overrides = atoi(value); |
146 | else if (!strcmp(name, "enable-gitweb-owner")) | ||
147 | ctx.cfg.enable_gitweb_owner = atoi(value); | ||
134 | else if (!strcmp(name, "enable-index-links")) | 148 | else if (!strcmp(name, "enable-index-links")) |
135 | ctx.cfg.enable_index_links = atoi(value); | 149 | ctx.cfg.enable_index_links = atoi(value); |
150 | else if (!strcmp(name, "enable-commit-graph")) | ||
151 | ctx.cfg.enable_commit_graph = atoi(value); | ||
136 | else if (!strcmp(name, "enable-log-filecount")) | 152 | else if (!strcmp(name, "enable-log-filecount")) |
137 | ctx.cfg.enable_log_filecount = atoi(value); | 153 | ctx.cfg.enable_log_filecount = atoi(value); |
138 | else if (!strcmp(name, "enable-log-linecount")) | 154 | else if (!strcmp(name, "enable-log-linecount")) |
139 | ctx.cfg.enable_log_linecount = atoi(value); | 155 | ctx.cfg.enable_log_linecount = atoi(value); |
156 | else if (!strcmp(name, "enable-remote-branches")) | ||
157 | ctx.cfg.enable_remote_branches = atoi(value); | ||
158 | else if (!strcmp(name, "enable-subject-links")) | ||
159 | ctx.cfg.enable_subject_links = atoi(value); | ||
140 | else if (!strcmp(name, "enable-tree-linenumbers")) | 160 | else if (!strcmp(name, "enable-tree-linenumbers")) |
141 | ctx.cfg.enable_tree_linenumbers = atoi(value); | 161 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
142 | else if (!strcmp(name, "max-stats")) | 162 | else if (!strcmp(name, "max-stats")) |
143 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); | 163 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
144 | else if (!strcmp(name, "cache-size")) | 164 | else if (!strcmp(name, "cache-size")) |
145 | ctx.cfg.cache_size = atoi(value); | 165 | ctx.cfg.cache_size = atoi(value); |
146 | else if (!strcmp(name, "cache-root")) | 166 | else if (!strcmp(name, "cache-root")) |
147 | ctx.cfg.cache_root = xstrdup(value); | 167 | ctx.cfg.cache_root = xstrdup(expand_macros(value)); |
148 | else if (!strcmp(name, "cache-root-ttl")) | 168 | else if (!strcmp(name, "cache-root-ttl")) |
149 | ctx.cfg.cache_root_ttl = atoi(value); | 169 | ctx.cfg.cache_root_ttl = atoi(value); |
150 | else if (!strcmp(name, "cache-repo-ttl")) | 170 | else if (!strcmp(name, "cache-repo-ttl")) |
151 | ctx.cfg.cache_repo_ttl = atoi(value); | 171 | ctx.cfg.cache_repo_ttl = atoi(value); |
152 | else if (!strcmp(name, "cache-scanrc-ttl")) | 172 | else if (!strcmp(name, "cache-scanrc-ttl")) |
153 | ctx.cfg.cache_scanrc_ttl = atoi(value); | 173 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
154 | else if (!strcmp(name, "cache-static-ttl")) | 174 | else if (!strcmp(name, "cache-static-ttl")) |
155 | ctx.cfg.cache_static_ttl = atoi(value); | 175 | ctx.cfg.cache_static_ttl = atoi(value); |
156 | else if (!strcmp(name, "cache-dynamic-ttl")) | 176 | else if (!strcmp(name, "cache-dynamic-ttl")) |
157 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 177 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
158 | else if (!strcmp(name, "about-filter")) | 178 | else if (!strcmp(name, "about-filter")) |
159 | ctx.cfg.about_filter = new_filter(value, 0); | 179 | ctx.cfg.about_filter = new_filter(value, 0); |
160 | else if (!strcmp(name, "commit-filter")) | 180 | else if (!strcmp(name, "commit-filter")) |
161 | ctx.cfg.commit_filter = new_filter(value, 0); | 181 | ctx.cfg.commit_filter = new_filter(value, 0); |
162 | else if (!strcmp(name, "embedded")) | 182 | else if (!strcmp(name, "embedded")) |
163 | ctx.cfg.embedded = atoi(value); | 183 | ctx.cfg.embedded = atoi(value); |
184 | else if (!strcmp(name, "max-atom-items")) | ||
185 | ctx.cfg.max_atom_items = atoi(value); | ||
164 | else if (!strcmp(name, "max-message-length")) | 186 | else if (!strcmp(name, "max-message-length")) |
165 | ctx.cfg.max_msg_len = atoi(value); | 187 | ctx.cfg.max_msg_len = atoi(value); |
166 | else if (!strcmp(name, "max-repodesc-length")) | 188 | else if (!strcmp(name, "max-repodesc-length")) |
167 | ctx.cfg.max_repodesc_len = atoi(value); | 189 | ctx.cfg.max_repodesc_len = atoi(value); |
190 | else if (!strcmp(name, "max-blob-size")) | ||
191 | ctx.cfg.max_blob_size = atoi(value); | ||
168 | else if (!strcmp(name, "max-repo-count")) | 192 | else if (!strcmp(name, "max-repo-count")) |
169 | ctx.cfg.max_repo_count = atoi(value); | 193 | ctx.cfg.max_repo_count = atoi(value); |
170 | else if (!strcmp(name, "max-commit-count")) | 194 | else if (!strcmp(name, "max-commit-count")) |
171 | ctx.cfg.max_commit_count = atoi(value); | 195 | ctx.cfg.max_commit_count = atoi(value); |
196 | else if (!strcmp(name, "project-list")) | ||
197 | ctx.cfg.project_list = xstrdup(expand_macros(value)); | ||
172 | else if (!strcmp(name, "scan-path")) | 198 | else if (!strcmp(name, "scan-path")) |
173 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) | 199 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
174 | process_cached_repolist(value); | 200 | process_cached_repolist(expand_macros(value)); |
201 | else if (ctx.cfg.project_list) | ||
202 | scan_projects(expand_macros(value), | ||
203 | ctx.cfg.project_list, repo_config); | ||
175 | else | 204 | else |
176 | scan_tree(value, repo_config); | 205 | scan_tree(expand_macros(value), repo_config); |
206 | else if (!strcmp(name, "scan-hidden-path")) | ||
207 | ctx.cfg.scan_hidden_path = atoi(value); | ||
208 | else if (!strcmp(name, "section-from-path")) | ||
209 | ctx.cfg.section_from_path = atoi(value); | ||
177 | else if (!strcmp(name, "source-filter")) | 210 | else if (!strcmp(name, "source-filter")) |
178 | ctx.cfg.source_filter = new_filter(value, 1); | 211 | ctx.cfg.source_filter = new_filter(value, 1); |
179 | else if (!strcmp(name, "summary-log")) | 212 | else if (!strcmp(name, "summary-log")) |
180 | ctx.cfg.summary_log = atoi(value); | 213 | ctx.cfg.summary_log = atoi(value); |
181 | else if (!strcmp(name, "summary-branches")) | 214 | else if (!strcmp(name, "summary-branches")) |
182 | ctx.cfg.summary_branches = atoi(value); | 215 | ctx.cfg.summary_branches = atoi(value); |
183 | else if (!strcmp(name, "summary-tags")) | 216 | else if (!strcmp(name, "summary-tags")) |
184 | ctx.cfg.summary_tags = atoi(value); | 217 | ctx.cfg.summary_tags = atoi(value); |
218 | else if (!strcmp(name, "side-by-side-diffs")) | ||
219 | ctx.cfg.ssdiff = atoi(value); | ||
185 | else if (!strcmp(name, "agefile")) | 220 | else if (!strcmp(name, "agefile")) |
186 | ctx.cfg.agefile = xstrdup(value); | 221 | ctx.cfg.agefile = xstrdup(value); |
187 | else if (!strcmp(name, "renamelimit")) | 222 | else if (!strcmp(name, "renamelimit")) |
188 | ctx.cfg.renamelimit = atoi(value); | 223 | ctx.cfg.renamelimit = atoi(value); |
224 | else if (!strcmp(name, "remove-suffix")) | ||
225 | ctx.cfg.remove_suffix = atoi(value); | ||
189 | else if (!strcmp(name, "robots")) | 226 | else if (!strcmp(name, "robots")) |
190 | ctx.cfg.robots = xstrdup(value); | 227 | ctx.cfg.robots = xstrdup(value); |
191 | else if (!strcmp(name, "clone-prefix")) | 228 | else if (!strcmp(name, "clone-prefix")) |
192 | ctx.cfg.clone_prefix = xstrdup(value); | 229 | ctx.cfg.clone_prefix = xstrdup(value); |
193 | else if (!strcmp(name, "local-time")) | 230 | else if (!strcmp(name, "local-time")) |
194 | ctx.cfg.local_time = atoi(value); | 231 | ctx.cfg.local_time = atoi(value); |
195 | else if (!prefixcmp(name, "mimetype.")) | 232 | else if (!prefixcmp(name, "mimetype.")) |
196 | add_mimetype(name + 9, value); | 233 | add_mimetype(name + 9, value); |
197 | else if (!strcmp(name, "include")) | 234 | else if (!strcmp(name, "include")) |
198 | parse_configfile(value, config_cb); | 235 | parse_configfile(expand_macros(value), config_cb); |
199 | } | 236 | } |
200 | 237 | ||
201 | static void querystring_cb(const char *name, const char *value) | 238 | static void querystring_cb(const char *name, const char *value) |
202 | { | 239 | { |
203 | if (!value) | 240 | if (!value) |
204 | value = ""; | 241 | value = ""; |
205 | 242 | ||
206 | if (!strcmp(name,"r")) { | 243 | if (!strcmp(name,"r")) { |
207 | ctx.qry.repo = xstrdup(value); | 244 | ctx.qry.repo = xstrdup(value); |
208 | ctx.repo = cgit_get_repoinfo(value); | 245 | ctx.repo = cgit_get_repoinfo(value); |
209 | } else if (!strcmp(name, "p")) { | 246 | } else if (!strcmp(name, "p")) { |
210 | ctx.qry.page = xstrdup(value); | 247 | ctx.qry.page = xstrdup(value); |
211 | } else if (!strcmp(name, "url")) { | 248 | } else if (!strcmp(name, "url")) { |
249 | if (*value == '/') | ||
250 | value++; | ||
212 | ctx.qry.url = xstrdup(value); | 251 | ctx.qry.url = xstrdup(value); |
213 | cgit_parse_url(value); | 252 | cgit_parse_url(value); |
214 | } else if (!strcmp(name, "qt")) { | 253 | } else if (!strcmp(name, "qt")) { |
215 | ctx.qry.grep = xstrdup(value); | 254 | ctx.qry.grep = xstrdup(value); |
216 | } else if (!strcmp(name, "q")) { | 255 | } else if (!strcmp(name, "q")) { |
217 | ctx.qry.search = xstrdup(value); | 256 | ctx.qry.search = xstrdup(value); |
218 | } else if (!strcmp(name, "h")) { | 257 | } else if (!strcmp(name, "h")) { |
219 | ctx.qry.head = xstrdup(value); | 258 | ctx.qry.head = xstrdup(value); |
220 | ctx.qry.has_symref = 1; | 259 | ctx.qry.has_symref = 1; |
221 | } else if (!strcmp(name, "id")) { | 260 | } else if (!strcmp(name, "id")) { |
222 | ctx.qry.sha1 = xstrdup(value); | 261 | ctx.qry.sha1 = xstrdup(value); |
223 | ctx.qry.has_sha1 = 1; | 262 | ctx.qry.has_sha1 = 1; |
224 | } else if (!strcmp(name, "id2")) { | 263 | } else if (!strcmp(name, "id2")) { |
225 | ctx.qry.sha2 = xstrdup(value); | 264 | ctx.qry.sha2 = xstrdup(value); |
226 | ctx.qry.has_sha1 = 1; | 265 | ctx.qry.has_sha1 = 1; |
227 | } else if (!strcmp(name, "ofs")) { | 266 | } else if (!strcmp(name, "ofs")) { |
228 | ctx.qry.ofs = atoi(value); | 267 | ctx.qry.ofs = atoi(value); |
229 | } else if (!strcmp(name, "path")) { | 268 | } else if (!strcmp(name, "path")) { |
230 | ctx.qry.path = trim_end(value, '/'); | 269 | ctx.qry.path = trim_end(value, '/'); |
231 | } else if (!strcmp(name, "name")) { | 270 | } else if (!strcmp(name, "name")) { |
232 | ctx.qry.name = xstrdup(value); | 271 | ctx.qry.name = xstrdup(value); |
233 | } else if (!strcmp(name, "mimetype")) { | 272 | } else if (!strcmp(name, "mimetype")) { |
234 | ctx.qry.mimetype = xstrdup(value); | 273 | ctx.qry.mimetype = xstrdup(value); |
235 | } else if (!strcmp(name, "s")){ | 274 | } else if (!strcmp(name, "s")){ |
236 | ctx.qry.sort = xstrdup(value); | 275 | ctx.qry.sort = xstrdup(value); |
237 | } else if (!strcmp(name, "showmsg")) { | 276 | } else if (!strcmp(name, "showmsg")) { |
238 | ctx.qry.showmsg = atoi(value); | 277 | ctx.qry.showmsg = atoi(value); |
239 | } else if (!strcmp(name, "period")) { | 278 | } else if (!strcmp(name, "period")) { |
240 | ctx.qry.period = xstrdup(value); | 279 | ctx.qry.period = xstrdup(value); |
280 | } else if (!strcmp(name, "ss")) { | ||
281 | ctx.qry.ssdiff = atoi(value); | ||
282 | } else if (!strcmp(name, "all")) { | ||
283 | ctx.qry.show_all = atoi(value); | ||
284 | } else if (!strcmp(name, "context")) { | ||
285 | ctx.qry.context = atoi(value); | ||
286 | } else if (!strcmp(name, "ignorews")) { | ||
287 | ctx.qry.ignorews = atoi(value); | ||
241 | } | 288 | } |
242 | } | 289 | } |
243 | 290 | ||
244 | char *xstrdupn(const char *str) | 291 | char *xstrdupn(const char *str) |
245 | { | 292 | { |
246 | return (str ? xstrdup(str) : NULL); | 293 | return (str ? xstrdup(str) : NULL); |
247 | } | 294 | } |
248 | 295 | ||
249 | static void prepare_context(struct cgit_context *ctx) | 296 | static void prepare_context(struct cgit_context *ctx) |
250 | { | 297 | { |
251 | memset(ctx, 0, sizeof(*ctx)); | 298 | memset(ctx, 0, sizeof(*ctx)); |
252 | ctx->cfg.agefile = "info/web/last-modified"; | 299 | ctx->cfg.agefile = "info/web/last-modified"; |
253 | ctx->cfg.nocache = 0; | 300 | ctx->cfg.nocache = 0; |
254 | ctx->cfg.cache_size = 0; | 301 | ctx->cfg.cache_size = 0; |
255 | ctx->cfg.cache_dynamic_ttl = 5; | 302 | ctx->cfg.cache_dynamic_ttl = 5; |
256 | ctx->cfg.cache_max_create_time = 5; | 303 | ctx->cfg.cache_max_create_time = 5; |
257 | ctx->cfg.cache_repo_ttl = 5; | 304 | ctx->cfg.cache_repo_ttl = 5; |
258 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 305 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
259 | ctx->cfg.cache_root_ttl = 5; | 306 | ctx->cfg.cache_root_ttl = 5; |
260 | ctx->cfg.cache_scanrc_ttl = 15; | 307 | ctx->cfg.cache_scanrc_ttl = 15; |
261 | ctx->cfg.cache_static_ttl = -1; | 308 | ctx->cfg.cache_static_ttl = -1; |
262 | ctx->cfg.css = "/cgit.css"; | 309 | ctx->cfg.css = "/cgit.css"; |
263 | ctx->cfg.logo = "/cgit.png"; | 310 | ctx->cfg.logo = "/cgit.png"; |
264 | ctx->cfg.local_time = 0; | 311 | ctx->cfg.local_time = 0; |
312 | ctx->cfg.enable_gitweb_owner = 1; | ||
265 | ctx->cfg.enable_tree_linenumbers = 1; | 313 | ctx->cfg.enable_tree_linenumbers = 1; |
266 | ctx->cfg.max_repo_count = 50; | 314 | ctx->cfg.max_repo_count = 50; |
267 | ctx->cfg.max_commit_count = 50; | 315 | ctx->cfg.max_commit_count = 50; |
268 | ctx->cfg.max_lock_attempts = 5; | 316 | ctx->cfg.max_lock_attempts = 5; |
269 | ctx->cfg.max_msg_len = 80; | 317 | ctx->cfg.max_msg_len = 80; |
270 | ctx->cfg.max_repodesc_len = 80; | 318 | ctx->cfg.max_repodesc_len = 80; |
319 | ctx->cfg.max_blob_size = 0; | ||
271 | ctx->cfg.max_stats = 0; | 320 | ctx->cfg.max_stats = 0; |
272 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 321 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
322 | ctx->cfg.project_list = NULL; | ||
273 | ctx->cfg.renamelimit = -1; | 323 | ctx->cfg.renamelimit = -1; |
324 | ctx->cfg.remove_suffix = 0; | ||
274 | ctx->cfg.robots = "index, nofollow"; | 325 | ctx->cfg.robots = "index, nofollow"; |
275 | ctx->cfg.root_title = "Git repository browser"; | 326 | ctx->cfg.root_title = "Git repository browser"; |
276 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 327 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
328 | ctx->cfg.scan_hidden_path = 0; | ||
277 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 329 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
278 | ctx->cfg.section = ""; | 330 | ctx->cfg.section = ""; |
279 | ctx->cfg.summary_branches = 10; | 331 | ctx->cfg.summary_branches = 10; |
280 | ctx->cfg.summary_log = 10; | 332 | ctx->cfg.summary_log = 10; |
281 | ctx->cfg.summary_tags = 10; | 333 | ctx->cfg.summary_tags = 10; |
334 | ctx->cfg.max_atom_items = 10; | ||
335 | ctx->cfg.ssdiff = 0; | ||
282 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); | 336 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
283 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); | 337 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); |
284 | ctx->env.https = xstrdupn(getenv("HTTPS")); | 338 | ctx->env.https = xstrdupn(getenv("HTTPS")); |
285 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); | 339 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); |
286 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); | 340 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); |
287 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); | 341 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); |
288 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); | 342 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); |
289 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); | 343 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); |
290 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); | 344 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); |
291 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); | 345 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); |
292 | ctx->page.mimetype = "text/html"; | 346 | ctx->page.mimetype = "text/html"; |
293 | ctx->page.charset = PAGE_ENCODING; | 347 | ctx->page.charset = PAGE_ENCODING; |
294 | ctx->page.filename = NULL; | 348 | ctx->page.filename = NULL; |
295 | ctx->page.size = 0; | 349 | ctx->page.size = 0; |
296 | ctx->page.modified = time(NULL); | 350 | ctx->page.modified = time(NULL); |
297 | ctx->page.expires = ctx->page.modified; | 351 | ctx->page.expires = ctx->page.modified; |
298 | ctx->page.etag = NULL; | 352 | ctx->page.etag = NULL; |
299 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | 353 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
300 | if (ctx->env.script_name) | 354 | if (ctx->env.script_name) |
301 | ctx->cfg.script_name = ctx->env.script_name; | 355 | ctx->cfg.script_name = ctx->env.script_name; |
302 | if (ctx->env.query_string) | 356 | if (ctx->env.query_string) |
303 | ctx->qry.raw = ctx->env.query_string; | 357 | ctx->qry.raw = ctx->env.query_string; |
304 | if (!ctx->env.cgit_config) | 358 | if (!ctx->env.cgit_config) |
305 | ctx->env.cgit_config = CGIT_CONFIG; | 359 | ctx->env.cgit_config = CGIT_CONFIG; |
306 | } | 360 | } |
307 | 361 | ||
308 | struct refmatch { | 362 | struct refmatch { |
309 | char *req_ref; | 363 | char *req_ref; |
310 | char *first_ref; | 364 | char *first_ref; |
311 | int match; | 365 | int match; |
312 | }; | 366 | }; |
313 | 367 | ||
314 | int find_current_ref(const char *refname, const unsigned char *sha1, | 368 | int find_current_ref(const char *refname, const unsigned char *sha1, |
315 | int flags, void *cb_data) | 369 | int flags, void *cb_data) |
316 | { | 370 | { |
317 | struct refmatch *info; | 371 | struct refmatch *info; |
318 | 372 | ||
319 | info = (struct refmatch *)cb_data; | 373 | info = (struct refmatch *)cb_data; |
320 | if (!strcmp(refname, info->req_ref)) | 374 | if (!strcmp(refname, info->req_ref)) |
321 | info->match = 1; | 375 | info->match = 1; |
322 | if (!info->first_ref) | 376 | if (!info->first_ref) |
323 | info->first_ref = xstrdup(refname); | 377 | info->first_ref = xstrdup(refname); |
324 | return info->match; | 378 | return info->match; |
325 | } | 379 | } |
326 | 380 | ||
327 | char *find_default_branch(struct cgit_repo *repo) | 381 | char *find_default_branch(struct cgit_repo *repo) |
328 | { | 382 | { |
329 | struct refmatch info; | 383 | struct refmatch info; |
@@ -365,252 +419,271 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
365 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 419 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
366 | 420 | ||
367 | if (!ctx->qry.head) { | 421 | if (!ctx->qry.head) { |
368 | ctx->qry.nohead = 1; | 422 | ctx->qry.nohead = 1; |
369 | ctx->qry.head = find_default_branch(ctx->repo); | 423 | ctx->qry.head = find_default_branch(ctx->repo); |
370 | ctx->repo->defbranch = ctx->qry.head; | 424 | ctx->repo->defbranch = ctx->qry.head; |
371 | } | 425 | } |
372 | 426 | ||
373 | if (!ctx->qry.head) { | 427 | if (!ctx->qry.head) { |
374 | cgit_print_http_headers(ctx); | 428 | cgit_print_http_headers(ctx); |
375 | cgit_print_docstart(ctx); | 429 | cgit_print_docstart(ctx); |
376 | cgit_print_pageheader(ctx); | 430 | cgit_print_pageheader(ctx); |
377 | cgit_print_error("Repository seems to be empty"); | 431 | cgit_print_error("Repository seems to be empty"); |
378 | cgit_print_docend(); | 432 | cgit_print_docend(); |
379 | return 1; | 433 | return 1; |
380 | } | 434 | } |
381 | 435 | ||
382 | if (get_sha1(ctx->qry.head, sha1)) { | 436 | if (get_sha1(ctx->qry.head, sha1)) { |
383 | tmp = xstrdup(ctx->qry.head); | 437 | tmp = xstrdup(ctx->qry.head); |
384 | ctx->qry.head = ctx->repo->defbranch; | 438 | ctx->qry.head = ctx->repo->defbranch; |
385 | ctx->page.status = 404; | 439 | ctx->page.status = 404; |
386 | ctx->page.statusmsg = "not found"; | 440 | ctx->page.statusmsg = "not found"; |
387 | cgit_print_http_headers(ctx); | 441 | cgit_print_http_headers(ctx); |
388 | cgit_print_docstart(ctx); | 442 | cgit_print_docstart(ctx); |
389 | cgit_print_pageheader(ctx); | 443 | cgit_print_pageheader(ctx); |
390 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 444 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
391 | cgit_print_docend(); | 445 | cgit_print_docend(); |
392 | return 1; | 446 | return 1; |
393 | } | 447 | } |
394 | return 0; | 448 | return 0; |
395 | } | 449 | } |
396 | 450 | ||
397 | static void process_request(void *cbdata) | 451 | static void process_request(void *cbdata) |
398 | { | 452 | { |
399 | struct cgit_context *ctx = cbdata; | 453 | struct cgit_context *ctx = cbdata; |
400 | struct cgit_cmd *cmd; | 454 | struct cgit_cmd *cmd; |
401 | 455 | ||
402 | cmd = cgit_get_cmd(ctx); | 456 | cmd = cgit_get_cmd(ctx); |
403 | if (!cmd) { | 457 | if (!cmd) { |
404 | ctx->page.title = "cgit error"; | 458 | ctx->page.title = "cgit error"; |
405 | cgit_print_http_headers(ctx); | 459 | cgit_print_http_headers(ctx); |
406 | cgit_print_docstart(ctx); | 460 | cgit_print_docstart(ctx); |
407 | cgit_print_pageheader(ctx); | 461 | cgit_print_pageheader(ctx); |
408 | cgit_print_error("Invalid request"); | 462 | cgit_print_error("Invalid request"); |
409 | cgit_print_docend(); | 463 | cgit_print_docend(); |
410 | return; | 464 | return; |
411 | } | 465 | } |
412 | 466 | ||
467 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" | ||
468 | * in-project path limit to be made available at ctx->qry.vpath. | ||
469 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). | ||
470 | */ | ||
471 | ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; | ||
472 | |||
413 | if (cmd->want_repo && !ctx->repo) { | 473 | if (cmd->want_repo && !ctx->repo) { |
414 | cgit_print_http_headers(ctx); | 474 | cgit_print_http_headers(ctx); |
415 | cgit_print_docstart(ctx); | 475 | cgit_print_docstart(ctx); |
416 | cgit_print_pageheader(ctx); | 476 | cgit_print_pageheader(ctx); |
417 | cgit_print_error(fmt("No repository selected")); | 477 | cgit_print_error(fmt("No repository selected")); |
418 | cgit_print_docend(); | 478 | cgit_print_docend(); |
419 | return; | 479 | return; |
420 | } | 480 | } |
421 | 481 | ||
422 | if (ctx->repo && prepare_repo_cmd(ctx)) | 482 | if (ctx->repo && prepare_repo_cmd(ctx)) |
423 | return; | 483 | return; |
424 | 484 | ||
425 | if (cmd->want_layout) { | 485 | if (cmd->want_layout) { |
426 | cgit_print_http_headers(ctx); | 486 | cgit_print_http_headers(ctx); |
427 | cgit_print_docstart(ctx); | 487 | cgit_print_docstart(ctx); |
428 | cgit_print_pageheader(ctx); | 488 | cgit_print_pageheader(ctx); |
429 | } | 489 | } |
430 | 490 | ||
431 | cmd->fn(ctx); | 491 | cmd->fn(ctx); |
432 | 492 | ||
433 | if (cmd->want_layout) | 493 | if (cmd->want_layout) |
434 | cgit_print_docend(); | 494 | cgit_print_docend(); |
435 | } | 495 | } |
436 | 496 | ||
437 | int cmp_repos(const void *a, const void *b) | 497 | int cmp_repos(const void *a, const void *b) |
438 | { | 498 | { |
439 | const struct cgit_repo *ra = a, *rb = b; | 499 | const struct cgit_repo *ra = a, *rb = b; |
440 | return strcmp(ra->url, rb->url); | 500 | return strcmp(ra->url, rb->url); |
441 | } | 501 | } |
442 | 502 | ||
443 | char *build_snapshot_setting(int bitmap) | 503 | char *build_snapshot_setting(int bitmap) |
444 | { | 504 | { |
445 | const struct cgit_snapshot_format *f; | 505 | const struct cgit_snapshot_format *f; |
446 | char *result = xstrdup(""); | 506 | char *result = xstrdup(""); |
447 | char *tmp; | 507 | char *tmp; |
448 | int len; | 508 | int len; |
449 | 509 | ||
450 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 510 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
451 | if (f->bit & bitmap) { | 511 | if (f->bit & bitmap) { |
452 | tmp = result; | 512 | tmp = result; |
453 | result = xstrdup(fmt("%s%s ", tmp, f->suffix)); | 513 | result = xstrdup(fmt("%s%s ", tmp, f->suffix)); |
454 | free(tmp); | 514 | free(tmp); |
455 | } | 515 | } |
456 | } | 516 | } |
457 | len = strlen(result); | 517 | len = strlen(result); |
458 | if (len) | 518 | if (len) |
459 | result[len - 1] = '\0'; | 519 | result[len - 1] = '\0'; |
460 | return result; | 520 | return result; |
461 | } | 521 | } |
462 | 522 | ||
463 | char *get_first_line(char *txt) | 523 | char *get_first_line(char *txt) |
464 | { | 524 | { |
465 | char *t = xstrdup(txt); | 525 | char *t = xstrdup(txt); |
466 | char *p = strchr(t, '\n'); | 526 | char *p = strchr(t, '\n'); |
467 | if (p) | 527 | if (p) |
468 | *p = '\0'; | 528 | *p = '\0'; |
469 | return t; | 529 | return t; |
470 | } | 530 | } |
471 | 531 | ||
472 | void print_repo(FILE *f, struct cgit_repo *repo) | 532 | void print_repo(FILE *f, struct cgit_repo *repo) |
473 | { | 533 | { |
474 | fprintf(f, "repo.url=%s\n", repo->url); | 534 | fprintf(f, "repo.url=%s\n", repo->url); |
475 | fprintf(f, "repo.name=%s\n", repo->name); | 535 | fprintf(f, "repo.name=%s\n", repo->name); |
476 | fprintf(f, "repo.path=%s\n", repo->path); | 536 | fprintf(f, "repo.path=%s\n", repo->path); |
477 | if (repo->owner) | 537 | if (repo->owner) |
478 | fprintf(f, "repo.owner=%s\n", repo->owner); | 538 | fprintf(f, "repo.owner=%s\n", repo->owner); |
479 | if (repo->desc) { | 539 | if (repo->desc) { |
480 | char *tmp = get_first_line(repo->desc); | 540 | char *tmp = get_first_line(repo->desc); |
481 | fprintf(f, "repo.desc=%s\n", tmp); | 541 | fprintf(f, "repo.desc=%s\n", tmp); |
482 | free(tmp); | 542 | free(tmp); |
483 | } | 543 | } |
484 | if (repo->readme) | 544 | if (repo->readme) |
485 | fprintf(f, "repo.readme=%s\n", repo->readme); | 545 | fprintf(f, "repo.readme=%s\n", repo->readme); |
486 | if (repo->defbranch) | 546 | if (repo->defbranch) |
487 | fprintf(f, "repo.defbranch=%s\n", repo->defbranch); | 547 | fprintf(f, "repo.defbranch=%s\n", repo->defbranch); |
488 | if (repo->module_link) | 548 | if (repo->module_link) |
489 | fprintf(f, "repo.module-link=%s\n", repo->module_link); | 549 | fprintf(f, "repo.module-link=%s\n", repo->module_link); |
490 | if (repo->section) | 550 | if (repo->section) |
491 | fprintf(f, "repo.section=%s\n", repo->section); | 551 | fprintf(f, "repo.section=%s\n", repo->section); |
492 | if (repo->clone_url) | 552 | if (repo->clone_url) |
493 | fprintf(f, "repo.clone-url=%s\n", repo->clone_url); | 553 | fprintf(f, "repo.clone-url=%s\n", repo->clone_url); |
554 | fprintf(f, "repo.enable-commit-graph=%d\n", | ||
555 | repo->enable_commit_graph); | ||
494 | fprintf(f, "repo.enable-log-filecount=%d\n", | 556 | fprintf(f, "repo.enable-log-filecount=%d\n", |
495 | repo->enable_log_filecount); | 557 | repo->enable_log_filecount); |
496 | fprintf(f, "repo.enable-log-linecount=%d\n", | 558 | fprintf(f, "repo.enable-log-linecount=%d\n", |
497 | repo->enable_log_linecount); | 559 | repo->enable_log_linecount); |
498 | if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) | 560 | if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) |
499 | fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd); | 561 | fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd); |
500 | if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) | 562 | if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) |
501 | fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd); | 563 | fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd); |
502 | if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) | 564 | if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) |
503 | fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd); | 565 | fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd); |
504 | if (repo->snapshots != ctx.cfg.snapshots) { | 566 | if (repo->snapshots != ctx.cfg.snapshots) { |
505 | char *tmp = build_snapshot_setting(repo->snapshots); | 567 | char *tmp = build_snapshot_setting(repo->snapshots); |
506 | fprintf(f, "repo.snapshots=%s\n", tmp); | 568 | fprintf(f, "repo.snapshots=%s\n", tmp); |
507 | free(tmp); | 569 | free(tmp); |
508 | } | 570 | } |
509 | if (repo->max_stats != ctx.cfg.max_stats) | 571 | if (repo->max_stats != ctx.cfg.max_stats) |
510 | fprintf(f, "repo.max-stats=%s\n", | 572 | fprintf(f, "repo.max-stats=%s\n", |
511 | cgit_find_stats_periodname(repo->max_stats)); | 573 | cgit_find_stats_periodname(repo->max_stats)); |
512 | fprintf(f, "\n"); | 574 | fprintf(f, "\n"); |
513 | } | 575 | } |
514 | 576 | ||
515 | void print_repolist(FILE *f, struct cgit_repolist *list, int start) | 577 | void print_repolist(FILE *f, struct cgit_repolist *list, int start) |
516 | { | 578 | { |
517 | int i; | 579 | int i; |
518 | 580 | ||
519 | for(i = start; i < list->count; i++) | 581 | for(i = start; i < list->count; i++) |
520 | print_repo(f, &list->repos[i]); | 582 | print_repo(f, &list->repos[i]); |
521 | } | 583 | } |
522 | 584 | ||
523 | /* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc' | 585 | /* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc' |
524 | * and return 0 on success. | 586 | * and return 0 on success. |
525 | */ | 587 | */ |
526 | static int generate_cached_repolist(const char *path, const char *cached_rc) | 588 | static int generate_cached_repolist(const char *path, const char *cached_rc) |
527 | { | 589 | { |
528 | char *locked_rc; | 590 | char *locked_rc; |
529 | int idx; | 591 | int idx; |
530 | FILE *f; | 592 | FILE *f; |
531 | 593 | ||
532 | locked_rc = xstrdup(fmt("%s.lock", cached_rc)); | 594 | locked_rc = xstrdup(fmt("%s.lock", cached_rc)); |
533 | f = fopen(locked_rc, "wx"); | 595 | f = fopen(locked_rc, "wx"); |
534 | if (!f) { | 596 | if (!f) { |
535 | /* Inform about the error unless the lockfile already existed, | 597 | /* Inform about the error unless the lockfile already existed, |
536 | * since that only means we've got concurrent requests. | 598 | * since that only means we've got concurrent requests. |
537 | */ | 599 | */ |
538 | if (errno != EEXIST) | 600 | if (errno != EEXIST) |
539 | fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", | 601 | fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", |
540 | locked_rc, strerror(errno), errno); | 602 | locked_rc, strerror(errno), errno); |
541 | return errno; | 603 | return errno; |
542 | } | 604 | } |
543 | idx = cgit_repolist.count; | 605 | idx = cgit_repolist.count; |
606 | if (ctx.cfg.project_list) | ||
607 | scan_projects(path, ctx.cfg.project_list, repo_config); | ||
608 | else | ||
544 | scan_tree(path, repo_config); | 609 | scan_tree(path, repo_config); |
545 | print_repolist(f, &cgit_repolist, idx); | 610 | print_repolist(f, &cgit_repolist, idx); |
546 | if (rename(locked_rc, cached_rc)) | 611 | if (rename(locked_rc, cached_rc)) |
547 | fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", | 612 | fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", |
548 | locked_rc, cached_rc, strerror(errno), errno); | 613 | locked_rc, cached_rc, strerror(errno), errno); |
549 | fclose(f); | 614 | fclose(f); |
550 | return 0; | 615 | return 0; |
551 | } | 616 | } |
552 | 617 | ||
553 | static void process_cached_repolist(const char *path) | 618 | static void process_cached_repolist(const char *path) |
554 | { | 619 | { |
555 | struct stat st; | 620 | struct stat st; |
556 | char *cached_rc; | 621 | char *cached_rc; |
557 | time_t age; | 622 | time_t age; |
623 | unsigned long hash; | ||
558 | 624 | ||
559 | cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, | 625 | hash = hash_str(path); |
560 | hash_str(path))); | 626 | if (ctx.cfg.project_list) |
627 | hash += hash_str(ctx.cfg.project_list); | ||
628 | cached_rc = xstrdup(fmt("%s/rc-%8lx", ctx.cfg.cache_root, hash)); | ||
561 | 629 | ||
562 | if (stat(cached_rc, &st)) { | 630 | if (stat(cached_rc, &st)) { |
563 | /* Nothing is cached, we need to scan without forking. And | 631 | /* Nothing is cached, we need to scan without forking. And |
564 | * if we fail to generate a cached repolist, we need to | 632 | * if we fail to generate a cached repolist, we need to |
565 | * invoke scan_tree manually. | 633 | * invoke scan_tree manually. |
566 | */ | 634 | */ |
567 | if (generate_cached_repolist(path, cached_rc)) | 635 | if (generate_cached_repolist(path, cached_rc)) { |
636 | if (ctx.cfg.project_list) | ||
637 | scan_projects(path, ctx.cfg.project_list, | ||
638 | repo_config); | ||
639 | else | ||
568 | scan_tree(path, repo_config); | 640 | scan_tree(path, repo_config); |
641 | } | ||
569 | return; | 642 | return; |
570 | } | 643 | } |
571 | 644 | ||
572 | parse_configfile(cached_rc, config_cb); | 645 | parse_configfile(cached_rc, config_cb); |
573 | 646 | ||
574 | /* If the cached configfile hasn't expired, lets exit now */ | 647 | /* If the cached configfile hasn't expired, lets exit now */ |
575 | age = time(NULL) - st.st_mtime; | 648 | age = time(NULL) - st.st_mtime; |
576 | if (age <= (ctx.cfg.cache_scanrc_ttl * 60)) | 649 | if (age <= (ctx.cfg.cache_scanrc_ttl * 60)) |
577 | return; | 650 | return; |
578 | 651 | ||
579 | /* The cached repolist has been parsed, but it was old. So lets | 652 | /* The cached repolist has been parsed, but it was old. So lets |
580 | * rescan the specified path and generate a new cached repolist | 653 | * rescan the specified path and generate a new cached repolist |
581 | * in a child-process to avoid latency for the current request. | 654 | * in a child-process to avoid latency for the current request. |
582 | */ | 655 | */ |
583 | if (fork()) | 656 | if (fork()) |
584 | return; | 657 | return; |
585 | 658 | ||
586 | exit(generate_cached_repolist(path, cached_rc)); | 659 | exit(generate_cached_repolist(path, cached_rc)); |
587 | } | 660 | } |
588 | 661 | ||
589 | static void cgit_parse_args(int argc, const char **argv) | 662 | static void cgit_parse_args(int argc, const char **argv) |
590 | { | 663 | { |
591 | int i; | 664 | int i; |
592 | int scan = 0; | 665 | int scan = 0; |
593 | 666 | ||
594 | for (i = 1; i < argc; i++) { | 667 | for (i = 1; i < argc; i++) { |
595 | if (!strncmp(argv[i], "--cache=", 8)) { | 668 | if (!strncmp(argv[i], "--cache=", 8)) { |
596 | ctx.cfg.cache_root = xstrdup(argv[i]+8); | 669 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
597 | } | 670 | } |
598 | if (!strcmp(argv[i], "--nocache")) { | 671 | if (!strcmp(argv[i], "--nocache")) { |
599 | ctx.cfg.nocache = 1; | 672 | ctx.cfg.nocache = 1; |
600 | } | 673 | } |
601 | if (!strcmp(argv[i], "--nohttp")) { | 674 | if (!strcmp(argv[i], "--nohttp")) { |
602 | ctx.env.no_http = "1"; | 675 | ctx.env.no_http = "1"; |
603 | } | 676 | } |
604 | if (!strncmp(argv[i], "--query=", 8)) { | 677 | if (!strncmp(argv[i], "--query=", 8)) { |
605 | ctx.qry.raw = xstrdup(argv[i]+8); | 678 | ctx.qry.raw = xstrdup(argv[i]+8); |
606 | } | 679 | } |
607 | if (!strncmp(argv[i], "--repo=", 7)) { | 680 | if (!strncmp(argv[i], "--repo=", 7)) { |
608 | ctx.qry.repo = xstrdup(argv[i]+7); | 681 | ctx.qry.repo = xstrdup(argv[i]+7); |
609 | } | 682 | } |
610 | if (!strncmp(argv[i], "--page=", 7)) { | 683 | if (!strncmp(argv[i], "--page=", 7)) { |
611 | ctx.qry.page = xstrdup(argv[i]+7); | 684 | ctx.qry.page = xstrdup(argv[i]+7); |
612 | } | 685 | } |
613 | if (!strncmp(argv[i], "--head=", 7)) { | 686 | if (!strncmp(argv[i], "--head=", 7)) { |
614 | ctx.qry.head = xstrdup(argv[i]+7); | 687 | ctx.qry.head = xstrdup(argv[i]+7); |
615 | ctx.qry.has_symref = 1; | 688 | ctx.qry.has_symref = 1; |
616 | } | 689 | } |
@@ -629,91 +702,91 @@ static void cgit_parse_args(int argc, const char **argv) | |||
629 | * currently 0. By setting all bits high before | 702 | * currently 0. By setting all bits high before |
630 | * scanning we make sure that any in-repo cgitrc | 703 | * scanning we make sure that any in-repo cgitrc |
631 | * snapshot setting is respected by scan_tree(). | 704 | * snapshot setting is respected by scan_tree(). |
632 | * BTW: we assume that there'll never be more than | 705 | * BTW: we assume that there'll never be more than |
633 | * 255 different snapshot formats supported by cgit... | 706 | * 255 different snapshot formats supported by cgit... |
634 | */ | 707 | */ |
635 | ctx.cfg.snapshots = 0xFF; | 708 | ctx.cfg.snapshots = 0xFF; |
636 | scan++; | 709 | scan++; |
637 | scan_tree(argv[i] + 12, repo_config); | 710 | scan_tree(argv[i] + 12, repo_config); |
638 | } | 711 | } |
639 | } | 712 | } |
640 | if (scan) { | 713 | if (scan) { |
641 | qsort(cgit_repolist.repos, cgit_repolist.count, | 714 | qsort(cgit_repolist.repos, cgit_repolist.count, |
642 | sizeof(struct cgit_repo), cmp_repos); | 715 | sizeof(struct cgit_repo), cmp_repos); |
643 | print_repolist(stdout, &cgit_repolist, 0); | 716 | print_repolist(stdout, &cgit_repolist, 0); |
644 | exit(0); | 717 | exit(0); |
645 | } | 718 | } |
646 | } | 719 | } |
647 | 720 | ||
648 | static int calc_ttl() | 721 | static int calc_ttl() |
649 | { | 722 | { |
650 | if (!ctx.repo) | 723 | if (!ctx.repo) |
651 | return ctx.cfg.cache_root_ttl; | 724 | return ctx.cfg.cache_root_ttl; |
652 | 725 | ||
653 | if (!ctx.qry.page) | 726 | if (!ctx.qry.page) |
654 | return ctx.cfg.cache_repo_ttl; | 727 | return ctx.cfg.cache_repo_ttl; |
655 | 728 | ||
656 | if (ctx.qry.has_symref) | 729 | if (ctx.qry.has_symref) |
657 | return ctx.cfg.cache_dynamic_ttl; | 730 | return ctx.cfg.cache_dynamic_ttl; |
658 | 731 | ||
659 | if (ctx.qry.has_sha1) | 732 | if (ctx.qry.has_sha1) |
660 | return ctx.cfg.cache_static_ttl; | 733 | return ctx.cfg.cache_static_ttl; |
661 | 734 | ||
662 | return ctx.cfg.cache_repo_ttl; | 735 | return ctx.cfg.cache_repo_ttl; |
663 | } | 736 | } |
664 | 737 | ||
665 | int main(int argc, const char **argv) | 738 | int main(int argc, const char **argv) |
666 | { | 739 | { |
667 | const char *path; | 740 | const char *path; |
668 | char *qry; | 741 | char *qry; |
669 | int err, ttl; | 742 | int err, ttl; |
670 | 743 | ||
671 | prepare_context(&ctx); | 744 | prepare_context(&ctx); |
672 | cgit_repolist.length = 0; | 745 | cgit_repolist.length = 0; |
673 | cgit_repolist.count = 0; | 746 | cgit_repolist.count = 0; |
674 | cgit_repolist.repos = NULL; | 747 | cgit_repolist.repos = NULL; |
675 | 748 | ||
676 | cgit_parse_args(argc, argv); | 749 | cgit_parse_args(argc, argv); |
677 | parse_configfile(ctx.env.cgit_config, config_cb); | 750 | parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); |
678 | ctx.repo = NULL; | 751 | ctx.repo = NULL; |
679 | http_parse_querystring(ctx.qry.raw, querystring_cb); | 752 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
680 | 753 | ||
681 | /* If virtual-root isn't specified in cgitrc, lets pretend | 754 | /* If virtual-root isn't specified in cgitrc, lets pretend |
682 | * that virtual-root equals SCRIPT_NAME, minus any possibly | 755 | * that virtual-root equals SCRIPT_NAME, minus any possibly |
683 | * trailing slashes. | 756 | * trailing slashes. |
684 | */ | 757 | */ |
685 | if (!ctx.cfg.virtual_root) | 758 | if (!ctx.cfg.virtual_root) |
686 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); | 759 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); |
687 | 760 | ||
688 | /* If no url parameter is specified on the querystring, lets | 761 | /* If no url parameter is specified on the querystring, lets |
689 | * use PATH_INFO as url. This allows cgit to work with virtual | 762 | * use PATH_INFO as url. This allows cgit to work with virtual |
690 | * urls without the need for rewriterules in the webserver (as | 763 | * urls without the need for rewriterules in the webserver (as |
691 | * long as PATH_INFO is included in the cache lookup key). | 764 | * long as PATH_INFO is included in the cache lookup key). |
692 | */ | 765 | */ |
693 | path = ctx.env.path_info; | 766 | path = ctx.env.path_info; |
694 | if (!ctx.qry.url && path) { | 767 | if (!ctx.qry.url && path) { |
695 | if (path[0] == '/') | 768 | if (path[0] == '/') |
696 | path++; | 769 | path++; |
697 | ctx.qry.url = xstrdup(path); | 770 | ctx.qry.url = xstrdup(path); |
698 | if (ctx.qry.raw) { | 771 | if (ctx.qry.raw) { |
699 | qry = ctx.qry.raw; | 772 | qry = ctx.qry.raw; |
700 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); | 773 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
701 | free(qry); | 774 | free(qry); |
702 | } else | 775 | } else |
703 | ctx.qry.raw = xstrdup(ctx.qry.url); | 776 | ctx.qry.raw = xstrdup(ctx.qry.url); |
704 | cgit_parse_url(ctx.qry.url); | 777 | cgit_parse_url(ctx.qry.url); |
705 | } | 778 | } |
706 | 779 | ||
707 | ttl = calc_ttl(); | 780 | ttl = calc_ttl(); |
708 | ctx.page.expires += ttl*60; | 781 | ctx.page.expires += ttl*60; |
709 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) | 782 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
710 | ctx.cfg.nocache = 1; | 783 | ctx.cfg.nocache = 1; |
711 | if (ctx.cfg.nocache) | 784 | if (ctx.cfg.nocache) |
712 | ctx.cfg.cache_size = 0; | 785 | ctx.cfg.cache_size = 0; |
713 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, | 786 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
714 | ctx.qry.raw, ttl, process_request, &ctx); | 787 | ctx.qry.raw, ttl, process_request, &ctx); |
715 | if (err) | 788 | if (err) |
716 | cgit_print_error(fmt("Error processing page: %s (%d)", | 789 | cgit_print_error(fmt("Error processing page: %s (%d)", |
717 | strerror(err), err)); | 790 | strerror(err), err)); |
718 | return err; | 791 | return err; |
719 | } | 792 | } |
@@ -19,347 +19,405 @@ a { | |||
19 | a:hover { | 19 | a:hover { |
20 | text-decoration: underline; | 20 | text-decoration: underline; |
21 | } | 21 | } |
22 | 22 | ||
23 | table { | 23 | table { |
24 | border-collapse: collapse; | 24 | border-collapse: collapse; |
25 | } | 25 | } |
26 | 26 | ||
27 | table#header { | 27 | table#header { |
28 | width: 100%; | 28 | width: 100%; |
29 | margin-bottom: 1em; | 29 | margin-bottom: 1em; |
30 | } | 30 | } |
31 | 31 | ||
32 | table#header td.logo { | 32 | table#header td.logo { |
33 | width: 96px; | 33 | width: 96px; |
34 | } | 34 | } |
35 | 35 | ||
36 | table#header td.main { | 36 | table#header td.main { |
37 | font-size: 250%; | 37 | font-size: 250%; |
38 | padding-left: 10px; | 38 | padding-left: 10px; |
39 | white-space: nowrap; | 39 | white-space: nowrap; |
40 | } | 40 | } |
41 | 41 | ||
42 | table#header td.main a { | 42 | table#header td.main a { |
43 | color: #000; | 43 | color: #000; |
44 | } | 44 | } |
45 | 45 | ||
46 | table#header td.form { | 46 | table#header td.form { |
47 | text-align: right; | 47 | text-align: right; |
48 | vertical-align: bottom; | 48 | vertical-align: bottom; |
49 | padding-right: 1em; | 49 | padding-right: 1em; |
50 | padding-bottom: 2px; | 50 | padding-bottom: 2px; |
51 | white-space: nowrap; | 51 | white-space: nowrap; |
52 | } | 52 | } |
53 | 53 | ||
54 | table#header td.form form, | 54 | table#header td.form form, |
55 | table#header td.form input, | 55 | table#header td.form input, |
56 | table#header td.form select { | 56 | table#header td.form select { |
57 | font-size: 90%; | 57 | font-size: 90%; |
58 | } | 58 | } |
59 | 59 | ||
60 | table#header td.sub { | 60 | table#header td.sub { |
61 | color: #777; | 61 | color: #777; |
62 | border-top: solid 1px #ccc; | 62 | border-top: solid 1px #ccc; |
63 | padding-left: 10px; | 63 | padding-left: 10px; |
64 | } | 64 | } |
65 | 65 | ||
66 | table.tabs { | 66 | table.tabs { |
67 | /* border-bottom: solid 2px #ccc; */ | 67 | border-bottom: solid 3px #ccc; |
68 | border-collapse: collapse; | 68 | border-collapse: collapse; |
69 | margin-top: 2em; | 69 | margin-top: 2em; |
70 | margin-bottom: 0px; | 70 | margin-bottom: 0px; |
71 | width: 100%; | 71 | width: 100%; |
72 | } | 72 | } |
73 | 73 | ||
74 | table.tabs td { | 74 | table.tabs td { |
75 | padding: 0px 1em; | 75 | padding: 0px 1em; |
76 | vertical-align: bottom; | 76 | vertical-align: bottom; |
77 | } | 77 | } |
78 | 78 | ||
79 | table.tabs td a { | 79 | table.tabs td a { |
80 | padding: 2px 0.75em; | 80 | padding: 2px 0.75em; |
81 | color: #777; | 81 | color: #777; |
82 | font-size: 110%; | 82 | font-size: 110%; |
83 | } | 83 | } |
84 | 84 | ||
85 | table.tabs td a.active { | 85 | table.tabs td a.active { |
86 | color: #000; | 86 | color: #000; |
87 | background-color: #ccc; | 87 | background-color: #ccc; |
88 | } | 88 | } |
89 | 89 | ||
90 | table.tabs td.form { | 90 | table.tabs td.form { |
91 | text-align: right; | 91 | text-align: right; |
92 | } | 92 | } |
93 | 93 | ||
94 | table.tabs td.form form { | 94 | table.tabs td.form form { |
95 | padding-bottom: 2px; | 95 | padding-bottom: 2px; |
96 | font-size: 90%; | 96 | font-size: 90%; |
97 | white-space: nowrap; | 97 | white-space: nowrap; |
98 | } | 98 | } |
99 | 99 | ||
100 | table.tabs td.form input, | 100 | table.tabs td.form input, |
101 | table.tabs td.form select { | 101 | table.tabs td.form select { |
102 | font-size: 90%; | 102 | font-size: 90%; |
103 | } | 103 | } |
104 | 104 | ||
105 | div.path { | ||
106 | margin: 0px; | ||
107 | padding: 5px 2em 2px 2em; | ||
108 | color: #000; | ||
109 | background-color: #eee; | ||
110 | } | ||
111 | |||
105 | div.content { | 112 | div.content { |
106 | margin: 0px; | 113 | margin: 0px; |
107 | padding: 2em; | 114 | padding: 2em; |
108 | border-top: solid 3px #ccc; | ||
109 | border-bottom: solid 3px #ccc; | 115 | border-bottom: solid 3px #ccc; |
110 | } | 116 | } |
111 | 117 | ||
112 | 118 | ||
113 | table.list { | 119 | table.list { |
114 | width: 100%; | 120 | width: 100%; |
115 | border: none; | 121 | border: none; |
116 | border-collapse: collapse; | 122 | border-collapse: collapse; |
117 | } | 123 | } |
118 | 124 | ||
119 | table.list tr { | 125 | table.list tr { |
120 | background: white; | 126 | background: white; |
121 | } | 127 | } |
122 | 128 | ||
123 | table.list tr.logheader { | 129 | table.list tr.logheader { |
124 | background: #eee; | 130 | background: #eee; |
125 | } | 131 | } |
126 | 132 | ||
127 | table.list tr:hover { | 133 | table.list tr:hover { |
128 | background: #eee; | 134 | background: #eee; |
129 | } | 135 | } |
130 | 136 | ||
131 | table.list tr.nohover:hover { | 137 | table.list tr.nohover:hover { |
132 | background: white; | 138 | background: white; |
133 | } | 139 | } |
134 | 140 | ||
135 | table.list th { | 141 | table.list th { |
136 | font-weight: bold; | 142 | font-weight: bold; |
137 | /* color: #888; | 143 | /* color: #888; |
138 | border-top: dashed 1px #888; | 144 | border-top: dashed 1px #888; |
139 | border-bottom: dashed 1px #888; | 145 | border-bottom: dashed 1px #888; |
140 | */ | 146 | */ |
141 | padding: 0.1em 0.5em 0.05em 0.5em; | 147 | padding: 0.1em 0.5em 0.05em 0.5em; |
142 | vertical-align: baseline; | 148 | vertical-align: baseline; |
143 | } | 149 | } |
144 | 150 | ||
145 | table.list td { | 151 | table.list td { |
146 | border: none; | 152 | border: none; |
147 | padding: 0.1em 0.5em 0.1em 0.5em; | 153 | padding: 0.1em 0.5em 0.1em 0.5em; |
148 | } | 154 | } |
149 | 155 | ||
156 | table.list td.commitgraph { | ||
157 | font-family: monospace; | ||
158 | white-space: pre; | ||
159 | } | ||
160 | |||
161 | table.list td.commitgraph .column1 { | ||
162 | color: #a00; | ||
163 | } | ||
164 | |||
165 | table.list td.commitgraph .column2 { | ||
166 | color: #0a0; | ||
167 | } | ||
168 | |||
169 | table.list td.commitgraph .column3 { | ||
170 | color: #aa0; | ||
171 | } | ||
172 | |||
173 | table.list td.commitgraph .column4 { | ||
174 | color: #00a; | ||
175 | } | ||
176 | |||
177 | table.list td.commitgraph .column5 { | ||
178 | color: #a0a; | ||
179 | } | ||
180 | |||
181 | table.list td.commitgraph .column6 { | ||
182 | color: #0aa; | ||
183 | } | ||
184 | |||
150 | table.list td.logsubject { | 185 | table.list td.logsubject { |
151 | font-family: monospace; | 186 | font-family: monospace; |
152 | font-weight: bold; | 187 | font-weight: bold; |
153 | } | 188 | } |
154 | 189 | ||
155 | table.list td.logmsg { | 190 | table.list td.logmsg { |
156 | font-family: monospace; | 191 | font-family: monospace; |
157 | white-space: pre; | 192 | white-space: pre; |
158 | padding: 1em 0.5em 2em 0.5em; | 193 | padding: 0 0.5em; |
159 | } | 194 | } |
160 | 195 | ||
161 | table.list td a { | 196 | table.list td a { |
162 | color: black; | 197 | color: black; |
163 | } | 198 | } |
164 | 199 | ||
200 | table.list td a.ls-dir { | ||
201 | font-weight: bold; | ||
202 | color: #00f; | ||
203 | } | ||
204 | |||
165 | table.list td a:hover { | 205 | table.list td a:hover { |
166 | color: #00f; | 206 | color: #00f; |
167 | } | 207 | } |
168 | 208 | ||
169 | img { | 209 | img { |
170 | border: none; | 210 | border: none; |
171 | } | 211 | } |
172 | 212 | ||
173 | input#switch-btn { | 213 | input#switch-btn { |
174 | margin: 2px 0px 0px 0px; | 214 | margin: 2px 0px 0px 0px; |
175 | } | 215 | } |
176 | 216 | ||
177 | td#sidebar input.txt { | 217 | td#sidebar input.txt { |
178 | width: 100%; | 218 | width: 100%; |
179 | margin: 2px 0px 0px 0px; | 219 | margin: 2px 0px 0px 0px; |
180 | } | 220 | } |
181 | 221 | ||
182 | table#grid { | 222 | table#grid { |
183 | margin: 0px; | 223 | margin: 0px; |
184 | } | 224 | } |
185 | 225 | ||
186 | td#content { | 226 | td#content { |
187 | vertical-align: top; | 227 | vertical-align: top; |
188 | padding: 1em 2em 1em 1em; | 228 | padding: 1em 2em 1em 1em; |
189 | border: none; | 229 | border: none; |
190 | } | 230 | } |
191 | 231 | ||
192 | div#summary { | 232 | div#summary { |
193 | vertical-align: top; | 233 | vertical-align: top; |
194 | margin-bottom: 1em; | 234 | margin-bottom: 1em; |
195 | } | 235 | } |
196 | 236 | ||
197 | table#downloads { | 237 | table#downloads { |
198 | float: right; | 238 | float: right; |
199 | border-collapse: collapse; | 239 | border-collapse: collapse; |
200 | border: solid 1px #777; | 240 | border: solid 1px #777; |
201 | margin-left: 0.5em; | 241 | margin-left: 0.5em; |
202 | margin-bottom: 0.5em; | 242 | margin-bottom: 0.5em; |
203 | } | 243 | } |
204 | 244 | ||
205 | table#downloads th { | 245 | table#downloads th { |
206 | background-color: #ccc; | 246 | background-color: #ccc; |
207 | } | 247 | } |
208 | 248 | ||
209 | div#blob { | 249 | div#blob { |
210 | border: solid 1px black; | 250 | border: solid 1px black; |
211 | } | 251 | } |
212 | 252 | ||
213 | div.error { | 253 | div.error { |
214 | color: red; | 254 | color: red; |
215 | font-weight: bold; | 255 | font-weight: bold; |
216 | margin: 1em 2em; | 256 | margin: 1em 2em; |
217 | } | 257 | } |
218 | 258 | ||
219 | a.ls-blob, a.ls-dir, a.ls-mod { | 259 | a.ls-blob, a.ls-dir, a.ls-mod { |
220 | font-family: monospace; | 260 | font-family: monospace; |
221 | } | 261 | } |
222 | 262 | ||
223 | td.ls-size { | 263 | td.ls-size { |
224 | text-align: right; | 264 | text-align: right; |
225 | font-family: monospace; | 265 | font-family: monospace; |
226 | width: 10em; | 266 | width: 10em; |
227 | } | 267 | } |
228 | 268 | ||
229 | td.ls-mode { | 269 | td.ls-mode { |
230 | font-family: monospace; | 270 | font-family: monospace; |
231 | width: 10em; | 271 | width: 10em; |
232 | } | 272 | } |
233 | 273 | ||
234 | table.blob { | 274 | table.blob { |
235 | margin-top: 0.5em; | 275 | margin-top: 0.5em; |
236 | border-top: solid 1px black; | 276 | border-top: solid 1px black; |
237 | } | 277 | } |
238 | 278 | ||
239 | table.blob td.lines { | 279 | table.blob td.lines { |
240 | margin: 0; padding: 0 0 0 0.5em; | 280 | margin: 0; padding: 0 0 0 0.5em; |
241 | vertical-align: top; | 281 | vertical-align: top; |
242 | color: black; | 282 | color: black; |
243 | } | 283 | } |
244 | 284 | ||
245 | table.blob td.linenumbers { | 285 | table.blob td.linenumbers { |
246 | margin: 0; padding: 0 0.5em 0 0.5em; | 286 | margin: 0; padding: 0 0.5em 0 0.5em; |
247 | vertical-align: top; | 287 | vertical-align: top; |
248 | text-align: right; | 288 | text-align: right; |
249 | border-right: 1px solid gray; | 289 | border-right: 1px solid gray; |
250 | } | 290 | } |
251 | 291 | ||
252 | table.blob pre { | 292 | table.blob pre { |
253 | padding: 0; margin: 0; | 293 | padding: 0; margin: 0; |
254 | } | 294 | } |
255 | 295 | ||
256 | table.blob a.no { | 296 | table.blob a.no, table.ssdiff a.no { |
257 | color: gray; | 297 | color: gray; |
258 | text-align: right; | 298 | text-align: right; |
259 | text-decoration: none; | 299 | text-decoration: none; |
260 | } | 300 | } |
261 | 301 | ||
262 | table.blob a.no a:hover { | 302 | table.blob a.no a:hover { |
263 | color: black; | 303 | color: black; |
264 | } | 304 | } |
265 | 305 | ||
266 | table.bin-blob { | 306 | table.bin-blob { |
267 | margin-top: 0.5em; | 307 | margin-top: 0.5em; |
268 | border: solid 1px black; | 308 | border: solid 1px black; |
269 | } | 309 | } |
270 | 310 | ||
271 | table.bin-blob th { | 311 | table.bin-blob th { |
272 | font-family: monospace; | 312 | font-family: monospace; |
273 | white-space: pre; | 313 | white-space: pre; |
274 | border: solid 1px #777; | 314 | border: solid 1px #777; |
275 | padding: 0.5em 1em; | 315 | padding: 0.5em 1em; |
276 | } | 316 | } |
277 | 317 | ||
278 | table.bin-blob td { | 318 | table.bin-blob td { |
279 | font-family: monospace; | 319 | font-family: monospace; |
280 | white-space: pre; | 320 | white-space: pre; |
281 | border-left: solid 1px #777; | 321 | border-left: solid 1px #777; |
282 | padding: 0em 1em; | 322 | padding: 0em 1em; |
283 | } | 323 | } |
284 | 324 | ||
285 | table.nowrap td { | 325 | table.nowrap td { |
286 | white-space: nowrap; | 326 | white-space: nowrap; |
287 | } | 327 | } |
288 | 328 | ||
289 | table.commit-info { | 329 | table.commit-info { |
290 | border-collapse: collapse; | 330 | border-collapse: collapse; |
291 | margin-top: 1.5em; | 331 | margin-top: 1.5em; |
292 | } | 332 | } |
293 | 333 | ||
294 | table.commit-info th { | 334 | table.commit-info th { |
295 | text-align: left; | 335 | text-align: left; |
296 | font-weight: normal; | 336 | font-weight: normal; |
297 | padding: 0.1em 1em 0.1em 0.1em; | 337 | padding: 0.1em 1em 0.1em 0.1em; |
298 | vertical-align: top; | 338 | vertical-align: top; |
299 | } | 339 | } |
300 | 340 | ||
301 | table.commit-info td { | 341 | table.commit-info td { |
302 | font-weight: normal; | 342 | font-weight: normal; |
303 | padding: 0.1em 1em 0.1em 0.1em; | 343 | padding: 0.1em 1em 0.1em 0.1em; |
304 | } | 344 | } |
305 | 345 | ||
306 | div.commit-subject { | 346 | div.commit-subject { |
307 | font-weight: bold; | 347 | font-weight: bold; |
308 | font-size: 125%; | 348 | font-size: 125%; |
309 | margin: 1.5em 0em 0.5em 0em; | 349 | margin: 1.5em 0em 0.5em 0em; |
310 | padding: 0em; | 350 | padding: 0em; |
311 | } | 351 | } |
312 | 352 | ||
313 | div.commit-msg { | 353 | div.commit-msg { |
314 | white-space: pre; | 354 | white-space: pre; |
315 | font-family: monospace; | 355 | font-family: monospace; |
316 | } | 356 | } |
317 | 357 | ||
358 | div.notes-header { | ||
359 | font-weight: bold; | ||
360 | padding-top: 1.5em; | ||
361 | } | ||
362 | |||
363 | div.notes { | ||
364 | white-space: pre; | ||
365 | font-family: monospace; | ||
366 | border: solid 1px #ee9; | ||
367 | background-color: #ffd; | ||
368 | padding: 0.3em 2em 0.3em 1em; | ||
369 | float: left; | ||
370 | } | ||
371 | |||
372 | div.notes-footer { | ||
373 | clear: left; | ||
374 | } | ||
375 | |||
318 | div.diffstat-header { | 376 | div.diffstat-header { |
319 | font-weight: bold; | 377 | font-weight: bold; |
320 | padding-top: 1.5em; | 378 | padding-top: 1.5em; |
321 | } | 379 | } |
322 | 380 | ||
323 | table.diffstat { | 381 | table.diffstat { |
324 | border-collapse: collapse; | 382 | border-collapse: collapse; |
325 | border: solid 1px #aaa; | 383 | border: solid 1px #aaa; |
326 | background-color: #eee; | 384 | background-color: #eee; |
327 | } | 385 | } |
328 | 386 | ||
329 | table.diffstat th { | 387 | table.diffstat th { |
330 | font-weight: normal; | 388 | font-weight: normal; |
331 | text-align: left; | 389 | text-align: left; |
332 | text-decoration: underline; | 390 | text-decoration: underline; |
333 | padding: 0.1em 1em 0.1em 0.1em; | 391 | padding: 0.1em 1em 0.1em 0.1em; |
334 | font-size: 100%; | 392 | font-size: 100%; |
335 | } | 393 | } |
336 | 394 | ||
337 | table.diffstat td { | 395 | table.diffstat td { |
338 | padding: 0.2em 0.2em 0.1em 0.1em; | 396 | padding: 0.2em 0.2em 0.1em 0.1em; |
339 | font-size: 100%; | 397 | font-size: 100%; |
340 | border: none; | 398 | border: none; |
341 | } | 399 | } |
342 | 400 | ||
343 | table.diffstat td.mode { | 401 | table.diffstat td.mode { |
344 | white-space: nowrap; | 402 | white-space: nowrap; |
345 | } | 403 | } |
346 | 404 | ||
347 | table.diffstat td span.modechange { | 405 | table.diffstat td span.modechange { |
348 | padding-left: 1em; | 406 | padding-left: 1em; |
349 | color: red; | 407 | color: red; |
350 | } | 408 | } |
351 | 409 | ||
352 | table.diffstat td.add a { | 410 | table.diffstat td.add a { |
353 | color: green; | 411 | color: green; |
354 | } | 412 | } |
355 | 413 | ||
356 | table.diffstat td.del a { | 414 | table.diffstat td.del a { |
357 | color: red; | 415 | color: red; |
358 | } | 416 | } |
359 | 417 | ||
360 | table.diffstat td.upd a { | 418 | table.diffstat td.upd a { |
361 | color: blue; | 419 | color: blue; |
362 | } | 420 | } |
363 | 421 | ||
364 | table.diffstat td.graph { | 422 | table.diffstat td.graph { |
365 | width: 500px; | 423 | width: 500px; |
@@ -475,129 +533,245 @@ span.age-hours { | |||
475 | } | 533 | } |
476 | 534 | ||
477 | span.age-days { | 535 | span.age-days { |
478 | color: #040; | 536 | color: #040; |
479 | } | 537 | } |
480 | 538 | ||
481 | span.age-weeks { | 539 | span.age-weeks { |
482 | color: #444; | 540 | color: #444; |
483 | } | 541 | } |
484 | 542 | ||
485 | span.age-months { | 543 | span.age-months { |
486 | color: #888; | 544 | color: #888; |
487 | } | 545 | } |
488 | 546 | ||
489 | span.age-years { | 547 | span.age-years { |
490 | color: #bbb; | 548 | color: #bbb; |
491 | } | 549 | } |
492 | div.footer { | 550 | div.footer { |
493 | margin-top: 0.5em; | 551 | margin-top: 0.5em; |
494 | text-align: center; | 552 | text-align: center; |
495 | font-size: 80%; | 553 | font-size: 80%; |
496 | color: #ccc; | 554 | color: #ccc; |
497 | } | 555 | } |
498 | a.branch-deco { | 556 | a.branch-deco { |
499 | margin: 0px 0.5em; | 557 | margin: 0px 0.5em; |
500 | padding: 0px 0.25em; | 558 | padding: 0px 0.25em; |
501 | background-color: #88ff88; | 559 | background-color: #88ff88; |
502 | border: solid 1px #007700; | 560 | border: solid 1px #007700; |
503 | } | 561 | } |
504 | a.tag-deco { | 562 | a.tag-deco { |
505 | margin: 0px 0.5em; | 563 | margin: 0px 0.5em; |
506 | padding: 0px 0.25em; | 564 | padding: 0px 0.25em; |
507 | background-color: #ffff88; | 565 | background-color: #ffff88; |
508 | border: solid 1px #777700; | 566 | border: solid 1px #777700; |
509 | } | 567 | } |
510 | a.remote-deco { | 568 | a.remote-deco { |
511 | margin: 0px 0.5em; | 569 | margin: 0px 0.5em; |
512 | padding: 0px 0.25em; | 570 | padding: 0px 0.25em; |
513 | background-color: #ccccff; | 571 | background-color: #ccccff; |
514 | border: solid 1px #000077; | 572 | border: solid 1px #000077; |
515 | } | 573 | } |
516 | a.deco { | 574 | a.deco { |
517 | margin: 0px 0.5em; | 575 | margin: 0px 0.5em; |
518 | padding: 0px 0.25em; | 576 | padding: 0px 0.25em; |
519 | background-color: #ff8888; | 577 | background-color: #ff8888; |
520 | border: solid 1px #770000; | 578 | border: solid 1px #770000; |
521 | } | 579 | } |
522 | 580 | ||
523 | div.commit-subject a { | 581 | div.commit-subject a.branch-deco, |
582 | div.commit-subject a.tag-deco, | ||
583 | div.commit-subject a.remote-deco, | ||
584 | div.commit-subject a.deco { | ||
524 | margin-left: 1em; | 585 | margin-left: 1em; |
525 | font-size: 75%; | 586 | font-size: 75%; |
526 | } | 587 | } |
527 | 588 | ||
528 | table.stats { | 589 | table.stats { |
529 | border: solid 1px black; | 590 | border: solid 1px black; |
530 | border-collapse: collapse; | 591 | border-collapse: collapse; |
531 | } | 592 | } |
532 | 593 | ||
533 | table.stats th { | 594 | table.stats th { |
534 | text-align: left; | 595 | text-align: left; |
535 | padding: 1px 0.5em; | 596 | padding: 1px 0.5em; |
536 | background-color: #eee; | 597 | background-color: #eee; |
537 | border: solid 1px black; | 598 | border: solid 1px black; |
538 | } | 599 | } |
539 | 600 | ||
540 | table.stats td { | 601 | table.stats td { |
541 | text-align: right; | 602 | text-align: right; |
542 | padding: 1px 0.5em; | 603 | padding: 1px 0.5em; |
543 | border: solid 1px black; | 604 | border: solid 1px black; |
544 | } | 605 | } |
545 | 606 | ||
546 | table.stats td.total { | 607 | table.stats td.total { |
547 | font-weight: bold; | 608 | font-weight: bold; |
548 | text-align: left; | 609 | text-align: left; |
549 | } | 610 | } |
550 | 611 | ||
551 | table.stats td.sum { | 612 | table.stats td.sum { |
552 | color: #c00; | 613 | color: #c00; |
553 | font-weight: bold; | 614 | font-weight: bold; |
554 | /*background-color: #eee; */ | 615 | /*background-color: #eee; */ |
555 | } | 616 | } |
556 | 617 | ||
557 | table.stats td.left { | 618 | table.stats td.left { |
558 | text-align: left; | 619 | text-align: left; |
559 | } | 620 | } |
560 | 621 | ||
561 | table.vgraph { | 622 | table.vgraph { |
562 | border-collapse: separate; | 623 | border-collapse: separate; |
563 | border: solid 1px black; | 624 | border: solid 1px black; |
564 | height: 200px; | 625 | height: 200px; |
565 | } | 626 | } |
566 | 627 | ||
567 | table.vgraph th { | 628 | table.vgraph th { |
568 | background-color: #eee; | 629 | background-color: #eee; |
569 | font-weight: bold; | 630 | font-weight: bold; |
570 | border: solid 1px white; | 631 | border: solid 1px white; |
571 | padding: 1px 0.5em; | 632 | padding: 1px 0.5em; |
572 | } | 633 | } |
573 | 634 | ||
574 | table.vgraph td { | 635 | table.vgraph td { |
575 | vertical-align: bottom; | 636 | vertical-align: bottom; |
576 | padding: 0px 10px; | 637 | padding: 0px 10px; |
577 | } | 638 | } |
578 | 639 | ||
579 | table.vgraph div.bar { | 640 | table.vgraph div.bar { |
580 | background-color: #eee; | 641 | background-color: #eee; |
581 | } | 642 | } |
582 | 643 | ||
583 | table.hgraph { | 644 | table.hgraph { |
584 | border: solid 1px black; | 645 | border: solid 1px black; |
585 | width: 800px; | 646 | width: 800px; |
586 | } | 647 | } |
587 | 648 | ||
588 | table.hgraph th { | 649 | table.hgraph th { |
589 | background-color: #eee; | 650 | background-color: #eee; |
590 | font-weight: bold; | 651 | font-weight: bold; |
591 | border: solid 1px black; | 652 | border: solid 1px black; |
592 | padding: 1px 0.5em; | 653 | padding: 1px 0.5em; |
593 | } | 654 | } |
594 | 655 | ||
595 | table.hgraph td { | 656 | table.hgraph td { |
596 | vertical-align: center; | 657 | vertical-align: center; |
597 | padding: 2px 2px; | 658 | padding: 2px 2px; |
598 | } | 659 | } |
599 | 660 | ||
600 | table.hgraph div.bar { | 661 | table.hgraph div.bar { |
601 | background-color: #eee; | 662 | background-color: #eee; |
602 | height: 1em; | 663 | height: 1em; |
603 | } | 664 | } |
665 | |||
666 | table.ssdiff { | ||
667 | width: 100%; | ||
668 | } | ||
669 | |||
670 | table.ssdiff td { | ||
671 | font-size: 75%; | ||
672 | font-family: monospace; | ||
673 | white-space: pre; | ||
674 | padding: 1px 4px 1px 4px; | ||
675 | border-left: solid 1px #aaa; | ||
676 | border-right: solid 1px #aaa; | ||
677 | } | ||
678 | |||
679 | table.ssdiff td.add { | ||
680 | color: black; | ||
681 | background: #cfc; | ||
682 | min-width: 50%; | ||
683 | } | ||
684 | |||
685 | table.ssdiff td.add_dark { | ||
686 | color: black; | ||
687 | background: #aca; | ||
688 | min-width: 50%; | ||
689 | } | ||
690 | |||
691 | table.ssdiff span.add { | ||
692 | background: #cfc; | ||
693 | font-weight: bold; | ||
694 | } | ||
695 | |||
696 | table.ssdiff td.del { | ||
697 | color: black; | ||
698 | background: #fcc; | ||
699 | min-width: 50%; | ||
700 | } | ||
701 | |||
702 | table.ssdiff td.del_dark { | ||
703 | color: black; | ||
704 | background: #caa; | ||
705 | min-width: 50%; | ||
706 | } | ||
707 | |||
708 | table.ssdiff span.del { | ||
709 | background: #fcc; | ||
710 | font-weight: bold; | ||
711 | } | ||
712 | |||
713 | table.ssdiff td.changed { | ||
714 | color: black; | ||
715 | background: #ffc; | ||
716 | min-width: 50%; | ||
717 | } | ||
718 | |||
719 | table.ssdiff td.changed_dark { | ||
720 | color: black; | ||
721 | background: #cca; | ||
722 | min-width: 50%; | ||
723 | } | ||
724 | |||
725 | table.ssdiff td.lineno { | ||
726 | color: black; | ||
727 | background: #eee; | ||
728 | text-align: right; | ||
729 | width: 3em; | ||
730 | min-width: 3em; | ||
731 | } | ||
732 | |||
733 | table.ssdiff td.hunk { | ||
734 | color: #black; | ||
735 | background: #ccf; | ||
736 | border-top: solid 1px #aaa; | ||
737 | border-bottom: solid 1px #aaa; | ||
738 | } | ||
739 | |||
740 | table.ssdiff td.head { | ||
741 | border-top: solid 1px #aaa; | ||
742 | border-bottom: solid 1px #aaa; | ||
743 | } | ||
744 | |||
745 | table.ssdiff td.head div.head { | ||
746 | font-weight: bold; | ||
747 | color: black; | ||
748 | } | ||
749 | |||
750 | table.ssdiff td.foot { | ||
751 | border-top: solid 1px #aaa; | ||
752 | border-left: none; | ||
753 | border-right: none; | ||
754 | border-bottom: none; | ||
755 | } | ||
756 | |||
757 | table.ssdiff td.space { | ||
758 | border: none; | ||
759 | } | ||
760 | |||
761 | table.ssdiff td.space div { | ||
762 | min-height: 3em; | ||
763 | } | ||
764 | |||
765 | /* Syntax highlighting */ | ||
766 | table.blob .num { color:#2928ff; } | ||
767 | table.blob .esc { color:#ff00ff; } | ||
768 | table.blob .str { color:#ff0000; } | ||
769 | table.blob .dstr { color:#818100; } | ||
770 | table.blob .slc { color:#838183; font-style:italic; } | ||
771 | table.blob .com { color:#838183; font-style:italic; } | ||
772 | table.blob .dir { color:#008200; } | ||
773 | table.blob .sym { color:#000000; } | ||
774 | table.blob .kwa { color:#000000; font-weight:bold; } | ||
775 | table.blob .kwb { color:#830000; } | ||
776 | table.blob .kwc { color:#000000; font-weight:bold; } | ||
777 | table.blob .kwd { color:#010181; } | ||
@@ -1,294 +1,324 @@ | |||
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 <string-list.h> | 18 | #include <string-list.h> |
19 | #include <xdiff-interface.h> | 19 | #include <xdiff-interface.h> |
20 | #include <xdiff/xdiff.h> | 20 | #include <xdiff/xdiff.h> |
21 | #include <utf8.h> | 21 | #include <utf8.h> |
22 | #include <notes.h> | ||
23 | #include <graph.h> | ||
22 | 24 | ||
23 | 25 | ||
24 | /* | 26 | /* |
25 | * Dateformats used on misc. pages | 27 | * Dateformats used on misc. pages |
26 | */ | 28 | */ |
27 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" | 29 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" |
28 | #define FMT_SHORTDATE "%Y-%m-%d" | 30 | #define FMT_SHORTDATE "%Y-%m-%d" |
29 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" | 31 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" |
30 | 32 | ||
31 | 33 | ||
32 | /* | 34 | /* |
33 | * Limits used for relative dates | 35 | * Limits used for relative dates |
34 | */ | 36 | */ |
35 | #define TM_MIN 60 | 37 | #define TM_MIN 60 |
36 | #define TM_HOUR (TM_MIN * 60) | 38 | #define TM_HOUR (TM_MIN * 60) |
37 | #define TM_DAY (TM_HOUR * 24) | 39 | #define TM_DAY (TM_HOUR * 24) |
38 | #define TM_WEEK (TM_DAY * 7) | 40 | #define TM_WEEK (TM_DAY * 7) |
39 | #define TM_YEAR (TM_DAY * 365) | 41 | #define TM_YEAR (TM_DAY * 365) |
40 | #define TM_MONTH (TM_YEAR / 12.0) | 42 | #define TM_MONTH (TM_YEAR / 12.0) |
41 | 43 | ||
42 | 44 | ||
43 | /* | 45 | /* |
44 | * Default encoding | 46 | * Default encoding |
45 | */ | 47 | */ |
46 | #define PAGE_ENCODING "UTF-8" | 48 | #define PAGE_ENCODING "UTF-8" |
47 | 49 | ||
48 | typedef void (*configfn)(const char *name, const char *value); | 50 | typedef void (*configfn)(const char *name, const char *value); |
49 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 51 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
50 | typedef void (*linediff_fn)(char *line, int len); | 52 | typedef void (*linediff_fn)(char *line, int len); |
51 | 53 | ||
52 | struct cgit_filter { | 54 | struct cgit_filter { |
53 | char *cmd; | 55 | char *cmd; |
54 | char **argv; | 56 | char **argv; |
55 | int old_stdout; | 57 | int old_stdout; |
56 | int pipe_fh[2]; | 58 | int pipe_fh[2]; |
57 | int pid; | 59 | int pid; |
58 | int exitstatus; | 60 | int exitstatus; |
59 | }; | 61 | }; |
60 | 62 | ||
61 | struct cgit_repo { | 63 | struct cgit_repo { |
62 | char *url; | 64 | char *url; |
63 | char *name; | 65 | char *name; |
64 | char *path; | 66 | char *path; |
65 | char *desc; | 67 | char *desc; |
66 | char *owner; | 68 | char *owner; |
67 | char *defbranch; | 69 | char *defbranch; |
68 | char *module_link; | 70 | char *module_link; |
69 | char *readme; | 71 | char *readme; |
70 | char *section; | 72 | char *section; |
71 | char *clone_url; | 73 | char *clone_url; |
74 | char *logo; | ||
75 | char *logo_link; | ||
72 | int snapshots; | 76 | int snapshots; |
77 | int enable_commit_graph; | ||
73 | int enable_log_filecount; | 78 | int enable_log_filecount; |
74 | int enable_log_linecount; | 79 | int enable_log_linecount; |
80 | int enable_remote_branches; | ||
81 | int enable_subject_links; | ||
75 | int max_stats; | 82 | int max_stats; |
76 | time_t mtime; | 83 | time_t mtime; |
77 | struct cgit_filter *about_filter; | 84 | struct cgit_filter *about_filter; |
78 | struct cgit_filter *commit_filter; | 85 | struct cgit_filter *commit_filter; |
79 | struct cgit_filter *source_filter; | 86 | struct cgit_filter *source_filter; |
80 | }; | 87 | }; |
81 | 88 | ||
82 | typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, | 89 | typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, |
83 | const char *value); | 90 | const char *value); |
84 | 91 | ||
85 | struct cgit_repolist { | 92 | struct cgit_repolist { |
86 | int length; | 93 | int length; |
87 | int count; | 94 | int count; |
88 | struct cgit_repo *repos; | 95 | struct cgit_repo *repos; |
89 | }; | 96 | }; |
90 | 97 | ||
91 | struct commitinfo { | 98 | struct commitinfo { |
92 | struct commit *commit; | 99 | struct commit *commit; |
93 | char *author; | 100 | char *author; |
94 | char *author_email; | 101 | char *author_email; |
95 | unsigned long author_date; | 102 | unsigned long author_date; |
96 | char *committer; | 103 | char *committer; |
97 | char *committer_email; | 104 | char *committer_email; |
98 | unsigned long committer_date; | 105 | unsigned long committer_date; |
99 | char *subject; | 106 | char *subject; |
100 | char *msg; | 107 | char *msg; |
101 | char *msg_encoding; | 108 | char *msg_encoding; |
102 | }; | 109 | }; |
103 | 110 | ||
104 | struct taginfo { | 111 | struct taginfo { |
105 | char *tagger; | 112 | char *tagger; |
106 | char *tagger_email; | 113 | char *tagger_email; |
107 | unsigned long tagger_date; | 114 | unsigned long tagger_date; |
108 | char *msg; | 115 | char *msg; |
109 | }; | 116 | }; |
110 | 117 | ||
111 | struct refinfo { | 118 | struct refinfo { |
112 | const char *refname; | 119 | const char *refname; |
113 | struct object *object; | 120 | struct object *object; |
114 | union { | 121 | union { |
115 | struct taginfo *tag; | 122 | struct taginfo *tag; |
116 | struct commitinfo *commit; | 123 | struct commitinfo *commit; |
117 | }; | 124 | }; |
118 | }; | 125 | }; |
119 | 126 | ||
120 | struct reflist { | 127 | struct reflist { |
121 | struct refinfo **refs; | 128 | struct refinfo **refs; |
122 | int alloc; | 129 | int alloc; |
123 | int count; | 130 | int count; |
124 | }; | 131 | }; |
125 | 132 | ||
126 | struct cgit_query { | 133 | struct cgit_query { |
127 | int has_symref; | 134 | int has_symref; |
128 | int has_sha1; | 135 | int has_sha1; |
129 | char *raw; | 136 | char *raw; |
130 | char *repo; | 137 | char *repo; |
131 | char *page; | 138 | char *page; |
132 | char *search; | 139 | char *search; |
133 | char *grep; | 140 | char *grep; |
134 | char *head; | 141 | char *head; |
135 | char *sha1; | 142 | char *sha1; |
136 | char *sha2; | 143 | char *sha2; |
137 | char *path; | 144 | char *path; |
138 | char *name; | 145 | char *name; |
139 | char *mimetype; | 146 | char *mimetype; |
140 | char *url; | 147 | char *url; |
141 | char *period; | 148 | char *period; |
142 | int ofs; | 149 | int ofs; |
143 | int nohead; | 150 | int nohead; |
144 | char *sort; | 151 | char *sort; |
145 | int showmsg; | 152 | int showmsg; |
153 | int ssdiff; | ||
154 | int show_all; | ||
155 | int context; | ||
156 | int ignorews; | ||
157 | char *vpath; | ||
146 | }; | 158 | }; |
147 | 159 | ||
148 | struct cgit_config { | 160 | struct cgit_config { |
149 | char *agefile; | 161 | char *agefile; |
150 | char *cache_root; | 162 | char *cache_root; |
151 | char *clone_prefix; | 163 | char *clone_prefix; |
152 | char *css; | 164 | char *css; |
153 | char *favicon; | 165 | char *favicon; |
154 | char *footer; | 166 | char *footer; |
155 | char *head_include; | 167 | char *head_include; |
156 | char *header; | 168 | char *header; |
157 | char *index_header; | 169 | char *index_header; |
158 | char *index_info; | 170 | char *index_info; |
159 | char *logo; | 171 | char *logo; |
160 | char *logo_link; | 172 | char *logo_link; |
161 | char *module_link; | 173 | char *module_link; |
174 | char *project_list; | ||
175 | char *readme; | ||
162 | char *robots; | 176 | char *robots; |
163 | char *root_title; | 177 | char *root_title; |
164 | char *root_desc; | 178 | char *root_desc; |
165 | char *root_readme; | 179 | char *root_readme; |
166 | char *script_name; | 180 | char *script_name; |
167 | char *section; | 181 | char *section; |
168 | char *virtual_root; | 182 | char *virtual_root; |
183 | char *strict_export; | ||
169 | int cache_size; | 184 | int cache_size; |
170 | int cache_dynamic_ttl; | 185 | int cache_dynamic_ttl; |
171 | int cache_max_create_time; | 186 | int cache_max_create_time; |
172 | int cache_repo_ttl; | 187 | int cache_repo_ttl; |
173 | int cache_root_ttl; | 188 | int cache_root_ttl; |
174 | int cache_scanrc_ttl; | 189 | int cache_scanrc_ttl; |
175 | int cache_static_ttl; | 190 | int cache_static_ttl; |
176 | int embedded; | 191 | int embedded; |
177 | int enable_filter_overrides; | 192 | int enable_filter_overrides; |
193 | int enable_gitweb_owner; | ||
178 | int enable_index_links; | 194 | int enable_index_links; |
195 | int enable_commit_graph; | ||
179 | int enable_log_filecount; | 196 | int enable_log_filecount; |
180 | int enable_log_linecount; | 197 | int enable_log_linecount; |
198 | int enable_remote_branches; | ||
199 | int enable_subject_links; | ||
181 | int enable_tree_linenumbers; | 200 | int enable_tree_linenumbers; |
182 | int local_time; | 201 | int local_time; |
202 | int max_atom_items; | ||
183 | int max_repo_count; | 203 | int max_repo_count; |
184 | int max_commit_count; | 204 | int max_commit_count; |
185 | int max_lock_attempts; | 205 | int max_lock_attempts; |
186 | int max_msg_len; | 206 | int max_msg_len; |
187 | int max_repodesc_len; | 207 | int max_repodesc_len; |
208 | int max_blob_size; | ||
188 | int max_stats; | 209 | int max_stats; |
189 | int nocache; | 210 | int nocache; |
190 | int noplainemail; | 211 | int noplainemail; |
191 | int noheader; | 212 | int noheader; |
192 | int renamelimit; | 213 | int renamelimit; |
214 | int remove_suffix; | ||
215 | int scan_hidden_path; | ||
216 | int section_from_path; | ||
193 | int snapshots; | 217 | int snapshots; |
194 | int summary_branches; | 218 | int summary_branches; |
195 | int summary_log; | 219 | int summary_log; |
196 | int summary_tags; | 220 | int summary_tags; |
221 | int ssdiff; | ||
197 | struct string_list mimetypes; | 222 | struct string_list mimetypes; |
198 | struct cgit_filter *about_filter; | 223 | struct cgit_filter *about_filter; |
199 | struct cgit_filter *commit_filter; | 224 | struct cgit_filter *commit_filter; |
200 | struct cgit_filter *source_filter; | 225 | struct cgit_filter *source_filter; |
201 | }; | 226 | }; |
202 | 227 | ||
203 | struct cgit_page { | 228 | struct cgit_page { |
204 | time_t modified; | 229 | time_t modified; |
205 | time_t expires; | 230 | time_t expires; |
206 | size_t size; | 231 | size_t size; |
207 | char *mimetype; | 232 | char *mimetype; |
208 | char *charset; | 233 | char *charset; |
209 | char *filename; | 234 | char *filename; |
210 | char *etag; | 235 | char *etag; |
211 | char *title; | 236 | char *title; |
212 | int status; | 237 | int status; |
213 | char *statusmsg; | 238 | char *statusmsg; |
214 | }; | 239 | }; |
215 | 240 | ||
216 | struct cgit_environment { | 241 | struct cgit_environment { |
217 | char *cgit_config; | 242 | char *cgit_config; |
218 | char *http_host; | 243 | char *http_host; |
219 | char *https; | 244 | char *https; |
220 | char *no_http; | 245 | char *no_http; |
221 | char *path_info; | 246 | char *path_info; |
222 | char *query_string; | 247 | char *query_string; |
223 | char *request_method; | 248 | char *request_method; |
224 | char *script_name; | 249 | char *script_name; |
225 | char *server_name; | 250 | char *server_name; |
226 | char *server_port; | 251 | char *server_port; |
227 | }; | 252 | }; |
228 | 253 | ||
229 | struct cgit_context { | 254 | struct cgit_context { |
230 | struct cgit_environment env; | 255 | struct cgit_environment env; |
231 | struct cgit_query qry; | 256 | struct cgit_query qry; |
232 | struct cgit_config cfg; | 257 | struct cgit_config cfg; |
233 | struct cgit_repo *repo; | 258 | struct cgit_repo *repo; |
234 | struct cgit_page page; | 259 | struct cgit_page page; |
235 | }; | 260 | }; |
236 | 261 | ||
237 | struct cgit_snapshot_format { | 262 | struct cgit_snapshot_format { |
238 | const char *suffix; | 263 | const char *suffix; |
239 | const char *mimetype; | 264 | const char *mimetype; |
240 | write_archive_fn_t write_func; | 265 | write_archive_fn_t write_func; |
241 | int bit; | 266 | int bit; |
242 | }; | 267 | }; |
243 | 268 | ||
244 | extern const char *cgit_version; | 269 | extern const char *cgit_version; |
245 | 270 | ||
246 | extern struct cgit_repolist cgit_repolist; | 271 | extern struct cgit_repolist cgit_repolist; |
247 | extern struct cgit_context ctx; | 272 | extern struct cgit_context ctx; |
248 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; | 273 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
249 | 274 | ||
250 | extern struct cgit_repo *cgit_add_repo(const char *url); | 275 | extern struct cgit_repo *cgit_add_repo(const char *url); |
251 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); | 276 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
252 | extern void cgit_repo_config_cb(const char *name, const char *value); | 277 | extern void cgit_repo_config_cb(const char *name, const char *value); |
253 | 278 | ||
254 | extern int chk_zero(int result, char *msg); | 279 | extern int chk_zero(int result, char *msg); |
255 | extern int chk_positive(int result, char *msg); | 280 | extern int chk_positive(int result, char *msg); |
256 | extern int chk_non_negative(int result, char *msg); | 281 | extern int chk_non_negative(int result, char *msg); |
257 | 282 | ||
258 | extern char *trim_end(const char *str, char c); | 283 | extern char *trim_end(const char *str, char c); |
259 | extern char *strlpart(char *txt, int maxlen); | 284 | extern char *strlpart(char *txt, int maxlen); |
260 | extern char *strrpart(char *txt, int maxlen); | 285 | extern char *strrpart(char *txt, int maxlen); |
261 | 286 | ||
262 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 287 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
263 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 288 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
264 | int flags, void *cb_data); | 289 | int flags, void *cb_data); |
265 | 290 | ||
266 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 291 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
267 | 292 | ||
268 | extern int cgit_diff_files(const unsigned char *old_sha1, | 293 | extern int cgit_diff_files(const unsigned char *old_sha1, |
269 | const unsigned char *new_sha1, | 294 | const unsigned char *new_sha1, |
270 | unsigned long *old_size, unsigned long *new_size, | 295 | unsigned long *old_size, unsigned long *new_size, |
271 | int *binary, linediff_fn fn); | 296 | int *binary, int context, int ignorews, |
297 | linediff_fn fn); | ||
272 | 298 | ||
273 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 299 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
274 | const unsigned char *new_sha1, | 300 | const unsigned char *new_sha1, |
275 | filepair_fn fn, const char *prefix); | 301 | filepair_fn fn, const char *prefix, int ignorews); |
276 | 302 | ||
277 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 303 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, |
304 | const char *prefix); | ||
278 | 305 | ||
306 | __attribute__((format (printf,1,2))) | ||
279 | extern char *fmt(const char *format,...); | 307 | extern char *fmt(const char *format,...); |
280 | 308 | ||
281 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 309 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
282 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 310 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
283 | extern void cgit_parse_url(const char *url); | 311 | extern void cgit_parse_url(const char *url); |
284 | 312 | ||
285 | extern const char *cgit_repobasename(const char *reponame); | 313 | extern const char *cgit_repobasename(const char *reponame); |
286 | 314 | ||
287 | extern int cgit_parse_snapshots_mask(const char *str); | 315 | extern int cgit_parse_snapshots_mask(const char *str); |
288 | 316 | ||
289 | extern int cgit_open_filter(struct cgit_filter *filter); | 317 | extern int cgit_open_filter(struct cgit_filter *filter); |
290 | extern int cgit_close_filter(struct cgit_filter *filter); | 318 | extern int cgit_close_filter(struct cgit_filter *filter); |
291 | 319 | ||
292 | extern int readfile(const char *path, char **buf, size_t *size); | 320 | extern int readfile(const char *path, char **buf, size_t *size); |
293 | 321 | ||
322 | extern char *expand_macros(const char *txt); | ||
323 | |||
294 | #endif /* CGIT_H */ | 324 | #endif /* CGIT_H */ |
Binary files differ | |||
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 0c13485..c3698a6 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -46,456 +46,555 @@ cache-root:: | |||
46 | 46 | ||
47 | cache-dynamic-ttl:: | 47 | cache-dynamic-ttl:: |
48 | Number which specifies the time-to-live, in minutes, for the cached | 48 | Number which specifies the time-to-live, in minutes, for the cached |
49 | version of repository pages accessed without a fixed SHA1. Default | 49 | version of repository pages accessed without a fixed SHA1. Default |
50 | value: "5". | 50 | value: "5". |
51 | 51 | ||
52 | cache-repo-ttl:: | 52 | cache-repo-ttl:: |
53 | Number which specifies the time-to-live, in minutes, for the cached | 53 | Number which specifies the time-to-live, in minutes, for the cached |
54 | version of the repository summary page. Default value: "5". | 54 | version of the repository summary page. Default value: "5". |
55 | 55 | ||
56 | cache-root-ttl:: | 56 | cache-root-ttl:: |
57 | Number which specifies the time-to-live, in minutes, for the cached | 57 | Number which specifies the time-to-live, in minutes, for the cached |
58 | version of the repository index page. Default value: "5". | 58 | version of the repository index page. Default value: "5". |
59 | 59 | ||
60 | cache-scanrc-ttl:: | 60 | cache-scanrc-ttl:: |
61 | Number which specifies the time-to-live, in minutes, for the result | 61 | Number which specifies the time-to-live, in minutes, for the result |
62 | of scanning a path for git repositories. Default value: "15". | 62 | of scanning a path for git repositories. Default value: "15". |
63 | 63 | ||
64 | cache-size:: | 64 | cache-size:: |
65 | The maximum number of entries in the cgit cache. Default value: "0" | 65 | The maximum number of entries in the cgit cache. Default value: "0" |
66 | (i.e. caching is disabled). | 66 | (i.e. caching is disabled). |
67 | 67 | ||
68 | cache-static-ttl:: | 68 | cache-static-ttl:: |
69 | Number which specifies the time-to-live, in minutes, for the cached | 69 | Number which specifies the time-to-live, in minutes, for the cached |
70 | version of repository pages accessed with a fixed SHA1. Default value: | 70 | version of repository pages accessed with a fixed SHA1. Default value: |
71 | "5". | 71 | "5". |
72 | 72 | ||
73 | clone-prefix:: | 73 | clone-prefix:: |
74 | Space-separated list of common prefixes which, when combined with a | 74 | Space-separated list of common prefixes which, when combined with a |
75 | repository url, generates valid clone urls for the repository. This | 75 | repository url, generates valid clone urls for the repository. This |
76 | setting is only used if `repo.clone-url` is unspecified. Default value: | 76 | setting is only used if `repo.clone-url` is unspecified. Default value: |
77 | none. | 77 | none. |
78 | 78 | ||
79 | commit-filter:: | 79 | commit-filter:: |
80 | Specifies a command which will be invoked to format commit messages. | 80 | Specifies a command which will be invoked to format commit messages. |
81 | The command will get the message on its STDIN, and the STDOUT from the | 81 | The command will get the message on its STDIN, and the STDOUT from the |
82 | command will be included verbatim as the commit message, i.e. this can | 82 | command will be included verbatim as the commit message, i.e. this can |
83 | be used to implement bugtracker integration. Default value: none. | 83 | be used to implement bugtracker integration. Default value: none. |
84 | 84 | ||
85 | css:: | 85 | css:: |
86 | Url which specifies the css document to include in all cgit pages. | 86 | Url which specifies the css document to include in all cgit pages. |
87 | Default value: "/cgit.css". | 87 | Default value: "/cgit.css". |
88 | 88 | ||
89 | embedded:: | 89 | embedded:: |
90 | Flag which, when set to "1", will make cgit generate a html fragment | 90 | Flag which, when set to "1", will make cgit generate a html fragment |
91 | suitable for embedding in other html pages. Default value: none. See | 91 | suitable for embedding in other html pages. Default value: none. See |
92 | also: "noheader". | 92 | also: "noheader". |
93 | 93 | ||
94 | enable-commit-graph:: | ||
95 | Flag which, when set to "1", will make cgit print an ASCII-art commit | ||
96 | history graph to the left of the commit messages in the repository | ||
97 | log page. Default value: "0". | ||
98 | |||
94 | enable-filter-overrides:: | 99 | enable-filter-overrides:: |
95 | Flag which, when set to "1", allows all filter settings to be | 100 | Flag which, when set to "1", allows all filter settings to be |
96 | overridden in repository-specific cgitrc files. Default value: none. | 101 | overridden in repository-specific cgitrc files. Default value: none. |
97 | 102 | ||
103 | enable-gitweb-owner:: | ||
104 | If set to "1" and scan-path is enabled, we first check each repository | ||
105 | for the git config value "gitweb.owner" to determine the owner. | ||
106 | Default value: "1". See also: scan-path. | ||
107 | |||
98 | enable-index-links:: | 108 | enable-index-links:: |
99 | Flag which, when set to "1", will make cgit generate extra links for | 109 | Flag which, when set to "1", will make cgit generate extra links for |
100 | each repo in the repository index (specifically, to the "summary", | 110 | each repo in the repository index (specifically, to the "summary", |
101 | "commit" and "tree" pages). Default value: "0". | 111 | "commit" and "tree" pages). Default value: "0". |
102 | 112 | ||
103 | enable-log-filecount:: | 113 | enable-log-filecount:: |
104 | Flag which, when set to "1", will make cgit print the number of | 114 | Flag which, when set to "1", will make cgit print the number of |
105 | modified files for each commit on the repository log page. Default | 115 | modified files for each commit on the repository log page. Default |
106 | value: "0". | 116 | value: "0". |
107 | 117 | ||
108 | enable-log-linecount:: | 118 | enable-log-linecount:: |
109 | Flag which, when set to "1", will make cgit print the number of added | 119 | Flag which, when set to "1", will make cgit print the number of added |
110 | and removed lines for each commit on the repository log page. Default | 120 | and removed lines for each commit on the repository log page. Default |
111 | value: "0". | 121 | value: "0". |
112 | 122 | ||
123 | enable-remote-branches:: | ||
124 | Flag which, when set to "1", will make cgit display remote branches | ||
125 | in the summary and refs views. Default value: "0". See also: | ||
126 | "repo.enable-remote-branches". | ||
127 | |||
128 | enable-subject-links:: | ||
129 | Flag which, when set to "1", will make cgit use the subject of the | ||
130 | parent commit as link text when generating links to parent commits | ||
131 | in commit view. Default value: "0". See also: | ||
132 | "repo.enable-subject-links". | ||
133 | |||
113 | enable-tree-linenumbers:: | 134 | enable-tree-linenumbers:: |
114 | Flag which, when set to "1", will make cgit generate linenumber links | 135 | Flag which, when set to "1", will make cgit generate linenumber links |
115 | for plaintext blobs printed in the tree view. Default value: "1". | 136 | for plaintext blobs printed in the tree view. Default value: "1". |
116 | 137 | ||
117 | favicon:: | 138 | favicon:: |
118 | Url used as link to a shortcut icon for cgit. If specified, it is | 139 | Url used as link to a shortcut icon for cgit. If specified, it is |
119 | suggested to use the value "/favicon.ico" since certain browsers will | 140 | suggested to use the value "/favicon.ico" since certain browsers will |
120 | ignore other values. Default value: none. | 141 | ignore other values. Default value: none. |
121 | 142 | ||
122 | footer:: | 143 | footer:: |
123 | The content of the file specified with this option will be included | 144 | The content of the file specified with this option will be included |
124 | verbatim at the bottom of all pages (i.e. it replaces the standard | 145 | verbatim at the bottom of all pages (i.e. it replaces the standard |
125 | "generated by..." message. Default value: none. | 146 | "generated by..." message. Default value: none. |
126 | 147 | ||
127 | head-include:: | 148 | head-include:: |
128 | The content of the file specified with this option will be included | 149 | The content of the file specified with this option will be included |
129 | verbatim in the html HEAD section on all pages. Default value: none. | 150 | verbatim in the html HEAD section on all pages. Default value: none. |
130 | 151 | ||
131 | header:: | 152 | header:: |
132 | The content of the file specified with this option will be included | 153 | The content of the file specified with this option will be included |
133 | verbatim at the top of all pages. Default value: none. | 154 | verbatim at the top of all pages. Default value: none. |
134 | 155 | ||
135 | include:: | 156 | include:: |
136 | Name of a configfile to include before the rest of the current config- | 157 | Name of a configfile to include before the rest of the current config- |
137 | file is parsed. Default value: none. | 158 | file is parsed. Default value: none. |
138 | 159 | ||
139 | index-header:: | 160 | index-header:: |
140 | The content of the file specified with this option will be included | 161 | The content of the file specified with this option will be included |
141 | verbatim above the repository index. This setting is deprecated, and | 162 | verbatim above the repository index. This setting is deprecated, and |
142 | will not be supported by cgit-1.0 (use root-readme instead). Default | 163 | will not be supported by cgit-1.0 (use root-readme instead). Default |
143 | value: none. | 164 | value: none. |
144 | 165 | ||
145 | index-info:: | 166 | index-info:: |
146 | The content of the file specified with this option will be included | 167 | The content of the file specified with this option will be included |
147 | verbatim below the heading on the repository index page. This setting | 168 | verbatim below the heading on the repository index page. This setting |
148 | is deprecated, and will not be supported by cgit-1.0 (use root-desc | 169 | is deprecated, and will not be supported by cgit-1.0 (use root-desc |
149 | instead). Default value: none. | 170 | instead). Default value: none. |
150 | 171 | ||
151 | local-time:: | 172 | local-time:: |
152 | Flag which, if set to "1", makes cgit print commit and tag times in the | 173 | Flag which, if set to "1", makes cgit print commit and tag times in the |
153 | servers timezone. Default value: "0". | 174 | servers timezone. Default value: "0". |
154 | 175 | ||
155 | logo:: | 176 | logo:: |
156 | Url which specifies the source of an image which will be used as a logo | 177 | Url which specifies the source of an image which will be used as a logo |
157 | on all cgit pages. Default value: "/cgit.png". | 178 | on all cgit pages. Default value: "/cgit.png". |
158 | 179 | ||
159 | logo-link:: | 180 | logo-link:: |
160 | Url loaded when clicking on the cgit logo image. If unspecified the | 181 | Url loaded when clicking on the cgit logo image. If unspecified the |
161 | calculated url of the repository index page will be used. Default | 182 | calculated url of the repository index page will be used. Default |
162 | value: none. | 183 | value: none. |
163 | 184 | ||
185 | max-atom-items:: | ||
186 | Specifies the number of items to display in atom feeds view. Default | ||
187 | value: "10". | ||
188 | |||
164 | max-commit-count:: | 189 | max-commit-count:: |
165 | Specifies the number of entries to list per page in "log" view. Default | 190 | Specifies the number of entries to list per page in "log" view. Default |
166 | value: "50". | 191 | value: "50". |
167 | 192 | ||
168 | max-message-length:: | 193 | max-message-length:: |
169 | Specifies the maximum number of commit message characters to display in | 194 | Specifies the maximum number of commit message characters to display in |
170 | "log" view. Default value: "80". | 195 | "log" view. Default value: "80". |
171 | 196 | ||
172 | max-repo-count:: | 197 | max-repo-count:: |
173 | Specifies the number of entries to list per page on therepository | 198 | Specifies the number of entries to list per page on therepository |
174 | index page. Default value: "50". | 199 | index page. Default value: "50". |
175 | 200 | ||
176 | max-repodesc-length:: | 201 | max-repodesc-length:: |
177 | Specifies the maximum number of repo description characters to display | 202 | Specifies the maximum number of repo description characters to display |
178 | on the repository index page. Default value: "80". | 203 | on the repository index page. Default value: "80". |
179 | 204 | ||
205 | max-blob-size:: | ||
206 | Specifies the maximum size of a blob to display HTML for in KBytes. | ||
207 | Default value: "0" (limit disabled). | ||
208 | |||
180 | max-stats:: | 209 | max-stats:: |
181 | Set the default maximum statistics period. Valid values are "week", | 210 | Set the default maximum statistics period. Valid values are "week", |
182 | "month", "quarter" and "year". If unspecified, statistics are | 211 | "month", "quarter" and "year". If unspecified, statistics are |
183 | disabled. Default value: none. See also: "repo.max-stats". | 212 | disabled. Default value: none. See also: "repo.max-stats". |
184 | 213 | ||
185 | mimetype.<ext>:: | 214 | mimetype.<ext>:: |
186 | Set the mimetype for the specified filename extension. This is used | 215 | Set the mimetype for the specified filename extension. This is used |
187 | by the `plain` command when returning blob content. | 216 | by the `plain` command when returning blob content. |
188 | 217 | ||
189 | module-link:: | 218 | module-link:: |
190 | Text which will be used as the formatstring for a hyperlink when a | 219 | Text which will be used as the formatstring for a hyperlink when a |
191 | submodule is printed in a directory listing. The arguments for the | 220 | submodule is printed in a directory listing. The arguments for the |
192 | formatstring are the path and SHA1 of the submodule commit. Default | 221 | formatstring are the path and SHA1 of the submodule commit. Default |
193 | value: "./?repo=%s&page=commit&id=%s" | 222 | value: "./?repo=%s&page=commit&id=%s" |
194 | 223 | ||
195 | nocache:: | 224 | nocache:: |
196 | If set to the value "1" caching will be disabled. This settings is | 225 | If set to the value "1" caching will be disabled. This settings is |
197 | deprecated, and will not be honored starting with cgit-1.0. Default | 226 | deprecated, and will not be honored starting with cgit-1.0. Default |
198 | value: "0". | 227 | value: "0". |
199 | 228 | ||
200 | noplainemail:: | 229 | noplainemail:: |
201 | If set to "1" showing full author email adresses will be disabled. | 230 | If set to "1" showing full author email adresses will be disabled. |
202 | Default value: "0". | 231 | Default value: "0". |
203 | 232 | ||
204 | noheader:: | 233 | noheader:: |
205 | Flag which, when set to "1", will make cgit omit the standard header | 234 | Flag which, when set to "1", will make cgit omit the standard header |
206 | on all pages. Default value: none. See also: "embedded". | 235 | on all pages. Default value: none. See also: "embedded". |
207 | 236 | ||
237 | project-list:: | ||
238 | A list of subdirectories inside of scan-path, relative to it, that | ||
239 | should loaded as git repositories. This must be defined prior to | ||
240 | scan-path. Default value: none. See also: scan-path. | ||
241 | |||
242 | readme:: | ||
243 | Text which will be used as default value for "repo.readme". Default | ||
244 | value: none. | ||
245 | |||
246 | remove-suffix:: | ||
247 | If set to "1" and scan-path is enabled, if any repositories are found | ||
248 | with a suffix of ".git", this suffix will be removed for the url and | ||
249 | name. Default value: "0". See also: scan-path. | ||
250 | |||
208 | renamelimit:: | 251 | renamelimit:: |
209 | Maximum number of files to consider when detecting renames. The value | 252 | Maximum number of files to consider when detecting renames. The value |
210 | "-1" uses the compiletime value in git (for further info, look at | 253 | "-1" uses the compiletime value in git (for further info, look at |
211 | `man git-diff`). Default value: "-1". | 254 | `man git-diff`). Default value: "-1". |
212 | 255 | ||
213 | repo.group:: | 256 | repo.group:: |
214 | Legacy alias for "section". This option is deprecated and will not be | 257 | Legacy alias for "section". This option is deprecated and will not be |
215 | supported in cgit-1.0. | 258 | supported in cgit-1.0. |
216 | 259 | ||
217 | robots:: | 260 | robots:: |
218 | Text used as content for the "robots" meta-tag. Default value: | 261 | Text used as content for the "robots" meta-tag. Default value: |
219 | "index, nofollow". | 262 | "index, nofollow". |
220 | 263 | ||
221 | root-desc:: | 264 | root-desc:: |
222 | Text printed below the heading on the repository index page. Default | 265 | Text printed below the heading on the repository index page. Default |
223 | value: "a fast webinterface for the git dscm". | 266 | value: "a fast webinterface for the git dscm". |
224 | 267 | ||
225 | root-readme:: | 268 | root-readme:: |
226 | The content of the file specified with this option will be included | 269 | The content of the file specified with this option will be included |
227 | verbatim below the "about" link on the repository index page. Default | 270 | verbatim below the "about" link on the repository index page. Default |
228 | value: none. | 271 | value: none. |
229 | 272 | ||
230 | root-title:: | 273 | root-title:: |
231 | Text printed as heading on the repository index page. Default value: | 274 | Text printed as heading on the repository index page. Default value: |
232 | "Git Repository Browser". | 275 | "Git Repository Browser". |
233 | 276 | ||
277 | scan-hidden-path:: | ||
278 | If set to "1" and scan-path is enabled, scan-path will recurse into | ||
279 | directories whose name starts with a period ('.'). Otherwise, | ||
280 | scan-path will stay away from such directories (considered as | ||
281 | "hidden"). Note that this does not apply to the ".git" directory in | ||
282 | non-bare repos. This must be defined prior to scan-path. | ||
283 | Default value: 0. See also: scan-path. | ||
284 | |||
234 | scan-path:: | 285 | scan-path:: |
235 | A path which will be scanned for repositories. If caching is enabled, | 286 | A path which will be scanned for repositories. If caching is enabled, |
236 | the result will be cached as a cgitrc include-file in the cache | 287 | the result will be cached as a cgitrc include-file in the cache |
237 | directory. Default value: none. See also: cache-scanrc-ttl. | 288 | directory. If project-list has been defined prior to scan-path, |
289 | scan-path loads only the directories listed in the file pointed to by | ||
290 | project-list. Default value: none. See also: cache-scanrc-ttl, | ||
291 | project-list. | ||
238 | 292 | ||
239 | section:: | 293 | section:: |
240 | The name of the current repository section - all repositories defined | 294 | The name of the current repository section - all repositories defined |
241 | after this option will inherit the current section name. Default value: | 295 | after this option will inherit the current section name. Default value: |
242 | none. | 296 | none. |
243 | 297 | ||
298 | section-from-path:: | ||
299 | A number which, if specified before scan-path, specifies how many | ||
300 | path elements from each repo path to use as a default section name. | ||
301 | If negative, cgit will discard the specified number of path elements | ||
302 | above the repo directory. Default value: 0. | ||
303 | |||
304 | side-by-side-diffs:: | ||
305 | If set to "1" shows side-by-side diffs instead of unidiffs per | ||
306 | default. Default value: "0". | ||
307 | |||
244 | snapshots:: | 308 | snapshots:: |
245 | Text which specifies the default set of snapshot formats generated by | 309 | Text which specifies the default set of snapshot formats generated by |
246 | cgit. The value is a space-separated list of zero or more of the | 310 | cgit. The value is a space-separated list of zero or more of the |
247 | values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none. | 311 | values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none. |
248 | 312 | ||
249 | source-filter:: | 313 | source-filter:: |
250 | Specifies a command which will be invoked to format plaintext blobs | 314 | Specifies a command which will be invoked to format plaintext blobs |
251 | in the tree view. The command will get the blob content on its STDIN | 315 | in the tree view. The command will get the blob content on its STDIN |
252 | and the name of the blob as its only command line argument. The STDOUT | 316 | and the name of the blob as its only command line argument. The STDOUT |
253 | from the command will be included verbatim as the blob contents, i.e. | 317 | from the command will be included verbatim as the blob contents, i.e. |
254 | this can be used to implement e.g. syntax highlighting. Default value: | 318 | this can be used to implement e.g. syntax highlighting. Default value: |
255 | none. | 319 | none. |
256 | 320 | ||
257 | summary-branches:: | 321 | summary-branches:: |
258 | Specifies the number of branches to display in the repository "summary" | 322 | Specifies the number of branches to display in the repository "summary" |
259 | view. Default value: "10". | 323 | view. Default value: "10". |
260 | 324 | ||
261 | summary-log:: | 325 | summary-log:: |
262 | Specifies the number of log entries to display in the repository | 326 | Specifies the number of log entries to display in the repository |
263 | "summary" view. Default value: "10". | 327 | "summary" view. Default value: "10". |
264 | 328 | ||
265 | summary-tags:: | 329 | summary-tags:: |
266 | Specifies the number of tags to display in the repository "summary" | 330 | Specifies the number of tags to display in the repository "summary" |
267 | view. Default value: "10". | 331 | view. Default value: "10". |
268 | 332 | ||
333 | strict-export:: | ||
334 | Filename which, if specified, needs to be present within the repository | ||
335 | for cgit to allow access to that repository. This can be used to emulate | ||
336 | gitweb's EXPORT_OK and STRICT_EXPORT functionality and limit cgit's | ||
337 | repositories to match those exported by git-daemon. This option MUST come | ||
338 | before 'scan-path'. | ||
339 | |||
269 | virtual-root:: | 340 | virtual-root:: |
270 | Url which, if specified, will be used as root for all cgit links. It | 341 | Url which, if specified, will be used as root for all cgit links. It |
271 | will also cause cgit to generate 'virtual urls', i.e. urls like | 342 | will also cause cgit to generate 'virtual urls', i.e. urls like |
272 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default | 343 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default |
273 | value: none. | 344 | value: none. |
274 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the | 345 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the |
275 | same kind of virtual urls, so this option will probably be deprecated. | 346 | same kind of virtual urls, so this option will probably be deprecated. |
276 | 347 | ||
277 | REPOSITORY SETTINGS | 348 | REPOSITORY SETTINGS |
278 | ------------------- | 349 | ------------------- |
279 | repo.about-filter:: | 350 | repo.about-filter:: |
280 | Override the default about-filter. Default value: none. See also: | 351 | Override the default about-filter. Default value: none. See also: |
281 | "enable-filter-overrides". | 352 | "enable-filter-overrides". |
282 | 353 | ||
283 | repo.clone-url:: | 354 | repo.clone-url:: |
284 | A list of space-separated urls which can be used to clone this repo. | 355 | A list of space-separated urls which can be used to clone this repo. |
285 | Default value: none. | 356 | Default value: none. |
286 | 357 | ||
287 | repo.commit-filter:: | 358 | repo.commit-filter:: |
288 | Override the default commit-filter. Default value: none. See also: | 359 | Override the default commit-filter. Default value: none. See also: |
289 | "enable-filter-overrides". | 360 | "enable-filter-overrides". |
290 | 361 | ||
291 | repo.defbranch:: | 362 | repo.defbranch:: |
292 | The name of the default branch for this repository. If no such branch | 363 | The name of the default branch for this repository. If no such branch |
293 | exists in the repository, the first branch name (when sorted) is used | 364 | exists in the repository, the first branch name (when sorted) is used |
294 | as default instead. Default value: "master". | 365 | as default instead. Default value: "master". |
295 | 366 | ||
296 | repo.desc:: | 367 | repo.desc:: |
297 | The value to show as repository description. Default value: none. | 368 | The value to show as repository description. Default value: none. |
298 | 369 | ||
370 | repo.enable-commit-graph:: | ||
371 | A flag which can be used to disable the global setting | ||
372 | `enable-commit-graph'. Default value: none. | ||
373 | |||
299 | repo.enable-log-filecount:: | 374 | repo.enable-log-filecount:: |
300 | A flag which can be used to disable the global setting | 375 | A flag which can be used to disable the global setting |
301 | `enable-log-filecount'. Default value: none. | 376 | `enable-log-filecount'. Default value: none. |
302 | 377 | ||
303 | repo.enable-log-linecount:: | 378 | repo.enable-log-linecount:: |
304 | A flag which can be used to disable the global setting | 379 | A flag which can be used to disable the global setting |
305 | `enable-log-linecount'. Default value: none. | 380 | `enable-log-linecount'. Default value: none. |
306 | 381 | ||
382 | repo.enable-remote-branches:: | ||
383 | Flag which, when set to "1", will make cgit display remote branches | ||
384 | in the summary and refs views. Default value: <enable-remote-branches>. | ||
385 | |||
386 | repo.enable-subject-links:: | ||
387 | A flag which can be used to override the global setting | ||
388 | `enable-subject-links'. Default value: none. | ||
389 | |||
390 | repo.logo:: | ||
391 | Url which specifies the source of an image which will be used as a logo | ||
392 | on this repo's pages. Default value: global logo. | ||
393 | |||
394 | repo.logo-link:: | ||
395 | Url loaded when clicking on the cgit logo image. If unspecified the | ||
396 | calculated url of the repository index page will be used. Default | ||
397 | value: global logo-link. | ||
398 | |||
307 | repo.max-stats:: | 399 | repo.max-stats:: |
308 | Override the default maximum statistics period. Valid values are equal | 400 | Override the default maximum statistics period. Valid values are equal |
309 | to the values specified for the global "max-stats" setting. Default | 401 | to the values specified for the global "max-stats" setting. Default |
310 | value: none. | 402 | value: none. |
311 | 403 | ||
312 | repo.name:: | 404 | repo.name:: |
313 | The value to show as repository name. Default value: <repo.url>. | 405 | The value to show as repository name. Default value: <repo.url>. |
314 | 406 | ||
315 | repo.owner:: | 407 | repo.owner:: |
316 | A value used to identify the owner of the repository. Default value: | 408 | A value used to identify the owner of the repository. Default value: |
317 | none. | 409 | none. |
318 | 410 | ||
319 | repo.path:: | 411 | repo.path:: |
320 | An absolute path to the repository directory. For non-bare repositories | 412 | An absolute path to the repository directory. For non-bare repositories |
321 | this is the .git-directory. Default value: none. | 413 | this is the .git-directory. Default value: none. |
322 | 414 | ||
323 | repo.readme:: | 415 | repo.readme:: |
324 | A path (relative to <repo.path>) which specifies a file to include | 416 | A path (relative to <repo.path>) which specifies a file to include |
325 | verbatim as the "About" page for this repo. Default value: none. | 417 | verbatim as the "About" page for this repo. You may also specify a |
418 | git refspec by head or by hash by prepending the refspec followed by | ||
419 | a colon. For example, "master:docs/readme.mkd" Default value: <readme>. | ||
326 | 420 | ||
327 | repo.snapshots:: | 421 | repo.snapshots:: |
328 | A mask of allowed snapshot-formats for this repo, restricted by the | 422 | A mask of allowed snapshot-formats for this repo, restricted by the |
329 | "snapshots" global setting. Default value: <snapshots>. | 423 | "snapshots" global setting. Default value: <snapshots>. |
330 | 424 | ||
331 | repo.section:: | 425 | repo.section:: |
332 | Override the current section name for this repository. Default value: | 426 | Override the current section name for this repository. Default value: |
333 | none. | 427 | none. |
334 | 428 | ||
335 | repo.source-filter:: | 429 | repo.source-filter:: |
336 | Override the default source-filter. Default value: none. See also: | 430 | Override the default source-filter. Default value: none. See also: |
337 | "enable-filter-overrides". | 431 | "enable-filter-overrides". |
338 | 432 | ||
339 | repo.url:: | 433 | repo.url:: |
340 | The relative url used to access the repository. This must be the first | 434 | The relative url used to access the repository. This must be the first |
341 | setting specified for each repo. Default value: none. | 435 | setting specified for each repo. Default value: none. |
342 | 436 | ||
343 | 437 | ||
344 | REPOSITORY-SPECIFIC CGITRC FILE | 438 | REPOSITORY-SPECIFIC CGITRC FILE |
345 | ------------------------------- | 439 | ------------------------------- |
346 | When the option "scan-path" is used to auto-discover git repositories, cgit | 440 | When the option "scan-path" is used to auto-discover git repositories, cgit |
347 | will try to parse the file "cgitrc" within any found repository. Such a | 441 | will try to parse the file "cgitrc" within any found repository. Such a |
348 | repo-specific config file may contain any of the repo-specific options | 442 | repo-specific config file may contain any of the repo-specific options |
349 | described above, except "repo.url" and "repo.path". Additionally, the "filter" | 443 | described above, except "repo.url" and "repo.path". Additionally, the "filter" |
350 | options are only acknowledged in repo-specific config files when | 444 | options are only acknowledged in repo-specific config files when |
351 | "enable-filter-overrides" is set to "1". | 445 | "enable-filter-overrides" is set to "1". |
352 | 446 | ||
353 | Note: the "repo." prefix is dropped from the option names in repo-specific | 447 | Note: the "repo." prefix is dropped from the option names in repo-specific |
354 | config files, e.g. "repo.desc" becomes "desc". | 448 | config files, e.g. "repo.desc" becomes "desc". |
355 | 449 | ||
356 | 450 | ||
357 | EXAMPLE CGITRC FILE | 451 | EXAMPLE CGITRC FILE |
358 | ------------------- | 452 | ------------------- |
359 | 453 | ||
360 | .... | 454 | .... |
361 | # Enable caching of up to 1000 output entriess | 455 | # Enable caching of up to 1000 output entriess |
362 | cache-size=1000 | 456 | cache-size=1000 |
363 | 457 | ||
364 | 458 | ||
365 | # Specify some default clone prefixes | 459 | # Specify some default clone prefixes |
366 | clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git | 460 | clone-prefix=git://example.com ssh://example.com/pub/git http://example.com/git |
367 | 461 | ||
368 | # Specify the css url | 462 | # Specify the css url |
369 | css=/css/cgit.css | 463 | css=/css/cgit.css |
370 | 464 | ||
371 | 465 | ||
372 | # Show extra links for each repository on the index page | 466 | # Show extra links for each repository on the index page |
373 | enable-index-links=1 | 467 | enable-index-links=1 |
374 | 468 | ||
375 | 469 | ||
470 | # Enable ASCII art commit history graph on the log pages | ||
471 | enable-commit-graph=1 | ||
472 | |||
473 | |||
376 | # Show number of affected files per commit on the log pages | 474 | # Show number of affected files per commit on the log pages |
377 | enable-log-filecount=1 | 475 | enable-log-filecount=1 |
378 | 476 | ||
379 | 477 | ||
380 | # Show number of added/removed lines per commit on the log pages | 478 | # Show number of added/removed lines per commit on the log pages |
381 | enable-log-linecount=1 | 479 | enable-log-linecount=1 |
382 | 480 | ||
383 | 481 | ||
384 | # Add a cgit favicon | 482 | # Add a cgit favicon |
385 | favicon=/favicon.ico | 483 | favicon=/favicon.ico |
386 | 484 | ||
387 | 485 | ||
388 | # Use a custom logo | 486 | # Use a custom logo |
389 | logo=/img/mylogo.png | 487 | logo=/img/mylogo.png |
390 | 488 | ||
391 | 489 | ||
392 | # Enable statistics per week, month and quarter | 490 | # Enable statistics per week, month and quarter |
393 | max-stats=quarter | 491 | max-stats=quarter |
394 | 492 | ||
395 | 493 | ||
396 | # Set the title and heading of the repository index page | 494 | # Set the title and heading of the repository index page |
397 | root-title=foobar.com git repositories | 495 | root-title=example.com git repositories |
398 | 496 | ||
399 | 497 | ||
400 | # Set a subheading for the repository index page | 498 | # Set a subheading for the repository index page |
401 | root-desc=tracking the foobar development | 499 | root-desc=tracking the foobar development |
402 | 500 | ||
403 | 501 | ||
404 | # Include some more info about foobar.com on the index page | 502 | # Include some more info about example.com on the index page |
405 | root-readme=/var/www/htdocs/about.html | 503 | root-readme=/var/www/htdocs/about.html |
406 | 504 | ||
407 | 505 | ||
408 | # Allow download of tar.gz, tar.bz2 and zip-files | 506 | # Allow download of tar.gz, tar.bz2 and zip-files |
409 | snapshots=tar.gz tar.bz2 zip | 507 | snapshots=tar.gz tar.bz2 zip |
410 | 508 | ||
411 | 509 | ||
412 | ## | 510 | ## |
413 | ## List of common mimetypes | 511 | ## List of common mimetypes |
414 | ## | 512 | ## |
415 | 513 | ||
416 | mimetype.git=image/git | 514 | mimetype.gif=image/gif |
417 | mimetype.html=text/html | 515 | mimetype.html=text/html |
418 | mimetype.jpg=image/jpeg | 516 | mimetype.jpg=image/jpeg |
419 | mimetype.jpeg=image/jpeg | 517 | mimetype.jpeg=image/jpeg |
420 | mimetype.pdf=application/pdf | 518 | mimetype.pdf=application/pdf |
421 | mimetype.png=image/png | 519 | mimetype.png=image/png |
422 | mimetype.svg=image/svg+xml | 520 | mimetype.svg=image/svg+xml |
423 | 521 | ||
424 | 522 | ||
425 | ## | 523 | ## |
426 | ## List of repositories. | 524 | ## List of repositories. |
427 | ## PS: Any repositories listed when section is unset will not be | 525 | ## PS: Any repositories listed when section is unset will not be |
428 | ## displayed under a section heading | 526 | ## displayed under a section heading |
429 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') | 527 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') |
430 | ## and included like this: | 528 | ## and included like this: |
431 | ## include=/etc/cgitrepos | 529 | ## include=/etc/cgitrepos |
432 | ## | 530 | ## |
433 | 531 | ||
434 | 532 | ||
435 | repo.url=foo | 533 | repo.url=foo |
436 | repo.path=/pub/git/foo.git | 534 | repo.path=/pub/git/foo.git |
437 | repo.desc=the master foo repository | 535 | repo.desc=the master foo repository |
438 | repo.owner=fooman@foobar.com | 536 | repo.owner=fooman@example.com |
439 | repo.readme=info/web/about.html | 537 | repo.readme=info/web/about.html |
440 | 538 | ||
441 | 539 | ||
442 | repo.url=bar | 540 | repo.url=bar |
443 | repo.path=/pub/git/bar.git | 541 | repo.path=/pub/git/bar.git |
444 | repo.desc=the bars for your foo | 542 | repo.desc=the bars for your foo |
445 | repo.owner=barman@foobar.com | 543 | repo.owner=barman@example.com |
446 | repo.readme=info/web/about.html | 544 | repo.readme=info/web/about.html |
447 | 545 | ||
448 | 546 | ||
449 | # The next repositories will be displayed under the 'extras' heading | 547 | # The next repositories will be displayed under the 'extras' heading |
450 | section=extras | 548 | section=extras |
451 | 549 | ||
452 | 550 | ||
453 | repo.url=baz | 551 | repo.url=baz |
454 | repo.path=/pub/git/baz.git | 552 | repo.path=/pub/git/baz.git |
455 | repo.desc=a set of extensions for bar users | 553 | repo.desc=a set of extensions for bar users |
456 | 554 | ||
457 | repo.url=wiz | 555 | repo.url=wiz |
458 | repo.path=/pub/git/wiz.git | 556 | repo.path=/pub/git/wiz.git |
459 | repo.desc=the wizard of foo | 557 | repo.desc=the wizard of foo |
460 | 558 | ||
461 | 559 | ||
462 | # Add some mirrored repositories | 560 | # Add some mirrored repositories |
463 | section=mirrors | 561 | section=mirrors |
464 | 562 | ||
465 | 563 | ||
466 | repo.url=git | 564 | repo.url=git |
467 | repo.path=/pub/git/git.git | 565 | repo.path=/pub/git/git.git |
468 | repo.desc=the dscm | 566 | repo.desc=the dscm |
469 | 567 | ||
470 | 568 | ||
471 | repo.url=linux | 569 | repo.url=linux |
472 | repo.path=/pub/git/linux.git | 570 | repo.path=/pub/git/linux.git |
473 | repo.desc=the kernel | 571 | repo.desc=the kernel |
474 | 572 | ||
475 | # Disable adhoc downloads of this repo | 573 | # Disable adhoc downloads of this repo |
476 | repo.snapshots=0 | 574 | repo.snapshots=0 |
477 | 575 | ||
478 | # Disable line-counts for this repo | 576 | # Disable line-counts for this repo |
479 | repo.enable-log-linecount=0 | 577 | repo.enable-log-linecount=0 |
480 | 578 | ||
481 | # Restrict the max statistics period for this repo | 579 | # Restrict the max statistics period for this repo |
482 | repo.max-stats=month | 580 | repo.max-stats=month |
483 | .... | 581 | .... |
484 | 582 | ||
485 | 583 | ||
486 | BUGS | 584 | BUGS |
487 | ---- | 585 | ---- |
488 | Comments currently cannot appear on the same line as a setting; the comment | 586 | Comments currently cannot appear on the same line as a setting; the comment |
489 | will be included as part of the value. E.g. this line: | 587 | will be included as part of the value. E.g. this line: |
490 | 588 | ||
491 | robots=index # allow indexing | 589 | robots=index # allow indexing |
492 | 590 | ||
493 | will generate the following html element: | 591 | will generate the following html element: |
494 | 592 | ||
495 | <meta name='robots' content='index # allow indexing'/> | 593 | <meta name='robots' content='index # allow indexing'/> |
496 | 594 | ||
497 | 595 | ||
498 | 596 | ||
499 | AUTHOR | 597 | AUTHOR |
500 | ------ | 598 | ------ |
501 | Lars Hjemli <hjemli@gmail.com> | 599 | Lars Hjemli <hjemli@gmail.com> |
600 | Jason A. Donenfeld <Jason@zx2c4.com> | ||
@@ -1,171 +1,172 @@ | |||
1 | /* cmd.c: the cgit command dispatcher | 1 | /* cmd.c: the cgit command dispatcher |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "cache.h" | 11 | #include "cache.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | #include "ui-atom.h" | 13 | #include "ui-atom.h" |
14 | #include "ui-blob.h" | 14 | #include "ui-blob.h" |
15 | #include "ui-clone.h" | 15 | #include "ui-clone.h" |
16 | #include "ui-commit.h" | 16 | #include "ui-commit.h" |
17 | #include "ui-diff.h" | 17 | #include "ui-diff.h" |
18 | #include "ui-log.h" | 18 | #include "ui-log.h" |
19 | #include "ui-patch.h" | 19 | #include "ui-patch.h" |
20 | #include "ui-plain.h" | 20 | #include "ui-plain.h" |
21 | #include "ui-refs.h" | 21 | #include "ui-refs.h" |
22 | #include "ui-repolist.h" | 22 | #include "ui-repolist.h" |
23 | #include "ui-snapshot.h" | 23 | #include "ui-snapshot.h" |
24 | #include "ui-stats.h" | 24 | #include "ui-stats.h" |
25 | #include "ui-summary.h" | 25 | #include "ui-summary.h" |
26 | #include "ui-tag.h" | 26 | #include "ui-tag.h" |
27 | #include "ui-tree.h" | 27 | #include "ui-tree.h" |
28 | 28 | ||
29 | static void HEAD_fn(struct cgit_context *ctx) | 29 | static void HEAD_fn(struct cgit_context *ctx) |
30 | { | 30 | { |
31 | cgit_clone_head(ctx); | 31 | cgit_clone_head(ctx); |
32 | } | 32 | } |
33 | 33 | ||
34 | static void atom_fn(struct cgit_context *ctx) | 34 | static void atom_fn(struct cgit_context *ctx) |
35 | { | 35 | { |
36 | cgit_print_atom(ctx->qry.head, ctx->qry.path, 10); | 36 | cgit_print_atom(ctx->qry.head, ctx->qry.path, ctx->cfg.max_atom_items); |
37 | } | 37 | } |
38 | 38 | ||
39 | static void about_fn(struct cgit_context *ctx) | 39 | static void about_fn(struct cgit_context *ctx) |
40 | { | 40 | { |
41 | if (ctx->repo) | 41 | if (ctx->repo) |
42 | cgit_print_repo_readme(ctx->qry.path); | 42 | cgit_print_repo_readme(ctx->qry.path); |
43 | else | 43 | else |
44 | cgit_print_site_readme(); | 44 | cgit_print_site_readme(); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void blob_fn(struct cgit_context *ctx) | 47 | static void blob_fn(struct cgit_context *ctx) |
48 | { | 48 | { |
49 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); | 49 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); |
50 | } | 50 | } |
51 | 51 | ||
52 | static void commit_fn(struct cgit_context *ctx) | 52 | static void commit_fn(struct cgit_context *ctx) |
53 | { | 53 | { |
54 | cgit_print_commit(ctx->qry.sha1); | 54 | cgit_print_commit(ctx->qry.sha1, ctx->qry.path); |
55 | } | 55 | } |
56 | 56 | ||
57 | static void diff_fn(struct cgit_context *ctx) | 57 | static void diff_fn(struct cgit_context *ctx) |
58 | { | 58 | { |
59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); | 59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); |
60 | } | 60 | } |
61 | 61 | ||
62 | static void info_fn(struct cgit_context *ctx) | 62 | static void info_fn(struct cgit_context *ctx) |
63 | { | 63 | { |
64 | cgit_clone_info(ctx); | 64 | cgit_clone_info(ctx); |
65 | } | 65 | } |
66 | 66 | ||
67 | static void log_fn(struct cgit_context *ctx) | 67 | static void log_fn(struct cgit_context *ctx) |
68 | { | 68 | { |
69 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, | 69 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, |
70 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); | 70 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1, |
71 | ctx->repo->enable_commit_graph); | ||
71 | } | 72 | } |
72 | 73 | ||
73 | static void ls_cache_fn(struct cgit_context *ctx) | 74 | static void ls_cache_fn(struct cgit_context *ctx) |
74 | { | 75 | { |
75 | ctx->page.mimetype = "text/plain"; | 76 | ctx->page.mimetype = "text/plain"; |
76 | ctx->page.filename = "ls-cache.txt"; | 77 | ctx->page.filename = "ls-cache.txt"; |
77 | cgit_print_http_headers(ctx); | 78 | cgit_print_http_headers(ctx); |
78 | cache_ls(ctx->cfg.cache_root); | 79 | cache_ls(ctx->cfg.cache_root); |
79 | } | 80 | } |
80 | 81 | ||
81 | static void objects_fn(struct cgit_context *ctx) | 82 | static void objects_fn(struct cgit_context *ctx) |
82 | { | 83 | { |
83 | cgit_clone_objects(ctx); | 84 | cgit_clone_objects(ctx); |
84 | } | 85 | } |
85 | 86 | ||
86 | static void repolist_fn(struct cgit_context *ctx) | 87 | static void repolist_fn(struct cgit_context *ctx) |
87 | { | 88 | { |
88 | cgit_print_repolist(); | 89 | cgit_print_repolist(); |
89 | } | 90 | } |
90 | 91 | ||
91 | static void patch_fn(struct cgit_context *ctx) | 92 | static void patch_fn(struct cgit_context *ctx) |
92 | { | 93 | { |
93 | cgit_print_patch(ctx->qry.sha1); | 94 | cgit_print_patch(ctx->qry.sha1, ctx->qry.path); |
94 | } | 95 | } |
95 | 96 | ||
96 | static void plain_fn(struct cgit_context *ctx) | 97 | static void plain_fn(struct cgit_context *ctx) |
97 | { | 98 | { |
98 | cgit_print_plain(ctx); | 99 | cgit_print_plain(ctx); |
99 | } | 100 | } |
100 | 101 | ||
101 | static void refs_fn(struct cgit_context *ctx) | 102 | static void refs_fn(struct cgit_context *ctx) |
102 | { | 103 | { |
103 | cgit_print_refs(); | 104 | cgit_print_refs(); |
104 | } | 105 | } |
105 | 106 | ||
106 | static void snapshot_fn(struct cgit_context *ctx) | 107 | static void snapshot_fn(struct cgit_context *ctx) |
107 | { | 108 | { |
108 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path, | 109 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path, |
109 | ctx->repo->snapshots, ctx->qry.nohead); | 110 | ctx->repo->snapshots, ctx->qry.nohead); |
110 | } | 111 | } |
111 | 112 | ||
112 | static void stats_fn(struct cgit_context *ctx) | 113 | static void stats_fn(struct cgit_context *ctx) |
113 | { | 114 | { |
114 | cgit_show_stats(ctx); | 115 | cgit_show_stats(ctx); |
115 | } | 116 | } |
116 | 117 | ||
117 | static void summary_fn(struct cgit_context *ctx) | 118 | static void summary_fn(struct cgit_context *ctx) |
118 | { | 119 | { |
119 | cgit_print_summary(); | 120 | cgit_print_summary(); |
120 | } | 121 | } |
121 | 122 | ||
122 | static void tag_fn(struct cgit_context *ctx) | 123 | static void tag_fn(struct cgit_context *ctx) |
123 | { | 124 | { |
124 | cgit_print_tag(ctx->qry.sha1); | 125 | cgit_print_tag(ctx->qry.sha1); |
125 | } | 126 | } |
126 | 127 | ||
127 | static void tree_fn(struct cgit_context *ctx) | 128 | static void tree_fn(struct cgit_context *ctx) |
128 | { | 129 | { |
129 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); | 130 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); |
130 | } | 131 | } |
131 | 132 | ||
132 | #define def_cmd(name, want_repo, want_layout) \ | 133 | #define def_cmd(name, want_repo, want_layout, want_vpath) \ |
133 | {#name, name##_fn, want_repo, want_layout} | 134 | {#name, name##_fn, want_repo, want_layout, want_vpath} |
134 | 135 | ||
135 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) | 136 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) |
136 | { | 137 | { |
137 | static struct cgit_cmd cmds[] = { | 138 | static struct cgit_cmd cmds[] = { |
138 | def_cmd(HEAD, 1, 0), | 139 | def_cmd(HEAD, 1, 0, 0), |
139 | def_cmd(atom, 1, 0), | 140 | def_cmd(atom, 1, 0, 0), |
140 | def_cmd(about, 0, 1), | 141 | def_cmd(about, 0, 1, 0), |
141 | def_cmd(blob, 1, 0), | 142 | def_cmd(blob, 1, 0, 0), |
142 | def_cmd(commit, 1, 1), | 143 | def_cmd(commit, 1, 1, 1), |
143 | def_cmd(diff, 1, 1), | 144 | def_cmd(diff, 1, 1, 1), |
144 | def_cmd(info, 1, 0), | 145 | def_cmd(info, 1, 0, 0), |
145 | def_cmd(log, 1, 1), | 146 | def_cmd(log, 1, 1, 1), |
146 | def_cmd(ls_cache, 0, 0), | 147 | def_cmd(ls_cache, 0, 0, 0), |
147 | def_cmd(objects, 1, 0), | 148 | def_cmd(objects, 1, 0, 0), |
148 | def_cmd(patch, 1, 0), | 149 | def_cmd(patch, 1, 0, 1), |
149 | def_cmd(plain, 1, 0), | 150 | def_cmd(plain, 1, 0, 0), |
150 | def_cmd(refs, 1, 1), | 151 | def_cmd(refs, 1, 1, 0), |
151 | def_cmd(repolist, 0, 0), | 152 | def_cmd(repolist, 0, 0, 0), |
152 | def_cmd(snapshot, 1, 0), | 153 | def_cmd(snapshot, 1, 0, 0), |
153 | def_cmd(stats, 1, 1), | 154 | def_cmd(stats, 1, 1, 1), |
154 | def_cmd(summary, 1, 1), | 155 | def_cmd(summary, 1, 1, 0), |
155 | def_cmd(tag, 1, 1), | 156 | def_cmd(tag, 1, 1, 0), |
156 | def_cmd(tree, 1, 1), | 157 | def_cmd(tree, 1, 1, 1), |
157 | }; | 158 | }; |
158 | int i; | 159 | int i; |
159 | 160 | ||
160 | if (ctx->qry.page == NULL) { | 161 | if (ctx->qry.page == NULL) { |
161 | if (ctx->repo) | 162 | if (ctx->repo) |
162 | ctx->qry.page = "summary"; | 163 | ctx->qry.page = "summary"; |
163 | else | 164 | else |
164 | ctx->qry.page = "repolist"; | 165 | ctx->qry.page = "repolist"; |
165 | } | 166 | } |
166 | 167 | ||
167 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) | 168 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) |
168 | if (!strcmp(ctx->qry.page, cmds[i].name)) | 169 | if (!strcmp(ctx->qry.page, cmds[i].name)) |
169 | return &cmds[i]; | 170 | return &cmds[i]; |
170 | return NULL; | 171 | return NULL; |
171 | } | 172 | } |
@@ -1,15 +1,16 @@ | |||
1 | #ifndef CMD_H | 1 | #ifndef CMD_H |
2 | #define CMD_H | 2 | #define CMD_H |
3 | 3 | ||
4 | typedef void (*cgit_cmd_fn)(struct cgit_context *ctx); | 4 | typedef void (*cgit_cmd_fn)(struct cgit_context *ctx); |
5 | 5 | ||
6 | struct cgit_cmd { | 6 | struct cgit_cmd { |
7 | const char *name; | 7 | const char *name; |
8 | cgit_cmd_fn fn; | 8 | cgit_cmd_fn fn; |
9 | unsigned int want_repo:1, | 9 | unsigned int want_repo:1, |
10 | want_layout:1; | 10 | want_layout:1, |
11 | want_vpath:1; | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); | 14 | extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); |
14 | 15 | ||
15 | #endif /* CMD_H */ | 16 | #endif /* CMD_H */ |
diff --git a/filters/commit-links.sh b/filters/commit-links.sh index 165a533..110c609 100755 --- a/filters/commit-links.sh +++ b/filters/commit-links.sh | |||
@@ -1,12 +1,14 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # This script can be used to generate links in commit messages - the first | 2 | # This script can be used to generate links in commit messages. |
3 | # sed expression generates links to commits referenced by their SHA1, while | ||
4 | # the second expression generates links to a fictional bugtracker. | ||
5 | # | 3 | # |
6 | # To use this script, refer to this file with either the commit-filter or the | 4 | # To use this script, refer to this file with either the commit-filter or the |
7 | # repo.commit-filter options in cgitrc. | 5 | # repo.commit-filter options in cgitrc. |
8 | 6 | ||
9 | sed -re ' | 7 | # This expression generates links to commits referenced by their SHA1. |
10 | s|\b([0-9a-fA-F]{8,40})\b|<a href="./?id=\1">\1</a>|g | 8 | regex=$regex' |
11 | s| #([0-9]+)\b|<a href="http://bugs.example.com/?bug=\1">#\1</a>|g | 9 | s|\b([0-9a-fA-F]{8,40})\b|<a href="./?id=\1">\1</a>|g' |
12 | ' | 10 | # This expression generates links to a fictional bugtracker. |
11 | regex=$regex' | ||
12 | s| #([0-9]+)\b|<a href="http://bugs.example.com/?bug=\1">#\1</a>|g' | ||
13 | |||
14 | sed -re "$regex" | ||
diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh index 999ad0c..6b1c576 100755 --- a/filters/syntax-highlighting.sh +++ b/filters/syntax-highlighting.sh | |||
@@ -1,39 +1,34 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # This script can be used to implement syntax highlighting in the cgit | 2 | # This script can be used to implement syntax highlighting in the cgit |
3 | # tree-view by refering to this file with the source-filter or repo.source- | 3 | # tree-view by refering to this file with the source-filter or repo.source- |
4 | # filter options in cgitrc. | 4 | # filter options in cgitrc. |
5 | # | 5 | # |
6 | # This script requires a shell supporting the ${var##pattern} syntax. | ||
7 | # It is supported by at least dash and bash, however busybox environments | ||
8 | # might have to use an external call to sed instead. | ||
9 | # | ||
6 | # Note: the highlight command (http://www.andre-simon.de/) uses css for syntax | 10 | # Note: the highlight command (http://www.andre-simon.de/) uses css for syntax |
7 | # highlighting, so you'll probably want something like the following included | 11 | # highlighting, so you'll probably want something like the following included |
8 | # in your css file (generated by highlight 2.4.8 and adapted for cgit): | 12 | # in your css file (generated by highlight 2.4.8 and adapted for cgit): |
9 | # | 13 | # |
10 | # table.blob .num { color:#2928ff; } | 14 | # table.blob .num { color:#2928ff; } |
11 | # table.blob .esc { color:#ff00ff; } | 15 | # table.blob .esc { color:#ff00ff; } |
12 | # table.blob .str { color:#ff0000; } | 16 | # table.blob .str { color:#ff0000; } |
13 | # table.blob .dstr { color:#818100; } | 17 | # table.blob .dstr { color:#818100; } |
14 | # table.blob .slc { color:#838183; font-style:italic; } | 18 | # table.blob .slc { color:#838183; font-style:italic; } |
15 | # table.blob .com { color:#838183; font-style:italic; } | 19 | # table.blob .com { color:#838183; font-style:italic; } |
16 | # table.blob .dir { color:#008200; } | 20 | # table.blob .dir { color:#008200; } |
17 | # table.blob .sym { color:#000000; } | 21 | # table.blob .sym { color:#000000; } |
18 | # table.blob .kwa { color:#000000; font-weight:bold; } | 22 | # table.blob .kwa { color:#000000; font-weight:bold; } |
19 | # table.blob .kwb { color:#830000; } | 23 | # table.blob .kwb { color:#830000; } |
20 | # table.blob .kwc { color:#000000; font-weight:bold; } | 24 | # table.blob .kwc { color:#000000; font-weight:bold; } |
21 | # table.blob .kwd { color:#010181; } | 25 | # table.blob .kwd { color:#010181; } |
22 | 26 | ||
23 | case "$1" in | 27 | # store filename and extension in local vars |
24 | *.c) | 28 | BASENAME="$1" |
25 | highlight -f -I -X -S c | 29 | EXTENSION="${BASENAME##*.}" |
26 | ;; | 30 | |
27 | *.h) | 31 | # map Makefile and Makefile.* to .mk |
28 | highlight -f -I -X -S c | 32 | [ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk |
29 | ;; | 33 | |
30 | *.sh) | 34 | exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null |
31 | highlight -f -I -X -S sh | ||
32 | ;; | ||
33 | *.css) | ||
34 | highlight -f -I -X -S css | ||
35 | ;; | ||
36 | *) | ||
37 | highlight -f -I -X -S txt | ||
38 | ;; | ||
39 | esac | ||
diff --git a/git b/git | |||
Subproject 87b50542a08ac6caa083ddc376e674424e37940 | Subproject 7ed863a85a6ce2c4ac4476848310b8f917ab41f | ||
@@ -1,292 +1,320 @@ | |||
1 | /* html.c: helper functions for html output | 1 | /* html.c: helper functions for html 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 <unistd.h> | 9 | #include <unistd.h> |
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <stdarg.h> | 12 | #include <stdarg.h> |
13 | #include <string.h> | 13 | #include <string.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */ | ||
17 | static const char* url_escape_table[256] = { | ||
18 | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", | ||
19 | "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", | ||
20 | "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", | ||
21 | "%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, | ||
22 | "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d", | ||
23 | "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0, | ||
25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%7b", | ||
26 | "%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85", | ||
27 | "%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", | ||
28 | "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", | ||
29 | "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3", | ||
30 | "%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", | ||
31 | "%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", | ||
32 | "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1", | ||
33 | "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb", | ||
34 | "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", | ||
35 | "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df", | ||
36 | "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9", | ||
37 | "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3", | ||
38 | "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", | ||
39 | "%fe", "%ff" | ||
40 | }; | ||
41 | |||
16 | int htmlfd = STDOUT_FILENO; | 42 | int htmlfd = STDOUT_FILENO; |
17 | 43 | ||
18 | char *fmt(const char *format, ...) | 44 | char *fmt(const char *format, ...) |
19 | { | 45 | { |
20 | static char buf[8][1024]; | 46 | static char buf[8][1024]; |
21 | static int bufidx; | 47 | static int bufidx; |
22 | int len; | 48 | int len; |
23 | va_list args; | 49 | va_list args; |
24 | 50 | ||
25 | bufidx++; | 51 | bufidx++; |
26 | bufidx &= 7; | 52 | bufidx &= 7; |
27 | 53 | ||
28 | va_start(args, format); | 54 | va_start(args, format); |
29 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 55 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
30 | va_end(args); | 56 | va_end(args); |
31 | if (len>sizeof(buf[bufidx])) { | 57 | if (len>sizeof(buf[bufidx])) { |
32 | fprintf(stderr, "[html.c] string truncated: %s\n", format); | 58 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
33 | exit(1); | 59 | exit(1); |
34 | } | 60 | } |
35 | return buf[bufidx]; | 61 | return buf[bufidx]; |
36 | } | 62 | } |
37 | 63 | ||
38 | void html_raw(const char *data, size_t size) | 64 | void html_raw(const char *data, size_t size) |
39 | { | 65 | { |
40 | write(htmlfd, data, size); | 66 | write(htmlfd, data, size); |
41 | } | 67 | } |
42 | 68 | ||
43 | void html(const char *txt) | 69 | void html(const char *txt) |
44 | { | 70 | { |
45 | write(htmlfd, txt, strlen(txt)); | 71 | write(htmlfd, txt, strlen(txt)); |
46 | } | 72 | } |
47 | 73 | ||
48 | void htmlf(const char *format, ...) | 74 | void htmlf(const char *format, ...) |
49 | { | 75 | { |
50 | static char buf[65536]; | 76 | static char buf[65536]; |
51 | va_list args; | 77 | va_list args; |
52 | 78 | ||
53 | va_start(args, format); | 79 | va_start(args, format); |
54 | vsnprintf(buf, sizeof(buf), format, args); | 80 | vsnprintf(buf, sizeof(buf), format, args); |
55 | va_end(args); | 81 | va_end(args); |
56 | html(buf); | 82 | html(buf); |
57 | } | 83 | } |
58 | 84 | ||
59 | void html_status(int code, const char *msg, int more_headers) | 85 | void html_status(int code, const char *msg, int more_headers) |
60 | { | 86 | { |
61 | htmlf("Status: %d %s\n", code, msg); | 87 | htmlf("Status: %d %s\n", code, msg); |
62 | if (!more_headers) | 88 | if (!more_headers) |
63 | html("\n"); | 89 | html("\n"); |
64 | } | 90 | } |
65 | 91 | ||
66 | void html_txt(char *txt) | 92 | void html_txt(const char *txt) |
67 | { | 93 | { |
68 | char *t = txt; | 94 | const char *t = txt; |
69 | while(t && *t){ | 95 | while(t && *t){ |
70 | int c = *t; | 96 | int c = *t; |
71 | if (c=='<' || c=='>' || c=='&') { | 97 | if (c=='<' || c=='>' || c=='&') { |
72 | write(htmlfd, txt, t - txt); | 98 | html_raw(txt, t - txt); |
73 | if (c=='>') | 99 | if (c=='>') |
74 | html(">"); | 100 | html(">"); |
75 | else if (c=='<') | 101 | else if (c=='<') |
76 | html("<"); | 102 | html("<"); |
77 | else if (c=='&') | 103 | else if (c=='&') |
78 | html("&"); | 104 | html("&"); |
79 | txt = t+1; | 105 | txt = t+1; |
80 | } | 106 | } |
81 | t++; | 107 | t++; |
82 | } | 108 | } |
83 | if (t!=txt) | 109 | if (t!=txt) |
84 | html(txt); | 110 | html(txt); |
85 | } | 111 | } |
86 | 112 | ||
87 | void html_ntxt(int len, char *txt) | 113 | void html_ntxt(int len, const char *txt) |
88 | { | 114 | { |
89 | char *t = txt; | 115 | const char *t = txt; |
90 | while(t && *t && len--){ | 116 | while(t && *t && len--){ |
91 | int c = *t; | 117 | int c = *t; |
92 | if (c=='<' || c=='>' || c=='&') { | 118 | if (c=='<' || c=='>' || c=='&') { |
93 | write(htmlfd, txt, t - txt); | 119 | html_raw(txt, t - txt); |
94 | if (c=='>') | 120 | if (c=='>') |
95 | html(">"); | 121 | html(">"); |
96 | else if (c=='<') | 122 | else if (c=='<') |
97 | html("<"); | 123 | html("<"); |
98 | else if (c=='&') | 124 | else if (c=='&') |
99 | html("&"); | 125 | html("&"); |
100 | txt = t+1; | 126 | txt = t+1; |
101 | } | 127 | } |
102 | t++; | 128 | t++; |
103 | } | 129 | } |
104 | if (t!=txt) | 130 | if (t!=txt) |
105 | write(htmlfd, txt, t - txt); | 131 | html_raw(txt, t - txt); |
106 | if (len<0) | 132 | if (len<0) |
107 | html("..."); | 133 | html("..."); |
108 | } | 134 | } |
109 | 135 | ||
110 | void html_attr(char *txt) | 136 | void html_attr(const char *txt) |
111 | { | 137 | { |
112 | char *t = txt; | 138 | const char *t = txt; |
113 | while(t && *t){ | 139 | while(t && *t){ |
114 | int c = *t; | 140 | int c = *t; |
115 | if (c=='<' || c=='>' || c=='\'' || c=='\"') { | 141 | if (c=='<' || c=='>' || c=='\'' || c=='\"') { |
116 | write(htmlfd, txt, t - txt); | 142 | html_raw(txt, t - txt); |
117 | if (c=='>') | 143 | if (c=='>') |
118 | html(">"); | 144 | html(">"); |
119 | else if (c=='<') | 145 | else if (c=='<') |
120 | html("<"); | 146 | html("<"); |
121 | else if (c=='\'') | 147 | else if (c=='\'') |
122 | html("'"); | 148 | html("'"); |
123 | else if (c=='"') | 149 | else if (c=='"') |
124 | html("""); | 150 | html("""); |
125 | txt = t+1; | 151 | txt = t+1; |
126 | } | 152 | } |
127 | t++; | 153 | t++; |
128 | } | 154 | } |
129 | if (t!=txt) | 155 | if (t!=txt) |
130 | html(txt); | 156 | html(txt); |
131 | } | 157 | } |
132 | 158 | ||
133 | void html_url_path(char *txt) | 159 | void html_url_path(const char *txt) |
134 | { | 160 | { |
135 | char *t = txt; | 161 | const char *t = txt; |
136 | while(t && *t){ | 162 | while(t && *t){ |
137 | int c = *t; | 163 | int c = *t; |
138 | if (c=='"' || c=='#' || c=='\'' || c=='?') { | 164 | const char *e = url_escape_table[c]; |
139 | write(htmlfd, txt, t - txt); | 165 | if (e && c!='+' && c!='&' && c!='+') { |
140 | write(htmlfd, fmt("%%%2x", c), 3); | 166 | html_raw(txt, t - txt); |
167 | html_raw(e, 3); | ||
141 | txt = t+1; | 168 | txt = t+1; |
142 | } | 169 | } |
143 | t++; | 170 | t++; |
144 | } | 171 | } |
145 | if (t!=txt) | 172 | if (t!=txt) |
146 | html(txt); | 173 | html(txt); |
147 | } | 174 | } |
148 | 175 | ||
149 | void html_url_arg(char *txt) | 176 | void html_url_arg(const char *txt) |
150 | { | 177 | { |
151 | char *t = txt; | 178 | const char *t = txt; |
152 | while(t && *t){ | 179 | while(t && *t){ |
153 | int c = *t; | 180 | int c = *t; |
154 | if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') { | 181 | const char *e = url_escape_table[c]; |
155 | write(htmlfd, txt, t - txt); | 182 | if (e) { |
156 | write(htmlfd, fmt("%%%2x", c), 3); | 183 | html_raw(txt, t - txt); |
184 | html_raw(e, strlen(e)); | ||
157 | txt = t+1; | 185 | txt = t+1; |
158 | } | 186 | } |
159 | t++; | 187 | t++; |
160 | } | 188 | } |
161 | if (t!=txt) | 189 | if (t!=txt) |
162 | html(txt); | 190 | html(txt); |
163 | } | 191 | } |
164 | 192 | ||
165 | void html_hidden(char *name, char *value) | 193 | void html_hidden(const char *name, const char *value) |
166 | { | 194 | { |
167 | html("<input type='hidden' name='"); | 195 | html("<input type='hidden' name='"); |
168 | html_attr(name); | 196 | html_attr(name); |
169 | html("' value='"); | 197 | html("' value='"); |
170 | html_attr(value); | 198 | html_attr(value); |
171 | html("'/>"); | 199 | html("'/>"); |
172 | } | 200 | } |
173 | 201 | ||
174 | void html_option(char *value, char *text, char *selected_value) | 202 | void html_option(const char *value, const char *text, const char *selected_value) |
175 | { | 203 | { |
176 | html("<option value='"); | 204 | html("<option value='"); |
177 | html_attr(value); | 205 | html_attr(value); |
178 | html("'"); | 206 | html("'"); |
179 | if (selected_value && !strcmp(selected_value, value)) | 207 | if (selected_value && !strcmp(selected_value, value)) |
180 | html(" selected='selected'"); | 208 | html(" selected='selected'"); |
181 | html(">"); | 209 | html(">"); |
182 | html_txt(text); | 210 | html_txt(text); |
183 | html("</option>\n"); | 211 | html("</option>\n"); |
184 | } | 212 | } |
185 | 213 | ||
186 | void html_link_open(char *url, char *title, char *class) | 214 | void html_link_open(const char *url, const char *title, const char *class) |
187 | { | 215 | { |
188 | html("<a href='"); | 216 | html("<a href='"); |
189 | html_attr(url); | 217 | html_attr(url); |
190 | if (title) { | 218 | if (title) { |
191 | html("' title='"); | 219 | html("' title='"); |
192 | html_attr(title); | 220 | html_attr(title); |
193 | } | 221 | } |
194 | if (class) { | 222 | if (class) { |
195 | html("' class='"); | 223 | html("' class='"); |
196 | html_attr(class); | 224 | html_attr(class); |
197 | } | 225 | } |
198 | html("'>"); | 226 | html("'>"); |
199 | } | 227 | } |
200 | 228 | ||
201 | void html_link_close(void) | 229 | void html_link_close(void) |
202 | { | 230 | { |
203 | html("</a>"); | 231 | html("</a>"); |
204 | } | 232 | } |
205 | 233 | ||
206 | void html_fileperm(unsigned short mode) | 234 | void html_fileperm(unsigned short mode) |
207 | { | 235 | { |
208 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 236 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
209 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 237 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
210 | } | 238 | } |
211 | 239 | ||
212 | int html_include(const char *filename) | 240 | int html_include(const char *filename) |
213 | { | 241 | { |
214 | FILE *f; | 242 | FILE *f; |
215 | char buf[4096]; | 243 | char buf[4096]; |
216 | size_t len; | 244 | size_t len; |
217 | 245 | ||
218 | if (!(f = fopen(filename, "r"))) { | 246 | if (!(f = fopen(filename, "r"))) { |
219 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", | 247 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", |
220 | filename, strerror(errno), errno); | 248 | filename, strerror(errno), errno); |
221 | return -1; | 249 | return -1; |
222 | } | 250 | } |
223 | while((len = fread(buf, 1, 4096, f)) > 0) | 251 | while((len = fread(buf, 1, 4096, f)) > 0) |
224 | write(htmlfd, buf, len); | 252 | html_raw(buf, len); |
225 | fclose(f); | 253 | fclose(f); |
226 | return 0; | 254 | return 0; |
227 | } | 255 | } |
228 | 256 | ||
229 | int hextoint(char c) | 257 | int hextoint(char c) |
230 | { | 258 | { |
231 | if (c >= 'a' && c <= 'f') | 259 | if (c >= 'a' && c <= 'f') |
232 | return 10 + c - 'a'; | 260 | return 10 + c - 'a'; |
233 | else if (c >= 'A' && c <= 'F') | 261 | else if (c >= 'A' && c <= 'F') |
234 | return 10 + c - 'A'; | 262 | return 10 + c - 'A'; |
235 | else if (c >= '0' && c <= '9') | 263 | else if (c >= '0' && c <= '9') |
236 | return c - '0'; | 264 | return c - '0'; |
237 | else | 265 | else |
238 | return -1; | 266 | return -1; |
239 | } | 267 | } |
240 | 268 | ||
241 | char *convert_query_hexchar(char *txt) | 269 | char *convert_query_hexchar(char *txt) |
242 | { | 270 | { |
243 | int d1, d2, n; | 271 | int d1, d2, n; |
244 | n = strlen(txt); | 272 | n = strlen(txt); |
245 | if (n < 3) { | 273 | if (n < 3) { |
246 | *txt = '\0'; | 274 | *txt = '\0'; |
247 | return txt-1; | 275 | return txt-1; |
248 | } | 276 | } |
249 | d1 = hextoint(*(txt+1)); | 277 | d1 = hextoint(*(txt+1)); |
250 | d2 = hextoint(*(txt+2)); | 278 | d2 = hextoint(*(txt+2)); |
251 | if (d1<0 || d2<0) { | 279 | if (d1<0 || d2<0) { |
252 | memmove(txt, txt+3, n-2); | 280 | memmove(txt, txt+3, n-2); |
253 | return txt-1; | 281 | return txt-1; |
254 | } else { | 282 | } else { |
255 | *txt = d1 * 16 + d2; | 283 | *txt = d1 * 16 + d2; |
256 | memmove(txt+1, txt+3, n-2); | 284 | memmove(txt+1, txt+3, n-2); |
257 | return txt; | 285 | return txt; |
258 | } | 286 | } |
259 | } | 287 | } |
260 | 288 | ||
261 | int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) | 289 | int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value)) |
262 | { | 290 | { |
263 | char *t, *value = NULL, c; | 291 | char *t, *txt, *value = NULL, c; |
264 | 292 | ||
265 | if (!txt) | 293 | if (!txt_) |
266 | return 0; | 294 | return 0; |
267 | 295 | ||
268 | t = txt = strdup(txt); | 296 | t = txt = strdup(txt_); |
269 | if (t == NULL) { | 297 | if (t == NULL) { |
270 | printf("Out of memory\n"); | 298 | printf("Out of memory\n"); |
271 | exit(1); | 299 | exit(1); |
272 | } | 300 | } |
273 | while((c=*t) != '\0') { | 301 | while((c=*t) != '\0') { |
274 | if (c=='=') { | 302 | if (c=='=') { |
275 | *t = '\0'; | 303 | *t = '\0'; |
276 | value = t+1; | 304 | value = t+1; |
277 | } else if (c=='+') { | 305 | } else if (c=='+') { |
278 | *t = ' '; | 306 | *t = ' '; |
279 | } else if (c=='%') { | 307 | } else if (c=='%') { |
280 | t = convert_query_hexchar(t); | 308 | t = convert_query_hexchar(t); |
281 | } else if (c=='&') { | 309 | } else if (c=='&') { |
282 | *t = '\0'; | 310 | *t = '\0'; |
283 | (*fn)(txt, value); | 311 | (*fn)(txt, value); |
284 | txt = t+1; | 312 | txt = t+1; |
285 | value = NULL; | 313 | value = NULL; |
286 | } | 314 | } |
287 | t++; | 315 | t++; |
288 | } | 316 | } |
289 | if (t!=txt) | 317 | if (t!=txt) |
290 | (*fn)(txt, value); | 318 | (*fn)(txt, value); |
291 | return 0; | 319 | return 0; |
292 | } | 320 | } |
@@ -1,24 +1,27 @@ | |||
1 | #ifndef HTML_H | 1 | #ifndef HTML_H |
2 | #define HTML_H | 2 | #define HTML_H |
3 | 3 | ||
4 | extern int htmlfd; | 4 | extern int htmlfd; |
5 | 5 | ||
6 | extern void html_raw(const char *txt, size_t size); | 6 | extern void html_raw(const char *txt, size_t size); |
7 | extern void html(const char *txt); | 7 | extern void html(const char *txt); |
8 | |||
9 | __attribute__((format (printf,1,2))) | ||
8 | extern void htmlf(const char *format,...); | 10 | extern void htmlf(const char *format,...); |
11 | |||
9 | extern void html_status(int code, const char *msg, int more_headers); | 12 | extern void html_status(int code, const char *msg, int more_headers); |
10 | extern void html_txt(char *txt); | 13 | extern void html_txt(const char *txt); |
11 | extern void html_ntxt(int len, char *txt); | 14 | extern void html_ntxt(int len, const char *txt); |
12 | extern void html_attr(char *txt); | 15 | extern void html_attr(const char *txt); |
13 | extern void html_url_path(char *txt); | 16 | extern void html_url_path(const char *txt); |
14 | extern void html_url_arg(char *txt); | 17 | extern void html_url_arg(const char *txt); |
15 | extern void html_hidden(char *name, char *value); | 18 | extern void html_hidden(const char *name, const char *value); |
16 | extern void html_option(char *value, char *text, char *selected_value); | 19 | extern void html_option(const char *value, const char *text, const char *selected_value); |
17 | extern void html_link_open(char *url, char *title, char *class); | 20 | extern void html_link_open(const char *url, const char *title, const char *class); |
18 | extern void html_link_close(void); | 21 | extern void html_link_close(void); |
19 | extern void html_fileperm(unsigned short mode); | 22 | extern void html_fileperm(unsigned short mode); |
20 | extern int html_include(const char *filename); | 23 | extern int html_include(const char *filename); |
21 | 24 | ||
22 | extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); | 25 | extern int http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)); |
23 | 26 | ||
24 | #endif /* HTML_H */ | 27 | #endif /* HTML_H */ |
diff --git a/scan-tree.c b/scan-tree.c index ebfd41e..627af1b 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,146 +1,241 @@ | |||
1 | /* scan-tree.c | ||
2 | * | ||
3 | * Copyright (C) 2008-2009 Lars Hjemli | ||
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
5 | * | ||
6 | * Licensed under GNU General Public License v2 | ||
7 | * (see COPYING for full license text) | ||
8 | */ | ||
9 | |||
1 | #include "cgit.h" | 10 | #include "cgit.h" |
2 | #include "configfile.h" | 11 | #include "configfile.h" |
3 | #include "html.h" | 12 | #include "html.h" |
4 | 13 | ||
5 | #define MAX_PATH 4096 | 14 | #define MAX_PATH 4096 |
6 | 15 | ||
7 | /* return 1 if path contains a objects/ directory and a HEAD file */ | 16 | /* return 1 if path contains a objects/ directory and a HEAD file */ |
8 | static int is_git_dir(const char *path) | 17 | static int is_git_dir(const char *path) |
9 | { | 18 | { |
10 | struct stat st; | 19 | struct stat st; |
11 | static char buf[MAX_PATH]; | 20 | static char buf[MAX_PATH]; |
12 | 21 | ||
13 | if (snprintf(buf, MAX_PATH, "%s/objects", path) >= MAX_PATH) { | 22 | if (snprintf(buf, MAX_PATH, "%s/objects", path) >= MAX_PATH) { |
14 | fprintf(stderr, "Insanely long path: %s\n", path); | 23 | fprintf(stderr, "Insanely long path: %s\n", path); |
15 | return 0; | 24 | return 0; |
16 | } | 25 | } |
17 | if (stat(buf, &st)) { | 26 | if (stat(buf, &st)) { |
18 | if (errno != ENOENT) | 27 | if (errno != ENOENT) |
19 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 28 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
20 | path, strerror(errno), errno); | 29 | path, strerror(errno), errno); |
21 | return 0; | 30 | return 0; |
22 | } | 31 | } |
23 | if (!S_ISDIR(st.st_mode)) | 32 | if (!S_ISDIR(st.st_mode)) |
24 | return 0; | 33 | return 0; |
25 | 34 | ||
26 | sprintf(buf, "%s/HEAD", path); | 35 | sprintf(buf, "%s/HEAD", path); |
27 | if (stat(buf, &st)) { | 36 | if (stat(buf, &st)) { |
28 | if (errno != ENOENT) | 37 | if (errno != ENOENT) |
29 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 38 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
30 | path, strerror(errno), errno); | 39 | path, strerror(errno), errno); |
31 | return 0; | 40 | return 0; |
32 | } | 41 | } |
33 | if (!S_ISREG(st.st_mode)) | 42 | if (!S_ISREG(st.st_mode)) |
34 | return 0; | 43 | return 0; |
35 | 44 | ||
36 | return 1; | 45 | return 1; |
37 | } | 46 | } |
38 | 47 | ||
39 | struct cgit_repo *repo; | 48 | struct cgit_repo *repo; |
40 | repo_config_fn config_fn; | 49 | repo_config_fn config_fn; |
50 | char *owner; | ||
41 | 51 | ||
42 | static void repo_config(const char *name, const char *value) | 52 | static void repo_config(const char *name, const char *value) |
43 | { | 53 | { |
44 | config_fn(repo, name, value); | 54 | config_fn(repo, name, value); |
45 | } | 55 | } |
46 | 56 | ||
57 | static int git_owner_config(const char *key, const char *value, void *cb) | ||
58 | { | ||
59 | if (!strcmp(key, "gitweb.owner")) | ||
60 | owner = xstrdup(value); | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static char *xstrrchr(char *s, char *from, int c) | ||
65 | { | ||
66 | while (from >= s && *from != c) | ||
67 | from--; | ||
68 | return from < s ? NULL : from; | ||
69 | } | ||
70 | |||
47 | static void add_repo(const char *base, const char *path, repo_config_fn fn) | 71 | static void add_repo(const char *base, const char *path, repo_config_fn fn) |
48 | { | 72 | { |
49 | struct stat st; | 73 | struct stat st; |
50 | struct passwd *pwd; | 74 | struct passwd *pwd; |
51 | char *p; | 75 | char *rel, *p, *slash; |
76 | int n; | ||
52 | size_t size; | 77 | size_t size; |
53 | 78 | ||
54 | if (stat(path, &st)) { | 79 | if (stat(path, &st)) { |
55 | fprintf(stderr, "Error accessing %s: %s (%d)\n", | 80 | fprintf(stderr, "Error accessing %s: %s (%d)\n", |
56 | path, strerror(errno), errno); | 81 | path, strerror(errno), errno); |
57 | return; | 82 | return; |
58 | } | 83 | } |
59 | if ((pwd = getpwuid(st.st_uid)) == NULL) { | 84 | |
60 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | 85 | if (ctx.cfg.strict_export && stat(fmt("%s/%s", path, ctx.cfg.strict_export), &st)) |
61 | path, strerror(errno), errno); | ||
62 | return; | 86 | return; |
63 | } | 87 | |
88 | if (!stat(fmt("%s/noweb", path), &st)) | ||
89 | return; | ||
90 | |||
91 | owner = NULL; | ||
92 | if (ctx.cfg.enable_gitweb_owner) | ||
93 | git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); | ||
64 | if (base == path) | 94 | if (base == path) |
65 | p = fmt("%s", path); | 95 | rel = xstrdup(fmt("%s", path)); |
66 | else | 96 | else |
67 | p = fmt("%s", path + strlen(base) + 1); | 97 | rel = xstrdup(fmt("%s", path + strlen(base) + 1)); |
68 | 98 | ||
69 | if (!strcmp(p + strlen(p) - 5, "/.git")) | 99 | if (!strcmp(rel + strlen(rel) - 5, "/.git")) |
70 | p[strlen(p) - 5] = '\0'; | 100 | rel[strlen(rel) - 5] = '\0'; |
71 | 101 | ||
72 | repo = cgit_add_repo(xstrdup(p)); | 102 | repo = cgit_add_repo(rel); |
103 | if (ctx.cfg.remove_suffix) | ||
104 | if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) | ||
105 | *p = '\0'; | ||
73 | repo->name = repo->url; | 106 | repo->name = repo->url; |
74 | repo->path = xstrdup(path); | 107 | repo->path = xstrdup(path); |
75 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; | 108 | while (!owner) { |
76 | if (p) | 109 | if ((pwd = getpwuid(st.st_uid)) == NULL) { |
110 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | ||
111 | path, strerror(errno), errno); | ||
112 | break; | ||
113 | } | ||
114 | if (pwd->pw_gecos) | ||
115 | if ((p = strchr(pwd->pw_gecos, ','))) | ||
77 | *p = '\0'; | 116 | *p = '\0'; |
78 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); | 117 | owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); |
118 | } | ||
119 | repo->owner = owner; | ||
79 | 120 | ||
80 | p = fmt("%s/description", path); | 121 | p = fmt("%s/description", path); |
81 | if (!stat(p, &st)) | 122 | if (!stat(p, &st)) |
82 | readfile(p, &repo->desc, &size); | 123 | readfile(p, &repo->desc, &size); |
83 | 124 | ||
125 | if (!repo->readme) { | ||
84 | p = fmt("%s/README.html", path); | 126 | p = fmt("%s/README.html", path); |
85 | if (!stat(p, &st)) | 127 | if (!stat(p, &st)) |
86 | repo->readme = xstrdup(p); | 128 | repo->readme = "README.html"; |
129 | } | ||
130 | if (ctx.cfg.section_from_path) { | ||
131 | n = ctx.cfg.section_from_path; | ||
132 | if (n > 0) { | ||
133 | slash = rel; | ||
134 | while (slash && n && (slash = strchr(slash, '/'))) | ||
135 | n--; | ||
136 | } else { | ||
137 | slash = rel + strlen(rel); | ||
138 | while (slash && n && (slash = xstrrchr(rel, slash, '/'))) | ||
139 | n++; | ||
140 | } | ||
141 | if (slash && !n) { | ||
142 | *slash = '\0'; | ||
143 | repo->section = xstrdup(rel); | ||
144 | *slash = '/'; | ||
145 | if (!prefixcmp(repo->name, repo->section)) { | ||
146 | repo->name += strlen(repo->section); | ||
147 | if (*repo->name == '/') | ||
148 | repo->name++; | ||
149 | } | ||
150 | } | ||
151 | } | ||
87 | 152 | ||
88 | p = fmt("%s/cgitrc", path); | 153 | p = fmt("%s/cgitrc", path); |
89 | if (!stat(p, &st)) { | 154 | if (!stat(p, &st)) { |
90 | config_fn = fn; | 155 | config_fn = fn; |
91 | parse_configfile(xstrdup(p), &repo_config); | 156 | parse_configfile(xstrdup(p), &repo_config); |
92 | } | 157 | } |
93 | } | 158 | } |
94 | 159 | ||
95 | static void scan_path(const char *base, const char *path, repo_config_fn fn) | 160 | static void scan_path(const char *base, const char *path, repo_config_fn fn) |
96 | { | 161 | { |
97 | DIR *dir; | 162 | DIR *dir = opendir(path); |
98 | struct dirent *ent; | 163 | struct dirent *ent; |
99 | char *buf; | 164 | char *buf; |
100 | struct stat st; | 165 | struct stat st; |
101 | 166 | ||
167 | if (!dir) { | ||
168 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", | ||
169 | path, strerror(errno), errno); | ||
170 | return; | ||
171 | } | ||
102 | if (is_git_dir(path)) { | 172 | if (is_git_dir(path)) { |
103 | add_repo(base, path, fn); | 173 | add_repo(base, path, fn); |
104 | return; | 174 | goto end; |
105 | } | 175 | } |
106 | if (is_git_dir(fmt("%s/.git", path))) { | 176 | if (is_git_dir(fmt("%s/.git", path))) { |
107 | add_repo(base, fmt("%s/.git", path), fn); | 177 | add_repo(base, fmt("%s/.git", path), fn); |
108 | return; | 178 | goto end; |
109 | } | ||
110 | dir = opendir(path); | ||
111 | if (!dir) { | ||
112 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", | ||
113 | path, strerror(errno), errno); | ||
114 | return; | ||
115 | } | 179 | } |
116 | while((ent = readdir(dir)) != NULL) { | 180 | while((ent = readdir(dir)) != NULL) { |
117 | if (ent->d_name[0] == '.') { | 181 | if (ent->d_name[0] == '.') { |
118 | if (ent->d_name[1] == '\0') | 182 | if (ent->d_name[1] == '\0') |
119 | continue; | 183 | continue; |
120 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') | 184 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') |
121 | continue; | 185 | continue; |
186 | if (!ctx.cfg.scan_hidden_path) | ||
187 | continue; | ||
122 | } | 188 | } |
123 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); | 189 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); |
124 | if (!buf) { | 190 | if (!buf) { |
125 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", | 191 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", |
126 | path, strerror(errno), errno); | 192 | path, strerror(errno), errno); |
127 | exit(1); | 193 | exit(1); |
128 | } | 194 | } |
129 | sprintf(buf, "%s/%s", path, ent->d_name); | 195 | sprintf(buf, "%s/%s", path, ent->d_name); |
130 | if (stat(buf, &st)) { | 196 | if (stat(buf, &st)) { |
131 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 197 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
132 | buf, strerror(errno), errno); | 198 | buf, strerror(errno), errno); |
133 | free(buf); | 199 | free(buf); |
134 | continue; | 200 | continue; |
135 | } | 201 | } |
136 | if (S_ISDIR(st.st_mode)) | 202 | if (S_ISDIR(st.st_mode)) |
137 | scan_path(base, buf, fn); | 203 | scan_path(base, buf, fn); |
138 | free(buf); | 204 | free(buf); |
139 | } | 205 | } |
206 | end: | ||
140 | closedir(dir); | 207 | closedir(dir); |
141 | } | 208 | } |
142 | 209 | ||
210 | #define lastc(s) s[strlen(s) - 1] | ||
211 | |||
212 | void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) | ||
213 | { | ||
214 | char line[MAX_PATH * 2], *z; | ||
215 | FILE *projects; | ||
216 | int err; | ||
217 | |||
218 | projects = fopen(projectsfile, "r"); | ||
219 | if (!projects) { | ||
220 | fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", | ||
221 | projectsfile, strerror(errno), errno); | ||
222 | } | ||
223 | while (fgets(line, sizeof(line), projects) != NULL) { | ||
224 | for (z = &lastc(line); | ||
225 | strlen(line) && strchr("\n\r", *z); | ||
226 | z = &lastc(line)) | ||
227 | *z = '\0'; | ||
228 | if (strlen(line)) | ||
229 | scan_path(path, fmt("%s/%s", path, line), fn); | ||
230 | } | ||
231 | if ((err = ferror(projects))) { | ||
232 | fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", | ||
233 | projectsfile, strerror(err), err); | ||
234 | } | ||
235 | fclose(projects); | ||
236 | } | ||
237 | |||
143 | void scan_tree(const char *path, repo_config_fn fn) | 238 | void scan_tree(const char *path, repo_config_fn fn) |
144 | { | 239 | { |
145 | scan_path(path, path, fn); | 240 | scan_path(path, path, fn); |
146 | } | 241 | } |
diff --git a/scan-tree.h b/scan-tree.h index 11539f4..1afbd4b 100644 --- a/scan-tree.h +++ b/scan-tree.h | |||
@@ -1,3 +1,2 @@ | |||
1 | 1 | extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn); | |
2 | |||
3 | extern void scan_tree(const char *path, repo_config_fn fn); | 2 | extern void scan_tree(const char *path, repo_config_fn fn); |
@@ -1,112 +1,114 @@ | |||
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 cgit_repolist cgit_repolist; | 11 | struct cgit_repolist cgit_repolist; |
12 | struct cgit_context ctx; | 12 | struct cgit_context ctx; |
13 | int cgit_cmd; | ||
14 | 13 | ||
15 | int chk_zero(int result, char *msg) | 14 | int chk_zero(int result, char *msg) |
16 | { | 15 | { |
17 | if (result != 0) | 16 | if (result != 0) |
18 | die("%s: %s", msg, strerror(errno)); | 17 | die("%s: %s", msg, strerror(errno)); |
19 | return result; | 18 | return result; |
20 | } | 19 | } |
21 | 20 | ||
22 | int chk_positive(int result, char *msg) | 21 | int chk_positive(int result, char *msg) |
23 | { | 22 | { |
24 | if (result <= 0) | 23 | if (result <= 0) |
25 | die("%s: %s", msg, strerror(errno)); | 24 | die("%s: %s", msg, strerror(errno)); |
26 | return result; | 25 | return result; |
27 | } | 26 | } |
28 | 27 | ||
29 | int chk_non_negative(int result, char *msg) | 28 | int chk_non_negative(int result, char *msg) |
30 | { | 29 | { |
31 | if (result < 0) | 30 | if (result < 0) |
32 | die("%s: %s",msg, strerror(errno)); | 31 | die("%s: %s",msg, strerror(errno)); |
33 | return result; | 32 | return result; |
34 | } | 33 | } |
35 | 34 | ||
36 | struct cgit_repo *cgit_add_repo(const char *url) | 35 | struct cgit_repo *cgit_add_repo(const char *url) |
37 | { | 36 | { |
38 | struct cgit_repo *ret; | 37 | struct cgit_repo *ret; |
39 | 38 | ||
40 | if (++cgit_repolist.count > cgit_repolist.length) { | 39 | if (++cgit_repolist.count > cgit_repolist.length) { |
41 | if (cgit_repolist.length == 0) | 40 | if (cgit_repolist.length == 0) |
42 | cgit_repolist.length = 8; | 41 | cgit_repolist.length = 8; |
43 | else | 42 | else |
44 | cgit_repolist.length *= 2; | 43 | cgit_repolist.length *= 2; |
45 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 44 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
46 | cgit_repolist.length * | 45 | cgit_repolist.length * |
47 | sizeof(struct cgit_repo)); | 46 | sizeof(struct cgit_repo)); |
48 | } | 47 | } |
49 | 48 | ||
50 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 49 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
51 | memset(ret, 0, sizeof(struct cgit_repo)); | 50 | memset(ret, 0, sizeof(struct cgit_repo)); |
52 | ret->url = trim_end(url, '/'); | 51 | ret->url = trim_end(url, '/'); |
53 | ret->name = ret->url; | 52 | ret->name = ret->url; |
54 | ret->path = NULL; | 53 | ret->path = NULL; |
55 | ret->desc = "[no description]"; | 54 | ret->desc = "[no description]"; |
56 | ret->owner = NULL; | 55 | ret->owner = NULL; |
57 | ret->section = ctx.cfg.section; | 56 | ret->section = ctx.cfg.section; |
58 | ret->defbranch = "master"; | 57 | ret->defbranch = "master"; |
59 | ret->snapshots = ctx.cfg.snapshots; | 58 | ret->snapshots = ctx.cfg.snapshots; |
59 | ret->enable_commit_graph = ctx.cfg.enable_commit_graph; | ||
60 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 60 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
62 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; | ||
63 | ret->enable_subject_links = ctx.cfg.enable_subject_links; | ||
62 | ret->max_stats = ctx.cfg.max_stats; | 64 | ret->max_stats = ctx.cfg.max_stats; |
63 | ret->module_link = ctx.cfg.module_link; | 65 | ret->module_link = ctx.cfg.module_link; |
64 | ret->readme = NULL; | 66 | ret->readme = ctx.cfg.readme; |
65 | ret->mtime = -1; | 67 | ret->mtime = -1; |
66 | ret->about_filter = ctx.cfg.about_filter; | 68 | ret->about_filter = ctx.cfg.about_filter; |
67 | ret->commit_filter = ctx.cfg.commit_filter; | 69 | ret->commit_filter = ctx.cfg.commit_filter; |
68 | ret->source_filter = ctx.cfg.source_filter; | 70 | ret->source_filter = ctx.cfg.source_filter; |
69 | return ret; | 71 | return ret; |
70 | } | 72 | } |
71 | 73 | ||
72 | struct cgit_repo *cgit_get_repoinfo(const char *url) | 74 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
73 | { | 75 | { |
74 | int i; | 76 | int i; |
75 | struct cgit_repo *repo; | 77 | struct cgit_repo *repo; |
76 | 78 | ||
77 | for (i=0; i<cgit_repolist.count; i++) { | 79 | for (i=0; i<cgit_repolist.count; i++) { |
78 | repo = &cgit_repolist.repos[i]; | 80 | repo = &cgit_repolist.repos[i]; |
79 | if (!strcmp(repo->url, url)) | 81 | if (!strcmp(repo->url, url)) |
80 | return repo; | 82 | return repo; |
81 | } | 83 | } |
82 | return NULL; | 84 | return NULL; |
83 | } | 85 | } |
84 | 86 | ||
85 | void *cgit_free_commitinfo(struct commitinfo *info) | 87 | void *cgit_free_commitinfo(struct commitinfo *info) |
86 | { | 88 | { |
87 | free(info->author); | 89 | free(info->author); |
88 | free(info->author_email); | 90 | free(info->author_email); |
89 | free(info->committer); | 91 | free(info->committer); |
90 | free(info->committer_email); | 92 | free(info->committer_email); |
91 | free(info->subject); | 93 | free(info->subject); |
92 | free(info->msg); | 94 | free(info->msg); |
93 | free(info->msg_encoding); | 95 | free(info->msg_encoding); |
94 | free(info); | 96 | free(info); |
95 | return NULL; | 97 | return NULL; |
96 | } | 98 | } |
97 | 99 | ||
98 | char *trim_end(const char *str, char c) | 100 | char *trim_end(const char *str, char c) |
99 | { | 101 | { |
100 | int len; | 102 | int len; |
101 | char *s, *t; | 103 | char *s, *t; |
102 | 104 | ||
103 | if (str == NULL) | 105 | if (str == NULL) |
104 | return NULL; | 106 | return NULL; |
105 | t = (char *)str; | 107 | t = (char *)str; |
106 | len = strlen(t); | 108 | len = strlen(t); |
107 | while(len > 0 && t[len - 1] == c) | 109 | while(len > 0 && t[len - 1] == c) |
108 | len--; | 110 | len--; |
109 | 111 | ||
110 | if (len == 0) | 112 | if (len == 0) |
111 | return NULL; | 113 | return NULL; |
112 | 114 | ||
@@ -217,216 +219,293 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | |||
217 | 219 | ||
218 | /* | 220 | /* |
219 | * Receive diff-buffers from xdiff and concatenate them as | 221 | * Receive diff-buffers from xdiff and concatenate them as |
220 | * needed across multiple callbacks. | 222 | * needed across multiple callbacks. |
221 | * | 223 | * |
222 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 224 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
223 | * ripped from git and modified to use globals instead of | 225 | * ripped from git and modified to use globals instead of |
224 | * a special callback-struct. | 226 | * a special callback-struct. |
225 | */ | 227 | */ |
226 | char *diffbuf = NULL; | 228 | char *diffbuf = NULL; |
227 | int buflen = 0; | 229 | int buflen = 0; |
228 | 230 | ||
229 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) | 231 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
230 | { | 232 | { |
231 | int i; | 233 | int i; |
232 | 234 | ||
233 | for (i = 0; i < nbuf; i++) { | 235 | for (i = 0; i < nbuf; i++) { |
234 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 236 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
235 | /* Incomplete line */ | 237 | /* Incomplete line */ |
236 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 238 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
237 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 239 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
238 | buflen += mb[i].size; | 240 | buflen += mb[i].size; |
239 | continue; | 241 | continue; |
240 | } | 242 | } |
241 | 243 | ||
242 | /* we have a complete line */ | 244 | /* we have a complete line */ |
243 | if (!diffbuf) { | 245 | if (!diffbuf) { |
244 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); | 246 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
245 | continue; | 247 | continue; |
246 | } | 248 | } |
247 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 249 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
248 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 250 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
249 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); | 251 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
250 | free(diffbuf); | 252 | free(diffbuf); |
251 | diffbuf = NULL; | 253 | diffbuf = NULL; |
252 | buflen = 0; | 254 | buflen = 0; |
253 | } | 255 | } |
254 | if (diffbuf) { | 256 | if (diffbuf) { |
255 | ((linediff_fn)priv)(diffbuf, buflen); | 257 | ((linediff_fn)priv)(diffbuf, buflen); |
256 | free(diffbuf); | 258 | free(diffbuf); |
257 | diffbuf = NULL; | 259 | diffbuf = NULL; |
258 | buflen = 0; | 260 | buflen = 0; |
259 | } | 261 | } |
260 | return 0; | 262 | return 0; |
261 | } | 263 | } |
262 | 264 | ||
263 | int cgit_diff_files(const unsigned char *old_sha1, | 265 | int cgit_diff_files(const unsigned char *old_sha1, |
264 | const unsigned char *new_sha1, unsigned long *old_size, | 266 | const unsigned char *new_sha1, unsigned long *old_size, |
265 | unsigned long *new_size, int *binary, linediff_fn fn) | 267 | unsigned long *new_size, int *binary, int context, |
268 | int ignorews, linediff_fn fn) | ||
266 | { | 269 | { |
267 | mmfile_t file1, file2; | 270 | mmfile_t file1, file2; |
268 | xpparam_t diff_params; | 271 | xpparam_t diff_params; |
269 | xdemitconf_t emit_params; | 272 | xdemitconf_t emit_params; |
270 | xdemitcb_t emit_cb; | 273 | xdemitcb_t emit_cb; |
271 | 274 | ||
272 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) | 275 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
273 | return 1; | 276 | return 1; |
274 | 277 | ||
275 | *old_size = file1.size; | 278 | *old_size = file1.size; |
276 | *new_size = file2.size; | 279 | *new_size = file2.size; |
277 | 280 | ||
278 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || | 281 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || |
279 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { | 282 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { |
280 | *binary = 1; | 283 | *binary = 1; |
281 | if (file1.size) | 284 | if (file1.size) |
282 | free(file1.ptr); | 285 | free(file1.ptr); |
283 | if (file2.size) | 286 | if (file2.size) |
284 | free(file2.ptr); | 287 | free(file2.ptr); |
285 | return 0; | 288 | return 0; |
286 | } | 289 | } |
287 | 290 | ||
288 | memset(&diff_params, 0, sizeof(diff_params)); | 291 | memset(&diff_params, 0, sizeof(diff_params)); |
289 | memset(&emit_params, 0, sizeof(emit_params)); | 292 | memset(&emit_params, 0, sizeof(emit_params)); |
290 | memset(&emit_cb, 0, sizeof(emit_cb)); | 293 | memset(&emit_cb, 0, sizeof(emit_cb)); |
291 | diff_params.flags = XDF_NEED_MINIMAL; | 294 | diff_params.flags = XDF_NEED_MINIMAL; |
292 | emit_params.ctxlen = 3; | 295 | if (ignorews) |
296 | diff_params.flags |= XDF_IGNORE_WHITESPACE; | ||
297 | emit_params.ctxlen = context > 0 ? context : 3; | ||
293 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 298 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
294 | emit_cb.outf = filediff_cb; | 299 | emit_cb.outf = filediff_cb; |
295 | emit_cb.priv = fn; | 300 | emit_cb.priv = fn; |
296 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 301 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
297 | if (file1.size) | 302 | if (file1.size) |
298 | free(file1.ptr); | 303 | free(file1.ptr); |
299 | if (file2.size) | 304 | if (file2.size) |
300 | free(file2.ptr); | 305 | free(file2.ptr); |
301 | return 0; | 306 | return 0; |
302 | } | 307 | } |
303 | 308 | ||
304 | void cgit_diff_tree(const unsigned char *old_sha1, | 309 | void cgit_diff_tree(const unsigned char *old_sha1, |
305 | const unsigned char *new_sha1, | 310 | const unsigned char *new_sha1, |
306 | filepair_fn fn, const char *prefix) | 311 | filepair_fn fn, const char *prefix, int ignorews) |
307 | { | 312 | { |
308 | struct diff_options opt; | 313 | struct diff_options opt; |
309 | int ret; | 314 | int ret; |
310 | int prefixlen; | 315 | int prefixlen; |
311 | 316 | ||
312 | diff_setup(&opt); | 317 | diff_setup(&opt); |
313 | opt.output_format = DIFF_FORMAT_CALLBACK; | 318 | opt.output_format = DIFF_FORMAT_CALLBACK; |
314 | opt.detect_rename = 1; | 319 | opt.detect_rename = 1; |
315 | opt.rename_limit = ctx.cfg.renamelimit; | 320 | opt.rename_limit = ctx.cfg.renamelimit; |
316 | DIFF_OPT_SET(&opt, RECURSIVE); | 321 | DIFF_OPT_SET(&opt, RECURSIVE); |
322 | if (ignorews) | ||
323 | DIFF_XDL_SET(&opt, IGNORE_WHITESPACE); | ||
317 | opt.format_callback = cgit_diff_tree_cb; | 324 | opt.format_callback = cgit_diff_tree_cb; |
318 | opt.format_callback_data = fn; | 325 | opt.format_callback_data = fn; |
319 | if (prefix) { | 326 | if (prefix) { |
320 | opt.nr_paths = 1; | 327 | opt.nr_paths = 1; |
321 | opt.paths = &prefix; | 328 | opt.paths = &prefix; |
322 | prefixlen = strlen(prefix); | 329 | prefixlen = strlen(prefix); |
323 | opt.pathlens = &prefixlen; | 330 | opt.pathlens = &prefixlen; |
324 | } | 331 | } |
325 | diff_setup_done(&opt); | 332 | diff_setup_done(&opt); |
326 | 333 | ||
327 | if (old_sha1 && !is_null_sha1(old_sha1)) | 334 | if (old_sha1 && !is_null_sha1(old_sha1)) |
328 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); | 335 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); |
329 | else | 336 | else |
330 | ret = diff_root_tree_sha1(new_sha1, "", &opt); | 337 | ret = diff_root_tree_sha1(new_sha1, "", &opt); |
331 | diffcore_std(&opt); | 338 | diffcore_std(&opt); |
332 | diff_flush(&opt); | 339 | diff_flush(&opt); |
333 | } | 340 | } |
334 | 341 | ||
335 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) | 342 | void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) |
336 | { | 343 | { |
337 | unsigned char *old_sha1 = NULL; | 344 | unsigned char *old_sha1 = NULL; |
338 | 345 | ||
339 | if (commit->parents) | 346 | if (commit->parents) |
340 | old_sha1 = commit->parents->item->object.sha1; | 347 | old_sha1 = commit->parents->item->object.sha1; |
341 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); | 348 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, prefix, |
349 | ctx.qry.ignorews); | ||
342 | } | 350 | } |
343 | 351 | ||
344 | int cgit_parse_snapshots_mask(const char *str) | 352 | int cgit_parse_snapshots_mask(const char *str) |
345 | { | 353 | { |
346 | const struct cgit_snapshot_format *f; | 354 | const struct cgit_snapshot_format *f; |
347 | static const char *delim = " \t,:/|;"; | 355 | static const char *delim = " \t,:/|;"; |
348 | int tl, sl, rv = 0; | 356 | int tl, sl, rv = 0; |
349 | 357 | ||
350 | /* favor legacy setting */ | 358 | /* favor legacy setting */ |
351 | if(atoi(str)) | 359 | if(atoi(str)) |
352 | return 1; | 360 | return 1; |
353 | for(;;) { | 361 | for(;;) { |
354 | str += strspn(str,delim); | 362 | str += strspn(str,delim); |
355 | tl = strcspn(str,delim); | 363 | tl = strcspn(str,delim); |
356 | if (!tl) | 364 | if (!tl) |
357 | break; | 365 | break; |
358 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 366 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
359 | sl = strlen(f->suffix); | 367 | sl = strlen(f->suffix); |
360 | if((tl == sl && !strncmp(f->suffix, str, tl)) || | 368 | if((tl == sl && !strncmp(f->suffix, str, tl)) || |
361 | (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) { | 369 | (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) { |
362 | rv |= f->bit; | 370 | rv |= f->bit; |
363 | break; | 371 | break; |
364 | } | 372 | } |
365 | } | 373 | } |
366 | str += tl; | 374 | str += tl; |
367 | } | 375 | } |
368 | return rv; | 376 | return rv; |
369 | } | 377 | } |
370 | 378 | ||
371 | int cgit_open_filter(struct cgit_filter *filter) | 379 | int cgit_open_filter(struct cgit_filter *filter) |
372 | { | 380 | { |
373 | 381 | ||
374 | filter->old_stdout = chk_positive(dup(STDOUT_FILENO), | 382 | filter->old_stdout = chk_positive(dup(STDOUT_FILENO), |
375 | "Unable to duplicate STDOUT"); | 383 | "Unable to duplicate STDOUT"); |
376 | chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess"); | 384 | chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess"); |
377 | filter->pid = chk_non_negative(fork(), "Unable to create subprocess"); | 385 | filter->pid = chk_non_negative(fork(), "Unable to create subprocess"); |
378 | if (filter->pid == 0) { | 386 | if (filter->pid == 0) { |
379 | close(filter->pipe_fh[1]); | 387 | close(filter->pipe_fh[1]); |
380 | chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), | 388 | chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), |
381 | "Unable to use pipe as STDIN"); | 389 | "Unable to use pipe as STDIN"); |
382 | execvp(filter->cmd, filter->argv); | 390 | execvp(filter->cmd, filter->argv); |
383 | die("Unable to exec subprocess %s: %s (%d)", filter->cmd, | 391 | die("Unable to exec subprocess %s: %s (%d)", filter->cmd, |
384 | strerror(errno), errno); | 392 | strerror(errno), errno); |
385 | } | 393 | } |
386 | close(filter->pipe_fh[0]); | 394 | close(filter->pipe_fh[0]); |
387 | chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO), | 395 | chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO), |
388 | "Unable to use pipe as STDOUT"); | 396 | "Unable to use pipe as STDOUT"); |
389 | close(filter->pipe_fh[1]); | 397 | close(filter->pipe_fh[1]); |
390 | return 0; | 398 | return 0; |
391 | } | 399 | } |
392 | 400 | ||
393 | int cgit_close_filter(struct cgit_filter *filter) | 401 | int cgit_close_filter(struct cgit_filter *filter) |
394 | { | 402 | { |
395 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), | 403 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), |
396 | "Unable to restore STDOUT"); | 404 | "Unable to restore STDOUT"); |
397 | close(filter->old_stdout); | 405 | close(filter->old_stdout); |
398 | if (filter->pid < 0) | 406 | if (filter->pid < 0) |
399 | return 0; | 407 | return 0; |
400 | waitpid(filter->pid, &filter->exitstatus, 0); | 408 | waitpid(filter->pid, &filter->exitstatus, 0); |
401 | if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus)) | 409 | if (WIFEXITED(filter->exitstatus) && !WEXITSTATUS(filter->exitstatus)) |
402 | return 0; | 410 | return 0; |
403 | die("Subprocess %s exited abnormally", filter->cmd); | 411 | die("Subprocess %s exited abnormally", filter->cmd); |
404 | } | 412 | } |
405 | 413 | ||
406 | /* Read the content of the specified file into a newly allocated buffer, | 414 | /* Read the content of the specified file into a newly allocated buffer, |
407 | * zeroterminate the buffer and return 0 on success, errno otherwise. | 415 | * zeroterminate the buffer and return 0 on success, errno otherwise. |
408 | */ | 416 | */ |
409 | int readfile(const char *path, char **buf, size_t *size) | 417 | int readfile(const char *path, char **buf, size_t *size) |
410 | { | 418 | { |
411 | int fd, e; | 419 | int fd, e; |
412 | struct stat st; | 420 | struct stat st; |
413 | 421 | ||
414 | fd = open(path, O_RDONLY); | 422 | fd = open(path, O_RDONLY); |
415 | if (fd == -1) | 423 | if (fd == -1) |
416 | return errno; | 424 | return errno; |
417 | if (fstat(fd, &st)) { | 425 | if (fstat(fd, &st)) { |
418 | e = errno; | 426 | e = errno; |
419 | close(fd); | 427 | close(fd); |
420 | return e; | 428 | return e; |
421 | } | 429 | } |
422 | if (!S_ISREG(st.st_mode)) { | 430 | if (!S_ISREG(st.st_mode)) { |
423 | close(fd); | 431 | close(fd); |
424 | return EISDIR; | 432 | return EISDIR; |
425 | } | 433 | } |
426 | *buf = xmalloc(st.st_size + 1); | 434 | *buf = xmalloc(st.st_size + 1); |
427 | *size = read_in_full(fd, *buf, st.st_size); | 435 | *size = read_in_full(fd, *buf, st.st_size); |
428 | e = errno; | 436 | e = errno; |
429 | (*buf)[*size] = '\0'; | 437 | (*buf)[*size] = '\0'; |
430 | close(fd); | 438 | close(fd); |
431 | return (*size == st.st_size ? 0 : e); | 439 | return (*size == st.st_size ? 0 : e); |
432 | } | 440 | } |
441 | |||
442 | int is_token_char(char c) | ||
443 | { | ||
444 | return isalnum(c) || c == '_'; | ||
445 | } | ||
446 | |||
447 | /* Replace name with getenv(name), return pointer to zero-terminating char | ||
448 | */ | ||
449 | char *expand_macro(char *name, int maxlength) | ||
450 | { | ||
451 | char *value; | ||
452 | int len; | ||
453 | |||
454 | len = 0; | ||
455 | value = getenv(name); | ||
456 | if (value) { | ||
457 | len = strlen(value); | ||
458 | if (len > maxlength) | ||
459 | len = maxlength; | ||
460 | strncpy(name, value, len); | ||
461 | } | ||
462 | return name + len; | ||
463 | } | ||
464 | |||
465 | #define EXPBUFSIZE (1024 * 8) | ||
466 | |||
467 | /* Replace all tokens prefixed by '$' in the specified text with the | ||
468 | * value of the named environment variable. | ||
469 | * NB: the return value is a static buffer, i.e. it must be strdup'd | ||
470 | * by the caller. | ||
471 | */ | ||
472 | char *expand_macros(const char *txt) | ||
473 | { | ||
474 | static char result[EXPBUFSIZE]; | ||
475 | char *p, *start; | ||
476 | int len; | ||
477 | |||
478 | p = result; | ||
479 | start = NULL; | ||
480 | while (p < result + EXPBUFSIZE - 1 && txt && *txt) { | ||
481 | *p = *txt; | ||
482 | if (start) { | ||
483 | if (!is_token_char(*txt)) { | ||
484 | if (p - start > 0) { | ||
485 | *p = '\0'; | ||
486 | len = result + EXPBUFSIZE - start - 1; | ||
487 | p = expand_macro(start, len) - 1; | ||
488 | } | ||
489 | start = NULL; | ||
490 | txt--; | ||
491 | } | ||
492 | p++; | ||
493 | txt++; | ||
494 | continue; | ||
495 | } | ||
496 | if (*txt == '$') { | ||
497 | start = p; | ||
498 | txt++; | ||
499 | continue; | ||
500 | } | ||
501 | p++; | ||
502 | txt++; | ||
503 | } | ||
504 | *p = '\0'; | ||
505 | if (start && p - start > 0) { | ||
506 | len = result + EXPBUFSIZE - start - 1; | ||
507 | p = expand_macro(start, len); | ||
508 | *p = '\0'; | ||
509 | } | ||
510 | return result; | ||
511 | } | ||
@@ -1,131 +1,141 @@ | |||
1 | /* ui-atom.c: functions for atom feeds | 1 | /* ui-atom.c: functions for atom feeds |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | void add_entry(struct commit *commit, char *host) | 13 | void add_entry(struct commit *commit, char *host) |
14 | { | 14 | { |
15 | char delim = '&'; | 15 | char delim = '&'; |
16 | char *hex; | 16 | char *hex; |
17 | char *mail, *t, *t2; | 17 | char *mail, *t, *t2; |
18 | struct commitinfo *info; | 18 | struct commitinfo *info; |
19 | 19 | ||
20 | info = cgit_parse_commit(commit); | 20 | info = cgit_parse_commit(commit); |
21 | hex = sha1_to_hex(commit->object.sha1); | 21 | hex = sha1_to_hex(commit->object.sha1); |
22 | html("<entry>\n"); | 22 | html("<entry>\n"); |
23 | html("<title>"); | 23 | html("<title>"); |
24 | html_txt(info->subject); | 24 | html_txt(info->subject); |
25 | html("</title>\n"); | 25 | html("</title>\n"); |
26 | html("<updated>"); | 26 | html("<updated>"); |
27 | cgit_print_date(info->author_date, FMT_ATOMDATE, 0); | 27 | cgit_print_date(info->committer_date, FMT_ATOMDATE, 0); |
28 | html("</updated>\n"); | 28 | html("</updated>\n"); |
29 | html("<author>\n"); | 29 | html("<author>\n"); |
30 | if (info->author) { | 30 | if (info->author) { |
31 | html("<name>"); | 31 | html("<name>"); |
32 | html_txt(info->author); | 32 | html_txt(info->author); |
33 | html("</name>\n"); | 33 | html("</name>\n"); |
34 | } | 34 | } |
35 | if (info->author_email && !ctx.cfg.noplainemail) { | 35 | if (info->author_email && !ctx.cfg.noplainemail) { |
36 | mail = xstrdup(info->author_email); | 36 | mail = xstrdup(info->author_email); |
37 | t = strchr(mail, '<'); | 37 | t = strchr(mail, '<'); |
38 | if (t) | 38 | if (t) |
39 | t++; | 39 | t++; |
40 | else | 40 | else |
41 | t = mail; | 41 | t = mail; |
42 | t2 = strchr(t, '>'); | 42 | t2 = strchr(t, '>'); |
43 | if (t2) | 43 | if (t2) |
44 | *t2 = '\0'; | 44 | *t2 = '\0'; |
45 | html("<email>"); | 45 | html("<email>"); |
46 | html_txt(t); | 46 | html_txt(t); |
47 | html("</email>\n"); | 47 | html("</email>\n"); |
48 | free(mail); | 48 | free(mail); |
49 | } | 49 | } |
50 | html("</author>\n"); | 50 | html("</author>\n"); |
51 | html("<published>"); | 51 | html("<published>"); |
52 | cgit_print_date(info->author_date, FMT_ATOMDATE, 0); | 52 | cgit_print_date(info->author_date, FMT_ATOMDATE, 0); |
53 | html("</published>\n"); | 53 | html("</published>\n"); |
54 | if (host) { | 54 | if (host) { |
55 | html("<link rel='alternate' type='text/html' href='"); | 55 | html("<link rel='alternate' type='text/html' href='"); |
56 | html(cgit_httpscheme()); | 56 | html(cgit_httpscheme()); |
57 | html_attr(host); | 57 | html_attr(host); |
58 | html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL)); | 58 | html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL)); |
59 | if (ctx.cfg.virtual_root) | 59 | if (ctx.cfg.virtual_root) |
60 | delim = '?'; | 60 | delim = '?'; |
61 | htmlf("%cid=%s", delim, hex); | 61 | htmlf("%cid=%s", delim, hex); |
62 | html("'/>\n"); | 62 | html("'/>\n"); |
63 | } | 63 | } |
64 | htmlf("<id>%s</id>\n", hex); | 64 | htmlf("<id>%s</id>\n", hex); |
65 | html("<content type='text'>\n"); | 65 | html("<content type='text'>\n"); |
66 | html_txt(info->msg); | 66 | html_txt(info->msg); |
67 | html("</content>\n"); | 67 | html("</content>\n"); |
68 | html("<content type='xhtml'>\n"); | 68 | html("<content type='xhtml'>\n"); |
69 | html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); | 69 | html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); |
70 | html("<pre>\n"); | 70 | html("<pre>\n"); |
71 | html_txt(info->msg); | 71 | html_txt(info->msg); |
72 | html("</pre>\n"); | 72 | html("</pre>\n"); |
73 | html("</div>\n"); | 73 | html("</div>\n"); |
74 | html("</content>\n"); | 74 | html("</content>\n"); |
75 | html("</entry>\n"); | 75 | html("</entry>\n"); |
76 | cgit_free_commitinfo(info); | 76 | cgit_free_commitinfo(info); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | void cgit_print_atom(char *tip, char *path, int max_count) | 80 | void cgit_print_atom(char *tip, char *path, int max_count) |
81 | { | 81 | { |
82 | char *host; | 82 | char *host; |
83 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 83 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
84 | struct commit *commit; | 84 | struct commit *commit; |
85 | struct rev_info rev; | 85 | struct rev_info rev; |
86 | int argc = 2; | 86 | int argc = 2; |
87 | 87 | ||
88 | if (!tip) | 88 | if (ctx.qry.show_all) |
89 | argv[1] = "--all"; | ||
90 | else if (!tip) | ||
89 | argv[1] = ctx.qry.head; | 91 | argv[1] = ctx.qry.head; |
90 | 92 | ||
91 | if (path) { | 93 | if (path) { |
92 | argv[argc++] = "--"; | 94 | argv[argc++] = "--"; |
93 | argv[argc++] = path; | 95 | argv[argc++] = path; |
94 | } | 96 | } |
95 | 97 | ||
96 | init_revisions(&rev, NULL); | 98 | init_revisions(&rev, NULL); |
97 | rev.abbrev = DEFAULT_ABBREV; | 99 | rev.abbrev = DEFAULT_ABBREV; |
98 | rev.commit_format = CMIT_FMT_DEFAULT; | 100 | rev.commit_format = CMIT_FMT_DEFAULT; |
99 | rev.verbose_header = 1; | 101 | rev.verbose_header = 1; |
100 | rev.show_root_diff = 0; | 102 | rev.show_root_diff = 0; |
101 | rev.max_count = max_count; | 103 | rev.max_count = max_count; |
102 | setup_revisions(argc, argv, &rev, NULL); | 104 | setup_revisions(argc, argv, &rev, NULL); |
103 | prepare_revision_walk(&rev); | 105 | prepare_revision_walk(&rev); |
104 | 106 | ||
105 | host = cgit_hosturl(); | 107 | host = cgit_hosturl(); |
106 | ctx.page.mimetype = "text/xml"; | 108 | ctx.page.mimetype = "text/xml"; |
107 | ctx.page.charset = "utf-8"; | 109 | ctx.page.charset = "utf-8"; |
108 | cgit_print_http_headers(&ctx); | 110 | cgit_print_http_headers(&ctx); |
109 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); | 111 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); |
110 | html("<title>"); | 112 | html("<title>"); |
111 | html_txt(ctx.repo->name); | 113 | html_txt(ctx.repo->name); |
114 | if (path) { | ||
115 | html("/"); | ||
116 | html_txt(path); | ||
117 | } | ||
118 | if (tip && !ctx.qry.show_all) { | ||
119 | html(", branch "); | ||
120 | html_txt(tip); | ||
121 | } | ||
112 | html("</title>\n"); | 122 | html("</title>\n"); |
113 | html("<subtitle>"); | 123 | html("<subtitle>"); |
114 | html_txt(ctx.repo->desc); | 124 | html_txt(ctx.repo->desc); |
115 | html("</subtitle>\n"); | 125 | html("</subtitle>\n"); |
116 | if (host) { | 126 | if (host) { |
117 | html("<link rel='alternate' type='text/html' href='"); | 127 | html("<link rel='alternate' type='text/html' href='"); |
118 | html(cgit_httpscheme()); | 128 | html(cgit_httpscheme()); |
119 | html_attr(host); | 129 | html_attr(host); |
120 | html_attr(cgit_repourl(ctx.repo->url)); | 130 | html_attr(cgit_repourl(ctx.repo->url)); |
121 | html("'/>\n"); | 131 | html("'/>\n"); |
122 | } | 132 | } |
123 | while ((commit = get_revision(&rev)) != NULL) { | 133 | while ((commit = get_revision(&rev)) != NULL) { |
124 | add_entry(commit, host); | 134 | add_entry(commit, host); |
125 | free(commit->buffer); | 135 | free(commit->buffer); |
126 | commit->buffer = NULL; | 136 | commit->buffer = NULL; |
127 | free_commit_list(commit->parents); | 137 | free_commit_list(commit->parents); |
128 | commit->parents = NULL; | 138 | commit->parents = NULL; |
129 | } | 139 | } |
130 | html("</feed>\n"); | 140 | html("</feed>\n"); |
131 | } | 141 | } |
@@ -1,79 +1,112 @@ | |||
1 | /* ui-blob.c: show blob content | 1 | /* ui-blob.c: show blob content |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
4 | * | 5 | * |
5 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
7 | */ | 8 | */ |
8 | 9 | ||
9 | #include "cgit.h" | 10 | #include "cgit.h" |
10 | #include "html.h" | 11 | #include "html.h" |
11 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
12 | 13 | ||
13 | static char *match_path; | 14 | static char *match_path; |
14 | static unsigned char *matched_sha1; | 15 | static unsigned char *matched_sha1; |
16 | static int found_path; | ||
15 | 17 | ||
16 | static int walk_tree(const unsigned char *sha1, const char *base,int baselen, | 18 | static int walk_tree(const unsigned char *sha1, const char *base,int baselen, |
17 | const char *pathname, unsigned mode, int stage, void *cbdata) { | 19 | const char *pathname, unsigned mode, int stage, void *cbdata) { |
18 | if(strncmp(base,match_path,baselen) | 20 | if(strncmp(base,match_path,baselen) |
19 | || strcmp(match_path+baselen,pathname) ) | 21 | || strcmp(match_path+baselen,pathname) ) |
20 | return READ_TREE_RECURSIVE; | 22 | return READ_TREE_RECURSIVE; |
21 | memmove(matched_sha1,sha1,20); | 23 | memmove(matched_sha1,sha1,20); |
24 | found_path = 1; | ||
22 | return 0; | 25 | return 0; |
23 | } | 26 | } |
24 | 27 | ||
25 | void cgit_print_blob(const char *hex, char *path, const char *head) | 28 | int cgit_print_file(char *path, const char *head) |
26 | { | 29 | { |
30 | unsigned char sha1[20]; | ||
31 | enum object_type type; | ||
32 | char *buf; | ||
33 | unsigned long size; | ||
34 | struct commit *commit; | ||
35 | const char *paths[] = {path, NULL}; | ||
36 | if (get_sha1(head, sha1)) | ||
37 | return -1; | ||
38 | type = sha1_object_info(sha1, &size); | ||
39 | if(type == OBJ_COMMIT && path) { | ||
40 | commit = lookup_commit_reference(sha1); | ||
41 | match_path = path; | ||
42 | matched_sha1 = sha1; | ||
43 | found_path = 0; | ||
44 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | ||
45 | if (!found_path) | ||
46 | return -1; | ||
47 | type = sha1_object_info(sha1, &size); | ||
48 | } | ||
49 | if (type == OBJ_BAD) | ||
50 | return -1; | ||
51 | buf = read_sha1_file(sha1, &type, &size); | ||
52 | if (!buf) | ||
53 | return -1; | ||
54 | buf[size] = '\0'; | ||
55 | html_raw(buf, size); | ||
56 | return 0; | ||
57 | } | ||
27 | 58 | ||
59 | void cgit_print_blob(const char *hex, char *path, const char *head) | ||
60 | { | ||
28 | unsigned char sha1[20]; | 61 | unsigned char sha1[20]; |
29 | enum object_type type; | 62 | enum object_type type; |
30 | char *buf; | 63 | char *buf; |
31 | unsigned long size; | 64 | unsigned long size; |
32 | struct commit *commit; | 65 | struct commit *commit; |
33 | const char *paths[] = {path, NULL}; | 66 | const char *paths[] = {path, NULL}; |
34 | 67 | ||
35 | if (hex) { | 68 | if (hex) { |
36 | if (get_sha1_hex(hex, sha1)){ | 69 | if (get_sha1_hex(hex, sha1)){ |
37 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 70 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
38 | return; | 71 | return; |
39 | } | 72 | } |
40 | } else { | 73 | } else { |
41 | if (get_sha1(head,sha1)) { | 74 | if (get_sha1(head,sha1)) { |
42 | cgit_print_error(fmt("Bad ref: %s", head)); | 75 | cgit_print_error(fmt("Bad ref: %s", head)); |
43 | return; | 76 | return; |
44 | } | 77 | } |
45 | } | 78 | } |
46 | 79 | ||
47 | type = sha1_object_info(sha1, &size); | 80 | type = sha1_object_info(sha1, &size); |
48 | 81 | ||
49 | if((!hex) && type == OBJ_COMMIT && path) { | 82 | if((!hex) && type == OBJ_COMMIT && path) { |
50 | commit = lookup_commit_reference(sha1); | 83 | commit = lookup_commit_reference(sha1); |
51 | match_path = path; | 84 | match_path = path; |
52 | matched_sha1 = sha1; | 85 | matched_sha1 = sha1; |
53 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | 86 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); |
54 | type = sha1_object_info(sha1,&size); | 87 | type = sha1_object_info(sha1,&size); |
55 | } | 88 | } |
56 | 89 | ||
57 | if (type == OBJ_BAD) { | 90 | if (type == OBJ_BAD) { |
58 | cgit_print_error(fmt("Bad object name: %s", hex)); | 91 | cgit_print_error(fmt("Bad object name: %s", hex)); |
59 | return; | 92 | return; |
60 | } | 93 | } |
61 | 94 | ||
62 | buf = read_sha1_file(sha1, &type, &size); | 95 | buf = read_sha1_file(sha1, &type, &size); |
63 | if (!buf) { | 96 | if (!buf) { |
64 | cgit_print_error(fmt("Error reading object %s", hex)); | 97 | cgit_print_error(fmt("Error reading object %s", hex)); |
65 | return; | 98 | return; |
66 | } | 99 | } |
67 | 100 | ||
68 | buf[size] = '\0'; | 101 | buf[size] = '\0'; |
69 | ctx.page.mimetype = ctx.qry.mimetype; | 102 | ctx.page.mimetype = ctx.qry.mimetype; |
70 | if (!ctx.page.mimetype) { | 103 | if (!ctx.page.mimetype) { |
71 | if (buffer_is_binary(buf, size)) | 104 | if (buffer_is_binary(buf, size)) |
72 | ctx.page.mimetype = "application/octet-stream"; | 105 | ctx.page.mimetype = "application/octet-stream"; |
73 | else | 106 | else |
74 | ctx.page.mimetype = "text/plain"; | 107 | ctx.page.mimetype = "text/plain"; |
75 | } | 108 | } |
76 | ctx.page.filename = path; | 109 | ctx.page.filename = path; |
77 | cgit_print_http_headers(&ctx); | 110 | cgit_print_http_headers(&ctx); |
78 | write(htmlfd, buf, size); | 111 | html_raw(buf, size); |
79 | } | 112 | } |
@@ -1,6 +1,7 @@ | |||
1 | #ifndef UI_BLOB_H | 1 | #ifndef UI_BLOB_H |
2 | #define UI_BLOB_H | 2 | #define UI_BLOB_H |
3 | 3 | ||
4 | extern int cgit_print_file(char *path, const char *head); | ||
4 | extern void cgit_print_blob(const char *hex, char *path, const char *head); | 5 | extern void cgit_print_blob(const char *hex, char *path, const char *head); |
5 | 6 | ||
6 | #endif /* UI_BLOB_H */ | 7 | #endif /* UI_BLOB_H */ |
diff --git a/ui-commit.c b/ui-commit.c index f5b0ae5..2b4f677 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -1,118 +1,146 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | #include "ui-diff.h" | 12 | #include "ui-diff.h" |
13 | #include "ui-log.h" | 13 | #include "ui-log.h" |
14 | 14 | ||
15 | void cgit_print_commit(char *hex) | 15 | void cgit_print_commit(char *hex, const char *prefix) |
16 | { | 16 | { |
17 | struct commit *commit, *parent; | 17 | struct commit *commit, *parent; |
18 | struct commitinfo *info; | 18 | struct commitinfo *info, *parent_info; |
19 | struct commit_list *p; | 19 | struct commit_list *p; |
20 | struct strbuf notes = STRBUF_INIT; | ||
20 | unsigned char sha1[20]; | 21 | unsigned char sha1[20]; |
21 | char *tmp; | 22 | char *tmp, *tmp2; |
22 | int parents = 0; | 23 | int parents = 0; |
23 | 24 | ||
24 | if (!hex) | 25 | if (!hex) |
25 | hex = ctx.qry.head; | 26 | hex = ctx.qry.head; |
26 | 27 | ||
27 | if (get_sha1(hex, sha1)) { | 28 | if (get_sha1(hex, sha1)) { |
28 | cgit_print_error(fmt("Bad object id: %s", hex)); | 29 | cgit_print_error(fmt("Bad object id: %s", hex)); |
29 | return; | 30 | return; |
30 | } | 31 | } |
31 | commit = lookup_commit_reference(sha1); | 32 | commit = lookup_commit_reference(sha1); |
32 | if (!commit) { | 33 | if (!commit) { |
33 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 34 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
34 | return; | 35 | return; |
35 | } | 36 | } |
36 | info = cgit_parse_commit(commit); | 37 | info = cgit_parse_commit(commit); |
37 | 38 | ||
39 | format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0); | ||
40 | |||
38 | load_ref_decorations(DECORATE_FULL_REFS); | 41 | load_ref_decorations(DECORATE_FULL_REFS); |
39 | 42 | ||
40 | html("<table summary='commit info' class='commit-info'>\n"); | 43 | html("<table summary='commit info' class='commit-info'>\n"); |
41 | html("<tr><th>author</th><td>"); | 44 | html("<tr><th>author</th><td>"); |
42 | html_txt(info->author); | 45 | html_txt(info->author); |
43 | if (!ctx.cfg.noplainemail) { | 46 | if (!ctx.cfg.noplainemail) { |
44 | html(" "); | 47 | html(" "); |
45 | html_txt(info->author_email); | 48 | html_txt(info->author_email); |
46 | } | 49 | } |
47 | html("</td><td class='right'>"); | 50 | html("</td><td class='right'>"); |
48 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); | 51 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); |
49 | html("</td></tr>\n"); | 52 | html("</td></tr>\n"); |
50 | html("<tr><th>committer</th><td>"); | 53 | html("<tr><th>committer</th><td>"); |
51 | html_txt(info->committer); | 54 | html_txt(info->committer); |
52 | if (!ctx.cfg.noplainemail) { | 55 | if (!ctx.cfg.noplainemail) { |
53 | html(" "); | 56 | html(" "); |
54 | html_txt(info->committer_email); | 57 | html_txt(info->committer_email); |
55 | } | 58 | } |
56 | html("</td><td class='right'>"); | 59 | html("</td><td class='right'>"); |
57 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); | 60 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); |
58 | html("</td></tr>\n"); | 61 | html("</td></tr>\n"); |
59 | html("<tr><th>commit</th><td colspan='2' class='sha1'>"); | 62 | html("<tr><th>commit</th><td colspan='2' class='sha1'>"); |
60 | tmp = sha1_to_hex(commit->object.sha1); | 63 | tmp = sha1_to_hex(commit->object.sha1); |
61 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp); | 64 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0); |
62 | html(" ("); | 65 | html(" ("); |
63 | cgit_patch_link("patch", NULL, NULL, NULL, tmp); | 66 | cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); |
67 | html(") ("); | ||
68 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | ||
69 | cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); | ||
70 | else | ||
71 | cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); | ||
64 | html(")</td></tr>\n"); | 72 | html(")</td></tr>\n"); |
65 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 73 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
66 | tmp = xstrdup(hex); | 74 | tmp = xstrdup(hex); |
67 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 75 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
68 | ctx.qry.head, tmp, NULL); | 76 | ctx.qry.head, tmp, NULL); |
77 | if (prefix) { | ||
78 | html(" /"); | ||
79 | cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); | ||
80 | } | ||
69 | html("</td></tr>\n"); | 81 | html("</td></tr>\n"); |
70 | for (p = commit->parents; p ; p = p->next) { | 82 | for (p = commit->parents; p ; p = p->next) { |
71 | parent = lookup_commit_reference(p->item->object.sha1); | 83 | parent = lookup_commit_reference(p->item->object.sha1); |
72 | if (!parent) { | 84 | if (!parent) { |
73 | html("<tr><td colspan='3'>"); | 85 | html("<tr><td colspan='3'>"); |
74 | cgit_print_error("Error reading parent commit"); | 86 | cgit_print_error("Error reading parent commit"); |
75 | html("</td></tr>"); | 87 | html("</td></tr>"); |
76 | continue; | 88 | continue; |
77 | } | 89 | } |
78 | html("<tr><th>parent</th>" | 90 | html("<tr><th>parent</th>" |
79 | "<td colspan='2' class='sha1'>"); | 91 | "<td colspan='2' class='sha1'>"); |
80 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 92 | tmp = tmp2 = sha1_to_hex(p->item->object.sha1); |
81 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); | 93 | if (ctx.repo->enable_subject_links) { |
94 | parent_info = cgit_parse_commit(parent); | ||
95 | tmp2 = parent_info->subject; | ||
96 | } | ||
97 | cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0); | ||
82 | html(" ("); | 98 | html(" ("); |
83 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, | 99 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
84 | sha1_to_hex(p->item->object.sha1), NULL); | 100 | sha1_to_hex(p->item->object.sha1), prefix, 0); |
85 | html(")</td></tr>"); | 101 | html(")</td></tr>"); |
86 | parents++; | 102 | parents++; |
87 | } | 103 | } |
88 | if (ctx.repo->snapshots) { | 104 | if (ctx.repo->snapshots) { |
89 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 105 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
90 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, | 106 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, |
91 | hex, ctx.repo->snapshots); | 107 | hex, ctx.repo->snapshots); |
92 | html("</td></tr>"); | 108 | html("</td></tr>"); |
93 | } | 109 | } |
94 | html("</table>\n"); | 110 | html("</table>\n"); |
95 | html("<div class='commit-subject'>"); | 111 | html("<div class='commit-subject'>"); |
96 | if (ctx.repo->commit_filter) | 112 | if (ctx.repo->commit_filter) |
97 | cgit_open_filter(ctx.repo->commit_filter); | 113 | cgit_open_filter(ctx.repo->commit_filter); |
98 | html_txt(info->subject); | 114 | html_txt(info->subject); |
99 | if (ctx.repo->commit_filter) | 115 | if (ctx.repo->commit_filter) |
100 | cgit_close_filter(ctx.repo->commit_filter); | 116 | cgit_close_filter(ctx.repo->commit_filter); |
101 | show_commit_decorations(commit); | 117 | show_commit_decorations(commit); |
102 | html("</div>"); | 118 | html("</div>"); |
103 | html("<div class='commit-msg'>"); | 119 | html("<div class='commit-msg'>"); |
104 | if (ctx.repo->commit_filter) | 120 | if (ctx.repo->commit_filter) |
105 | cgit_open_filter(ctx.repo->commit_filter); | 121 | cgit_open_filter(ctx.repo->commit_filter); |
106 | html_txt(info->msg); | 122 | html_txt(info->msg); |
107 | if (ctx.repo->commit_filter) | 123 | if (ctx.repo->commit_filter) |
108 | cgit_close_filter(ctx.repo->commit_filter); | 124 | cgit_close_filter(ctx.repo->commit_filter); |
109 | html("</div>"); | 125 | html("</div>"); |
126 | if (notes.len != 0) { | ||
127 | html("<div class='notes-header'>Notes</div>"); | ||
128 | html("<div class='notes'>"); | ||
129 | if (ctx.repo->commit_filter) | ||
130 | cgit_open_filter(ctx.repo->commit_filter); | ||
131 | html_txt(notes.buf); | ||
132 | if (ctx.repo->commit_filter) | ||
133 | cgit_close_filter(ctx.repo->commit_filter); | ||
134 | html("</div>"); | ||
135 | html("<div class='notes-footer'></div>"); | ||
136 | } | ||
110 | if (parents < 3) { | 137 | if (parents < 3) { |
111 | if (parents) | 138 | if (parents) |
112 | tmp = sha1_to_hex(commit->parents->item->object.sha1); | 139 | tmp = sha1_to_hex(commit->parents->item->object.sha1); |
113 | else | 140 | else |
114 | tmp = NULL; | 141 | tmp = NULL; |
115 | cgit_print_diff(ctx.qry.sha1, tmp, NULL); | 142 | cgit_print_diff(ctx.qry.sha1, tmp, prefix); |
116 | } | 143 | } |
144 | strbuf_release(¬es); | ||
117 | cgit_free_commitinfo(info); | 145 | cgit_free_commitinfo(info); |
118 | } | 146 | } |
diff --git a/ui-commit.h b/ui-commit.h index 40bcb31..8198b4b 100644 --- a/ui-commit.h +++ b/ui-commit.h | |||
@@ -1,6 +1,6 @@ | |||
1 | #ifndef UI_COMMIT_H | 1 | #ifndef UI_COMMIT_H |
2 | #define UI_COMMIT_H | 2 | #define UI_COMMIT_H |
3 | 3 | ||
4 | extern void cgit_print_commit(char *hex); | 4 | extern void cgit_print_commit(char *hex, const char *prefix); |
5 | 5 | ||
6 | #endif /* UI_COMMIT_H */ | 6 | #endif /* UI_COMMIT_H */ |
@@ -1,313 +1,383 @@ | |||
1 | /* ui-diff.c: show diff between two blobs | 1 | /* ui-diff.c: show diff between two blobs |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | #include "ui-ssdiff.h" | ||
12 | 13 | ||
13 | unsigned char old_rev_sha1[20]; | 14 | unsigned char old_rev_sha1[20]; |
14 | unsigned char new_rev_sha1[20]; | 15 | unsigned char new_rev_sha1[20]; |
15 | 16 | ||
16 | static int files, slots; | 17 | static int files, slots; |
17 | static int total_adds, total_rems, max_changes; | 18 | static int total_adds, total_rems, max_changes; |
18 | static int lines_added, lines_removed; | 19 | static int lines_added, lines_removed; |
19 | 20 | ||
20 | static struct fileinfo { | 21 | static struct fileinfo { |
21 | char status; | 22 | char status; |
22 | unsigned char old_sha1[20]; | 23 | unsigned char old_sha1[20]; |
23 | unsigned char new_sha1[20]; | 24 | unsigned char new_sha1[20]; |
24 | unsigned short old_mode; | 25 | unsigned short old_mode; |
25 | unsigned short new_mode; | 26 | unsigned short new_mode; |
26 | char *old_path; | 27 | char *old_path; |
27 | char *new_path; | 28 | char *new_path; |
28 | unsigned int added; | 29 | unsigned int added; |
29 | unsigned int removed; | 30 | unsigned int removed; |
30 | unsigned long old_size; | 31 | unsigned long old_size; |
31 | unsigned long new_size; | 32 | unsigned long new_size; |
32 | int binary:1; | 33 | int binary:1; |
33 | } *items; | 34 | } *items; |
34 | 35 | ||
36 | static int use_ssdiff = 0; | ||
37 | static struct diff_filepair *current_filepair; | ||
38 | |||
39 | struct diff_filespec *cgit_get_current_old_file(void) | ||
40 | { | ||
41 | return current_filepair->one; | ||
42 | } | ||
43 | |||
44 | struct diff_filespec *cgit_get_current_new_file(void) | ||
45 | { | ||
46 | return current_filepair->two; | ||
47 | } | ||
35 | 48 | ||
36 | static void print_fileinfo(struct fileinfo *info) | 49 | static void print_fileinfo(struct fileinfo *info) |
37 | { | 50 | { |
38 | char *class; | 51 | char *class; |
39 | 52 | ||
40 | switch (info->status) { | 53 | switch (info->status) { |
41 | case DIFF_STATUS_ADDED: | 54 | case DIFF_STATUS_ADDED: |
42 | class = "add"; | 55 | class = "add"; |
43 | break; | 56 | break; |
44 | case DIFF_STATUS_COPIED: | 57 | case DIFF_STATUS_COPIED: |
45 | class = "cpy"; | 58 | class = "cpy"; |
46 | break; | 59 | break; |
47 | case DIFF_STATUS_DELETED: | 60 | case DIFF_STATUS_DELETED: |
48 | class = "del"; | 61 | class = "del"; |
49 | break; | 62 | break; |
50 | case DIFF_STATUS_MODIFIED: | 63 | case DIFF_STATUS_MODIFIED: |
51 | class = "upd"; | 64 | class = "upd"; |
52 | break; | 65 | break; |
53 | case DIFF_STATUS_RENAMED: | 66 | case DIFF_STATUS_RENAMED: |
54 | class = "mov"; | 67 | class = "mov"; |
55 | break; | 68 | break; |
56 | case DIFF_STATUS_TYPE_CHANGED: | 69 | case DIFF_STATUS_TYPE_CHANGED: |
57 | class = "typ"; | 70 | class = "typ"; |
58 | break; | 71 | break; |
59 | case DIFF_STATUS_UNKNOWN: | 72 | case DIFF_STATUS_UNKNOWN: |
60 | class = "unk"; | 73 | class = "unk"; |
61 | break; | 74 | break; |
62 | case DIFF_STATUS_UNMERGED: | 75 | case DIFF_STATUS_UNMERGED: |
63 | class = "stg"; | 76 | class = "stg"; |
64 | break; | 77 | break; |
65 | default: | 78 | default: |
66 | die("bug: unhandled diff status %c", info->status); | 79 | die("bug: unhandled diff status %c", info->status); |
67 | } | 80 | } |
68 | 81 | ||
69 | html("<tr>"); | 82 | html("<tr>"); |
70 | htmlf("<td class='mode'>"); | 83 | htmlf("<td class='mode'>"); |
71 | if (is_null_sha1(info->new_sha1)) { | 84 | if (is_null_sha1(info->new_sha1)) { |
72 | cgit_print_filemode(info->old_mode); | 85 | cgit_print_filemode(info->old_mode); |
73 | } else { | 86 | } else { |
74 | cgit_print_filemode(info->new_mode); | 87 | cgit_print_filemode(info->new_mode); |
75 | } | 88 | } |
76 | 89 | ||
77 | if (info->old_mode != info->new_mode && | 90 | if (info->old_mode != info->new_mode && |
78 | !is_null_sha1(info->old_sha1) && | 91 | !is_null_sha1(info->old_sha1) && |
79 | !is_null_sha1(info->new_sha1)) { | 92 | !is_null_sha1(info->new_sha1)) { |
80 | html("<span class='modechange'>["); | 93 | html("<span class='modechange'>["); |
81 | cgit_print_filemode(info->old_mode); | 94 | cgit_print_filemode(info->old_mode); |
82 | html("]</span>"); | 95 | html("]</span>"); |
83 | } | 96 | } |
84 | htmlf("</td><td class='%s'>", class); | 97 | htmlf("</td><td class='%s'>", class); |
85 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 98 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
86 | ctx.qry.sha2, info->new_path); | 99 | ctx.qry.sha2, info->new_path, 0); |
87 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 100 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
88 | htmlf(" (%s from %s)", | 101 | htmlf(" (%s from %s)", |
89 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", | 102 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
90 | info->old_path); | 103 | info->old_path); |
91 | html("</td><td class='right'>"); | 104 | html("</td><td class='right'>"); |
92 | if (info->binary) { | 105 | if (info->binary) { |
93 | htmlf("bin</td><td class='graph'>%d -> %d bytes", | 106 | htmlf("bin</td><td class='graph'>%ld -> %ld bytes", |
94 | info->old_size, info->new_size); | 107 | info->old_size, info->new_size); |
95 | return; | 108 | return; |
96 | } | 109 | } |
97 | htmlf("%d", info->added + info->removed); | 110 | htmlf("%d", info->added + info->removed); |
98 | html("</td><td class='graph'>"); | 111 | html("</td><td class='graph'>"); |
99 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 112 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
100 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 113 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
101 | info->added * 100.0 / max_changes); | 114 | info->added * 100.0 / max_changes); |
102 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 115 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
103 | info->removed * 100.0 / max_changes); | 116 | info->removed * 100.0 / max_changes); |
104 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 117 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
105 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 118 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
106 | html("</tr></table></td></tr>\n"); | 119 | html("</tr></table></td></tr>\n"); |
107 | } | 120 | } |
108 | 121 | ||
109 | static void count_diff_lines(char *line, int len) | 122 | static void count_diff_lines(char *line, int len) |
110 | { | 123 | { |
111 | if (line && (len > 0)) { | 124 | if (line && (len > 0)) { |
112 | if (line[0] == '+') | 125 | if (line[0] == '+') |
113 | lines_added++; | 126 | lines_added++; |
114 | else if (line[0] == '-') | 127 | else if (line[0] == '-') |
115 | lines_removed++; | 128 | lines_removed++; |
116 | } | 129 | } |
117 | } | 130 | } |
118 | 131 | ||
119 | static void inspect_filepair(struct diff_filepair *pair) | 132 | static void inspect_filepair(struct diff_filepair *pair) |
120 | { | 133 | { |
121 | int binary = 0; | 134 | int binary = 0; |
122 | unsigned long old_size = 0; | 135 | unsigned long old_size = 0; |
123 | unsigned long new_size = 0; | 136 | unsigned long new_size = 0; |
124 | files++; | 137 | files++; |
125 | lines_added = 0; | 138 | lines_added = 0; |
126 | lines_removed = 0; | 139 | lines_removed = 0; |
127 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, | 140 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, |
128 | &binary, count_diff_lines); | 141 | &binary, 0, ctx.qry.ignorews, count_diff_lines); |
129 | if (files >= slots) { | 142 | if (files >= slots) { |
130 | if (slots == 0) | 143 | if (slots == 0) |
131 | slots = 4; | 144 | slots = 4; |
132 | else | 145 | else |
133 | slots = slots * 2; | 146 | slots = slots * 2; |
134 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 147 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
135 | } | 148 | } |
136 | items[files-1].status = pair->status; | 149 | items[files-1].status = pair->status; |
137 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 150 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
138 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 151 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
139 | items[files-1].old_mode = pair->one->mode; | 152 | items[files-1].old_mode = pair->one->mode; |
140 | items[files-1].new_mode = pair->two->mode; | 153 | items[files-1].new_mode = pair->two->mode; |
141 | items[files-1].old_path = xstrdup(pair->one->path); | 154 | items[files-1].old_path = xstrdup(pair->one->path); |
142 | items[files-1].new_path = xstrdup(pair->two->path); | 155 | items[files-1].new_path = xstrdup(pair->two->path); |
143 | items[files-1].added = lines_added; | 156 | items[files-1].added = lines_added; |
144 | items[files-1].removed = lines_removed; | 157 | items[files-1].removed = lines_removed; |
145 | items[files-1].old_size = old_size; | 158 | items[files-1].old_size = old_size; |
146 | items[files-1].new_size = new_size; | 159 | items[files-1].new_size = new_size; |
147 | items[files-1].binary = binary; | 160 | items[files-1].binary = binary; |
148 | if (lines_added + lines_removed > max_changes) | 161 | if (lines_added + lines_removed > max_changes) |
149 | max_changes = lines_added + lines_removed; | 162 | max_changes = lines_added + lines_removed; |
150 | total_adds += lines_added; | 163 | total_adds += lines_added; |
151 | total_rems += lines_removed; | 164 | total_rems += lines_removed; |
152 | } | 165 | } |
153 | 166 | ||
154 | void cgit_print_diffstat(const unsigned char *old_sha1, | 167 | void cgit_print_diffstat(const unsigned char *old_sha1, |
155 | const unsigned char *new_sha1) | 168 | const unsigned char *new_sha1, const char *prefix) |
156 | { | 169 | { |
157 | int i; | 170 | int i, save_context = ctx.qry.context; |
158 | 171 | ||
159 | html("<div class='diffstat-header'>"); | 172 | html("<div class='diffstat-header'>"); |
160 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 173 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
161 | ctx.qry.sha2, NULL); | 174 | ctx.qry.sha2, NULL, 0); |
175 | if (prefix) | ||
176 | htmlf(" (limited to '%s')", prefix); | ||
177 | html(" ("); | ||
178 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; | ||
179 | cgit_self_link("more", NULL, NULL, &ctx); | ||
180 | html("/"); | ||
181 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; | ||
182 | cgit_self_link("less", NULL, NULL, &ctx); | ||
183 | ctx.qry.context = save_context; | ||
184 | html(" context)"); | ||
185 | html(" ("); | ||
186 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
187 | cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); | ||
188 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
189 | html(" whitespace changes)"); | ||
162 | html("</div>"); | 190 | html("</div>"); |
163 | html("<table summary='diffstat' class='diffstat'>"); | 191 | html("<table summary='diffstat' class='diffstat'>"); |
164 | max_changes = 0; | 192 | max_changes = 0; |
165 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL); | 193 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, |
194 | ctx.qry.ignorews); | ||
166 | for(i = 0; i<files; i++) | 195 | for(i = 0; i<files; i++) |
167 | print_fileinfo(&items[i]); | 196 | print_fileinfo(&items[i]); |
168 | html("</table>"); | 197 | html("</table>"); |
169 | html("<div class='diffstat-summary'>"); | 198 | html("<div class='diffstat-summary'>"); |
170 | htmlf("%d files changed, %d insertions, %d deletions", | 199 | htmlf("%d files changed, %d insertions, %d deletions", |
171 | files, total_adds, total_rems); | 200 | files, total_adds, total_rems); |
172 | html("</div>"); | 201 | html("</div>"); |
173 | } | 202 | } |
174 | 203 | ||
175 | 204 | ||
176 | /* | 205 | /* |
177 | * print a single line returned from xdiff | 206 | * print a single line returned from xdiff |
178 | */ | 207 | */ |
179 | static void print_line(char *line, int len) | 208 | static void print_line(char *line, int len) |
180 | { | 209 | { |
181 | char *class = "ctx"; | 210 | char *class = "ctx"; |
182 | char c = line[len-1]; | 211 | char c = line[len-1]; |
183 | 212 | ||
184 | if (line[0] == '+') | 213 | if (line[0] == '+') |
185 | class = "add"; | 214 | class = "add"; |
186 | else if (line[0] == '-') | 215 | else if (line[0] == '-') |
187 | class = "del"; | 216 | class = "del"; |
188 | else if (line[0] == '@') | 217 | else if (line[0] == '@') |
189 | class = "hunk"; | 218 | class = "hunk"; |
190 | 219 | ||
191 | htmlf("<div class='%s'>", class); | 220 | htmlf("<div class='%s'>", class); |
192 | line[len-1] = '\0'; | 221 | line[len-1] = '\0'; |
193 | html_txt(line); | 222 | html_txt(line); |
194 | html("</div>"); | 223 | html("</div>"); |
195 | line[len-1] = c; | 224 | line[len-1] = c; |
196 | } | 225 | } |
197 | 226 | ||
198 | static void header(unsigned char *sha1, char *path1, int mode1, | 227 | static void header(unsigned char *sha1, char *path1, int mode1, |
199 | unsigned char *sha2, char *path2, int mode2) | 228 | unsigned char *sha2, char *path2, int mode2) |
200 | { | 229 | { |
201 | char *abbrev1, *abbrev2; | 230 | char *abbrev1, *abbrev2; |
202 | int subproject; | 231 | int subproject; |
203 | 232 | ||
204 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | 233 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
205 | html("<div class='head'>"); | 234 | html("<div class='head'>"); |
206 | html("diff --git a/"); | 235 | html("diff --git a/"); |
207 | html_txt(path1); | 236 | html_txt(path1); |
208 | html(" b/"); | 237 | html(" b/"); |
209 | html_txt(path2); | 238 | html_txt(path2); |
210 | 239 | ||
211 | if (is_null_sha1(sha1)) | 240 | if (is_null_sha1(sha1)) |
212 | path1 = "dev/null"; | 241 | path1 = "dev/null"; |
213 | if (is_null_sha1(sha2)) | 242 | if (is_null_sha1(sha2)) |
214 | path2 = "dev/null"; | 243 | path2 = "dev/null"; |
215 | 244 | ||
216 | if (mode1 == 0) | 245 | if (mode1 == 0) |
217 | htmlf("<br/>new file mode %.6o", mode2); | 246 | htmlf("<br/>new file mode %.6o", mode2); |
218 | 247 | ||
219 | if (mode2 == 0) | 248 | if (mode2 == 0) |
220 | htmlf("<br/>deleted file mode %.6o", mode1); | 249 | htmlf("<br/>deleted file mode %.6o", mode1); |
221 | 250 | ||
222 | if (!subproject) { | 251 | if (!subproject) { |
223 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | 252 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
224 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | 253 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
225 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); | 254 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
226 | free(abbrev1); | 255 | free(abbrev1); |
227 | free(abbrev2); | 256 | free(abbrev2); |
228 | if (mode1 != 0 && mode2 != 0) { | 257 | if (mode1 != 0 && mode2 != 0) { |
229 | htmlf(" %.6o", mode1); | 258 | htmlf(" %.6o", mode1); |
230 | if (mode2 != mode1) | 259 | if (mode2 != mode1) |
231 | htmlf("..%.6o", mode2); | 260 | htmlf("..%.6o", mode2); |
232 | } | 261 | } |
233 | html("<br/>--- a/"); | 262 | html("<br/>--- a/"); |
234 | if (mode1 != 0) | 263 | if (mode1 != 0) |
235 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, | 264 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
236 | sha1_to_hex(old_rev_sha1), path1); | 265 | sha1_to_hex(old_rev_sha1), path1); |
237 | else | 266 | else |
238 | html_txt(path1); | 267 | html_txt(path1); |
239 | html("<br/>+++ b/"); | 268 | html("<br/>+++ b/"); |
240 | if (mode2 != 0) | 269 | if (mode2 != 0) |
241 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, | 270 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
242 | sha1_to_hex(new_rev_sha1), path2); | 271 | sha1_to_hex(new_rev_sha1), path2); |
243 | else | 272 | else |
244 | html_txt(path2); | 273 | html_txt(path2); |
245 | } | 274 | } |
246 | html("</div>"); | 275 | html("</div>"); |
247 | } | 276 | } |
248 | 277 | ||
278 | static void print_ssdiff_link() | ||
279 | { | ||
280 | if (!strcmp(ctx.qry.page, "diff")) { | ||
281 | if (use_ssdiff) | ||
282 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, | ||
283 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1); | ||
284 | else | ||
285 | cgit_diff_link("Side-by-side diff", NULL, NULL, | ||
286 | ctx.qry.head, ctx.qry.sha1, | ||
287 | ctx.qry.sha2, ctx.qry.path, 1); | ||
288 | } | ||
289 | } | ||
290 | |||
249 | static void filepair_cb(struct diff_filepair *pair) | 291 | static void filepair_cb(struct diff_filepair *pair) |
250 | { | 292 | { |
251 | unsigned long old_size = 0; | 293 | unsigned long old_size = 0; |
252 | unsigned long new_size = 0; | 294 | unsigned long new_size = 0; |
253 | int binary = 0; | 295 | int binary = 0; |
296 | linediff_fn print_line_fn = print_line; | ||
254 | 297 | ||
298 | current_filepair = pair; | ||
299 | if (use_ssdiff) { | ||
300 | cgit_ssdiff_header_begin(); | ||
301 | print_line_fn = cgit_ssdiff_line_cb; | ||
302 | } | ||
255 | header(pair->one->sha1, pair->one->path, pair->one->mode, | 303 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
256 | pair->two->sha1, pair->two->path, pair->two->mode); | 304 | pair->two->sha1, pair->two->path, pair->two->mode); |
305 | if (use_ssdiff) | ||
306 | cgit_ssdiff_header_end(); | ||
257 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 307 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
258 | if (S_ISGITLINK(pair->one->mode)) | 308 | if (S_ISGITLINK(pair->one->mode)) |
259 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 309 | print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
260 | if (S_ISGITLINK(pair->two->mode)) | 310 | if (S_ISGITLINK(pair->two->mode)) |
261 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 311 | print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
312 | if (use_ssdiff) | ||
313 | cgit_ssdiff_footer(); | ||
262 | return; | 314 | return; |
263 | } | 315 | } |
264 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 316 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
265 | &new_size, &binary, print_line)) | 317 | &new_size, &binary, ctx.qry.context, |
318 | ctx.qry.ignorews, print_line_fn)) | ||
266 | cgit_print_error("Error running diff"); | 319 | cgit_print_error("Error running diff"); |
267 | if (binary) | 320 | if (binary) { |
321 | if (use_ssdiff) | ||
322 | html("<tr><td colspan='4'>Binary files differ</td></tr>"); | ||
323 | else | ||
268 | html("Binary files differ"); | 324 | html("Binary files differ"); |
269 | } | 325 | } |
326 | if (use_ssdiff) | ||
327 | cgit_ssdiff_footer(); | ||
328 | } | ||
270 | 329 | ||
271 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 330 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
272 | { | 331 | { |
273 | enum object_type type; | 332 | enum object_type type; |
274 | unsigned long size; | 333 | unsigned long size; |
275 | struct commit *commit, *commit2; | 334 | struct commit *commit, *commit2; |
276 | 335 | ||
277 | if (!new_rev) | 336 | if (!new_rev) |
278 | new_rev = ctx.qry.head; | 337 | new_rev = ctx.qry.head; |
279 | get_sha1(new_rev, new_rev_sha1); | 338 | get_sha1(new_rev, new_rev_sha1); |
280 | type = sha1_object_info(new_rev_sha1, &size); | 339 | type = sha1_object_info(new_rev_sha1, &size); |
281 | if (type == OBJ_BAD) { | 340 | if (type == OBJ_BAD) { |
282 | cgit_print_error(fmt("Bad object name: %s", new_rev)); | 341 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
283 | return; | 342 | return; |
284 | } | 343 | } |
285 | commit = lookup_commit_reference(new_rev_sha1); | 344 | commit = lookup_commit_reference(new_rev_sha1); |
286 | if (!commit || parse_commit(commit)) | 345 | if (!commit || parse_commit(commit)) |
287 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); | 346 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
288 | 347 | ||
289 | if (old_rev) | 348 | if (old_rev) |
290 | get_sha1(old_rev, old_rev_sha1); | 349 | get_sha1(old_rev, old_rev_sha1); |
291 | else if (commit->parents && commit->parents->item) | 350 | else if (commit->parents && commit->parents->item) |
292 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); | 351 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
293 | else | 352 | else |
294 | hashclr(old_rev_sha1); | 353 | hashclr(old_rev_sha1); |
295 | 354 | ||
296 | if (!is_null_sha1(old_rev_sha1)) { | 355 | if (!is_null_sha1(old_rev_sha1)) { |
297 | type = sha1_object_info(old_rev_sha1, &size); | 356 | type = sha1_object_info(old_rev_sha1, &size); |
298 | if (type == OBJ_BAD) { | 357 | if (type == OBJ_BAD) { |
299 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); | 358 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
300 | return; | 359 | return; |
301 | } | 360 | } |
302 | commit2 = lookup_commit_reference(old_rev_sha1); | 361 | commit2 = lookup_commit_reference(old_rev_sha1); |
303 | if (!commit2 || parse_commit(commit2)) | 362 | if (!commit2 || parse_commit(commit2)) |
304 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); | 363 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
305 | } | 364 | } |
306 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); | ||
307 | 365 | ||
366 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | ||
367 | use_ssdiff = 1; | ||
368 | |||
369 | print_ssdiff_link(); | ||
370 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); | ||
371 | |||
372 | if (use_ssdiff) { | ||
373 | html("<table summary='ssdiff' class='ssdiff'>"); | ||
374 | } else { | ||
308 | html("<table summary='diff' class='diff'>"); | 375 | html("<table summary='diff' class='diff'>"); |
309 | html("<tr><td>"); | 376 | html("<tr><td>"); |
310 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); | 377 | } |
378 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix, | ||
379 | ctx.qry.ignorews); | ||
380 | if (!use_ssdiff) | ||
311 | html("</td></tr>"); | 381 | html("</td></tr>"); |
312 | html("</table>"); | 382 | html("</table>"); |
313 | } | 383 | } |
@@ -1,10 +1,16 @@ | |||
1 | #ifndef UI_DIFF_H | 1 | #ifndef UI_DIFF_H |
2 | #define UI_DIFF_H | 2 | #define UI_DIFF_H |
3 | 3 | ||
4 | extern void cgit_print_diffstat(const unsigned char *old_sha1, | 4 | extern void cgit_print_diffstat(const unsigned char *old_sha1, |
5 | const unsigned char *new_sha1); | 5 | const unsigned char *new_sha1); |
6 | 6 | ||
7 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, | 7 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, |
8 | const char *prefix); | 8 | const char *prefix); |
9 | 9 | ||
10 | extern struct diff_filespec *cgit_get_current_old_file(void); | ||
11 | extern struct diff_filespec *cgit_get_current_new_file(void); | ||
12 | |||
13 | extern unsigned char old_rev_sha1[20]; | ||
14 | extern unsigned char new_rev_sha1[20]; | ||
15 | |||
10 | #endif /* UI_DIFF_H */ | 16 | #endif /* UI_DIFF_H */ |
@@ -1,234 +1,428 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | #include "vector.h" | ||
12 | 13 | ||
13 | int files, add_lines, rem_lines; | 14 | int files, add_lines, rem_lines; |
14 | 15 | ||
16 | /* | ||
17 | * The list of available column colors in the commit graph. | ||
18 | */ | ||
19 | static const char *column_colors_html[] = { | ||
20 | "<span class='column1'>", | ||
21 | "<span class='column2'>", | ||
22 | "<span class='column3'>", | ||
23 | "<span class='column4'>", | ||
24 | "<span class='column5'>", | ||
25 | "<span class='column6'>", | ||
26 | "</span>", | ||
27 | }; | ||
28 | |||
29 | #define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) | ||
30 | |||
15 | void count_lines(char *line, int size) | 31 | void count_lines(char *line, int size) |
16 | { | 32 | { |
17 | if (size <= 0) | 33 | if (size <= 0) |
18 | return; | 34 | return; |
19 | 35 | ||
20 | if (line[0] == '+') | 36 | if (line[0] == '+') |
21 | add_lines++; | 37 | add_lines++; |
22 | 38 | ||
23 | else if (line[0] == '-') | 39 | else if (line[0] == '-') |
24 | rem_lines++; | 40 | rem_lines++; |
25 | } | 41 | } |
26 | 42 | ||
27 | void inspect_files(struct diff_filepair *pair) | 43 | void inspect_files(struct diff_filepair *pair) |
28 | { | 44 | { |
29 | unsigned long old_size = 0; | 45 | unsigned long old_size = 0; |
30 | unsigned long new_size = 0; | 46 | unsigned long new_size = 0; |
31 | int binary = 0; | 47 | int binary = 0; |
32 | 48 | ||
33 | files++; | 49 | files++; |
34 | if (ctx.repo->enable_log_linecount) | 50 | if (ctx.repo->enable_log_linecount) |
35 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 51 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
36 | &new_size, &binary, count_lines); | 52 | &new_size, &binary, 0, ctx.qry.ignorews, |
53 | count_lines); | ||
37 | } | 54 | } |
38 | 55 | ||
39 | void show_commit_decorations(struct commit *commit) | 56 | void show_commit_decorations(struct commit *commit) |
40 | { | 57 | { |
41 | struct name_decoration *deco; | 58 | struct name_decoration *deco; |
42 | static char buf[1024]; | 59 | static char buf[1024]; |
43 | 60 | ||
44 | buf[sizeof(buf) - 1] = 0; | 61 | buf[sizeof(buf) - 1] = 0; |
45 | deco = lookup_decoration(&name_decoration, &commit->object); | 62 | deco = lookup_decoration(&name_decoration, &commit->object); |
46 | while (deco) { | 63 | while (deco) { |
47 | if (!prefixcmp(deco->name, "refs/heads/")) { | 64 | if (!prefixcmp(deco->name, "refs/heads/")) { |
48 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); | 65 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); |
49 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL, | 66 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, |
50 | 0, NULL, NULL, ctx.qry.showmsg); | 67 | ctx.qry.vpath, 0, NULL, NULL, |
68 | ctx.qry.showmsg); | ||
51 | } | 69 | } |
52 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { | 70 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { |
53 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); | 71 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); |
54 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 72 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
55 | } | 73 | } |
56 | else if (!prefixcmp(deco->name, "refs/tags/")) { | 74 | else if (!prefixcmp(deco->name, "refs/tags/")) { |
57 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); | 75 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); |
58 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 76 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
59 | } | 77 | } |
60 | else if (!prefixcmp(deco->name, "refs/remotes/")) { | 78 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
61 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); | 79 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
62 | cgit_log_link(buf, NULL, "remote-deco", NULL, | 80 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
63 | sha1_to_hex(commit->object.sha1), NULL, | 81 | sha1_to_hex(commit->object.sha1), |
64 | 0, NULL, NULL, ctx.qry.showmsg); | 82 | ctx.qry.vpath, 0, NULL, NULL, |
83 | ctx.qry.showmsg); | ||
65 | } | 84 | } |
66 | else { | 85 | else { |
67 | strncpy(buf, deco->name, sizeof(buf) - 1); | 86 | strncpy(buf, deco->name, sizeof(buf) - 1); |
68 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, | 87 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
69 | sha1_to_hex(commit->object.sha1)); | 88 | sha1_to_hex(commit->object.sha1), |
89 | ctx.qry.vpath, 0); | ||
70 | } | 90 | } |
71 | deco = deco->next; | 91 | deco = deco->next; |
72 | } | 92 | } |
73 | } | 93 | } |
74 | 94 | ||
75 | void print_commit(struct commit *commit) | 95 | void print_commit(struct commit *commit, struct rev_info *revs) |
76 | { | 96 | { |
77 | struct commitinfo *info; | 97 | struct commitinfo *info; |
78 | char *tmp; | 98 | char *tmp; |
79 | int cols = 2; | 99 | int cols = revs->graph ? 3 : 2; |
100 | struct strbuf graphbuf = STRBUF_INIT; | ||
101 | struct strbuf msgbuf = STRBUF_INIT; | ||
102 | |||
103 | if (ctx.repo->enable_log_filecount) { | ||
104 | cols++; | ||
105 | if (ctx.repo->enable_log_linecount) | ||
106 | cols++; | ||
107 | } | ||
108 | |||
109 | if (revs->graph) { | ||
110 | /* Advance graph until current commit */ | ||
111 | while (!graph_next_line(revs->graph, &graphbuf)) { | ||
112 | /* Print graph segment in otherwise empty table row */ | ||
113 | html("<tr class='nohover'><td class='commitgraph'>"); | ||
114 | html(graphbuf.buf); | ||
115 | htmlf("</td><td colspan='%d' /></tr>\n", cols); | ||
116 | strbuf_setlen(&graphbuf, 0); | ||
117 | } | ||
118 | /* Current commit's graph segment is now ready in graphbuf */ | ||
119 | } | ||
80 | 120 | ||
81 | info = cgit_parse_commit(commit); | 121 | info = cgit_parse_commit(commit); |
82 | htmlf("<tr%s><td>", | 122 | htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); |
83 | ctx.qry.showmsg ? " class='logheader'" : ""); | 123 | |
124 | if (revs->graph) { | ||
125 | /* Print graph segment for current commit */ | ||
126 | html("<td class='commitgraph'>"); | ||
127 | html(graphbuf.buf); | ||
128 | html("</td>"); | ||
129 | strbuf_setlen(&graphbuf, 0); | ||
130 | } | ||
131 | else { | ||
132 | html("<td>"); | ||
84 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 133 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
85 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); | 134 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); |
86 | html_link_open(tmp, NULL, NULL); | 135 | html_link_open(tmp, NULL, NULL); |
87 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 136 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
88 | html_link_close(); | 137 | html_link_close(); |
89 | htmlf("</td><td%s>", | 138 | html("</td>"); |
90 | ctx.qry.showmsg ? " class='logsubject'" : ""); | 139 | } |
140 | |||
141 | htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : ""); | ||
142 | if (ctx.qry.showmsg) { | ||
143 | /* line-wrap long commit subjects instead of truncating them */ | ||
144 | size_t subject_len = strlen(info->subject); | ||
145 | |||
146 | if (subject_len > ctx.cfg.max_msg_len && | ||
147 | ctx.cfg.max_msg_len >= 15) { | ||
148 | /* symbol for signaling line-wrap (in PAGE_ENCODING) */ | ||
149 | const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 }; | ||
150 | int i = ctx.cfg.max_msg_len - strlen(wrap_symbol); | ||
151 | |||
152 | /* Rewind i to preceding space character */ | ||
153 | while (i > 0 && !isspace(info->subject[i])) | ||
154 | --i; | ||
155 | if (!i) /* Oops, zero spaces. Reset i */ | ||
156 | i = ctx.cfg.max_msg_len - strlen(wrap_symbol); | ||
157 | |||
158 | /* add remainder starting at i to msgbuf */ | ||
159 | strbuf_add(&msgbuf, info->subject + i, subject_len - i); | ||
160 | strbuf_trim(&msgbuf); | ||
161 | strbuf_add(&msgbuf, "\n\n", 2); | ||
162 | |||
163 | /* Place wrap_symbol at position i in info->subject */ | ||
164 | strcpy(info->subject + i, wrap_symbol); | ||
165 | } | ||
166 | } | ||
91 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 167 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
92 | sha1_to_hex(commit->object.sha1)); | 168 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); |
93 | show_commit_decorations(commit); | 169 | show_commit_decorations(commit); |
94 | html("</td><td>"); | 170 | html("</td><td>"); |
95 | html_txt(info->author); | 171 | html_txt(info->author); |
172 | |||
173 | if (revs->graph) { | ||
174 | html("</td><td>"); | ||
175 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | ||
176 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); | ||
177 | html_link_open(tmp, NULL, NULL); | ||
178 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | ||
179 | html_link_close(); | ||
180 | } | ||
181 | |||
96 | if (ctx.repo->enable_log_filecount) { | 182 | if (ctx.repo->enable_log_filecount) { |
97 | files = 0; | 183 | files = 0; |
98 | add_lines = 0; | 184 | add_lines = 0; |
99 | rem_lines = 0; | 185 | rem_lines = 0; |
100 | cgit_diff_commit(commit, inspect_files); | 186 | cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); |
101 | html("</td><td>"); | 187 | html("</td><td>"); |
102 | htmlf("%d", files); | 188 | htmlf("%d", files); |
103 | if (ctx.repo->enable_log_linecount) { | 189 | if (ctx.repo->enable_log_linecount) { |
104 | html("</td><td>"); | 190 | html("</td><td>"); |
105 | htmlf("-%d/+%d", rem_lines, add_lines); | 191 | htmlf("-%d/+%d", rem_lines, add_lines); |
106 | } | 192 | } |
107 | } | 193 | } |
108 | html("</td></tr>\n"); | 194 | html("</td></tr>\n"); |
195 | |||
196 | if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ | ||
197 | html("<tr class='nohover'>"); | ||
198 | |||
109 | if (ctx.qry.showmsg) { | 199 | if (ctx.qry.showmsg) { |
110 | if (ctx.repo->enable_log_filecount) { | 200 | /* Concatenate commit message + notes in msgbuf */ |
111 | cols++; | 201 | if (info->msg && *(info->msg)) { |
112 | if (ctx.repo->enable_log_linecount) | 202 | strbuf_addstr(&msgbuf, info->msg); |
113 | cols++; | 203 | strbuf_addch(&msgbuf, '\n'); |
114 | } | 204 | } |
115 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", | 205 | format_note(NULL, commit->object.sha1, &msgbuf, |
116 | cols); | 206 | PAGE_ENCODING, |
117 | html_txt(info->msg); | 207 | NOTES_SHOW_HEADER | NOTES_INDENT); |
208 | strbuf_addch(&msgbuf, '\n'); | ||
209 | strbuf_ltrim(&msgbuf); | ||
210 | } | ||
211 | |||
212 | if (revs->graph) { | ||
213 | int lines = 0; | ||
214 | |||
215 | /* Calculate graph padding */ | ||
216 | if (ctx.qry.showmsg) { | ||
217 | /* Count #lines in commit message + notes */ | ||
218 | const char *p = msgbuf.buf; | ||
219 | lines = 1; | ||
220 | while ((p = strchr(p, '\n'))) { | ||
221 | p++; | ||
222 | lines++; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | /* Print graph padding */ | ||
227 | html("<td class='commitgraph'>"); | ||
228 | while (lines > 0 || !graph_is_commit_finished(revs->graph)) { | ||
229 | if (graphbuf.len) | ||
230 | html("\n"); | ||
231 | strbuf_setlen(&graphbuf, 0); | ||
232 | graph_next_line(revs->graph, &graphbuf); | ||
233 | html(graphbuf.buf); | ||
234 | lines--; | ||
235 | } | ||
236 | html("</td>\n"); | ||
237 | } | ||
238 | else | ||
239 | html("<td/>"); /* Empty 'Age' column */ | ||
240 | |||
241 | /* Print msgbuf into remainder of table row */ | ||
242 | htmlf("<td colspan='%d'%s>\n", cols, | ||
243 | ctx.qry.showmsg ? " class='logmsg'" : ""); | ||
244 | html_txt(msgbuf.buf); | ||
118 | html("</td></tr>\n"); | 245 | html("</td></tr>\n"); |
119 | } | 246 | } |
247 | |||
248 | strbuf_release(&msgbuf); | ||
249 | strbuf_release(&graphbuf); | ||
120 | cgit_free_commitinfo(info); | 250 | cgit_free_commitinfo(info); |
121 | } | 251 | } |
122 | 252 | ||
123 | static const char *disambiguate_ref(const char *ref) | 253 | static const char *disambiguate_ref(const char *ref) |
124 | { | 254 | { |
125 | unsigned char sha1[20]; | 255 | unsigned char sha1[20]; |
126 | const char *longref; | 256 | const char *longref; |
127 | 257 | ||
128 | longref = fmt("refs/heads/%s", ref); | 258 | longref = fmt("refs/heads/%s", ref); |
129 | if (get_sha1(longref, sha1) == 0) | 259 | if (get_sha1(longref, sha1) == 0) |
130 | return longref; | 260 | return longref; |
131 | 261 | ||
132 | return ref; | 262 | return ref; |
133 | } | 263 | } |
134 | 264 | ||
265 | static char *next_token(char **src) | ||
266 | { | ||
267 | char *result; | ||
268 | |||
269 | if (!src || !*src) | ||
270 | return NULL; | ||
271 | while (isspace(**src)) | ||
272 | (*src)++; | ||
273 | if (!**src) | ||
274 | return NULL; | ||
275 | result = *src; | ||
276 | while (**src) { | ||
277 | if (isspace(**src)) { | ||
278 | **src = '\0'; | ||
279 | (*src)++; | ||
280 | break; | ||
281 | } | ||
282 | (*src)++; | ||
283 | } | ||
284 | return result; | ||
285 | } | ||
286 | |||
135 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 287 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
136 | char *path, int pager) | 288 | char *path, int pager, int commit_graph) |
137 | { | 289 | { |
138 | struct rev_info rev; | 290 | struct rev_info rev; |
139 | struct commit *commit; | 291 | struct commit *commit; |
140 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; | 292 | struct vector vec = VECTOR_INIT(char *); |
141 | int argc = 2; | ||
142 | int i, columns = 3; | 293 | int i, columns = 3; |
294 | char *arg; | ||
295 | |||
296 | /* First argv is NULL */ | ||
297 | vector_push(&vec, NULL, 0); | ||
143 | 298 | ||
144 | if (!tip) | 299 | if (!tip) |
145 | tip = ctx.qry.head; | 300 | tip = ctx.qry.head; |
301 | tip = disambiguate_ref(tip); | ||
302 | vector_push(&vec, &tip, 0); | ||
146 | 303 | ||
147 | argv[1] = disambiguate_ref(tip); | 304 | if (grep && pattern && *pattern) { |
148 | 305 | pattern = xstrdup(pattern); | |
149 | if (grep && pattern && (!strcmp(grep, "grep") || | 306 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || |
150 | !strcmp(grep, "author") || | 307 | !strcmp(grep, "committer")) { |
151 | !strcmp(grep, "committer"))) | 308 | arg = fmt("--%s=%s", grep, pattern); |
152 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 309 | vector_push(&vec, &arg, 0); |
310 | } | ||
311 | if (!strcmp(grep, "range")) { | ||
312 | /* Split the pattern at whitespace and add each token | ||
313 | * as a revision expression. Do not accept other | ||
314 | * rev-list options. Also, replace the previously | ||
315 | * pushed tip (it's no longer relevant). | ||
316 | */ | ||
317 | vec.count--; | ||
318 | while ((arg = next_token(&pattern))) { | ||
319 | if (*arg == '-') { | ||
320 | fprintf(stderr, "Bad range expr: %s\n", | ||
321 | arg); | ||
322 | break; | ||
323 | } | ||
324 | vector_push(&vec, &arg, 0); | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | if (commit_graph) { | ||
329 | static const char *graph_arg = "--graph"; | ||
330 | static const char *color_arg = "--color"; | ||
331 | vector_push(&vec, &graph_arg, 0); | ||
332 | vector_push(&vec, &color_arg, 0); | ||
333 | graph_set_column_colors(column_colors_html, | ||
334 | COLUMN_COLORS_HTML_MAX); | ||
335 | } | ||
153 | 336 | ||
154 | if (path) { | 337 | if (path) { |
155 | argv[argc++] = "--"; | 338 | arg = "--"; |
156 | argv[argc++] = path; | 339 | vector_push(&vec, &arg, 0); |
340 | vector_push(&vec, &path, 0); | ||
157 | } | 341 | } |
342 | |||
343 | /* Make sure the vector is NULL-terminated */ | ||
344 | vector_push(&vec, NULL, 0); | ||
345 | vec.count--; | ||
346 | |||
158 | init_revisions(&rev, NULL); | 347 | init_revisions(&rev, NULL); |
159 | rev.abbrev = DEFAULT_ABBREV; | 348 | rev.abbrev = DEFAULT_ABBREV; |
160 | rev.commit_format = CMIT_FMT_DEFAULT; | 349 | rev.commit_format = CMIT_FMT_DEFAULT; |
161 | rev.verbose_header = 1; | 350 | rev.verbose_header = 1; |
162 | rev.show_root_diff = 0; | 351 | rev.show_root_diff = 0; |
163 | setup_revisions(argc, argv, &rev, NULL); | 352 | setup_revisions(vec.count, vec.data, &rev, NULL); |
164 | load_ref_decorations(DECORATE_FULL_REFS); | 353 | load_ref_decorations(DECORATE_FULL_REFS); |
165 | rev.show_decorations = 1; | 354 | rev.show_decorations = 1; |
166 | rev.grep_filter.regflags |= REG_ICASE; | 355 | rev.grep_filter.regflags |= REG_ICASE; |
167 | compile_grep_patterns(&rev.grep_filter); | 356 | compile_grep_patterns(&rev.grep_filter); |
168 | prepare_revision_walk(&rev); | 357 | prepare_revision_walk(&rev); |
169 | 358 | ||
170 | if (pager) | 359 | if (pager) |
171 | html("<table class='list nowrap'>"); | 360 | html("<table class='list nowrap'>"); |
172 | 361 | ||
173 | html("<tr class='nohover'><th class='left'>Age</th>" | 362 | html("<tr class='nohover'>"); |
174 | "<th class='left'>Commit message"); | 363 | if (commit_graph) |
364 | html("<th></th>"); | ||
365 | else | ||
366 | html("<th class='left'>Age</th>"); | ||
367 | html("<th class='left'>Commit message"); | ||
175 | if (pager) { | 368 | if (pager) { |
176 | html(" ("); | 369 | html(" ("); |
177 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, | 370 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
178 | NULL, ctx.qry.head, ctx.qry.sha1, | 371 | NULL, ctx.qry.head, ctx.qry.sha1, |
179 | ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, | 372 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |
180 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); | 373 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); |
181 | html(")"); | 374 | html(")"); |
182 | } | 375 | } |
183 | html("</th><th class='left'>Author</th>"); | 376 | html("</th><th class='left'>Author</th>"); |
377 | if (commit_graph) | ||
378 | html("<th class='left'>Age</th>"); | ||
184 | if (ctx.repo->enable_log_filecount) { | 379 | if (ctx.repo->enable_log_filecount) { |
185 | html("<th class='left'>Files</th>"); | 380 | html("<th class='left'>Files</th>"); |
186 | columns++; | 381 | columns++; |
187 | if (ctx.repo->enable_log_linecount) { | 382 | if (ctx.repo->enable_log_linecount) { |
188 | html("<th class='left'>Lines</th>"); | 383 | html("<th class='left'>Lines</th>"); |
189 | columns++; | 384 | columns++; |
190 | } | 385 | } |
191 | } | 386 | } |
192 | html("</tr>\n"); | 387 | html("</tr>\n"); |
193 | 388 | ||
194 | if (ofs<0) | 389 | if (ofs<0) |
195 | ofs = 0; | 390 | ofs = 0; |
196 | 391 | ||
197 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 392 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
198 | free(commit->buffer); | 393 | free(commit->buffer); |
199 | commit->buffer = NULL; | 394 | commit->buffer = NULL; |
200 | free_commit_list(commit->parents); | 395 | free_commit_list(commit->parents); |
201 | commit->parents = NULL; | 396 | commit->parents = NULL; |
202 | } | 397 | } |
203 | 398 | ||
204 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 399 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
205 | print_commit(commit); | 400 | print_commit(commit, &rev); |
206 | free(commit->buffer); | 401 | free(commit->buffer); |
207 | commit->buffer = NULL; | 402 | commit->buffer = NULL; |
208 | free_commit_list(commit->parents); | 403 | free_commit_list(commit->parents); |
209 | commit->parents = NULL; | 404 | commit->parents = NULL; |
210 | } | 405 | } |
211 | if (pager) { | 406 | if (pager) { |
212 | htmlf("</table><div class='pager'>", | 407 | html("</table><div class='pager'>"); |
213 | columns); | ||
214 | if (ofs > 0) { | 408 | if (ofs > 0) { |
215 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 409 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
216 | ctx.qry.sha1, ctx.qry.path, | 410 | ctx.qry.sha1, ctx.qry.vpath, |
217 | ofs - cnt, ctx.qry.grep, | 411 | ofs - cnt, ctx.qry.grep, |
218 | ctx.qry.search, ctx.qry.showmsg); | 412 | ctx.qry.search, ctx.qry.showmsg); |
219 | html(" "); | 413 | html(" "); |
220 | } | 414 | } |
221 | if ((commit = get_revision(&rev)) != NULL) { | 415 | if ((commit = get_revision(&rev)) != NULL) { |
222 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 416 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
223 | ctx.qry.sha1, ctx.qry.path, | 417 | ctx.qry.sha1, ctx.qry.vpath, |
224 | ofs + cnt, ctx.qry.grep, | 418 | ofs + cnt, ctx.qry.grep, |
225 | ctx.qry.search, ctx.qry.showmsg); | 419 | ctx.qry.search, ctx.qry.showmsg); |
226 | } | 420 | } |
227 | html("</div>"); | 421 | html("</div>"); |
228 | } else if ((commit = get_revision(&rev)) != NULL) { | 422 | } else if ((commit = get_revision(&rev)) != NULL) { |
229 | html("<tr class='nohover'><td colspan='3'>"); | 423 | html("<tr class='nohover'><td colspan='3'>"); |
230 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, | 424 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, |
231 | NULL, NULL, ctx.qry.showmsg); | 425 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); |
232 | html("</td></tr>\n"); | 426 | html("</td></tr>\n"); |
233 | } | 427 | } |
234 | } | 428 | } |
@@ -1,8 +1,9 @@ | |||
1 | #ifndef UI_LOG_H | 1 | #ifndef UI_LOG_H |
2 | #define UI_LOG_H | 2 | #define UI_LOG_H |
3 | 3 | ||
4 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, | 4 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, |
5 | char *pattern, char *path, int pager); | 5 | char *pattern, char *path, int pager, |
6 | int commit_graph); | ||
6 | extern void show_commit_decorations(struct commit *commit); | 7 | extern void show_commit_decorations(struct commit *commit); |
7 | 8 | ||
8 | #endif /* UI_LOG_H */ | 9 | #endif /* UI_LOG_H */ |
@@ -26,104 +26,106 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
26 | int subproject; | 26 | int subproject; |
27 | 27 | ||
28 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | 28 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
29 | htmlf("diff --git a/%s b/%s\n", path1, path2); | 29 | htmlf("diff --git a/%s b/%s\n", path1, path2); |
30 | 30 | ||
31 | if (is_null_sha1(sha1)) | 31 | if (is_null_sha1(sha1)) |
32 | path1 = "dev/null"; | 32 | path1 = "dev/null"; |
33 | if (is_null_sha1(sha2)) | 33 | if (is_null_sha1(sha2)) |
34 | path2 = "dev/null"; | 34 | path2 = "dev/null"; |
35 | 35 | ||
36 | if (mode1 == 0) | 36 | if (mode1 == 0) |
37 | htmlf("new file mode %.6o\n", mode2); | 37 | htmlf("new file mode %.6o\n", mode2); |
38 | 38 | ||
39 | if (mode2 == 0) | 39 | if (mode2 == 0) |
40 | htmlf("deleted file mode %.6o\n", mode1); | 40 | htmlf("deleted file mode %.6o\n", mode1); |
41 | 41 | ||
42 | if (!subproject) { | 42 | if (!subproject) { |
43 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | 43 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
44 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | 44 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
45 | htmlf("index %s..%s", abbrev1, abbrev2); | 45 | htmlf("index %s..%s", abbrev1, abbrev2); |
46 | free(abbrev1); | 46 | free(abbrev1); |
47 | free(abbrev2); | 47 | free(abbrev2); |
48 | if (mode1 != 0 && mode2 != 0) { | 48 | if (mode1 != 0 && mode2 != 0) { |
49 | htmlf(" %.6o", mode1); | 49 | htmlf(" %.6o", mode1); |
50 | if (mode2 != mode1) | 50 | if (mode2 != mode1) |
51 | htmlf("..%.6o", mode2); | 51 | htmlf("..%.6o", mode2); |
52 | } | 52 | } |
53 | htmlf("\n--- a/%s\n", path1); | 53 | htmlf("\n--- a/%s\n", path1); |
54 | htmlf("+++ b/%s\n", path2); | 54 | htmlf("+++ b/%s\n", path2); |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | static void filepair_cb(struct diff_filepair *pair) | 58 | static void filepair_cb(struct diff_filepair *pair) |
59 | { | 59 | { |
60 | unsigned long old_size = 0; | 60 | unsigned long old_size = 0; |
61 | unsigned long new_size = 0; | 61 | unsigned long new_size = 0; |
62 | int binary = 0; | 62 | int binary = 0; |
63 | 63 | ||
64 | header(pair->one->sha1, pair->one->path, pair->one->mode, | 64 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
65 | pair->two->sha1, pair->two->path, pair->two->mode); | 65 | pair->two->sha1, pair->two->path, pair->two->mode); |
66 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 66 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
67 | if (S_ISGITLINK(pair->one->mode)) | 67 | if (S_ISGITLINK(pair->one->mode)) |
68 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 68 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
69 | if (S_ISGITLINK(pair->two->mode)) | 69 | if (S_ISGITLINK(pair->two->mode)) |
70 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 70 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 73 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
74 | &new_size, &binary, print_line)) | 74 | &new_size, &binary, 0, 0, print_line)) |
75 | html("Error running diff"); | 75 | html("Error running diff"); |
76 | if (binary) | 76 | if (binary) |
77 | html("Binary files differ\n"); | 77 | html("Binary files differ\n"); |
78 | } | 78 | } |
79 | 79 | ||
80 | void cgit_print_patch(char *hex) | 80 | void cgit_print_patch(char *hex, const char *prefix) |
81 | { | 81 | { |
82 | struct commit *commit; | 82 | struct commit *commit; |
83 | struct commitinfo *info; | 83 | struct commitinfo *info; |
84 | unsigned char sha1[20], old_sha1[20]; | 84 | unsigned char sha1[20], old_sha1[20]; |
85 | char *patchname; | 85 | char *patchname; |
86 | 86 | ||
87 | if (!hex) | 87 | if (!hex) |
88 | hex = ctx.qry.head; | 88 | hex = ctx.qry.head; |
89 | 89 | ||
90 | if (get_sha1(hex, sha1)) { | 90 | if (get_sha1(hex, sha1)) { |
91 | cgit_print_error(fmt("Bad object id: %s", hex)); | 91 | cgit_print_error(fmt("Bad object id: %s", hex)); |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | commit = lookup_commit_reference(sha1); | 94 | commit = lookup_commit_reference(sha1); |
95 | if (!commit) { | 95 | if (!commit) { |
96 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 96 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
97 | return; | 97 | return; |
98 | } | 98 | } |
99 | info = cgit_parse_commit(commit); | 99 | info = cgit_parse_commit(commit); |
100 | 100 | ||
101 | if (commit->parents && commit->parents->item) | 101 | if (commit->parents && commit->parents->item) |
102 | hashcpy(old_sha1, commit->parents->item->object.sha1); | 102 | hashcpy(old_sha1, commit->parents->item->object.sha1); |
103 | else | 103 | else |
104 | hashclr(old_sha1); | 104 | hashclr(old_sha1); |
105 | 105 | ||
106 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); | 106 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); |
107 | ctx.page.mimetype = "text/plain"; | 107 | ctx.page.mimetype = "text/plain"; |
108 | ctx.page.filename = patchname; | 108 | ctx.page.filename = patchname; |
109 | cgit_print_http_headers(&ctx); | 109 | cgit_print_http_headers(&ctx); |
110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); | 110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); |
111 | htmlf("From: %s", info->author); | 111 | htmlf("From: %s", info->author); |
112 | if (!ctx.cfg.noplainemail) { | 112 | if (!ctx.cfg.noplainemail) { |
113 | htmlf(" %s", info->author_email); | 113 | htmlf(" %s", info->author_email); |
114 | } | 114 | } |
115 | html("\n"); | 115 | html("\n"); |
116 | html("Date: "); | 116 | html("Date: "); |
117 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); | 117 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); |
118 | htmlf("Subject: %s\n\n", info->subject); | 118 | htmlf("Subject: %s\n\n", info->subject); |
119 | if (info->msg && *info->msg) { | 119 | if (info->msg && *info->msg) { |
120 | htmlf("%s", info->msg); | 120 | htmlf("%s", info->msg); |
121 | if (info->msg[strlen(info->msg) - 1] != '\n') | 121 | if (info->msg[strlen(info->msg) - 1] != '\n') |
122 | html("\n"); | 122 | html("\n"); |
123 | } | 123 | } |
124 | html("---\n"); | 124 | html("---\n"); |
125 | cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); | 125 | if (prefix) |
126 | htmlf("(limited to '%s')\n\n", prefix); | ||
127 | cgit_diff_tree(old_sha1, sha1, filepair_cb, prefix, 0); | ||
126 | html("--\n"); | 128 | html("--\n"); |
127 | htmlf("cgit %s\n", CGIT_VERSION); | 129 | htmlf("cgit %s\n", CGIT_VERSION); |
128 | cgit_free_commitinfo(info); | 130 | cgit_free_commitinfo(info); |
129 | } | 131 | } |
@@ -1,6 +1,6 @@ | |||
1 | #ifndef UI_PATCH_H | 1 | #ifndef UI_PATCH_H |
2 | #define UI_PATCH_H | 2 | #define UI_PATCH_H |
3 | 3 | ||
4 | extern void cgit_print_patch(char *hex); | 4 | extern void cgit_print_patch(char *hex, const char *prefix); |
5 | 5 | ||
6 | #endif /* UI_PATCH_H */ | 6 | #endif /* UI_PATCH_H */ |
@@ -1,94 +1,146 @@ | |||
1 | /* ui-plain.c: functions for output of plain blobs by path | 1 | /* ui-plain.c: functions for output of plain blobs by path |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | char *curr_rev; | 13 | int match_baselen; |
14 | char *match_path; | ||
15 | int match; | 14 | int match; |
16 | 15 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 16 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 17 | { |
19 | enum object_type type; | 18 | enum object_type type; |
20 | char *buf, *ext; | 19 | char *buf, *ext; |
21 | unsigned long size; | 20 | unsigned long size; |
22 | struct string_list_item *mime; | 21 | struct string_list_item *mime; |
23 | 22 | ||
24 | type = sha1_object_info(sha1, &size); | 23 | type = sha1_object_info(sha1, &size); |
25 | if (type == OBJ_BAD) { | 24 | if (type == OBJ_BAD) { |
26 | html_status(404, "Not found", 0); | 25 | html_status(404, "Not found", 0); |
27 | return; | 26 | return; |
28 | } | 27 | } |
29 | 28 | ||
30 | buf = read_sha1_file(sha1, &type, &size); | 29 | buf = read_sha1_file(sha1, &type, &size); |
31 | if (!buf) { | 30 | if (!buf) { |
32 | html_status(404, "Not found", 0); | 31 | html_status(404, "Not found", 0); |
33 | return; | 32 | return; |
34 | } | 33 | } |
35 | ctx.page.mimetype = NULL; | 34 | ctx.page.mimetype = NULL; |
36 | ext = strrchr(path, '.'); | 35 | ext = strrchr(path, '.'); |
37 | if (ext && *(++ext)) { | 36 | if (ext && *(++ext)) { |
38 | mime = string_list_lookup(&ctx.cfg.mimetypes, ext); | 37 | mime = string_list_lookup(&ctx.cfg.mimetypes, ext); |
39 | if (mime) | 38 | if (mime) |
40 | ctx.page.mimetype = (char *)mime->util; | 39 | ctx.page.mimetype = (char *)mime->util; |
41 | } | 40 | } |
42 | if (!ctx.page.mimetype) { | 41 | if (!ctx.page.mimetype) { |
43 | if (buffer_is_binary(buf, size)) | 42 | if (buffer_is_binary(buf, size)) |
44 | ctx.page.mimetype = "application/octet-stream"; | 43 | ctx.page.mimetype = "application/octet-stream"; |
45 | else | 44 | else |
46 | ctx.page.mimetype = "text/plain"; | 45 | ctx.page.mimetype = "text/plain"; |
47 | } | 46 | } |
48 | ctx.page.filename = fmt("%s", path); | 47 | ctx.page.filename = fmt("%s", path); |
49 | ctx.page.size = size; | 48 | ctx.page.size = size; |
50 | ctx.page.etag = sha1_to_hex(sha1); | 49 | ctx.page.etag = sha1_to_hex(sha1); |
51 | cgit_print_http_headers(&ctx); | 50 | cgit_print_http_headers(&ctx); |
52 | html_raw(buf, size); | 51 | html_raw(buf, size); |
53 | match = 1; | 52 | match = 1; |
54 | } | 53 | } |
55 | 54 | ||
55 | static void print_dir(const unsigned char *sha1, const char *path, | ||
56 | const char *base) | ||
57 | { | ||
58 | char *fullpath; | ||
59 | if (path[0] || base[0]) | ||
60 | fullpath = fmt("/%s%s/", base, path); | ||
61 | else | ||
62 | fullpath = "/"; | ||
63 | ctx.page.etag = sha1_to_hex(sha1); | ||
64 | cgit_print_http_headers(&ctx); | ||
65 | htmlf("<html><head><title>%s</title></head>\n<body>\n" | ||
66 | " <h2>%s</h2>\n <ul>\n", fullpath, fullpath); | ||
67 | if (path[0] || base[0]) | ||
68 | html(" <li><a href=\"../\">../</a></li>\n"); | ||
69 | match = 2; | ||
70 | } | ||
71 | |||
72 | static void print_dir_entry(const unsigned char *sha1, const char *path, | ||
73 | unsigned mode) | ||
74 | { | ||
75 | const char *sep = ""; | ||
76 | if (S_ISDIR(mode)) | ||
77 | sep = "/"; | ||
78 | htmlf(" <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep); | ||
79 | match = 2; | ||
80 | } | ||
81 | |||
82 | static void print_dir_tail(void) | ||
83 | { | ||
84 | html(" </ul>\n</body></html>\n"); | ||
85 | } | ||
86 | |||
56 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 87 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
57 | const char *pathname, unsigned mode, int stage, | 88 | const char *pathname, unsigned mode, int stage, |
58 | void *cbdata) | 89 | void *cbdata) |
59 | { | 90 | { |
60 | if (S_ISDIR(mode)) | 91 | if (baselen == match_baselen) { |
92 | if (S_ISREG(mode)) | ||
93 | print_object(sha1, pathname); | ||
94 | else if (S_ISDIR(mode)) { | ||
95 | print_dir(sha1, pathname, base); | ||
96 | return READ_TREE_RECURSIVE; | ||
97 | } | ||
98 | } | ||
99 | else if (baselen > match_baselen) | ||
100 | print_dir_entry(sha1, pathname, mode); | ||
101 | else if (S_ISDIR(mode)) | ||
61 | return READ_TREE_RECURSIVE; | 102 | return READ_TREE_RECURSIVE; |
62 | 103 | ||
63 | if (S_ISREG(mode) && !strncmp(base, match_path, baselen) && | 104 | return 0; |
64 | !strcmp(pathname, match_path + baselen)) | 105 | } |
65 | print_object(sha1, pathname); | ||
66 | 106 | ||
107 | static int basedir_len(const char *path) | ||
108 | { | ||
109 | char *p = strrchr(path, '/'); | ||
110 | if (p) | ||
111 | return p - path + 1; | ||
67 | return 0; | 112 | return 0; |
68 | } | 113 | } |
69 | 114 | ||
70 | void cgit_print_plain(struct cgit_context *ctx) | 115 | void cgit_print_plain(struct cgit_context *ctx) |
71 | { | 116 | { |
72 | const char *rev = ctx->qry.sha1; | 117 | const char *rev = ctx->qry.sha1; |
73 | unsigned char sha1[20]; | 118 | unsigned char sha1[20]; |
74 | struct commit *commit; | 119 | struct commit *commit; |
75 | const char *paths[] = {ctx->qry.path, NULL}; | 120 | const char *paths[] = {ctx->qry.path, NULL}; |
76 | 121 | ||
77 | if (!rev) | 122 | if (!rev) |
78 | rev = ctx->qry.head; | 123 | rev = ctx->qry.head; |
79 | 124 | ||
80 | curr_rev = xstrdup(rev); | ||
81 | if (get_sha1(rev, sha1)) { | 125 | if (get_sha1(rev, sha1)) { |
82 | html_status(404, "Not found", 0); | 126 | html_status(404, "Not found", 0); |
83 | return; | 127 | return; |
84 | } | 128 | } |
85 | commit = lookup_commit_reference(sha1); | 129 | commit = lookup_commit_reference(sha1); |
86 | if (!commit || parse_commit(commit)) { | 130 | if (!commit || parse_commit(commit)) { |
87 | html_status(404, "Not found", 0); | 131 | html_status(404, "Not found", 0); |
88 | return; | 132 | return; |
89 | } | 133 | } |
90 | match_path = ctx->qry.path; | 134 | if (!paths[0]) { |
135 | paths[0] = ""; | ||
136 | match_baselen = -1; | ||
137 | print_dir(commit->tree->object.sha1, "", ""); | ||
138 | } | ||
139 | else | ||
140 | match_baselen = basedir_len(paths[0]); | ||
91 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | 141 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); |
92 | if (!match) | 142 | if (!match) |
93 | html_status(404, "Not found", 0); | 143 | html_status(404, "Not found", 0); |
144 | else if (match == 2) | ||
145 | print_dir_tail(); | ||
94 | } | 146 | } |
@@ -31,97 +31,97 @@ static int cmp_ref_name(const void *a, const void *b) | |||
31 | struct refinfo *r1 = *(struct refinfo **)a; | 31 | struct refinfo *r1 = *(struct refinfo **)a; |
32 | struct refinfo *r2 = *(struct refinfo **)b; | 32 | struct refinfo *r2 = *(struct refinfo **)b; |
33 | 33 | ||
34 | return strcmp(r1->refname, r2->refname); | 34 | return strcmp(r1->refname, r2->refname); |
35 | } | 35 | } |
36 | 36 | ||
37 | static int cmp_branch_age(const void *a, const void *b) | 37 | static int cmp_branch_age(const void *a, const void *b) |
38 | { | 38 | { |
39 | struct refinfo *r1 = *(struct refinfo **)a; | 39 | struct refinfo *r1 = *(struct refinfo **)a; |
40 | struct refinfo *r2 = *(struct refinfo **)b; | 40 | struct refinfo *r2 = *(struct refinfo **)b; |
41 | 41 | ||
42 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | 42 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
43 | } | 43 | } |
44 | 44 | ||
45 | static int get_ref_age(struct refinfo *ref) | 45 | static int get_ref_age(struct refinfo *ref) |
46 | { | 46 | { |
47 | if (!ref->object) | 47 | if (!ref->object) |
48 | return 0; | 48 | return 0; |
49 | switch (ref->object->type) { | 49 | switch (ref->object->type) { |
50 | case OBJ_TAG: | 50 | case OBJ_TAG: |
51 | return ref->tag ? ref->tag->tagger_date : 0; | 51 | return ref->tag ? ref->tag->tagger_date : 0; |
52 | case OBJ_COMMIT: | 52 | case OBJ_COMMIT: |
53 | return ref->commit ? ref->commit->committer_date : 0; | 53 | return ref->commit ? ref->commit->committer_date : 0; |
54 | } | 54 | } |
55 | return 0; | 55 | return 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | static int cmp_tag_age(const void *a, const void *b) | 58 | static int cmp_tag_age(const void *a, const void *b) |
59 | { | 59 | { |
60 | struct refinfo *r1 = *(struct refinfo **)a; | 60 | struct refinfo *r1 = *(struct refinfo **)a; |
61 | struct refinfo *r2 = *(struct refinfo **)b; | 61 | struct refinfo *r2 = *(struct refinfo **)b; |
62 | 62 | ||
63 | return cmp_age(get_ref_age(r1), get_ref_age(r2)); | 63 | return cmp_age(get_ref_age(r1), get_ref_age(r2)); |
64 | } | 64 | } |
65 | 65 | ||
66 | static int print_branch(struct refinfo *ref) | 66 | static int print_branch(struct refinfo *ref) |
67 | { | 67 | { |
68 | struct commitinfo *info = ref->commit; | 68 | struct commitinfo *info = ref->commit; |
69 | char *name = (char *)ref->refname; | 69 | char *name = (char *)ref->refname; |
70 | 70 | ||
71 | if (!info) | 71 | if (!info) |
72 | return 1; | 72 | return 1; |
73 | html("<tr><td>"); | 73 | html("<tr><td>"); |
74 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, | 74 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, |
75 | ctx.qry.showmsg); | 75 | ctx.qry.showmsg); |
76 | html("</td><td>"); | 76 | html("</td><td>"); |
77 | 77 | ||
78 | if (ref->object->type == OBJ_COMMIT) { | 78 | if (ref->object->type == OBJ_COMMIT) { |
79 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 79 | cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0); |
80 | html("</td><td>"); | 80 | html("</td><td>"); |
81 | html_txt(info->author); | 81 | html_txt(info->author); |
82 | html("</td><td colspan='2'>"); | 82 | html("</td><td colspan='2'>"); |
83 | cgit_print_age(info->commit->date, -1, NULL); | 83 | cgit_print_age(info->commit->date, -1, NULL); |
84 | } else { | 84 | } else { |
85 | html("</td><td></td><td>"); | 85 | html("</td><td></td><td>"); |
86 | cgit_object_link(ref->object); | 86 | cgit_object_link(ref->object); |
87 | } | 87 | } |
88 | html("</td></tr>\n"); | 88 | html("</td></tr>\n"); |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | static void print_tag_header() | 92 | static void print_tag_header() |
93 | { | 93 | { |
94 | html("<tr class='nohover'><th class='left'>Tag</th>" | 94 | html("<tr class='nohover'><th class='left'>Tag</th>" |
95 | "<th class='left'>Download</th>" | 95 | "<th class='left'>Download</th>" |
96 | "<th class='left'>Author</th>" | 96 | "<th class='left'>Author</th>" |
97 | "<th class='left' colspan='2'>Age</th></tr>\n"); | 97 | "<th class='left' colspan='2'>Age</th></tr>\n"); |
98 | header = 1; | 98 | header = 1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) | 101 | static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) |
102 | { | 102 | { |
103 | const struct cgit_snapshot_format* f; | 103 | const struct cgit_snapshot_format* f; |
104 | char *filename; | 104 | char *filename; |
105 | const char *basename; | 105 | const char *basename; |
106 | 106 | ||
107 | if (!ref || strlen(ref) < 2) | 107 | if (!ref || strlen(ref) < 2) |
108 | return; | 108 | return; |
109 | 109 | ||
110 | basename = cgit_repobasename(repo->url); | 110 | basename = cgit_repobasename(repo->url); |
111 | if (prefixcmp(ref, basename) != 0) { | 111 | if (prefixcmp(ref, basename) != 0) { |
112 | if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) | 112 | if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) |
113 | ref++; | 113 | ref++; |
114 | if (isdigit(ref[0])) | 114 | if (isdigit(ref[0])) |
115 | ref = xstrdup(fmt("%s-%s", basename, ref)); | 115 | ref = xstrdup(fmt("%s-%s", basename, ref)); |
116 | } | 116 | } |
117 | 117 | ||
118 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 118 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
119 | if (!(repo->snapshots & f->bit)) | 119 | if (!(repo->snapshots & f->bit)) |
120 | continue; | 120 | continue; |
121 | filename = fmt("%s%s", ref, f->suffix); | 121 | filename = fmt("%s%s", ref, f->suffix); |
122 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); | 122 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); |
123 | html(" "); | 123 | html(" "); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | static int print_tag(struct refinfo *ref) | 126 | static int print_tag(struct refinfo *ref) |
127 | { | 127 | { |
@@ -144,96 +144,98 @@ static int print_tag(struct refinfo *ref) | |||
144 | html("</td><td>"); | 144 | html("</td><td>"); |
145 | if (info->tagger) | 145 | if (info->tagger) |
146 | html(info->tagger); | 146 | html(info->tagger); |
147 | html("</td><td colspan='2'>"); | 147 | html("</td><td colspan='2'>"); |
148 | if (info->tagger_date > 0) | 148 | if (info->tagger_date > 0) |
149 | cgit_print_age(info->tagger_date, -1, NULL); | 149 | cgit_print_age(info->tagger_date, -1, NULL); |
150 | html("</td></tr>\n"); | 150 | html("</td></tr>\n"); |
151 | } else { | 151 | } else { |
152 | if (!header) | 152 | if (!header) |
153 | print_tag_header(); | 153 | print_tag_header(); |
154 | html("<tr><td>"); | 154 | html("<tr><td>"); |
155 | cgit_tag_link(name, NULL, NULL, ctx.qry.head, name); | 155 | cgit_tag_link(name, NULL, NULL, ctx.qry.head, name); |
156 | html("</td><td>"); | 156 | html("</td><td>"); |
157 | if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT)) | 157 | if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT)) |
158 | print_tag_downloads(ctx.repo, name); | 158 | print_tag_downloads(ctx.repo, name); |
159 | else | 159 | else |
160 | cgit_object_link(ref->object); | 160 | cgit_object_link(ref->object); |
161 | html("</td><td>"); | 161 | html("</td><td>"); |
162 | if (ref->object->type == OBJ_COMMIT) | 162 | if (ref->object->type == OBJ_COMMIT) |
163 | html(ref->commit->author); | 163 | html(ref->commit->author); |
164 | html("</td><td colspan='2'>"); | 164 | html("</td><td colspan='2'>"); |
165 | if (ref->object->type == OBJ_COMMIT) | 165 | if (ref->object->type == OBJ_COMMIT) |
166 | cgit_print_age(ref->commit->commit->date, -1, NULL); | 166 | cgit_print_age(ref->commit->commit->date, -1, NULL); |
167 | html("</td></tr>\n"); | 167 | html("</td></tr>\n"); |
168 | } | 168 | } |
169 | return 0; | 169 | return 0; |
170 | } | 170 | } |
171 | 171 | ||
172 | static void print_refs_link(char *path) | 172 | static void print_refs_link(char *path) |
173 | { | 173 | { |
174 | html("<tr class='nohover'><td colspan='4'>"); | 174 | html("<tr class='nohover'><td colspan='4'>"); |
175 | cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); | 175 | cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); |
176 | html("</td></tr>"); | 176 | html("</td></tr>"); |
177 | } | 177 | } |
178 | 178 | ||
179 | void cgit_print_branches(int maxcount) | 179 | void cgit_print_branches(int maxcount) |
180 | { | 180 | { |
181 | struct reflist list; | 181 | struct reflist list; |
182 | int i; | 182 | int i; |
183 | 183 | ||
184 | html("<tr class='nohover'><th class='left'>Branch</th>" | 184 | html("<tr class='nohover'><th class='left'>Branch</th>" |
185 | "<th class='left'>Commit message</th>" | 185 | "<th class='left'>Commit message</th>" |
186 | "<th class='left'>Author</th>" | 186 | "<th class='left'>Author</th>" |
187 | "<th class='left' colspan='2'>Age</th></tr>\n"); | 187 | "<th class='left' colspan='2'>Age</th></tr>\n"); |
188 | 188 | ||
189 | list.refs = NULL; | 189 | list.refs = NULL; |
190 | list.alloc = list.count = 0; | 190 | list.alloc = list.count = 0; |
191 | for_each_branch_ref(cgit_refs_cb, &list); | 191 | for_each_branch_ref(cgit_refs_cb, &list); |
192 | if (ctx.repo->enable_remote_branches) | ||
193 | for_each_remote_ref(cgit_refs_cb, &list); | ||
192 | 194 | ||
193 | if (maxcount == 0 || maxcount > list.count) | 195 | if (maxcount == 0 || maxcount > list.count) |
194 | maxcount = list.count; | 196 | maxcount = list.count; |
195 | 197 | ||
196 | if (maxcount < list.count) { | 198 | if (maxcount < list.count) { |
197 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 199 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
198 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 200 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
199 | } | 201 | } |
200 | 202 | ||
201 | for(i=0; i<maxcount; i++) | 203 | for(i=0; i<maxcount; i++) |
202 | print_branch(list.refs[i]); | 204 | print_branch(list.refs[i]); |
203 | 205 | ||
204 | if (maxcount < list.count) | 206 | if (maxcount < list.count) |
205 | print_refs_link("heads"); | 207 | print_refs_link("heads"); |
206 | } | 208 | } |
207 | 209 | ||
208 | void cgit_print_tags(int maxcount) | 210 | void cgit_print_tags(int maxcount) |
209 | { | 211 | { |
210 | struct reflist list; | 212 | struct reflist list; |
211 | int i; | 213 | int i; |
212 | 214 | ||
213 | header = 0; | 215 | header = 0; |
214 | list.refs = NULL; | 216 | list.refs = NULL; |
215 | list.alloc = list.count = 0; | 217 | list.alloc = list.count = 0; |
216 | for_each_tag_ref(cgit_refs_cb, &list); | 218 | for_each_tag_ref(cgit_refs_cb, &list); |
217 | if (list.count == 0) | 219 | if (list.count == 0) |
218 | return; | 220 | return; |
219 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 221 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
220 | if (!maxcount) | 222 | if (!maxcount) |
221 | maxcount = list.count; | 223 | maxcount = list.count; |
222 | else if (maxcount > list.count) | 224 | else if (maxcount > list.count) |
223 | maxcount = list.count; | 225 | maxcount = list.count; |
224 | print_tag_header(); | 226 | print_tag_header(); |
225 | for(i=0; i<maxcount; i++) | 227 | for(i=0; i<maxcount; i++) |
226 | print_tag(list.refs[i]); | 228 | print_tag(list.refs[i]); |
227 | 229 | ||
228 | if (maxcount < list.count) | 230 | if (maxcount < list.count) |
229 | print_refs_link("tags"); | 231 | print_refs_link("tags"); |
230 | } | 232 | } |
231 | 233 | ||
232 | void cgit_print_refs() | 234 | void cgit_print_refs() |
233 | { | 235 | { |
234 | 236 | ||
235 | html("<table class='list nowrap'>"); | 237 | html("<table class='list nowrap'>"); |
236 | 238 | ||
237 | if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5)) | 239 | if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5)) |
238 | cgit_print_branches(0); | 240 | cgit_print_branches(0); |
239 | else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4)) | 241 | else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4)) |
diff --git a/ui-repolist.c b/ui-repolist.c index 0a0b6ca..2c98668 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,62 +1,56 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | /* This is needed for strcasestr to be defined by <string.h> */ | ||
10 | #define _GNU_SOURCE 1 | ||
11 | #include <string.h> | ||
12 | |||
13 | #include <time.h> | ||
14 | |||
15 | #include "cgit.h" | 9 | #include "cgit.h" |
16 | #include "html.h" | 10 | #include "html.h" |
17 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
18 | 12 | ||
19 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
20 | { | 14 | { |
21 | time_t result; | 15 | time_t result; |
22 | size_t size; | 16 | size_t size; |
23 | char *buf; | 17 | char *buf; |
24 | static char buf2[64]; | 18 | static char buf2[64]; |
25 | 19 | ||
26 | if (readfile(path, &buf, &size)) | 20 | if (readfile(path, &buf, &size)) |
27 | return -1; | 21 | return -1; |
28 | 22 | ||
29 | if (parse_date(buf, buf2, sizeof(buf2))) | 23 | if (parse_date(buf, buf2, sizeof(buf2))) |
30 | result = strtoul(buf2, NULL, 10); | 24 | result = strtoul(buf2, NULL, 10); |
31 | else | 25 | else |
32 | result = 0; | 26 | result = 0; |
33 | free(buf); | 27 | free(buf); |
34 | return result; | 28 | return result; |
35 | } | 29 | } |
36 | 30 | ||
37 | static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) | 31 | static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) |
38 | { | 32 | { |
39 | char *path; | 33 | char *path; |
40 | struct stat s; | 34 | struct stat s; |
41 | struct cgit_repo *r = (struct cgit_repo *)repo; | 35 | struct cgit_repo *r = (struct cgit_repo *)repo; |
42 | 36 | ||
43 | if (repo->mtime != -1) { | 37 | if (repo->mtime != -1) { |
44 | *mtime = repo->mtime; | 38 | *mtime = repo->mtime; |
45 | return 1; | 39 | return 1; |
46 | } | 40 | } |
47 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 41 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
48 | if (stat(path, &s) == 0) { | 42 | if (stat(path, &s) == 0) { |
49 | *mtime = read_agefile(path); | 43 | *mtime = read_agefile(path); |
50 | r->mtime = *mtime; | 44 | r->mtime = *mtime; |
51 | return 1; | 45 | return 1; |
52 | } | 46 | } |
53 | 47 | ||
54 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 48 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
55 | if (stat(path, &s) == 0) | 49 | if (stat(path, &s) == 0) |
56 | *mtime = s.st_mtime; | 50 | *mtime = s.st_mtime; |
57 | else | 51 | else |
58 | *mtime = 0; | 52 | *mtime = 0; |
59 | 53 | ||
60 | r->mtime = *mtime; | 54 | r->mtime = *mtime; |
61 | return (r->mtime != 0); | 55 | return (r->mtime != 0); |
62 | } | 56 | } |
diff --git a/ui-shared.c b/ui-shared.c index d1b020b..5aa9119 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,78 +1,78 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output 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 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
18 | { | 18 | { |
19 | static char day[][4] = | 19 | static char day[][4] = |
20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
21 | static char month[][4] = | 21 | static char month[][4] = |
22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
24 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(const char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | 37 | char *cgit_httpscheme() |
38 | { | 38 | { |
39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) | 39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
40 | return "https://"; | 40 | return "https://"; |
41 | else | 41 | else |
42 | return "http://"; | 42 | return "http://"; |
43 | } | 43 | } |
44 | 44 | ||
45 | char *cgit_hosturl() | 45 | char *cgit_hosturl() |
46 | { | 46 | { |
47 | if (ctx.env.http_host) | 47 | if (ctx.env.http_host) |
48 | return ctx.env.http_host; | 48 | return ctx.env.http_host; |
49 | if (!ctx.env.server_name) | 49 | if (!ctx.env.server_name) |
50 | return NULL; | 50 | return NULL; |
51 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) | 51 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) |
52 | return ctx.env.server_name; | 52 | return ctx.env.server_name; |
53 | return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); | 53 | return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); |
54 | } | 54 | } |
55 | 55 | ||
56 | char *cgit_rooturl() | 56 | char *cgit_rooturl() |
57 | { | 57 | { |
58 | if (ctx.cfg.virtual_root) | 58 | if (ctx.cfg.virtual_root) |
59 | return fmt("%s/", ctx.cfg.virtual_root); | 59 | return fmt("%s/", ctx.cfg.virtual_root); |
60 | else | 60 | else |
61 | return ctx.cfg.script_name; | 61 | return ctx.cfg.script_name; |
62 | } | 62 | } |
63 | 63 | ||
64 | char *cgit_repourl(const char *reponame) | 64 | char *cgit_repourl(const char *reponame) |
65 | { | 65 | { |
66 | if (ctx.cfg.virtual_root) { | 66 | if (ctx.cfg.virtual_root) { |
67 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 67 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
68 | } else { | 68 | } else { |
69 | return fmt("?r=%s", reponame); | 69 | return fmt("?r=%s", reponame); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | char *cgit_fileurl(const char *reponame, const char *pagename, | 73 | char *cgit_fileurl(const char *reponame, const char *pagename, |
74 | const char *filename, const char *query) | 74 | const char *filename, const char *query) |
75 | { | 75 | { |
76 | char *tmp; | 76 | char *tmp; |
77 | char *delim; | 77 | char *delim; |
78 | 78 | ||
@@ -88,374 +88,482 @@ char *cgit_fileurl(const char *reponame, const char *pagename, | |||
88 | if (query) | 88 | if (query) |
89 | tmp = fmt("%s%s%s", tmp, delim, query); | 89 | tmp = fmt("%s%s%s", tmp, delim, query); |
90 | return tmp; | 90 | return tmp; |
91 | } | 91 | } |
92 | 92 | ||
93 | char *cgit_pageurl(const char *reponame, const char *pagename, | 93 | char *cgit_pageurl(const char *reponame, const char *pagename, |
94 | const char *query) | 94 | const char *query) |
95 | { | 95 | { |
96 | return cgit_fileurl(reponame,pagename,0,query); | 96 | return cgit_fileurl(reponame,pagename,0,query); |
97 | } | 97 | } |
98 | 98 | ||
99 | const char *cgit_repobasename(const char *reponame) | 99 | const char *cgit_repobasename(const char *reponame) |
100 | { | 100 | { |
101 | /* I assume we don't need to store more than one repo basename */ | 101 | /* I assume we don't need to store more than one repo basename */ |
102 | static char rvbuf[1024]; | 102 | static char rvbuf[1024]; |
103 | int p; | 103 | int p; |
104 | const char *rv; | 104 | const char *rv; |
105 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 105 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
106 | if(rvbuf[sizeof(rvbuf)-1]) | 106 | if(rvbuf[sizeof(rvbuf)-1]) |
107 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 107 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
108 | p = strlen(rvbuf)-1; | 108 | p = strlen(rvbuf)-1; |
109 | /* strip trailing slashes */ | 109 | /* strip trailing slashes */ |
110 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 110 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
111 | /* strip trailing .git */ | 111 | /* strip trailing .git */ |
112 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 112 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
113 | p -= 3; rvbuf[p--] = 0; | 113 | p -= 3; rvbuf[p--] = 0; |
114 | } | 114 | } |
115 | /* strip more trailing slashes if any */ | 115 | /* strip more trailing slashes if any */ |
116 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 116 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
117 | /* find last slash in the remaining string */ | 117 | /* find last slash in the remaining string */ |
118 | rv = strrchr(rvbuf,'/'); | 118 | rv = strrchr(rvbuf,'/'); |
119 | if(rv) | 119 | if(rv) |
120 | return ++rv; | 120 | return ++rv; |
121 | return rvbuf; | 121 | return rvbuf; |
122 | } | 122 | } |
123 | 123 | ||
124 | char *cgit_currurl() | 124 | char *cgit_currurl() |
125 | { | 125 | { |
126 | if (!ctx.cfg.virtual_root) | 126 | if (!ctx.cfg.virtual_root) |
127 | return ctx.cfg.script_name; | 127 | return ctx.cfg.script_name; |
128 | else if (ctx.qry.page) | 128 | else if (ctx.qry.page) |
129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
130 | else if (ctx.qry.repo) | 130 | else if (ctx.qry.repo) |
131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
132 | else | 132 | else |
133 | return fmt("%s/", ctx.cfg.virtual_root); | 133 | return fmt("%s/", ctx.cfg.virtual_root); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void site_url(char *page, char *search, int ofs) | 136 | static void site_url(const char *page, const char *search, int ofs) |
137 | { | 137 | { |
138 | char *delim = "?"; | 138 | char *delim = "?"; |
139 | 139 | ||
140 | if (ctx.cfg.virtual_root) { | 140 | if (ctx.cfg.virtual_root) { |
141 | html_attr(ctx.cfg.virtual_root); | 141 | html_attr(ctx.cfg.virtual_root); |
142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 143 | html("/"); |
144 | } else | 144 | } else |
145 | html(ctx.cfg.script_name); | 145 | html(ctx.cfg.script_name); |
146 | 146 | ||
147 | if (page) { | 147 | if (page) { |
148 | htmlf("?p=%s", page); | 148 | htmlf("?p=%s", page); |
149 | delim = "&"; | 149 | delim = "&"; |
150 | } | 150 | } |
151 | if (search) { | 151 | if (search) { |
152 | html(delim); | 152 | html(delim); |
153 | html("q="); | 153 | html("q="); |
154 | html_attr(search); | 154 | html_attr(search); |
155 | delim = "&"; | 155 | delim = "&"; |
156 | } | 156 | } |
157 | if (ofs) { | 157 | if (ofs) { |
158 | html(delim); | 158 | html(delim); |
159 | htmlf("ofs=%d", ofs); | 159 | htmlf("ofs=%d", ofs); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | static void site_link(char *page, char *name, char *title, char *class, | 163 | static void site_link(const char *page, const char *name, const char *title, |
164 | char *search, int ofs) | 164 | const char *class, const char *search, int ofs) |
165 | { | 165 | { |
166 | html("<a"); | 166 | html("<a"); |
167 | if (title) { | 167 | if (title) { |
168 | html(" title='"); | 168 | html(" title='"); |
169 | html_attr(title); | 169 | html_attr(title); |
170 | html("'"); | 170 | html("'"); |
171 | } | 171 | } |
172 | if (class) { | 172 | if (class) { |
173 | html(" class='"); | 173 | html(" class='"); |
174 | html_attr(class); | 174 | html_attr(class); |
175 | html("'"); | 175 | html("'"); |
176 | } | 176 | } |
177 | html(" href='"); | 177 | html(" href='"); |
178 | site_url(page, search, ofs); | 178 | site_url(page, search, ofs); |
179 | html("'>"); | 179 | html("'>"); |
180 | html_txt(name); | 180 | html_txt(name); |
181 | html("</a>"); | 181 | html("</a>"); |
182 | } | 182 | } |
183 | 183 | ||
184 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | 184 | void cgit_index_link(const char *name, const char *title, const char *class, |
185 | int ofs) | 185 | const char *pattern, int ofs) |
186 | { | 186 | { |
187 | site_link(NULL, name, title, class, pattern, ofs); | 187 | site_link(NULL, name, title, class, pattern, ofs); |
188 | } | 188 | } |
189 | 189 | ||
190 | static char *repolink(char *title, char *class, char *page, char *head, | 190 | static char *repolink(const char *title, const char *class, const char *page, |
191 | char *path) | 191 | const char *head, const char *path) |
192 | { | 192 | { |
193 | char *delim = "?"; | 193 | char *delim = "?"; |
194 | 194 | ||
195 | html("<a"); | 195 | html("<a"); |
196 | if (title) { | 196 | if (title) { |
197 | html(" title='"); | 197 | html(" title='"); |
198 | html_attr(title); | 198 | html_attr(title); |
199 | html("'"); | 199 | html("'"); |
200 | } | 200 | } |
201 | if (class) { | 201 | if (class) { |
202 | html(" class='"); | 202 | html(" class='"); |
203 | html_attr(class); | 203 | html_attr(class); |
204 | html("'"); | 204 | html("'"); |
205 | } | 205 | } |
206 | html(" href='"); | 206 | html(" href='"); |
207 | if (ctx.cfg.virtual_root) { | 207 | if (ctx.cfg.virtual_root) { |
208 | html_url_path(ctx.cfg.virtual_root); | 208 | html_url_path(ctx.cfg.virtual_root); |
209 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 209 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
210 | html("/"); | 210 | html("/"); |
211 | html_url_path(ctx.repo->url); | 211 | html_url_path(ctx.repo->url); |
212 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 212 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
213 | html("/"); | 213 | html("/"); |
214 | if (page) { | 214 | if (page) { |
215 | html_url_path(page); | 215 | html_url_path(page); |
216 | html("/"); | 216 | html("/"); |
217 | if (path) | 217 | if (path) |
218 | html_url_path(path); | 218 | html_url_path(path); |
219 | } | 219 | } |
220 | } else { | 220 | } else { |
221 | html(ctx.cfg.script_name); | 221 | html(ctx.cfg.script_name); |
222 | html("?url="); | 222 | html("?url="); |
223 | html_url_arg(ctx.repo->url); | 223 | html_url_arg(ctx.repo->url); |
224 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 224 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
225 | html("/"); | 225 | html("/"); |
226 | if (page) { | 226 | if (page) { |
227 | html_url_arg(page); | 227 | html_url_arg(page); |
228 | html("/"); | 228 | html("/"); |
229 | if (path) | 229 | if (path) |
230 | html_url_arg(path); | 230 | html_url_arg(path); |
231 | } | 231 | } |
232 | delim = "&"; | 232 | delim = "&"; |
233 | } | 233 | } |
234 | if (head && strcmp(head, ctx.repo->defbranch)) { | 234 | if (head && strcmp(head, ctx.repo->defbranch)) { |
235 | html(delim); | 235 | html(delim); |
236 | html("h="); | 236 | html("h="); |
237 | html_url_arg(head); | 237 | html_url_arg(head); |
238 | delim = "&"; | 238 | delim = "&"; |
239 | } | 239 | } |
240 | return fmt("%s", delim); | 240 | return fmt("%s", delim); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void reporevlink(char *page, char *name, char *title, char *class, | 243 | static void reporevlink(const char *page, const char *name, const char *title, |
244 | char *head, char *rev, char *path) | 244 | const char *class, const char *head, const char *rev, |
245 | const char *path) | ||
245 | { | 246 | { |
246 | char *delim; | 247 | char *delim; |
247 | 248 | ||
248 | delim = repolink(title, class, page, head, path); | 249 | delim = repolink(title, class, page, head, path); |
249 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { | 250 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { |
250 | html(delim); | 251 | html(delim); |
251 | html("id="); | 252 | html("id="); |
252 | html_url_arg(rev); | 253 | html_url_arg(rev); |
253 | } | 254 | } |
254 | html("'>"); | 255 | html("'>"); |
255 | html_txt(name); | 256 | html_txt(name); |
256 | html("</a>"); | 257 | html("</a>"); |
257 | } | 258 | } |
258 | 259 | ||
259 | void cgit_summary_link(char *name, char *title, char *class, char *head) | 260 | void cgit_summary_link(const char *name, const char *title, const char *class, |
261 | const char *head) | ||
260 | { | 262 | { |
261 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 263 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
262 | } | 264 | } |
263 | 265 | ||
264 | void cgit_tag_link(char *name, char *title, char *class, char *head, | 266 | void cgit_tag_link(const char *name, const char *title, const char *class, |
265 | char *rev) | 267 | const char *head, const char *rev) |
266 | { | 268 | { |
267 | reporevlink("tag", name, title, class, head, rev, NULL); | 269 | reporevlink("tag", name, title, class, head, rev, NULL); |
268 | } | 270 | } |
269 | 271 | ||
270 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 272 | void cgit_tree_link(const char *name, const char *title, const char *class, |
271 | char *rev, char *path) | 273 | const char *head, const char *rev, const char *path) |
272 | { | 274 | { |
273 | reporevlink("tree", name, title, class, head, rev, path); | 275 | reporevlink("tree", name, title, class, head, rev, path); |
274 | } | 276 | } |
275 | 277 | ||
276 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 278 | void cgit_plain_link(const char *name, const char *title, const char *class, |
277 | char *rev, char *path) | 279 | const char *head, const char *rev, const char *path) |
278 | { | 280 | { |
279 | reporevlink("plain", name, title, class, head, rev, path); | 281 | reporevlink("plain", name, title, class, head, rev, path); |
280 | } | 282 | } |
281 | 283 | ||
282 | void cgit_log_link(char *name, char *title, char *class, char *head, | 284 | void cgit_log_link(const char *name, const char *title, const char *class, |
283 | char *rev, char *path, int ofs, char *grep, char *pattern, | 285 | const char *head, const char *rev, const char *path, |
284 | int showmsg) | 286 | int ofs, const char *grep, const char *pattern, int showmsg) |
285 | { | 287 | { |
286 | char *delim; | 288 | char *delim; |
287 | 289 | ||
288 | delim = repolink(title, class, "log", head, path); | 290 | delim = repolink(title, class, "log", head, path); |
289 | if (rev && strcmp(rev, ctx.qry.head)) { | 291 | if (rev && strcmp(rev, ctx.qry.head)) { |
290 | html(delim); | 292 | html(delim); |
291 | html("id="); | 293 | html("id="); |
292 | html_url_arg(rev); | 294 | html_url_arg(rev); |
293 | delim = "&"; | 295 | delim = "&"; |
294 | } | 296 | } |
295 | if (grep && pattern) { | 297 | if (grep && pattern) { |
296 | html(delim); | 298 | html(delim); |
297 | html("qt="); | 299 | html("qt="); |
298 | html_url_arg(grep); | 300 | html_url_arg(grep); |
299 | delim = "&"; | 301 | delim = "&"; |
300 | html(delim); | 302 | html(delim); |
301 | html("q="); | 303 | html("q="); |
302 | html_url_arg(pattern); | 304 | html_url_arg(pattern); |
303 | } | 305 | } |
304 | if (ofs > 0) { | 306 | if (ofs > 0) { |
305 | html(delim); | 307 | html(delim); |
306 | html("ofs="); | 308 | html("ofs="); |
307 | htmlf("%d", ofs); | 309 | htmlf("%d", ofs); |
308 | delim = "&"; | 310 | delim = "&"; |
309 | } | 311 | } |
310 | if (showmsg) { | 312 | if (showmsg) { |
311 | html(delim); | 313 | html(delim); |
312 | html("showmsg=1"); | 314 | html("showmsg=1"); |
313 | } | 315 | } |
314 | html("'>"); | 316 | html("'>"); |
315 | html_txt(name); | 317 | html_txt(name); |
316 | html("</a>"); | 318 | html("</a>"); |
317 | } | 319 | } |
318 | 320 | ||
319 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 321 | void cgit_commit_link(char *name, const char *title, const char *class, |
320 | char *rev) | 322 | const char *head, const char *rev, const char *path, |
323 | int toggle_ssdiff) | ||
321 | { | 324 | { |
322 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 325 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
323 | name[ctx.cfg.max_msg_len] = '\0'; | 326 | name[ctx.cfg.max_msg_len] = '\0'; |
324 | name[ctx.cfg.max_msg_len - 1] = '.'; | 327 | name[ctx.cfg.max_msg_len - 1] = '.'; |
325 | name[ctx.cfg.max_msg_len - 2] = '.'; | 328 | name[ctx.cfg.max_msg_len - 2] = '.'; |
326 | name[ctx.cfg.max_msg_len - 3] = '.'; | 329 | name[ctx.cfg.max_msg_len - 3] = '.'; |
327 | } | 330 | } |
328 | reporevlink("commit", name, title, class, head, rev, NULL); | 331 | |
332 | char *delim; | ||
333 | |||
334 | delim = repolink(title, class, "commit", head, path); | ||
335 | if (rev && strcmp(rev, ctx.qry.head)) { | ||
336 | html(delim); | ||
337 | html("id="); | ||
338 | html_url_arg(rev); | ||
339 | delim = "&"; | ||
340 | } | ||
341 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | ||
342 | html(delim); | ||
343 | html("ss=1"); | ||
344 | delim = "&"; | ||
345 | } | ||
346 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | ||
347 | html(delim); | ||
348 | html("context="); | ||
349 | htmlf("%d", ctx.qry.context); | ||
350 | delim = "&"; | ||
351 | } | ||
352 | if (ctx.qry.ignorews) { | ||
353 | html(delim); | ||
354 | html("ignorews=1"); | ||
355 | delim = "&"; | ||
356 | } | ||
357 | html("'>"); | ||
358 | html_txt(name); | ||
359 | html("</a>"); | ||
329 | } | 360 | } |
330 | 361 | ||
331 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 362 | void cgit_refs_link(const char *name, const char *title, const char *class, |
332 | char *rev, char *path) | 363 | const char *head, const char *rev, const char *path) |
333 | { | 364 | { |
334 | reporevlink("refs", name, title, class, head, rev, path); | 365 | reporevlink("refs", name, title, class, head, rev, path); |
335 | } | 366 | } |
336 | 367 | ||
337 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 368 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
338 | char *rev, char *archivename) | 369 | const char *head, const char *rev, |
370 | const char *archivename) | ||
339 | { | 371 | { |
340 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 372 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
341 | } | 373 | } |
342 | 374 | ||
343 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 375 | void cgit_diff_link(const char *name, const char *title, const char *class, |
344 | char *new_rev, char *old_rev, char *path) | 376 | const char *head, const char *new_rev, const char *old_rev, |
377 | const char *path, int toggle_ssdiff) | ||
345 | { | 378 | { |
346 | char *delim; | 379 | char *delim; |
347 | 380 | ||
348 | delim = repolink(title, class, "diff", head, path); | 381 | delim = repolink(title, class, "diff", head, path); |
349 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { | 382 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
350 | html(delim); | 383 | html(delim); |
351 | html("id="); | 384 | html("id="); |
352 | html_url_arg(new_rev); | 385 | html_url_arg(new_rev); |
353 | delim = "&"; | 386 | delim = "&"; |
354 | } | 387 | } |
355 | if (old_rev) { | 388 | if (old_rev) { |
356 | html(delim); | 389 | html(delim); |
357 | html("id2="); | 390 | html("id2="); |
358 | html_url_arg(old_rev); | 391 | html_url_arg(old_rev); |
392 | delim = "&"; | ||
393 | } | ||
394 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | ||
395 | html(delim); | ||
396 | html("ss=1"); | ||
397 | delim = "&"; | ||
398 | } | ||
399 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | ||
400 | html(delim); | ||
401 | html("context="); | ||
402 | htmlf("%d", ctx.qry.context); | ||
403 | delim = "&"; | ||
404 | } | ||
405 | if (ctx.qry.ignorews) { | ||
406 | html(delim); | ||
407 | html("ignorews=1"); | ||
408 | delim = "&"; | ||
359 | } | 409 | } |
360 | html("'>"); | 410 | html("'>"); |
361 | html_txt(name); | 411 | html_txt(name); |
362 | html("</a>"); | 412 | html("</a>"); |
363 | } | 413 | } |
364 | 414 | ||
365 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 415 | void cgit_patch_link(const char *name, const char *title, const char *class, |
366 | char *rev) | 416 | const char *head, const char *rev, const char *path) |
367 | { | 417 | { |
368 | reporevlink("patch", name, title, class, head, rev, NULL); | 418 | reporevlink("patch", name, title, class, head, rev, path); |
369 | } | 419 | } |
370 | 420 | ||
371 | void cgit_stats_link(char *name, char *title, char *class, char *head, | 421 | void cgit_stats_link(const char *name, const char *title, const char *class, |
372 | char *path) | 422 | const char *head, const char *path) |
373 | { | 423 | { |
374 | reporevlink("stats", name, title, class, head, NULL, path); | 424 | reporevlink("stats", name, title, class, head, NULL, path); |
375 | } | 425 | } |
376 | 426 | ||
427 | void cgit_self_link(char *name, const char *title, const char *class, | ||
428 | struct cgit_context *ctx) | ||
429 | { | ||
430 | if (!strcmp(ctx->qry.page, "repolist")) | ||
431 | return cgit_index_link(name, title, class, ctx->qry.search, | ||
432 | ctx->qry.ofs); | ||
433 | else if (!strcmp(ctx->qry.page, "summary")) | ||
434 | return cgit_summary_link(name, title, class, ctx->qry.head); | ||
435 | else if (!strcmp(ctx->qry.page, "tag")) | ||
436 | return cgit_tag_link(name, title, class, ctx->qry.head, | ||
437 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | ||
438 | else if (!strcmp(ctx->qry.page, "tree")) | ||
439 | return cgit_tree_link(name, title, class, ctx->qry.head, | ||
440 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
441 | ctx->qry.path); | ||
442 | else if (!strcmp(ctx->qry.page, "plain")) | ||
443 | return cgit_plain_link(name, title, class, ctx->qry.head, | ||
444 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
445 | ctx->qry.path); | ||
446 | else if (!strcmp(ctx->qry.page, "log")) | ||
447 | return cgit_log_link(name, title, class, ctx->qry.head, | ||
448 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
449 | ctx->qry.path, ctx->qry.ofs, | ||
450 | ctx->qry.grep, ctx->qry.search, | ||
451 | ctx->qry.showmsg); | ||
452 | else if (!strcmp(ctx->qry.page, "commit")) | ||
453 | return cgit_commit_link(name, title, class, ctx->qry.head, | ||
454 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
455 | ctx->qry.path, 0); | ||
456 | else if (!strcmp(ctx->qry.page, "patch")) | ||
457 | return cgit_patch_link(name, title, class, ctx->qry.head, | ||
458 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
459 | ctx->qry.path); | ||
460 | else if (!strcmp(ctx->qry.page, "refs")) | ||
461 | return cgit_refs_link(name, title, class, ctx->qry.head, | ||
462 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
463 | ctx->qry.path); | ||
464 | else if (!strcmp(ctx->qry.page, "snapshot")) | ||
465 | return cgit_snapshot_link(name, title, class, ctx->qry.head, | ||
466 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
467 | ctx->qry.path); | ||
468 | else if (!strcmp(ctx->qry.page, "diff")) | ||
469 | return cgit_diff_link(name, title, class, ctx->qry.head, | ||
470 | ctx->qry.sha1, ctx->qry.sha2, | ||
471 | ctx->qry.path, 0); | ||
472 | else if (!strcmp(ctx->qry.page, "stats")) | ||
473 | return cgit_stats_link(name, title, class, ctx->qry.head, | ||
474 | ctx->qry.path); | ||
475 | |||
476 | /* Don't known how to make link for this page */ | ||
477 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); | ||
478 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); | ||
479 | html_txt(ctx->qry.page); | ||
480 | html("' -->"); | ||
481 | html_txt(name); | ||
482 | html("</a>"); | ||
483 | } | ||
484 | |||
377 | void cgit_object_link(struct object *obj) | 485 | void cgit_object_link(struct object *obj) |
378 | { | 486 | { |
379 | char *page, *shortrev, *fullrev, *name; | 487 | char *page, *shortrev, *fullrev, *name; |
380 | 488 | ||
381 | fullrev = sha1_to_hex(obj->sha1); | 489 | fullrev = sha1_to_hex(obj->sha1); |
382 | shortrev = xstrdup(fullrev); | 490 | shortrev = xstrdup(fullrev); |
383 | shortrev[10] = '\0'; | 491 | shortrev[10] = '\0'; |
384 | if (obj->type == OBJ_COMMIT) { | 492 | if (obj->type == OBJ_COMMIT) { |
385 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 493 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
386 | ctx.qry.head, fullrev); | 494 | ctx.qry.head, fullrev, NULL, 0); |
387 | return; | 495 | return; |
388 | } else if (obj->type == OBJ_TREE) | 496 | } else if (obj->type == OBJ_TREE) |
389 | page = "tree"; | 497 | page = "tree"; |
390 | else if (obj->type == OBJ_TAG) | 498 | else if (obj->type == OBJ_TAG) |
391 | page = "tag"; | 499 | page = "tag"; |
392 | else | 500 | else |
393 | page = "blob"; | 501 | page = "blob"; |
394 | name = fmt("%s %s...", typename(obj->type), shortrev); | 502 | name = fmt("%s %s...", typename(obj->type), shortrev); |
395 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 503 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
396 | } | 504 | } |
397 | 505 | ||
398 | void cgit_print_date(time_t secs, char *format, int local_time) | 506 | void cgit_print_date(time_t secs, const char *format, int local_time) |
399 | { | 507 | { |
400 | char buf[64]; | 508 | char buf[64]; |
401 | struct tm *time; | 509 | struct tm *time; |
402 | 510 | ||
403 | if (!secs) | 511 | if (!secs) |
404 | return; | 512 | return; |
405 | if(local_time) | 513 | if(local_time) |
406 | time = localtime(&secs); | 514 | time = localtime(&secs); |
407 | else | 515 | else |
408 | time = gmtime(&secs); | 516 | time = gmtime(&secs); |
409 | strftime(buf, sizeof(buf)-1, format, time); | 517 | strftime(buf, sizeof(buf)-1, format, time); |
410 | html_txt(buf); | 518 | html_txt(buf); |
411 | } | 519 | } |
412 | 520 | ||
413 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 521 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
414 | { | 522 | { |
415 | time_t now, secs; | 523 | time_t now, secs; |
416 | 524 | ||
417 | if (!t) | 525 | if (!t) |
418 | return; | 526 | return; |
419 | time(&now); | 527 | time(&now); |
420 | secs = now - t; | 528 | secs = now - t; |
421 | 529 | ||
422 | if (secs > max_relative && max_relative >= 0) { | 530 | if (secs > max_relative && max_relative >= 0) { |
423 | cgit_print_date(t, format, ctx.cfg.local_time); | 531 | cgit_print_date(t, format, ctx.cfg.local_time); |
424 | return; | 532 | return; |
425 | } | 533 | } |
426 | 534 | ||
427 | if (secs < TM_HOUR * 2) { | 535 | if (secs < TM_HOUR * 2) { |
428 | htmlf("<span class='age-mins'>%.0f min.</span>", | 536 | htmlf("<span class='age-mins'>%.0f min.</span>", |
429 | secs * 1.0 / TM_MIN); | 537 | secs * 1.0 / TM_MIN); |
430 | return; | 538 | return; |
431 | } | 539 | } |
432 | if (secs < TM_DAY * 2) { | 540 | if (secs < TM_DAY * 2) { |
433 | htmlf("<span class='age-hours'>%.0f hours</span>", | 541 | htmlf("<span class='age-hours'>%.0f hours</span>", |
434 | secs * 1.0 / TM_HOUR); | 542 | secs * 1.0 / TM_HOUR); |
435 | return; | 543 | return; |
436 | } | 544 | } |
437 | if (secs < TM_WEEK * 2) { | 545 | if (secs < TM_WEEK * 2) { |
438 | htmlf("<span class='age-days'>%.0f days</span>", | 546 | htmlf("<span class='age-days'>%.0f days</span>", |
439 | secs * 1.0 / TM_DAY); | 547 | secs * 1.0 / TM_DAY); |
440 | return; | 548 | return; |
441 | } | 549 | } |
442 | if (secs < TM_MONTH * 2) { | 550 | if (secs < TM_MONTH * 2) { |
443 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 551 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
444 | secs * 1.0 / TM_WEEK); | 552 | secs * 1.0 / TM_WEEK); |
445 | return; | 553 | return; |
446 | } | 554 | } |
447 | if (secs < TM_YEAR * 2) { | 555 | if (secs < TM_YEAR * 2) { |
448 | htmlf("<span class='age-months'>%.0f months</span>", | 556 | htmlf("<span class='age-months'>%.0f months</span>", |
449 | secs * 1.0 / TM_MONTH); | 557 | secs * 1.0 / TM_MONTH); |
450 | return; | 558 | return; |
451 | } | 559 | } |
452 | htmlf("<span class='age-years'>%.0f years</span>", | 560 | htmlf("<span class='age-years'>%.0f years</span>", |
453 | secs * 1.0 / TM_YEAR); | 561 | secs * 1.0 / TM_YEAR); |
454 | } | 562 | } |
455 | 563 | ||
456 | void cgit_print_http_headers(struct cgit_context *ctx) | 564 | void cgit_print_http_headers(struct cgit_context *ctx) |
457 | { | 565 | { |
458 | if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) | 566 | if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) |
459 | return; | 567 | return; |
460 | 568 | ||
461 | if (ctx->page.status) | 569 | if (ctx->page.status) |
@@ -464,310 +572,348 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
464 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 572 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
465 | ctx->page.charset); | 573 | ctx->page.charset); |
466 | else if (ctx->page.mimetype) | 574 | else if (ctx->page.mimetype) |
467 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 575 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
468 | if (ctx->page.size) | 576 | if (ctx->page.size) |
469 | htmlf("Content-Length: %zd\n", ctx->page.size); | 577 | htmlf("Content-Length: %zd\n", ctx->page.size); |
470 | if (ctx->page.filename) | 578 | if (ctx->page.filename) |
471 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 579 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
472 | ctx->page.filename); | 580 | ctx->page.filename); |
473 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 581 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
474 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 582 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
475 | if (ctx->page.etag) | 583 | if (ctx->page.etag) |
476 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | 584 | htmlf("ETag: \"%s\"\n", ctx->page.etag); |
477 | html("\n"); | 585 | html("\n"); |
478 | if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) | 586 | if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) |
479 | exit(0); | 587 | exit(0); |
480 | } | 588 | } |
481 | 589 | ||
482 | void cgit_print_docstart(struct cgit_context *ctx) | 590 | void cgit_print_docstart(struct cgit_context *ctx) |
483 | { | 591 | { |
484 | if (ctx->cfg.embedded) { | 592 | if (ctx->cfg.embedded) { |
485 | if (ctx->cfg.header) | 593 | if (ctx->cfg.header) |
486 | html_include(ctx->cfg.header); | 594 | html_include(ctx->cfg.header); |
487 | return; | 595 | return; |
488 | } | 596 | } |
489 | 597 | ||
490 | char *host = cgit_hosturl(); | 598 | char *host = cgit_hosturl(); |
491 | html(cgit_doctype); | 599 | html(cgit_doctype); |
492 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 600 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
493 | html("<head>\n"); | 601 | html("<head>\n"); |
494 | html("<title>"); | 602 | html("<title>"); |
495 | html_txt(ctx->page.title); | 603 | html_txt(ctx->page.title); |
496 | html("</title>\n"); | 604 | html("</title>\n"); |
497 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 605 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
498 | if (ctx->cfg.robots && *ctx->cfg.robots) | 606 | if (ctx->cfg.robots && *ctx->cfg.robots) |
499 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 607 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
500 | html("<link rel='stylesheet' type='text/css' href='"); | 608 | html("<link rel='stylesheet' type='text/css' href='"); |
501 | html_attr(ctx->cfg.css); | 609 | html_attr(ctx->cfg.css); |
502 | html("'/>\n"); | 610 | html("'/>\n"); |
503 | if (ctx->cfg.favicon) { | 611 | if (ctx->cfg.favicon) { |
504 | html("<link rel='shortcut icon' href='"); | 612 | html("<link rel='shortcut icon' href='"); |
505 | html_attr(ctx->cfg.favicon); | 613 | html_attr(ctx->cfg.favicon); |
506 | html("'/>\n"); | 614 | html("'/>\n"); |
507 | } | 615 | } |
508 | if (host && ctx->repo) { | 616 | if (host && ctx->repo) { |
509 | html("<link rel='alternate' title='Atom feed' href='"); | 617 | html("<link rel='alternate' title='Atom feed' href='"); |
510 | html(cgit_httpscheme()); | 618 | html(cgit_httpscheme()); |
511 | html_attr(cgit_hosturl()); | 619 | html_attr(cgit_hosturl()); |
512 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 620 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, |
513 | fmt("h=%s", ctx->qry.head))); | 621 | fmt("h=%s", ctx->qry.head))); |
514 | html("' type='application/atom+xml'/>\n"); | 622 | html("' type='application/atom+xml'/>\n"); |
515 | } | 623 | } |
516 | if (ctx->cfg.head_include) | 624 | if (ctx->cfg.head_include) |
517 | html_include(ctx->cfg.head_include); | 625 | html_include(ctx->cfg.head_include); |
518 | html("</head>\n"); | 626 | html("</head>\n"); |
519 | html("<body>\n"); | 627 | html("<body>\n"); |
520 | if (ctx->cfg.header) | 628 | if (ctx->cfg.header) |
521 | html_include(ctx->cfg.header); | 629 | html_include(ctx->cfg.header); |
522 | } | 630 | } |
523 | 631 | ||
524 | void cgit_print_docend() | 632 | void cgit_print_docend() |
525 | { | 633 | { |
526 | html("</div> <!-- class=content -->\n"); | 634 | html("</div> <!-- class=content -->\n"); |
527 | if (ctx.cfg.embedded) { | 635 | if (ctx.cfg.embedded) { |
528 | html("</div> <!-- id=cgit -->\n"); | 636 | html("</div> <!-- id=cgit -->\n"); |
529 | if (ctx.cfg.footer) | 637 | if (ctx.cfg.footer) |
530 | html_include(ctx.cfg.footer); | 638 | html_include(ctx.cfg.footer); |
531 | return; | 639 | return; |
532 | } | 640 | } |
533 | if (ctx.cfg.footer) | 641 | if (ctx.cfg.footer) |
534 | html_include(ctx.cfg.footer); | 642 | html_include(ctx.cfg.footer); |
535 | else { | 643 | else { |
536 | htmlf("<div class='footer'>generated by cgit %s at ", | 644 | htmlf("<div class='footer'>generated by cgit %s at ", |
537 | cgit_version); | 645 | cgit_version); |
538 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 646 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
539 | html("</div>\n"); | 647 | html("</div>\n"); |
540 | } | 648 | } |
541 | html("</div> <!-- id=cgit -->\n"); | 649 | html("</div> <!-- id=cgit -->\n"); |
542 | html("</body>\n</html>\n"); | 650 | html("</body>\n</html>\n"); |
543 | } | 651 | } |
544 | 652 | ||
545 | int print_branch_option(const char *refname, const unsigned char *sha1, | 653 | int print_branch_option(const char *refname, const unsigned char *sha1, |
546 | int flags, void *cb_data) | 654 | int flags, void *cb_data) |
547 | { | 655 | { |
548 | char *name = (char *)refname; | 656 | char *name = (char *)refname; |
549 | html_option(name, name, ctx.qry.head); | 657 | html_option(name, name, ctx.qry.head); |
550 | return 0; | 658 | return 0; |
551 | } | 659 | } |
552 | 660 | ||
553 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 661 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
554 | int flags, void *cb_data) | 662 | int flags, void *cb_data) |
555 | { | 663 | { |
556 | struct tag *tag; | 664 | struct tag *tag; |
557 | struct taginfo *info; | 665 | struct taginfo *info; |
558 | struct object *obj; | 666 | struct object *obj; |
559 | char buf[256], *url; | 667 | char buf[256], *url; |
560 | unsigned char fileid[20]; | 668 | unsigned char fileid[20]; |
561 | int *header = (int *)cb_data; | 669 | int *header = (int *)cb_data; |
562 | 670 | ||
563 | if (prefixcmp(refname, "refs/archives")) | 671 | if (prefixcmp(refname, "refs/archives")) |
564 | return 0; | 672 | return 0; |
565 | strncpy(buf, refname+14, sizeof(buf)); | 673 | strncpy(buf, refname+14, sizeof(buf)); |
566 | obj = parse_object(sha1); | 674 | obj = parse_object(sha1); |
567 | if (!obj) | 675 | if (!obj) |
568 | return 1; | 676 | return 1; |
569 | if (obj->type == OBJ_TAG) { | 677 | if (obj->type == OBJ_TAG) { |
570 | tag = lookup_tag(sha1); | 678 | tag = lookup_tag(sha1); |
571 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 679 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
572 | return 0; | 680 | return 0; |
573 | hashcpy(fileid, tag->tagged->sha1); | 681 | hashcpy(fileid, tag->tagged->sha1); |
574 | } else if (obj->type != OBJ_BLOB) { | 682 | } else if (obj->type != OBJ_BLOB) { |
575 | return 0; | 683 | return 0; |
576 | } else { | 684 | } else { |
577 | hashcpy(fileid, sha1); | 685 | hashcpy(fileid, sha1); |
578 | } | 686 | } |
579 | if (!*header) { | 687 | if (!*header) { |
580 | html("<h1>download</h1>\n"); | 688 | html("<h1>download</h1>\n"); |
581 | *header = 1; | 689 | *header = 1; |
582 | } | 690 | } |
583 | url = cgit_pageurl(ctx.qry.repo, "blob", | 691 | url = cgit_pageurl(ctx.qry.repo, "blob", |
584 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 692 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
585 | buf)); | 693 | buf)); |
586 | html_link_open(url, NULL, "menu"); | 694 | html_link_open(url, NULL, "menu"); |
587 | html_txt(strlpart(buf, 20)); | 695 | html_txt(strlpart(buf, 20)); |
588 | html_link_close(); | 696 | html_link_close(); |
589 | return 0; | 697 | return 0; |
590 | } | 698 | } |
591 | 699 | ||
592 | void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) | 700 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
701 | const char *page) | ||
593 | { | 702 | { |
594 | char *url; | 703 | char *url; |
595 | 704 | ||
596 | if (!ctx.cfg.virtual_root) { | 705 | if (!ctx.cfg.virtual_root) { |
597 | url = fmt("%s/%s", ctx.qry.repo, page); | 706 | url = fmt("%s/%s", ctx.qry.repo, page); |
598 | if (ctx.qry.path) | 707 | if (ctx.qry.vpath) |
599 | url = fmt("%s/%s", url, ctx.qry.path); | 708 | url = fmt("%s/%s", url, ctx.qry.vpath); |
600 | html_hidden("url", url); | 709 | html_hidden("url", url); |
601 | } | 710 | } |
602 | 711 | ||
603 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 712 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
604 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 713 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
605 | html_hidden("h", ctx.qry.head); | 714 | html_hidden("h", ctx.qry.head); |
606 | 715 | ||
607 | if (ctx.qry.sha1) | 716 | if (ctx.qry.sha1) |
608 | html_hidden("id", ctx.qry.sha1); | 717 | html_hidden("id", ctx.qry.sha1); |
609 | if (ctx.qry.sha2) | 718 | if (ctx.qry.sha2) |
610 | html_hidden("id2", ctx.qry.sha2); | 719 | html_hidden("id2", ctx.qry.sha2); |
611 | if (ctx.qry.showmsg) | 720 | if (ctx.qry.showmsg) |
612 | html_hidden("showmsg", "1"); | 721 | html_hidden("showmsg", "1"); |
613 | 722 | ||
614 | if (incl_search) { | 723 | if (incl_search) { |
615 | if (ctx.qry.grep) | 724 | if (ctx.qry.grep) |
616 | html_hidden("qt", ctx.qry.grep); | 725 | html_hidden("qt", ctx.qry.grep); |
617 | if (ctx.qry.search) | 726 | if (ctx.qry.search) |
618 | html_hidden("q", ctx.qry.search); | 727 | html_hidden("q", ctx.qry.search); |
619 | } | 728 | } |
620 | } | 729 | } |
621 | 730 | ||
622 | const char *fallback_cmd = "repolist"; | 731 | static const char *hc(struct cgit_context *ctx, const char *page) |
732 | { | ||
733 | return strcmp(ctx->qry.page, page) ? NULL : "active"; | ||
734 | } | ||
623 | 735 | ||
624 | char *hc(struct cgit_cmd *cmd, const char *page) | 736 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) |
625 | { | 737 | { |
626 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); | 738 | char *old_path = ctx->qry.path; |
739 | char *p = path, *q, *end = path + strlen(path); | ||
740 | |||
741 | ctx->qry.path = NULL; | ||
742 | cgit_self_link("root", NULL, NULL, ctx); | ||
743 | ctx->qry.path = p = path; | ||
744 | while (p < end) { | ||
745 | if (!(q = strchr(p, '/'))) | ||
746 | q = end; | ||
747 | *q = '\0'; | ||
748 | html_txt("/"); | ||
749 | cgit_self_link(p, NULL, NULL, ctx); | ||
750 | if (q < end) | ||
751 | *q = '/'; | ||
752 | p = q + 1; | ||
753 | } | ||
754 | ctx->qry.path = old_path; | ||
627 | } | 755 | } |
628 | 756 | ||
629 | static void print_header(struct cgit_context *ctx) | 757 | static void print_header(struct cgit_context *ctx) |
630 | { | 758 | { |
759 | char *logo = NULL, *logo_link = NULL; | ||
760 | |||
631 | html("<table id='header'>\n"); | 761 | html("<table id='header'>\n"); |
632 | html("<tr>\n"); | 762 | html("<tr>\n"); |
633 | 763 | ||
634 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { | 764 | if (ctx->repo && ctx->repo->logo && *ctx->repo->logo) |
765 | logo = ctx->repo->logo; | ||
766 | else | ||
767 | logo = ctx->cfg.logo; | ||
768 | if (ctx->repo && ctx->repo->logo_link && *ctx->repo->logo_link) | ||
769 | logo_link = ctx->repo->logo_link; | ||
770 | else | ||
771 | logo_link = ctx->cfg.logo_link; | ||
772 | if (logo && *logo) { | ||
635 | html("<td class='logo' rowspan='2'><a href='"); | 773 | html("<td class='logo' rowspan='2'><a href='"); |
636 | if (ctx->cfg.logo_link) | 774 | if (logo_link && *logo_link) |
637 | html_attr(ctx->cfg.logo_link); | 775 | html_attr(logo_link); |
638 | else | 776 | else |
639 | html_attr(cgit_rooturl()); | 777 | html_attr(cgit_rooturl()); |
640 | html("'><img src='"); | 778 | html("'><img src='"); |
641 | html_attr(ctx->cfg.logo); | 779 | html_attr(logo); |
642 | html("' alt='cgit logo'/></a></td>\n"); | 780 | html("' alt='cgit logo'/></a></td>\n"); |
643 | } | 781 | } |
644 | 782 | ||
645 | html("<td class='main'>"); | 783 | html("<td class='main'>"); |
646 | if (ctx->repo) { | 784 | if (ctx->repo) { |
647 | cgit_index_link("index", NULL, NULL, NULL, 0); | 785 | cgit_index_link("index", NULL, NULL, NULL, 0); |
648 | html(" : "); | 786 | html(" : "); |
649 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 787 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
650 | html("</td><td class='form'>"); | 788 | html("</td><td class='form'>"); |
651 | html("<form method='get' action=''>\n"); | 789 | html("<form method='get' action=''>\n"); |
652 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); | 790 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); |
653 | html("<select name='h' onchange='this.form.submit();'>\n"); | 791 | html("<select name='h' onchange='this.form.submit();'>\n"); |
654 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 792 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
655 | html("</select> "); | 793 | html("</select> "); |
656 | html("<input type='submit' name='' value='switch'/>"); | 794 | html("<input type='submit' name='' value='switch'/>"); |
657 | html("</form>"); | 795 | html("</form>"); |
658 | } else | 796 | } else |
659 | html_txt(ctx->cfg.root_title); | 797 | html_txt(ctx->cfg.root_title); |
660 | html("</td></tr>\n"); | 798 | html("</td></tr>\n"); |
661 | 799 | ||
662 | html("<tr><td class='sub'>"); | 800 | html("<tr><td class='sub'>"); |
663 | if (ctx->repo) { | 801 | if (ctx->repo) { |
664 | html_txt(ctx->repo->desc); | 802 | html_txt(ctx->repo->desc); |
665 | html("</td><td class='sub right'>"); | 803 | html("</td><td class='sub right'>"); |
666 | html_txt(ctx->repo->owner); | 804 | html_txt(ctx->repo->owner); |
667 | } else { | 805 | } else { |
668 | if (ctx->cfg.root_desc) | 806 | if (ctx->cfg.root_desc) |
669 | html_txt(ctx->cfg.root_desc); | 807 | html_txt(ctx->cfg.root_desc); |
670 | else if (ctx->cfg.index_info) | 808 | else if (ctx->cfg.index_info) |
671 | html_include(ctx->cfg.index_info); | 809 | html_include(ctx->cfg.index_info); |
672 | } | 810 | } |
673 | html("</td></tr></table>\n"); | 811 | html("</td></tr></table>\n"); |
674 | } | 812 | } |
675 | 813 | ||
676 | void cgit_print_pageheader(struct cgit_context *ctx) | 814 | void cgit_print_pageheader(struct cgit_context *ctx) |
677 | { | 815 | { |
678 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | ||
679 | |||
680 | if (!cmd && ctx->repo) | ||
681 | fallback_cmd = "summary"; | ||
682 | |||
683 | html("<div id='cgit'>"); | 816 | html("<div id='cgit'>"); |
684 | if (!ctx->cfg.noheader) | 817 | if (!ctx->cfg.noheader) |
685 | print_header(ctx); | 818 | print_header(ctx); |
686 | 819 | ||
687 | html("<table class='tabs'><tr><td>\n"); | 820 | html("<table class='tabs'><tr><td>\n"); |
688 | if (ctx->repo) { | 821 | if (ctx->repo) { |
689 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 822 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), |
690 | ctx->qry.head); | 823 | ctx->qry.head); |
691 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 824 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, |
692 | ctx->qry.sha1, NULL); | 825 | ctx->qry.sha1, NULL); |
693 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 826 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, |
694 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); | 827 | NULL, ctx->qry.vpath, 0, NULL, NULL, |
695 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 828 | ctx->qry.showmsg); |
696 | ctx->qry.sha1, NULL); | 829 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, |
697 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 830 | ctx->qry.sha1, ctx->qry.vpath); |
698 | ctx->qry.head, ctx->qry.sha1); | 831 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), |
699 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 832 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); |
700 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 833 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, |
834 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); | ||
701 | if (ctx->repo->max_stats) | 835 | if (ctx->repo->max_stats) |
702 | cgit_stats_link("stats", NULL, hc(cmd, "stats"), | 836 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), |
703 | ctx->qry.head, NULL); | 837 | ctx->qry.head, ctx->qry.vpath); |
704 | if (ctx->repo->readme) | 838 | if (ctx->repo->readme) |
705 | reporevlink("about", "about", NULL, | 839 | reporevlink("about", "about", NULL, |
706 | hc(cmd, "about"), ctx->qry.head, NULL, | 840 | hc(ctx, "about"), ctx->qry.head, NULL, |
707 | NULL); | 841 | NULL); |
708 | html("</td><td class='form'>"); | 842 | html("</td><td class='form'>"); |
709 | html("<form class='right' method='get' action='"); | 843 | html("<form class='right' method='get' action='"); |
710 | if (ctx->cfg.virtual_root) | 844 | if (ctx->cfg.virtual_root) |
711 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 845 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
712 | ctx->qry.path, NULL)); | 846 | ctx->qry.vpath, NULL)); |
713 | html("'>\n"); | 847 | html("'>\n"); |
714 | cgit_add_hidden_formfields(1, 0, "log"); | 848 | cgit_add_hidden_formfields(1, 0, "log"); |
715 | html("<select name='qt'>\n"); | 849 | html("<select name='qt'>\n"); |
716 | html_option("grep", "log msg", ctx->qry.grep); | 850 | html_option("grep", "log msg", ctx->qry.grep); |
717 | html_option("author", "author", ctx->qry.grep); | 851 | html_option("author", "author", ctx->qry.grep); |
718 | html_option("committer", "committer", ctx->qry.grep); | 852 | html_option("committer", "committer", ctx->qry.grep); |
853 | html_option("range", "range", ctx->qry.grep); | ||
719 | html("</select>\n"); | 854 | html("</select>\n"); |
720 | html("<input class='txt' type='text' size='10' name='q' value='"); | 855 | html("<input class='txt' type='text' size='10' name='q' value='"); |
721 | html_attr(ctx->qry.search); | 856 | html_attr(ctx->qry.search); |
722 | html("'/>\n"); | 857 | html("'/>\n"); |
723 | html("<input type='submit' value='search'/>\n"); | 858 | html("<input type='submit' value='search'/>\n"); |
724 | html("</form>\n"); | 859 | html("</form>\n"); |
725 | } else { | 860 | } else { |
726 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); | 861 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); |
727 | if (ctx->cfg.root_readme) | 862 | if (ctx->cfg.root_readme) |
728 | site_link("about", "about", NULL, hc(cmd, "about"), | 863 | site_link("about", "about", NULL, hc(ctx, "about"), |
729 | NULL, 0); | 864 | NULL, 0); |
730 | html("</td><td class='form'>"); | 865 | html("</td><td class='form'>"); |
731 | html("<form method='get' action='"); | 866 | html("<form method='get' action='"); |
732 | html_attr(cgit_rooturl()); | 867 | html_attr(cgit_rooturl()); |
733 | html("'>\n"); | 868 | html("'>\n"); |
734 | html("<input type='text' name='q' size='10' value='"); | 869 | html("<input type='text' name='q' size='10' value='"); |
735 | html_attr(ctx->qry.search); | 870 | html_attr(ctx->qry.search); |
736 | html("'/>\n"); | 871 | html("'/>\n"); |
737 | html("<input type='submit' value='search'/>\n"); | 872 | html("<input type='submit' value='search'/>\n"); |
738 | html("</form>"); | 873 | html("</form>"); |
739 | } | 874 | } |
740 | html("</td></tr></table>\n"); | 875 | html("</td></tr></table>\n"); |
876 | if (ctx->qry.vpath) { | ||
877 | html("<div class='path'>"); | ||
878 | html("path: "); | ||
879 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); | ||
880 | html("</div>"); | ||
881 | } | ||
741 | html("<div class='content'>"); | 882 | html("<div class='content'>"); |
742 | } | 883 | } |
743 | 884 | ||
744 | void cgit_print_filemode(unsigned short mode) | 885 | void cgit_print_filemode(unsigned short mode) |
745 | { | 886 | { |
746 | if (S_ISDIR(mode)) | 887 | if (S_ISDIR(mode)) |
747 | html("d"); | 888 | html("d"); |
748 | else if (S_ISLNK(mode)) | 889 | else if (S_ISLNK(mode)) |
749 | html("l"); | 890 | html("l"); |
750 | else if (S_ISGITLINK(mode)) | 891 | else if (S_ISGITLINK(mode)) |
751 | html("m"); | 892 | html("m"); |
752 | else | 893 | else |
753 | html("-"); | 894 | html("-"); |
754 | html_fileperm(mode >> 6); | 895 | html_fileperm(mode >> 6); |
755 | html_fileperm(mode >> 3); | 896 | html_fileperm(mode >> 3); |
756 | html_fileperm(mode); | 897 | html_fileperm(mode); |
757 | } | 898 | } |
758 | 899 | ||
759 | void cgit_print_snapshot_links(const char *repo, const char *head, | 900 | void cgit_print_snapshot_links(const char *repo, const char *head, |
760 | const char *hex, int snapshots) | 901 | const char *hex, int snapshots) |
761 | { | 902 | { |
762 | const struct cgit_snapshot_format* f; | 903 | const struct cgit_snapshot_format* f; |
904 | char *prefix; | ||
763 | char *filename; | 905 | char *filename; |
906 | unsigned char sha1[20]; | ||
764 | 907 | ||
908 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && | ||
909 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) | ||
910 | hex++; | ||
911 | prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); | ||
765 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 912 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
766 | if (!(snapshots & f->bit)) | 913 | if (!(snapshots & f->bit)) |
767 | continue; | 914 | continue; |
768 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 915 | filename = fmt("%s%s", prefix, f->suffix); |
769 | f->suffix); | ||
770 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); | 916 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); |
771 | html("<br/>"); | 917 | html("<br/>"); |
772 | } | 918 | } |
773 | } | 919 | } |
diff --git a/ui-shared.h b/ui-shared.h index b12aa89..3cc1258 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -1,51 +1,66 @@ | |||
1 | #ifndef UI_SHARED_H | 1 | #ifndef UI_SHARED_H |
2 | #define UI_SHARED_H | 2 | #define UI_SHARED_H |
3 | 3 | ||
4 | extern char *cgit_httpscheme(); | 4 | extern char *cgit_httpscheme(); |
5 | extern char *cgit_hosturl(); | 5 | extern char *cgit_hosturl(); |
6 | extern char *cgit_rooturl(); | 6 | extern char *cgit_rooturl(); |
7 | extern char *cgit_repourl(const char *reponame); | 7 | extern char *cgit_repourl(const char *reponame); |
8 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 8 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
9 | const char *filename, const char *query); | 9 | const char *filename, const char *query); |
10 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 10 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
11 | const char *query); | 11 | const char *query); |
12 | 12 | ||
13 | extern void cgit_index_link(char *name, char *title, char *class, | 13 | extern void cgit_index_link(const char *name, const char *title, |
14 | char *pattern, int ofs); | 14 | const char *class, const char *pattern, int ofs); |
15 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); | 15 | extern void cgit_summary_link(const char *name, const char *title, |
16 | extern void cgit_tag_link(char *name, char *title, char *class, char *head, | 16 | const char *class, const char *head); |
17 | char *rev); | 17 | extern void cgit_tag_link(const char *name, const char *title, |
18 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 18 | const char *class, const char *head, |
19 | char *rev, char *path); | 19 | const char *rev); |
20 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, | 20 | extern void cgit_tree_link(const char *name, const char *title, |
21 | char *rev, char *path); | 21 | const char *class, const char *head, |
22 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 22 | const char *rev, const char *path); |
23 | char *rev, char *path, int ofs, char *grep, | 23 | extern void cgit_plain_link(const char *name, const char *title, |
24 | char *pattern, int showmsg); | 24 | const char *class, const char *head, |
25 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 25 | const char *rev, const char *path); |
26 | char *rev); | 26 | extern void cgit_log_link(const char *name, const char *title, |
27 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, | 27 | const char *class, const char *head, const char *rev, |
28 | char *rev); | 28 | const char *path, int ofs, const char *grep, |
29 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | 29 | const char *pattern, int showmsg); |
30 | char *rev, char *path); | 30 | extern void cgit_commit_link(char *name, const char *title, |
31 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 31 | const char *class, const char *head, |
32 | char *head, char *rev, char *archivename); | 32 | const char *rev, const char *path, |
33 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 33 | int toggle_ssdiff); |
34 | char *new_rev, char *old_rev, char *path); | 34 | extern void cgit_patch_link(const char *name, const char *title, |
35 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, | 35 | const char *class, const char *head, |
36 | char *path); | 36 | const char *rev, const char *path); |
37 | extern void cgit_refs_link(const char *name, const char *title, | ||
38 | const char *class, const char *head, | ||
39 | const char *rev, const char *path); | ||
40 | extern void cgit_snapshot_link(const char *name, const char *title, | ||
41 | const char *class, const char *head, | ||
42 | const char *rev, const char *archivename); | ||
43 | extern void cgit_diff_link(const char *name, const char *title, | ||
44 | const char *class, const char *head, | ||
45 | const char *new_rev, const char *old_rev, | ||
46 | const char *path, int toggle_ssdiff); | ||
47 | extern void cgit_stats_link(const char *name, const char *title, | ||
48 | const char *class, const char *head, | ||
49 | const char *path); | ||
50 | extern void cgit_self_link(char *name, const char *title, | ||
51 | const char *class, struct cgit_context *ctx); | ||
37 | extern void cgit_object_link(struct object *obj); | 52 | extern void cgit_object_link(struct object *obj); |
38 | 53 | ||
39 | extern void cgit_print_error(char *msg); | 54 | extern void cgit_print_error(const char *msg); |
40 | extern void cgit_print_date(time_t secs, char *format, int local_time); | 55 | extern void cgit_print_date(time_t secs, const char *format, int local_time); |
41 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 56 | extern void cgit_print_age(time_t t, time_t max_relative, const char *format); |
42 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 57 | extern void cgit_print_http_headers(struct cgit_context *ctx); |
43 | extern void cgit_print_docstart(struct cgit_context *ctx); | 58 | extern void cgit_print_docstart(struct cgit_context *ctx); |
44 | extern void cgit_print_docend(); | 59 | extern void cgit_print_docend(); |
45 | extern void cgit_print_pageheader(struct cgit_context *ctx); | 60 | extern void cgit_print_pageheader(struct cgit_context *ctx); |
46 | extern void cgit_print_filemode(unsigned short mode); | 61 | extern void cgit_print_filemode(unsigned short mode); |
47 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 62 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
48 | const char *hex, int snapshots); | 63 | const char *hex, int snapshots); |
49 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, | 64 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, |
50 | char *page); | 65 | const char *page); |
51 | #endif /* UI_SHARED_H */ | 66 | #endif /* UI_SHARED_H */ |
diff --git a/ui-snapshot.c b/ui-snapshot.c index dbb5564..6e3412c 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -1,90 +1,96 @@ | |||
1 | /* ui-snapshot.c: generate snapshot of a commit | 1 | /* ui-snapshot.c: generate snapshot of a commit |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | static int write_compressed_tar_archive(struct archiver_args *args,const char *filter) | 13 | static int write_compressed_tar_archive(struct archiver_args *args,const char *filter) |
14 | { | 14 | { |
15 | int rv; | 15 | int rv; |
16 | struct cgit_filter f; | 16 | struct cgit_filter f; |
17 | 17 | ||
18 | f.cmd = xstrdup(filter); | 18 | f.cmd = xstrdup(filter); |
19 | f.argv = malloc(2 * sizeof(char *)); | 19 | f.argv = malloc(2 * sizeof(char *)); |
20 | f.argv[0] = f.cmd; | 20 | f.argv[0] = f.cmd; |
21 | f.argv[1] = NULL; | 21 | f.argv[1] = NULL; |
22 | cgit_open_filter(&f); | 22 | cgit_open_filter(&f); |
23 | rv = write_tar_archive(args); | 23 | rv = write_tar_archive(args); |
24 | cgit_close_filter(&f); | 24 | cgit_close_filter(&f); |
25 | return rv; | 25 | return rv; |
26 | } | 26 | } |
27 | 27 | ||
28 | static int write_tar_gzip_archive(struct archiver_args *args) | 28 | static int write_tar_gzip_archive(struct archiver_args *args) |
29 | { | 29 | { |
30 | return write_compressed_tar_archive(args,"gzip"); | 30 | return write_compressed_tar_archive(args,"gzip"); |
31 | } | 31 | } |
32 | 32 | ||
33 | static int write_tar_bzip2_archive(struct archiver_args *args) | 33 | static int write_tar_bzip2_archive(struct archiver_args *args) |
34 | { | 34 | { |
35 | return write_compressed_tar_archive(args,"bzip2"); | 35 | return write_compressed_tar_archive(args,"bzip2"); |
36 | } | 36 | } |
37 | 37 | ||
38 | static int write_tar_xz_archive(struct archiver_args *args) | ||
39 | { | ||
40 | return write_compressed_tar_archive(args,"xz"); | ||
41 | } | ||
42 | |||
38 | const struct cgit_snapshot_format cgit_snapshot_formats[] = { | 43 | const struct cgit_snapshot_format cgit_snapshot_formats[] = { |
39 | { ".zip", "application/x-zip", write_zip_archive, 0x1 }, | 44 | { ".zip", "application/x-zip", write_zip_archive, 0x01 }, |
40 | { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x2 }, | 45 | { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 }, |
41 | { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x4 }, | 46 | { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 }, |
42 | { ".tar", "application/x-tar", write_tar_archive, 0x8 }, | 47 | { ".tar", "application/x-tar", write_tar_archive, 0x08 }, |
48 | { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 }, | ||
43 | {} | 49 | {} |
44 | }; | 50 | }; |
45 | 51 | ||
46 | static const struct cgit_snapshot_format *get_format(const char *filename) | 52 | static const struct cgit_snapshot_format *get_format(const char *filename) |
47 | { | 53 | { |
48 | const struct cgit_snapshot_format *fmt; | 54 | const struct cgit_snapshot_format *fmt; |
49 | int fl, sl; | 55 | int fl, sl; |
50 | 56 | ||
51 | fl = strlen(filename); | 57 | fl = strlen(filename); |
52 | for(fmt = cgit_snapshot_formats; fmt->suffix; fmt++) { | 58 | for(fmt = cgit_snapshot_formats; fmt->suffix; fmt++) { |
53 | sl = strlen(fmt->suffix); | 59 | sl = strlen(fmt->suffix); |
54 | if (sl >= fl) | 60 | if (sl >= fl) |
55 | continue; | 61 | continue; |
56 | if (!strcmp(fmt->suffix, filename + fl - sl)) | 62 | if (!strcmp(fmt->suffix, filename + fl - sl)) |
57 | return fmt; | 63 | return fmt; |
58 | } | 64 | } |
59 | return NULL; | 65 | return NULL; |
60 | } | 66 | } |
61 | 67 | ||
62 | static int make_snapshot(const struct cgit_snapshot_format *format, | 68 | static int make_snapshot(const struct cgit_snapshot_format *format, |
63 | const char *hex, const char *prefix, | 69 | const char *hex, const char *prefix, |
64 | const char *filename) | 70 | const char *filename) |
65 | { | 71 | { |
66 | struct archiver_args args; | 72 | struct archiver_args args; |
67 | struct commit *commit; | 73 | struct commit *commit; |
68 | unsigned char sha1[20]; | 74 | unsigned char sha1[20]; |
69 | 75 | ||
70 | if(get_sha1(hex, sha1)) { | 76 | if(get_sha1(hex, sha1)) { |
71 | cgit_print_error(fmt("Bad object id: %s", hex)); | 77 | cgit_print_error(fmt("Bad object id: %s", hex)); |
72 | return 1; | 78 | return 1; |
73 | } | 79 | } |
74 | commit = lookup_commit_reference(sha1); | 80 | commit = lookup_commit_reference(sha1); |
75 | if(!commit) { | 81 | if(!commit) { |
76 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 82 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
77 | return 1; | 83 | return 1; |
78 | } | 84 | } |
79 | memset(&args, 0, sizeof(args)); | 85 | memset(&args, 0, sizeof(args)); |
80 | if (prefix) { | 86 | if (prefix) { |
81 | args.base = fmt("%s/", prefix); | 87 | args.base = fmt("%s/", prefix); |
82 | args.baselen = strlen(prefix) + 1; | 88 | args.baselen = strlen(prefix) + 1; |
83 | } else { | 89 | } else { |
84 | args.base = ""; | 90 | args.base = ""; |
85 | args.baselen = 0; | 91 | args.baselen = 0; |
86 | } | 92 | } |
87 | args.tree = commit->tree; | 93 | args.tree = commit->tree; |
88 | args.time = commit->date; | 94 | args.time = commit->date; |
89 | args.compression_level = Z_DEFAULT_COMPRESSION; | 95 | args.compression_level = Z_DEFAULT_COMPRESSION; |
90 | ctx.page.mimetype = xstrdup(format->mimetype); | 96 | ctx.page.mimetype = xstrdup(format->mimetype); |
diff --git a/ui-ssdiff.c b/ui-ssdiff.c new file mode 100644 index 0000000..2481585 --- a/dev/null +++ b/ui-ssdiff.c | |||
@@ -0,0 +1,383 @@ | |||
1 | #include "cgit.h" | ||
2 | #include "html.h" | ||
3 | #include "ui-shared.h" | ||
4 | #include "ui-diff.h" | ||
5 | |||
6 | extern int use_ssdiff; | ||
7 | |||
8 | static int current_old_line, current_new_line; | ||
9 | |||
10 | struct deferred_lines { | ||
11 | int line_no; | ||
12 | char *line; | ||
13 | struct deferred_lines *next; | ||
14 | }; | ||
15 | |||
16 | static struct deferred_lines *deferred_old, *deferred_old_last; | ||
17 | static struct deferred_lines *deferred_new, *deferred_new_last; | ||
18 | |||
19 | static char *longest_common_subsequence(char *A, char *B) | ||
20 | { | ||
21 | int i, j, ri; | ||
22 | int m = strlen(A); | ||
23 | int n = strlen(B); | ||
24 | int L[m + 1][n + 1]; | ||
25 | int tmp1, tmp2; | ||
26 | int lcs_length; | ||
27 | char *result; | ||
28 | |||
29 | for (i = m; i >= 0; i--) { | ||
30 | for (j = n; j >= 0; j--) { | ||
31 | if (A[i] == '\0' || B[j] == '\0') { | ||
32 | L[i][j] = 0; | ||
33 | } else if (A[i] == B[j]) { | ||
34 | L[i][j] = 1 + L[i + 1][j + 1]; | ||
35 | } else { | ||
36 | tmp1 = L[i + 1][j]; | ||
37 | tmp2 = L[i][j + 1]; | ||
38 | L[i][j] = (tmp1 > tmp2 ? tmp1 : tmp2); | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | lcs_length = L[0][0]; | ||
44 | result = xmalloc(lcs_length + 2); | ||
45 | memset(result, 0, sizeof(*result) * (lcs_length + 2)); | ||
46 | |||
47 | ri = 0; | ||
48 | i = 0; | ||
49 | j = 0; | ||
50 | while (i < m && j < n) { | ||
51 | if (A[i] == B[j]) { | ||
52 | result[ri] = A[i]; | ||
53 | ri += 1; | ||
54 | i += 1; | ||
55 | j += 1; | ||
56 | } else if (L[i + 1][j] >= L[i][j + 1]) { | ||
57 | i += 1; | ||
58 | } else { | ||
59 | j += 1; | ||
60 | } | ||
61 | } | ||
62 | return result; | ||
63 | } | ||
64 | |||
65 | static int line_from_hunk(char *line, char type) | ||
66 | { | ||
67 | char *buf1, *buf2; | ||
68 | int len; | ||
69 | |||
70 | buf1 = strchr(line, type); | ||
71 | if (buf1 == NULL) | ||
72 | return 0; | ||
73 | buf1 += 1; | ||
74 | buf2 = strchr(buf1, ','); | ||
75 | if (buf2 == NULL) | ||
76 | return 0; | ||
77 | len = buf2 - buf1; | ||
78 | buf2 = xmalloc(len + 1); | ||
79 | strncpy(buf2, buf1, len); | ||
80 | buf2[len] = '\0'; | ||
81 | int res = atoi(buf2); | ||
82 | free(buf2); | ||
83 | return res; | ||
84 | } | ||
85 | |||
86 | static char *replace_tabs(char *line) | ||
87 | { | ||
88 | char *prev_buf = line; | ||
89 | char *cur_buf; | ||
90 | int linelen = strlen(line); | ||
91 | int n_tabs = 0; | ||
92 | int i; | ||
93 | char *result; | ||
94 | char *spaces = " "; | ||
95 | |||
96 | if (linelen == 0) { | ||
97 | result = xmalloc(1); | ||
98 | result[0] = '\0'; | ||
99 | return result; | ||
100 | } | ||
101 | |||
102 | for (i = 0; i < linelen; i++) | ||
103 | if (line[i] == '\t') | ||
104 | n_tabs += 1; | ||
105 | result = xmalloc(linelen + n_tabs * 8 + 1); | ||
106 | result[0] = '\0'; | ||
107 | |||
108 | while (1) { | ||
109 | cur_buf = strchr(prev_buf, '\t'); | ||
110 | if (!cur_buf) { | ||
111 | strcat(result, prev_buf); | ||
112 | break; | ||
113 | } else { | ||
114 | strcat(result, " "); | ||
115 | strncat(result, spaces, 8 - (strlen(result) % 8)); | ||
116 | strncat(result, prev_buf, cur_buf - prev_buf); | ||
117 | } | ||
118 | prev_buf = cur_buf + 1; | ||
119 | } | ||
120 | return result; | ||
121 | } | ||
122 | |||
123 | static int calc_deferred_lines(struct deferred_lines *start) | ||
124 | { | ||
125 | struct deferred_lines *item = start; | ||
126 | int result = 0; | ||
127 | while (item) { | ||
128 | result += 1; | ||
129 | item = item->next; | ||
130 | } | ||
131 | return result; | ||
132 | } | ||
133 | |||
134 | static void deferred_old_add(char *line, int line_no) | ||
135 | { | ||
136 | struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines)); | ||
137 | item->line = xstrdup(line); | ||
138 | item->line_no = line_no; | ||
139 | item->next = NULL; | ||
140 | if (deferred_old) { | ||
141 | deferred_old_last->next = item; | ||
142 | deferred_old_last = item; | ||
143 | } else { | ||
144 | deferred_old = deferred_old_last = item; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | static void deferred_new_add(char *line, int line_no) | ||
149 | { | ||
150 | struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines)); | ||
151 | item->line = xstrdup(line); | ||
152 | item->line_no = line_no; | ||
153 | item->next = NULL; | ||
154 | if (deferred_new) { | ||
155 | deferred_new_last->next = item; | ||
156 | deferred_new_last = item; | ||
157 | } else { | ||
158 | deferred_new = deferred_new_last = item; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static void print_part_with_lcs(char *class, char *line, char *lcs) | ||
163 | { | ||
164 | int line_len = strlen(line); | ||
165 | int i, j; | ||
166 | char c[2] = " "; | ||
167 | int same = 1; | ||
168 | |||
169 | j = 0; | ||
170 | for (i = 0; i < line_len; i++) { | ||
171 | c[0] = line[i]; | ||
172 | if (same) { | ||
173 | if (line[i] == lcs[j]) | ||
174 | j += 1; | ||
175 | else { | ||
176 | same = 0; | ||
177 | htmlf("<span class='%s'>", class); | ||
178 | } | ||
179 | } else if (line[i] == lcs[j]) { | ||
180 | same = 1; | ||
181 | htmlf("</span>"); | ||
182 | j += 1; | ||
183 | } | ||
184 | html_txt(c); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | static void print_ssdiff_line(char *class, | ||
189 | int old_line_no, | ||
190 | char *old_line, | ||
191 | int new_line_no, | ||
192 | char *new_line, int individual_chars) | ||
193 | { | ||
194 | char *lcs = NULL; | ||
195 | |||
196 | if (old_line) | ||
197 | old_line = replace_tabs(old_line + 1); | ||
198 | if (new_line) | ||
199 | new_line = replace_tabs(new_line + 1); | ||
200 | if (individual_chars && old_line && new_line) | ||
201 | lcs = longest_common_subsequence(old_line, new_line); | ||
202 | html("<tr>\n"); | ||
203 | if (old_line_no > 0) { | ||
204 | struct diff_filespec *old_file = cgit_get_current_old_file(); | ||
205 | char *lineno_str = fmt("n%d", old_line_no); | ||
206 | char *id_str = fmt("%s#%s", is_null_sha1(old_file->sha1)?"HEAD":sha1_to_hex(old_rev_sha1), lineno_str); | ||
207 | html("<td class='lineno'><a class='no' href='"); | ||
208 | html(cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str)); | ||
209 | htmlf("' id='%s' name='%s'>%s</a>", lineno_str, lineno_str, lineno_str + 1); | ||
210 | html("</td>"); | ||
211 | htmlf("<td class='%s'>", class); | ||
212 | } else if (old_line) | ||
213 | htmlf("<td class='lineno'></td><td class='%s'>", class); | ||
214 | else | ||
215 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); | ||
216 | if (old_line) { | ||
217 | if (lcs) | ||
218 | print_part_with_lcs("del", old_line, lcs); | ||
219 | else | ||
220 | html_txt(old_line); | ||
221 | } | ||
222 | |||
223 | html("</td>\n"); | ||
224 | if (new_line_no > 0) { | ||
225 | struct diff_filespec *new_file = cgit_get_current_new_file(); | ||
226 | char *lineno_str = fmt("n%d", new_line_no); | ||
227 | char *id_str = fmt("%s#%s", is_null_sha1(new_file->sha1)?"HEAD":sha1_to_hex(new_rev_sha1), lineno_str); | ||
228 | html("<td class='lineno'><a class='no' href='"); | ||
229 | html(cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str)); | ||
230 | htmlf("' id='%s' name='%s'>%s</a>", lineno_str, lineno_str, lineno_str + 1); | ||
231 | html("</td>"); | ||
232 | htmlf("<td class='%s'>", class); | ||
233 | } else if (new_line) | ||
234 | htmlf("<td class='lineno'></td><td class='%s'>", class); | ||
235 | else | ||
236 | htmlf("<td class='lineno'></td><td class='%s_dark'>", class); | ||
237 | if (new_line) { | ||
238 | if (lcs) | ||
239 | print_part_with_lcs("add", new_line, lcs); | ||
240 | else | ||
241 | html_txt(new_line); | ||
242 | } | ||
243 | |||
244 | html("</td></tr>"); | ||
245 | if (lcs) | ||
246 | free(lcs); | ||
247 | if (new_line) | ||
248 | free(new_line); | ||
249 | if (old_line) | ||
250 | free(old_line); | ||
251 | } | ||
252 | |||
253 | static void print_deferred_old_lines() | ||
254 | { | ||
255 | struct deferred_lines *iter_old, *tmp; | ||
256 | iter_old = deferred_old; | ||
257 | while (iter_old) { | ||
258 | print_ssdiff_line("del", iter_old->line_no, | ||
259 | iter_old->line, -1, NULL, 0); | ||
260 | tmp = iter_old->next; | ||
261 | free(iter_old); | ||
262 | iter_old = tmp; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | static void print_deferred_new_lines() | ||
267 | { | ||
268 | struct deferred_lines *iter_new, *tmp; | ||
269 | iter_new = deferred_new; | ||
270 | while (iter_new) { | ||
271 | print_ssdiff_line("add", -1, NULL, | ||
272 | iter_new->line_no, iter_new->line, 0); | ||
273 | tmp = iter_new->next; | ||
274 | free(iter_new); | ||
275 | iter_new = tmp; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | static void print_deferred_changed_lines() | ||
280 | { | ||
281 | struct deferred_lines *iter_old, *iter_new, *tmp; | ||
282 | int n_old_lines = calc_deferred_lines(deferred_old); | ||
283 | int n_new_lines = calc_deferred_lines(deferred_new); | ||
284 | int individual_chars = (n_old_lines == n_new_lines ? 1 : 0); | ||
285 | |||
286 | iter_old = deferred_old; | ||
287 | iter_new = deferred_new; | ||
288 | while (iter_old || iter_new) { | ||
289 | if (iter_old && iter_new) | ||
290 | print_ssdiff_line("changed", iter_old->line_no, | ||
291 | iter_old->line, | ||
292 | iter_new->line_no, iter_new->line, | ||
293 | individual_chars); | ||
294 | else if (iter_old) | ||
295 | print_ssdiff_line("changed", iter_old->line_no, | ||
296 | iter_old->line, -1, NULL, 0); | ||
297 | else if (iter_new) | ||
298 | print_ssdiff_line("changed", -1, NULL, | ||
299 | iter_new->line_no, iter_new->line, 0); | ||
300 | if (iter_old) { | ||
301 | tmp = iter_old->next; | ||
302 | free(iter_old); | ||
303 | iter_old = tmp; | ||
304 | } | ||
305 | |||
306 | if (iter_new) { | ||
307 | tmp = iter_new->next; | ||
308 | free(iter_new); | ||
309 | iter_new = tmp; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | |||
314 | void cgit_ssdiff_print_deferred_lines() | ||
315 | { | ||
316 | if (!deferred_old && !deferred_new) | ||
317 | return; | ||
318 | if (deferred_old && !deferred_new) | ||
319 | print_deferred_old_lines(); | ||
320 | else if (!deferred_old && deferred_new) | ||
321 | print_deferred_new_lines(); | ||
322 | else | ||
323 | print_deferred_changed_lines(); | ||
324 | deferred_old = deferred_old_last = NULL; | ||
325 | deferred_new = deferred_new_last = NULL; | ||
326 | } | ||
327 | |||
328 | /* | ||
329 | * print a single line returned from xdiff | ||
330 | */ | ||
331 | void cgit_ssdiff_line_cb(char *line, int len) | ||
332 | { | ||
333 | char c = line[len - 1]; | ||
334 | line[len - 1] = '\0'; | ||
335 | if (line[0] == '@') { | ||
336 | current_old_line = line_from_hunk(line, '-'); | ||
337 | current_new_line = line_from_hunk(line, '+'); | ||
338 | } | ||
339 | |||
340 | if (line[0] == ' ') { | ||
341 | if (deferred_old || deferred_new) | ||
342 | cgit_ssdiff_print_deferred_lines(); | ||
343 | print_ssdiff_line("ctx", current_old_line, line, | ||
344 | current_new_line, line, 0); | ||
345 | current_old_line += 1; | ||
346 | current_new_line += 1; | ||
347 | } else if (line[0] == '+') { | ||
348 | deferred_new_add(line, current_new_line); | ||
349 | current_new_line += 1; | ||
350 | } else if (line[0] == '-') { | ||
351 | deferred_old_add(line, current_old_line); | ||
352 | current_old_line += 1; | ||
353 | } else if (line[0] == '@') { | ||
354 | html("<tr><td colspan='4' class='hunk'>"); | ||
355 | html_txt(line); | ||
356 | html("</td></tr>"); | ||
357 | } else { | ||
358 | html("<tr><td colspan='4' class='ctx'>"); | ||
359 | html_txt(line); | ||
360 | html("</td></tr>"); | ||
361 | } | ||
362 | line[len - 1] = c; | ||
363 | } | ||
364 | |||
365 | void cgit_ssdiff_header_begin() | ||
366 | { | ||
367 | current_old_line = -1; | ||
368 | current_new_line = -1; | ||
369 | html("<tr><td class='space' colspan='4'><div></div></td></tr>"); | ||
370 | html("<tr><td class='head' colspan='4'>"); | ||
371 | } | ||
372 | |||
373 | void cgit_ssdiff_header_end() | ||
374 | { | ||
375 | html("</td><tr>"); | ||
376 | } | ||
377 | |||
378 | void cgit_ssdiff_footer() | ||
379 | { | ||
380 | if (deferred_old || deferred_new) | ||
381 | cgit_ssdiff_print_deferred_lines(); | ||
382 | html("<tr><td class='foot' colspan='4'></td></tr>"); | ||
383 | } | ||
diff --git a/ui-ssdiff.h b/ui-ssdiff.h new file mode 100644 index 0000000..64b4b12 --- a/dev/null +++ b/ui-ssdiff.h | |||
@@ -0,0 +1,13 @@ | |||
1 | #ifndef UI_SSDIFF_H | ||
2 | #define UI_SSDIFF_H | ||
3 | |||
4 | extern void cgit_ssdiff_print_deferred_lines(); | ||
5 | |||
6 | extern void cgit_ssdiff_line_cb(char *line, int len); | ||
7 | |||
8 | extern void cgit_ssdiff_header_begin(); | ||
9 | extern void cgit_ssdiff_header_end(); | ||
10 | |||
11 | extern void cgit_ssdiff_footer(); | ||
12 | |||
13 | #endif /* UI_SSDIFF_H */ | ||
@@ -1,55 +1,59 @@ | |||
1 | #include <string-list.h> | ||
2 | |||
3 | #include "cgit.h" | 1 | #include "cgit.h" |
4 | #include "html.h" | 2 | #include "html.h" |
5 | #include "ui-shared.h" | 3 | #include "ui-shared.h" |
6 | #include "ui-stats.h" | 4 | #include "ui-stats.h" |
7 | 5 | ||
6 | #ifdef NO_C99_FORMAT | ||
7 | #define SZ_FMT "%u" | ||
8 | #else | ||
9 | #define SZ_FMT "%zu" | ||
10 | #endif | ||
11 | |||
8 | #define MONTHS 6 | 12 | #define MONTHS 6 |
9 | 13 | ||
10 | struct authorstat { | 14 | struct authorstat { |
11 | long total; | 15 | long total; |
12 | struct string_list list; | 16 | struct string_list list; |
13 | }; | 17 | }; |
14 | 18 | ||
15 | #define DAY_SECS (60 * 60 * 24) | 19 | #define DAY_SECS (60 * 60 * 24) |
16 | #define WEEK_SECS (DAY_SECS * 7) | 20 | #define WEEK_SECS (DAY_SECS * 7) |
17 | 21 | ||
18 | static void trunc_week(struct tm *tm) | 22 | static void trunc_week(struct tm *tm) |
19 | { | 23 | { |
20 | time_t t = timegm(tm); | 24 | time_t t = timegm(tm); |
21 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; | 25 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
22 | gmtime_r(&t, tm); | 26 | gmtime_r(&t, tm); |
23 | } | 27 | } |
24 | 28 | ||
25 | static void dec_week(struct tm *tm) | 29 | static void dec_week(struct tm *tm) |
26 | { | 30 | { |
27 | time_t t = timegm(tm); | 31 | time_t t = timegm(tm); |
28 | t -= WEEK_SECS; | 32 | t -= WEEK_SECS; |
29 | gmtime_r(&t, tm); | 33 | gmtime_r(&t, tm); |
30 | } | 34 | } |
31 | 35 | ||
32 | static void inc_week(struct tm *tm) | 36 | static void inc_week(struct tm *tm) |
33 | { | 37 | { |
34 | time_t t = timegm(tm); | 38 | time_t t = timegm(tm); |
35 | t += WEEK_SECS; | 39 | t += WEEK_SECS; |
36 | gmtime_r(&t, tm); | 40 | gmtime_r(&t, tm); |
37 | } | 41 | } |
38 | 42 | ||
39 | static char *pretty_week(struct tm *tm) | 43 | static char *pretty_week(struct tm *tm) |
40 | { | 44 | { |
41 | static char buf[10]; | 45 | static char buf[10]; |
42 | 46 | ||
43 | strftime(buf, sizeof(buf), "W%V %G", tm); | 47 | strftime(buf, sizeof(buf), "W%V %G", tm); |
44 | return buf; | 48 | return buf; |
45 | } | 49 | } |
46 | 50 | ||
47 | static void trunc_month(struct tm *tm) | 51 | static void trunc_month(struct tm *tm) |
48 | { | 52 | { |
49 | tm->tm_mday = 1; | 53 | tm->tm_mday = 1; |
50 | } | 54 | } |
51 | 55 | ||
52 | static void dec_month(struct tm *tm) | 56 | static void dec_month(struct tm *tm) |
53 | { | 57 | { |
54 | tm->tm_mon--; | 58 | tm->tm_mon--; |
55 | if (tm->tm_mon < 0) { | 59 | if (tm->tm_mon < 0) { |
@@ -238,181 +242,181 @@ struct string_list collect_stats(struct cgit_context *ctx, | |||
238 | rev.no_merges = 1; | 242 | rev.no_merges = 1; |
239 | rev.verbose_header = 1; | 243 | rev.verbose_header = 1; |
240 | rev.show_root_diff = 0; | 244 | rev.show_root_diff = 0; |
241 | setup_revisions(argc, argv, &rev, NULL); | 245 | setup_revisions(argc, argv, &rev, NULL); |
242 | prepare_revision_walk(&rev); | 246 | prepare_revision_walk(&rev); |
243 | memset(&authors, 0, sizeof(authors)); | 247 | memset(&authors, 0, sizeof(authors)); |
244 | while ((commit = get_revision(&rev)) != NULL) { | 248 | while ((commit = get_revision(&rev)) != NULL) { |
245 | add_commit(&authors, commit, period); | 249 | add_commit(&authors, commit, period); |
246 | free(commit->buffer); | 250 | free(commit->buffer); |
247 | free_commit_list(commit->parents); | 251 | free_commit_list(commit->parents); |
248 | } | 252 | } |
249 | return authors; | 253 | return authors; |
250 | } | 254 | } |
251 | 255 | ||
252 | void print_combined_authorrow(struct string_list *authors, int from, int to, | 256 | void print_combined_authorrow(struct string_list *authors, int from, int to, |
253 | const char *name, const char *leftclass, const char *centerclass, | 257 | const char *name, const char *leftclass, const char *centerclass, |
254 | const char *rightclass, struct cgit_period *period) | 258 | const char *rightclass, struct cgit_period *period) |
255 | { | 259 | { |
256 | struct string_list_item *author; | 260 | struct string_list_item *author; |
257 | struct authorstat *authorstat; | 261 | struct authorstat *authorstat; |
258 | struct string_list *items; | 262 | struct string_list *items; |
259 | struct string_list_item *date; | 263 | struct string_list_item *date; |
260 | time_t now; | 264 | time_t now; |
261 | long i, j, total, subtotal; | 265 | long i, j, total, subtotal; |
262 | struct tm *tm; | 266 | struct tm *tm; |
263 | char *tmp; | 267 | char *tmp; |
264 | 268 | ||
265 | time(&now); | 269 | time(&now); |
266 | tm = gmtime(&now); | 270 | tm = gmtime(&now); |
267 | period->trunc(tm); | 271 | period->trunc(tm); |
268 | for (i = 1; i < period->count; i++) | 272 | for (i = 1; i < period->count; i++) |
269 | period->dec(tm); | 273 | period->dec(tm); |
270 | 274 | ||
271 | total = 0; | 275 | total = 0; |
272 | htmlf("<tr><td class='%s'>%s</td>", leftclass, | 276 | htmlf("<tr><td class='%s'>%s</td>", leftclass, |
273 | fmt(name, to - from + 1)); | 277 | fmt(name, to - from + 1)); |
274 | for (j = 0; j < period->count; j++) { | 278 | for (j = 0; j < period->count; j++) { |
275 | tmp = period->pretty(tm); | 279 | tmp = period->pretty(tm); |
276 | period->inc(tm); | 280 | period->inc(tm); |
277 | subtotal = 0; | 281 | subtotal = 0; |
278 | for (i = from; i <= to; i++) { | 282 | for (i = from; i <= to; i++) { |
279 | author = &authors->items[i]; | 283 | author = &authors->items[i]; |
280 | authorstat = author->util; | 284 | authorstat = author->util; |
281 | items = &authorstat->list; | 285 | items = &authorstat->list; |
282 | date = string_list_lookup(items, tmp); | 286 | date = string_list_lookup(items, tmp); |
283 | if (date) | 287 | if (date) |
284 | subtotal += (size_t)date->util; | 288 | subtotal += (size_t)date->util; |
285 | } | 289 | } |
286 | htmlf("<td class='%s'>%d</td>", centerclass, subtotal); | 290 | htmlf("<td class='%s'>%ld</td>", centerclass, subtotal); |
287 | total += subtotal; | 291 | total += subtotal; |
288 | } | 292 | } |
289 | htmlf("<td class='%s'>%d</td></tr>", rightclass, total); | 293 | htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); |
290 | } | 294 | } |
291 | 295 | ||
292 | void print_authors(struct string_list *authors, int top, | 296 | void print_authors(struct string_list *authors, int top, |
293 | struct cgit_period *period) | 297 | struct cgit_period *period) |
294 | { | 298 | { |
295 | struct string_list_item *author; | 299 | struct string_list_item *author; |
296 | struct authorstat *authorstat; | 300 | struct authorstat *authorstat; |
297 | struct string_list *items; | 301 | struct string_list *items; |
298 | struct string_list_item *date; | 302 | struct string_list_item *date; |
299 | time_t now; | 303 | time_t now; |
300 | long i, j, total; | 304 | long i, j, total; |
301 | struct tm *tm; | 305 | struct tm *tm; |
302 | char *tmp; | 306 | char *tmp; |
303 | 307 | ||
304 | time(&now); | 308 | time(&now); |
305 | tm = gmtime(&now); | 309 | tm = gmtime(&now); |
306 | period->trunc(tm); | 310 | period->trunc(tm); |
307 | for (i = 1; i < period->count; i++) | 311 | for (i = 1; i < period->count; i++) |
308 | period->dec(tm); | 312 | period->dec(tm); |
309 | 313 | ||
310 | html("<table class='stats'><tr><th>Author</th>"); | 314 | html("<table class='stats'><tr><th>Author</th>"); |
311 | for (j = 0; j < period->count; j++) { | 315 | for (j = 0; j < period->count; j++) { |
312 | tmp = period->pretty(tm); | 316 | tmp = period->pretty(tm); |
313 | htmlf("<th>%s</th>", tmp); | 317 | htmlf("<th>%s</th>", tmp); |
314 | period->inc(tm); | 318 | period->inc(tm); |
315 | } | 319 | } |
316 | html("<th>Total</th></tr>\n"); | 320 | html("<th>Total</th></tr>\n"); |
317 | 321 | ||
318 | if (top <= 0 || top > authors->nr) | 322 | if (top <= 0 || top > authors->nr) |
319 | top = authors->nr; | 323 | top = authors->nr; |
320 | 324 | ||
321 | for (i = 0; i < top; i++) { | 325 | for (i = 0; i < top; i++) { |
322 | author = &authors->items[i]; | 326 | author = &authors->items[i]; |
323 | html("<tr><td class='left'>"); | 327 | html("<tr><td class='left'>"); |
324 | html_txt(author->string); | 328 | html_txt(author->string); |
325 | html("</td>"); | 329 | html("</td>"); |
326 | authorstat = author->util; | 330 | authorstat = author->util; |
327 | items = &authorstat->list; | 331 | items = &authorstat->list; |
328 | total = 0; | 332 | total = 0; |
329 | for (j = 0; j < period->count; j++) | 333 | for (j = 0; j < period->count; j++) |
330 | period->dec(tm); | 334 | period->dec(tm); |
331 | for (j = 0; j < period->count; j++) { | 335 | for (j = 0; j < period->count; j++) { |
332 | tmp = period->pretty(tm); | 336 | tmp = period->pretty(tm); |
333 | period->inc(tm); | 337 | period->inc(tm); |
334 | date = string_list_lookup(items, tmp); | 338 | date = string_list_lookup(items, tmp); |
335 | if (!date) | 339 | if (!date) |
336 | html("<td>0</td>"); | 340 | html("<td>0</td>"); |
337 | else { | 341 | else { |
338 | htmlf("<td>%d</td>", date->util); | 342 | htmlf("<td>"SZ_FMT"</td>", (size_t)date->util); |
339 | total += (size_t)date->util; | 343 | total += (size_t)date->util; |
340 | } | 344 | } |
341 | } | 345 | } |
342 | htmlf("<td class='sum'>%d</td></tr>", total); | 346 | htmlf("<td class='sum'>%ld</td></tr>", total); |
343 | } | 347 | } |
344 | 348 | ||
345 | if (top < authors->nr) | 349 | if (top < authors->nr) |
346 | print_combined_authorrow(authors, top, authors->nr - 1, | 350 | print_combined_authorrow(authors, top, authors->nr - 1, |
347 | "Others (%d)", "left", "", "sum", period); | 351 | "Others (%ld)", "left", "", "sum", period); |
348 | 352 | ||
349 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", | 353 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", |
350 | "total", "sum", "sum", period); | 354 | "total", "sum", "sum", period); |
351 | html("</table>"); | 355 | html("</table>"); |
352 | } | 356 | } |
353 | 357 | ||
354 | /* Create a sorted string_list with one entry per author. The util-field | 358 | /* Create a sorted string_list with one entry per author. The util-field |
355 | * for each author is another string_list which is used to calculate the | 359 | * for each author is another string_list which is used to calculate the |
356 | * number of commits per time-interval. | 360 | * number of commits per time-interval. |
357 | */ | 361 | */ |
358 | void cgit_show_stats(struct cgit_context *ctx) | 362 | void cgit_show_stats(struct cgit_context *ctx) |
359 | { | 363 | { |
360 | struct string_list authors; | 364 | struct string_list authors; |
361 | struct cgit_period *period; | 365 | struct cgit_period *period; |
362 | int top, i; | 366 | int top, i; |
363 | const char *code = "w"; | 367 | const char *code = "w"; |
364 | 368 | ||
365 | if (ctx->qry.period) | 369 | if (ctx->qry.period) |
366 | code = ctx->qry.period; | 370 | code = ctx->qry.period; |
367 | 371 | ||
368 | i = cgit_find_stats_period(code, &period); | 372 | i = cgit_find_stats_period(code, &period); |
369 | if (!i) { | 373 | if (!i) { |
370 | cgit_print_error(fmt("Unknown statistics type: %c", code)); | 374 | cgit_print_error(fmt("Unknown statistics type: %c", code[0])); |
371 | return; | 375 | return; |
372 | } | 376 | } |
373 | if (i > ctx->repo->max_stats) { | 377 | if (i > ctx->repo->max_stats) { |
374 | cgit_print_error(fmt("Statistics type disabled: %s", | 378 | cgit_print_error(fmt("Statistics type disabled: %s", |
375 | period->name)); | 379 | period->name)); |
376 | return; | 380 | return; |
377 | } | 381 | } |
378 | authors = collect_stats(ctx, period); | 382 | authors = collect_stats(ctx, period); |
379 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), | 383 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), |
380 | cmp_total_commits); | 384 | cmp_total_commits); |
381 | 385 | ||
382 | top = ctx->qry.ofs; | 386 | top = ctx->qry.ofs; |
383 | if (!top) | 387 | if (!top) |
384 | top = 10; | 388 | top = 10; |
385 | htmlf("<h2>Commits per author per %s", period->name); | 389 | htmlf("<h2>Commits per author per %s", period->name); |
386 | if (ctx->qry.path) { | 390 | if (ctx->qry.path) { |
387 | html(" (path '"); | 391 | html(" (path '"); |
388 | html_txt(ctx->qry.path); | 392 | html_txt(ctx->qry.path); |
389 | html("')"); | 393 | html("')"); |
390 | } | 394 | } |
391 | html("</h2>"); | 395 | html("</h2>"); |
392 | 396 | ||
393 | html("<form method='get' action='' style='float: right; text-align: right;'>"); | 397 | html("<form method='get' action='' style='float: right; text-align: right;'>"); |
394 | cgit_add_hidden_formfields(1, 0, "stats"); | 398 | cgit_add_hidden_formfields(1, 0, "stats"); |
395 | if (ctx->repo->max_stats > 1) { | 399 | if (ctx->repo->max_stats > 1) { |
396 | html("Period: "); | 400 | html("Period: "); |
397 | html("<select name='period' onchange='this.form.submit();'>"); | 401 | html("<select name='period' onchange='this.form.submit();'>"); |
398 | for (i = 0; i < ctx->repo->max_stats; i++) | 402 | for (i = 0; i < ctx->repo->max_stats; i++) |
399 | htmlf("<option value='%c'%s>%s</option>", | 403 | htmlf("<option value='%c'%s>%s</option>", |
400 | periods[i].code, | 404 | periods[i].code, |
401 | period == &periods[i] ? " selected" : "", | 405 | period == &periods[i] ? " selected" : "", |
402 | periods[i].name); | 406 | periods[i].name); |
403 | html("</select><br/><br/>"); | 407 | html("</select><br/><br/>"); |
404 | } | 408 | } |
405 | html("Authors: "); | 409 | html("Authors: "); |
406 | html(""); | 410 | html(""); |
407 | html("<select name='ofs' onchange='this.form.submit();'>"); | 411 | html("<select name='ofs' onchange='this.form.submit();'>"); |
408 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); | 412 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); |
409 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); | 413 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); |
410 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); | 414 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); |
411 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); | 415 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); |
412 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); | 416 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); |
413 | html("</select>"); | 417 | html("</select>"); |
414 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); | 418 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); |
415 | html("</form>"); | 419 | html("</form>"); |
416 | print_authors(&authors, top, period); | 420 | print_authors(&authors, top, period); |
417 | } | 421 | } |
418 | 422 | ||
diff --git a/ui-summary.c b/ui-summary.c index a2c018e..5be2545 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,92 +1,124 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
4 | * | 5 | * |
5 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
7 | */ | 8 | */ |
8 | 9 | ||
9 | #include "cgit.h" | 10 | #include "cgit.h" |
10 | #include "html.h" | 11 | #include "html.h" |
11 | #include "ui-log.h" | 12 | #include "ui-log.h" |
12 | #include "ui-refs.h" | 13 | #include "ui-refs.h" |
14 | #include "ui-blob.h" | ||
13 | 15 | ||
14 | int urls = 0; | 16 | int urls = 0; |
15 | 17 | ||
16 | static void print_url(char *base, char *suffix) | 18 | static void print_url(char *base, char *suffix) |
17 | { | 19 | { |
18 | if (!base || !*base) | 20 | if (!base || !*base) |
19 | return; | 21 | return; |
20 | if (urls++ == 0) { | 22 | if (urls++ == 0) { |
21 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 23 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
22 | html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); | 24 | html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); |
23 | } | 25 | } |
24 | if (suffix && *suffix) | 26 | if (suffix && *suffix) |
25 | base = fmt("%s/%s", base, suffix); | 27 | base = fmt("%s/%s", base, suffix); |
26 | html("<tr><td colspan='4'><a href='"); | 28 | html("<tr><td colspan='4'><a href='"); |
27 | html_url_path(base); | 29 | html_url_path(base); |
28 | html("'>"); | 30 | html("'>"); |
29 | html_txt(base); | 31 | html_txt(base); |
30 | html("</a></td></tr>\n"); | 32 | html("</a></td></tr>\n"); |
31 | } | 33 | } |
32 | 34 | ||
33 | static void print_urls(char *txt, char *suffix) | 35 | static void print_urls(char *txt, char *suffix) |
34 | { | 36 | { |
35 | char *h = txt, *t, c; | 37 | char *h = txt, *t, c; |
36 | 38 | ||
37 | while (h && *h) { | 39 | while (h && *h) { |
38 | while (h && *h == ' ') | 40 | while (h && *h == ' ') |
39 | h++; | 41 | h++; |
40 | t = h; | 42 | t = h; |
41 | while (t && *t && *t != ' ') | 43 | while (t && *t && *t != ' ') |
42 | t++; | 44 | t++; |
43 | c = *t; | 45 | c = *t; |
44 | *t = 0; | 46 | *t = 0; |
45 | print_url(h, suffix); | 47 | print_url(h, suffix); |
46 | *t = c; | 48 | *t = c; |
47 | h = t; | 49 | h = t; |
48 | } | 50 | } |
49 | } | 51 | } |
50 | 52 | ||
51 | void cgit_print_summary() | 53 | void cgit_print_summary() |
52 | { | 54 | { |
53 | html("<table summary='repository info' class='list nowrap'>"); | 55 | html("<table summary='repository info' class='list nowrap'>"); |
54 | cgit_print_branches(ctx.cfg.summary_branches); | 56 | cgit_print_branches(ctx.cfg.summary_branches); |
55 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 57 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
56 | cgit_print_tags(ctx.cfg.summary_tags); | 58 | cgit_print_tags(ctx.cfg.summary_tags); |
57 | if (ctx.cfg.summary_log > 0) { | 59 | if (ctx.cfg.summary_log > 0) { |
58 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 60 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
59 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, | 61 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, |
60 | NULL, NULL, 0); | 62 | NULL, NULL, 0, 0); |
61 | } | 63 | } |
62 | if (ctx.repo->clone_url) | 64 | if (ctx.repo->clone_url) |
63 | print_urls(ctx.repo->clone_url, NULL); | 65 | print_urls(ctx.repo->clone_url, NULL); |
64 | else if (ctx.cfg.clone_prefix) | 66 | else if (ctx.cfg.clone_prefix) |
65 | print_urls(ctx.cfg.clone_prefix, ctx.repo->url); | 67 | print_urls(ctx.cfg.clone_prefix, ctx.repo->url); |
66 | html("</table>"); | 68 | html("</table>"); |
67 | } | 69 | } |
68 | 70 | ||
69 | void cgit_print_repo_readme(char *path) | 71 | void cgit_print_repo_readme(char *path) |
70 | { | 72 | { |
71 | char *slash, *tmp; | 73 | char *slash, *tmp, *colon, *ref; |
72 | 74 | ||
73 | if (!ctx.repo->readme) | 75 | if (!ctx.repo->readme || !(*ctx.repo->readme)) |
74 | return; | 76 | return; |
75 | 77 | ||
78 | ref = NULL; | ||
79 | |||
80 | /* Check if the readme is tracked in the git repo. */ | ||
81 | colon = strchr(ctx.repo->readme, ':'); | ||
82 | if (colon && strlen(colon) > 1) { | ||
83 | *colon = '\0'; | ||
84 | ref = ctx.repo->readme; | ||
85 | ctx.repo->readme = colon + 1; | ||
86 | if (!(*ctx.repo->readme)) | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | /* Prepend repo path to relative readme path unless tracked. */ | ||
91 | if (!ref && *ctx.repo->readme != '/') | ||
92 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, | ||
93 | ctx.repo->readme)); | ||
94 | |||
95 | /* If a subpath is specified for the about page, make it relative | ||
96 | * to the directory containing the configured readme. | ||
97 | */ | ||
76 | if (path) { | 98 | if (path) { |
77 | slash = strrchr(ctx.repo->readme, '/'); | 99 | slash = strrchr(ctx.repo->readme, '/'); |
78 | if (!slash) | 100 | if (!slash) { |
101 | if (!colon) | ||
79 | return; | 102 | return; |
103 | slash = colon; | ||
104 | } | ||
80 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); | 105 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); |
81 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); | 106 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); |
82 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); | 107 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); |
83 | } else | 108 | } else |
84 | tmp = ctx.repo->readme; | 109 | tmp = ctx.repo->readme; |
110 | |||
111 | /* Print the calculated readme, either from the git repo or from the | ||
112 | * filesystem, while applying the about-filter. | ||
113 | */ | ||
85 | html("<div id='summary'>"); | 114 | html("<div id='summary'>"); |
86 | if (ctx.repo->about_filter) | 115 | if (ctx.repo->about_filter) |
87 | cgit_open_filter(ctx.repo->about_filter); | 116 | cgit_open_filter(ctx.repo->about_filter); |
117 | if (ref) | ||
118 | cgit_print_file(tmp, ref); | ||
119 | else | ||
88 | html_include(tmp); | 120 | html_include(tmp); |
89 | if (ctx.repo->about_filter) | 121 | if (ctx.repo->about_filter) |
90 | cgit_close_filter(ctx.repo->about_filter); | 122 | cgit_close_filter(ctx.repo->about_filter); |
91 | html("</div>"); | 123 | html("</div>"); |
92 | } | 124 | } |
@@ -1,92 +1,104 @@ | |||
1 | /* ui-tag.c: display a tag | 1 | /* ui-tag.c: display a tag |
2 | * | 2 | * |
3 | * Copyright (C) 2007 Lars Hjemli | 3 | * Copyright (C) 2007 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | static void print_tag_content(char *buf) | 13 | static void print_tag_content(char *buf) |
14 | { | 14 | { |
15 | char *p; | 15 | char *p; |
16 | 16 | ||
17 | if (!buf) | 17 | if (!buf) |
18 | return; | 18 | return; |
19 | 19 | ||
20 | html("<div class='commit-subject'>"); | 20 | html("<div class='commit-subject'>"); |
21 | p = strchr(buf, '\n'); | 21 | p = strchr(buf, '\n'); |
22 | if (p) | 22 | if (p) |
23 | *p = '\0'; | 23 | *p = '\0'; |
24 | html_txt(buf); | 24 | html_txt(buf); |
25 | html("</div>"); | 25 | html("</div>"); |
26 | if (p) { | 26 | if (p) { |
27 | html("<div class='commit-msg'>"); | 27 | html("<div class='commit-msg'>"); |
28 | html_txt(++p); | 28 | html_txt(++p); |
29 | html("</div>"); | 29 | html("</div>"); |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | void print_download_links(char *revname) | ||
34 | { | ||
35 | html("<tr><th>download</th><td class='sha1'>"); | ||
36 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, | ||
37 | revname, ctx.repo->snapshots); | ||
38 | html("</td></tr>"); | ||
39 | } | ||
40 | |||
33 | void cgit_print_tag(char *revname) | 41 | void cgit_print_tag(char *revname) |
34 | { | 42 | { |
35 | unsigned char sha1[20]; | 43 | unsigned char sha1[20]; |
36 | struct object *obj; | 44 | struct object *obj; |
37 | struct tag *tag; | 45 | struct tag *tag; |
38 | struct taginfo *info; | 46 | struct taginfo *info; |
39 | 47 | ||
40 | if (!revname) | 48 | if (!revname) |
41 | revname = ctx.qry.head; | 49 | revname = ctx.qry.head; |
42 | 50 | ||
43 | if (get_sha1(fmt("refs/tags/%s", revname), sha1)) { | 51 | if (get_sha1(fmt("refs/tags/%s", revname), sha1)) { |
44 | cgit_print_error(fmt("Bad tag reference: %s", revname)); | 52 | cgit_print_error(fmt("Bad tag reference: %s", revname)); |
45 | return; | 53 | return; |
46 | } | 54 | } |
47 | obj = parse_object(sha1); | 55 | obj = parse_object(sha1); |
48 | if (!obj) { | 56 | if (!obj) { |
49 | cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); | 57 | cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); |
50 | return; | 58 | return; |
51 | } | 59 | } |
52 | if (obj->type == OBJ_TAG) { | 60 | if (obj->type == OBJ_TAG) { |
53 | tag = lookup_tag(sha1); | 61 | tag = lookup_tag(sha1); |
54 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { | 62 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { |
55 | cgit_print_error(fmt("Bad tag object: %s", revname)); | 63 | cgit_print_error(fmt("Bad tag object: %s", revname)); |
56 | return; | 64 | return; |
57 | } | 65 | } |
58 | html("<table class='commit-info'>\n"); | 66 | html("<table class='commit-info'>\n"); |
59 | htmlf("<tr><td>Tag name</td><td>"); | 67 | htmlf("<tr><td>tag name</td><td>"); |
60 | html_txt(revname); | 68 | html_txt(revname); |
61 | htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); | 69 | htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); |
62 | if (info->tagger_date > 0) { | 70 | if (info->tagger_date > 0) { |
63 | html("<tr><td>Tag date</td><td>"); | 71 | html("<tr><td>tag date</td><td>"); |
64 | cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); | 72 | cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); |
65 | html("</td></tr>\n"); | 73 | html("</td></tr>\n"); |
66 | } | 74 | } |
67 | if (info->tagger) { | 75 | if (info->tagger) { |
68 | html("<tr><td>Tagged by</td><td>"); | 76 | html("<tr><td>tagged by</td><td>"); |
69 | html_txt(info->tagger); | 77 | html_txt(info->tagger); |
70 | if (info->tagger_email && !ctx.cfg.noplainemail) { | 78 | if (info->tagger_email && !ctx.cfg.noplainemail) { |
71 | html(" "); | 79 | html(" "); |
72 | html_txt(info->tagger_email); | 80 | html_txt(info->tagger_email); |
73 | } | 81 | } |
74 | html("</td></tr>\n"); | 82 | html("</td></tr>\n"); |
75 | } | 83 | } |
76 | html("<tr><td>Tagged object</td><td>"); | 84 | html("<tr><td>tagged object</td><td class='sha1'>"); |
77 | cgit_object_link(tag->tagged); | 85 | cgit_object_link(tag->tagged); |
78 | html("</td></tr>\n"); | 86 | html("</td></tr>\n"); |
87 | if (ctx.repo->snapshots) | ||
88 | print_download_links(revname); | ||
79 | html("</table>\n"); | 89 | html("</table>\n"); |
80 | print_tag_content(info->msg); | 90 | print_tag_content(info->msg); |
81 | } else { | 91 | } else { |
82 | html("<table class='commit-info'>\n"); | 92 | html("<table class='commit-info'>\n"); |
83 | htmlf("<tr><td>Tag name</td><td>"); | 93 | htmlf("<tr><td>tag name</td><td>"); |
84 | html_txt(revname); | 94 | html_txt(revname); |
85 | html("</td></tr>\n"); | 95 | html("</td></tr>\n"); |
86 | html("<tr><td>Tagged object</td><td>"); | 96 | html("<tr><td>Tagged object</td><td class='sha1'>"); |
87 | cgit_object_link(obj); | 97 | cgit_object_link(obj); |
88 | html("</td></tr>\n"); | 98 | html("</td></tr>\n"); |
99 | if (ctx.repo->snapshots) | ||
100 | print_download_links(revname); | ||
89 | html("</table>\n"); | 101 | html("</table>\n"); |
90 | } | 102 | } |
91 | return; | 103 | return; |
92 | } | 104 | } |
@@ -1,285 +1,282 @@ | |||
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 <ctype.h> | 9 | #include <ctype.h> |
10 | #include "cgit.h" | 10 | #include "cgit.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | char *curr_rev; | 14 | char *curr_rev; |
15 | char *match_path; | 15 | char *match_path; |
16 | int header = 0; | 16 | int header = 0; |
17 | 17 | ||
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) | 18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
19 | { | 19 | { |
20 | unsigned long lineno, idx; | 20 | unsigned long lineno, idx; |
21 | const char *numberfmt = | 21 | const char *numberfmt = |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; | 22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
23 | 23 | ||
24 | html("<table summary='blob content' class='blob'>\n"); | 24 | html("<table summary='blob content' class='blob'>\n"); |
25 | 25 | ||
26 | if (ctx.cfg.enable_tree_linenumbers) { | 26 | if (ctx.cfg.enable_tree_linenumbers) { |
27 | html("<tr><td class='linenumbers'><pre>"); | 27 | html("<tr><td class='linenumbers'><pre>"); |
28 | idx = 0; | 28 | idx = 0; |
29 | lineno = 0; | 29 | lineno = 0; |
30 | 30 | ||
31 | if (size) { | 31 | if (size) { |
32 | htmlf(numberfmt, ++lineno); | 32 | htmlf(numberfmt, ++lineno); |
33 | while(idx < size - 1) { // skip absolute last newline | 33 | while(idx < size - 1) { // skip absolute last newline |
34 | if (buf[idx] == '\n') | 34 | if (buf[idx] == '\n') |
35 | htmlf(numberfmt, ++lineno); | 35 | htmlf(numberfmt, ++lineno); |
36 | idx++; | 36 | idx++; |
37 | } | 37 | } |
38 | } | 38 | } |
39 | html("</pre></td>\n"); | 39 | html("</pre></td>\n"); |
40 | } | 40 | } |
41 | else { | 41 | else { |
42 | html("<tr>\n"); | 42 | html("<tr>\n"); |
43 | } | 43 | } |
44 | 44 | ||
45 | if (ctx.repo->source_filter) { | 45 | if (ctx.repo->source_filter) { |
46 | html("<td class='lines'><pre><code>"); | 46 | html("<td class='lines'><pre><code>"); |
47 | ctx.repo->source_filter->argv[1] = xstrdup(name); | 47 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
48 | cgit_open_filter(ctx.repo->source_filter); | 48 | cgit_open_filter(ctx.repo->source_filter); |
49 | write(STDOUT_FILENO, buf, size); | 49 | html_raw(buf, size); |
50 | cgit_close_filter(ctx.repo->source_filter); | 50 | cgit_close_filter(ctx.repo->source_filter); |
51 | html("</code></pre></td></tr></table>\n"); | 51 | html("</code></pre></td></tr></table>\n"); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | 54 | ||
55 | html("<td class='lines'><pre><code>"); | 55 | html("<td class='lines'><pre><code>"); |
56 | html_txt(buf); | 56 | html_txt(buf); |
57 | html("</code></pre></td></tr></table>\n"); | 57 | html("</code></pre></td></tr></table>\n"); |
58 | } | 58 | } |
59 | 59 | ||
60 | #define ROWLEN 32 | 60 | #define ROWLEN 32 |
61 | 61 | ||
62 | static void print_binary_buffer(char *buf, unsigned long size) | 62 | static void print_binary_buffer(char *buf, unsigned long size) |
63 | { | 63 | { |
64 | unsigned long ofs, idx; | 64 | unsigned long ofs, idx; |
65 | static char ascii[ROWLEN + 1]; | 65 | static char ascii[ROWLEN + 1]; |
66 | 66 | ||
67 | html("<table summary='blob content' class='bin-blob'>\n"); | 67 | html("<table summary='blob content' class='bin-blob'>\n"); |
68 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); | 68 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
69 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { | 69 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
70 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); | 70 | htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs); |
71 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) | 71 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
72 | htmlf("%*s%02x", | 72 | htmlf("%*s%02x", |
73 | idx == 16 ? 4 : 1, "", | 73 | idx == 16 ? 4 : 1, "", |
74 | buf[idx] & 0xff); | 74 | buf[idx] & 0xff); |
75 | html(" </td><td class='hex'>"); | 75 | html(" </td><td class='hex'>"); |
76 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) | 76 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
77 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; | 77 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
78 | ascii[idx] = '\0'; | 78 | ascii[idx] = '\0'; |
79 | html_txt(ascii); | 79 | html_txt(ascii); |
80 | html("</td></tr>\n"); | 80 | html("</td></tr>\n"); |
81 | } | 81 | } |
82 | html("</table>\n"); | 82 | html("</table>\n"); |
83 | } | 83 | } |
84 | 84 | ||
85 | static void print_object(const unsigned char *sha1, char *path, const char *basename) | 85 | static void print_object(const unsigned char *sha1, char *path, const char *basename) |
86 | { | 86 | { |
87 | enum object_type type; | 87 | enum object_type type; |
88 | char *buf; | 88 | char *buf; |
89 | unsigned long size; | 89 | unsigned long size; |
90 | 90 | ||
91 | type = sha1_object_info(sha1, &size); | 91 | type = sha1_object_info(sha1, &size); |
92 | if (type == OBJ_BAD) { | 92 | if (type == OBJ_BAD) { |
93 | cgit_print_error(fmt("Bad object name: %s", | 93 | cgit_print_error(fmt("Bad object name: %s", |
94 | sha1_to_hex(sha1))); | 94 | sha1_to_hex(sha1))); |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | 97 | ||
98 | buf = read_sha1_file(sha1, &type, &size); | 98 | buf = read_sha1_file(sha1, &type, &size); |
99 | if (!buf) { | 99 | if (!buf) { |
100 | cgit_print_error(fmt("Error reading object %s", | 100 | cgit_print_error(fmt("Error reading object %s", |
101 | sha1_to_hex(sha1))); | 101 | sha1_to_hex(sha1))); |
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | 104 | ||
105 | html(" ("); | 105 | htmlf("blob: %s (", sha1_to_hex(sha1)); |
106 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, | 106 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, |
107 | curr_rev, path); | 107 | curr_rev, path); |
108 | htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); | 108 | html(")\n"); |
109 | |||
110 | if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { | ||
111 | htmlf("<div class='error'>blob size (%ldKB) exceeds display size limit (%dKB).</div>", | ||
112 | size / 1024, ctx.cfg.max_blob_size); | ||
113 | return; | ||
114 | } | ||
109 | 115 | ||
110 | if (buffer_is_binary(buf, size)) | 116 | if (buffer_is_binary(buf, size)) |
111 | print_binary_buffer(buf, size); | 117 | print_binary_buffer(buf, size); |
112 | else | 118 | else |
113 | print_text_buffer(basename, buf, size); | 119 | print_text_buffer(basename, buf, size); |
114 | } | 120 | } |
115 | 121 | ||
116 | 122 | ||
117 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 123 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
118 | const char *pathname, unsigned int mode, int stage, | 124 | const char *pathname, unsigned int mode, int stage, |
119 | void *cbdata) | 125 | void *cbdata) |
120 | { | 126 | { |
121 | char *name; | 127 | char *name; |
122 | char *fullpath; | 128 | char *fullpath; |
123 | char *class; | 129 | char *class; |
124 | enum object_type type; | 130 | enum object_type type; |
125 | unsigned long size = 0; | 131 | unsigned long size = 0; |
126 | 132 | ||
127 | name = xstrdup(pathname); | 133 | name = xstrdup(pathname); |
128 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", | 134 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
129 | ctx.qry.path ? "/" : "", name); | 135 | ctx.qry.path ? "/" : "", name); |
130 | 136 | ||
131 | if (!S_ISGITLINK(mode)) { | 137 | if (!S_ISGITLINK(mode)) { |
132 | type = sha1_object_info(sha1, &size); | 138 | type = sha1_object_info(sha1, &size); |
133 | if (type == OBJ_BAD) { | 139 | if (type == OBJ_BAD) { |
134 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 140 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
135 | name, | 141 | name, |
136 | sha1_to_hex(sha1)); | 142 | sha1_to_hex(sha1)); |
137 | return 0; | 143 | return 0; |
138 | } | 144 | } |
139 | } | 145 | } |
140 | 146 | ||
141 | html("<tr><td class='ls-mode'>"); | 147 | html("<tr><td class='ls-mode'>"); |
142 | cgit_print_filemode(mode); | 148 | cgit_print_filemode(mode); |
143 | html("</td><td>"); | 149 | html("</td><td>"); |
144 | if (S_ISGITLINK(mode)) { | 150 | if (S_ISGITLINK(mode)) { |
145 | htmlf("<a class='ls-mod' href='"); | 151 | htmlf("<a class='ls-mod' href='"); |
146 | html_attr(fmt(ctx.repo->module_link, | 152 | html_attr(fmt(ctx.repo->module_link, |
147 | name, | 153 | name, |
148 | sha1_to_hex(sha1))); | 154 | sha1_to_hex(sha1))); |
149 | html("'>"); | 155 | html("'>"); |
150 | html_txt(name); | 156 | html_txt(name); |
151 | html("</a>"); | 157 | html("</a>"); |
152 | } else if (S_ISDIR(mode)) { | 158 | } else if (S_ISDIR(mode)) { |
153 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, | 159 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
154 | curr_rev, fullpath); | 160 | curr_rev, fullpath); |
155 | } else { | 161 | } else { |
156 | class = strrchr(name, '.'); | 162 | class = strrchr(name, '.'); |
157 | if (class != NULL) { | 163 | if (class != NULL) { |
158 | class = fmt("ls-blob %s", class + 1); | 164 | class = fmt("ls-blob %s", class + 1); |
159 | } else | 165 | } else |
160 | class = "ls-blob"; | 166 | class = "ls-blob"; |
161 | cgit_tree_link(name, NULL, class, ctx.qry.head, | 167 | cgit_tree_link(name, NULL, class, ctx.qry.head, |
162 | curr_rev, fullpath); | 168 | curr_rev, fullpath); |
163 | } | 169 | } |
164 | htmlf("</td><td class='ls-size'>%li</td>", size); | 170 | htmlf("</td><td class='ls-size'>%li</td>", size); |
165 | 171 | ||
166 | html("<td>"); | 172 | html("<td>"); |
167 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, | 173 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
168 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); | 174 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); |
169 | if (ctx.repo->max_stats) | 175 | if (ctx.repo->max_stats) |
170 | cgit_stats_link("stats", NULL, "button", ctx.qry.head, | 176 | cgit_stats_link("stats", NULL, "button", ctx.qry.head, |
171 | fullpath); | 177 | fullpath); |
178 | cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev, | ||
179 | fullpath); | ||
172 | html("</td></tr>\n"); | 180 | html("</td></tr>\n"); |
173 | free(name); | 181 | free(name); |
174 | return 0; | 182 | return 0; |
175 | } | 183 | } |
176 | 184 | ||
177 | static void ls_head() | 185 | static void ls_head() |
178 | { | 186 | { |
179 | html("<table summary='tree listing' class='list'>\n"); | 187 | html("<table summary='tree listing' class='list'>\n"); |
180 | html("<tr class='nohover'>"); | 188 | html("<tr class='nohover'>"); |
181 | html("<th class='left'>Mode</th>"); | 189 | html("<th class='left'>Mode</th>"); |
182 | html("<th class='left'>Name</th>"); | 190 | html("<th class='left'>Name</th>"); |
183 | html("<th class='right'>Size</th>"); | 191 | html("<th class='right'>Size</th>"); |
184 | html("<th/>"); | 192 | html("<th/>"); |
185 | html("</tr>\n"); | 193 | html("</tr>\n"); |
186 | header = 1; | 194 | header = 1; |
187 | } | 195 | } |
188 | 196 | ||
189 | static void ls_tail() | 197 | static void ls_tail() |
190 | { | 198 | { |
191 | if (!header) | 199 | if (!header) |
192 | return; | 200 | return; |
193 | html("</table>\n"); | 201 | html("</table>\n"); |
194 | header = 0; | 202 | header = 0; |
195 | } | 203 | } |
196 | 204 | ||
197 | static void ls_tree(const unsigned char *sha1, char *path) | 205 | static void ls_tree(const unsigned char *sha1, char *path) |
198 | { | 206 | { |
199 | struct tree *tree; | 207 | struct tree *tree; |
200 | 208 | ||
201 | tree = parse_tree_indirect(sha1); | 209 | tree = parse_tree_indirect(sha1); |
202 | if (!tree) { | 210 | if (!tree) { |
203 | cgit_print_error(fmt("Not a tree object: %s", | 211 | cgit_print_error(fmt("Not a tree object: %s", |
204 | sha1_to_hex(sha1))); | 212 | sha1_to_hex(sha1))); |
205 | return; | 213 | return; |
206 | } | 214 | } |
207 | 215 | ||
208 | ls_head(); | 216 | ls_head(); |
209 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL); | 217 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL); |
210 | ls_tail(); | 218 | ls_tail(); |
211 | } | 219 | } |
212 | 220 | ||
213 | 221 | ||
214 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 222 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
215 | const char *pathname, unsigned mode, int stage, | 223 | const char *pathname, unsigned mode, int stage, |
216 | void *cbdata) | 224 | void *cbdata) |
217 | { | 225 | { |
218 | static int state; | 226 | static int state; |
219 | static char buffer[PATH_MAX]; | 227 | static char buffer[PATH_MAX]; |
220 | char *url; | ||
221 | 228 | ||
222 | if (state == 0) { | 229 | if (state == 0) { |
223 | memcpy(buffer, base, baselen); | 230 | memcpy(buffer, base, baselen); |
224 | strcpy(buffer+baselen, pathname); | 231 | strcpy(buffer+baselen, pathname); |
225 | url = cgit_pageurl(ctx.qry.repo, "tree", | ||
226 | fmt("h=%s&path=%s", curr_rev, buffer)); | ||
227 | html("/"); | ||
228 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, | ||
229 | curr_rev, buffer); | ||
230 | |||
231 | if (strcmp(match_path, buffer)) | 232 | if (strcmp(match_path, buffer)) |
232 | return READ_TREE_RECURSIVE; | 233 | return READ_TREE_RECURSIVE; |
233 | 234 | ||
234 | if (S_ISDIR(mode)) { | 235 | if (S_ISDIR(mode)) { |
235 | state = 1; | 236 | state = 1; |
236 | ls_head(); | 237 | ls_head(); |
237 | return READ_TREE_RECURSIVE; | 238 | return READ_TREE_RECURSIVE; |
238 | } else { | 239 | } else { |
239 | print_object(sha1, buffer, pathname); | 240 | print_object(sha1, buffer, pathname); |
240 | return 0; | 241 | return 0; |
241 | } | 242 | } |
242 | } | 243 | } |
243 | ls_item(sha1, base, baselen, pathname, mode, stage, NULL); | 244 | ls_item(sha1, base, baselen, pathname, mode, stage, NULL); |
244 | return 0; | 245 | return 0; |
245 | } | 246 | } |
246 | 247 | ||
247 | 248 | ||
248 | /* | 249 | /* |
249 | * Show a tree or a blob | 250 | * Show a tree or a blob |
250 | * rev: the commit pointing at the root tree object | 251 | * rev: the commit pointing at the root tree object |
251 | * path: path to tree or blob | 252 | * path: path to tree or blob |
252 | */ | 253 | */ |
253 | void cgit_print_tree(const char *rev, char *path) | 254 | void cgit_print_tree(const char *rev, char *path) |
254 | { | 255 | { |
255 | unsigned char sha1[20]; | 256 | unsigned char sha1[20]; |
256 | struct commit *commit; | 257 | struct commit *commit; |
257 | const char *paths[] = {path, NULL}; | 258 | const char *paths[] = {path, NULL}; |
258 | 259 | ||
259 | if (!rev) | 260 | if (!rev) |
260 | rev = ctx.qry.head; | 261 | rev = ctx.qry.head; |
261 | 262 | ||
262 | curr_rev = xstrdup(rev); | 263 | curr_rev = xstrdup(rev); |
263 | if (get_sha1(rev, sha1)) { | 264 | if (get_sha1(rev, sha1)) { |
264 | cgit_print_error(fmt("Invalid revision name: %s", rev)); | 265 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
265 | return; | 266 | return; |
266 | } | 267 | } |
267 | commit = lookup_commit_reference(sha1); | 268 | commit = lookup_commit_reference(sha1); |
268 | if (!commit || parse_commit(commit)) { | 269 | if (!commit || parse_commit(commit)) { |
269 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); | 270 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
270 | return; | 271 | return; |
271 | } | 272 | } |
272 | 273 | ||
273 | html("path: <a href='"); | ||
274 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); | ||
275 | html("'>root</a>"); | ||
276 | |||
277 | if (path == NULL) { | 274 | if (path == NULL) { |
278 | ls_tree(commit->tree->object.sha1, NULL); | 275 | ls_tree(commit->tree->object.sha1, NULL); |
279 | return; | 276 | return; |
280 | } | 277 | } |
281 | 278 | ||
282 | match_path = path; | 279 | match_path = path; |
283 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | 280 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); |
284 | ls_tail(); | 281 | ls_tail(); |
285 | } | 282 | } |
diff --git a/vector.c b/vector.c new file mode 100644 index 0000000..0863908 --- a/dev/null +++ b/vector.c | |||
@@ -0,0 +1,38 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include <errno.h> | ||
4 | #include "vector.h" | ||
5 | |||
6 | static int grow(struct vector *vec, int gently) | ||
7 | { | ||
8 | size_t new_alloc; | ||
9 | void *new_data; | ||
10 | |||
11 | new_alloc = vec->alloc * 3 / 2; | ||
12 | if (!new_alloc) | ||
13 | new_alloc = 8; | ||
14 | new_data = realloc(vec->data, new_alloc * vec->size); | ||
15 | if (!new_data) { | ||
16 | if (gently) | ||
17 | return ENOMEM; | ||
18 | perror("vector.c:grow()"); | ||
19 | exit(1); | ||
20 | } | ||
21 | vec->data = new_data; | ||
22 | vec->alloc = new_alloc; | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | int vector_push(struct vector *vec, const void *data, int gently) | ||
27 | { | ||
28 | int rc; | ||
29 | |||
30 | if (vec->count == vec->alloc && (rc = grow(vec, gently))) | ||
31 | return rc; | ||
32 | if (data) | ||
33 | memmove(vec->data + vec->count * vec->size, data, vec->size); | ||
34 | else | ||
35 | memset(vec->data + vec->count * vec->size, 0, vec->size); | ||
36 | vec->count++; | ||
37 | return 0; | ||
38 | } | ||
diff --git a/vector.h b/vector.h new file mode 100644 index 0000000..c64eb1f --- a/dev/null +++ b/vector.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef CGIT_VECTOR_H | ||
2 | #define CGIT_VECTOR_H | ||
3 | |||
4 | #include <stdlib.h> | ||
5 | |||
6 | struct vector { | ||
7 | size_t size; | ||
8 | size_t count; | ||
9 | size_t alloc; | ||
10 | void *data; | ||
11 | }; | ||
12 | |||
13 | #define VECTOR_INIT(type) {sizeof(type), 0, 0, NULL} | ||
14 | |||
15 | int vector_push(struct vector *vec, const void *data, int gently); | ||
16 | |||
17 | #endif /* CGIT_VECTOR_H */ | ||