diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2020-06-19 19:55:52 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-06-19 23:04:08 +0200 |
commit | 586740aa6e70013a837e0d9f3e0ea04c7f180fbd (patch) | |
tree | b2a857ee9fd89f8a1a42f18430652521f0327d59 /builtin/index-pack.c | |
parent | remote-curl: detect algorithm for dumb HTTP by size (diff) | |
download | git-586740aa6e70013a837e0d9f3e0ea04c7f180fbd.tar.xz git-586740aa6e70013a837e0d9f3e0ea04c7f180fbd.zip |
builtin/index-pack: add option to specify hash algorithm
git index-pack is usually run in a repository, but need not be. Since
packs don't contains information on the algorithm in use, instead
relying on context, add an option to index-pack to tell it which one
we're using in case someone runs it outside of a repository. Since
using --stdin necessarily implies a repository, don't allow specifying
an object format if it's provided to prevent users from passing an
option that won't work. Add documentation for this option.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r-- | builtin/index-pack.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 7bea1fba52..f865666db9 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1667,6 +1667,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) unsigned char pack_hash[GIT_MAX_RAWSZ]; unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */ int report_end_of_input = 0; + int hash_algo = 0; /* * index-pack never needs to fetch missing objects except when @@ -1760,6 +1761,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) die(_("bad %s"), arg); } else if (skip_prefix(arg, "--max-input-size=", &arg)) { max_input_size = strtoumax(arg, NULL, 10); + } else if (skip_prefix(arg, "--object-format=", &arg)) { + hash_algo = hash_algo_by_name(arg); + if (hash_algo == GIT_HASH_UNKNOWN) + die(_("unknown hash algorithm '%s'"), arg); + repo_set_hash_algo(the_repository, hash_algo); } else usage(index_pack_usage); continue; @@ -1776,6 +1782,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) die(_("--fix-thin cannot be used without --stdin")); if (from_stdin && !startup_info->have_repository) die(_("--stdin requires a git repository")); + if (from_stdin && hash_algo) + die(_("--object-format cannot be used with --stdin")); if (!index_name && pack_name) index_name = derive_filename(pack_name, "idx", &index_name_buf); |