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

Re: [PATCH] Don't use cpio in git-clone when not installed

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 1, 2007, 21:06 UTC
Message-ID
<7vlk9had5v.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20071101105318.GA4744@glandium.org>
Mike Hommey <mh@glandium.org> writes:
Show 10 quoted lines
> On Wed, Oct 31, 2007 at 06:15:27PM -0700, Junio C Hamano wrote:
>> "Nguyen Thai Ngoc Duy" <pclouds@gmail.com> writes:
>> 
>> > BTW, you have workaround for git-merge also? It uses cpio to save/restore state.
>> 
>> Why do people want "workaround"?  Is installing cpio such a
>> hassle?
>
> Note that to do what git-merge does with cpio, i wonder if it wouldn't
> be sensible to use git stash, now.
Like this?  That's an excellent suggestion.

The patch uses the 'git stash create' which is in 'next' (jc/stash-create topic).

Having said that, the savestate()/restorestate() codepaths are only relevant to the "try multiple strategies and pick the best one" feature of git-merge, and that is where cpio is used (and the patch rewrites it to use stash). I am not sure if anybody ever used it in practice. I admit I am guilty of inventing it, but I certainly do not.

It might make sense to remove that try-multiple-strategies feature from git-merge and be done with it. It would certainly make the eventual rewrite to C much easier.

---
 git-merge.sh |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index 3a01db0..e8916cc 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -28,20 +28,19 @@ allow_trivial_merge=t
 
 dropsave() {
 	rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
-		 "$GIT_DIR/MERGE_SAVE" || exit 1
+		 "$GIT_DIR/MERGE_STASH" || exit 1
 }
 
 savestate() {
 	# Stash away any local modifications.
-	git diff-index -z --name-only $head |
-	cpio -0 -o >"$GIT_DIR/MERGE_SAVE"
+	git stash create >"$GIT_DIR/MERGE_STASH"
 }
 
 restorestate() {
-        if test -f "$GIT_DIR/MERGE_SAVE"
+        if test -f "$GIT_DIR/MERGE_STASH"
 	then
 		git reset --hard $head >/dev/null
-		cpio -iuv <"$GIT_DIR/MERGE_SAVE"
+		git stash apply --index $(cat "$GIT_DIR/MERGE_STASH")
 		git update-index --refresh >/dev/null
 	fi
 }
@@ -386,7 +385,7 @@ case "$use_strategies" in
     single_strategy=no
     ;;
 *)
-    rm -f "$GIT_DIR/MERGE_SAVE"
+    rm -f "$GIT_DIR/MERGE_STASH"
     single_strategy=yes
     ;;
 esac
Previous: Mike Hommey
Message 16 of 16 in “Don't use cpio in git-clone when not installed”
  1. Don't use cpio in git-clone when not installedMike Hommey, Oct 31, 2007
  2. Mike HommeyOct 31, 2007
  3. Junio C HamanoOct 31, 2007
  4. Johannes SchindelinOct 31, 2007
  5. Linus TorvaldsNov 1, 2007
  6. Jakub NarebskiNov 1, 2007
  7. Nguyen Thai Ngoc DuyNov 1, 2007
  8. Junio C HamanoNov 1, 2007
  9. Mike HommeyNov 1, 2007
  10. Alexander SkwarNov 1, 2007
  11. Nguyen Thai Ngoc DuyNov 1, 2007
  12. Junio C HamanoNov 1, 2007
  13. Nguyen Thai Ngoc DuyNov 1, 2007
  14. Junio C HamanoNov 1, 2007
  15. Mike HommeyNov 1, 2007
  16. Junio C HamanoNov 1, 2007

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.