Skip to content

Commit 29401e1

Browse files
peffgitster
authored andcommitted
index-pack: skip collision check when not in repository
You can run "git index-pack path/to/foo.pack" outside of a repository to generate an index file, or just to verify the contents. There's no point in doing a collision check, since we obviously do not have any objects to collide with. The current code will blindly look in .git/objects based on the result of setup_git_env(). That effectively gives us the right answer (since we won't find any objects), but it's a waste of time, and it conflicts with our desire to eventually get rid of the "fallback to .git" behavior of setup_git_env(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3c45d1 commit 29401e1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

builtin/index-pack.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
787787
const unsigned char *sha1)
788788
{
789789
void *new_data = NULL;
790-
int collision_test_needed;
790+
int collision_test_needed = 0;
791791

792792
assert(data || obj_entry);
793793

794-
read_lock();
795-
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
796-
read_unlock();
794+
if (startup_info->have_repository) {
795+
read_lock();
796+
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
797+
read_unlock();
798+
}
797799

798800
if (collision_test_needed && !data) {
799801
read_lock();

0 commit comments

Comments
 (0)