mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 16:38:42 +00:00
Refactor cgit_parse_snapshots_mask()
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This significantly improves readability. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
This commit is contained in:
parent
2abce4300b
commit
f04b8d5c99
23
shared.c
23
shared.c
@ -404,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)
|
|||||||
|
|
||||||
int cgit_parse_snapshots_mask(const char *str)
|
int cgit_parse_snapshots_mask(const char *str)
|
||||||
{
|
{
|
||||||
|
struct string_list tokens = STRING_LIST_INIT_DUP;
|
||||||
|
struct string_list_item *item;
|
||||||
const struct cgit_snapshot_format *f;
|
const struct cgit_snapshot_format *f;
|
||||||
static const char *delim = " ";
|
int rv = 0;
|
||||||
int tl, sl, rv = 0;
|
|
||||||
|
|
||||||
/* favor legacy setting */
|
/* favor legacy setting */
|
||||||
if (atoi(str))
|
if (atoi(str))
|
||||||
return 1;
|
return 1;
|
||||||
for (;;) {
|
|
||||||
str += strspn(str, delim);
|
string_list_split(&tokens, str, ' ', -1);
|
||||||
tl = strcspn(str, delim);
|
string_list_remove_empty_items(&tokens, 0);
|
||||||
if (!tl)
|
|
||||||
break;
|
for_each_string_list_item(item, &tokens) {
|
||||||
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
||||||
sl = strlen(f->suffix);
|
if (!strcmp(item->string, f->suffix) ||
|
||||||
if ((tl == sl && !strncmp(f->suffix, str, tl)) ||
|
!strcmp(item->string, f->suffix + 1)) {
|
||||||
(tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
|
|
||||||
rv |= f->bit;
|
rv |= f->bit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str += tl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string_list_clear(&tokens, 0);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user