]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-parse: add a --show-object-format option
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 28 Oct 2019 00:58:55 +0000 (00:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Oct 2019 02:34:57 +0000 (11:34 +0900)
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>
Documentation/git-rev-parse.txt
builtin/rev-parse.c
t/t1500-rev-parse.sh

index e72d332b8316763d40e7bcfe0e32bcaa61842cf8..9985477efe9c3e7defb639fa30517d0ea93eb7b6 100644 (file)
@@ -274,6 +274,13 @@ print a message to stderr and exit with nonzero status.
        Show the path to the shared index file in split index mode, or
        empty if not in split-index mode.
 
+--show-object-format[=(storage|input|output)]::
+       Show the object format (hash algorithm) used for the repository
+       for storage inside the `.git` directory, input, or output. For
+       input, multiple algorithms may be printed, space-separated.
+       If not specified, the default is "storage".
+
+
 Other Options
 ~~~~~~~~~~~~~
 
index f8bbe6d47ec397f55bec62d6a71bc6db8f08b54b..6c5d5d6a70f9c8834801dd309e111d72df2a3e31 100644 (file)
@@ -918,6 +918,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                show_datestring("--min-age=", arg);
                                continue;
                        }
+                       if (opt_with_value(arg, "--show-object-format", &arg)) {
+                               const char *val = arg ? arg : "storage";
+
+                               if (strcmp(val, "storage") &&
+                                   strcmp(val, "input") &&
+                                   strcmp(val, "output"))
+                                       die("unknown mode for --show-object-format: %s",
+                                           arg);
+                               puts(the_hash_algo->name);
+                               continue;
+                       }
                        if (show_flag(arg) && verify)
                                die_no_single_rev(quiet);
                        continue;
index 01abee533dedfd1e2d8bd347d06fc5c0c8b7833a..0177fd815c03d9f3dafeb99e3e915bd89ba714c2 100755 (executable)
@@ -59,6 +59,7 @@ test_rev_parse () {
 ROOT=$(pwd)
 
 test_expect_success 'setup' '
+       test_oid_init &&
        mkdir -p sub/dir work &&
        cp -R .git repo.git
 '
@@ -131,6 +132,20 @@ test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
        test_cmp expect actual
 '
 
+test_expect_success 'rev-parse --show-object-format in repo' '
+       echo "$(test_oid algo)" >expect &&
+       git rev-parse --show-object-format >actual &&
+       test_cmp expect actual &&
+       git rev-parse --show-object-format=storage >actual &&
+       test_cmp expect actual &&
+       git rev-parse --show-object-format=input >actual &&
+       test_cmp expect actual &&
+       git rev-parse --show-object-format=output >actual &&
+       test_cmp expect actual &&
+       test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
+       grep "unknown mode for --show-object-format: squeamish-ossifrage" err
+'
+
 test_expect_success 'showing the superproject correctly' '
        git rev-parse --show-superproject-working-tree >out &&
        test_must_be_empty out &&