From 7176a31444ce5ed683dbd75d2e1e2f89018d0100 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 Dec 2016 21:30:59 -0500 Subject: index-pack: complain when --stdin is used outside of a repo The index-pack builtin is marked as RUN_SETUP_GENTLY, because it's perfectly fine to index a pack in the filesystem outside of any repository. However, --stdin mode will write the result to the object database, which does not make sense outside of a repository. Doing so creates a bogus ".git" directory with nothing in it except the newly-created pack and its index. Instead, let's flag this as an error and abort. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin/index-pack.c') diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0a27bab11b..d450a6ada2 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1730,6 +1730,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) usage(index_pack_usage); if (fix_thin_pack && !from_stdin) die(_("--fix-thin cannot be used without --stdin")); + if (from_stdin && !startup_info->have_repository) + die(_("--stdin requires a git repository")); if (!index_name && pack_name) index_name = derive_filename(pack_name, ".idx", &index_name_buf); if (keep_msg && !keep_name && pack_name) -- cgit v1.2.3 From 29401e15754518a0e63e00d6cabc5a5f2f9b0973 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 16 Dec 2016 16:43:22 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'builtin/index-pack.c') diff --git a/builtin/index-pack.c b/builtin/index-pack.c index d450a6ada2..f4b87c6c9f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -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(); -- cgit v1.2.3