Skip to content

Commit 712b351

Browse files
committed
Merge branch 'jk/index-pack-reduce-recheck'
Disable "have we lost a race with competing repack?" check while receiving a huge object transfer that runs index-pack. * jk/index-pack-reduce-recheck: index-pack: avoid excessive re-reading of pack directory
2 parents c595cb9 + 0eeb077 commit 712b351

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
786786
assert(data || obj_entry);
787787

788788
read_lock();
789-
collision_test_needed = has_sha1_file(sha1);
789+
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
790790
read_unlock();
791791

792792
if (collision_test_needed && !data) {

cache.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,17 @@ extern int has_sha1_pack(const unsigned char *sha1);
943943
* Return true iff we have an object named sha1, whether local or in
944944
* an alternate object database, and whether packed or loose. This
945945
* function does not respect replace references.
946+
*
947+
* If the QUICK flag is set, do not re-check the pack directory
948+
* when we cannot find the object (this means we may give a false
949+
* negative answer if another process is simultaneously repacking).
946950
*/
947-
extern int has_sha1_file(const unsigned char *sha1);
951+
#define HAS_SHA1_QUICK 0x1
952+
extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
953+
static inline int has_sha1_file(const unsigned char *sha1)
954+
{
955+
return has_sha1_file_with_flags(sha1, 0);
956+
}
948957

949958
/*
950959
* Return true iff an alternate object database has a loose object

sha1_file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,14 +3168,16 @@ int has_sha1_pack(const unsigned char *sha1)
31683168
return find_pack_entry(sha1, &e);
31693169
}
31703170

3171-
int has_sha1_file(const unsigned char *sha1)
3171+
int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
31723172
{
31733173
struct pack_entry e;
31743174

31753175
if (find_pack_entry(sha1, &e))
31763176
return 1;
31773177
if (has_loose_object(sha1))
31783178
return 1;
3179+
if (flags & HAS_SHA1_QUICK)
3180+
return 0;
31793181
reprepare_packed_git();
31803182
return find_pack_entry(sha1, &e);
31813183
}

0 commit comments

Comments
 (0)