summaryrefslogtreecommitdiff
path: root/sha1-name.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-03-13 10:16:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-14 03:46:29 (GMT)
commit6d67a993b2a7c3e1a9c3688c92f28b237144c2fd (patch)
tree8e48f88cb326fa6e3d6f3d5b7820463eee60e8f6 /sha1-name.c
parent01710d0a3ff549a2bb5d8a97990393c2d95ce9c1 (diff)
downloadgit-6d67a993b2a7c3e1a9c3688c92f28b237144c2fd.zip
git-6d67a993b2a7c3e1a9c3688c92f28b237144c2fd.tar.gz
git-6d67a993b2a7c3e1a9c3688c92f28b237144c2fd.tar.bz2
get_oid(): when an object was not found, try harder
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-name.c')
-rw-r--r--sha1-name.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c1..cfe5c87 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;