-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | html.c | 4 | ||||
-rw-r--r-- | ui-log.c | 71 | ||||
-rw-r--r-- | vector.c | 38 | ||||
-rw-r--r-- | vector.h | 17 |
5 files changed, 118 insertions, 13 deletions
@@ -1,243 +1,244 @@ | |||
1 | CGIT_VERSION = v0.8.3.4 | 1 | CGIT_VERSION = v0.8.3.4 |
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 | 7 | prefix = /usr |
8 | libdir = $(prefix)/lib | 8 | libdir = $(prefix)/lib |
9 | filterdir = $(libdir)/cgit/filters | 9 | filterdir = $(libdir)/cgit/filters |
10 | docdir = $(prefix)/share/doc/cgit | 10 | docdir = $(prefix)/share/doc/cgit |
11 | htmldir = $(docdir) | 11 | htmldir = $(docdir) |
12 | pdfdir = $(docdir) | 12 | pdfdir = $(docdir) |
13 | mandir = $(prefix)/share/man | 13 | mandir = $(prefix)/share/man |
14 | SHA1_HEADER = <openssl/sha.h> | 14 | SHA1_HEADER = <openssl/sha.h> |
15 | GIT_VER = 1.7.4 | 15 | GIT_VER = 1.7.4 |
16 | 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 |
17 | INSTALL = install | 17 | INSTALL = install |
18 | MAN5_TXT = $(wildcard *.5.txt) | 18 | MAN5_TXT = $(wildcard *.5.txt) |
19 | MAN_TXT = $(MAN5_TXT) | 19 | MAN_TXT = $(MAN5_TXT) |
20 | DOC_MAN5 = $(patsubst %.txt,%,$(MAN5_TXT)) | 20 | DOC_MAN5 = $(patsubst %.txt,%,$(MAN5_TXT)) |
21 | DOC_HTML = $(patsubst %.txt,%.html,$(MAN_TXT)) | 21 | DOC_HTML = $(patsubst %.txt,%.html,$(MAN_TXT)) |
22 | DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) | 22 | DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) |
23 | 23 | ||
24 | # Define NO_STRCASESTR if you don't have strcasestr. | 24 | # Define NO_STRCASESTR if you don't have strcasestr. |
25 | # | 25 | # |
26 | # Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 | 26 | # Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 |
27 | # implementation (slower). | 27 | # implementation (slower). |
28 | # | 28 | # |
29 | # 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). |
30 | # | 30 | # |
31 | # Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.) | 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, | 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). | 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. | 34 | # some C compilers supported these specifiers prior to C99 as an extension. |
35 | # | 35 | # |
36 | 36 | ||
37 | #-include config.mak | 37 | #-include config.mak |
38 | 38 | ||
39 | # | 39 | # |
40 | # Platform specific tweaks | 40 | # Platform specific tweaks |
41 | # | 41 | # |
42 | 42 | ||
43 | 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') |
44 | 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') |
45 | 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') |
46 | 46 | ||
47 | ifeq ($(uname_O),Cygwin) | 47 | ifeq ($(uname_O),Cygwin) |
48 | NO_STRCASESTR = YesPlease | 48 | NO_STRCASESTR = YesPlease |
49 | NEEDS_LIBICONV = YesPlease | 49 | NEEDS_LIBICONV = YesPlease |
50 | endif | 50 | endif |
51 | 51 | ||
52 | # | 52 | # |
53 | # Let the user override the above settings. | 53 | # Let the user override the above settings. |
54 | # | 54 | # |
55 | -include cgit.conf | 55 | -include cgit.conf |
56 | 56 | ||
57 | # | 57 | # |
58 | # Define a way to invoke make in subdirs quietly, shamelessly ripped | 58 | # Define a way to invoke make in subdirs quietly, shamelessly ripped |
59 | # from git.git | 59 | # from git.git |
60 | # | 60 | # |
61 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | 61 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir |
62 | QUIET_SUBDIR1 = | 62 | QUIET_SUBDIR1 = |
63 | 63 | ||
64 | ifneq ($(findstring $(MAKEFLAGS),w),w) | 64 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
65 | PRINT_DIR = --no-print-directory | 65 | PRINT_DIR = --no-print-directory |
66 | else # "make -w" | 66 | else # "make -w" |
67 | NO_SUBDIR = : | 67 | NO_SUBDIR = : |
68 | endif | 68 | endif |
69 | 69 | ||
70 | ifndef V | 70 | ifndef V |
71 | QUIET_CC = @echo ' ' CC $@; | 71 | QUIET_CC = @echo ' ' CC $@; |
72 | QUIET_MM = @echo ' ' MM $@; | 72 | QUIET_MM = @echo ' ' MM $@; |
73 | QUIET_SUBDIR0 = +@subdir= | 73 | QUIET_SUBDIR0 = +@subdir= |
74 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ | 74 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ |
75 | $(MAKE) $(PRINT_DIR) -C $$subdir | 75 | $(MAKE) $(PRINT_DIR) -C $$subdir |
76 | endif | 76 | endif |
77 | 77 | ||
78 | # | 78 | # |
79 | # Define a pattern rule for automatic dependency building | 79 | # Define a pattern rule for automatic dependency building |
80 | # | 80 | # |
81 | %.d: %.c | 81 | %.d: %.c |
82 | $(QUIET_MM)$(CC) $(CFLAGS) -MM -MP $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ | 82 | $(QUIET_MM)$(CC) $(CFLAGS) -MM -MP $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ |
83 | 83 | ||
84 | # | 84 | # |
85 | # Define a pattern rule for silent object building | 85 | # Define a pattern rule for silent object building |
86 | # | 86 | # |
87 | %.o: %.c | 87 | %.o: %.c |
88 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< | 88 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< |
89 | 89 | ||
90 | 90 | ||
91 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread | 91 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread |
92 | OBJECTS = | 92 | OBJECTS = |
93 | OBJECTS += cache.o | 93 | OBJECTS += cache.o |
94 | OBJECTS += cgit.o | 94 | OBJECTS += cgit.o |
95 | OBJECTS += cmd.o | 95 | OBJECTS += cmd.o |
96 | OBJECTS += configfile.o | 96 | OBJECTS += configfile.o |
97 | OBJECTS += html.o | 97 | OBJECTS += html.o |
98 | OBJECTS += parsing.o | 98 | OBJECTS += parsing.o |
99 | OBJECTS += scan-tree.o | 99 | OBJECTS += scan-tree.o |
100 | OBJECTS += shared.o | 100 | OBJECTS += shared.o |
101 | OBJECTS += ui-atom.o | 101 | OBJECTS += ui-atom.o |
102 | OBJECTS += ui-blob.o | 102 | OBJECTS += ui-blob.o |
103 | OBJECTS += ui-clone.o | 103 | OBJECTS += ui-clone.o |
104 | OBJECTS += ui-commit.o | 104 | OBJECTS += ui-commit.o |
105 | OBJECTS += ui-diff.o | 105 | OBJECTS += ui-diff.o |
106 | OBJECTS += ui-log.o | 106 | OBJECTS += ui-log.o |
107 | OBJECTS += ui-patch.o | 107 | OBJECTS += ui-patch.o |
108 | OBJECTS += ui-plain.o | 108 | OBJECTS += ui-plain.o |
109 | OBJECTS += ui-refs.o | 109 | OBJECTS += ui-refs.o |
110 | OBJECTS += ui-repolist.o | 110 | OBJECTS += ui-repolist.o |
111 | OBJECTS += ui-shared.o | 111 | OBJECTS += ui-shared.o |
112 | OBJECTS += ui-snapshot.o | 112 | OBJECTS += ui-snapshot.o |
113 | OBJECTS += ui-ssdiff.o | 113 | OBJECTS += ui-ssdiff.o |
114 | OBJECTS += ui-stats.o | 114 | OBJECTS += ui-stats.o |
115 | OBJECTS += ui-summary.o | 115 | OBJECTS += ui-summary.o |
116 | OBJECTS += ui-tag.o | 116 | OBJECTS += ui-tag.o |
117 | OBJECTS += ui-tree.o | 117 | OBJECTS += ui-tree.o |
118 | OBJECTS += vector.o | ||
118 | 119 | ||
119 | ifdef NEEDS_LIBICONV | 120 | ifdef NEEDS_LIBICONV |
120 | EXTLIBS += -liconv | 121 | EXTLIBS += -liconv |
121 | endif | 122 | endif |
122 | 123 | ||
123 | 124 | ||
124 | .PHONY: all libgit test install uninstall clean force-version get-git \ | 125 | .PHONY: all libgit test install uninstall clean force-version get-git \ |
125 | doc clean-doc install-doc install-man install-html install-pdf \ | 126 | doc clean-doc install-doc install-man install-html install-pdf \ |
126 | uninstall-doc uninstall-man uninstall-html uninstall-pdf | 127 | uninstall-doc uninstall-man uninstall-html uninstall-pdf |
127 | 128 | ||
128 | all: cgit | 129 | all: cgit |
129 | 130 | ||
130 | VERSION: force-version | 131 | VERSION: force-version |
131 | @./gen-version.sh "$(CGIT_VERSION)" | 132 | @./gen-version.sh "$(CGIT_VERSION)" |
132 | -include VERSION | 133 | -include VERSION |
133 | 134 | ||
134 | 135 | ||
135 | CFLAGS += -g -Wall -Igit | 136 | CFLAGS += -g -Wall -Igit |
136 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 137 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
137 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 138 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
138 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 139 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
139 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 140 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
140 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 141 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
141 | 142 | ||
142 | GIT_OPTIONS = prefix=/usr | 143 | GIT_OPTIONS = prefix=/usr |
143 | 144 | ||
144 | ifdef NO_ICONV | 145 | ifdef NO_ICONV |
145 | CFLAGS += -DNO_ICONV | 146 | CFLAGS += -DNO_ICONV |
146 | endif | 147 | endif |
147 | ifdef NO_STRCASESTR | 148 | ifdef NO_STRCASESTR |
148 | CFLAGS += -DNO_STRCASESTR | 149 | CFLAGS += -DNO_STRCASESTR |
149 | endif | 150 | endif |
150 | ifdef NO_C99_FORMAT | 151 | ifdef NO_C99_FORMAT |
151 | CFLAGS += -DNO_C99_FORMAT | 152 | CFLAGS += -DNO_C99_FORMAT |
152 | endif | 153 | endif |
153 | ifdef NO_OPENSSL | 154 | ifdef NO_OPENSSL |
154 | CFLAGS += -DNO_OPENSSL | 155 | CFLAGS += -DNO_OPENSSL |
155 | GIT_OPTIONS += NO_OPENSSL=1 | 156 | GIT_OPTIONS += NO_OPENSSL=1 |
156 | else | 157 | else |
157 | EXTLIBS += -lcrypto | 158 | EXTLIBS += -lcrypto |
158 | endif | 159 | endif |
159 | 160 | ||
160 | cgit: $(OBJECTS) libgit | 161 | cgit: $(OBJECTS) libgit |
161 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) | 162 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
162 | 163 | ||
163 | cgit.o: VERSION | 164 | cgit.o: VERSION |
164 | 165 | ||
165 | ifneq "$(MAKECMDGOALS)" "clean" | 166 | ifneq "$(MAKECMDGOALS)" "clean" |
166 | -include $(OBJECTS:.o=.d) | 167 | -include $(OBJECTS:.o=.d) |
167 | endif | 168 | endif |
168 | 169 | ||
169 | libgit: | 170 | libgit: |
170 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a | 171 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a |
171 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a | 172 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a |
172 | 173 | ||
173 | test: all | 174 | test: all |
174 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all | 175 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
175 | 176 | ||
176 | install: all | 177 | install: all |
177 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) | 178 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) |
178 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 179 | $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
179 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) | 180 | $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) |
180 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css | 181 | $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css |
181 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png | 182 | $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png |
182 | $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) | 183 | $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) |
183 | $(INSTALL) -m 0755 filters/* $(DESTDIR)$(filterdir) | 184 | $(INSTALL) -m 0755 filters/* $(DESTDIR)$(filterdir) |
184 | 185 | ||
185 | install-doc: install-man install-html install-pdf | 186 | install-doc: install-man install-html install-pdf |
186 | 187 | ||
187 | install-man: doc-man | 188 | install-man: doc-man |
188 | $(INSTALL) -m 0755 -d $(DESTDIR)$(mandir)/man5 | 189 | $(INSTALL) -m 0755 -d $(DESTDIR)$(mandir)/man5 |
189 | $(INSTALL) -m 0644 $(DOC_MAN5) $(DESTDIR)$(mandir)/man5 | 190 | $(INSTALL) -m 0644 $(DOC_MAN5) $(DESTDIR)$(mandir)/man5 |
190 | 191 | ||
191 | install-html: doc-html | 192 | install-html: doc-html |
192 | $(INSTALL) -m 0755 -d $(DESTDIR)$(htmldir) | 193 | $(INSTALL) -m 0755 -d $(DESTDIR)$(htmldir) |
193 | $(INSTALL) -m 0644 $(DOC_HTML) $(DESTDIR)$(htmldir) | 194 | $(INSTALL) -m 0644 $(DOC_HTML) $(DESTDIR)$(htmldir) |
194 | 195 | ||
195 | install-pdf: doc-pdf | 196 | install-pdf: doc-pdf |
196 | $(INSTALL) -m 0755 -d $(DESTDIR)$(pdfdir) | 197 | $(INSTALL) -m 0755 -d $(DESTDIR)$(pdfdir) |
197 | $(INSTALL) -m 0644 $(DOC_PDF) $(DESTDIR)$(pdfdir) | 198 | $(INSTALL) -m 0644 $(DOC_PDF) $(DESTDIR)$(pdfdir) |
198 | 199 | ||
199 | uninstall: | 200 | uninstall: |
200 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 201 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
201 | rm -f $(CGIT_DATA_PATH)/cgit.css | 202 | rm -f $(CGIT_DATA_PATH)/cgit.css |
202 | rm -f $(CGIT_DATA_PATH)/cgit.png | 203 | rm -f $(CGIT_DATA_PATH)/cgit.png |
203 | 204 | ||
204 | uninstall-doc: uninstall-man uninstall-html uninstall-pdf | 205 | uninstall-doc: uninstall-man uninstall-html uninstall-pdf |
205 | 206 | ||
206 | uninstall-man: | 207 | uninstall-man: |
207 | @for i in $(DOC_MAN5); do \ | 208 | @for i in $(DOC_MAN5); do \ |
208 | rm -fv $(DESTDIR)$(mandir)/man5/$$i; \ | 209 | rm -fv $(DESTDIR)$(mandir)/man5/$$i; \ |
209 | done | 210 | done |
210 | 211 | ||
211 | uninstall-html: | 212 | uninstall-html: |
212 | @for i in $(DOC_HTML); do \ | 213 | @for i in $(DOC_HTML); do \ |
213 | rm -fv $(DESTDIR)$(htmldir)/$$i; \ | 214 | rm -fv $(DESTDIR)$(htmldir)/$$i; \ |
214 | done | 215 | done |
215 | 216 | ||
216 | uninstall-pdf: | 217 | uninstall-pdf: |
217 | @for i in $(DOC_PDF); do \ | 218 | @for i in $(DOC_PDF); do \ |
218 | rm -fv $(DESTDIR)$(pdfdir)/$$i; \ | 219 | rm -fv $(DESTDIR)$(pdfdir)/$$i; \ |
219 | done | 220 | done |
220 | 221 | ||
221 | doc: doc-man doc-html doc-pdf | 222 | doc: doc-man doc-html doc-pdf |
222 | doc-man: doc-man5 | 223 | doc-man: doc-man5 |
223 | doc-man5: $(DOC_MAN5) | 224 | doc-man5: $(DOC_MAN5) |
224 | doc-html: $(DOC_HTML) | 225 | doc-html: $(DOC_HTML) |
225 | doc-pdf: $(DOC_PDF) | 226 | doc-pdf: $(DOC_PDF) |
226 | 227 | ||
227 | %.5 : %.5.txt | 228 | %.5 : %.5.txt |
228 | a2x -f manpage $< | 229 | a2x -f manpage $< |
229 | 230 | ||
230 | $(DOC_HTML): %.html : %.txt | 231 | $(DOC_HTML): %.html : %.txt |
231 | a2x -f xhtml --stylesheet=cgit-doc.css $< | 232 | a2x -f xhtml --stylesheet=cgit-doc.css $< |
232 | 233 | ||
233 | $(DOC_PDF): %.pdf : %.txt | 234 | $(DOC_PDF): %.pdf : %.txt |
234 | a2x -f pdf cgitrc.5.txt | 235 | a2x -f pdf cgitrc.5.txt |
235 | 236 | ||
236 | clean: clean-doc | 237 | clean: clean-doc |
237 | rm -f cgit VERSION *.o *.d | 238 | rm -f cgit VERSION *.o *.d |
238 | 239 | ||
239 | clean-doc: | 240 | clean-doc: |
240 | 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 |
241 | 242 | ||
242 | get-git: | 243 | get-git: |
243 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 244 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
@@ -1,320 +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!$()*,./:;@- */ | 16 | /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */ |
17 | static const char* url_escape_table[256] = { | 17 | static const char* url_escape_table[256] = { |
18 | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", | 18 | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", |
19 | "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", | 19 | "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", |
20 | "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", | 20 | "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", |
21 | "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, | 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", | 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, | 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, | 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", | 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", | 26 | "%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85", |
27 | "%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", | 27 | "%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", |
28 | "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", | 28 | "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", |
29 | "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3", | 29 | "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3", |
30 | "%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", | 30 | "%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", |
31 | "%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", | 31 | "%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", |
32 | "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1", | 32 | "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1", |
33 | "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb", | 33 | "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb", |
34 | "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", | 34 | "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", |
35 | "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df", | 35 | "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df", |
36 | "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9", | 36 | "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9", |
37 | "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3", | 37 | "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3", |
38 | "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", | 38 | "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", |
39 | "%fe", "%ff" | 39 | "%fe", "%ff" |
40 | }; | 40 | }; |
41 | 41 | ||
42 | int htmlfd = STDOUT_FILENO; | 42 | int htmlfd = STDOUT_FILENO; |
43 | 43 | ||
44 | char *fmt(const char *format, ...) | 44 | char *fmt(const char *format, ...) |
45 | { | 45 | { |
46 | static char buf[8][1024]; | 46 | static char buf[8][1024]; |
47 | static int bufidx; | 47 | static int bufidx; |
48 | int len; | 48 | int len; |
49 | va_list args; | 49 | va_list args; |
50 | 50 | ||
51 | bufidx++; | 51 | bufidx++; |
52 | bufidx &= 7; | 52 | bufidx &= 7; |
53 | 53 | ||
54 | va_start(args, format); | 54 | va_start(args, format); |
55 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 55 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
56 | va_end(args); | 56 | va_end(args); |
57 | if (len>sizeof(buf[bufidx])) { | 57 | if (len>sizeof(buf[bufidx])) { |
58 | fprintf(stderr, "[html.c] string truncated: %s\n", format); | 58 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
59 | exit(1); | 59 | exit(1); |
60 | } | 60 | } |
61 | return buf[bufidx]; | 61 | return buf[bufidx]; |
62 | } | 62 | } |
63 | 63 | ||
64 | void html_raw(const char *data, size_t size) | 64 | void html_raw(const char *data, size_t size) |
65 | { | 65 | { |
66 | write(htmlfd, data, size); | 66 | write(htmlfd, data, size); |
67 | } | 67 | } |
68 | 68 | ||
69 | void html(const char *txt) | 69 | void html(const char *txt) |
70 | { | 70 | { |
71 | write(htmlfd, txt, strlen(txt)); | 71 | write(htmlfd, txt, strlen(txt)); |
72 | } | 72 | } |
73 | 73 | ||
74 | void htmlf(const char *format, ...) | 74 | void htmlf(const char *format, ...) |
75 | { | 75 | { |
76 | static char buf[65536]; | 76 | static char buf[65536]; |
77 | va_list args; | 77 | va_list args; |
78 | 78 | ||
79 | va_start(args, format); | 79 | va_start(args, format); |
80 | vsnprintf(buf, sizeof(buf), format, args); | 80 | vsnprintf(buf, sizeof(buf), format, args); |
81 | va_end(args); | 81 | va_end(args); |
82 | html(buf); | 82 | html(buf); |
83 | } | 83 | } |
84 | 84 | ||
85 | void html_status(int code, const char *msg, int more_headers) | 85 | void html_status(int code, const char *msg, int more_headers) |
86 | { | 86 | { |
87 | htmlf("Status: %d %s\n", code, msg); | 87 | htmlf("Status: %d %s\n", code, msg); |
88 | if (!more_headers) | 88 | if (!more_headers) |
89 | html("\n"); | 89 | html("\n"); |
90 | } | 90 | } |
91 | 91 | ||
92 | void html_txt(const char *txt) | 92 | void html_txt(const char *txt) |
93 | { | 93 | { |
94 | const char *t = txt; | 94 | const char *t = txt; |
95 | while(t && *t){ | 95 | while(t && *t){ |
96 | int c = *t; | 96 | int c = *t; |
97 | if (c=='<' || c=='>' || c=='&') { | 97 | if (c=='<' || c=='>' || c=='&') { |
98 | html_raw(txt, t - txt); | 98 | html_raw(txt, t - txt); |
99 | if (c=='>') | 99 | if (c=='>') |
100 | html(">"); | 100 | html(">"); |
101 | else if (c=='<') | 101 | else if (c=='<') |
102 | html("<"); | 102 | html("<"); |
103 | else if (c=='&') | 103 | else if (c=='&') |
104 | html("&"); | 104 | html("&"); |
105 | txt = t+1; | 105 | txt = t+1; |
106 | } | 106 | } |
107 | t++; | 107 | t++; |
108 | } | 108 | } |
109 | if (t!=txt) | 109 | if (t!=txt) |
110 | html(txt); | 110 | html(txt); |
111 | } | 111 | } |
112 | 112 | ||
113 | void html_ntxt(int len, const char *txt) | 113 | void html_ntxt(int len, const char *txt) |
114 | { | 114 | { |
115 | const char *t = txt; | 115 | const char *t = txt; |
116 | while(t && *t && len--){ | 116 | while(t && *t && len--){ |
117 | int c = *t; | 117 | int c = *t; |
118 | if (c=='<' || c=='>' || c=='&') { | 118 | if (c=='<' || c=='>' || c=='&') { |
119 | html_raw(txt, t - txt); | 119 | html_raw(txt, t - txt); |
120 | if (c=='>') | 120 | if (c=='>') |
121 | html(">"); | 121 | html(">"); |
122 | else if (c=='<') | 122 | else if (c=='<') |
123 | html("<"); | 123 | html("<"); |
124 | else if (c=='&') | 124 | else if (c=='&') |
125 | html("&"); | 125 | html("&"); |
126 | txt = t+1; | 126 | txt = t+1; |
127 | } | 127 | } |
128 | t++; | 128 | t++; |
129 | } | 129 | } |
130 | if (t!=txt) | 130 | if (t!=txt) |
131 | html_raw(txt, t - txt); | 131 | html_raw(txt, t - txt); |
132 | if (len<0) | 132 | if (len<0) |
133 | html("..."); | 133 | html("..."); |
134 | } | 134 | } |
135 | 135 | ||
136 | void html_attr(const char *txt) | 136 | void html_attr(const char *txt) |
137 | { | 137 | { |
138 | const char *t = txt; | 138 | const char *t = txt; |
139 | while(t && *t){ | 139 | while(t && *t){ |
140 | int c = *t; | 140 | int c = *t; |
141 | if (c=='<' || c=='>' || c=='\'' || c=='\"') { | 141 | if (c=='<' || c=='>' || c=='\'' || c=='\"') { |
142 | html_raw(txt, t - txt); | 142 | html_raw(txt, t - txt); |
143 | if (c=='>') | 143 | if (c=='>') |
144 | html(">"); | 144 | html(">"); |
145 | else if (c=='<') | 145 | else if (c=='<') |
146 | html("<"); | 146 | html("<"); |
147 | else if (c=='\'') | 147 | else if (c=='\'') |
148 | html("'"); | 148 | html("'"); |
149 | else if (c=='"') | 149 | else if (c=='"') |
150 | html("""); | 150 | html("""); |
151 | txt = t+1; | 151 | txt = t+1; |
152 | } | 152 | } |
153 | t++; | 153 | t++; |
154 | } | 154 | } |
155 | if (t!=txt) | 155 | if (t!=txt) |
156 | html(txt); | 156 | html(txt); |
157 | } | 157 | } |
158 | 158 | ||
159 | void html_url_path(const char *txt) | 159 | void html_url_path(const char *txt) |
160 | { | 160 | { |
161 | const char *t = txt; | 161 | const char *t = txt; |
162 | while(t && *t){ | 162 | while(t && *t){ |
163 | int c = *t; | 163 | int c = *t; |
164 | const char *e = url_escape_table[c]; | 164 | const char *e = url_escape_table[c]; |
165 | if (e && c!='+' && c!='&' && c!='+') { | 165 | if (e && c!='+' && c!='&' && c!='+') { |
166 | html_raw(txt, t - txt); | 166 | html_raw(txt, t - txt); |
167 | html_raw(e, 3); | 167 | html_raw(e, 3); |
168 | txt = t+1; | 168 | txt = t+1; |
169 | } | 169 | } |
170 | t++; | 170 | t++; |
171 | } | 171 | } |
172 | if (t!=txt) | 172 | if (t!=txt) |
173 | html(txt); | 173 | html(txt); |
174 | } | 174 | } |
175 | 175 | ||
176 | void html_url_arg(const char *txt) | 176 | void html_url_arg(const char *txt) |
177 | { | 177 | { |
178 | const char *t = txt; | 178 | const char *t = txt; |
179 | while(t && *t){ | 179 | while(t && *t){ |
180 | int c = *t; | 180 | int c = *t; |
181 | const char *e = url_escape_table[c]; | 181 | const char *e = url_escape_table[c]; |
182 | if (e) { | 182 | if (e) { |
183 | html_raw(txt, t - txt); | 183 | html_raw(txt, t - txt); |
184 | html_raw(e, 3); | 184 | html_raw(e, strlen(e)); |
185 | txt = t+1; | 185 | txt = t+1; |
186 | } | 186 | } |
187 | t++; | 187 | t++; |
188 | } | 188 | } |
189 | if (t!=txt) | 189 | if (t!=txt) |
190 | html(txt); | 190 | html(txt); |
191 | } | 191 | } |
192 | 192 | ||
193 | void html_hidden(const char *name, const char *value) | 193 | void html_hidden(const char *name, const char *value) |
194 | { | 194 | { |
195 | html("<input type='hidden' name='"); | 195 | html("<input type='hidden' name='"); |
196 | html_attr(name); | 196 | html_attr(name); |
197 | html("' value='"); | 197 | html("' value='"); |
198 | html_attr(value); | 198 | html_attr(value); |
199 | html("'/>"); | 199 | html("'/>"); |
200 | } | 200 | } |
201 | 201 | ||
202 | void html_option(const char *value, const char *text, const char *selected_value) | 202 | void html_option(const char *value, const char *text, const char *selected_value) |
203 | { | 203 | { |
204 | html("<option value='"); | 204 | html("<option value='"); |
205 | html_attr(value); | 205 | html_attr(value); |
206 | html("'"); | 206 | html("'"); |
207 | if (selected_value && !strcmp(selected_value, value)) | 207 | if (selected_value && !strcmp(selected_value, value)) |
208 | html(" selected='selected'"); | 208 | html(" selected='selected'"); |
209 | html(">"); | 209 | html(">"); |
210 | html_txt(text); | 210 | html_txt(text); |
211 | html("</option>\n"); | 211 | html("</option>\n"); |
212 | } | 212 | } |
213 | 213 | ||
214 | void html_link_open(const char *url, const char *title, const char *class) | 214 | void html_link_open(const char *url, const char *title, const char *class) |
215 | { | 215 | { |
216 | html("<a href='"); | 216 | html("<a href='"); |
217 | html_attr(url); | 217 | html_attr(url); |
218 | if (title) { | 218 | if (title) { |
219 | html("' title='"); | 219 | html("' title='"); |
220 | html_attr(title); | 220 | html_attr(title); |
221 | } | 221 | } |
222 | if (class) { | 222 | if (class) { |
223 | html("' class='"); | 223 | html("' class='"); |
224 | html_attr(class); | 224 | html_attr(class); |
225 | } | 225 | } |
226 | html("'>"); | 226 | html("'>"); |
227 | } | 227 | } |
228 | 228 | ||
229 | void html_link_close(void) | 229 | void html_link_close(void) |
230 | { | 230 | { |
231 | html("</a>"); | 231 | html("</a>"); |
232 | } | 232 | } |
233 | 233 | ||
234 | void html_fileperm(unsigned short mode) | 234 | void html_fileperm(unsigned short mode) |
235 | { | 235 | { |
236 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 236 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
237 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 237 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
238 | } | 238 | } |
239 | 239 | ||
240 | int html_include(const char *filename) | 240 | int html_include(const char *filename) |
241 | { | 241 | { |
242 | FILE *f; | 242 | FILE *f; |
243 | char buf[4096]; | 243 | char buf[4096]; |
244 | size_t len; | 244 | size_t len; |
245 | 245 | ||
246 | if (!(f = fopen(filename, "r"))) { | 246 | if (!(f = fopen(filename, "r"))) { |
247 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", | 247 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", |
248 | filename, strerror(errno), errno); | 248 | filename, strerror(errno), errno); |
249 | return -1; | 249 | return -1; |
250 | } | 250 | } |
251 | while((len = fread(buf, 1, 4096, f)) > 0) | 251 | while((len = fread(buf, 1, 4096, f)) > 0) |
252 | html_raw(buf, len); | 252 | html_raw(buf, len); |
253 | fclose(f); | 253 | fclose(f); |
254 | return 0; | 254 | return 0; |
255 | } | 255 | } |
256 | 256 | ||
257 | int hextoint(char c) | 257 | int hextoint(char c) |
258 | { | 258 | { |
259 | if (c >= 'a' && c <= 'f') | 259 | if (c >= 'a' && c <= 'f') |
260 | return 10 + c - 'a'; | 260 | return 10 + c - 'a'; |
261 | else if (c >= 'A' && c <= 'F') | 261 | else if (c >= 'A' && c <= 'F') |
262 | return 10 + c - 'A'; | 262 | return 10 + c - 'A'; |
263 | else if (c >= '0' && c <= '9') | 263 | else if (c >= '0' && c <= '9') |
264 | return c - '0'; | 264 | return c - '0'; |
265 | else | 265 | else |
266 | return -1; | 266 | return -1; |
267 | } | 267 | } |
268 | 268 | ||
269 | char *convert_query_hexchar(char *txt) | 269 | char *convert_query_hexchar(char *txt) |
270 | { | 270 | { |
271 | int d1, d2, n; | 271 | int d1, d2, n; |
272 | n = strlen(txt); | 272 | n = strlen(txt); |
273 | if (n < 3) { | 273 | if (n < 3) { |
274 | *txt = '\0'; | 274 | *txt = '\0'; |
275 | return txt-1; | 275 | return txt-1; |
276 | } | 276 | } |
277 | d1 = hextoint(*(txt+1)); | 277 | d1 = hextoint(*(txt+1)); |
278 | d2 = hextoint(*(txt+2)); | 278 | d2 = hextoint(*(txt+2)); |
279 | if (d1<0 || d2<0) { | 279 | if (d1<0 || d2<0) { |
280 | memmove(txt, txt+3, n-3); | 280 | memmove(txt, txt+3, n-3); |
281 | return txt-1; | 281 | return txt-1; |
282 | } else { | 282 | } else { |
283 | *txt = d1 * 16 + d2; | 283 | *txt = d1 * 16 + d2; |
284 | memmove(txt+1, txt+3, n-2); | 284 | memmove(txt+1, txt+3, n-2); |
285 | return txt; | 285 | return txt; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||
289 | int http_parse_querystring(const 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)) |
290 | { | 290 | { |
291 | char *t, *txt, *value = NULL, c; | 291 | char *t, *txt, *value = NULL, c; |
292 | 292 | ||
293 | if (!txt_) | 293 | if (!txt_) |
294 | return 0; | 294 | return 0; |
295 | 295 | ||
296 | t = txt = strdup(txt_); | 296 | t = txt = strdup(txt_); |
297 | if (t == NULL) { | 297 | if (t == NULL) { |
298 | printf("Out of memory\n"); | 298 | printf("Out of memory\n"); |
299 | exit(1); | 299 | exit(1); |
300 | } | 300 | } |
301 | while((c=*t) != '\0') { | 301 | while((c=*t) != '\0') { |
302 | if (c=='=') { | 302 | if (c=='=') { |
303 | *t = '\0'; | 303 | *t = '\0'; |
304 | value = t+1; | 304 | value = t+1; |
305 | } else if (c=='+') { | 305 | } else if (c=='+') { |
306 | *t = ' '; | 306 | *t = ' '; |
307 | } else if (c=='%') { | 307 | } else if (c=='%') { |
308 | t = convert_query_hexchar(t); | 308 | t = convert_query_hexchar(t); |
309 | } else if (c=='&') { | 309 | } else if (c=='&') { |
310 | *t = '\0'; | 310 | *t = '\0'; |
311 | (*fn)(txt, value); | 311 | (*fn)(txt, value); |
312 | txt = t+1; | 312 | txt = t+1; |
313 | value = NULL; | 313 | value = NULL; |
314 | } | 314 | } |
315 | t++; | 315 | t++; |
316 | } | 316 | } |
317 | if (t!=txt) | 317 | if (t!=txt) |
318 | (*fn)(txt, value); | 318 | (*fn)(txt, value); |
319 | return 0; | 319 | return 0; |
320 | } | 320 | } |
@@ -1,252 +1,301 @@ | |||
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 | ||
15 | void count_lines(char *line, int size) | 16 | void count_lines(char *line, int size) |
16 | { | 17 | { |
17 | if (size <= 0) | 18 | if (size <= 0) |
18 | return; | 19 | return; |
19 | 20 | ||
20 | if (line[0] == '+') | 21 | if (line[0] == '+') |
21 | add_lines++; | 22 | add_lines++; |
22 | 23 | ||
23 | else if (line[0] == '-') | 24 | else if (line[0] == '-') |
24 | rem_lines++; | 25 | rem_lines++; |
25 | } | 26 | } |
26 | 27 | ||
27 | void inspect_files(struct diff_filepair *pair) | 28 | void inspect_files(struct diff_filepair *pair) |
28 | { | 29 | { |
29 | unsigned long old_size = 0; | 30 | unsigned long old_size = 0; |
30 | unsigned long new_size = 0; | 31 | unsigned long new_size = 0; |
31 | int binary = 0; | 32 | int binary = 0; |
32 | 33 | ||
33 | files++; | 34 | files++; |
34 | if (ctx.repo->enable_log_linecount) | 35 | if (ctx.repo->enable_log_linecount) |
35 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 36 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
36 | &new_size, &binary, 0, ctx.qry.ignorews, | 37 | &new_size, &binary, 0, ctx.qry.ignorews, |
37 | count_lines); | 38 | count_lines); |
38 | } | 39 | } |
39 | 40 | ||
40 | void show_commit_decorations(struct commit *commit) | 41 | void show_commit_decorations(struct commit *commit) |
41 | { | 42 | { |
42 | struct name_decoration *deco; | 43 | struct name_decoration *deco; |
43 | static char buf[1024]; | 44 | static char buf[1024]; |
44 | 45 | ||
45 | buf[sizeof(buf) - 1] = 0; | 46 | buf[sizeof(buf) - 1] = 0; |
46 | deco = lookup_decoration(&name_decoration, &commit->object); | 47 | deco = lookup_decoration(&name_decoration, &commit->object); |
47 | while (deco) { | 48 | while (deco) { |
48 | if (!prefixcmp(deco->name, "refs/heads/")) { | 49 | if (!prefixcmp(deco->name, "refs/heads/")) { |
49 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); | 50 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); |
50 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, | 51 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, |
51 | ctx.qry.vpath, 0, NULL, NULL, | 52 | ctx.qry.vpath, 0, NULL, NULL, |
52 | ctx.qry.showmsg); | 53 | ctx.qry.showmsg); |
53 | } | 54 | } |
54 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { | 55 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { |
55 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); | 56 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); |
56 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 57 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
57 | } | 58 | } |
58 | else if (!prefixcmp(deco->name, "refs/tags/")) { | 59 | else if (!prefixcmp(deco->name, "refs/tags/")) { |
59 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); | 60 | strncpy(buf, deco->name + 10, sizeof(buf) - 1); |
60 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 61 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
61 | } | 62 | } |
62 | else if (!prefixcmp(deco->name, "refs/remotes/")) { | 63 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
63 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); | 64 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
64 | cgit_log_link(buf, NULL, "remote-deco", NULL, | 65 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
65 | sha1_to_hex(commit->object.sha1), | 66 | sha1_to_hex(commit->object.sha1), |
66 | ctx.qry.vpath, 0, NULL, NULL, | 67 | ctx.qry.vpath, 0, NULL, NULL, |
67 | ctx.qry.showmsg); | 68 | ctx.qry.showmsg); |
68 | } | 69 | } |
69 | else { | 70 | else { |
70 | strncpy(buf, deco->name, sizeof(buf) - 1); | 71 | strncpy(buf, deco->name, sizeof(buf) - 1); |
71 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, | 72 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
72 | sha1_to_hex(commit->object.sha1), | 73 | sha1_to_hex(commit->object.sha1), |
73 | ctx.qry.vpath, 0); | 74 | ctx.qry.vpath, 0); |
74 | } | 75 | } |
75 | deco = deco->next; | 76 | deco = deco->next; |
76 | } | 77 | } |
77 | } | 78 | } |
78 | 79 | ||
79 | void print_commit(struct commit *commit) | 80 | void print_commit(struct commit *commit) |
80 | { | 81 | { |
81 | struct commitinfo *info; | 82 | struct commitinfo *info; |
82 | char *tmp; | 83 | char *tmp; |
83 | int cols = 2; | 84 | int cols = 2; |
84 | 85 | ||
85 | info = cgit_parse_commit(commit); | 86 | info = cgit_parse_commit(commit); |
86 | htmlf("<tr%s><td>", | 87 | htmlf("<tr%s><td>", |
87 | ctx.qry.showmsg ? " class='logheader'" : ""); | 88 | ctx.qry.showmsg ? " class='logheader'" : ""); |
88 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 89 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
89 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); | 90 | tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); |
90 | html_link_open(tmp, NULL, NULL); | 91 | html_link_open(tmp, NULL, NULL); |
91 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 92 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
92 | html_link_close(); | 93 | html_link_close(); |
93 | htmlf("</td><td%s>", | 94 | htmlf("</td><td%s>", |
94 | ctx.qry.showmsg ? " class='logsubject'" : ""); | 95 | ctx.qry.showmsg ? " class='logsubject'" : ""); |
95 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 96 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
96 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); | 97 | sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); |
97 | show_commit_decorations(commit); | 98 | show_commit_decorations(commit); |
98 | html("</td><td>"); | 99 | html("</td><td>"); |
99 | html_txt(info->author); | 100 | html_txt(info->author); |
100 | if (ctx.repo->enable_log_filecount) { | 101 | if (ctx.repo->enable_log_filecount) { |
101 | files = 0; | 102 | files = 0; |
102 | add_lines = 0; | 103 | add_lines = 0; |
103 | rem_lines = 0; | 104 | rem_lines = 0; |
104 | cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); | 105 | cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); |
105 | html("</td><td>"); | 106 | html("</td><td>"); |
106 | htmlf("%d", files); | 107 | htmlf("%d", files); |
107 | if (ctx.repo->enable_log_linecount) { | 108 | if (ctx.repo->enable_log_linecount) { |
108 | html("</td><td>"); | 109 | html("</td><td>"); |
109 | htmlf("-%d/+%d", rem_lines, add_lines); | 110 | htmlf("-%d/+%d", rem_lines, add_lines); |
110 | } | 111 | } |
111 | } | 112 | } |
112 | html("</td></tr>\n"); | 113 | html("</td></tr>\n"); |
113 | if (ctx.qry.showmsg) { | 114 | if (ctx.qry.showmsg) { |
114 | struct strbuf notes = STRBUF_INIT; | 115 | struct strbuf notes = STRBUF_INIT; |
115 | format_note(NULL, commit->object.sha1, ¬es, PAGE_ENCODING, 0); | 116 | format_note(NULL, commit->object.sha1, ¬es, PAGE_ENCODING, 0); |
116 | 117 | ||
117 | if (ctx.repo->enable_log_filecount) { | 118 | if (ctx.repo->enable_log_filecount) { |
118 | cols++; | 119 | cols++; |
119 | if (ctx.repo->enable_log_linecount) | 120 | if (ctx.repo->enable_log_linecount) |
120 | cols++; | 121 | cols++; |
121 | } | 122 | } |
122 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", | 123 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", |
123 | cols); | 124 | cols); |
124 | html_txt(info->msg); | 125 | html_txt(info->msg); |
125 | html("</td></tr>\n"); | 126 | html("</td></tr>\n"); |
126 | if (notes.len != 0) { | 127 | if (notes.len != 0) { |
127 | html("<tr class='nohover'>"); | 128 | html("<tr class='nohover'>"); |
128 | html("<td class='lognotes-label'>Notes:</td>"); | 129 | html("<td class='lognotes-label'>Notes:</td>"); |
129 | htmlf("<td colspan='%d' class='lognotes'>", | 130 | htmlf("<td colspan='%d' class='lognotes'>", |
130 | cols); | 131 | cols); |
131 | html_txt(notes.buf); | 132 | html_txt(notes.buf); |
132 | html("</td></tr>\n"); | 133 | html("</td></tr>\n"); |
133 | } | 134 | } |
134 | strbuf_release(¬es); | 135 | strbuf_release(¬es); |
135 | } | 136 | } |
136 | cgit_free_commitinfo(info); | 137 | cgit_free_commitinfo(info); |
137 | } | 138 | } |
138 | 139 | ||
139 | static const char *disambiguate_ref(const char *ref) | 140 | static const char *disambiguate_ref(const char *ref) |
140 | { | 141 | { |
141 | unsigned char sha1[20]; | 142 | unsigned char sha1[20]; |
142 | const char *longref; | 143 | const char *longref; |
143 | 144 | ||
144 | longref = fmt("refs/heads/%s", ref); | 145 | longref = fmt("refs/heads/%s", ref); |
145 | if (get_sha1(longref, sha1) == 0) | 146 | if (get_sha1(longref, sha1) == 0) |
146 | return longref; | 147 | return longref; |
147 | 148 | ||
148 | return ref; | 149 | return ref; |
149 | } | 150 | } |
150 | 151 | ||
152 | static char *next_token(char **src) | ||
153 | { | ||
154 | char *result; | ||
155 | |||
156 | if (!src || !*src) | ||
157 | return NULL; | ||
158 | while (isspace(**src)) | ||
159 | (*src)++; | ||
160 | if (!**src) | ||
161 | return NULL; | ||
162 | result = *src; | ||
163 | while (**src) { | ||
164 | if (isspace(**src)) { | ||
165 | **src = '\0'; | ||
166 | (*src)++; | ||
167 | break; | ||
168 | } | ||
169 | (*src)++; | ||
170 | } | ||
171 | return result; | ||
172 | } | ||
173 | |||
151 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 174 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
152 | char *path, int pager) | 175 | char *path, int pager) |
153 | { | 176 | { |
154 | struct rev_info rev; | 177 | struct rev_info rev; |
155 | struct commit *commit; | 178 | struct commit *commit; |
156 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; | 179 | struct vector vec = VECTOR_INIT(char *); |
157 | int argc = 2; | ||
158 | int i, columns = 3; | 180 | int i, columns = 3; |
181 | char *arg; | ||
182 | |||
183 | /* First argv is NULL */ | ||
184 | vector_push(&vec, NULL, 0); | ||
159 | 185 | ||
160 | if (!tip) | 186 | if (!tip) |
161 | tip = ctx.qry.head; | 187 | tip = ctx.qry.head; |
162 | 188 | tip = disambiguate_ref(tip); | |
163 | argv[1] = disambiguate_ref(tip); | 189 | vector_push(&vec, &tip, 0); |
164 | 190 | ||
165 | if (grep && pattern && *pattern) { | 191 | if (grep && pattern && *pattern) { |
192 | pattern = xstrdup(pattern); | ||
166 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || | 193 | if (!strcmp(grep, "grep") || !strcmp(grep, "author") || |
167 | !strcmp(grep, "committer")) | 194 | !strcmp(grep, "committer")) { |
168 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 195 | arg = fmt("--%s=%s", grep, pattern); |
169 | if (!strcmp(grep, "range")) | 196 | vector_push(&vec, &arg, 0); |
170 | argv[1] = pattern; | 197 | } |
198 | if (!strcmp(grep, "range")) { | ||
199 | /* Split the pattern at whitespace and add each token | ||
200 | * as a revision expression. Do not accept other | ||
201 | * rev-list options. Also, replace the previously | ||
202 | * pushed tip (it's no longer relevant). | ||
203 | */ | ||
204 | vec.count--; | ||
205 | while ((arg = next_token(&pattern))) { | ||
206 | if (*arg == '-') { | ||
207 | fprintf(stderr, "Bad range expr: %s\n", | ||
208 | arg); | ||
209 | break; | ||
210 | } | ||
211 | vector_push(&vec, &arg, 0); | ||
212 | } | ||
213 | } | ||
171 | } | 214 | } |
172 | 215 | ||
173 | if (path) { | 216 | if (path) { |
174 | argv[argc++] = "--"; | 217 | arg = "--"; |
175 | argv[argc++] = path; | 218 | vector_push(&vec, &arg, 0); |
219 | vector_push(&vec, &path, 0); | ||
176 | } | 220 | } |
221 | |||
222 | /* Make sure the vector is NULL-terminated */ | ||
223 | vector_push(&vec, NULL, 0); | ||
224 | vec.count--; | ||
225 | |||
177 | init_revisions(&rev, NULL); | 226 | init_revisions(&rev, NULL); |
178 | rev.abbrev = DEFAULT_ABBREV; | 227 | rev.abbrev = DEFAULT_ABBREV; |
179 | rev.commit_format = CMIT_FMT_DEFAULT; | 228 | rev.commit_format = CMIT_FMT_DEFAULT; |
180 | rev.verbose_header = 1; | 229 | rev.verbose_header = 1; |
181 | rev.show_root_diff = 0; | 230 | rev.show_root_diff = 0; |
182 | setup_revisions(argc, argv, &rev, NULL); | 231 | setup_revisions(vec.count, vec.data, &rev, NULL); |
183 | load_ref_decorations(DECORATE_FULL_REFS); | 232 | load_ref_decorations(DECORATE_FULL_REFS); |
184 | rev.show_decorations = 1; | 233 | rev.show_decorations = 1; |
185 | rev.grep_filter.regflags |= REG_ICASE; | 234 | rev.grep_filter.regflags |= REG_ICASE; |
186 | compile_grep_patterns(&rev.grep_filter); | 235 | compile_grep_patterns(&rev.grep_filter); |
187 | prepare_revision_walk(&rev); | 236 | prepare_revision_walk(&rev); |
188 | 237 | ||
189 | if (pager) | 238 | if (pager) |
190 | html("<table class='list nowrap'>"); | 239 | html("<table class='list nowrap'>"); |
191 | 240 | ||
192 | html("<tr class='nohover'><th class='left'>Age</th>" | 241 | html("<tr class='nohover'><th class='left'>Age</th>" |
193 | "<th class='left'>Commit message"); | 242 | "<th class='left'>Commit message"); |
194 | if (pager) { | 243 | if (pager) { |
195 | html(" ("); | 244 | html(" ("); |
196 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, | 245 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
197 | NULL, ctx.qry.head, ctx.qry.sha1, | 246 | NULL, ctx.qry.head, ctx.qry.sha1, |
198 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, | 247 | ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |
199 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); | 248 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); |
200 | html(")"); | 249 | html(")"); |
201 | } | 250 | } |
202 | html("</th><th class='left'>Author</th>"); | 251 | html("</th><th class='left'>Author</th>"); |
203 | if (ctx.repo->enable_log_filecount) { | 252 | if (ctx.repo->enable_log_filecount) { |
204 | html("<th class='left'>Files</th>"); | 253 | html("<th class='left'>Files</th>"); |
205 | columns++; | 254 | columns++; |
206 | if (ctx.repo->enable_log_linecount) { | 255 | if (ctx.repo->enable_log_linecount) { |
207 | html("<th class='left'>Lines</th>"); | 256 | html("<th class='left'>Lines</th>"); |
208 | columns++; | 257 | columns++; |
209 | } | 258 | } |
210 | } | 259 | } |
211 | html("</tr>\n"); | 260 | html("</tr>\n"); |
212 | 261 | ||
213 | if (ofs<0) | 262 | if (ofs<0) |
214 | ofs = 0; | 263 | ofs = 0; |
215 | 264 | ||
216 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 265 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
217 | free(commit->buffer); | 266 | free(commit->buffer); |
218 | commit->buffer = NULL; | 267 | commit->buffer = NULL; |
219 | free_commit_list(commit->parents); | 268 | free_commit_list(commit->parents); |
220 | commit->parents = NULL; | 269 | commit->parents = NULL; |
221 | } | 270 | } |
222 | 271 | ||
223 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 272 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
224 | print_commit(commit); | 273 | print_commit(commit); |
225 | free(commit->buffer); | 274 | free(commit->buffer); |
226 | commit->buffer = NULL; | 275 | commit->buffer = NULL; |
227 | free_commit_list(commit->parents); | 276 | free_commit_list(commit->parents); |
228 | commit->parents = NULL; | 277 | commit->parents = NULL; |
229 | } | 278 | } |
230 | if (pager) { | 279 | if (pager) { |
231 | html("</table><div class='pager'>"); | 280 | html("</table><div class='pager'>"); |
232 | if (ofs > 0) { | 281 | if (ofs > 0) { |
233 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 282 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
234 | ctx.qry.sha1, ctx.qry.vpath, | 283 | ctx.qry.sha1, ctx.qry.vpath, |
235 | ofs - cnt, ctx.qry.grep, | 284 | ofs - cnt, ctx.qry.grep, |
236 | ctx.qry.search, ctx.qry.showmsg); | 285 | ctx.qry.search, ctx.qry.showmsg); |
237 | html(" "); | 286 | html(" "); |
238 | } | 287 | } |
239 | if ((commit = get_revision(&rev)) != NULL) { | 288 | if ((commit = get_revision(&rev)) != NULL) { |
240 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 289 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
241 | ctx.qry.sha1, ctx.qry.vpath, | 290 | ctx.qry.sha1, ctx.qry.vpath, |
242 | ofs + cnt, ctx.qry.grep, | 291 | ofs + cnt, ctx.qry.grep, |
243 | ctx.qry.search, ctx.qry.showmsg); | 292 | ctx.qry.search, ctx.qry.showmsg); |
244 | } | 293 | } |
245 | html("</div>"); | 294 | html("</div>"); |
246 | } else if ((commit = get_revision(&rev)) != NULL) { | 295 | } else if ((commit = get_revision(&rev)) != NULL) { |
247 | html("<tr class='nohover'><td colspan='3'>"); | 296 | html("<tr class='nohover'><td colspan='3'>"); |
248 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, | 297 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, |
249 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); | 298 | ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); |
250 | html("</td></tr>\n"); | 299 | html("</td></tr>\n"); |
251 | } | 300 | } |
252 | } | 301 | } |
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 */ | ||