git-commit: Implement racy-safe save_index() with ln instead of cp -p.

git-commit must allocate a copy of the current index if only a subset of
files is to be commited in save_index(). It uses 'cp -p' because the index
may contain racily-clean entries, which will be detected only if the
timestamp of the index remains unaltered.

In general, it is safe to create a hardlink instead of copying the index
because all writers use the lock_file infrastructure that writes a new
file and moves it into the destination, breaking the hardlink.

On Windows, in particular, 'cp -p' suffers from a mysterious inability to
accurately preserve the timestamp under some circumstances. (This was
detected by the test suite, where some racily clean files were not
recognized.) 'ln' does create a hardlink on Windows on NTFS, and makes
a copy with the correctly preserved timestamp on FAT.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This commit is contained in:
Johannes Sixt
2007-09-21 21:31:51 +02:00
parent b49fa05b92
commit a64e23954f

View File

@@ -29,7 +29,7 @@ THIS_INDEX="$GIT_DIR/index"
NEXT_INDEX="$GIT_DIR/next-index$$"
rm -f "$NEXT_INDEX"
save_index () {
cp -p "$THIS_INDEX" "$NEXT_INDEX"
ln "$THIS_INDEX" "$NEXT_INDEX"
}
run_status () {