]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/index-pack: add option to specify hash algorithm
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 19 Jun 2020 17:55:52 +0000 (17:55 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Jun 2020 21:04:08 +0000 (14:04 -0700)
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>
Documentation/git-index-pack.txt
builtin/index-pack.c

index d5b7560bfe2d51370c313ee006a9f0ed4388eda4..9316d9a80b0d7bb5f83f80400585fe7cb22dc723 100644 (file)
@@ -93,6 +93,14 @@ OPTIONS
 --max-input-size=<size>::
        Die, if the pack is larger than <size>.
 
+--object-format=<hash-algorithm>::
+       Specify the given object format (hash algorithm) for the pack.  The valid
+       values are 'sha1' and (if enabled) 'sha256'.  The default is the algorithm for
+       the current repository (set by `extensions.objectFormat`), or 'sha1' if no
+       value is set or outside a repository.
++
+This option cannot be used with --stdin.
+
 NOTES
 -----
 
index 7bea1fba52a9d3762ffb376f35f4773117fa4f4e..f865666db9ee62ba0b1dd60111912b233df47d7c 100644 (file)
@@ -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);