git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFD] git stash over OpenBSD/Linux NFS - cp -p breakage

From
JPJakob Pfender <jpfender@elegosoft.com>
Date
Mar 15, 2011, 12:00 UTC
Message-ID
<4D7F54C2.5060500@elegosoft.com>
In-Reply-To
<4D7F466A.4090508@viscovery.net>
On 03/15/2011 11:58 AM, Johannes Sixt wrote:
 > Am 3/15/2011 11:08, schrieb Jakob Pfender:
 >> We have an NFS setup with Linux machines mounting an NFS that is 
hosted on
 >> an OpenBSD server. Recently, we discovered git-stash breaking with:
 >>
 >> $ git stash
 >> cp: preserving permissions for
 >> `/home/jpfender/stashtest/.git/.git-stash.3056-index': Operation not
 >> supported
 >> Cannot save the current worktree state
 >>
 >> This was discovered to be caused by a bug in cp that causes 'cp -p' to
 >> fail in this particular NFS setup - preserving permissions in an NFS
 >> shared across Linux and OpenBSD machines doesn't work.
 >>
 >> I looked at git-stash.sh and could not discover a reason why it had 
to use
 >> 'cp -p'. I patched it to use only cp without preserving permissions, and
 >> everything seemed to work fine. All stash tests succeeded (bar two known
 >> breakages).
 >>
 >> So my question is: Does git-stash really need 'cp -p'? Is it safe to 
remove?
 >
 > Yes. No.
 >
 > The timestamp of the index file is important. It is needed to discover
 > racily-clean index entries. Therefore, the -p must remain.

You're right. The funny thing is: 'cp --preserve=timestamps' works over NFS, 'cp -p' just fails because it wants to copy file ownership as well.

 >
 > You can also try the patch below. Warning: completely untested.

Works fine for me! Also has the advantage that a git tool is used to copy the data, which can interpret the data better than cp could if need arose.

Does anyone want to commit Hannes' patch with the following log message:
Subject: [PATCH] git-stash.sh: Use git-read-tree instead of cp -p

cp -p fails in certain Linux/*BSD NFS setups because it wants to preserve file ownership. However, the reason we use -p is because we want to preserve the timestamp. This can be achieved by using git-read-tree --index-output=<tmp-file>, which copies all the data including the timestamp and avoids using cp -p altogether.

Signed-off-by: Johannes Sixt <j.sixt@viscovery.net>
Acked-by: Jakob Pfender <jpfender@elegosoft.com>
---
  git-stash.sh |    3 +--
  1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 7561b37..fa62135 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -82,10 +82,9 @@ create_stash () {
  		# state of the working tree
  		w_tree=$( (
  			rm -f "$TMP-index" &&
-			cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" &&
+			git read-tree --index-output="$TMP-index" -m $i_tree &&
  			GIT_INDEX_FILE="$TMP-index" &&
  			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"
-- 
1.7.0.4
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 9 in “[RFD] git stash over OpenBSD/Linux NFS - cp -p breakage”
  1. Jakob PfenderMar 15, 2011
  2. Johannes SixtMar 15, 2011
  3. Jakob PfenderMar 15, 2011
  4. stash: copy the index using --index-output instead of cp -pJohannes Sixt, Mar 15, 2011
  5. Junio C HamanoMar 15, 2011
  6. Bert WesargMar 15, 2011
  7. Johannes SixtMar 16, 2011
  8. 1/2 stash: fix incorrect quoting in cleanup of temporary filesJohannes Sixt, Mar 16, 2011
  9. 2/2 stash: copy the index using --index-output instead of cp -pJohannes Sixt, Mar 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.