@matheusbsbs / matheus-bagliano / commits / a64d2aae5a
Fork 0

sha1-file: make pretend_object_file() not prefetch

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>

Jonathan Tan committed Jul 21, 2020 at 15:50 UTC a64d2aae5a593f4fb8b2020dc39556b256d1846e
2 files changed +13 -1
sha1-file.c
+2 -1
@@ -1589,7 +1589,8 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1589 struct cached_object *co;
1590
1591 hash_object_file(the_hash_algo, buf, len, type_name(type), oid);
1592 - if (has_object_file(oid) || find_cached_object(oid))
1592 + if (has_object_file_with_flags(oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) ||
1593 + find_cached_object(oid))
1594 return 0;
1595 ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
1596 co = &cached_objects[cached_object_nr++];
t/t8002-blame.sh
+11
@@ -122,4 +122,15 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
122 test_must_fail git blame --exclude-promisor-objects one
123 '
124
125 +test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
126 + git init server &&
127 + echo foo >server/file.txt &&
128 + git -C server add file.txt &&
129 + git -C server commit -m file &&
130 +
131 + git clone --filter=blob:none "file://$(pwd)/server" client &&
132 + echo bar >>client/file.txt &&
133 + git -C client blame file.txt
134 +'
135 +
136 test_done