提交 a4c0d463 编写于 作者: A Alex Vandiver 提交者: Junio C Hamano

Make section_name_match start on '[', and return the length on success

Signed-off-by: NAlex Vandiver <alex@chmrr.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 735c6744
...@@ -1174,7 +1174,9 @@ int git_config_set_multivar(const char *key, const char *value, ...@@ -1174,7 +1174,9 @@ int git_config_set_multivar(const char *key, const char *value,
static int section_name_match (const char *buf, const char *name) static int section_name_match (const char *buf, const char *name)
{ {
int i = 0, j = 0, dot = 0; 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])) { if (!dot && isspace(buf[i])) {
dot = 1; dot = 1;
if (name[j++] != '.') if (name[j++] != '.')
...@@ -1195,7 +1197,17 @@ static int section_name_match (const char *buf, const char *name) ...@@ -1195,7 +1197,17 @@ static int section_name_match (const char *buf, const char *name)
if (buf[i] != name[j++]) if (buf[i] != name[j++])
break; 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 */ /* if new_name == NULL, the section is removed instead */
...@@ -1229,7 +1241,8 @@ int git_config_rename_section(const char *old_name, const char *new_name) ...@@ -1229,7 +1241,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
; /* do nothing */ ; /* do nothing */
if (buf[i] == '[') { if (buf[i] == '[') {
/* it's a section */ /* 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++; ret++;
if (new_name == NULL) { if (new_name == NULL) {
remove = 1; remove = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册