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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 16, 2016 at 16:43 UTC 29401e15754518a0e63e00d6cabc5a5f2f9b0973
1 file changed +6 -4
builtin/index-pack.c
+6 -4
@@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
787 const unsigned char *sha1)
788 {
789 void *new_data = NULL;
790 - int collision_test_needed;
790 + int collision_test_needed = 0;
791
792 assert(data || obj_entry);
793
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 + }
799
800 if (collision_test_needed && !data) {
801 read_lock();