git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Stefan Beller <stefanbeller@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 03/15] rev-parse: add an --object-format option
Date: Sat,  5 Oct 2019 21:11:57 +0000	[thread overview]
Message-ID: <20191005211209.18237-4-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20191005211209.18237-1-sandals@crustytoothpaste.net>

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>
---
 Documentation/git-rev-parse.txt |  7 +++++++
 builtin/rev-parse.c             | 11 +++++++++++
 t/t1500-rev-parse.sh            | 15 +++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index e72d332b83..8a72190940 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -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.
 
+--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
 ~~~~~~~~~~~~~
 
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index f8bbe6d47e..8036219921 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -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, "--object-format", &arg)) {
+				const char *val = arg ? arg : "storage";
+
+				if (strcmp(val, "storage") &&
+				    strcmp(val, "input") &&
+				    strcmp(val, "output"))
+					die("unknown mode for --object-format: %s",
+					    arg);
+				puts(the_hash_algo->name);
+				continue;
+			}
 			if (show_flag(arg) && verify)
 				die_no_single_rev(quiet);
 			continue;
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 01abee533d..fb3d81df4c 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -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 --object-format in repo' '
+	echo "$(test_oid algo)" >expect &&
+	git rev-parse --object-format >actual &&
+	test_cmp expect actual &&
+	git rev-parse --object-format=storage >actual &&
+	test_cmp expect actual &&
+	git rev-parse --object-format=input >actual &&
+	test_cmp expect actual &&
+	git rev-parse --object-format=output >actual &&
+	test_cmp expect actual &&
+	test_must_fail git rev-parse --object-format=squeamish-ossifrage 2>err &&
+	grep "unknown mode for --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 &&

  parent reply	other threads:[~2019-10-05 21:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-05 21:11 [PATCH 00/15] SHA-256 test fixes, part 6 brian m. carlson
2019-10-05 21:11 ` [PATCH 01/15] t/oid-info: allow looking up hash algorithm name brian m. carlson
2019-10-05 21:11 ` [PATCH 02/15] t/oid-info: add empty tree and empty blob values brian m. carlson
2019-10-05 21:11 ` brian m. carlson [this message]
2019-10-08 11:51   ` [PATCH 03/15] rev-parse: add an --object-format option Derrick Stolee
2019-10-08 19:31     ` brian m. carlson
2019-10-05 21:11 ` [PATCH 04/15] t1305: avoid comparing extensions brian m. carlson
2019-10-05 21:11 ` [PATCH 05/15] t3429: remove SHA1 annotation brian m. carlson
2019-10-05 21:12 ` [PATCH 06/15] t4010: abstract away SHA-1-specific constants brian m. carlson
2019-10-05 21:12 ` [PATCH 07/15] t4011: " brian m. carlson
2019-10-08 12:21   ` Derrick Stolee
2019-10-08 12:33     ` Bert Wesarg
2019-10-08 12:38       ` Derrick Stolee
2019-10-08 19:40       ` brian m. carlson
2019-10-05 21:12 ` [PATCH 08/15] t4015: " brian m. carlson
2019-10-08 12:31   ` Derrick Stolee
2019-10-05 21:12 ` [PATCH 09/15] t4027: make hash-size independent brian m. carlson
2019-10-05 21:12 ` [PATCH 10/15] t4034: abstract away SHA-1-specific constants brian m. carlson
2019-10-05 21:12 ` [PATCH 11/15] t4038: abstract away SHA-1 specific constants brian m. carlson
2019-10-05 21:12 ` [PATCH 12/15] t4039: abstract away SHA-1-specific constants brian m. carlson
2019-10-05 21:12 ` [PATCH 13/15] t4044: update test to work with SHA-256 brian m. carlson
2019-10-05 21:12 ` [PATCH 14/15] t4045: make hash-size independent brian m. carlson
2019-10-05 21:12 ` [PATCH 15/15] t4048: abstract away SHA-1-specific constants brian m. carlson
2019-10-08 12:40 ` [PATCH 00/15] SHA-256 test fixes, part 6 Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191005211209.18237-4-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=stefanbeller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).