user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] cindex: index full (40/64 char) hex blob OIDs
Date: Tue,  5 Dec 2023 09:46:23 +0000	[thread overview]
Message-ID: <20231205094623.3394786-3-e@80x24.org> (raw)
In-Reply-To: <20231205094623.3394786-1-e@80x24.org>

This future proofs the index against git auto-abbreviation
needing more characters as the repo grows.  It'll be useful for
joining against inboxes using dfpre.

As with emails, we'll continue indexing abbreviated blob OIDs
down to 7 hex characters so a SHA-1 git repo will have all
abbreviations of the OID from 7-39 hex characters in addition
to the 40 character unabbreviated form.
---
 lib/PublicInbox/CodeSearchIdx.pm | 15 +++++++++------
 t/cindex.t                       |  3 +++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index ec0fc6e3..20aac584 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -107,6 +107,8 @@ our (
 	$DUMP_IBX_WPIPE, # goes to sort(1)
 	$ANY_SHARD, # shard round-robin for scan fingerprinting
 	@OFF2ROOT,
+	$GIT_VER,
+	@NO_ABBREV,
 );
 
 # stop walking history if we see >$SEEN_MAX existing commits, this assumes
@@ -304,7 +306,7 @@ sub shard_index { # via wq_io_do in IDX_SHARDS
 	my $in = delete($self->{0}) // die 'BUG: no {0} input';
 	my $op_p = delete($self->{1}) // die 'BUG: no {1} op_p';
 	sysseek($in, 0, SEEK_SET);
-	my $cmd = $git->cmd(@LOG_STDIN);
+	my $cmd = $git->cmd(@NO_ABBREV, @LOG_STDIN);
 	my $rd = popen_rd($cmd, undef, { 0 => $in },
 				\&cidx_reap_log, $cmd, $self, $op_p);
 	PublicInbox::CidxLogP->new($rd, $self, $git, $roots);
@@ -1151,15 +1153,14 @@ sub run_prune { # OnDestroy when `git config extensions.objectFormat' are done
 	run_await([@SORT, '-u'], $CMD_ENV, $sort_opt, \&cmd_done);
 	my $comm_rd = popen_rd(\@COMM, $CMD_ENV, $comm_opt, \&cmd_done, \@COMM);
 	PublicInbox::CidxComm->new($comm_rd, $self, $drs); # ->cidx_read_comm
-	my $git_ver = PublicInbox::Git::git_version();
-	push @PRUNE_BATCH, '--buffer' if $git_ver ge v2.6;
+	push @PRUNE_BATCH, '--buffer' if $GIT_VER ge v2.6;
 
 	# Yes, we pipe --unordered git output to sort(1) because sorting
 	# inside git leads to orders-of-magnitude slowdowns on rotational
 	# storage.  GNU sort(1) also works well on larger-than-memory
 	# datasets, and it's not worth eliding sort(1) for old git.
-	push @PRUNE_BATCH, '--unordered' if $git_ver ge v2.19;
-	warn(sprintf(<<EOM, $git_ver)) if $git_ver lt v2.19;
+	push @PRUNE_BATCH, '--unordered' if $GIT_VER ge v2.19;
+	warn(sprintf(<<EOM, $GIT_VER)) if $GIT_VER lt v2.19;
 W: git v2.19+ recommended for high-latency storage (have git v%vd)
 EOM
 	dump_git_commits(undef, undef, undef, $batch_opt, $self);
@@ -1281,7 +1282,7 @@ sub cidx_run { # main entry point
 	local $SCANQ = [];
 	local ($DO_QUIT, $REINDEX, $TXN_BYTES, @GIT_DIR_GONE, @PRUNEQ,
 		$REPO_CTX, %ALT_FH, $TMPDIR, @AWK, @COMM, $CMD_ENV,
-		%TODO, @IBXQ, @IBX, @JOIN, %JOIN, @JOIN_PFX,
+		%TODO, @IBXQ, @IBX, @JOIN, %JOIN, @JOIN_PFX, @NO_ABBREV,
 		@JOIN_DT, $DUMP_IBX_WPIPE, @OFF2ROOT, $XHC, @SORT, $GITS_NR);
 	local $BATCH_BYTES = $self->{-opt}->{batch_size} //
 				$PublicInbox::SearchIdx::BATCH_BYTES;
@@ -1289,6 +1290,8 @@ sub cidx_run { # main entry point
 	local $self->{PENDING} = {}; # used by PublicInbox::CidxXapHelperAux
 	my $cfg = $self->{-opt}->{-pi_cfg} // die 'BUG: -pi_cfg unset';
 	$self->{-cfg_f} = $cfg->{-f} = rel2abs_collapsed($cfg->{-f});
+	local $GIT_VER = PublicInbox::Git::git_version();
+	@NO_ABBREV = ('-c', 'core.abbrev='.($GIT_VER lt v2.31.0 ? 40 : 'no'));
 	if (grep { $_ } @{$self->{-opt}}{qw(prune join)}) {
 		require File::Temp;
 		$TMPDIR = File::Temp->newdir('cidx-all-git-XXXX', TMPDIR => 1);
diff --git a/t/cindex.t b/t/cindex.t
index 0193cf18..716e5984 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -288,6 +288,9 @@ EOM
 		++$nr;
 	}, '.');
 	is $nr, 1, 'iterated through cindices';
+	my $oid = 'dba13ed2ddf783ee8118c6a581dbf75305f816a3';
+	my $mset = $csrch->mset("dfpost:$oid");
+	is $mset->size, 1, 'got result from full OID search';
 }
 
 done_testing;

      parent reply	other threads:[~2023-12-05  9:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  9:46 [PATCH 0/2] cindex: future-proof blob OID indexing Eric Wong
2023-12-05  9:46 ` [PATCH 1/2] searchidx: drop redundant decl in index_git_blob_id Eric Wong
2023-12-05  9:46 ` Eric Wong [this message]

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20231205094623.3394786-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).