aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.mk1
-rw-r--r--ui-log.c34
-rw-r--r--vector.c38
-rw-r--r--vector.h17
4 files changed, 15 insertions, 75 deletions
diff --git a/cgit.mk b/cgit.mk
index 8af0041..b5cc7a2 100644
--- a/cgit.mk
+++ b/cgit.mk
@@ -50,7 +50,6 @@ CGIT_OBJ_NAMES += ui-stats.o
50CGIT_OBJ_NAMES += ui-summary.o 50CGIT_OBJ_NAMES += ui-summary.o
51CGIT_OBJ_NAMES += ui-tag.o 51CGIT_OBJ_NAMES += ui-tag.o
52CGIT_OBJ_NAMES += ui-tree.o 52CGIT_OBJ_NAMES += ui-tree.o
53CGIT_OBJ_NAMES += vector.o
54 53
55CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES)) 54CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
56 55
diff --git a/ui-log.c b/ui-log.c
index 6f1249b..3c5130a 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -10,7 +10,7 @@
10#include "ui-log.h" 10#include "ui-log.h"
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13#include "vector.h" 13#include "argv-array.h"
14 14
15int files, add_lines, rem_lines; 15int files, add_lines, rem_lines;
16 16
@@ -288,25 +288,25 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
288{ 288{
289 struct rev_info rev; 289 struct rev_info rev;
290 struct commit *commit; 290 struct commit *commit;
291 struct vector vec = VECTOR_INIT(char *); 291 struct argv_array rev_argv = ARGV_ARRAY_INIT;
292 int i, columns = commit_graph ? 4 : 3; 292 int i, columns = commit_graph ? 4 : 3;
293 int must_free_tip = 0; 293 int must_free_tip = 0;
294 struct strbuf argbuf = STRBUF_INIT; 294 struct strbuf argbuf = STRBUF_INIT;
295 295
296 /* First argv is NULL */ 296 /* rev_argv.argv[0] will be ignored by setup_revisions */
297 vector_push(&vec, NULL, 0); 297 argv_array_push(&rev_argv, "log_rev_setup");
298 298
299 if (!tip) 299 if (!tip)
300 tip = ctx.qry.head; 300 tip = ctx.qry.head;
301 tip = disambiguate_ref(tip, &must_free_tip); 301 tip = disambiguate_ref(tip, &must_free_tip);
302 vector_push(&vec, &tip, 0); 302 argv_array_push(&rev_argv, tip);
303 303
304 if (grep && pattern && *pattern) { 304 if (grep && pattern && *pattern) {
305 pattern = xstrdup(pattern); 305 pattern = xstrdup(pattern);
306 if (!strcmp(grep, "grep") || !strcmp(grep, "author") || 306 if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
307 !strcmp(grep, "committer")) { 307 !strcmp(grep, "committer")) {
308 strbuf_addf(&argbuf, "--%s=%s", grep, pattern); 308 strbuf_addf(&argbuf, "--%s=%s", grep, pattern);
309 vector_push(&vec, &argbuf.buf, 0); 309 argv_array_push(&rev_argv, argbuf.buf);
310 } 310 }
311 if (!strcmp(grep, "range")) { 311 if (!strcmp(grep, "range")) {
312 char *arg; 312 char *arg;
@@ -315,50 +315,46 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
315 * rev-list options. Also, replace the previously 315 * rev-list options. Also, replace the previously
316 * pushed tip (it's no longer relevant). 316 * pushed tip (it's no longer relevant).
317 */ 317 */
318 vec.count--; 318 argv_array_pop(&rev_argv);
319 while ((arg = next_token(&pattern))) { 319 while ((arg = next_token(&pattern))) {
320 if (*arg == '-') { 320 if (*arg == '-') {
321 fprintf(stderr, "Bad range expr: %s\n", 321 fprintf(stderr, "Bad range expr: %s\n",
322 arg); 322 arg);
323 break; 323 break;
324 } 324 }
325 vector_push(&vec, &arg, 0); 325 argv_array_push(&rev_argv, arg);
326 } 326 }
327 } 327 }
328 } 328 }
329 if (commit_graph) { 329 if (commit_graph) {
330 static const char *graph_arg = "--graph"; 330 static const char *graph_arg = "--graph";
331 static const char *color_arg = "--color"; 331 static const char *color_arg = "--color";
332 vector_push(&vec, &graph_arg, 0); 332 argv_array_push(&rev_argv, graph_arg);
333 vector_push(&vec, &color_arg, 0); 333 argv_array_push(&rev_argv, color_arg);
334 graph_set_column_colors(column_colors_html, 334 graph_set_column_colors(column_colors_html,
335 COLUMN_COLORS_HTML_MAX); 335 COLUMN_COLORS_HTML_MAX);
336 } 336 }
337 337
338 if (commit_sort == 1) { 338 if (commit_sort == 1) {
339 static const char *date_order_arg = "--date-order"; 339 static const char *date_order_arg = "--date-order";
340 vector_push(&vec, &date_order_arg, 0); 340 argv_array_push(&rev_argv, date_order_arg);
341 } else if (commit_sort == 2) { 341 } else if (commit_sort == 2) {
342 static const char *topo_order_arg = "--topo-order"; 342 static const char *topo_order_arg = "--topo-order";
343 vector_push(&vec, &topo_order_arg, 0); 343 argv_array_push(&rev_argv, topo_order_arg);
344 } 344 }
345 345
346 if (path) { 346 if (path) {
347 static const char *double_dash_arg = "--"; 347 static const char *double_dash_arg = "--";
348 vector_push(&vec, &double_dash_arg, 0); 348 argv_array_push(&rev_argv, double_dash_arg);
349 vector_push(&vec, &path, 0); 349 argv_array_push(&rev_argv, path);
350 } 350 }
351 351
352 /* Make sure the vector is NULL-terminated */
353 vector_push(&vec, NULL, 0);
354 vec.count--;
355
356 init_revisions(&rev, NULL); 352 init_revisions(&rev, NULL);
357 rev.abbrev = DEFAULT_ABBREV; 353 rev.abbrev = DEFAULT_ABBREV;
358 rev.commit_format = CMIT_FMT_DEFAULT; 354 rev.commit_format = CMIT_FMT_DEFAULT;
359 rev.verbose_header = 1; 355 rev.verbose_header = 1;
360 rev.show_root_diff = 0; 356 rev.show_root_diff = 0;
361 setup_revisions(vec.count, vec.data, &rev, NULL); 357 setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL);
362 load_ref_decorations(DECORATE_FULL_REFS); 358 load_ref_decorations(DECORATE_FULL_REFS);
363 rev.show_decorations = 1; 359 rev.show_decorations = 1;
364 rev.grep_filter.regflags |= REG_ICASE; 360 rev.grep_filter.regflags |= REG_ICASE;
diff --git a/vector.c b/vector.c
deleted file mode 100644
index 0863908..0000000
--- a/vector.c
+++ /dev/null
@@ -1,38 +0,0 @@
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
deleted file mode 100644
index c64eb1f..0000000
--- a/vector.h
+++ /dev/null
@@ -1,17 +0,0 @@
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 */