@matheusbsbs / matheus-bagliano / commits / 586740aa6e
Fork 0

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>

brian m. carlson committed Jun 19, 2020 at 17:55 UTC 586740aa6e70013a837e0d9f3e0ea04c7f180fbd
2 files changed +16
Documentation/git-index-pack.txt
+8
@@ -93,6 +93,14 @@ OPTIONS
93 --max-input-size=<size>::
94 Die, if the pack is larger than <size>.
95
96 +--object-format=<hash-algorithm>::
97 + Specify the given object format (hash algorithm) for the pack. The valid
98 + values are 'sha1' and (if enabled) 'sha256'. The default is the algorithm for
99 + the current repository (set by `extensions.objectFormat`), or 'sha1' if no
100 + value is set or outside a repository.
101 ++
102 +This option cannot be used with --stdin.
103 +
104 NOTES
105 -----
106
builtin/index-pack.c
+8
@@ -1667,6 +1667,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1667 unsigned char pack_hash[GIT_MAX_RAWSZ];
1668 unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
1669 int report_end_of_input = 0;
1670 + int hash_algo = 0;
1671
1672 /*
1673 * 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)
1761 die(_("bad %s"), arg);
1762 } else if (skip_prefix(arg, "--max-input-size=", &arg)) {
1763 max_input_size = strtoumax(arg, NULL, 10);
1764 + } else if (skip_prefix(arg, "--object-format=", &arg)) {
1765 + hash_algo = hash_algo_by_name(arg);
1766 + if (hash_algo == GIT_HASH_UNKNOWN)
1767 + die(_("unknown hash algorithm '%s'"), arg);
1768 + repo_set_hash_algo(the_repository, hash_algo);
1769 } else
1770 usage(index_pack_usage);
1771 continue;
@@ -1776,6 +1782,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1782 die(_("--fix-thin cannot be used without --stdin"));
1783 if (from_stdin && !startup_info->have_repository)
1784 die(_("--stdin requires a git repository"));
1785 + if (from_stdin && hash_algo)
1786 + die(_("--object-format cannot be used with --stdin"));
1787 if (!index_name && pack_name)
1788 index_name = derive_filename(pack_name, "idx", &index_name_buf);
1789