Skip to content

Commit 586740a

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac093d0 commit 586740a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Documentation/git-index-pack.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ OPTIONS
9393
--max-input-size=<size>::
9494
Die, if the pack is larger than <size>.
9595

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+
96104
NOTES
97105
-----
98106

builtin/index-pack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
16671667
unsigned char pack_hash[GIT_MAX_RAWSZ];
16681668
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
16691669
int report_end_of_input = 0;
1670+
int hash_algo = 0;
16701671

16711672
/*
16721673
* 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)
17601761
die(_("bad %s"), arg);
17611762
} else if (skip_prefix(arg, "--max-input-size=", &arg)) {
17621763
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);
17631769
} else
17641770
usage(index_pack_usage);
17651771
continue;
@@ -1776,6 +1782,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17761782
die(_("--fix-thin cannot be used without --stdin"));
17771783
if (from_stdin && !startup_info->have_repository)
17781784
die(_("--stdin requires a git repository"));
1785+
if (from_stdin && hash_algo)
1786+
die(_("--object-format cannot be used with --stdin"));
17791787
if (!index_name && pack_name)
17801788
index_name = derive_filename(pack_name, "idx", &index_name_buf);
17811789

0 commit comments

Comments
 (0)