user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/6] lei saved search improvements
@ 2021-04-19  8:52  7% Eric Wong
  2021-04-19  8:52  5% ` [PATCH 5/6] lei_saved_search: split "lei q --save" and "lei up" init paths Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-04-19  8:52 UTC (permalink / raw)
  To: meta

I think the "lei q --save" and "lei up" commands are in a good
state.  There's no way to edit/forget saved searches, yet,
so I guess that's next...

Eric Wong (6):
  lei: support unlinked/missing saved searches
  lei q: implement import-before default for --save
  lei_saved_search: avoid needless var shadowing
  config: git_config_dump blesses
  lei_saved_search: split "lei q --save" and "lei up" init paths
  lei q: --save and --augment may be combined

 lib/PublicInbox/Config.pm         | 10 ++--
 lib/PublicInbox/LEI.pm            |  3 +-
 lib/PublicInbox/LeiLsSearch.pm    |  2 +-
 lib/PublicInbox/LeiMirror.pm      |  2 +-
 lib/PublicInbox/LeiSavedSearch.pm | 94 +++++++++++++++----------------
 lib/PublicInbox/LeiToMail.pm      |  6 +-
 lib/PublicInbox/LeiUp.pm          |  4 +-
 t/lei-q-save.t                    | 41 ++++++++++++++
 8 files changed, 101 insertions(+), 61 deletions(-)


^ permalink raw reply	[relevance 7%]

* [PATCH 5/6] lei_saved_search: split "lei q --save" and "lei up" init paths
  2021-04-19  8:52  7% [PATCH 0/6] lei saved search improvements Eric Wong
@ 2021-04-19  8:52  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-04-19  8:52 UTC (permalink / raw)
  To: meta

They're more different than alike, and having two separate
methods seems less confusing to me.
---
 lib/PublicInbox/LeiLsSearch.pm    |  2 +-
 lib/PublicInbox/LeiSavedSearch.pm | 79 ++++++++++++++++---------------
 lib/PublicInbox/LeiUp.pm          |  2 +-
 3 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/lib/PublicInbox/LeiLsSearch.pm b/lib/PublicInbox/LeiLsSearch.pm
index 2aa457c0..9ac4870f 100644
--- a/lib/PublicInbox/LeiLsSearch.pm
+++ b/lib/PublicInbox/LeiLsSearch.pm
@@ -29,7 +29,7 @@ sub do_ls_search_long {
 	my @x = sort(grep(/\A\Q$pfx/, PublicInbox::LeiSavedSearch::list($lei)));
 	while (my $x = shift @x) {
 		$ORS = '' if !scalar(@x);
-		my $lss = PublicInbox::LeiSavedSearch->new($lei, $x) or next;
+		my $lss = PublicInbox::LeiSavedSearch->up($lei, $x) or next;
 		my $cfg = $lss->{-cfg};
 		my $ent = {
 			q => $cfg->get_all('lei.q'),
diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm
index d3a32d36..948e4954 100644
--- a/lib/PublicInbox/LeiSavedSearch.pm
+++ b/lib/PublicInbox/LeiSavedSearch.pm
@@ -65,52 +65,57 @@ sub list {
 	} @$out
 }
 
-sub new {
+sub up { # updating existing saved search via "lei up"
 	my ($cls, $lei, $dst) = @_;
+	my $f;
 	my $self = bless { ale => $lei->ale }, $cls;
-	my $dir;
-	if (defined $dst) { # updating existing saved search via "lei up"
-		my $f;
-		$dir = $dst;
-		output2lssdir($self, $lei, \$dir, \$f) or
-			return $lei->fail("--save was not used with $dst cwd=".
-						$lei->rel2abs('.'));
-		$self->{'-f'} = $f;
-	} else { # new saved search "lei q --save"
-		$dst = $lei->{ovv}->{dst};
-		$dir = lss_dir_for($lei, \$dst);
-		require File::Path;
-		File::Path::make_path($dir); # raises on error
-		$self->{-cfg} = {};
-		my $f = $self->{'-f'} = "$dir/lei.saved-search";
-		open my $fh, '>', $f or return $lei->fail("open $f: $!");
-		my $sq_dst = PublicInbox::Config::squote_maybe($dst);
-		my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
-		if (ref $q) {
-			$q = join("\n", map { "\tq = ".cquote_val($_) } @$q);
-		} else {
-			$q = "\tq = ".cquote_val($q);
-		}
-		$dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i;
-		print $fh <<EOM;
+	my $dir = $dst;
+	output2lssdir($self, $lei, \$dir, \$f) or
+		return $lei->fail("--save was not used with $dst cwd=".
+					$lei->rel2abs('.'));
+	$self->{-cfg} = PublicInbox::Config->git_config_dump($f);
+	$self->{-ovf} = "$dir/over.sqlite3";
+	$self->{'-f'} = $f;
+	$self->{lock_path} = "$self->{-f}.flock";
+	$self;
+}
+
+sub new { # new saved search "lei q --save"
+	my ($cls, $lei) = @_;
+	my $self = bless { ale => $lei->ale }, $cls;
+	my $dst = $lei->{ovv}->{dst};
+	my $dir = lss_dir_for($lei, \$dst);
+	require File::Path;
+	File::Path::make_path($dir); # raises on error
+	$self->{-cfg} = {};
+	my $f = $self->{'-f'} = "$dir/lei.saved-search";
+	open my $fh, '>', $f or return $lei->fail("open $f: $!");
+	my $sq_dst = PublicInbox::Config::squote_maybe($dst);
+	my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
+	if (ref $q) {
+		$q = join("\n", map { "\tq = ".cquote_val($_) } @$q);
+	} else {
+		$q = "\tq = ".cquote_val($q);
+	}
+	$dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i;
+	print $fh <<EOM;
 ; to refresh with new results, run: lei up $sq_dst
 [lei]
-$q
+	$q
 [lei "q"]
 	output = $dst
 EOM
-		for my $k (ARRAY_FIELDS) {
-			my $ary = $lei->{opt}->{$k} // next;
-			for my $x (@$ary) {
-				print $fh "\t$k = ".cquote_val($x)."\n";
-			}
-		}
-		for my $k (BOOL_FIELDS) {
-			my $val = $lei->{opt}->{$k} // next;
-			print $fh "\t$k = ".($val ? 1 : 0)."\n";
+	for my $k (ARRAY_FIELDS) {
+		my $ary = $lei->{opt}->{$k} // next;
+		for my $x (@$ary) {
+			print $fh "\t$k = ".cquote_val($x)."\n";
 		}
-		close($fh) or return $lei->fail("close $f: $!");
 	}
+	for my $k (BOOL_FIELDS) {
+		my $val = $lei->{opt}->{$k} // next;
+		print $fh "\t$k = ".($val ? 1 : 0)."\n";
+	}
+	close($fh) or return $lei->fail("close $f: $!");
 	$self->{lock_path} = "$self->{-f}.flock";
 	$self->{-ovf} = "$dir/over.sqlite3";
 	$self;
diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index e4cbc825..23c5c606 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -11,7 +11,7 @@ use PublicInbox::LeiOverview;
 sub lei_up {
 	my ($lei, $out) = @_;
 	$lei->{lse} = $lei->_lei_store(1)->search;
-	my $lss = PublicInbox::LeiSavedSearch->new($lei, $out) or return;
+	my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return;
 	my $mset_opt = $lei->{mset_opt} = { relevance => -2 };
 	$mset_opt->{limit} = $lei->{opt}->{limit} // 10000;
 	my $q = $mset_opt->{q_raw} = $lss->{-cfg}->{'lei.q'} //

^ permalink raw reply related	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-04-19  8:52  7% [PATCH 0/6] lei saved search improvements Eric Wong
2021-04-19  8:52  5% ` [PATCH 5/6] lei_saved_search: split "lei q --save" and "lei up" init paths Eric Wong

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).