summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2011-02-19 13:00:56 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2011-02-19 13:00:59 (UTC)
commite66a16cebcdac53b63e77876acef1ca9e4877038 (patch) (unidiff)
tree839123e66853c4a80c305a3a1c13295fe5e6acc9
parent286c4c0a1d7085afdc8d9ddba86da4ed9f2f7400 (diff)
parentc2680325f68192368d32f26458fea9cfb50df6e5 (diff)
downloadcgit-e66a16cebcdac53b63e77876acef1ca9e4877038.zip
cgit-e66a16cebcdac53b63e77876acef1ca9e4877038.tar.gz
cgit-e66a16cebcdac53b63e77876acef1ca9e4877038.tar.bz2
Merge branch 'lh/improve-range-search'
* lh/improve-range-search: html.c: use '+' to escape spaces in urls ui-log.c: improve handling of range-search argument Add vector utility functions
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--Makefile1
-rw-r--r--html.c4
-rw-r--r--ui-log.c71
-rw-r--r--vector.c38
-rw-r--r--vector.h17
5 files changed, 118 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 84790a8..a988751 100644
--- a/Makefile
+++ b/Makefile
@@ -70,96 +70,97 @@ endif
70ifndef V 70ifndef 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
76endif 76endif
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
91EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread 91EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread
92OBJECTS = 92OBJECTS =
93OBJECTS += cache.o 93OBJECTS += cache.o
94OBJECTS += cgit.o 94OBJECTS += cgit.o
95OBJECTS += cmd.o 95OBJECTS += cmd.o
96OBJECTS += configfile.o 96OBJECTS += configfile.o
97OBJECTS += html.o 97OBJECTS += html.o
98OBJECTS += parsing.o 98OBJECTS += parsing.o
99OBJECTS += scan-tree.o 99OBJECTS += scan-tree.o
100OBJECTS += shared.o 100OBJECTS += shared.o
101OBJECTS += ui-atom.o 101OBJECTS += ui-atom.o
102OBJECTS += ui-blob.o 102OBJECTS += ui-blob.o
103OBJECTS += ui-clone.o 103OBJECTS += ui-clone.o
104OBJECTS += ui-commit.o 104OBJECTS += ui-commit.o
105OBJECTS += ui-diff.o 105OBJECTS += ui-diff.o
106OBJECTS += ui-log.o 106OBJECTS += ui-log.o
107OBJECTS += ui-patch.o 107OBJECTS += ui-patch.o
108OBJECTS += ui-plain.o 108OBJECTS += ui-plain.o
109OBJECTS += ui-refs.o 109OBJECTS += ui-refs.o
110OBJECTS += ui-repolist.o 110OBJECTS += ui-repolist.o
111OBJECTS += ui-shared.o 111OBJECTS += ui-shared.o
112OBJECTS += ui-snapshot.o 112OBJECTS += ui-snapshot.o
113OBJECTS += ui-ssdiff.o 113OBJECTS += ui-ssdiff.o
114OBJECTS += ui-stats.o 114OBJECTS += ui-stats.o
115OBJECTS += ui-summary.o 115OBJECTS += ui-summary.o
116OBJECTS += ui-tag.o 116OBJECTS += ui-tag.o
117OBJECTS += ui-tree.o 117OBJECTS += ui-tree.o
118OBJECTS += vector.o
118 119
119ifdef NEEDS_LIBICONV 120ifdef NEEDS_LIBICONV
120 EXTLIBS += -liconv 121 EXTLIBS += -liconv
121endif 122endif
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
128all: cgit 129all: cgit
129 130
130VERSION: force-version 131VERSION: force-version
131 @./gen-version.sh "$(CGIT_VERSION)" 132 @./gen-version.sh "$(CGIT_VERSION)"
132-include VERSION 133-include VERSION
133 134
134 135
135CFLAGS += -g -Wall -Igit 136CFLAGS += -g -Wall -Igit
136CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 137CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
137CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' 138CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
138CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' 139CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
139CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' 140CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
140CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 141CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
141 142
142GIT_OPTIONS = prefix=/usr 143GIT_OPTIONS = prefix=/usr
143 144
144ifdef NO_ICONV 145ifdef NO_ICONV
145 CFLAGS += -DNO_ICONV 146 CFLAGS += -DNO_ICONV
146endif 147endif
147ifdef NO_STRCASESTR 148ifdef NO_STRCASESTR
148 CFLAGS += -DNO_STRCASESTR 149 CFLAGS += -DNO_STRCASESTR
149endif 150endif
150ifdef NO_C99_FORMAT 151ifdef NO_C99_FORMAT
151 CFLAGS += -DNO_C99_FORMAT 152 CFLAGS += -DNO_C99_FORMAT
152endif 153endif
153ifdef NO_OPENSSL 154ifdef NO_OPENSSL
154 CFLAGS += -DNO_OPENSSL 155 CFLAGS += -DNO_OPENSSL
155 GIT_OPTIONS += NO_OPENSSL=1 156 GIT_OPTIONS += NO_OPENSSL=1
156else 157else
157 EXTLIBS += -lcrypto 158 EXTLIBS += -lcrypto
158endif 159endif
159 160
160cgit: $(OBJECTS) libgit 161cgit: $(OBJECTS) libgit
161 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) 162 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
162 163
163cgit.o: VERSION 164cgit.o: VERSION
164 165
165ifneq "$(MAKECMDGOALS)" "clean" 166ifneq "$(MAKECMDGOALS)" "clean"
diff --git a/html.c b/html.c
index 1305910..a1fe87d 100644
--- a/html.c
+++ b/html.c
@@ -1,69 +1,69 @@
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!$()*,./:;@- */
17static const char* url_escape_table[256] = { 17static 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
42int htmlfd = STDOUT_FILENO; 42int htmlfd = STDOUT_FILENO;
43 43
44char *fmt(const char *format, ...) 44char *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
64void html_raw(const char *data, size_t size) 64void html_raw(const char *data, size_t size)
65{ 65{
66 write(htmlfd, data, size); 66 write(htmlfd, data, size);
67} 67}
68 68
69void html(const char *txt) 69void html(const char *txt)
@@ -136,97 +136,97 @@ void html_ntxt(int len, const char *txt)
136void html_attr(const char *txt) 136void 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("&gt;"); 144 html("&gt;");
145 else if (c=='<') 145 else if (c=='<')
146 html("&lt;"); 146 html("&lt;");
147 else if (c=='\'') 147 else if (c=='\'')
148 html("&#x27;"); 148 html("&#x27;");
149 else if (c=='"') 149 else if (c=='"')
150 html("&quot;"); 150 html("&quot;");
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
159void html_url_path(const char *txt) 159void 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
176void html_url_arg(const char *txt) 176void 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
193void html_hidden(const char *name, const char *value) 193void 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
202void html_option(const char *value, const char *text, const char *selected_value) 202void 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
214void html_link_open(const char *url, const char *title, const char *class) 214void 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
229void html_link_close(void) 229void html_link_close(void)
230{ 230{
231 html("</a>"); 231 html("</a>");
232} 232}
diff --git a/ui-log.c b/ui-log.c
index b9771fa..27f5a1a 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,59 +1,60 @@
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
13int files, add_lines, rem_lines; 14int files, add_lines, rem_lines;
14 15
15void count_lines(char *line, int size) 16void 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
27void inspect_files(struct diff_filepair *pair) 28void 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
40void show_commit_decorations(struct commit *commit) 41void 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);
@@ -103,128 +104,176 @@ void print_commit(struct commit *commit)
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, &notes, PAGE_ENCODING, 0); 116 format_note(NULL, commit->object.sha1, &notes, 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(&notes); 135 strbuf_release(&notes);
135 } 136 }
136 cgit_free_commitinfo(info); 137 cgit_free_commitinfo(info);
137} 138}
138 139
139static const char *disambiguate_ref(const char *ref) 140static 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
152static 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
151void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, 174void 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) {
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
6static 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
26int 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
6struct 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
15int vector_push(struct vector *vec, const void *data, int gently);
16
17#endif /* CGIT_VECTOR_H */