summaryrefslogtreecommitdiffabout
Side-by-side diff
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
@@ -106,24 +106,25 @@ OBJECTS += ui-diff.o
OBJECTS += ui-log.o
OBJECTS += ui-patch.o
OBJECTS += ui-plain.o
OBJECTS += ui-refs.o
OBJECTS += ui-repolist.o
OBJECTS += ui-shared.o
OBJECTS += ui-snapshot.o
OBJECTS += ui-ssdiff.o
OBJECTS += ui-stats.o
OBJECTS += ui-summary.o
OBJECTS += ui-tag.o
OBJECTS += ui-tree.o
+OBJECTS += vector.o
ifdef NEEDS_LIBICONV
EXTLIBS += -liconv
endif
.PHONY: all libgit test install uninstall clean force-version get-git \
doc clean-doc install-doc install-man install-html install-pdf \
uninstall-doc uninstall-man uninstall-html uninstall-pdf
all: cgit
diff --git a/html.c b/html.c
index 1305910..a1fe87d 100644
--- a/html.c
+++ b/html.c
@@ -9,25 +9,25 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
/* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
static const char* url_escape_table[256] = {
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
"%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
"%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
- "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
+ "%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
"%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
"%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%7b",
"%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85",
"%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99",
"%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3",
"%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad",
"%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
"%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1",
"%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb",
@@ -172,25 +172,25 @@ void html_url_path(const char *txt)
if (t!=txt)
html(txt);
}
void html_url_arg(const char *txt)
{
const char *t = txt;
while(t && *t){
int c = *t;
const char *e = url_escape_table[c];
if (e) {
html_raw(txt, t - txt);
- html_raw(e, 3);
+ html_raw(e, strlen(e));
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
void html_hidden(const char *name, const char *value)
{
html("<input type='hidden' name='");
html_attr(name);
diff --git a/ui-log.c b/ui-log.c
index b9771fa..27f5a1a 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,23 +1,24 @@
/* ui-log.c: functions for log output
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
+#include "vector.h"
int files, add_lines, rem_lines;
void count_lines(char *line, int size)
{
if (size <= 0)
return;
if (line[0] == '+')
add_lines++;
else if (line[0] == '-')
@@ -139,56 +140,104 @@ void print_commit(struct commit *commit)
static const char *disambiguate_ref(const char *ref)
{
unsigned char sha1[20];
const char *longref;
longref = fmt("refs/heads/%s", ref);
if (get_sha1(longref, sha1) == 0)
return longref;
return ref;
}
+static char *next_token(char **src)
+{
+ char *result;
+
+ if (!src || !*src)
+ return NULL;
+ while (isspace(**src))
+ (*src)++;
+ if (!**src)
+ return NULL;
+ result = *src;
+ while (**src) {
+ if (isspace(**src)) {
+ **src = '\0';
+ (*src)++;
+ break;
+ }
+ (*src)++;
+ }
+ return result;
+}
+
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
char *path, int pager)
{
struct rev_info rev;
struct commit *commit;
- const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
- int argc = 2;
+ struct vector vec = VECTOR_INIT(char *);
int i, columns = 3;
+ char *arg;
+
+ /* First argv is NULL */
+ vector_push(&vec, NULL, 0);
if (!tip)
tip = ctx.qry.head;
-
- argv[1] = disambiguate_ref(tip);
+ tip = disambiguate_ref(tip);
+ vector_push(&vec, &tip, 0);
if (grep && pattern && *pattern) {
+ pattern = xstrdup(pattern);
if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
- !strcmp(grep, "committer"))
- argv[argc++] = fmt("--%s=%s", grep, pattern);
- if (!strcmp(grep, "range"))
- argv[1] = pattern;
+ !strcmp(grep, "committer")) {
+ arg = fmt("--%s=%s", grep, pattern);
+ vector_push(&vec, &arg, 0);
+ }
+ if (!strcmp(grep, "range")) {
+ /* Split the pattern at whitespace and add each token
+ * as a revision expression. Do not accept other
+ * rev-list options. Also, replace the previously
+ * pushed tip (it's no longer relevant).
+ */
+ vec.count--;
+ while ((arg = next_token(&pattern))) {
+ if (*arg == '-') {
+ fprintf(stderr, "Bad range expr: %s\n",
+ arg);
+ break;
+ }
+ vector_push(&vec, &arg, 0);
+ }
+ }
}
if (path) {
- argv[argc++] = "--";
- argv[argc++] = path;
+ arg = "--";
+ vector_push(&vec, &arg, 0);
+ vector_push(&vec, &path, 0);
}
+
+ /* Make sure the vector is NULL-terminated */
+ vector_push(&vec, NULL, 0);
+ vec.count--;
+
init_revisions(&rev, NULL);
rev.abbrev = DEFAULT_ABBREV;
rev.commit_format = CMIT_FMT_DEFAULT;
rev.verbose_header = 1;
rev.show_root_diff = 0;
- setup_revisions(argc, argv, &rev, NULL);
+ setup_revisions(vec.count, vec.data, &rev, NULL);
load_ref_decorations(DECORATE_FULL_REFS);
rev.show_decorations = 1;
rev.grep_filter.regflags |= REG_ICASE;
compile_grep_patterns(&rev.grep_filter);
prepare_revision_walk(&rev);
if (pager)
html("<table class='list nowrap'>");
html("<tr class='nohover'><th class='left'>Age</th>"
"<th class='left'>Commit message");
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 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "vector.h"
+
+static int grow(struct vector *vec, int gently)
+{
+ size_t new_alloc;
+ void *new_data;
+
+ new_alloc = vec->alloc * 3 / 2;
+ if (!new_alloc)
+ new_alloc = 8;
+ new_data = realloc(vec->data, new_alloc * vec->size);
+ if (!new_data) {
+ if (gently)
+ return ENOMEM;
+ perror("vector.c:grow()");
+ exit(1);
+ }
+ vec->data = new_data;
+ vec->alloc = new_alloc;
+ return 0;
+}
+
+int vector_push(struct vector *vec, const void *data, int gently)
+{
+ int rc;
+
+ if (vec->count == vec->alloc && (rc = grow(vec, gently)))
+ return rc;
+ if (data)
+ memmove(vec->data + vec->count * vec->size, data, vec->size);
+ else
+ memset(vec->data + vec->count * vec->size, 0, vec->size);
+ vec->count++;
+ return 0;
+}
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 @@
+#ifndef CGIT_VECTOR_H
+#define CGIT_VECTOR_H
+
+#include <stdlib.h>
+
+struct vector {
+ size_t size;
+ size_t count;
+ size_t alloc;
+ void *data;
+};
+
+#define VECTOR_INIT(type) {sizeof(type), 0, 0, NULL}
+
+int vector_push(struct vector *vec, const void *data, int gently);
+
+#endif /* CGIT_VECTOR_H */