about summary refs log tree commit homepage
path: root/lib/PublicInbox/LEI.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-28 18:25:26 +0600
committerEric Wong <e@80x24.org>2021-03-01 05:51:54 +0000
commit9c55d0015717c198dce748afd97db12eb70586c7 (patch)
treeab3a94a944293cd08425aa7acfe566c5c3d0e8d7 /lib/PublicInbox/LEI.pm
parentc9ff20cbef45d32e4b46a78f081312543c781428 (diff)
downloadpublic-inbox-9c55d0015717c198dce748afd97db12eb70586c7.tar.gz
Instead of teaching the to-be-implemented "lei show" to search
threads/messages based commits, this orthogonal sub-command is
designed to generate queries for use with "lei q --stdin".

URI-escaped query parameters may be generated with --uri for
HTTP(S) public-inbox instances, but otherwise the output is
designed for "lei q --stdin".

To find threads for a given git commit from a git worktree:

	lei p2q $COMMIT_OID | lei q --stdin -t ...

It can also read via --stdin|-

	curl $INBOX_URL/$MSGID/raw | lei p2q - | lei q --stdin -t

Or from the filesystem:

	lei p2q $(git format-patch -1) | lei q --stdin -t

This defaults to only generating "dfpost:"-prefixed terms since
I've found those most useful for finding messages relating to a
commit.  This is subject to change.

--want=s@ is a comma-separated or multi-value list of prefixes
that defaults to "dfpost7".  Not all are implemented, yet, but
s, dfn, dfpre, and dfpost all seem to mostly work.  Phrase
handling may need to be tweaked to work with Xapian.

OR, NEAR, ADJ, AND, NOT may be used with --want
(e.g. --want=dfpost,OR,dfn)

Prefixing the field prefix with '+' or '-' (e.g. --want=+dfpost)
generates "+dfpost:$EXTRACTED_OID" for Xapian.   For non-boolean
search prefixes, wildcard (*) may also be supplied: (--want=dfn*)

For boolean search prefixes, suffixing the field prefix with a
digit (e.g. --want=dfpost7) provides a minimum length, allowing
truncated variations to be searched.  This is helpful for
finding older messages as git chooses longer dfpost|dfpre
abbreviations as repos get larger.

Automatic date range generation is not implemented, yet.
Diffstat (limited to 'lib/PublicInbox/LEI.pm')
-rw-r--r--lib/PublicInbox/LEI.pm30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 0da24499..a2f8ffe7 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -179,6 +179,9 @@ our %CMD = ( # sorted in order of importance/use:
         qw(stdin| in-format|F=s out-format|f=s output|mfolder|o=s quiet|q
         lock=s@ kw|keywords|flags! C=s@),
         ],
+'p2q' => [ 'FILE|COMMIT_OID|--stdin',
+        "use a patch to generate a query for `lei q --stdin'",
+        qw(stdin| want|w=s@ uri debug) ],
 'config' => [ '[...]', sub {
                 'git-config(1) wrapper for '._config_path($_[0]);
         }, qw(config-file|system|global|file|f=s), # for conflict detection
@@ -238,6 +241,10 @@ my %OPTDESC = (
 'show        threads|t' => 'display entire thread a message belongs to',
 'q        threads|t+' =>
         'return all messages in the same threads as the actual match(es)',
+
+'want|w=s@' => [ 'PREFIX|dfpost|dfn', # common ones in help...
+                'search prefixes to extract (default: dfpost7)' ],
+
 'alert=s@' => ['CMD,:WINCH,:bell,<any command>',
         'run command(s) or perform ops when done writing to output ' .
         '(default: ":WINCH,:bell" with --mua and Maildir/IMAP output, ' .
@@ -331,7 +338,7 @@ my %CONFIG_KEYS = (
         'leistore.dir' => 'top-level storage location',
 );
 
-my @WQ_KEYS = qw(lxs l2m imp mrr cnv); # internal workers
+my @WQ_KEYS = qw(lxs l2m imp mrr cnv p2q); # internal workers
 
 # pronounced "exit": x_it(1 << 8) => exit(1); x_it(13) => SIGPIPE
 sub x_it ($$) {
@@ -673,6 +680,11 @@ sub lei_convert {
         PublicInbox::LeiConvert->call(@_);
 }
 
+sub lei_p2q {
+        require PublicInbox::LeiP2q;
+        PublicInbox::LeiP2q->call(@_);
+}
+
 sub lei_init {
         my ($self, $dir) = @_;
         my $cfg = _lei_cfg($self, 1);
@@ -854,6 +866,22 @@ sub poke_mua { # forces terminal MUAs to wake up and hopefully notice new mail
         }
 }
 
+my %path_to_fd = ('/dev/stdin' => 0, '/dev/stdout' => 1, '/dev/stderr' => 2);
+$path_to_fd{"/dev/fd/$_"} = $path_to_fd{"/proc/self/fd/$_"} for (0..2);
+sub fopen {
+        my ($self, $mode, $path) = @_;
+        rel2abs($self, $path);
+        $path =~ tr!/!/!s;
+        if (defined(my $fd = $path_to_fd{$path})) {
+                return $self->{$fd};
+        }
+        if ($path =~ m!\A/(?:dev|proc/self)/fd/[0-9]+\z!) {
+                return fail($self, "cannot open $path from daemon");
+        }
+        open my $fh, $mode, $path or return;
+        $fh;
+}
+
 # caller needs to "-t $self->{1}" to check if tty
 sub start_pager {
         my ($self) = @_;