Skip to content

Commit 9f41c7a

Browse files
jeffhostetlergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49800c9 commit 9f41c7a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

read-cache.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,9 +2011,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
20112011
rollback_lock_file(lockfile);
20122012
}
20132013

2014-
static int do_write_index(struct index_state *istate, int newfd,
2014+
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
20152015
int strip_extensions)
20162016
{
2017+
int newfd = tempfile->fd;
20172018
git_SHA_CTX c;
20182019
struct cache_header hdr;
20192020
int i, err, removed, extended, hdr_version;
@@ -2122,7 +2123,11 @@ static int do_write_index(struct index_state *istate, int newfd,
21222123
return -1;
21232124
}
21242125

2125-
if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
2126+
if (ce_flush(&c, newfd, istate->sha1))
2127+
return -1;
2128+
if (close_tempfile(tempfile))
2129+
return error(_("could not close '%s'"), tempfile->filename.buf);
2130+
if (stat(tempfile->filename.buf, &st))
21262131
return -1;
21272132
istate->timestamp.sec = (unsigned int)st.st_mtime;
21282133
istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -2145,7 +2150,7 @@ static int commit_locked_index(struct lock_file *lk)
21452150
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
21462151
unsigned flags)
21472152
{
2148-
int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
2153+
int ret = do_write_index(istate, &lock->tempfile, 0);
21492154
if (ret)
21502155
return ret;
21512156
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
@@ -2183,7 +2188,7 @@ static int write_shared_index(struct index_state *istate,
21832188
return do_write_locked_index(istate, lock, flags);
21842189
}
21852190
move_cache_to_base_index(istate);
2186-
ret = do_write_index(si->base, fd, 1);
2191+
ret = do_write_index(si->base, &temporary_sharedindex, 1);
21872192
if (ret) {
21882193
delete_tempfile(&temporary_sharedindex);
21892194
return ret;

0 commit comments

Comments
 (0)