Diff options
| -rw-r--r-- | source/ui-log.c | 36 | |
| -rw-r--r-- | source/ui-log.h | 2 |
2 files changed, 9 insertions, 29 deletions
diff --git a/source/ui-log.c b/source/ui-log.c index 3cbbe33..b7804c8 100644 --- a/source/ui-log.c +++ b/source/ui-log.c @@ -351,28 +351,6 @@ static int valid_range_token(const char *arg) return ok; } -static char *next_token(char **src) -{ - char *token; - - if (!*src) - return NULL; - while (isspace((unsigned char)**src)) - (*src)++; - if (!**src) - return NULL; - token = *src; - while (**src) { - if (isspace((unsigned char)**src)) { - **src = '\0'; - (*src)++; - break; - } - (*src)++; - } - return token; -} - /* * Whether there is a page after this one is answered by pulling one more * commit off the walk. The links carry the path as it was asked for, since a @@ -462,12 +440,13 @@ void cgit_print_commit_decorations(struct commit *commit) html("</span>"); } -void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, +void cgit_print_log(const char *tip, int ofs, int cnt, const char *grep, const char *pattern, const char *path, int pager, int commit_graph, int commit_sort, int table_columns) { struct rev_info rev; struct commit *commit; struct strvec rev_argv = STRVEC_INIT; + struct string_list tokens = STRING_LIST_INIT_DUP; int i, columns, filler = 0; int must_free_tip = 0; @@ -495,7 +474,6 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } if (grep && pattern && *pattern) { - pattern = xstrdup(pattern); if (!strcmp(grep, "grep") || !strcmp(grep, "author") || !strcmp(grep, "committer")) { // The search is literal and ignores case. setup_revisions // compiles the pattern, so the flags go in with it. @@ -503,18 +481,19 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern strvec_push(&rev_argv, "--regexp-ignore-case"); strvec_pushf(&rev_argv, "--%s=%s", grep, pattern); } else if (!strcmp(grep, "range")) { - char *arg; + struct string_list_item *token; // Each whitespace separated token has to pass the same // check as any other revision. The tip pushed above goes // away, since the range supersedes it. strvec_pop(&rev_argv); - while ((arg = next_token(&pattern))) { - if (!valid_range_token(arg)) { + string_list_split_f(&tokens, pattern, " \t\n\r", -1, STRING_LIST_SPLIT_NONEMPTY); + for_each_string_list_item(token, &tokens) { + if (!valid_range_token(token->string)) { cgit_print_error_page(400, "Bad Request", "Invalid revision"); goto out; } - strvec_push(&rev_argv, arg); + strvec_push(&rev_argv, token->string); } } } @@ -644,4 +623,5 @@ out: if (must_free_tip) free((char *)tip); strvec_clear(&rev_argv); + string_list_clear(&tokens, 0); } diff --git a/source/ui-log.h b/source/ui-log.h index d01a63d..cec0f7a 100644 --- a/source/ui-log.h +++ b/source/ui-log.h @@ -14,7 +14,7 @@ * is that table's width, which every row is filled out to. 0 leaves the rows * at their own width. */ -extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, +extern void cgit_print_log(const char *tip, int ofs, int cnt, const char *grep, const char *pattern, const char *path, int pager, int commit_graph, int commit_sort, int table_columns); extern void cgit_print_commit_decorations(struct commit *commit); |
