git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
@ 2010-12-14 18:27 Ramsay Jones
  2010-12-14 19:15 ` Junio C Hamano
  2010-12-17  2:33 ` David Aguilar
  0 siblings, 2 replies; 6+ messages in thread
From: Ramsay Jones @ 2010-12-14 18:27 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list, davvid


In particular, test 14 'difftool last flag wins' fails. This is
caused by git-difftool.perl passing both GIT_DIFFTOOL_NO_PROMPT
(='true') and GIT_DIFFTOOL_PROMPT (='true') to the difftool helper
script. Despite the appropriate key being deleted from the ENV
hash, it seems that once a key has been set in the hash, it gets
passed along to the system() call. (ie deleting the key does not
do the equivalent of unsetenv()).

In order to fix the problem, we keep track of the required prompt
state while processing the arguments, and then set the relevant
ENV hash key only once at the end.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 git-difftool.perl |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/git-difftool.perl b/git-difftool.perl
index e95e4ad..ced1615 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -52,6 +52,7 @@ sub generate_command
 	my @command = (exe('git'), 'diff');
 	my $skip_next = 0;
 	my $idx = -1;
+	my $prompt = '';
 	for my $arg (@ARGV) {
 		$idx++;
 		if ($skip_next) {
@@ -89,13 +90,11 @@ sub generate_command
 			next;
 		}
 		if ($arg eq '-y' || $arg eq '--no-prompt') {
-			$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
-			delete $ENV{GIT_DIFFTOOL_PROMPT};
+			$prompt = 'no';
 			next;
 		}
 		if ($arg eq '--prompt') {
-			$ENV{GIT_DIFFTOOL_PROMPT} = 'true';
-			delete $ENV{GIT_DIFFTOOL_NO_PROMPT};
+			$prompt = 'yes';
 			next;
 		}
 		if ($arg eq '-h' || $arg eq '--help') {
@@ -103,6 +102,11 @@ sub generate_command
 		}
 		push @command, $arg;
 	}
+	if ($prompt eq 'yes') {
+		$ENV{GIT_DIFFTOOL_PROMPT} = 'true';
+	} elsif ($prompt eq 'no') {
+		$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
+	}
 	return @command
 }
 
-- 
1.7.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
  2010-12-14 18:27 [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin Ramsay Jones
@ 2010-12-14 19:15 ` Junio C Hamano
  2010-12-16 20:04   ` Ramsay Jones
  2010-12-17  2:33 ` David Aguilar
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2010-12-14 19:15 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: GIT Mailing-list, davvid

This is not just "test failure" but can cause a failure in the real life
for people who want "the last flag wins" to work, no?

I'll retitle the patch and queue it separately from other test fixes.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
  2010-12-14 19:15 ` Junio C Hamano
@ 2010-12-16 20:04   ` Ramsay Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2010-12-16 20:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list, davvid

Junio C Hamano wrote:
> This is not just "test failure" but can cause a failure in the real life
> for people who want "the last flag wins" to work, no?

Yes, indeed. I was concentrating on fixing test-suite failures (and that
can mean you have to modify the test, the application or both) so...

> I'll retitle the patch and queue it separately from other test fixes.

Thanks!

ATB,
Ramsay Jones

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
  2010-12-14 18:27 [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin Ramsay Jones
  2010-12-14 19:15 ` Junio C Hamano
@ 2010-12-17  2:33 ` David Aguilar
  2010-12-17 19:59   ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: David Aguilar @ 2010-12-17  2:33 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list

On Tue, Dec 14, 2010 at 06:27:48PM +0000, Ramsay Jones wrote:
> 
> In particular, test 14 'difftool last flag wins' fails. This is
> caused by git-difftool.perl passing both GIT_DIFFTOOL_NO_PROMPT
> (='true') and GIT_DIFFTOOL_PROMPT (='true') to the difftool helper
> script. Despite the appropriate key being deleted from the ENV
> hash, it seems that once a key has been set in the hash, it gets
> passed along to the system() call. (ie deleting the key does not
> do the equivalent of unsetenv()).
> 
> In order to fix the problem, we keep track of the required prompt
> state while processing the arguments, and then set the relevant
> ENV hash key only once at the end.
> 
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>  git-difftool.perl |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/git-difftool.perl b/git-difftool.perl
> index e95e4ad..ced1615 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -52,6 +52,7 @@ sub generate_command
>  	my @command = (exe('git'), 'diff');
>  	my $skip_next = 0;
>  	my $idx = -1;
> +	my $prompt = '';

Would it be simpler to set $prompt = 1 and then
flip it to 0 when -y | or --no-prompt is supplied?



>  	for my $arg (@ARGV) {
>  		$idx++;
>  		if ($skip_next) {
> @@ -89,13 +90,11 @@ sub generate_command
>  			next;
>  		}
>  		if ($arg eq '-y' || $arg eq '--no-prompt') {
> -			$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
> -			delete $ENV{GIT_DIFFTOOL_PROMPT};
> +			$prompt = 'no';
>  			next;
>  		}
>  		if ($arg eq '--prompt') {
> -			$ENV{GIT_DIFFTOOL_PROMPT} = 'true';
> -			delete $ENV{GIT_DIFFTOOL_NO_PROMPT};
> +			$prompt = 'yes';
>  			next;
>  		}
>  		if ($arg eq '-h' || $arg eq '--help') {
> @@ -103,6 +102,11 @@ sub generate_command
>  		}
>  		push @command, $arg;
>  	}
> +	if ($prompt eq 'yes') {

This would become:

	if ($prompt) {
		...
	}
	else {
		...
	}

> +		$ENV{GIT_DIFFTOOL_PROMPT} = 'true';
> +	} elsif ($prompt eq 'no') {
> +		$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
> +	}
>  	return @command
>  }
>  
> -- 
> 1.7.3
> 
> 

-- 
		David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
  2010-12-17  2:33 ` David Aguilar
@ 2010-12-17 19:59   ` Junio C Hamano
  2010-12-18 20:32     ` Ramsay Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2010-12-17 19:59 UTC (permalink / raw)
  To: David Aguilar; +Cc: Ramsay Jones, Junio C Hamano, GIT Mailing-list

David Aguilar <davvid@gmail.com> writes:

>> diff --git a/git-difftool.perl b/git-difftool.perl
>> index e95e4ad..ced1615 100755
>> --- a/git-difftool.perl
>> +++ b/git-difftool.perl
>> @@ -52,6 +52,7 @@ sub generate_command
>>  	my @command = (exe('git'), 'diff');
>>  	my $skip_next = 0;
>>  	my $idx = -1;
>> +	my $prompt = '';
>
> Would it be simpler to set $prompt = 1 and then
> flip it to 0 when -y | or --no-prompt is supplied?
> ...
>
> This would become:
>
> 	if ($prompt) {
> 		...
> 	}
> 	else {
> 		...
> 	}

But that is not what the patch does, is it?

Isn't it more like initializing $prompt to undef and then the above
condition becomes:

	if (!defined $prompt) {
        	; # nothing
        elsif ($prompt) {
		setenv PROMPT true
	} else {
		setenv NO_PROMPT true
	}

no?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin
  2010-12-17 19:59   ` Junio C Hamano
@ 2010-12-18 20:32     ` Ramsay Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2010-12-18 20:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: David Aguilar, GIT Mailing-list

Junio C Hamano wrote:
> David Aguilar <davvid@gmail.com> writes:
> 
>>> diff --git a/git-difftool.perl b/git-difftool.perl
>>> index e95e4ad..ced1615 100755
>>> --- a/git-difftool.perl
>>> +++ b/git-difftool.perl
>>> @@ -52,6 +52,7 @@ sub generate_command
>>>  	my @command = (exe('git'), 'diff');
>>>  	my $skip_next = 0;
>>>  	my $idx = -1;
>>> +	my $prompt = '';
>> Would it be simpler to set $prompt = 1 and then
>> flip it to 0 when -y | or --no-prompt is supplied?
>> ...
>>
>> This would become:
>>
>> 	if ($prompt) {
>> 		...
>> 	}
>> 	else {
>> 		...
>> 	}
> 
> But that is not what the patch does, is it?
> 
> Isn't it more like initializing $prompt to undef and then the above
> condition becomes:
> 
> 	if (!defined $prompt) {
>         	; # nothing
>         elsif ($prompt) {
> 		setenv PROMPT true
> 	} else {
> 		setenv NO_PROMPT true
> 	}
> 
> no?

Yes. :-P
At least that is what I was aiming for.

In particular, if none of -y, --no-prompt or --prompt is passed on
the command-line, I don't want to set either key in the hash.
(Or, to put it another way, I don't want to change the behaviour
in this case, where neither variable is set in the environment
of the helper script)

ATB,
Ramsay Jones

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-12-18 22:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-14 18:27 [PATCH 07/14] t7800-difftool.sh: Fix a test failure on Cygwin Ramsay Jones
2010-12-14 19:15 ` Junio C Hamano
2010-12-16 20:04   ` Ramsay Jones
2010-12-17  2:33 ` David Aguilar
2010-12-17 19:59   ` Junio C Hamano
2010-12-18 20:32     ` Ramsay Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).