diff options
author | Junio C Hamano <junkio@cox.net> | 2007-03-08 00:53:38 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-03-08 00:53:38 -0800 |
commit | bd1fc628b8d456bdaea3e10d435cf1e98bc5d8a8 (patch) | |
tree | 0c8847f5b24622dc1158edd48b3e0de1cd7f3255 /config.c | |
parent | f45fa2a073da591f3ac0b63900e07afa2dccee44 (diff) | |
parent | 118f8b241355b38cd21e644e8620d81f10190627 (diff) | |
download | git-bd1fc628b8d456bdaea3e10d435cf1e98bc5d8a8.tar.gz git-bd1fc628b8d456bdaea3e10d435cf1e98bc5d8a8.tar.xz |
Merge branch 'js/config-rename'
* js/config-rename:
git-config: document --rename-section, provide --remove-section
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 60 |
1 files changed, 36 insertions, 24 deletions
@@ -861,9 +861,37 @@ 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 (!dot && isspace(buf[i])) { + dot = 1; + if (name[j++] != '.') + break; + for (i++; isspace(buf[i]); i++) + ; /* do nothing */ + if (buf[i] != '"') + break; + continue; + } + if (buf[i] == '\\' && dot) + i++; + else if (buf[i] == '"' && dot) { + for (i++; isspace(buf[i]); i++) + ; /* do_nothing */ + break; + } + if (buf[i] != name[j++]) + break; + } + return (buf[i] == ']' && name[j] == 0); +} + +/* if new_name == NULL, the section is removed instead */ int git_config_rename_section(const char *old_name, const char *new_name) { - int ret = 0; + int ret = 0, remove = 0; char *config_filename; struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1); int out_fd; @@ -894,31 +922,12 @@ int git_config_rename_section(const char *old_name, const char *new_name) ; /* do nothing */ if (buf[i] == '[') { /* it's a section */ - int j = 0, dot = 0; - for (i++; buf[i] && buf[i] != ']'; i++) { - if (!dot && isspace(buf[i])) { - dot = 1; - if (old_name[j++] != '.') - break; - for (i++; isspace(buf[i]); i++) - ; /* do nothing */ - if (buf[i] != '"') - break; + if (section_name_match (&buf[i+1], old_name)) { + ret++; + if (new_name == NULL) { + remove = 1; continue; } - if (buf[i] == '\\' && dot) - i++; - else if (buf[i] == '"' && dot) { - for (i++; isspace(buf[i]); i++) - ; /* do_nothing */ - break; - } - if (buf[i] != old_name[j++]) - break; - } - if (buf[i] == ']' && old_name[j] == 0) { - /* old_name matches */ - ret++; store.baselen = strlen(new_name); if (!store_write_section(out_fd, new_name)) { ret = write_error(); @@ -926,7 +935,10 @@ int git_config_rename_section(const char *old_name, const char *new_name) } continue; } + remove = 0; } + if (remove) + continue; length = strlen(buf); if (write_in_full(out_fd, buf, length) != length) { ret = write_error(); |