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 4/5] solvergit: allow shorter-than-necessary OIDs from user
Date: Thu, 31 Jan 2019 04:27:23 +0000	[thread overview]
Message-ID: <20190131042724.2675-5-e@80x24.org> (raw)
In-Reply-To: <20190131042724.2675-1-e@80x24.org>

We can rely on git to disambiguate, here; because sometimes
shorter OIDs can be unambiguous even if we only resolved the
longer one.
---
 lib/PublicInbox/SolverGit.pm | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index 97da795..a13ae9e 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -302,6 +302,26 @@ sub extract_old_mode ($) {
 	'100644';
 }
 
+sub do_finish ($$) {
+	my ($self, $user_cb) = @_;
+	my $found = $self->{found};
+	my $oid_want = $self->{oid_want};
+	if (my $exists = $found->{$oid_want}) {
+		return $user_cb->($exists);
+	}
+
+	# let git disambiguate if oid_want was too short,
+	# but long enough to be unambiguous:
+	my $tmp_git = $self->{tmp_git};
+	if (my @res = $tmp_git->check($oid_want)) {
+		return $user_cb->($found->{$res[0]});
+	}
+	if (my $err = $tmp_git->last_check_err) {
+		dbg($self, $err);
+	}
+	$user_cb->(undef);
+}
+
 sub do_step ($) {
 	my ($self) = @_;
 	eval {
@@ -323,8 +343,8 @@ sub do_step ($) {
 		# our result: (which may be undef)
 		# Other steps may call user_cb to terminate prematurely
 		# on error
-		} elsif (my $ucb = delete($self->{user_cb})) {
-			$ucb->($self->{found}->{$self->{oid_want}});
+		} elsif (my $user_cb = delete($self->{user_cb})) {
+			do_finish($self, $user_cb);
 		} else {
 			die 'about to call user_cb twice'; # Oops :x
 		}
-- 
EW


  parent reply	other threads:[~2019-01-31  4:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-31  4:27 [PATCH 0/5] a few more solver fixups and improvements Eric Wong
2019-01-31  4:27 ` [PATCH 1/5] t/config.t: test PublicInbox::Git sharing between inboxes Eric Wong
2019-01-31  4:27 ` [PATCH 2/5] inbox: perform cleanup of Git objects for coderepos Eric Wong
2019-01-31  4:27 ` [PATCH 3/5] solvergit: allow searching on longer-than-needed OIDs Eric Wong
2019-01-31  4:27 ` Eric Wong [this message]
2019-01-31  4:27 ` [PATCH 5/5] viewvcs: support streaming large blobs Eric Wong

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=20190131042724.2675-5-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).