user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: Kyle Meyer <kyle@kyleam.com>
Cc: meta@public-inbox.org
Subject: Re: view: why is the diff line number incremented by one?
Date: Sat, 9 May 2020 18:24:01 +0000	[thread overview]
Message-ID: <20200509182401.GA20512@dcvr> (raw)
In-Reply-To: <87tv0pc8vg.fsf@kyleam.com>

Kyle Meyer <kyle@kyleam.com> wrote:
> Diff links position the line one beyond what I expect.  Here's a hunk at
> <https://public-inbox.org/meta/20200509082738.23602-2-e@yhbt.net/>:

<snip>

> The link at "-71,11" is
> <https://public-inbox.org/meta/4508bd84/s/?b=lib/PublicInbox/Eml.pm#n72>.
> When I follow it, I'm taken to line 72, one line below the first context
> line above.  I haven't been able to come up with a reason why +1 would
> be preferable here, and I didn't spot any explanation when looking
> around the code.  It looks like it'd just be a matter of making the
> two-line change below, but perhaps that causes breakage that I didn't
> notice with my light testing.

Good question, it's been that way since the beginning...

It might have been due to the "0" for new files and line numbers
counting starting at "1".  But hunks aren't hyperlinks for new files,
since the blob OID already is.

> diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
> index 6fe9a0d7..536bb9e3 100644
> --- a/lib/PublicInbox/ViewDiff.pm
> +++ b/lib/PublicInbox/ViewDiff.pm
> @@ -50,12 +50,12 @@ sub diff_hunk ($$$$) {
>  
>  	if (defined($spfx) && defined($oid_a) && defined($oid_b)) {
>  		my ($n) = ($ca =~ /^-([0-9]+)/);
> -		$n = defined($n) ? do { ++$n; "#n$n" } : '';
> +		$n = defined($n) ? "#n$n" : '';
>  
>  		$$dst .= qq(@@ <a\nhref="$spfx$oid_a/s/$dctx->{Q}$n">$ca</a>);
>  
>  		($n) = ($cb =~ /^\+([0-9]+)/);
> -		$n = defined($n) ? do { ++$n; "#n$n" } : '';
> +		$n = defined($n) ? "#n$n" : '';
>  		$$dst .= qq( <a\nhref="$spfx$oid_b/s/$dctx->{Q}$n">$cb</a> @@);
>  	} else {
>  		$$dst .= "@@ $ca $cb @@";

I'll probably take this patch, soon, got a commit message?
Given the massive change Eml is, 1.5.0 will probably be released, soon.

  reply	other threads:[~2020-05-09 18:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 17:32 view: why is the diff line number incremented by one? Kyle Meyer
2020-05-09 18:24 ` Eric Wong [this message]
2020-05-09 18:57   ` [PATCH] viewdiff: don't increment the reported hunk line number Kyle Meyer

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

  List information: http://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20200509182401.GA20512@dcvr \
    --to=e@yhbt.net \
    --cc=kyle@kyleam.com \
    --cc=meta@public-inbox.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).