All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-mergetool: print filename when it contains %
@ 2013-02-08  1:16 Asheesh Laroia
  2013-02-08 17:32 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Asheesh Laroia @ 2013-02-08  1:16 UTC (permalink / raw)
  To: git; +Cc: Asheesh Laroia

Before this change, if git-mergetool was invoked with regard to
files with a percent sign (%) in their names, it would print an
error. For example, if you were calling mergetool on a file called
"%2F":

    printf: %2F: invalid directive

This changes the behavior to pass "%s" to printf as its first argument
to avoid processing the filename as a format string.

Signed-off-by: Asheesh Laroia <asheesh@asheesh.org>
---
 git-mergetool.sh |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index c50e18a..d2b9289 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -440,7 +440,7 @@ then
 fi
 
 printf "Merging:\n"
-printf "$files\n"
+printf "%s" "$files\n"
 
 IFS='
 '
-- 
1.7.10.4

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

* Re: [PATCH] git-mergetool: print filename when it contains %
  2013-02-08  1:16 [PATCH] git-mergetool: print filename when it contains % Asheesh Laroia
@ 2013-02-08 17:32 ` Junio C Hamano
  2013-02-08 20:58   ` Asheesh Laroia
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2013-02-08 17:32 UTC (permalink / raw)
  To: Asheesh Laroia; +Cc: git

Asheesh Laroia <asheesh@asheesh.org> writes:

> Before this change, if git-mergetool was invoked with regard to

Drop "before this change,"; it is clear (and it is a recommended
practice) you are first describing what problem you are addressing.

> files with a percent sign (%) in their names, it would print an
> error. For example, if you were calling mergetool on a file called
> "%2F":
>
>     printf: %2F: invalid directive
>
> This changes the behavior to pass "%s" to printf as its first argument
> to avoid processing the filename as a format string.
>
> Signed-off-by: Asheesh Laroia <asheesh@asheesh.org>
> ---

Thanks.

As a follow-up to this patch, we may want to perform a systematic
audit of

    $ git grep -e 'printf "[^"]*\$[^"]*"'

There is one in git-difftool-helper.sh

    printf "\nViewing: '$MERGED'\n"

and mergetools/p4merge:

    printf "$empty_file"

>  git-mergetool.sh |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index c50e18a..d2b9289 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -440,7 +440,7 @@ then
>  fi
>  
>  printf "Merging:\n"
> -printf "$files\n"
> +printf "%s" "$files\n"

I think

	printf "%s\n" "$files"

would be clearer.

>  
>  IFS='
>  '

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

* Re: [PATCH] git-mergetool: print filename when it contains %
  2013-02-08 17:32 ` Junio C Hamano
@ 2013-02-08 20:58   ` Asheesh Laroia
  2013-02-08 21:09     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Asheesh Laroia @ 2013-02-08 20:58 UTC (permalink / raw)
  To: git

On Fri, 8 Feb 2013, Junio C Hamano wrote:

> Asheesh Laroia <asheesh@asheesh.org> writes:
>
>> Before this change, if git-mergetool was invoked with regard to
>
> Drop "before this change,"; it is clear (and it is a recommended
> practice) you are first describing what problem you are addressing.
>

Junio, thanks for the quick reply! I agree with your suggestions, and will 
take a look at addressing them, hopefully by Tuesday or so.

-- Asheesh.

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

* Re: [PATCH] git-mergetool: print filename when it contains %
  2013-02-08 20:58   ` Asheesh Laroia
@ 2013-02-08 21:09     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2013-02-08 21:09 UTC (permalink / raw)
  To: Asheesh Laroia; +Cc: git

Asheesh Laroia <asheesh@asheesh.org> writes:

> Junio, thanks for the quick reply! I agree with your suggestions, and
> will take a look at addressing them, hopefully by Tuesday or so.

FYI, here is what I queued for now.

-- >8 --
From: Asheesh Laroia <asheesh@asheesh.org>
Date: Thu, 7 Feb 2013 17:16:24 -0800
Subject: [PATCH] git-mergetool: print filename when it contains %

If git-mergetool was invoked with files with a percent sign (%) in
their names, it would print an error.  For example, if you were
calling mergetool on a file called "%2F":

    printf: %2F: invalid directive

Do not pass random string to printf as if it were a valid format.
Use format string "%s" and pass the string as a data to be formatted
instead.

Signed-off-by: Asheesh Laroia <asheesh@asheesh.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-mergetool.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index c50e18a..012afa5 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -440,7 +440,7 @@ then
 fi
 
 printf "Merging:\n"
-printf "$files\n"
+printf "%s\n" "$files"
 
 IFS='
 '
-- 
1.8.1.3.617.gb5c8e72

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

end of thread, other threads:[~2013-02-08 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-08  1:16 [PATCH] git-mergetool: print filename when it contains % Asheesh Laroia
2013-02-08 17:32 ` Junio C Hamano
2013-02-08 20:58   ` Asheesh Laroia
2013-02-08 21:09     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.