summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore 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
@@ -115,6 +115,7 @@ OBJECTS += 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
diff --git a/html.c b/html.c
index 1305910..a1fe87d 100644
--- a/html.c
+++ b/html.c
@@ -18,7 +18,7 @@ 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,
@@ -181,7 +181,7 @@ void html_url_arg(const char *txt)
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++;
diff --git a/ui-log.c b/ui-log.c
index b9771fa..27f5a1a 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -9,6 +9,7 @@
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
@@ -148,38 +149,86 @@ static const char *disambiguate_ref(const char *ref)
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;
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 */