lockfile: change lock_file::filename into a strbuf
For now, we still make sure to allocate at least PATH_MAX characters for the strbuf because resolve_symlink() doesn't know how to expand the space for its return value. (That will be fixed in a moment.) Another alternative would be to just use a strbuf as scratch space in lock_file() but then store a pointer to the naked string in struct lock_file. But lock_file objects are often reused. By reusing the same strbuf, we can avoid having to reallocate the string most times when a lock_file object is reused. Helped-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
3e88e8fc08
commit
cf6950d3bf
14
config.c
14
config.c
@ -2024,9 +2024,9 @@ int git_config_set_multivar_in_file(const char *config_filename,
|
||||
MAP_PRIVATE, in_fd, 0);
|
||||
close(in_fd);
|
||||
|
||||
if (chmod(lock->filename, st.st_mode & 07777) < 0) {
|
||||
if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
|
||||
error("chmod on %s failed: %s",
|
||||
lock->filename, strerror(errno));
|
||||
lock->filename.buf, strerror(errno));
|
||||
ret = CONFIG_NO_WRITE;
|
||||
goto out_free;
|
||||
}
|
||||
@ -2106,7 +2106,7 @@ out_free:
|
||||
return ret;
|
||||
|
||||
write_err_out:
|
||||
ret = write_error(lock->filename);
|
||||
ret = write_error(lock->filename.buf);
|
||||
goto out_free;
|
||||
|
||||
}
|
||||
@ -2207,9 +2207,9 @@ int git_config_rename_section_in_file(const char *config_filename,
|
||||
|
||||
fstat(fileno(config_file), &st);
|
||||
|
||||
if (chmod(lock->filename, st.st_mode & 07777) < 0) {
|
||||
if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {
|
||||
ret = error("chmod on %s failed: %s",
|
||||
lock->filename, strerror(errno));
|
||||
lock->filename.buf, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -2230,7 +2230,7 @@ int git_config_rename_section_in_file(const char *config_filename,
|
||||
}
|
||||
store.baselen = strlen(new_name);
|
||||
if (!store_write_section(out_fd, new_name)) {
|
||||
ret = write_error(lock->filename);
|
||||
ret = write_error(lock->filename.buf);
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
@ -2256,7 +2256,7 @@ int git_config_rename_section_in_file(const char *config_filename,
|
||||
continue;
|
||||
length = strlen(output);
|
||||
if (write_in_full(out_fd, output, length) != length) {
|
||||
ret = write_error(lock->filename);
|
||||
ret = write_error(lock->filename.buf);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user