rev-parse: allow printing compatibility hash
Right now, we have a way to print the storage hash, the input hash, and the output hash, but we lack a way to print the compatibility hash. Add a new type to --show-object-format, compat, which prints this value. If no compatibility hash exists, simply print a newline. This is important to allow users to use multiple options at once while still getting unambiguous output. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 9, 2025 at 21:56 UTC
b95c59e21e6afeddc56400e162e818a9312f04d2
3 files changed
+50
-6
Documentation/git-rev-parse.adoc
+6
-5
@@ -324,11 +324,12 @@ The following options are unaffected by `--path-format`:
324
path of the current directory relative to the top-level
325
directory.
326
327
---show-object-format[=(storage|input|output)]::
328
- Show the object format (hash algorithm) used for the repository
329
- for storage inside the `.git` directory, input, or output. For
330
- input, multiple algorithms may be printed, space-separated.
331
- If not specified, the default is "storage".
327
+--show-object-format[=(storage|input|output|compat)]::
328
+ Show the object format (hash algorithm) used for the repository for storage
329
+ inside the `.git` directory, input, output, or compatibility. For input,
330
+ multiple algorithms may be printed, space-separated. If `compat` is
331
+ requested and no compatibility algorithm is enabled, prints an empty line. If
332
+ not specified, the default is "storage".
333
334
--show-ref-format::
335
Show the reference storage format used for the repository.
builtin/rev-parse.c
+10
-1
@@ -1108,11 +1108,20 @@ int cmd_rev_parse(int argc,
1108
const char *val = arg ? arg : "storage";
1109
1110
if (strcmp(val, "storage") &&
1111
+ strcmp(val, "compat") &&
1112
strcmp(val, "input") &&
1113
strcmp(val, "output"))
1114
die(_("unknown mode for --show-object-format: %s"),
1115
arg);
1115
- puts(the_hash_algo->name);
1116
+
1117
+ if (!strcmp(val, "compat")) {
1118
+ if (the_repository->compat_hash_algo)
1119
+ puts(the_repository->compat_hash_algo->name);
1120
+ else
1121
+ putchar('\n');
1122
+ } else {
1123
+ puts(the_hash_algo->name);
1124
+ }
1125
continue;
1126
}
1127
if (!strcmp(arg, "--show-ref-format")) {
t/t1500-rev-parse.sh
+34
@@ -207,6 +207,40 @@ test_expect_success 'rev-parse --show-object-format in repo' '
207
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
208
'
209
210
+
211
+test_expect_success 'rev-parse --show-object-format in repo with compat mode' '
212
+ mkdir repo &&
213
+ (
214
+ sane_unset GIT_DEFAULT_HASH &&
215
+ cd repo &&
216
+ git init --object-format=sha256 &&
217
+ git config extensions.compatobjectformat sha1 &&
218
+ echo sha256 >expect &&
219
+ git rev-parse --show-object-format >actual &&
220
+ test_cmp expect actual &&
221
+ git rev-parse --show-object-format=storage >actual &&
222
+ test_cmp expect actual &&
223
+ git rev-parse --show-object-format=input >actual &&
224
+ test_cmp expect actual &&
225
+ git rev-parse --show-object-format=output >actual &&
226
+ test_cmp expect actual &&
227
+ echo sha1 >expect &&
228
+ git rev-parse --show-object-format=compat >actual &&
229
+ test_cmp expect actual &&
230
+ test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
231
+ grep "unknown mode for --show-object-format: squeamish-ossifrage" err
232
+ ) &&
233
+ mkdir repo2 &&
234
+ (
235
+ sane_unset GIT_DEFAULT_HASH &&
236
+ cd repo2 &&
237
+ git init --object-format=sha256 &&
238
+ echo >expect &&
239
+ git rev-parse --show-object-format=compat >actual &&
240
+ test_cmp expect actual
241
+ )
242
+'
243
+
244
test_expect_success 'rev-parse --show-ref-format' '
245
test_detect_ref_format >expect &&
246
git rev-parse --show-ref-format >actual &&