threads / patch / 37173

patch, 2 partsmergetool: don't require a work tree for --tool-help

Subject: [PATCH 1/2] mergetool: don't require a work tree for --tool-help

## tl;dr

6 messages between Jul 19, 2014 and Jul 29, 2014. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Charles Bailey· Jul 19, 2014, 16:35 UTC · lore
From: Charles Bailey <cbailey32@bloomberg.net>
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
---
You can call git difftool --tool-help outside of a work tree but not
mergetool --tool-help but there's not real reason for this restriction
and it can be easily relaxed by deferring the require_work_tree call
until after the options have been parsed.
 git-mergetool.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to git-mergetool.sh +2 −1
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 9a046b7..e969dd0 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -14,7 +14,6 @@ OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {
@@ -372,6 +371,8 @@ prompt_after_failed_merge () {
 	done
 }
 
+require_work_tree
+
 if test -z "$merge_tool"
 then
 	# Check if a merge tool has been configured
-- 
2.0.2.611.g8c85416
Charles Bailey· Jul 19, 2014, 16:35 UTC · re: Charles Bailey · lore

[PATCH 2/2] difftool: don't assume that default sh is sane

From: Charles Bailey <cbailey32@bloomberg.net>

git-difftool used to create a command list script containing $( ... ) and explicitly call "sh -c" with this list.

Instead, allow mergetool --tool-help to take a mode parameter and call mergetool directly to invoke the show_tool_help function. This mode parameter is intented for use solely by difftool.

Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
---
Another issue for Solaris. Originally I had a fix for this that
substituted "@SHELL_PATH@" even inside perl scripts but I felt that
having an interface for show_tool_help was a little neater all round but
I welcome alternative views.
 git-difftool.perl |  6 +-----
 git-mergetool.sh  | 12 +++++++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)
Show changes to 2 files +12 −6

git-difftool.perl, git-mergetool.sh

diff --git a/git-difftool.perl b/git-difftool.perl
index 18ca61e..598fcc2 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -47,13 +47,9 @@ sub find_worktree
 
 sub print_tool_help
 {
-	my $cmd = 'TOOL_MODE=diff';
-	$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
-	$cmd .= ' && show_tool_help';
-
 	# See the comment at the bottom of file_diff() for the reason behind
 	# using system() followed by exit() instead of exec().
-	my $rc = system('sh', '-c', $cmd);
+	my $rc = system(qw(git mergetool --tool-help=diff));
 	exit($rc | ($rc >> 8));
 }
 
diff --git a/git-mergetool.sh b/git-mergetool.sh
index e969dd0..d32b663 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -320,7 +320,17 @@ guessed_merge_tool=false
 while test $# != 0
 do
 	case "$1" in
-	--tool-help)
+	--tool-help*)
+		case "$#,$1" in
+		1,*=*)
+			TOOL_MODE=$(expr "z$1" : 'z-[^=]*=\(.*\)')
+			;;
+		1,--tool-help)
+			;;
+		*)
+			usage
+			;;
+		esac
 		show_tool_help
 		;;
 	-t|--tool*)
-- 
2.0.2.611.g8c85416
John Keeping· Jul 19, 2014, 17:21 UTC · re: Charles Bailey · lore

Re: [PATCH 2/2] difftool: don't assume that default sh is sane

On Sat, Jul 19, 2014 at 05:35:17PM +0100, Charles Bailey wrote:
Show 51 quoted lines
> From: Charles Bailey <cbailey32@bloomberg.net>
> 
> git-difftool used to create a command list script containing $( ... )
> and explicitly call "sh -c" with this list.
> 
> Instead, allow mergetool --tool-help to take a mode parameter and call
> mergetool directly to invoke the show_tool_help function. This mode
> parameter is intented for use solely by difftool.
> 
> Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
> ---
> Another issue for Solaris. Originally I had a fix for this that
> substituted "@SHELL_PATH@" even inside perl scripts but I felt that
> having an interface for show_tool_help was a little neater all round but
> I welcome alternative views.
> 
>  git-difftool.perl |  6 +-----
>  git-mergetool.sh  | 12 +++++++++++-
>  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/git-difftool.perl b/git-difftool.perl
> index 18ca61e..598fcc2 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -47,13 +47,9 @@ sub find_worktree
>  
>  sub print_tool_help
>  {
> -	my $cmd = 'TOOL_MODE=diff';
> -	$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
> -	$cmd .= ' && show_tool_help';
> -
>  	# See the comment at the bottom of file_diff() for the reason behind
>  	# using system() followed by exit() instead of exec().
> -	my $rc = system('sh', '-c', $cmd);
> +	my $rc = system(qw(git mergetool --tool-help=diff));
>  	exit($rc | ($rc >> 8));
>  }
>  
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index e969dd0..d32b663 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -320,7 +320,17 @@ guessed_merge_tool=false
>  while test $# != 0
>  do
>  	case "$1" in
> -	--tool-help)
> +	--tool-help*)
> +		case "$#,$1" in
> +		1,*=*)

What's the reason for forcing `--tool-help` to be the last option? Wouldn't it be simpler to just change the top-level case statement to:

	--tool-help=*)
		TOOL_MODE=${1#--tool-help=}
		show_tool_help
		;;
	--tool-help)
		show_tool_help
		;;
Show 13 quoted lines
> +			TOOL_MODE=$(expr "z$1" : 'z-[^=]*=\(.*\)')
> +			;;
> +		1,--tool-help)
> +			;;
> +		*)
> +			usage
> +			;;
> +		esac
>  		show_tool_help
>  		;;
>  	-t|--tool*)
> -- 
> 2.0.2.611.g8c85416
Charles Bailey· Jul 19, 2014, 18:29 UTC · re: John Keeping · lore

Re: [PATCH 2/2] difftool: don't assume that default sh is sane

On Sat, Jul 19, 2014 at 06:21:32PM +0100, John Keeping wrote:
Show 11 quoted lines
> 
> What's the reason for forcing `--tool-help` to be the last option?
> Wouldn't it be simpler to just change the top-level case statement to:
> 
> 	--tool-help=*)
> 		TOOL_MODE=${1#--tool-help=}
> 		show_tool_help
> 		;;
> 	--tool-help)
> 		show_tool_help
> 		;;

It doesn't make sense to use --tool-help with other parameters so issuing an error made sense to me at the time. You've pointed out to me that I don't error when those other options come first so I'm now unsure how valuable this behaviour is, now. (I can't immediately see a really neat way to give a diagnostic if other options do come first.)

Your version is good, obviously simpler.
David Aguilar· Jul 29, 2014, 07:53 UTC · re: Charles Bailey · lore

Re: [PATCH 2/2] difftool: don't assume that default sh is sane

On Sat, Jul 19, 2014 at 05:35:17PM +0100, Charles Bailey wrote:
Show 15 quoted lines
> From: Charles Bailey <cbailey32@bloomberg.net>
> 
> git-difftool used to create a command list script containing $( ... )
> and explicitly call "sh -c" with this list.
> 
> Instead, allow mergetool --tool-help to take a mode parameter and call
> mergetool directly to invoke the show_tool_help function. This mode
> parameter is intented for use solely by difftool.
> 
> Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
> ---
> Another issue for Solaris. Originally I had a fix for this that
> substituted "@SHELL_PATH@" even inside perl scripts but I felt that
> having an interface for show_tool_help was a little neater all round but
> I welcome alternative views.
I definitely agree that having an interface is nice and tidy.
Show 20 quoted lines
>  git-difftool.perl |  6 +-----
>  git-mergetool.sh  | 12 +++++++++++-
>  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/git-difftool.perl b/git-difftool.perl
> index 18ca61e..598fcc2 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -47,13 +47,9 @@ sub find_worktree
>  
>  sub print_tool_help
>  {
> -	my $cmd = 'TOOL_MODE=diff';
> -	$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
> -	$cmd .= ' && show_tool_help';
> -
>  	# See the comment at the bottom of file_diff() for the reason behind
>  	# using system() followed by exit() instead of exec().
> -	my $rc = system('sh', '-c', $cmd);
> +	my $rc = system(qw(git mergetool --tool-help=diff));
I believe qw() in list context is considered deprecated.
cheers,
-- 
David
David Aguilar· Jul 29, 2014, 08:03 UTC · re: David Aguilar · lore

Re: [PATCH 2/2] difftool: don't assume that default sh is sane

On Tue, Jul 29, 2014 at 12:53:29AM -0700, David Aguilar wrote:
Show 19 quoted lines
> On Sat, Jul 19, 2014 at 05:35:17PM +0100, Charles Bailey wrote:
> > diff --git a/git-difftool.perl b/git-difftool.perl
> > index 18ca61e..598fcc2 100755
> > --- a/git-difftool.perl
> > +++ b/git-difftool.perl
> > @@ -47,13 +47,9 @@ sub find_worktree
> >  
> >  sub print_tool_help
> >  {
> > -	my $cmd = 'TOOL_MODE=diff';
> > -	$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
> > -	$cmd .= ' && show_tool_help';
> > -
> >  	# See the comment at the bottom of file_diff() for the reason behind
> >  	# using system() followed by exit() instead of exec().
> > -	my $rc = system('sh', '-c', $cmd);
> > +	my $rc = system(qw(git mergetool --tool-help=diff));
> 
> I believe qw() in list context is considered deprecated.

Sorry for the noise, I got my warnings mixed up. It's only deprecated when used as parentheses, so this is fine as-is.

-- 
David

← back to recent threads