git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 4/4] get_oid(): when an object was not found, try harder
Date: Wed, 13 Mar 2019 03:16:34 -0700 (PDT)	[thread overview]
Message-ID: <994446236d05d9d014e12a5102bcf9be222e3b57.1552472189.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.161.git.gitgitgadget@gmail.com>

From: Johannes Schindelin <johannes.schindelin@gmx.de>

It is quite possible that the loose object cache gets stale when new
objects are written. In that case, get_oid() would potentially say that
it cannot find a given object, even if it should find it.

Let's blow away the loose object cache as well as the read packs and try
again in that case.

Note: this does *not* affect the code path that was introduced to help
avoid looking for the same non-existing objects (which made some
operations really expensive via NFS): that code path is handled by the
`OBJECT_INFO_QUICK` flag (which does not even apply to `get_oid()`,
which has no equivalent flag, at least at the time this patch was
written).

This incidentally fixes the problem identified earlier where an
interactive rebase wanted to re-read (and validate) the todo list after
an `exec` command modified it.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 sha1-name.c                 | 12 ++++++++++++
 t/t3429-rebase-edit-todo.sh |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c16df..cfe5c874b6 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -442,6 +442,18 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	find_short_packed_object(&ds);
 	status = finish_object_disambiguation(&ds, oid);
 
+	/*
+	 * If we didn't find it, do the usual reprepare() slow-path,
+	 * since the object may have recently been added to the repository
+	 * or migrated from loose to packed.
+	 */
+	if (status == MISSING_OBJECT) {
+		reprepare_packed_git(the_repository);
+		find_short_object_filename(&ds);
+		find_short_packed_object(&ds);
+		status = finish_object_disambiguation(&ds, oid);
+	}
+
 	if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
 		struct oid_array collect = OID_ARRAY_INIT;
 
diff --git a/t/t3429-rebase-edit-todo.sh b/t/t3429-rebase-edit-todo.sh
index 862f229c87..76f6d306ea 100755
--- a/t/t3429-rebase-edit-todo.sh
+++ b/t/t3429-rebase-edit-todo.sh
@@ -11,7 +11,7 @@ test_expect_success 'rebase exec modifies rebase-todo' '
 	test -e F
 '
 
-test_expect_failure SHA1 'loose object cache vs re-reading todo list' '
+test_expect_success SHA1 'loose object cache vs re-reading todo list' '
 	GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
 	export GIT_REBASE_TODO &&
 	write_script append-todo.sh <<-\EOS &&
-- 
gitgitgadget

  parent reply	other threads:[~2019-03-13 10:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 10:16 [PATCH 0/4] get_oid: cope with a possibly stale loose object cache Johannes Schindelin via GitGitGadget
2019-03-13 10:16 ` [PATCH 1/4] rebase -i: demonstrate obscure loose object cache bug Johannes Schindelin via GitGitGadget
2019-03-13 16:11   ` Ævar Arnfjörð Bjarmason
2019-03-13 16:35     ` Jeff King
2019-03-13 16:53       ` Jeff King
2019-03-13 22:40         ` Johannes Schindelin
2019-03-14  0:07           ` Jeff King
2019-03-13 22:27       ` Johannes Schindelin
2019-03-14  0:05         ` Jeff King
2019-03-14  6:40       ` Johannes Sixt
2019-03-14 13:06         ` Johannes Schindelin
2019-03-14  1:12   ` Junio C Hamano
2019-03-14 12:44     ` Johannes Schindelin
2019-03-13 10:16 ` [PATCH 2/4] sequencer: improve error message when an OID could not be parsed Johannes Schindelin via GitGitGadget
2019-03-14  1:14   ` Junio C Hamano
2019-03-13 10:16 ` [PATCH 3/4] sequencer: move stale comment into correct location Johannes Schindelin via GitGitGadget
2019-03-13 10:16 ` Johannes Schindelin via GitGitGadget [this message]
2019-03-14  1:29   ` [PATCH 4/4] get_oid(): when an object was not found, try harder Junio C Hamano
2019-03-14  2:22     ` Jeff King
2019-03-14  2:40       ` Jeff King
2019-03-14  4:05         ` Junio C Hamano
2019-03-14 18:55           ` Jeff King
2019-03-14  3:49       ` Junio C Hamano
2019-03-14 13:17     ` Johannes Schindelin
2019-03-14 18:57       ` Jeff King
2019-03-14 19:55         ` Johannes Schindelin
2019-03-13 15:33 ` [PATCH 0/4] get_oid: cope with a possibly stale loose object cache Jeff King
2019-03-14 15:33 ` [PATCH v2 0/4] get_short_oid: " Johannes Schindelin via GitGitGadget
2019-03-14 15:33   ` [PATCH v2 1/4] rebase -i: demonstrate obscure loose object cache bug Johannes Schindelin via GitGitGadget
2019-03-14 15:33   ` [PATCH v2 2/4] sequencer: improve error message when an OID could not be parsed Johannes Schindelin via GitGitGadget
2019-03-14 15:33   ` [PATCH v2 3/4] sequencer: move stale comment into correct location Johannes Schindelin via GitGitGadget
2019-03-14 15:33   ` [PATCH v2 4/4] get_oid(): when an object was not found, try harder Johannes Schindelin via GitGitGadget

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: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=994446236d05d9d014e12a5102bcf9be222e3b57.1552472189.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=peff@peff.net \
    /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/mirrors/git.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).