Skip to content

Commit 2eabd38

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

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ print a message to stderr and exit with nonzero status.
274274
Show the path to the shared index file in split index mode, or
275275
empty if not in split-index mode.
276276

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+
277284
Other Options
278285
~~~~~~~~~~~~~
279286

builtin/rev-parse.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
918918
show_datestring("--min-age=", arg);
919919
continue;
920920
}
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+
}
921932
if (show_flag(arg) && verify)
922933
die_no_single_rev(quiet);
923934
continue;

t/t1500-rev-parse.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ test_rev_parse () {
5959
ROOT=$(pwd)
6060

6161
test_expect_success 'setup' '
62+
test_oid_init &&
6263
mkdir -p sub/dir work &&
6364
cp -R .git repo.git
6465
'
@@ -131,6 +132,20 @@ test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
131132
test_cmp expect actual
132133
'
133134

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+
134149
test_expect_success 'showing the superproject correctly' '
135150
git rev-parse --show-superproject-working-tree >out &&
136151
test_must_be_empty out &&

0 commit comments

Comments
 (0)