Skip to content

Commit de62fe8

Browse files
committed
Merge branch 'jk/index-pack-reduce-recheck' into maint
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 bb3e7b1 + 0eeb077 commit de62fe8

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
@@ -730,7 +730,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
730730
assert(data || obj_entry);
731731

732732
read_lock();
733-
collision_test_needed = has_sha1_file(sha1);
733+
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
734734
read_unlock();
735735

736736
if (collision_test_needed && !data) {

cache.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,17 @@ extern int has_sha1_pack(const unsigned char *sha1);
901901
* Return true iff we have an object named sha1, whether local or in
902902
* an alternate object database, and whether packed or loose. This
903903
* function does not respect replace references.
904+
*
905+
* If the QUICK flag is set, do not re-check the pack directory
906+
* when we cannot find the object (this means we may give a false
907+
* negative answer if another process is simultaneously repacking).
904908
*/
905-
extern int has_sha1_file(const unsigned char *sha1);
909+
#define HAS_SHA1_QUICK 0x1
910+
extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
911+
static inline int has_sha1_file(const unsigned char *sha1)
912+
{
913+
return has_sha1_file_with_flags(sha1, 0);
914+
}
906915

907916
/*
908917
* 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
@@ -3084,14 +3084,16 @@ int has_sha1_pack(const unsigned char *sha1)
30843084
return find_pack_entry(sha1, &e);
30853085
}
30863086

3087-
int has_sha1_file(const unsigned char *sha1)
3087+
int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
30883088
{
30893089
struct pack_entry e;
30903090

30913091
if (find_pack_entry(sha1, &e))
30923092
return 1;
30933093
if (has_loose_object(sha1))
30943094
return 1;
3095+
if (flags & HAS_SHA1_QUICK)
3096+
return 0;
30953097
reprepare_packed_git();
30963098
return find_pack_entry(sha1, &e);
30973099
}

0 commit comments

Comments
 (0)