diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-11-06 13:11:21 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-06 13:11:21 +0900 |
commit | 0b646bcac96a57e345887e607e0b8c9a64ff262a (patch) | |
tree | 4c4e0e29d1743413c7fa0e1172ccebb7cbc37191 /config.c | |
parent | cb5918aa0d50f50e83787f65c2ddc3dcb10159fe (diff) | |
parent | b74c90fb419b002c664b0236f2941c34786b18b9 (diff) | |
download | git-0b646bcac96a57e345887e607e0b8c9a64ff262a.tar.gz |
Merge branch 'ma/lockfile-fixes'
An earlier update made it possible to use an on-stack in-core
lockfile structure (as opposed to having to deliberately leak an
on-heap one). Many codepaths have been updated to take advantage
of this new facility.
* ma/lockfile-fixes:
read_cache: roll back lock in `update_index_if_able()`
read-cache: leave lock in right state in `write_locked_index()`
read-cache: drop explicit `CLOSE_LOCK`-flag
cache.h: document `write_locked_index()`
apply: remove `newfd` from `struct apply_state`
apply: move lockfile into `apply_state`
cache-tree: simplify locking logic
checkout-index: simplify locking logic
tempfile: fix documentation on `delete_tempfile()`
lockfile: fix documentation on `close_lock_file_gently()`
treewide: prefer lockfiles on the stack
sha1_file: do not leak `lock_file`
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -2751,7 +2751,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename { int ret = 0, remove = 0; char *filename_buf = NULL; - struct lock_file *lock; + struct lock_file lock = LOCK_INIT; int out_fd; char buf[1024]; FILE *config_file = NULL; @@ -2766,8 +2766,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename if (!config_filename) config_filename = filename_buf = git_pathdup("config"); - lock = xcalloc(1, sizeof(struct lock_file)); - out_fd = hold_lock_file_for_update(lock, config_filename, 0); + out_fd = hold_lock_file_for_update(&lock, config_filename, 0); if (out_fd < 0) { ret = error("could not lock config file %s", config_filename); goto out; @@ -2786,9 +2785,9 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename goto out; } - if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { + if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) { ret = error_errno("chmod on %s failed", - get_lock_file_path(lock)); + get_lock_file_path(&lock)); goto out; } @@ -2812,7 +2811,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename */ if (copystr.len > 0) { if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) { - ret = write_error(get_lock_file_path(lock)); + ret = write_error(get_lock_file_path(&lock)); goto out; } strbuf_reset(©str); @@ -2828,7 +2827,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename store.baselen = strlen(new_name); if (!copy) { if (write_section(out_fd, new_name) < 0) { - ret = write_error(get_lock_file_path(lock)); + ret = write_error(get_lock_file_path(&lock)); goto out; } /* @@ -2862,7 +2861,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename } if (write_in_full(out_fd, output, length) < 0) { - ret = write_error(get_lock_file_path(lock)); + ret = write_error(get_lock_file_path(&lock)); goto out; } } @@ -2874,7 +2873,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename */ if (copystr.len > 0) { if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) { - ret = write_error(get_lock_file_path(lock)); + ret = write_error(get_lock_file_path(&lock)); goto out; } strbuf_reset(©str); @@ -2883,13 +2882,13 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename fclose(config_file); config_file = NULL; commit_and_out: - if (commit_lock_file(lock) < 0) + if (commit_lock_file(&lock) < 0) ret = error_errno("could not write config file %s", config_filename); out: if (config_file) fclose(config_file); - rollback_lock_file(lock); + rollback_lock_file(&lock); out_no_rollback: free(filename_buf); return ret; |