Merge branch 'mh/tempfile'

The "lockfile" API has been rebuilt on top of a new "tempfile" API.

* mh/tempfile:
  credential-cache--daemon: use tempfile module
  credential-cache--daemon: delete socket from main()
  gc: use tempfile module to handle gc.pid file
  lock_repo_for_gc(): compute the path to "gc.pid" only once
  diff: use tempfile module
  setup_temporary_shallow(): use tempfile module
  write_shared_index(): use tempfile module
  register_tempfile(): new function to handle an existing temporary file
  tempfile: add several functions for creating temporary files
  prepare_tempfile_object(): new function, extracted from create_tempfile()
  tempfile: a new module for handling temporary files
  commit_lock_file(): use get_locked_file_path()
  lockfile: add accessor get_lock_file_path()
  lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()
  create_bundle(): duplicate file descriptor to avoid closing it twice
  lockfile: move documentation to lockfile.h and lockfile.c
This commit is contained in:
Junio C Hamano
2015-08-25 14:57:09 -07:00
18 changed files with 964 additions and 625 deletions

18
refs.c
View File

@ -3401,6 +3401,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
{
static char term = '\n';
struct object *o;
int fd;
o = parse_object(sha1);
if (!o) {
@ -3417,11 +3418,12 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
unlock_ref(lock);
return -1;
}
if (write_in_full(lock->lk->fd, sha1_to_hex(sha1), 40) != 40 ||
write_in_full(lock->lk->fd, &term, 1) != 1 ||
fd = get_lock_file_fd(lock->lk);
if (write_in_full(fd, sha1_to_hex(sha1), 40) != 40 ||
write_in_full(fd, &term, 1) != 1 ||
close_ref(lock) < 0) {
strbuf_addf(err,
"Couldn't write %s", lock->lk->filename.buf);
"Couldn't write %s", get_lock_file_path(lock->lk));
unlock_ref(lock);
return -1;
}
@ -4608,7 +4610,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
cb.newlog = fdopen_lock_file(&reflog_lock, "w");
if (!cb.newlog) {
error("cannot fdopen %s (%s)",
reflog_lock.filename.buf, strerror(errno));
get_lock_file_path(&reflog_lock), strerror(errno));
goto failure;
}
}
@ -4633,12 +4635,12 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
status |= error("couldn't write %s: %s", log_file,
strerror(errno));
} else if (update &&
(write_in_full(lock->lk->fd,
(write_in_full(get_lock_file_fd(lock->lk),
sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
write_str_in_full(lock->lk->fd, "\n") != 1 ||
close_ref(lock) < 0)) {
write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 ||
close_ref(lock) < 0)) {
status |= error("couldn't write %s",
lock->lk->filename.buf);
get_lock_file_path(lock->lk));
rollback_lock_file(&reflog_lock);
} else if (commit_lock_file(&reflog_lock)) {
status |= error("unable to commit reflog '%s' (%s)",