Skip to content

Commit b95c59e

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

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

Documentation/git-rev-parse.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ The following options are unaffected by `--path-format`:
324324
path of the current directory relative to the top-level
325325
directory.
326326

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".
332333

333334
--show-ref-format::
334335
Show the reference storage format used for the repository.

builtin/rev-parse.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,11 +1108,20 @@ int cmd_rev_parse(int argc,
11081108
const char *val = arg ? arg : "storage";
11091109

11101110
if (strcmp(val, "storage") &&
1111+
strcmp(val, "compat") &&
11111112
strcmp(val, "input") &&
11121113
strcmp(val, "output"))
11131114
die(_("unknown mode for --show-object-format: %s"),
11141115
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+
}
11161125
continue;
11171126
}
11181127
if (!strcmp(arg, "--show-ref-format")) {

t/t1500-rev-parse.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,40 @@ test_expect_success 'rev-parse --show-object-format in repo' '
207207
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
208208
'
209209

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+
210244
test_expect_success 'rev-parse --show-ref-format' '
211245
test_detect_ref_format >expect &&
212246
git rev-parse --show-ref-format >actual &&

0 commit comments

Comments
 (0)