git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Vandiver <alex@chmrr.net>
To: git@vger.kernel.org
Subject: [PATCH 1/2] Make section_name_match start on '[', and return the length on success
Date: Fri, 24 Jul 2009 17:21:43 -0400	[thread overview]
Message-ID: <1248470504-16326-2-git-send-email-alex@chmrr.net> (raw)
In-Reply-To: <1248470504-16326-1-git-send-email-alex@chmrr.net>


Signed-off-by: Alex Vandiver <alex@chmrr.net>
---
 config.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index 04380bb..7d6f6f6 100644
--- a/config.c
+++ b/config.c
@@ -1194,7 +1194,9 @@ write_err_out:
 static int section_name_match (const char *buf, const char *name)
 {
 	int i = 0, j = 0, dot = 0;
-	for (; buf[i] && buf[i] != ']'; i++) {
+	if (buf[i] != '[')
+		return 0;
+	for (i = 1; buf[i] && buf[i] != ']'; i++) {
 		if (!dot && isspace(buf[i])) {
 			dot = 1;
 			if (name[j++] != '.')
@@ -1215,7 +1217,17 @@ static int section_name_match (const char *buf, const char *name)
 		if (buf[i] != name[j++])
 			break;
 	}
-	return (buf[i] == ']' && name[j] == 0);
+	if (buf[i] == ']' && name[j] == 0) {
+		/*
+		 * We match, now just find the right length offset by
+		 * gobbling up any whitespace after it, as well
+		 */
+		i++;
+		for (; buf[i] && isspace(buf[i]); i++)
+			; /* do nothing */
+		return i;
+	}
+	return 0;
 }
 
 /* if new_name == NULL, the section is removed instead */
@@ -1249,7 +1261,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
 			; /* do nothing */
 		if (buf[i] == '[') {
 			/* it's a section */
-			if (section_name_match (&buf[i+1], old_name)) {
+			int offset = section_name_match (&buf[i], old_name);
+			if (offset > 0) {
 				ret++;
 				if (new_name == NULL) {
 					remove = 1;
-- 
1.6.3.3.473.gb74fc4.dirty

  reply	other threads:[~2009-07-24 21:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 21:21 [PATCH 0/2] Section renaming can lose content Alex Vandiver
2009-07-24 21:21 ` Alex Vandiver [this message]
2009-07-24 21:21   ` [PATCH 2/2] After renaming a section, print any trailing variable definitions Alex Vandiver
2009-07-24 22:11     ` Nanako Shiraishi
2009-07-24 22:26       ` Alex Vandiver
2009-07-26 16:18         ` [PATCH] Make git config fail on variables with no section, as documented Alex Vandiver
2009-07-26 16:49           ` Johannes Schindelin
2009-07-26 19:32             ` Alex Vandiver
2009-07-26 19:48               ` Johannes Schindelin
2009-07-26 20:24                 ` Alex Vandiver
2009-07-24 23:39       ` [PATCH 2/2] After renaming a section, print any trailing variable definitions Junio C Hamano
2009-07-25  0:28         ` (unknown), Nanako Shiraishi
2009-07-25 14:10         ` [PATCH 2/2] After renaming a section, print any trailing variable definitions Johannes Schindelin
2009-07-25 14:09   ` [PATCH 1/2] Make section_name_match start on '[', and return the length on success Johannes Schindelin
2009-07-25 17:18     ` Alex Vandiver
2009-07-25 17:39       ` Junio C Hamano
2009-07-25 17:41       ` Johannes Schindelin

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=1248470504-16326-2-git-send-email-alex@chmrr.net \
    --to=alex@chmrr.net \
    --cc=git@vger.kernel.org \
    /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).