summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-04-26 20:05:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-04-28 03:40:24 (GMT)
commit9f41c7a6b3e3cc3ac4a739364400393fa2492880 (patch)
tree38753a8a56b7bc5e6a2a856780a9430f025f74e0
parent49800c940790cc7465d1b03e08d472ffd8684808 (diff)
downloadgit-9f41c7a6b3e3cc3ac4a739364400393fa2492880.zip
git-9f41c7a6b3e3cc3ac4a739364400393fa2492880.tar.gz
git-9f41c7a6b3e3cc3ac4a739364400393fa2492880.tar.bz2
read-cache: close index.lock in do_write_index
Teach do_write_index() to close the index.lock file before getting the mtime and updating the istate.timestamp fields. On Windows, a file's mtime is not updated until the file is closed. On Linux, the mtime is set after the last flush. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--read-cache.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/read-cache.c b/read-cache.c
index 9054369..c02b6be 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2011,9 +2011,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
rollback_lock_file(lockfile);
}
-static int do_write_index(struct index_state *istate, int newfd,
+static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int strip_extensions)
{
+ int newfd = tempfile->fd;
git_SHA_CTX c;
struct cache_header hdr;
int i, err, removed, extended, hdr_version;
@@ -2122,7 +2123,11 @@ static int do_write_index(struct index_state *istate, int newfd,
return -1;
}
- if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
+ if (ce_flush(&c, newfd, istate->sha1))
+ return -1;
+ if (close_tempfile(tempfile))
+ return error(_("could not close '%s'"), tempfile->filename.buf);
+ if (stat(tempfile->filename.buf, &st))
return -1;
istate->timestamp.sec = (unsigned int)st.st_mtime;
istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -2145,7 +2150,7 @@ static int commit_locked_index(struct lock_file *lk)
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
unsigned flags)
{
- int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
+ int ret = do_write_index(istate, &lock->tempfile, 0);
if (ret)
return ret;
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
@@ -2183,7 +2188,7 @@ static int write_shared_index(struct index_state *istate,
return do_write_locked_index(istate, lock, flags);
}
move_cache_to_base_index(istate);
- ret = do_write_index(si->base, fd, 1);
+ ret = do_write_index(si->base, &temporary_sharedindex, 1);
if (ret) {
delete_tempfile(&temporary_sharedindex);
return ret;