git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 3/7] Increment num_attr in parse_attr_line(), not parse_attr()
Date: Fri, 12 Aug 2011 23:43:06 +0200	[thread overview]
Message-ID: <1313185390-19724-4-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1313185390-19724-1-git-send-email-mhagger@alum.mit.edu>

num_attr is incremented iff parse_attr() returns non-NULL.  So do the
counting in parse_attr_line() instead of within parse_attr().  This
allows an integer rather than a pointer to an integer to be passed to
parse_attr().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 attr.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/attr.c b/attr.c
index c33e413..cac550d 100644
--- a/attr.c
+++ b/attr.c
@@ -140,7 +140,7 @@ struct match_attr {
 static const char blank[] = " \t\r\n";
 
 static const char *parse_attr(const char *src, int lineno, const char *cp,
-			      int *num_attr, struct match_attr *res)
+			      int num_attr, struct match_attr *res)
 {
 	const char *ep, *equals;
 	int len;
@@ -167,7 +167,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
 	} else {
 		struct attr_state *e;
 
-		e = &(res->state[*num_attr]);
+		e = &(res->state[num_attr]);
 		if (*cp == '-' || *cp == '!') {
 			e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
 			cp++;
@@ -180,7 +180,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
 		}
 		e->attr = git_attr_internal(cp, len);
 	}
-	(*num_attr)++;
 	return ep + strspn(ep, blank);
 }
 
@@ -226,9 +225,10 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
 		cp = name + namelen;
 		cp = cp + strspn(cp, blank);
 		while (*cp) {
-			cp = parse_attr(src, lineno, cp, &num_attr, res);
+			cp = parse_attr(src, lineno, cp, num_attr, res);
 			if (!cp)
 				return NULL;
+			num_attr++;
 		}
 		if (pass)
 			break;
-- 
1.7.6.8.gd2879

  parent reply	other threads:[~2011-08-12 21:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 21:43 [PATCH 0/7] Comments and refactoring in attr.c Michael Haggerty
2011-08-12 21:43 ` [PATCH 1/7] Add a file comment Michael Haggerty
2011-08-12 21:43 ` [PATCH 2/7] Document struct match_attr Michael Haggerty
2011-08-12 21:43 ` Michael Haggerty [this message]
2011-08-12 21:43 ` [PATCH 4/7] Change parse_attr() to take a pointer to struct attr_state Michael Haggerty
2011-08-12 21:43 ` [PATCH 5/7] Determine the start of the states outside of the pass loop Michael Haggerty
2011-08-12 21:43 ` [PATCH 6/7] Change while loop into for loop Michael Haggerty
2011-08-12 21:43 ` [PATCH 7/7] Unroll the loop over passes Michael Haggerty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1313185390-19724-4-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).