[PATCH] rev-parse --show-prefix: add in trailing newline

Subsystems: the rest

DORMANTno replies

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] rev-parse --show-prefix: add in trailing newline

From: Ross Lagerwall <hidden>
Date: 2016-06-15 22:53:32

Print out a trailing newline when --show-prefix is run with cwd
at the top level of the tree which results in an empty prefix.
Behavior is now like --show-cdup.

Fixes an expected failure in t1501.

Signed-off-by: Ross Lagerwall <redacted>
---
 builtin/rev-parse.c |    2 ++
 t/t1501-worktree.sh |    2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 98d1cbe..733f626 100644
--- 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;
 			}
 			if (!strcmp(arg, "--show-cdup")) {
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index e661147..8f36aa9 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -68,7 +68,7 @@ test_expect_success 'inside work tree' '
 	)
 '
 
-test_expect_failure 'empty prefix is actually written out' '
+test_expect_success 'empty prefix is actually written out' '
 	echo >expected &&
 	(
 		cd work &&
-- 
1.7.10

Re: [PATCH] rev-parse --show-prefix: add in trailing newline

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:53:32

(cc-ing Duy)
Hi,

Ross Lagerwall wrote:
quoted hunk
--- 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?

Thanks,
Jonathan

Re: [PATCH] rev-parse --show-prefix: add in trailing newline

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:53:32

2012/4/11 Jonathan Nieder [off-list ref]:
(cc-ing Duy)
Hi,

Ross Lagerwall wrote:
quoted
--- 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help