Skip to content

Commit

Permalink
index-pack: skip collision check when not in repository
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Dec 16, 2016
1 parent a3c45d1 commit 29401e1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
const unsigned char *sha1)
{
void *new_data = NULL;
int collision_test_needed;
int collision_test_needed = 0;

assert(data || obj_entry);

read_lock();
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
read_unlock();
if (startup_info->have_repository) {
read_lock();
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
read_unlock();
}

if (collision_test_needed && !data) {
read_lock();
Expand Down

0 comments on commit 29401e1

Please sign in to comment.