]> git.ipfire.org Git - thirdparty/git.git/commitdiff
get_oid(): when an object was not found, try harder
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 13 Mar 2019 10:16:34 +0000 (03:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Mar 2019 03:46:29 +0000 (12:46 +0900)
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>
sha1-name.c
t/t3429-rebase-edit-todo.sh

index 6dda2c16df1026e50b7d9be255b6bbfc4e92725c..cfe5c874b6f06361b444ec897fddcc36e19979f3 100644 (file)
@@ -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;
 
index 862f229c875211cf0b45d7691b71c626468d37fc..76f6d306eaf39e9727bfeb3dbb04aa3c3941cf1d 100755 (executable)
@@ -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 &&