X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=config.c;h=0f518c957cda48bb4fdc3aa7b472bb8a1c26a3bf;hb=a62be77f5ebdbbd46d6956dc4d07571835588389;hp=11d65f8c70b692327de5bfaa8afe1e7979aafea6;hpb=5d8ee9ceb8912c83336191d32b8898943b8944b8;p=git.git diff --git a/config.c b/config.c index 11d65f8c..0f518c95 100644 --- a/config.c +++ b/config.c @@ -336,8 +336,10 @@ static int store_aux(const char* key, const char* value) store.state = KEY_SEEN; store.seen++; } else if (strrchr(key, '.') - key == store.baselen && - !strncmp(key, store.key, store.baselen)) + !strncmp(key, store.key, store.baselen)) { store.state = SECTION_SEEN; + store.offset[store.seen] = ftell(config_file); + } } return 0; } @@ -420,7 +422,7 @@ int git_config_set_multivar(const char* key, const char* value, const char* value_regex, int multi_replace) { int i; - int fd, in_fd; + int fd = -1, in_fd; int ret; char* config_filename = strdup(git_path("config")); char* lock_file = strdup(git_path("config.lock")); @@ -478,15 +480,11 @@ int git_config_set_multivar(const char* key, const char* value, if ( ENOENT != errno ) { error("opening %s: %s", config_filename, strerror(errno)); - close(fd); - unlink(lock_file); ret = 3; /* same as "invalid config file" */ goto out_free; } /* if nothing to unset, error out */ if (value == NULL) { - close(fd); - unlink(lock_file); ret = 5; goto out_free; } @@ -514,8 +512,6 @@ int git_config_set_multivar(const char* key, const char* value, fprintf(stderr, "Invalid pattern: %s\n", value_regex); free(store.value_regex); - close(fd); - unlink(lock_file); ret = 6; goto out_free; } @@ -551,8 +547,6 @@ int git_config_set_multivar(const char* key, const char* value, /* if nothing to unset, or too many matches, error out */ if ((store.seen == 0 && value == NULL) || (store.seen > 1 && multi_replace == 0)) { - close(fd); - unlink(lock_file); ret = 5; goto out_free; } @@ -601,8 +595,6 @@ int git_config_set_multivar(const char* key, const char* value, unlink(config_filename); } - close(fd); - if (rename(lock_file, config_filename) < 0) { fprintf(stderr, "Could not rename the lock file?\n"); ret = 4; @@ -612,10 +604,14 @@ int git_config_set_multivar(const char* key, const char* value, ret = 0; out_free: + if (0 <= fd) + close(fd); if (config_filename) free(config_filename); - if (lock_file) + if (lock_file) { + unlink(lock_file); free(lock_file); + } return ret; }