All of lore.kernel.org
 help / color / mirror / Atom feed
* Output from "rev-parse --resolve-git-dir" changed: two lines (prints original argument)
@ 2014-02-17  8:13 Daniel Hahler
  2014-02-17  8:46 ` [PATCH] rev-parse: fix --resolve-git-dir argument handling John Keeping
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Hahler @ 2014-02-17  8:13 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

I have noticed that the output from "git rev-parse --resolve-git-dir" changed.

While it used to only print the resolved git dir, it now prints the argument passed to it itself:

    % git rev-parse --resolve-git-dir .git
    /path/to/root/.git/modules/vim/bundle/reporoot
    .git

This is with Git version 1.8.5.3, but also happens with master.

You can use "--flags" to avoid this ("git rev-parse --flags --resolve-git-dir .git"), but it is unclear from the documentation if that's the intended beahviour.

It seems like the "--resolve-git-dir" subcommand needs to consume the argument passed to it.


Regards,
Daniel.

-- 
http://daniel.hahler.de/


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

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

* [PATCH] rev-parse: fix --resolve-git-dir argument handling
  2014-02-17  8:13 Output from "rev-parse --resolve-git-dir" changed: two lines (prints original argument) Daniel Hahler
@ 2014-02-17  8:46 ` John Keeping
  2014-02-18 20:42   ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: John Keeping @ 2014-02-17  8:46 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Daniel Hahler, John Keeping

There are two problems here:

1) If no argument is provided, then the command segfaults
2) The argument is not consumed, so there will be excess output

Fix both of these in one go by restructuring the handler for this
option.

Reported-by: Daniel Hahler <genml+git-2014@thequod.de>
Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/rev-parse.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index aaeb611..645cc4a 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -738,9 +738,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--resolve-git-dir")) {
-				const char *gitdir = resolve_gitdir(argv[i+1]);
+				const char *gitdir;
+				if (++i >= argc)
+					die("--resolve-git-dir requires an argument");
+				gitdir = resolve_gitdir(argv[i]);
 				if (!gitdir)
-					die("not a gitdir '%s'", argv[i+1]);
+					die("not a gitdir '%s'", argv[i]);
 				puts(gitdir);
 				continue;
 			}
-- 
1.9.0.6.g037df60.dirty

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

* Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling
  2014-02-17  8:46 ` [PATCH] rev-parse: fix --resolve-git-dir argument handling John Keeping
@ 2014-02-18 20:42   ` Junio C Hamano
  2014-02-19  0:25     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-02-18 20:42 UTC (permalink / raw)
  To: John Keeping; +Cc: git, Daniel Hahler

John Keeping <john@keeping.me.uk> writes:

> There are two problems here:
>
> 1) If no argument is provided, then the command segfaults
> 2) The argument is not consumed, so there will be excess output
>
> Fix both of these in one go by restructuring the handler for this
> option.
>
> Reported-by: Daniel Hahler <genml+git-2014@thequod.de>
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---

Looks sensible; thanks.

>  builtin/rev-parse.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index aaeb611..645cc4a 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -738,9 +738,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>  				continue;
>  			}
>  			if (!strcmp(arg, "--resolve-git-dir")) {
> -				const char *gitdir = resolve_gitdir(argv[i+1]);
> +				const char *gitdir;
> +				if (++i >= argc)
> +					die("--resolve-git-dir requires an argument");
> +				gitdir = resolve_gitdir(argv[i]);
>  				if (!gitdir)
> -					die("not a gitdir '%s'", argv[i+1]);
> +					die("not a gitdir '%s'", argv[i]);
>  				puts(gitdir);
>  				continue;
>  			}

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

* Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling
  2014-02-18 20:42   ` Junio C Hamano
@ 2014-02-19  0:25     ` Junio C Hamano
  2014-02-19  9:09       ` John Keeping
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-02-19  0:25 UTC (permalink / raw)
  To: John Keeping; +Cc: git, Daniel Hahler

Junio C Hamano <gitster@pobox.com> writes:

> John Keeping <john@keeping.me.uk> writes:
>
>> There are two problems here:
>>
>> 1) If no argument is provided, then the command segfaults
>> 2) The argument is not consumed, so there will be excess output
>>
>> Fix both of these in one go by restructuring the handler for this
>> option.
>>
>> Reported-by: Daniel Hahler <genml+git-2014@thequod.de>
>> Signed-off-by: John Keeping <john@keeping.me.uk>
>> ---
>
> Looks sensible; thanks.

Ehh, I spoke too fast. Don't we already have this queued as a43219f2
(rev-parse: check i before using argv[i] against argc, 2014-01-28)?

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

* Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling
  2014-02-19  0:25     ` Junio C Hamano
@ 2014-02-19  9:09       ` John Keeping
  0 siblings, 0 replies; 5+ messages in thread
From: John Keeping @ 2014-02-19  9:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Daniel Hahler

On Tue, Feb 18, 2014 at 04:25:37PM -0800, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > John Keeping <john@keeping.me.uk> writes:
> >
> >> There are two problems here:
> >>
> >> 1) If no argument is provided, then the command segfaults
> >> 2) The argument is not consumed, so there will be excess output
> >>
> >> Fix both of these in one go by restructuring the handler for this
> >> option.
> >>
> >> Reported-by: Daniel Hahler <genml+git-2014@thequod.de>
> >> Signed-off-by: John Keeping <john@keeping.me.uk>
> >> ---
> >
> > Looks sensible; thanks.
> 
> Ehh, I spoke too fast. Don't we already have this queued as a43219f2
> (rev-parse: check i before using argv[i] against argc, 2014-01-28)?

Yes, and it catches more cases than mine.  I only checked against master
and had missed that when it went past on the list.

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

end of thread, other threads:[~2014-02-19  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-17  8:13 Output from "rev-parse --resolve-git-dir" changed: two lines (prints original argument) Daniel Hahler
2014-02-17  8:46 ` [PATCH] rev-parse: fix --resolve-git-dir argument handling John Keeping
2014-02-18 20:42   ` Junio C Hamano
2014-02-19  0:25     ` Junio C Hamano
2014-02-19  9:09       ` John Keeping

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.