From: Johannes Sixt <j.sixt@viscovery.net>
To: git@vger.kernel.org
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
Junio C Hamano <gitster@pobox.com>,
Jakob Pfender <jpfender@elegosoft.com>,
casey@nrlssc.navy.mil, jon.seymour@gmail.com
Subject: [PATCH 2/2 v2] stash: copy the index using --index-output instead of cp -p
Date: Wed, 16 Mar 2011 09:18:49 +0100 [thread overview]
Message-ID: <4D807269.1070802@viscovery.net> (raw)
In-Reply-To: <4D8070E1.8000305@viscovery.net>
From: Johannes Sixt <j6t@kdbg.org>
'git stash create' must operate with a temporary index. For this purpose,
it used 'cp -p' to create a copy. -p is needed to preserve the timestamp
of the index file. Now Jakob Pfender reported a certain combination of
a Linux NFS client, OpenBSD NFS server, and cp implementation where this
operation failed.
Luckily, the first operation in git-stash after copying the index is to
call 'git read-tree'. Therefore, use --index-output instead of 'cp -p'
to write the copy of the index.
--index-output requires that the specified file is on the same volume as
the source index, so that the lock file can be rename()d. For this reason,
the name of the temporary index is constructed in a way different from the
other temporary files. The code path of 'stash -p' also needs a temporary
index, but we do not use the new name because it does not depend on the
same precondition as --index-output.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Changes since v1:
- Addresses the --index-output precondition.
- Also removes the first 'rm -f "$TMP-index" &&'
Warning: This was only tested by the test suite.
git-stash.sh | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 7c0d563..5130228 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -17,7 +17,8 @@ require_work_tree
cd_to_toplevel
TMP="$GIT_DIR/.git-stash.$$"
-trap 'rm -f "$TMP-"*' 0
+TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$
+trap 'rm -f "$TMP-"* "$TMPindex"' 0
ref_stash=refs/stash
@@ -81,14 +82,12 @@ create_stash () {
# state of the working tree
w_tree=$( (
- rm -f "$TMP-index" &&
- cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" &&
- GIT_INDEX_FILE="$TMP-index" &&
+ git read-tree --index-output="$TMPindex" -m $i_tree &&
+ GIT_INDEX_FILE="$TMPindex" &&
export GIT_INDEX_FILE &&
- git read-tree -m $i_tree &&
git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
git write-tree &&
- rm -f "$TMP-index"
+ rm -f "$TMPindex"
) ) ||
die "Cannot save the current worktree state"
--
1.7.4.1.316.g2ab2cb
prev parent reply other threads:[~2011-03-16 8:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 10:08 [RFD] git stash over OpenBSD/Linux NFS - cp -p breakage Jakob Pfender
2011-03-15 10:58 ` Johannes Sixt
2011-03-15 12:00 ` Jakob Pfender
2011-03-15 12:37 ` [PATCH] stash: copy the index using --index-output instead of cp -p Johannes Sixt
2011-03-15 19:28 ` Junio C Hamano
2011-03-15 19:53 ` Bert Wesarg
2011-03-16 8:12 ` Johannes Sixt
2011-03-16 8:14 ` [PATCH 1/2] stash: fix incorrect quoting in cleanup of temporary files Johannes Sixt
2011-03-16 8:18 ` Johannes Sixt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D807269.1070802@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=bert.wesarg@googlemail.com \
--cc=casey@nrlssc.navy.mil \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jon.seymour@gmail.com \
--cc=jpfender@elegosoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).