From a64e23954fc617019354a929dcefaa6049c2f744 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 21 Sep 2007 21:31:51 +0200 Subject: [PATCH] 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 --- git-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-commit.sh b/git-commit.sh index 1d04f1ff31..427b48dd8b 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -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 () {