diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-01-18 00:11:06 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-01-18 00:11:06 +0100 |
commit | b984bc58ce4e67de7e7f1b360c9e153fb6398bca (patch) | |
tree | 6d8f8e68cd612133020725788345866b336a88be /builtin | |
parent | Merge branch 'jk/parseopt-usage-msg-opt' into maint (diff) | |
parent | index-pack: skip collision check when not in repository (diff) | |
download | git-b984bc58ce4e67de7e7f1b360c9e153fb6398bca.tar.xz git-b984bc58ce4e67de7e7f1b360c9e153fb6398bca.zip |
Merge branch 'jk/index-pack-wo-repo-from-stdin' into maint
"git index-pack --stdin" needs an access to an existing repository,
but "git index-pack file.pack" to generate an .idx file that
corresponds to a packfile does not.
* jk/index-pack-wo-repo-from-stdin:
index-pack: skip collision check when not in repository
t: use nongit() function where applicable
index-pack: complain when --stdin is used outside of a repo
t5000: extract nongit function to test-lib-functions.sh
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/index-pack.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0a27bab11b..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(); @@ -1730,6 +1732,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) |