pathspec: create parse_short_magic function
Factor out the logic responsible for parsing short magic into its own function. Signed-off-by: Brandon Williams <bmwill@google.com> Reviewed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
db7e85988f
commit
b4bebdce83
54
pathspec.c
54
pathspec.c
|
@ -156,6 +156,41 @@ static int get_global_magic(int element_magic)
|
||||||
return global_magic;
|
return global_magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse the pathspec element looking for short magic
|
||||||
|
*
|
||||||
|
* saves all magic in 'magic'
|
||||||
|
* returns the position in 'elem' after all magic has been parsed
|
||||||
|
*/
|
||||||
|
static const char *parse_short_magic(unsigned *magic, const char *elem)
|
||||||
|
{
|
||||||
|
const char *pos;
|
||||||
|
|
||||||
|
for (pos = elem + 1; *pos && *pos != ':'; pos++) {
|
||||||
|
char ch = *pos;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!is_pathspec_magic(ch))
|
||||||
|
break;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) {
|
||||||
|
if (pathspec_magic[i].mnemonic == ch) {
|
||||||
|
*magic |= pathspec_magic[i].bit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARRAY_SIZE(pathspec_magic) <= i)
|
||||||
|
die(_("Unimplemented pathspec magic '%c' in '%s'"),
|
||||||
|
ch, elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pos == ':')
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Take an element of a pathspec and check for magic signatures.
|
* Take an element of a pathspec and check for magic signatures.
|
||||||
* Append the result to the prefix. Return the magic bitmap.
|
* Append the result to the prefix. Return the magic bitmap.
|
||||||
|
@ -220,24 +255,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
|
||||||
copyfrom++;
|
copyfrom++;
|
||||||
} else {
|
} else {
|
||||||
/* shorthand */
|
/* shorthand */
|
||||||
for (copyfrom = elt + 1;
|
copyfrom = parse_short_magic(&element_magic, elt);
|
||||||
*copyfrom && *copyfrom != ':';
|
|
||||||
copyfrom++) {
|
|
||||||
char ch = *copyfrom;
|
|
||||||
|
|
||||||
if (!is_pathspec_magic(ch))
|
|
||||||
break;
|
|
||||||
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
|
|
||||||
if (pathspec_magic[i].mnemonic == ch) {
|
|
||||||
element_magic |= pathspec_magic[i].bit;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ARRAY_SIZE(pathspec_magic) <= i)
|
|
||||||
die(_("Unimplemented pathspec magic '%c' in '%s'"),
|
|
||||||
ch, elt);
|
|
||||||
}
|
|
||||||
if (*copyfrom == ':')
|
|
||||||
copyfrom++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
magic |= element_magic;
|
magic |= element_magic;
|
||||||
|
|
Loading…
Reference in New Issue