user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <>
To: "SZEDER Gábor" <>
Subject: [PATCH] viewdiff: do not anchor using diffstat comments
Date: Fri, 5 Jul 2019 04:03:11 +0000
Message-ID: <20190705040311.GA2896@dcvr> (raw)
In-Reply-To: <>

SZEDER Gábor <> wrote:
> Hi,
> being able to jump around from diffstat to the diff of a particular
> file and back by simply clicking on links is great, but it doesn't
> seem to work with newly added files.  Consider this message:

Glad you noticed this feature :)  I keep forgetting to do more
work on it (fixing interdiffs and such), and also writing
automated tests to catch it.

> Clicking on the link that is the name of the doc source file or any of
> the C source of header files in the diffstat jumps to the diff of the
> particular file, but clicking on the link of any of the two new test
> files doesn't go anywhere.  Conversely, in the "diff --git a/...
> b/..." lines of the doc and source files the word "diff" is a link
> pointing back to the diffstat, but in the diff lines of those two new
> test files there is no link.

Thanks for the bug report.  The following should fix it,
it's also deployed on

Subject: [PATCH] viewdiff: do not anchor using diffstat comments

Diffstat summary comments were added to git last year and
we need to filter them out to get anchors working properly.

Reported-by: SZEDER Gábor <>
 lib/PublicInbox/ | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/ b/lib/PublicInbox/
index b7dab81..4669e87 100644
--- a/lib/PublicInbox/
+++ b/lib/PublicInbox/
@@ -41,6 +41,9 @@ my $OID_BLOB = '[a-f0-9]{7,40}';
 my $PATH_A = '"?a/.+|/dev/null';
 my $PATH_B = '"?b/.+|/dev/null';
+# cf. git diff.c :: get_compact_summary
+my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/;
 sub to_html ($$) {
@@ -89,7 +92,7 @@ sub anchor0 ($$$$$) {
 	# So only do best-effort handling of renames for common cases;
 	# which works well in practice. If projects put "=>", or trailing
 	# spaces in filenames, oh well :P
-	$fn =~ s/ +\z//s;
+	$fn =~ s/(?: *$DIFFSTAT_COMMENT)? *\z//so;
 	$fn =~ s/{(?:.+) => (.+)}/$1/ or $fn =~ s/.* => (.+)/$1/;
 	$fn = git_unquote($fn);

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04 23:11 broken link in diffstat for new files SZEDER Gábor
2019-07-05  4:03 ` Eric Wong [this message]
2019-07-05  4:06   ` [PATCH] viewdiff: do not anchor using diffstat comments Eric Wong
2019-07-05  8:55     ` SZEDER Gábor
2020-01-04  9:16       ` [PATCH] viewdiff: do not anchor spaces after filenames in diffstat Eric Wong

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:

  List information:

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

  git send-email \
    --in-reply-to=20190705040311.GA2896@dcvr \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:

 note: .onion URLs require Tor:

AGPL code for this site: git clone