rev-parse: add a --show-object-format option
Add an option to print the object format used for input, output, or storage. This allows shell scripts to discover the hash algorithm in use. Since the transition plan allows for multiple input algorithms, document that we may provide multiple results for input, and the format that the results may take. While we don't support this now, documenting it early means that script authors can future-proof their scripts for when we do. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 28, 2019 at 00:58 UTC
2eabd383134b7dedbda0e8367ef3df63c67a0445
3 files changed
+33
Documentation/git-rev-parse.txt
+7
@@ -274,6 +274,13 @@ print a message to stderr and exit with nonzero status.
274
Show the path to the shared index file in split index mode, or
275
empty if not in split-index mode.
276
277
+--show-object-format[=(storage|input|output)]::
278
+ Show the object format (hash algorithm) used for the repository
279
+ for storage inside the `.git` directory, input, or output. For
280
+ input, multiple algorithms may be printed, space-separated.
281
+ If not specified, the default is "storage".
282
+
283
+
284
Other Options
285
~~~~~~~~~~~~~
286
builtin/rev-parse.c
+11
@@ -918,6 +918,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
918
show_datestring("--min-age=", arg);
919
continue;
920
}
921
+ if (opt_with_value(arg, "--show-object-format", &arg)) {
922
+ const char *val = arg ? arg : "storage";
923
+
924
+ if (strcmp(val, "storage") &&
925
+ strcmp(val, "input") &&
926
+ strcmp(val, "output"))
927
+ die("unknown mode for --show-object-format: %s",
928
+ arg);
929
+ puts(the_hash_algo->name);
930
+ continue;
931
+ }
932
if (show_flag(arg) && verify)
933
die_no_single_rev(quiet);
934
continue;
t/t1500-rev-parse.sh
+15
@@ -59,6 +59,7 @@ test_rev_parse () {
59
ROOT=$(pwd)
60
61
test_expect_success 'setup' '
62
+ test_oid_init &&
63
mkdir -p sub/dir work &&
64
cp -R .git repo.git
65
'
@@ -131,6 +132,20 @@ test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
132
test_cmp expect actual
133
'
134
135
+test_expect_success 'rev-parse --show-object-format in repo' '
136
+ echo "$(test_oid algo)" >expect &&
137
+ git rev-parse --show-object-format >actual &&
138
+ test_cmp expect actual &&
139
+ git rev-parse --show-object-format=storage >actual &&
140
+ test_cmp expect actual &&
141
+ git rev-parse --show-object-format=input >actual &&
142
+ test_cmp expect actual &&
143
+ git rev-parse --show-object-format=output >actual &&
144
+ test_cmp expect actual &&
145
+ test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
146
+ grep "unknown mode for --show-object-format: squeamish-ossifrage" err
147
+'
148
+
149
test_expect_success 'showing the superproject correctly' '
150
git rev-parse --show-superproject-working-tree >out &&
151
test_must_be_empty out &&