Re: [PATCH] rev-parse --show-prefix: add in trailing newline
- From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
- Date
- Apr 10, 2012, 22:51 UTC
- Message-ID
- <CACsJy8Dc9xi=z7x4OfeAWHSeuUOFFVFf93GFOfauVB7c=_cZ1Q@mail.gmail.com>
- In-Reply-To
- <20120410173616.GA4300@burratino>
2012/4/11 Jonathan Nieder <jrnieder@gmail.com>:
Show 18 quoted lines
> (cc-ing Duy)
> Hi,
>
> Ross Lagerwall wrote:
>
>> --- a/builtin/rev-parse.c
>> +++ b/builtin/rev-parse.c
>> @@ -634,6 +634,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>> if (!strcmp(arg, "--show-prefix")) {
>> if (prefix)
>> puts(prefix);
>> + else
>> + putchar('\n');
>> continue;
>
> This makes the output more consistent but it is a little puzzling how
> it does that. Why is prefix NULL instead of "" when we are at the
> toplevel of the worktree?It dates back to the first version of setup_git_directory() in d288a70 ([PATCH] Make "git diff" work inside relative subdirectories - 2005-08-16). If we get "", setup_git_.. converts it to NULL. Although I think Linus made a mistake in the first version of "rev-parse --git-dir" doing "puts(prefix);" unconditionally in the same commit. Junio fixed --git-dir in 4866ccf (Rationalize output selection in rev-parse. - 2005-08-24) with the "if (prefix)" clause and should have added the "else putchar('\n');" there too, I think.
-- Duy