pathspec: small readability changes
A few small changes to improve readability. This is done by grouping related assignments, adding blank lines, ensuring lines are <80 characters, and adding additional comments. 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
5590215b13
commit
4f1bf4d2b4
25
pathspec.c
25
pathspec.c
|
|
@ -67,11 +67,11 @@ static struct pathspec_magic {
|
||||||
char mnemonic; /* this cannot be ':'! */
|
char mnemonic; /* this cannot be ':'! */
|
||||||
const char *name;
|
const char *name;
|
||||||
} pathspec_magic[] = {
|
} pathspec_magic[] = {
|
||||||
{ PATHSPEC_FROMTOP, '/', "top" },
|
{ PATHSPEC_FROMTOP, '/', "top" },
|
||||||
{ PATHSPEC_LITERAL, 0, "literal" },
|
{ PATHSPEC_LITERAL, '\0', "literal" },
|
||||||
{ PATHSPEC_GLOB, '\0', "glob" },
|
{ PATHSPEC_GLOB, '\0', "glob" },
|
||||||
{ PATHSPEC_ICASE, '\0', "icase" },
|
{ PATHSPEC_ICASE, '\0', "icase" },
|
||||||
{ PATHSPEC_EXCLUDE, '!', "exclude" },
|
{ PATHSPEC_EXCLUDE, '!', "exclude" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void prefix_magic(struct strbuf *sb, int prefixlen, unsigned magic)
|
static void prefix_magic(struct strbuf *sb, int prefixlen, unsigned magic)
|
||||||
|
|
@ -336,6 +336,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
|
||||||
if ((magic & PATHSPEC_LITERAL) && (magic & PATHSPEC_GLOB))
|
if ((magic & PATHSPEC_LITERAL) && (magic & PATHSPEC_GLOB))
|
||||||
die(_("%s: 'literal' and 'glob' are incompatible"), elt);
|
die(_("%s: 'literal' and 'glob' are incompatible"), elt);
|
||||||
|
|
||||||
|
/* Create match string which will be used for pathspec matching */
|
||||||
if (pathspec_prefix >= 0) {
|
if (pathspec_prefix >= 0) {
|
||||||
match = xstrdup(copyfrom);
|
match = xstrdup(copyfrom);
|
||||||
prefixlen = pathspec_prefix;
|
prefixlen = pathspec_prefix;
|
||||||
|
|
@ -343,11 +344,16 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
|
||||||
match = xstrdup(copyfrom);
|
match = xstrdup(copyfrom);
|
||||||
prefixlen = 0;
|
prefixlen = 0;
|
||||||
} else {
|
} else {
|
||||||
match = prefix_path_gently(prefix, prefixlen, &prefixlen, copyfrom);
|
match = prefix_path_gently(prefix, prefixlen,
|
||||||
|
&prefixlen, copyfrom);
|
||||||
if (!match)
|
if (!match)
|
||||||
die(_("%s: '%s' is outside repository"), elt, copyfrom);
|
die(_("%s: '%s' is outside repository"), elt, copyfrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
item->match = match;
|
item->match = match;
|
||||||
|
item->len = strlen(item->match);
|
||||||
|
item->prefix = prefixlen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prefix the pathspec (keep all magic) and assign to
|
* Prefix the pathspec (keep all magic) and assign to
|
||||||
* original. Useful for passing to another command.
|
* original. Useful for passing to another command.
|
||||||
|
|
@ -364,8 +370,6 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
|
||||||
} else {
|
} else {
|
||||||
item->original = xstrdup(elt);
|
item->original = xstrdup(elt);
|
||||||
}
|
}
|
||||||
item->len = strlen(item->match);
|
|
||||||
item->prefix = prefixlen;
|
|
||||||
|
|
||||||
if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP)
|
if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP)
|
||||||
strip_submodule_slash_cheap(item);
|
strip_submodule_slash_cheap(item);
|
||||||
|
|
@ -373,13 +377,14 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
|
||||||
if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
|
if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
|
||||||
strip_submodule_slash_expensive(item);
|
strip_submodule_slash_expensive(item);
|
||||||
|
|
||||||
if (magic & PATHSPEC_LITERAL)
|
if (magic & PATHSPEC_LITERAL) {
|
||||||
item->nowildcard_len = item->len;
|
item->nowildcard_len = item->len;
|
||||||
else {
|
} else {
|
||||||
item->nowildcard_len = simple_length(item->match);
|
item->nowildcard_len = simple_length(item->match);
|
||||||
if (item->nowildcard_len < prefixlen)
|
if (item->nowildcard_len < prefixlen)
|
||||||
item->nowildcard_len = prefixlen;
|
item->nowildcard_len = prefixlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
item->flags = 0;
|
item->flags = 0;
|
||||||
if (magic & PATHSPEC_GLOB) {
|
if (magic & PATHSPEC_GLOB) {
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue