]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sha1-file: make pretend_object_file() not prefetch
authorJonathan Tan <jonathantanmy@google.com>
Tue, 21 Jul 2020 22:50:20 +0000 (15:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Jul 2020 23:27:22 +0000 (16:27 -0700)
When pretend_object_file() is invoked with an object that does not exist
(as is the typical case), there is no need to fetch anything from the
promisor remote, because the caller already knows what the object is
supposed to contain. Therefore, suppress the fetch. (The
OBJECT_INFO_QUICK flag is added for the same reason.)

This was noticed at $DAYJOB when "blame" was run on a file that had
uncommitted modifications.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1-file.c
t/t8002-blame.sh

index 616886799e5906988ac4834d71cd259ee1e540a8..60765dbaa0c53c4a3514eedf7beee9e1d09425a1 100644 (file)
@@ -1589,7 +1589,8 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
        struct cached_object *co;
 
        hash_object_file(the_hash_algo, buf, len, type_name(type), oid);
-       if (has_object_file(oid) || find_cached_object(oid))
+       if (has_object_file_with_flags(oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) ||
+           find_cached_object(oid))
                return 0;
        ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
        co = &cached_objects[cached_object_nr++];
index eea048e52ceb328fd5d97b17e996c8f821ae4abb..2ed6aaae35e9ed2615ef5255f22d994b9f2b6f1a 100755 (executable)
@@ -122,4 +122,15 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
        test_must_fail git blame --exclude-promisor-objects one
 '
 
+test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
+       git init server &&
+       echo foo >server/file.txt &&
+       git -C server add file.txt &&
+       git -C server commit -m file &&
+
+       git clone --filter=blob:none "file://$(pwd)/server" client &&
+       echo bar >>client/file.txt &&
+       git -C client blame file.txt
+'
+
 test_done