git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: pp yy <yoann.mac.donald@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [bug] Adding -z to git status seems to disable relative path
Date: Mon, 16 Dec 2019 01:34:25 -0500	[thread overview]
Message-ID: <20191216063425.GA2127604@coredump.intra.peff.net> (raw)
In-Reply-To: <CAK60LiX0g8mNVH5YY0JNOuUNRNYp+URt=2MyH758OAWpX_Phxg@mail.gmail.com>

On Sun, Dec 15, 2019 at 09:31:23PM +0100, pp yy wrote:

> Maybe i missed something but i can't get relativepath when adding '-z'
> 
> $ git --version
> git version 2.17.1
> $ git status -s test
> ?? test
> $ git status -s -z test
> ?? plugins/git/test
> $ git -c status.relativePaths=true status -s test
> ?? test
> $ git -c status.relativePaths=true status -s -z test
> ?? plugins/git/test
> 
> Bug or did i missed something ?

I think it's a bug. At first I thought you were running up against the
implied porcelain output:

  -z
      Terminate entries with NUL, instead of LF. This implies the
      --porcelain=v1 output format if no other format is given.

but you are explicitly saying "-s" (and running this in a terminal shows
that the result is colorized, which means we're triggering the short
format and not porcelain).

And indeed, the "-z" code path seems to ignore the prefix entirely.
Something like this would fix it:

diff --git a/wt-status.c b/wt-status.c
index cc6f94504d..3a0e479407 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1837,9 +1837,13 @@ static void wt_shortstatus_status(struct string_list_item *it,
 		putchar(' ');
 	putchar(' ');
 	if (s->null_termination) {
-		fprintf(stdout, "%s%c", it->string, 0);
+		struct strbuf scratch = STRBUF_INIT;
+		fprintf(stdout, "%s%c",
+			relative_path(it->string, s->prefix, &scratch), 0);
 		if (d->rename_source)
-			fprintf(stdout, "%s%c", d->rename_source, 0);
+			fprintf(stdout, "%s%c",
+				relative_path(d->rename_source, s->prefix, &scratch), 0);
+		strbuf_release(&scratch);
 	} else {
 		struct strbuf onebuf = STRBUF_INIT;
 		const char *one;

Now I do think it's a little weird to use "-z" with "--short" in the
first place, since the whole point of "-z" is make something that can be
parsed. And the whole point of "--short" versus "--porcelain" is that
the latter is stable and predictable (so it doesn't respect config at
all).

But I guess I could imagine a use case where a script is taking in paths
from the "-z" and then showing them to the user without further
processing (and so it's convenient to get the relative path directly
rather than computing them itself). I do wonder if there are any other
surprises in "--short" that might be lurking, though (IIRC, we do not
even promise that the output will stay syntactically the same between
versions; it could change to something completely different, or add new
lines in future versions).

-Peff

  reply	other threads:[~2019-12-16  6:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-15 20:31 [bug] Adding -z to git status seems to disable relative path pp yy
2019-12-16  6:34 ` Jeff King [this message]
2019-12-18 14:04   ` pp yy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191216063425.GA2127604@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=yoann.mac.donald@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).