Change parse_attr() to take a pointer to struct attr_state
parse_attr() only needs access to the attr_state to which it should store its results, not to the whole match_attr structure. This change also removes the need for it to know num_attr. Change its signature accordingly and add a comment. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4c7517c9cc
commit
d175129857
17
attr.c
17
attr.c
@ -139,8 +139,15 @@ struct match_attr {
|
|||||||
|
|
||||||
static const char blank[] = " \t\r\n";
|
static const char blank[] = " \t\r\n";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse a whitespace-delimited attribute state (i.e., "attr",
|
||||||
|
* "-attr", "!attr", or "attr=value") from the string starting at src.
|
||||||
|
* If e is not NULL, write the results to *e. Return a pointer to the
|
||||||
|
* remainder of the string (with leading whitespace removed), or NULL
|
||||||
|
* if there was an error.
|
||||||
|
*/
|
||||||
static const char *parse_attr(const char *src, int lineno, const char *cp,
|
static const char *parse_attr(const char *src, int lineno, const char *cp,
|
||||||
int num_attr, struct match_attr *res)
|
struct attr_state *e)
|
||||||
{
|
{
|
||||||
const char *ep, *equals;
|
const char *ep, *equals;
|
||||||
int len;
|
int len;
|
||||||
@ -153,7 +160,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
|
|||||||
len = equals - cp;
|
len = equals - cp;
|
||||||
else
|
else
|
||||||
len = ep - cp;
|
len = ep - cp;
|
||||||
if (!res) {
|
if (!e) {
|
||||||
if (*cp == '-' || *cp == '!') {
|
if (*cp == '-' || *cp == '!') {
|
||||||
cp++;
|
cp++;
|
||||||
len--;
|
len--;
|
||||||
@ -165,9 +172,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct attr_state *e;
|
|
||||||
|
|
||||||
e = &(res->state[num_attr]);
|
|
||||||
if (*cp == '-' || *cp == '!') {
|
if (*cp == '-' || *cp == '!') {
|
||||||
e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
|
e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
|
||||||
cp++;
|
cp++;
|
||||||
@ -225,7 +229,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
cp = name + namelen;
|
cp = name + namelen;
|
||||||
cp = cp + strspn(cp, blank);
|
cp = cp + strspn(cp, blank);
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
cp = parse_attr(src, lineno, cp, num_attr, res);
|
cp = parse_attr(src, lineno, cp,
|
||||||
|
pass ? &(res->state[num_attr]) : NULL);
|
||||||
if (!cp)
|
if (!cp)
|
||||||
return NULL;
|
return NULL;
|
||||||
num_attr++;
|
num_attr++;
|
||||||
|
Loading…
Reference in New Issue
Block a user