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

Previous thread: Newbie: report of first experience with git-rebase. by Sergei Organov on Wednesday, October 31, 2007 - 3:39 pm. (16 messages)

Next thread: Bug in git-show-branch, or in core-tutorial? by Sergei Organov on Wednesday, October 31, 2007 - 4:17 pm. (3 messages)
To: <git@...>
Cc: Junio C Hamano <gitster@...>
Date: Wednesday, October 31, 2007 - 4:05 pm

Signed-off-by: Mike Hommey <mh@glandium.org>
---
git-clone.sh | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 0ea3c24..57e96ae 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -191,7 +191,9 @@ fi
# it is local
if base=$(get_repo_base "$repo"); then
repo="$base"
- local=yes
+ if type cpio > /dev/null 2>&1; then
+ local=yes
+ fi
fi

dir="$2"
--
1.5.3.4

-

To: Mike Hommey <mh@...>
Cc: Junio C Hamano <gitster@...>, <git@...>
Date: Wednesday, October 31, 2007 - 9:09 pm

BTW, you have workaround for git-merge also? It uses cpio to save/restore state.

--
Duy
-

To: Nguyen Thai Ngoc Duy <pclouds@...>
Cc: Mike Hommey <mh@...>, Junio C Hamano <gitster@...>, <git@...>
Date: Wednesday, October 31, 2007 - 9:15 pm

Why do people want "workaround"? Is installing cpio such a
hassle?

-

To: Junio C Hamano <gitster@...>
Cc: Nguyen Thai Ngoc Duy <pclouds@...>, <git@...>
Date: Thursday, November 1, 2007 - 6:53 am

Note that to do what git-merge does with cpio, i wonder if it wouldn't
be sensible to use git stash, now.

Mike
-

To: Mike Hommey <mh@...>
Cc: Nguyen Thai Ngoc Duy <pclouds@...>, <git@...>
Date: Thursday, November 1, 2007 - 5:06 pm

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
-

To: Junio C Hamano <gitster@...>
Cc: Mike Hommey <mh@...>, <git@...>
Date: Wednesday, October 31, 2007 - 9:25 pm

It is on Windows because busybox cpio is not really good and busybox
tar is even worse (for cpio emulation). Maybe I should just improve
busybox cpio :-)
--
Duy
-

To: Nguyen Thai Ngoc Duy <pclouds@...>
Cc: Mike Hommey <mh@...>, Junio C Hamano <gitster@...>, <git@...>
Date: Thursday, November 1, 2007 - 2:45 am

Sounds sensible, as it (at least its -p mode of operation) is
one of the programs that is very useful yet not so well known to
people new to UNIX.

-

To: Mike Hommey <mh@...>
Cc: Junio C Hamano <gitster@...>, <git@...>
Date: Wednesday, October 31, 2007 - 8:46 pm

Isn't "type" a bashism?

Maybe just do

if echo . | cpio -o > /dev/null 2>&1; then

instead? Maybe even doing this at install time to avoid the overhead of
executing another process..

Linus
-

To: Linus Torvalds <torvalds@...>
Cc: Junio C Hamano <gitster@...>, <git@...>
Date: Thursday, November 1, 2007 - 2:31 am

I think it's POSIX, and since I found the same construct in
git-mergetool.sh, I thought it would be okay for git.

Mike
-

To: Linus Torvalds <torvalds@...>
Cc: Mike Hommey <mh@...>, <git@...>
Date: Wednesday, October 31, 2007 - 9:12 pm

I seem to recall that it is in POSIX.
-

To: Linus Torvalds <torvalds@...>
Cc: Mike Hommey <mh@...>, Junio C Hamano <gitster@...>, <git@...>
Date: Wednesday, October 31, 2007 - 9:05 pm

busybox ash has "type". I'm happy.

--
Duy
-

To: Mike Hommey <mh@...>
Cc: <git@...>
Date: Wednesday, October 31, 2007 - 6:29 pm

"type"? That's probably better than using "which", but sounds
quite wrong. Why not add Makefile target that the shell scripts
depend on to see if necessary tools are available and let the
builder know if they are not?
-

To: Junio C Hamano <gitster@...>
Cc: Mike Hommey <mh@...>, <git@...>
Date: Wednesday, October 31, 2007 - 7:55 pm

Hi,

I thought the accord was that "cpio" is a _runtime_ dependency. But yes,
I agree "type" is not necessarily the best choice. Maybe testing the exit
code for 127 (not found) is the better choice?

Ciao,
Dscho

-

To: <git@...>
Date: Wednesday, October 31, 2007 - 4:10 pm

Damn, and I forgot git-send-email doesn't add the <> to In-Reply-To.

Mike
-

Previous thread: Newbie: report of first experience with git-rebase. by Sergei Organov on Wednesday, October 31, 2007 - 3:39 pm. (16 messages)

Next thread: Bug in git-show-branch, or in core-tutorial? by Sergei Organov on Wednesday, October 31, 2007 - 4:17 pm. (3 messages)