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>

Michael Haggerty committed Aug 12, 2011 at 23:43 UTC d175129857fe712bc7a4d882b0b9ef9f9d0a337e
1 file changed +11 -6
attr.c
+11 -6
@@ -139,8 +139,15 @@ struct match_attr {
139
140 static const char blank[] = " \t\r\n";
141
142 +/*
143 + * Parse a whitespace-delimited attribute state (i.e., "attr",
144 + * "-attr", "!attr", or "attr=value") from the string starting at src.
145 + * If e is not NULL, write the results to *e. Return a pointer to the
146 + * remainder of the string (with leading whitespace removed), or NULL
147 + * if there was an error.
148 + */
149 static const char *parse_attr(const char *src, int lineno, const char *cp,
143 - int num_attr, struct match_attr *res)
150 + struct attr_state *e)
151 {
152 const char *ep, *equals;
153 int len;
@@ -153,7 +160,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
160 len = equals - cp;
161 else
162 len = ep - cp;
156 - if (!res) {
163 + if (!e) {
164 if (*cp == '-' || *cp == '!') {
165 cp++;
166 len--;
@@ -165,9 +172,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
172 return NULL;
173 }
174 } else {
168 - struct attr_state *e;
169 -
170 - e = &(res->state[num_attr]);
175 if (*cp == '-' || *cp == '!') {
176 e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
177 cp++;
@@ -225,7 +229,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
229 cp = name + namelen;
230 cp = cp + strspn(cp, blank);
231 while (*cp) {
228 - cp = parse_attr(src, lineno, cp, num_attr, res);
232 + cp = parse_attr(src, lineno, cp,
233 + pass ? &(res->state[num_attr]) : NULL);
234 if (!cp)
235 return NULL;
236 num_attr++;