user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] cindex bug fixes
@ 2023-12-06 21:12 Eric Wong
  2023-12-06 21:12 ` [PATCH 1/2] t/cindex: fix test when worktree PWD is a symlink Eric Wong
  2023-12-06 21:12 ` [PATCH 2/2] cindex: avoid recursion on prune Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2023-12-06 21:12 UTC (permalink / raw)
  To: meta

Eric Wong (2):
  t/cindex: fix test when worktree PWD is a symlink
  cindex: avoid recursion on prune

 lib/PublicInbox/CodeSearchIdx.pm | 16 +++++++++-------
 t/cindex.t                       |  5 +++--
 2 files changed, 12 insertions(+), 9 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] t/cindex: fix test when worktree PWD is a symlink
  2023-12-06 21:12 [PATCH 0/2] cindex bug fixes Eric Wong
@ 2023-12-06 21:12 ` Eric Wong
  2023-12-06 21:12 ` [PATCH 2/2] cindex: avoid recursion on prune Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2023-12-06 21:12 UTC (permalink / raw)
  To: meta

Our code aims to respect $ENV{PWD} (and therefore symlinks) as
much as possible to ensure portability across devices when repos
and indices are on portable or shared storage.  Thus we can't
rely on Cwd::abs_path and ought to favor File::Spec->rel2abs
whenever absolute paths are required.

I noticed this when working on a VM where my worktree is a
symlink to a more reliable device.
---
 t/cindex.t | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/cindex.t b/t/cindex.t
index 716e5984..15c860e1 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -3,7 +3,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use v5.12;
 use PublicInbox::TestCommon;
-use Cwd qw(getcwd abs_path);
+use Cwd qw(getcwd);
 use List::Util qw(sum);
 use autodie qw(close mkdir open rename);
 require_mods(qw(json Xapian +SCM_RIGHTS));
@@ -67,6 +67,7 @@ git gc -q
 EOM
 }; # /create_coderepo
 
+$zp = File::Spec->rel2abs($zp);
 ok(run_script([qw(-cindex --dangerous -q -d), "$tmp/ext",
 		'-g', $zp, '-g', "$tmp/wt0" ]),
 	'cindex external');
@@ -125,7 +126,7 @@ use_ok 'PublicInbox::CodeSearch';
 
 my @xh_args;
 my $exp = [ 'initial with NUL character', 'remove NUL character' ];
-my $zp_git = abs_path("$zp/.git");
+my $zp_git = "$zp/.git";
 if ('multi-repo search') {
 	my $csrch = PublicInbox::CodeSearch->new("$tmp/ext");
 	my $mset = $csrch->mset('NUL');

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] cindex: avoid recursion on prune
  2023-12-06 21:12 [PATCH 0/2] cindex bug fixes Eric Wong
  2023-12-06 21:12 ` [PATCH 1/2] t/cindex: fix test when worktree PWD is a symlink Eric Wong
@ 2023-12-06 21:12 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2023-12-06 21:12 UTC (permalink / raw)
  To: meta

There's no need to recurse and trigger deep recursion warnings
when we hit a coderepo with a known hash (SHA-1 vs SHA-256).
Noticed while pruning the 1200+ repos on a git.kernel.org
mirror.
---
 lib/PublicInbox/CodeSearchIdx.pm | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 20aac584..967933f2 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -909,21 +909,23 @@ sub prep_alternate_read { # run_git cb for config extensions.objectFormat
 
 sub prep_alternate_start {
 	my ($self, $git, $run_prune) = @_;
-	my $o = $git->git_path('objects');
+	local $self->{xdb};
+	my ($o, $n, @ids, @fmt);
+start:
+	$o = $git->git_path('objects');
 	while (!-d $o) {
 		$git = shift(@PRUNEQ) // return;
 		$o = $git->git_path('objects');
 	}
-	my $n = git_dir_hash($git->{git_dir}) % scalar(@RDONLY_XDB);
-	local $self->{xdb} = $RDONLY_XDB[$n] // croak("BUG: no shard[$n]");
-	my @ids = $self->docids_by_postlist('P'.$git->{git_dir});
-	my @fmt = @ids ? xap_terms('H', $self->{xdb}, $ids[0]) : ();
+	$n = git_dir_hash($git->{git_dir}) % scalar(@RDONLY_XDB);
+	$self->{xdb} = $RDONLY_XDB[$n] // croak("BUG: no shard[$n]");
+	@ids = $self->docids_by_postlist('P'.$git->{git_dir});
+	@fmt = @ids ? xap_terms('H', $self->{xdb}, $ids[0]) : ();
 	@fmt > 1 and warn "BUG? multi `H' for shard[$n] #$ids[0]: @fmt";
 
 	if (@fmt) { # cache hit
-		@PRUNEQ and
-			prep_alternate_start($self, shift(@PRUNEQ), $run_prune);
 		prep_alternate_end $o, $fmt[0];
+		$git = shift(@PRUNEQ) and goto start;
 	} else { # compatibility w/ early cidx format
 		run_git([qw(config extensions.objectFormat)], { quiet => 1 },
 			\&prep_alternate_read, $self, $git, $o, $ids[0], $n,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-06 21:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 21:12 [PATCH 0/2] cindex bug fixes Eric Wong
2023-12-06 21:12 ` [PATCH 1/2] t/cindex: fix test when worktree PWD is a symlink Eric Wong
2023-12-06 21:12 ` [PATCH 2/2] cindex: avoid recursion on prune 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).