git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] git-jump: always specify column 1 for diff entries
Date: Mon, 16 Sep 2024 22:13:39 +0200	[thread overview]
Message-ID: <CAN0heSrQiV6WOP4C5mFPh1AMgX9yy3CcHx2RPraKMFtmNJ2fPw@mail.gmail.com> (raw)
In-Reply-To: <20240915111846.GA2017851@coredump.intra.peff.net>

On Sun, 15 Sept 2024 at 13:18, Jeff King <peff@peff.net> wrote:
>
> When we generate a quickfix entry for a diff hunk, we provide just the
> filename and line number along with the content, like:
>
>   file:1: contents of the line
>
> This can be a problem if the line itself looks like a quickfix header.
> For example (and this is adapted from a real-world case that bit me):
>
>   echo 'static_lease 10:11:12:13:14:15:16 10.0.0.1' >file
>   git add file
>   echo change >file
>
> produces:
>
>   file:1: static_lease 10:11:12:13:14:15:16 10.0.0.1
>
> which is ambiguous. It could be line 1 of "file", or line 11 of the file
> "file:1: static_lease 10", and so on. In the case of vim's default
> config, it seems to prefer the latter (you can configure "errorformat"
> with a variety of patterns, but out of the box it matches some common
> ones).

I've never hit this, but it doesn't look too crazy. A couple of digits
and a colon and things begin to match. Ok.

> One easy way to fix this is to provide a column number, like:
>
>   file:1:1: static_lease 10:11:12:13:14:15:16 10.0.0.1
>
> which causes vim to prefer line 1 of "file" again (due to the preference
> order of the various patterns in the default errorformat).

Makes sense.

> There are other options. For example, at least in my version of vim,
> wrapping the file in quotation marks like:
>
>   "file":1: static_lease 10:11:12:13:14:15:16 10.0.0.1
>
> also works. That perhaps would the right thing even if you had the silly
> file name "file:1:1: foo 10". But it's not clear what would happen if
> you had a filename with quotes in it.

Right. Looking around, I can find someone asking the Internet how to
escape the filename and not getting any response.

> This feature is inherently scraping text, and there's bound to be some
> ambiguities. I don't think it's worth worrying too much about unlikely
> filenames, as its the file content that is more likely to introduce
> unexpected characters.

Agreed. (s/its/it's/)

> So let's just go with the extra ":1" column specifier. We know this is
> supported everywhere, as git-jump's "grep" mode already uses it (and
> thus doesn't exhibit the same problem).
>
> The "merge" mode is mostly immune to this, as it only matches "<<<<<<<"
> conflict marker lines. It's possible of course to have a marker that
> says "foo 10:11" later in the line, but in practice these will only have
> branches and perhaps file names, so it's probably not worth worrying
> about (and fixing it would involve passing --column to the system grep,
> which may not be portable).

I suppose we could use `git grep --no-index` instead of `grep` for `git
jump merge`. Anyway, that's out of scope here.

> I also gave some thought as to whether we could put something more
> useful than "1" in the column field for diffs. In theory we could find

Heh. Yes, in theory everything is possible. Your approach makes sense.

> -               print "$file:$line: $1\n";
> +               print "$file:$line:1: $1\n";

Looks good to me and from my testing, this fixes the problem as
described.

Martin

  reply	other threads:[~2024-09-16 20:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-15 11:11 [PATCH 0/2] a few git-jump quality-of-life fixes Jeff King
2024-09-15 11:18 ` [PATCH 1/2] git-jump: always specify column 1 for diff entries Jeff King
2024-09-16 20:13   ` Martin Ågren [this message]
2024-09-15 11:20 ` [PATCH 2/2] git-jump: ignore deleted files in diff mode Jeff King
2024-09-16 20:14   ` Martin Ågren
2024-09-17  8:58   ` Taylor Blau
2024-09-17 15:03     ` Junio C Hamano
2024-09-24 20:55       ` Jeff King
2024-09-24 22:03         ` Taylor Blau
2024-09-25 17:11           ` Junio C Hamano

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=CAN0heSrQiV6WOP4C5mFPh1AMgX9yy3CcHx2RPraKMFtmNJ2fPw@mail.gmail.com \
    --to=martin.agren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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).