Re: [PATCH] allow git-am to run in a subdirectory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 29, 2008 at 11:38:55PM -0800, Junio C Hamano wrote:

> As long as you do not lose sight of the mailbox parameter by chdir'ing
> around, I am Ok with the patch.
> 
> ... and after I started writing that, I find...

Ugh. Below is a patch that saves the original pwd and prefixes it for
relative paths. However:

  - it probably doesn't correctly determine absolute versus relative
    paths on Windows. I don't think we have a solution for fixing this
    within shell scripts.

  - it will eat newlines in parameters names (actually, turning them
    into spaces)

The problem is that I need to turn the original "$@" into a new "$@"
that is correctly prefixed, which requires proper quoting. Please, spend
some of your shell guru points to show me how to do this correctly and
portably.

We could wait on doing the 'cd_to_toplevel' until after the mailsplit,
but then your .dotest will end up in a prefixed directory (and of course
we have a similar munging problem when we point .dotest to the right
spot).

Maybe I should just wait for a git-am rewrite in C. ;)

---
diff --git a/git-am.sh b/git-am.sh
index 2ecebc4..a5e0c43 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2005, 2006 Junio C Hamano
 
+SUBDIRECTORY_OK=Yes
 OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git-am [options] <mbox>|<Maildir>...
@@ -25,6 +26,13 @@ skip            skip the current patch"
 . git-sh-setup
 set_reflog_action am
 require_work_tree
+orig_pwd=$(pwd)
+cd_to_toplevel
+if test "$(pwd)" = "$orig_pwd"; then
+	orig_pwd=
+else
+	orig_pwd="$orig_pwd/"
+fi
 
 git var GIT_COMMITTER_IDENT >/dev/null || exit
 
@@ -121,6 +129,21 @@ reread_subject () {
 	git stripspace <"$1" | sed -e 1q
 }
 
+shellquote() {
+	printf \'
+	printf "$1" | sed "s/'/\\'/g"
+	echo \'
+}
+
+handle_file_args() {
+	for i in "$@"; do
+		case "$i" in
+		/*) shellquote "$i";;
+		 *) shellquote "$orig_pwd$i";;
+		esac
+	done
+}
+
 prec=4
 dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
 resolvemsg= resume=
@@ -148,7 +171,7 @@ do
 	--skip)
 		skip=t ;;
 	-d|--dotest)
-		shift; dotest=$1;;
+		shift; eval dotest=`handle_file_args "$1"` ;;
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
 	--whitespace)
@@ -163,6 +186,8 @@ do
 	shift
 done
 
+eval set -- `handle_file_args "$@"`
+
 # If the dotest directory exists, but we have finished applying all the
 # patches in them, clear it out.
 if test -d "$dotest" &&
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux