All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matheus Tavares Bernardino <matheus.bernardino@usp.br>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Andreas Heiduk" <asheiduk@gmail.com>, git <git@vger.kernel.org>,
	"Greg Hurrell" <greg@hurrell.net>, "René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH] grep: follow conventions for printing paths w/ unusual chars
Date: Fri, 17 Apr 2020 18:19:07 -0300	[thread overview]
Message-ID: <CAHd-oW7B1wtHOE7KCtOR-kAXhuj8Du_MAYobWd9nSsSvm_sChQ@mail.gmail.com> (raw)
In-Reply-To: <xmqq8siuwqxp.fsf@gitster.c.googlers.com>

On Fri, Apr 17, 2020 at 3:45 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Matheus Tavares <matheus.bernardino@usp.br> writes:
>
> > +     if (opt->relative && opt->prefix_length)
> > +             quote_path_relative(filename + tree_name_len, opt->prefix, out);
> > +     else
> > +             quote_c_style(filename + tree_name_len, out, NULL, 0);
>
> Yup.  This solves the discrepancy reported correctly (i.e. both
> sides should do the quoting, the original only quoted when relative,
> and the new code corrects the other side).
>
> > +     if (tree_name_len)
> > +             strbuf_insert(out, 0, filename, tree_name_len);
>
> I am not quite sure about this part, though.
>
> Earlier we inserted the latter part of filename (after offset
> tree_name_len) to strbuf "out" after quoting, and then we are
> prefixing the earlier part of the filename without quoting to that
> same "out".  Wouldn't a path ABCDEF (I do not literally mean that
> these ascii alphabets need quoting---just imagine each of these
> stands for a different letter and some causes the path to be quoted)
> with tree_name_len pointing somewhere in the middle be added as (an
> analog of) ABC"DEF", i.e. literal prefix with remainder quoted?

Right. But the ABC prefix here is always a tree name, so the output is
one of the following:

<sha1>:"unusual path":line
<ref name>:"unusual path":line
"unusual path":line

(Always having the entire "unusual path" inside the double quotes, though)

> I would (perhaps näively) expect that the whole thing would be placed
> inside a dq pair in such a case, even if the prefix part alone would
> not require quoting.

Hm, it might be just me, but I think that including the tree name and
path in the same dq pair could be a bit confusing, as they can seem
like one unique thing.

There is also the case of ref names containing unusual chars, as dq's.
Such ref names are not currently escaped in the output of other
commands as checkout, branch or describe. But if we include the ref
name in grep's output quote, it would be escaped, which would be a
minor inconsistency (I don't know if that's relevant, though).

  reply	other threads:[~2020-04-17 21:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 21:55 git-grep's "-z" option misbehaves in subdirectory Greg Hurrell
2020-04-13 23:33 ` Junio C Hamano
2020-04-14  7:42 ` Matheus Tavares
2020-04-16 18:59 ` git-grep's "-z" option misbehaves in subdirectory Matheus Tavares Bernardino
2020-04-16 20:07   ` Junio C Hamano
2020-04-17  6:04     ` [PATCH] grep: follow conventions for printing paths w/ unusual chars Matheus Tavares
2020-04-17  6:45       ` Junio C Hamano
2020-04-17 21:19         ` Matheus Tavares Bernardino [this message]
2020-04-17 21:35           ` Junio C Hamano
2020-04-18 13:13       ` Johannes Schindelin
2020-04-18 14:56         ` Johannes Schindelin
2020-04-19  6:27           ` Matheus Tavares Bernardino
2020-04-19  6:33       ` [PATCH v2] " Matheus Tavares

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=CAHd-oW7B1wtHOE7KCtOR-kAXhuj8Du_MAYobWd9nSsSvm_sChQ@mail.gmail.com \
    --to=matheus.bernardino@usp.br \
    --cc=asheiduk@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=greg@hurrell.net \
    --cc=l.s.r@web.de \
    /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 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.