about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewDiff.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-23 08:31:56 +0000
committerEric Wong <e@80x24.org>2022-08-23 22:40:52 +0000
commit66512e177390aedb4a9380484230768621528e57 (patch)
tree892a41e5daa80eb45ae1a3143ea7e8af9cef5f83 /lib/PublicInbox/ViewDiff.pm
parent6b4e4f0d2d52a4b39c68d8f63915ddb7e1e8270e (diff)
downloadpublic-inbox-66512e177390aedb4a9380484230768621528e57.tar.gz
The dfblob: search prefix is probably under-utilized, but is
extremely powerful IMHO.  To make it easier-to-use, add a search
textarea with it prefilled with values for the existing patch
message.  This allows users to easily run a query for all
patches which alter or result in either pre or post-image
blobs in the current patch.

Behavior changes are as follows: "changed" in the diffstat
jumps to the bottom of the message.  For /T/ and /t/, it
goes to the "related" anchor which is just above the reply
instructions in the single-message view.  For the single
message view, it'll jump to the textarea search form.

I initially wanted to use a normal `<a href=' link, but
figured the textarea is advantageous for two reasons:

1) users should be able to edit the query before submitting
2) crawlers are less likely to waste CPU/disk on forms

It's probably too noisy to add this directly to the /T/ and /t/
views, but seems like a good place to put above the reply
instructions in the single message view.

Note that the queries used by the /$COMMIT_OID/s/ view is
subtly different than the /$MSGID/ view since git will lengthen
its abbreviations over time, while emails are immutable.

I tried adding dfn: (filename) and s: (subject) support, but
couldn't come up with cases where it really made sense for
/$MSGID/.  /$COMMIT_OID/s/ may benefit from it, since patchid:
could be flaky due to non-standard diff generation options.
Diffstat (limited to 'lib/PublicInbox/ViewDiff.pm')
-rw-r--r--lib/PublicInbox/ViewDiff.pm22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index fb394b7c..960f7e61 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # used by PublicInbox::View
@@ -141,13 +141,16 @@ sub diff_header ($$$) {
 
         # no need to capture oid_a and oid_b on add/delete,
         # we just linkify OIDs directly via s///e in conditional
-        if (($$x =~ s/$NULL_TO_BLOB/$1 . oid($dctx, $spfx, $2)/e) ||
-                ($$x =~ s/$BLOB_TO_NULL/
-                        'index ' . oid($dctx, $spfx, $1) . $2/e)) {
+        if ($$x =~ s/$NULL_TO_BLOB/$1 . oid($dctx, $spfx, $2)/e) {
+                push @{$ctx->{-qry}->{dfpost}}, $2;
+        } elsif ($$x =~ s/$BLOB_TO_NULL/'index '.oid($dctx, $spfx, $1).$2/e) {
+                push @{$ctx->{-qry}->{dfpre}}, $1;
         } elsif ($$x =~ $BLOB_TO_BLOB) {
                 # modification-only, not add/delete:
                 # linkify hunk headers later using oid_a and oid_b
                 @$dctx{qw(oid_a oid_b)} = ($1, $2);
+                push @{$ctx->{-qry}->{dfpre}}, $1;
+                push @{$ctx->{-qry}->{dfpost}}, $2;
         } else {
                 warn "BUG? <$$x> had no ^index line";
         }
@@ -172,9 +175,16 @@ sub diff_before_or_after ($$) {
                         # ok, looks like a diffstat, go line-by-line:
                         for my $l (split(/^/m, $y)) {
                                 if ($l =~ /^ (.+)( +\| .*\z)/s) {
-                                        anchor0($dst, $ctx, $1, $2) and next;
+                                        anchor0($dst, $ctx, $1, $2) or
+                                                $$dst .= $linkify->to_html($l);
+                                } elsif ($l =~ s/^( [0-9]+ files? )changed,//) {
+                                        $$dst .= $1;
+                                        my $end = $ctx->{end_id} // 'related';
+                                        $$dst .= "<a href=#$end>changed</a>,";
+                                        $$dst .= ascii_html($l);
+                                } else {
+                                        $$dst .= $linkify->to_html($l);
                                 }
-                                $$dst .= $linkify->to_html($l);
                         }
                 } else { # commit message, notes, etc
                         $$dst .= $linkify->to_html($y);