threads / patch / 16598

patchAllow passing of --directory to git-am.

Subject: [PATCH] Allow passing of --directory to git-am.

## tl;dr

13 messages between Dec 4, 2008 and Dec 5, 2008. Diffs are folded; open one to read it.

replies: 12people: 4as markdown or json

Simon 'corecode' Schubert· Dec 4, 2008, 18:48 UTC · lore

We need to play some shell tricks to be able to pass directory names which contain spaces and/or quotes.

Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
---
Boyd Stephen Smith Jr. wrote:
 > I'm thinking your sed line doesn't do what you think it does.  You 
probably
 > want something like:
 > bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
 > don'\''t
Thanks, I clearly did not test this well enough.
  git-am.sh |    8 +++++---
  1 files changed, 5 insertions(+), 3 deletions(-)
Show changes to git-am.sh +5 −3
diff --git a/git-am.sh b/git-am.sh
index aa60261..3baff4e 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit 
message
  u,utf8          recode into utf8 (default)
  k,keep          pass -k flag to git-mailinfo
  whitespace=     pass it through git-apply
+directory=      pass it through git-apply
  C=              pass it through git-apply
  p=              pass it through git-apply
  resolvemsg=     override error message when patch failure occurs
@@ -155,8 +156,9 @@ do
  		;;
  	--resolvemsg)
  		shift; resolvemsg=$1 ;;
-	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+	--whitespace|--directory)
+		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")
+		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
  	-C|-p)
  		git_apply_opt="$git_apply_opt $1$2"; shift ;;
  	--)
@@ -454,7 +456,7 @@ do

  	case "$resolved" in
  	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		eval git apply $git_apply_opt --index '"$dotest/patch"'
  		apply_status=$?
  		;;
  	t)
-- 
1.6.1.rc1.45.g123ed.dirty
Jeff King· Dec 4, 2008, 18:51 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

On Thu, Dec 04, 2008 at 07:48:50PM +0100, Simon 'corecode' Schubert wrote:
Show 8 quoted lines
> Boyd Stephen Smith Jr. wrote:
> > I'm thinking your sed line doesn't do what you think it does.  You  
> probably
> > want something like:
> > bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
> > don'\''t
>
> Thanks, I clearly did not test this well enough.
Maybe it would be a good idea to add a test to the test script, then?
-Peff
Junio C Hamano· Dec 4, 2008, 19:27 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
> We need to play some shell tricks to be able to pass directory names
> which contain spaces and/or quotes.

There already was an earlier attempt for this feature by Kevin Ballard, which had issues I pointed out:

  http://thread.gmane.org/gmane.comp.version-control.git/94335/focus=94456

The patch was carried for a few weeks in 'pu' but was dropped due to lack of follow-up updates.

Does your version address the issues Kevin's one had?
Simon 'corecode' Schubert· Dec 4, 2008, 22:26 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow passing of --directory to git-am.

Junio C Hamano wrote:
Show 14 quoted lines
> Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
> 
>> We need to play some shell tricks to be able to pass directory names
>> which contain spaces and/or quotes.
> 
> There already was an earlier attempt for this feature by Kevin Ballard,
> which had issues I pointed out:
> 
>   http://thread.gmane.org/gmane.comp.version-control.git/94335/focus=94456
> 
> The patch was carried for a few weeks in 'pu' but was dropped due to lack
> of follow-up updates.
> 
> Does your version address the issues Kevin's one had?

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

cheers
   simon
-- 
   <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
   rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
Junio C Hamano· Dec 4, 2008, 22:33 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
> You mean not storing/restoring the flags across an invocation?  No,
> that's a different thing.  My patch only adds the --directory option,
> it does not fix the previously existing bug.

The question is if it _introduces_ a bug that the directory given in the initial invocation of "git am --directory=foo" is lost if an patch does not apply and you need to manually resolve and continue.

If it does not introduce such a bug, you do not have the same issue as the old patch. Otherwise you have the same issue as the old patch. The question was if you have the same issue or you don't. Yes? No?

Junio C Hamano· Dec 4, 2008, 23:14 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow passing of --directory to git-am.

Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
>
>> You mean not storing/restoring the flags across an invocation?  No,
>> that's a different thing.  My patch only adds the --directory option,
>> it does not fix the previously existing bug.
>
> The question is if it _introduces_ a bug that the directory given in the
> initial invocation of "git am --directory=foo" is lost if an patch does
> not apply and you need to manually resolve and continue.
>
> If it does not introduce such a bug, you do not have the same issue as the
> old patch.  Otherwise you have the same issue as the old patch.  The
> question was if you have the same issue or you don't.  Yes?  No?

I think this fixes the --whitespace=* one, although I obviously haven't tried to use it myself extensively.

The third hunk is just a style fix. "am" is written in a quite old fashioned way.

-- >8 --
Subject: [PATCH] git-am --whitespace: do not lose the command line option

When you start "git am --whitespace=fix" and the patch application process is interrupted by an unapplicable patch early in the series, after fixing the offending patch, the remainder of the patch should be processed still with --whitespace=fix when restarted with "git am --resolved".

The commit 67dad68 (add -C[NUM] to git-am, 2007-02-08) broke this long time ago. This should fix it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-am.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to git-am.sh +4 −4
diff --git a/git-am.sh b/git-am.sh
index aa60261..1bf70d4 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index."
 
 prec=4
 dotest="$GIT_DIR/rebase-apply"
-sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
+sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -156,7 +156,7 @@ do
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
 	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+		ws="--whitespace=$2"; shift ;;
 	-C|-p)
 		git_apply_opt="$git_apply_opt $1$2"; shift ;;
 	--)
@@ -283,7 +283,7 @@ if test "$(cat "$dotest/keep")" = t
 then
 	keep=-k
 fi
-ws=`cat "$dotest/whitespace"`
+ws=$(cat "$dotest/whitespace")
 if test "$(cat "$dotest/sign")" = t
 then
 	SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
@@ -454,7 +454,7 @@ do
 
 	case "$resolved" in
 	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		git apply $git_apply_opt $ws --index "$dotest/patch"
 		apply_status=$?
 		;;
 	t)
-- 
1.6.1.rc1.60.g1d1d7
Junio C Hamano· Dec 4, 2008, 23:36 UTC · re: Junio C Hamano · lore

[PATCH - DONTUSE] git-am: propagate -C/-p as well

Junio C Hamano <gitster@pobox.com> writes:
> I think this fixes the --whitespace=* one, although I obviously haven't
> tried to use it myself extensively.

This one comes on top of it *if* you want to propagate -C/-p as well, but I think it might be a wrong idea to propagate these to begin with.

Just like --3way is a one-shot option to deal with a single unapplicable patch (because it was based on an old version) in the whole series, and is designed not to get propagated, I suspect that people use -C<n> to fix a single broken patch and they may expect it not to apply to the whole series.

The breakage --whitespace deals with is an attribute of the submitter (use of a broken editor and lack of diligence). You most often feed a single series from the same submitter in the same mbox to "git am", preserving the --whitespace=fix option during the same "am" run makes sense, and somewhat more importantly, even though the option indeed modifies what you received, the change the option causes and the risk of breaking the semantics of the patch is minimum. I am not sure the breakage --3way deals with falls into the exactly the same category, but it is similar (if the first patch in the series was based on an old version, it is very likely that the subsequent ones are also based on the same old version). So after all it might be better to propagate --3way as well (which this patch does not do).

If we decide that propagating --3way is a good thing, then it would be equally good to propagate -C, -p and --directory options.

I dunno.
 git-am.sh |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
Show changes to diff +6 −8
diff --git c/git-am.sh w/git-am.sh
index 1bf70d4..a35e07a 100755
--- c/git-am.sh
+++ w/git-am.sh
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index."
 
 prec=4
 dotest="$GIT_DIR/rebase-apply"
-sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws=
+sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -155,9 +155,7 @@ do
 		;;
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
-	--whitespace)
-		ws="--whitespace=$2"; shift ;;
-	-C|-p)
+	-C|-p|--whitespace)
 		git_apply_opt="$git_apply_opt $1$2"; shift ;;
 	--)
 		shift; break ;;
@@ -247,10 +245,10 @@ else
 		exit 1
 	}
 
-	# -s, -u, -k and --whitespace flags are kept for the
-	# resuming session after a patch failure.
+	# -s, -u, -k, --whitespace, -C and -p flags are kept
+	# for the resuming session after a patch failure.
 	# -3 and -i can and must be given when resuming.
-	echo " $ws" >"$dotest/whitespace"
+	echo " $git_apply_opt" >"$dotest/apply_opt_extra"
 	echo "$sign" >"$dotest/sign"
 	echo "$utf8" >"$dotest/utf8"
 	echo "$keep" >"$dotest/keep"
@@ -283,7 +281,7 @@ if test "$(cat "$dotest/keep")" = t
 then
 	keep=-k
 fi
-ws=$(cat "$dotest/whitespace")
+apply_opt_extra=$(cat "$dotest/apply_opt_extra")
 if test "$(cat "$dotest/sign")" = t
 then
 	SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
Simon 'corecode' Schubert· Dec 4, 2008, 23:41 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow passing of --directory to git-am.

Junio C Hamano wrote:
Show 13 quoted lines
> Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
> 
>> You mean not storing/restoring the flags across an invocation?  No,
>> that's a different thing.  My patch only adds the --directory option,
>> it does not fix the previously existing bug.
> 
> The question is if it _introduces_ a bug that the directory given in the
> initial invocation of "git am --directory=foo" is lost if an patch does
> not apply and you need to manually resolve and continue.
> 
> If it does not introduce such a bug, you do not have the same issue as the
> old patch.  Otherwise you have the same issue as the old patch.  The
> question was if you have the same issue or you don't.  Yes?  No?

Yes, that's the issue. In this regard it behaves bug-compatible with the -p and -C options.

-- 
   <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
   rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
Junio C Hamano· Dec 5, 2008, 00:11 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
Show 17 quoted lines
> Junio C Hamano wrote:
>> Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
>>
>>> You mean not storing/restoring the flags across an invocation?  No,
>>> that's a different thing.  My patch only adds the --directory option,
>>> it does not fix the previously existing bug.
>>
>> The question is if it _introduces_ a bug that the directory given in the
>> initial invocation of "git am --directory=foo" is lost if an patch does
>> not apply and you need to manually resolve and continue.
>>
>> If it does not introduce such a bug, you do not have the same issue as the
>> old patch.  Otherwise you have the same issue as the old patch.  The
>> question was if you have the same issue or you don't.  Yes?  No?
>
> Yes, that's the issue.  In this regard it behaves bug-compatible with
> the -p and -C options.

If that is the case, and assuming that propagating -C/-p would be a good idea (which I am not sure yet), the patch I sent out earlier (which was flawed somewhat; it should use "$git_apply_opt_extra" where it invokes the "git apply" command) with necessary fix would serve as the basis to implement --directory=<dir>?

Simon 'corecode' Schubert· Dec 5, 2008, 00:16 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow passing of --directory to git-am.

Junio C Hamano wrote:
Show 5 quoted lines
> If that is the case, and assuming that propagating -C/-p would be a good
> idea (which I am not sure yet), the patch I sent out earlier (which was
> flawed somewhat; it should use "$git_apply_opt_extra" where it invokes the
> "git apply" command) with necessary fix would serve as the basis to
> implement --directory=<dir>?

certainly. I'll be travelling, so don't expect anything real soon, will resubmit unless I forget.

-- 
   <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
   rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
Jakub Narebski· Dec 4, 2008, 19:35 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
Show 26 quoted lines
> We need to play some shell tricks to be able to pass directory names
> which contain spaces and/or quotes.
> 
> Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
> ---
> 
> Boyd Stephen Smith Jr. wrote:
>  > I'm thinking your sed line doesn't do what you think it does.
>  > You probably want something like:
>  > bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
>  > don'\''t
> 
> Thanks, I clearly did not test this well enough.
> 
>   git-am.sh |    8 +++++---
>   1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/git-am.sh b/git-am.sh
> index aa60261..3baff4e 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit message
>   u,utf8          recode into utf8 (default)
>   k,keep          pass -k flag to git-mailinfo
>   whitespace=     pass it through git-apply
> +directory=      pass it through git-apply
Shouldn't it be
+ directory=      pass it through git-apply
to have it aligned like the rest of it?

By the way, your patch looks whitespace damaged, although only context for the above chunk was wrapped...

Show 11 quoted lines
>   C=              pass it through git-apply
>   p=              pass it through git-apply
>   resolvemsg=     override error message when patch failure occurs
> @@ -155,8 +156,9 @@ do
>   		;;
>   	--resolvemsg)
>   		shift; resolvemsg=$1 ;;
> -	--whitespace)
> -		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
> +	--whitespace|--directory)
> +		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")
Why not simply use "git rev-parse --sq"?
Show 10 quoted lines
> +		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
>   	-C|-p)
>   		git_apply_opt="$git_apply_opt $1$2"; shift ;;
>   	--)
> @@ -454,7 +456,7 @@ do
> 
>   	case "$resolved" in
>   	'')
> -		git apply $git_apply_opt --index "$dotest/patch"
> +		eval git apply $git_apply_opt --index '"$dotest/patch"'
Why eval?
Show 5 quoted lines
>   		apply_status=$?
>   		;;
>   	t)
> -- 
> 1.6.1.rc1.45.g123ed.dirty
Hmmm... 
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Simon 'corecode' Schubert· Dec 4, 2008, 22:25 UTC · re: Jakub Narebski · lore

Re: [PATCH] Allow passing of --directory to git-am.

Jakub Narebski wrote:
Show 8 quoted lines
> Shouldn't it be
> 
> + directory=      pass it through git-apply
> 
> to have it aligned like the rest of it?
> 
> By the way, your patch looks whitespace damaged, although only context
> for the above chunk was wrapped...

Thunderbird must have pummeled it. No clue why it does that though. Black magic software.

Show 10 quoted lines
>> @@ -155,8 +156,9 @@ do
>>   		;;
>>   	--resolvemsg)
>>   		shift; resolvemsg=$1 ;;
>> -	--whitespace)
>> -		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
>> +	--whitespace|--directory)
>> +		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")
> 
> Why not simply use "git rev-parse --sq"?

What I need is to convert $2 into a form suitable for quoting, does git rev-parse --sq do that?

Show 10 quoted lines
>> +		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
>>   	-C|-p)
>>   		git_apply_opt="$git_apply_opt $1$2"; shift ;;
>>   	--)
>> @@ -454,7 +456,7 @@ do
>>
>>   	case "$resolved" in
>>   	'')
>> -		git apply $git_apply_opt --index "$dotest/patch"
>> +		eval git apply $git_apply_opt --index '"$dotest/patch"'
 >
 > Why eval?
I quoted the above variable, so I now need to unquote it, that's done by eval.
-- 
   <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
   rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
Jakub Narebski· Dec 4, 2008, 22:46 UTC · re: Simon 'corecode' Schubert · lore

Re: [PATCH] Allow passing of --directory to git-am.

Simon 'corecode' Schubert wrote:
> Jakub Narebski wrote:
>> Simon 'corecode' Schubert wrote:
Show 13 quoted lines
>>> @@ -155,8 +156,9 @@ do
>>>   		;;
>>>   	--resolvemsg)
>>>   		shift; resolvemsg=$1 ;;
>>> -	--whitespace)
>>> -		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
>>> +	--whitespace|--directory)
>>> +		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")
>> 
>> Why not simply use "git rev-parse --sq"?
> 
> What I need is to convert $2 into a form suitable for quoting, does git 
> rev-parse --sq do that?
  $ git rev-parse --sq -- "don't do that"
  '--' 'don'\''t do that'
Without terminating newline. The '--' is needed because otherwise
git-rev-parse expects revisions... and doesn't find any.
 
By the way you could both simplify option parsing _and_ take care of
proper quoting by using --parseopt, i.e. use git-rev-parse in PARSEOPT
mode. But that is more involved change.
Show 10 quoted lines
>>> @@ -454,7 +456,7 @@ do
>>>
>>>   	case "$resolved" in
>>>   	'')
>>> -		git apply $git_apply_opt --index "$dotest/patch"
>>> +		eval git apply $git_apply_opt --index '"$dotest/patch"'
>>
>> Why eval?
> 
> I quoted the above variable, so I now need to unquote it, that's done by eval.
Ah.
-- 
Jakub Narebski
Poland

← back to recent threads