author | Lars Hjemli <hjemli@gmail.com> | 2011-02-19 13:00:56 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2011-02-19 13:00:59 (UTC) |
commit | e66a16cebcdac53b63e77876acef1ca9e4877038 (patch) (side-by-side diff) | |
tree | 839123e66853c4a80c305a3a1c13295fe5e6acc9 /ui-log.c | |
parent | 286c4c0a1d7085afdc8d9ddba86da4ed9f2f7400 (diff) | |
parent | c2680325f68192368d32f26458fea9cfb50df6e5 (diff) | |
download | cgit-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
-rw-r--r-- | ui-log.c | 71 |
1 files changed, 60 insertions, 11 deletions
@@ -1,27 +1,28 @@ /* 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] == '-') rem_lines++; } void inspect_files(struct diff_filepair *pair) @@ -135,64 +136,112 @@ void print_commit(struct commit *commit) } cgit_free_commitinfo(info); } 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) { html(" ("); cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, NULL, ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, |