git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/39] SHA-256, part 3/3
@ 2020-07-23  1:09 brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 01/39] t: make test-bloom initialize repository brian m. carlson
                   ` (38 more replies)
  0 siblings, 39 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

This is the final part required for the stage 4 implementation of
SHA-256.

Changes from v2:
* Move bundle signature parsing into a function.
* Improve parsing of bundle capabilities.
* Improve t5510 to select only the interesting lines with sed.
* Use cat and a heredoc instead of multiple echos.
* Use test_i18ngrep where appropriate.
* Reject extensions.objectFormat for repo v0.
* Update documentation accordingly.

Changes from v1:
* Add a patch to add a bundle v3 format with capabilities that include
  the hash algorithm.
* Remove bundle detection of hash algorithm using hash algorithm length.
* Fix typo in the extensions.objectFormat documentation.
* Document that extensions.objectFormat is ignored for repo v0.
* Use test instead of brackets.
* Use a command group instead of a subshell for efficiency.
* Drop the bizarre test_might_fail, since it isn't needed (and is
  bizarre and wrong).
* Write "SHA-256" instead of "NewHash" in commit messages.
* Split SHA-256 CI tests to an independent run and avoid running a third
  test run to a single CI job.

Johannes Schindelin (1):
  t3404: prepare 'short SHA-1 collision' tests for SHA-256

brian m. carlson (38):
  t: make test-bloom initialize repository
  t1001: use $ZERO_OID
  t3305: make hash agnostic
  t6100: make hash size independent
  t6101: make hash size independent
  t6301: make hash size independent
  t6500: specify test values for SHA-256
  t6501: avoid hard-coded objects
  t7003: compute appropriate length constant
  t7063: make hash size independent
  t7201: abstract away SHA-1-specific constants
  t7102: abstract away SHA-1-specific constants
  t7400: make hash size independent
  t7405: make hash size independent
  t7506: avoid checking for SHA-1-specific constants
  t7508: use $ZERO_OID instead of hard-coded constant
  t8002: make hash size independent
  t8003: make hash size independent
  t8011: make hash size independent
  t9300: abstract away SHA-1-specific constants
  t9300: use $ZERO_OID instead of hard-coded object ID
  t9301: make hash size independent
  t9350: make hash size independent
  t9500: ensure that algorithm info is preserved in config
  t9700: make hash size independent
  t5308: make test work with SHA-256
  t0410: mark test with SHA1 prerequisite
  http-fetch: set up git directory before parsing pack hashes
  builtin/verify-pack: implement an --object-format option
  bundle: add new version for use with SHA-256
  setup: add support for reading extensions.objectformat
  Enable SHA-256 support by default
  t: add test_oid option to select hash algorithm
  t: allow testing different hash algorithms via environment
  t: make SHA1 prerequisite depend on default hash
  ci: run tests with SHA-256
  docs: add documentation for extensions.objectFormat
  t: remove test_oid_init in tests

 Documentation/config.txt                  |   2 +
 Documentation/config/extensions.txt       |   8 ++
 Documentation/git-bundle.txt              |   9 +-
 Documentation/technical/bundle-format.txt |  30 ++++-
 builtin/bundle.c                          |   5 +-
 builtin/init-db.c                         |   5 -
 builtin/verify-pack.c                     |  25 ++--
 bundle.c                                  |  85 ++++++++----
 bundle.h                                  |   4 +-
 ci/run-build-and-tests.sh                 |   5 +
 config.mak.dev                            |   2 -
 http-fetch.c                              |   4 +-
 repository.c                              |   4 -
 setup.c                                   |  16 ++-
 t/helper/test-bloom.c                     |   2 +
 t/lib-pack.sh                             |  11 +-
 t/lib-submodule-update.sh                 |   1 -
 t/t0000-basic.sh                          |  15 ++-
 t/t0001-init.sh                           |  29 +++++
 t/t0410-partial-clone.sh                  |   4 +-
 t/t1006-cat-file.sh                       |   2 -
 t/t1050-large.sh                          |   1 -
 t/t1091-sparse-checkout-builtin.sh        |   4 +-
 t/t1410-reflog.sh                         |   1 -
 t/t1450-fsck.sh                           |   1 -
 t/t1500-rev-parse.sh                      |   1 -
 t/t3305-notes-fanout.sh                   |   2 +-
 t/t3308-notes-merge.sh                    |   1 -
 t/t3404-rebase-interactive.sh             |  49 +++++--
 t/t3600-rm.sh                             |   1 -
 t/t3800-mktag.sh                          |   1 -
 t/t4002-diff-basic.sh                     |   2 -
 t/t4027-diff-submodule.sh                 |   1 -
 t/t4134-apply-submodule.sh                |   1 -
 t/t4200-rerere.sh                         |   1 -
 t/t4211-line-log.sh                       |   1 -
 t/t5300-pack-object.sh                    |   3 +-
 t/t5302-pack-index.sh                     |   1 -
 t/t5308-pack-detect-duplicates.sh         |  20 +--
 t/t5313-pack-bounds-checks.sh             |   1 -
 t/t5318-commit-graph.sh                   |   3 +-
 t/t5319-multi-pack-index.sh               |   1 -
 t/t5324-split-commit-graph.sh             |   1 -
 t/t5504-fetch-receive-strict.sh           |   1 -
 t/t5510-fetch.sh                          |  11 +-
 t/t5530-upload-pack-error.sh              |   1 -
 t/t5562-http-backend-content-length.sh    |   1 -
 t/t5607-clone-bundle.sh                   |  29 +++++
 t/t5702-protocol-v2.sh                    |   3 +-
 t/t5703-upload-pack-ref-in-want.sh        |   1 -
 t/t6006-rev-list-format.sh                |   1 -
 t/t6100-rev-list-in-order.sh              |   4 +-
 t/t6101-rev-parse-parents.sh              |   2 +-
 t/t6301-for-each-ref-errors.sh            |   2 +-
 t/t6500-gc.sh                             |  27 +++-
 t/t6501-freshen-objects.sh                |  14 +-
 t/t7003-filter-branch.sh                  |   3 +-
 t/t7063-status-untracked-cache.sh         | 151 ++++++++++++----------
 t/t7102-reset.sh                          |  93 +++++++------
 t/t7201-co.sh                             |   5 +-
 t/t7400-submodule-basic.sh                |  26 ++--
 t/t7405-submodule-merge.sh                |   4 +-
 t/t7506-status-submodule.sh               |  12 +-
 t/t7508-status.sh                         |   2 +-
 t/t8002-blame.sh                          |  15 ++-
 t/t8003-blame-corner-cases.sh             |   3 +-
 t/t8011-blame-split-file.sh               |   2 +-
 t/t9300-fast-import.sh                    | 117 +++++++++--------
 t/t9301-fast-import-notes.sh              |  13 +-
 t/t9350-fast-export.sh                    |  15 +--
 t/t9500-gitweb-standalone-no-errors.sh    |  22 +++-
 t/t9700/test.pl                           |   6 +-
 t/test-lib-functions.sh                   |  16 ++-
 t/test-lib.sh                             |   6 +-
 74 files changed, 620 insertions(+), 354 deletions(-)
 create mode 100644 Documentation/config/extensions.txt

Range-diff against v2:
 1:  11bb3918df =  1:  792a7e6b99 t: make test-bloom initialize repository
 2:  bff32965d2 =  2:  652259edaa t1001: use $ZERO_OID
 3:  03f49899e0 =  3:  b719726393 t3305: make hash agnostic
 4:  d6c75da18f =  4:  137c86a4e0 t3404: prepare 'short SHA-1 collision' tests for SHA-256
 5:  31cbce9d44 =  5:  307b90fa2a t6100: make hash size independent
 6:  bc21adaf33 =  6:  f5f4028291 t6101: make hash size independent
 7:  31a1c614cf =  7:  654b95494c t6301: make hash size independent
 8:  4c19b39507 =  8:  787bde1ffc t6500: specify test values for SHA-256
 9:  cd43450d20 =  9:  b63ed599fe t6501: avoid hard-coded objects
10:  2f7ef3bd9d = 10:  40847a1490 t7003: compute appropriate length constant
11:  96b29887b0 = 11:  3dbd65993c t7063: make hash size independent
12:  d67c1e49d0 = 12:  bba7969017 t7201: abstract away SHA-1-specific constants
13:  48b254250b = 13:  bf5d06f1fc t7102: abstract away SHA-1-specific constants
14:  cfc96d8181 = 14:  a272eafa86 t7400: make hash size independent
15:  187f3bf5c1 = 15:  4dc14d1ded t7405: make hash size independent
16:  0d91991588 = 16:  f291df2f20 t7506: avoid checking for SHA-1-specific constants
17:  e22ec03788 = 17:  ded35216ce t7508: use $ZERO_OID instead of hard-coded constant
18:  bfd9a593a7 = 18:  a197d7f09a t8002: make hash size independent
19:  d4ca86e473 = 19:  7c49d9a8e8 t8003: make hash size independent
20:  28d1b7bf0b = 20:  4ab13f691a t8011: make hash size independent
21:  c982602ffa = 21:  81edf64b72 t9300: abstract away SHA-1-specific constants
22:  503be79740 = 22:  d8253d9aca t9300: use $ZERO_OID instead of hard-coded object ID
23:  bdede03ff0 = 23:  7b40da5753 t9301: make hash size independent
24:  a50d67d7bd = 24:  1890f22a5b t9350: make hash size independent
25:  acea64aa18 = 25:  708f599a71 t9500: ensure that algorithm info is preserved in config
26:  0b5bb05dea = 26:  33c84a2bc6 t9700: make hash size independent
27:  41a1e3a78f = 27:  3d7476f28b t5308: make test work with SHA-256
28:  70f77a2508 <  -:  ---------- t0410: mark test with SHA1 prerequisite
 -:  ---------- > 28:  0d80e419e5 t0410: mark test with SHA1 prerequisite
29:  1c619ed160 = 29:  bd812fb0e4 http-fetch: set up git directory before parsing pack hashes
30:  cd643a0b1d = 30:  667537e1aa builtin/verify-pack: implement an --object-format option
31:  611ad8ffd0 ! 31:  acdf1d9009 bundle: add new version for use with SHA-256
    @@ Commit message
         for SHA-256.
     
         In t5510, always use format v3 so we can be sure we produce consistent
    -    results across hash algorithms.
    +    results across hash algorithms.  Note here that head -n N lists the top
    +    N lines, whereas we want to check only the given line, so while we're at
    +    it, switch to use sed to make sure we're checking only the line we care
    +    about for a match.
     
         Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
     
    @@ bundle.c
      #include "argv-array.h"
      
     -static const char bundle_signature[] = "# v2 git bundle\n";
    ++
     +static const char v2_bundle_signature[] = "# v2 git bundle\n";
     +static const char v3_bundle_signature[] = "# v3 git bundle\n";
    ++static struct {
    ++	int version;
    ++	const char *signature;
    ++} bundle_sigs[] = {
    ++	{ 2, v2_bundle_signature },
    ++	{ 3, v3_bundle_signature },
    ++};
      
      static void add_to_ref_list(const struct object_id *oid, const char *name,
      		struct ref_list *list)
    @@ bundle.c: static void add_to_ref_list(const struct object_id *oid, const char *n
      {
     -	size_t len = strcspn(buf->buf, " \n");
     -	int algo;
    --
    --	algo = hash_algo_by_length(len / 2);
    --	if (algo == GIT_HASH_UNKNOWN)
    --		return NULL;
    --	return &hash_algos[algo];
     +	const char *arg;
     +	if (skip_prefix(capability, "object-format=", &arg)) {
     +		int algo = hash_algo_by_name(arg);
    @@ bundle.c: static void add_to_ref_list(const struct object_id *oid, const char *n
     +		return 0;
     +	}
     +	return error(_("unknown capability '%s'"), capability);
    ++}
    + 
    +-	algo = hash_algo_by_length(len / 2);
    +-	if (algo == GIT_HASH_UNKNOWN)
    +-		return NULL;
    +-	return &hash_algos[algo];
    ++static int parse_bundle_signature(struct bundle_header *header, const char *line)
    ++{
    ++	int i;
    ++
    ++	for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) {
    ++		if (!strcmp(line, bundle_sigs[i].signature)) {
    ++			header->version = bundle_sigs[i].version;
    ++			return 0;
    ++		}
    ++	}
    ++	return -1;
      }
      
    -+
      static int parse_bundle_header(int fd, struct bundle_header *header,
    - 			       const char *report_path)
    - {
     @@ bundle.c: static int parse_bundle_header(int fd, struct bundle_header *header,
      
      	/* The bundle header begins with the signature */
      	if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
     -	    strcmp(buf.buf, bundle_signature)) {
    -+	    (strcmp(buf.buf, v2_bundle_signature) &&
    -+	     strcmp(buf.buf, v3_bundle_signature))) {
    ++	    parse_bundle_signature(header, buf.buf)) {
      		if (report_path)
     -			error(_("'%s' does not look like a v2 bundle file"),
     +			error(_("'%s' does not look like a v2 or v3 bundle file"),
    @@ bundle.c: static int parse_bundle_header(int fd, struct bundle_header *header,
      		goto abort;
      	}
      
    -+	header->version = buf.buf[3] - '0';
     +	header->hash_algo = the_hash_algo;
     +
      	/* The bundle header ends with an empty line */
    @@ bundle.c: static int parse_bundle_header(int fd, struct bundle_header *header,
      		const char *p;
      
     +		if (header->version == 3 && *buf.buf == '@') {
    -+			buf.buf[buf.len - 1] = '\0';
    ++			buf.buf[--buf.len] = '\0';
     +			if (parse_capability(header, buf.buf + 1)) {
     +				status = -1;
     +				break;
    @@ t/t5510-fetch.sh: test_expect_success 'create bundle 1' '
      
      test_expect_success 'header of bundle looks right' '
      	head -n 4 "$D"/bundle1 &&
    - 	head -n 1 "$D"/bundle1 | grep "^#" &&
    +-	head -n 1 "$D"/bundle1 | grep "^#" &&
     -	head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
     -	head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
     -	head -n 4 "$D"/bundle1 | grep "^$"
    -+	head -n 2 "$D"/bundle1 | grep "^@object-format=" &&
    -+	head -n 3 "$D"/bundle1 | grep "^-$OID_REGEX " &&
    -+	head -n 4 "$D"/bundle1 | grep "^$OID_REGEX " &&
    -+	head -n 5 "$D"/bundle1 | grep "^$"
    ++	sed -n -e 1p "$D"/bundle1 | grep "^#" &&
    ++	sed -n -e 2p "$D"/bundle1 | grep "^@object-format=" &&
    ++	sed -n -e 3p "$D"/bundle1 | grep "^-$OID_REGEX " &&
    ++	sed -n -e 4p "$D"/bundle1 | grep "^$OID_REGEX " &&
    ++	sed -n -e 5p "$D"/bundle1 | grep "^$"
      '
      
      test_expect_success 'create bundle 2' '
    @@ t/t5607-clone-bundle.sh: test_expect_success 'fetch SHA-1 from bundle' '
     +	git branch side HEAD &&
     +	git bundle create --version=3 bundle HEAD^..side &&
     +	head -n2 bundle >actual &&
    -+	echo "# v3 git bundle" >expected &&
    -+	echo "@object-format=$(test_oid algo)" >>expected &&
    -+	test_cmp actual expected &&
    ++	cat >expect <<-EOF &&
    ++	# v3 git bundle
    ++	@object-format=$(test_oid algo)
    ++	EOF
    ++	test_cmp actual expect &&
     +	git bundle verify bundle
     +'
     +
     +test_expect_success 'git bundle v3 rejects unknown extensions' '
     +	head -n2 bundle >new &&
     +	echo "@unknown=silly" >>new &&
    -+	sed "1,2d" >>new &&
    ++	sed "1,2d" bundle >>new &&
     +	test_must_fail git bundle verify new 2>output &&
    -+	grep "unknown capability .unknown=silly." output
    ++	test_i18ngrep "unknown capability .unknown=silly." output
     +'
     +
      test_done
32:  f299f46406 ! 32:  65310eaf1b setup: add support for reading extensions.objectformat
    @@ Commit message
         the extensions we support.  If the user has specified an invalid value,
         fail.
     
    -    Ensure that we don't use the value of the extension if the repository
    -    format version is 0.
    +    Ensure that we reject the extension if the repository format version is
    +    0.
     
         Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
     
    @@ setup.c: static int check_repo_format(const char *var, const char *value, void *
      			string_list_append(&data->unknown_extensions, ext);
      	}
      
    -@@ setup.c: static int check_repository_format_gently(const char *gitdir, struct repository_
    - 		repository_format_precious_objects = 0;
    - 		set_repository_format_partial_clone(NULL);
    - 		repository_format_worktree_config = 0;
    -+		candidate->hash_algo = GIT_HASH_SHA1;
    +@@ setup.c: int verify_repository_format(const struct repository_format *format,
    + 		return -1;
      	}
    - 	string_list_clear(&candidate->unknown_extensions, 0);
    + 
    ++	if (format->version <= 0 && format->hash_algo != GIT_HASH_SHA1) {
    ++		strbuf_addstr(err, _("extensions.objectFormat is not valid in repo v0"));
    ++		return -1;
    ++	}
    ++
    + 	return 0;
    + }
      
33:  59652ad4e7 ! 33:  f69cf8b1b5 Enable SHA-256 support by default
    @@ t/t0001-init.sh: test_expect_success 're-init from a linked worktree' '
     +	test_cmp expected actual
     +'
     +
    -+test_expect_success 'extensions.objectFormat is not honored with repo version 0' '
    ++test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
     +	git init --object-format=sha256 explicit-v0 &&
    -+	test_config -C explicit-v0 core.repositoryformatversion 0 &&
    -+	git -C explicit-v0 rev-parse --show-object-format >actual &&
    -+	echo sha1 >expected &&
    -+	test_cmp expected actual
    ++	git -C explicit-v0 config core.repositoryformatversion 0 &&
    ++	test_must_fail git -C explicit-v0 rev-parse --show-object-format
     +'
     +
     +test_expect_success 'init rejects attempts to initialize with different hash' '
34:  90d38c1f09 = 34:  e41d139b78 t: add test_oid option to select hash algorithm
35:  8eb68c2895 = 35:  20dbc5ff66 t: allow testing different hash algorithms via environment
36:  b0b832f3d8 = 36:  4ee7f9eec8 t: make SHA1 prerequisite depend on default hash
37:  f6fdad20d2 = 37:  0080a96f7b ci: run tests with SHA-256
38:  dce20fcd6e ! 38:  03e1203a08 docs: add documentation for extensions.objectFormat
    @@ Documentation/config/extensions.txt (new)
     @@
     +extensions.objectFormat::
     +	Specify the hash algorithm to use.  The acceptable values are `sha1` and
    -+	`sha256`.  If not specified, `sha1` is assumed.  As with other keys under
    -+	the `extensions` hierarchy, this value is ignored and has no effect unless
    -+	`core.repositoryformatversion` is 1.
    ++	`sha256`.  If not specified, `sha1` is assumed.  It is an error to specify
    ++	this key unless `core.repositoryformatversion` is 1.
     ++
     +Note that this setting should only be set by linkgit:git-init[1] or
     +linkgit:git-clone[1].  Trying to change it after initialization will not
39:  42d1c5b8d1 = 39:  fbc015258f t: remove test_oid_init in tests

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH v3 01/39] t: make test-bloom initialize repository
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 02/39] t1001: use $ZERO_OID brian m. carlson
                   ` (37 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

The bloom filter code relies on reading object IDs using parse_oid_hex.
In order to make that work with an appropriate size, we need to have
initialized the repository's hash algorithm.  Since the values we're
processing depend on the repository in use, let's set up the repository
when we run the test helper.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/helper/test-bloom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index f0aa80b98e..5e77d56f59 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -50,6 +50,8 @@ static const char *bloom_usage = "\n"
 
 int cmd__bloom(int argc, const char **argv)
 {
+	setup_git_directory();
+
 	if (argc < 2)
 		usage(bloom_usage);
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 02/39] t1001: use $ZERO_OID
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 01/39] t: make test-bloom initialize repository brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 03/39] t3305: make hash agnostic brian m. carlson
                   ` (36 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Use $ZERO_OID to make the test hash independent.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t1091-sparse-checkout-builtin.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 7cd45fc139..84acfc48b6 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -369,7 +369,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat
 	git clone repo unmerged &&
 
 	cat >input <<-EOF &&
-	0 0000000000000000000000000000000000000000	folder1/a
+	0 $ZERO_OID	folder1/a
 	100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1	folder1/a
 	EOF
 	git -C unmerged update-index --index-info <input &&
@@ -396,7 +396,7 @@ test_expect_success 'sparse-checkout reapply' '
 	echo dirty >tweak/deep/deeper2/a &&
 
 	cat >input <<-EOF &&
-	0 0000000000000000000000000000000000000000	folder1/a
+	0 $ZERO_OID	folder1/a
 	100644 $(git -C tweak rev-parse HEAD:folder1/a) 1	folder1/a
 	EOF
 	git -C tweak update-index --index-info <input &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 03/39] t3305: make hash agnostic
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 01/39] t: make test-bloom initialize repository brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 02/39] t1001: use $ZERO_OID brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 04/39] t3404: prepare 'short SHA-1 collision' tests for SHA-256 brian m. carlson
                   ` (35 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

When computing the fanout length, let's use test_oid to look up the
hexadecimal size of the hash in question instead of hard-coding a value.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t3305-notes-fanout.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh
index 3b4753e1b4..d5a94b7174 100755
--- a/t/t3305-notes-fanout.sh
+++ b/t/t3305-notes-fanout.sh
@@ -7,7 +7,7 @@ test_description='Test that adding/removing many notes triggers automatic fanout
 path_has_fanout() {
 	path=$1 &&
 	fanout=$2 &&
-	after_last_slash=$((40 - $fanout * 2)) &&
+	after_last_slash=$(($(test_oid hexsz) - $fanout * 2)) &&
 	echo $path | grep -q "^\([0-9a-f]\{2\}/\)\{$fanout\}[0-9a-f]\{$after_last_slash\}$"
 }
 
@@ -31,6 +31,7 @@ all_notes_have_fanout() {
 }
 
 test_expect_success 'tweak test environment' '
+	test_oid_init &&
 	git checkout -b nondeterminism &&
 	test_commit A &&
 	git checkout --orphan with_notes;

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 04/39] t3404: prepare 'short SHA-1 collision' tests for SHA-256
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (2 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 03/39] t3305: make hash agnostic brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 05/39] t6100: make hash size independent brian m. carlson
                   ` (34 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

From: Johannes Schindelin <johannes.schindelin@gmx.de>

The idea of the magic value "ac4f2ee" in this test is to make the
reworded commit `collide2` have the same shortened ID as the commit
`collide3`.

To port the same idea to the SHA-256 version of Git, we therefore need
another magic value that causes the same collision, but this time with
the SHA-256 version of the commit IDs.

In this patch, we add code guarded by `GIT_TEST_FIND_COLLIDER` to do
exactly that. Essentially, a large number of integers is appended to the
commit message "collide2" to find such a collision. To make it easier to
find such a collision, we reduce the number of digits to 4.

The `t/oid-info/oid` file now lists the values found in that way, and
the test cases are modified to use those values.

As the tests are no longer dependent on SHA-1, we also rename their
titles to talk about "commit IDs" instead of "SHA-1s".

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t3404-rebase-interactive.sh | 50 ++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 4a7d21f898..2fb2c581cb 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -30,6 +30,7 @@ Initial setup:
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
 test_expect_success 'setup' '
+	test_oid_init &&
 	test_commit A file1 &&
 	test_commit B file1 &&
 	test_commit C file2 &&
@@ -1250,7 +1251,7 @@ test_expect_success 'rebase -i error on commits with \ in message' '
 	test_expect_code 1 grep  "	emp" error
 '
 
-test_expect_success SHA1 'short SHA-1 setup' '
+test_expect_success 'short commit ID setup' '
 	test_when_finished "git checkout master" &&
 	git checkout --orphan collide &&
 	git rm -rf . &&
@@ -1262,23 +1263,54 @@ test_expect_success SHA1 'short SHA-1 setup' '
 	)
 '
 
-test_expect_success SHA1 'short SHA-1 collide' '
+if test -n "$GIT_TEST_FIND_COLLIDER"
+then
+	author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
+	committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
+	blob="$(git rev-parse collide2:collide)"
+	from="$(git rev-parse collide1^0)"
+	repl="commit refs/heads/collider-&\\n"
+	repl="${repl}author $author\\ncommitter $committer\\n"
+	repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
+	repl="${repl}from $from\\nM 100644 $blob collide\\n"
+	test_seq 1 32768 | sed "s|.*|$repl|" >script &&
+	git fast-import <script &&
+	git pack-refs &&
+	git for-each-ref >refs &&
+	grep "^$(test_oid t3404_collision)" <refs >matches &&
+	cat matches &&
+	test_line_count -gt 2 matches || {
+		echo "Could not find a collider" >&2
+		exit 1
+	}
+fi
+
+test_expect_success 'short commit ID collide' '
+	test_oid_cache <<-EOF &&
+	# collision-related constants
+	t3404_collision	sha1:6bcd
+	t3404_collision	sha256:0161
+	t3404_collider	sha1:ac4f2ee
+	t3404_collider	sha256:16697
+	EOF
 	test_when_finished "reset_rebase && git checkout master" &&
 	git checkout collide &&
-	colliding_sha1=6bcda37 &&
-	test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
+	colliding_id=$(test_oid t3404_collision) &&
+	hexsz=$(test_oid hexsz) &&
+	test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
+	test_config core.abbrev 4 &&
 	(
 		unset test_tick &&
 		test_tick &&
 		set_fake_editor &&
-		FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
+		FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
 		FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
-		test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
-		grep "^pick $colliding_sha1 " \
+		test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
+		grep "^pick $colliding_id " \
 			.git/rebase-merge/git-rebase-todo.tmp &&
-		grep "^pick [0-9a-f]\{40\}" \
+		grep "^pick [0-9a-f]\{$hexsz\}" \
 			.git/rebase-merge/git-rebase-todo &&
-		grep "^pick [0-9a-f]\{40\}" \
+		grep "^pick [0-9a-f]\{$hexsz\}" \
 			.git/rebase-merge/git-rebase-todo.backup &&
 		git rebase --continue
 	) &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 05/39] t6100: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (3 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 04/39] t3404: prepare 'short SHA-1 collision' tests for SHA-256 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 06/39] t6101: " brian m. carlson
                   ` (33 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Instead of hard-coding a constant 40, split the output of rev-list by
field.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t6100-rev-list-in-order.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t6100-rev-list-in-order.sh b/t/t6100-rev-list-in-order.sh
index b2bb0a7f61..e934bc239c 100755
--- a/t/t6100-rev-list-in-order.sh
+++ b/t/t6100-rev-list-in-order.sh
@@ -22,7 +22,7 @@ test_expect_success 'setup a commit history with trees, blobs' '
 
 test_expect_success 'rev-list --in-commit-order' '
 	git rev-list --in-commit-order --objects HEAD >actual.raw &&
-	cut -c 1-40 >actual <actual.raw &&
+	cut -d" " -f1 >actual <actual.raw &&
 
 	git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
 		HEAD^{commit}
@@ -49,7 +49,7 @@ test_expect_success 'rev-list --in-commit-order' '
 
 test_expect_success 'rev-list lists blobs and trees after commits' '
 	git rev-list --objects HEAD >actual.raw &&
-	cut -c 1-40 >actual <actual.raw &&
+	cut -d" " -f1 >actual <actual.raw &&
 
 	git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
 		HEAD^{commit}

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 06/39] t6101: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (4 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 05/39] t6100: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 07/39] t6301: " brian m. carlson
                   ` (32 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Use $OID_REGEX instead of a hard-coded regular expression.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t6101-rev-parse-parents.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh
index 7683e4a114..7531262a5e 100755
--- a/t/t6101-rev-parse-parents.sh
+++ b/t/t6101-rev-parse-parents.sh
@@ -34,7 +34,7 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'start is valid' '
-	git rev-parse start | grep "^[0-9a-f]\{40\}$"
+	git rev-parse start | grep "^$OID_REGEX$"
 '
 
 test_expect_success 'start^0' '

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 07/39] t6301: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (5 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 06/39] t6101: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 08/39] t6500: specify test values for SHA-256 brian m. carlson
                   ` (31 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Instead of hard-coding a fixed length example object ID in the test,
compute one using the translation tables.  Move a variable into the
setup block so that we can ensure the exit status of test_oid_init is
checked.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t6301-for-each-ref-errors.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
index 49cc65bb58..d545a725a5 100755
--- a/t/t6301-for-each-ref-errors.sh
+++ b/t/t6301-for-each-ref-errors.sh
@@ -5,9 +5,10 @@ test_description='for-each-ref errors for broken refs'
 . ./test-lib.sh
 
 ZEROS=$ZERO_OID
-MISSING=abababababababababababababababababababab
 
 test_expect_success setup '
+	test_oid_init &&
+	MISSING=$(test_oid deadbeef) &&
 	git commit --allow-empty -m "Initial" &&
 	git tag testtag &&
 	git for-each-ref >full-list &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 08/39] t6500: specify test values for SHA-256
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (6 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 07/39] t6301: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 09/39] t6501: avoid hard-coded objects brian m. carlson
                   ` (30 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

In this test, we want to produce several blobs whose first two hex
characters are "17", since we look at this object directory as a proxy
for how many loose objects there are before we need to GC.  Use
test_oid_cache to specify strings that will hash to the right values
when turned into blobs.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t6500-gc.sh | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 0a69a67117..4a3b8f48ac 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -10,7 +10,24 @@ test_expect_success 'setup' '
 	# do not let the amount of physical memory affects gc
 	# behavior, make sure we always pack everything to one pack by
 	# default
-	git config gc.bigPackThreshold 2g
+	git config gc.bigPackThreshold 2g &&
+
+	# These are simply values which, when hashed as a blob with a newline,
+	# produce a hash where the first byte is 0x17 in their respective
+	# algorithms.
+	test_oid_cache <<-EOF
+	obj1 sha1:263
+	obj1 sha256:34
+
+	obj2 sha1:410
+	obj2 sha256:174
+
+	obj3 sha1:523
+	obj3 sha256:313
+
+	obj4 sha1:790
+	obj4 sha256:481
+	EOF
 '
 
 test_expect_success 'gc empty repository' '
@@ -85,13 +102,13 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre
 	# We need to create two object whose sha1s start with 17
 	# since this is what git gc counts.  As it happens, these
 	# two blobs will do so.
-	test_commit 263 &&
-	test_commit 410 &&
+	test_commit "$(test_oid obj1)" &&
+	test_commit "$(test_oid obj2)" &&
 	# Our first gc will create a pack; our second will create a second pack
 	git gc --auto &&
 	ls .git/objects/pack | sort >existing_packs &&
-	test_commit 523 &&
-	test_commit 790 &&
+	test_commit "$(test_oid obj3)" &&
+	test_commit "$(test_oid obj4)" &&
 
 	git gc --auto 2>err &&
 	test_i18ngrep ! "^warning:" err &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 09/39] t6501: avoid hard-coded objects
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (7 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 08/39] t6500: specify test values for SHA-256 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 10/39] t7003: compute appropriate length constant brian m. carlson
                   ` (29 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

This test contains hard-coded invalid object IDs.  Make it hash size
independent by generating invalid object IDs using the translation
tables.  Add a setup target to ensure the output of test_oid_init is
checked properly.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t6501-freshen-objects.sh | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh
index f30b4849b6..7416ed5ffe 100755
--- a/t/t6501-freshen-objects.sh
+++ b/t/t6501-freshen-objects.sh
@@ -45,6 +45,10 @@ maybe_repack () {
 	fi
 }
 
+test_expect_success 'setup' '
+	test_oid_init
+'
+
 for repack in '' true; do
 	title=${repack:+repack}
 	title=${title:-loose}
@@ -128,9 +132,9 @@ for repack in '' true; do
 done
 
 test_expect_success 'do not complain about existing broken links (commit)' '
-	cat >broken-commit <<-\EOF &&
-	tree 0000000000000000000000000000000000000001
-	parent 0000000000000000000000000000000000000002
+	cat >broken-commit <<-EOF &&
+	tree $(test_oid 001)
+	parent $(test_oid 002)
 	author whatever <whatever@example.com> 1234 -0000
 	committer whatever <whatever@example.com> 1234 -0000
 
@@ -143,8 +147,8 @@ test_expect_success 'do not complain about existing broken links (commit)' '
 '
 
 test_expect_success 'do not complain about existing broken links (tree)' '
-	cat >broken-tree <<-\EOF &&
-	100644 blob 0000000000000000000000000000000000000003	foo
+	cat >broken-tree <<-EOF &&
+	100644 blob $(test_oid 003)	foo
 	EOF
 	tree=$(git mktree --missing <broken-tree) &&
 	git gc -q 2>stderr &&
@@ -153,8 +157,8 @@ test_expect_success 'do not complain about existing broken links (tree)' '
 '
 
 test_expect_success 'do not complain about existing broken links (tag)' '
-	cat >broken-tag <<-\EOF &&
-	object 0000000000000000000000000000000000000004
+	cat >broken-tag <<-EOF &&
+	object $(test_oid 004)
 	type commit
 	tag broken
 	tagger whatever <whatever@example.com> 1234 -0000

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 10/39] t7003: compute appropriate length constant
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (8 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 09/39] t6501: avoid hard-coded objects brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 11/39] t7063: make hash size independent brian m. carlson
                   ` (28 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Instead of using a specific invalid hard-coded object ID, look one
up from the translation table.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7003-filter-branch.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index e23de7d0b5..beeb2b855a 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -5,6 +5,7 @@ test_description='git filter-branch'
 . "$TEST_DIRECTORY/lib-gpg.sh"
 
 test_expect_success 'setup' '
+	test_oid_init &&
 	test_commit A &&
 	GIT_COMMITTER_DATE="@0 +0000" GIT_AUTHOR_DATE="@0 +0000" &&
 	test_commit --notick B &&
@@ -463,10 +464,11 @@ test_expect_success 'rewrite submodule with another content' '
 '
 
 test_expect_success 'replace submodule revision' '
+	invalid=$(test_oid numeric) &&
 	git reset --hard original &&
 	git filter-branch -f --tree-filter \
 	    "if git ls-files --error-unmatch -- submod > /dev/null 2>&1
-	     then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod
+	     then git update-index --cacheinfo 160000 $invalid submod
 	     fi" HEAD &&
 	test $orig_head != $(git show-ref --hash --head HEAD)
 '

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 11/39] t7063: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (9 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 10/39] t7003: compute appropriate length constant brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 12/39] t7201: abstract away SHA-1-specific constants brian m. carlson
                   ` (27 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Use test_oid instead of hard-coding a fixed size all-zeros object ID.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7063-status-untracked-cache.sh | 151 ++++++++++++++++--------------
 1 file changed, 81 insertions(+), 70 deletions(-)

diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 428cff9cf3..c713c0dc3f 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -75,14 +75,24 @@ test_expect_success 'setup' '
 	touch one two three done/one dtwo/two dthree/three &&
 	git add one two done/one &&
 	: >.git/info/exclude &&
-	git update-index --untracked-cache
+	git update-index --untracked-cache &&
+	test_oid_cache <<-EOF
+	root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
+	root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
+
+	exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
+	exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
+
+	done sha1:1946f0437f90c5005533cbe1736a6451ca301714
+	done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
+	EOF
 '
 
 test_expect_success 'untracked cache is empty' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect-empty <<EOF &&
-info/exclude 0000000000000000000000000000000000000000
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $ZERO_OID
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
 EOF
@@ -100,17 +110,17 @@ EOF
 
 cat >../dump.expect <<EOF &&
 info/exclude $EMPTY_BLOB
-core.excludesfile 0000000000000000000000000000000000000000
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ 0000000000000000000000000000000000000000 recurse valid
+/ $ZERO_OID recurse valid
 dthree/
 dtwo/
 three
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
 three
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 
@@ -190,18 +200,18 @@ test_expect_success 'verify untracked cache dump' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
 info/exclude $EMPTY_BLOB
-core.excludesfile 0000000000000000000000000000000000000000
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ 0000000000000000000000000000000000000000 recurse valid
+/ $ZERO_OID recurse valid
 dthree/
 dtwo/
 four
 three
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
 three
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -239,18 +249,18 @@ test_expect_success 'verify untracked cache dump' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
 info/exclude $EMPTY_BLOB
-core.excludesfile 0000000000000000000000000000000000000000
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dthree/
 dtwo/
 three
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
 three
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -284,16 +294,16 @@ EOF
 test_expect_success 'verify untracked cache dump' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -303,14 +313,14 @@ test_expect_success 'move two from tracked to untracked' '
 	git rm --cached two &&
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/ $(test_oid root) recurse
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -342,17 +352,17 @@ EOF
 test_expect_success 'verify untracked cache dump' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
 two
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -362,14 +372,14 @@ test_expect_success 'move two from untracked to tracked' '
 	git add two &&
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/ $(test_oid root) recurse
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -401,16 +411,16 @@ EOF
 test_expect_success 'verify untracked cache dump' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -447,16 +457,16 @@ EOF
 test_expect_success 'untracked cache correct after commit' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
-/done/ 0000000000000000000000000000000000000000 recurse valid
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/ $ZERO_OID recurse valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -508,17 +518,17 @@ EOF
 test_expect_success 'untracked cache correct after status' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
-/done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
+/done/ $(test_oid done) recurse valid
 five
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect ../actual
@@ -580,22 +590,22 @@ EOF
 test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
 	test-tool dump-untracked-cache >../actual &&
 	cat >../expect-from-test-dump <<EOF &&
-info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
-core.excludesfile 0000000000000000000000000000000000000000
+info/exclude $(test_oid exclude)
+core.excludesfile $ZERO_OID
 exclude_per_dir .gitignore
 flags 00000006
-/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
+/ $(test_oid root) recurse valid
 .gitignore
 dtwo/
-/done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
+/done/ $(test_oid done) recurse valid
 five
 sub/
-/done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/sub/ $ZERO_OID recurse check_only valid
 sub/
-/done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
+/done/sub/sub/ $ZERO_OID recurse check_only valid
 file
-/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
-/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
+/dthree/ $ZERO_OID recurse check_only valid
+/dtwo/ $ZERO_OID recurse check_only valid
 two
 EOF
 	test_cmp ../expect-from-test-dump ../actual
@@ -695,6 +705,7 @@ test_expect_success 'using --untracked-cache does not fail when core.untrackedCa
 '
 
 test_expect_success 'setting core.untrackedCache to keep' '
+	touch ../expect-from-test-dump &&
 	git config core.untrackedCache keep &&
 	git update-index --untracked-cache &&
 	test-tool dump-untracked-cache >../actual &&
@@ -806,8 +817,8 @@ test_expect_success '"status" after file replacement should be clean with UC=tru
 	test-tool dump-untracked-cache >../actual &&
 	grep -F "recurse valid" ../actual >../actual.grep &&
 	cat >../expect.grep <<EOF &&
-/ 0000000000000000000000000000000000000000 recurse valid
-/two/ 0000000000000000000000000000000000000000 recurse valid
+/ $ZERO_OID recurse valid
+/two/ $ZERO_OID recurse valid
 EOF
 	status_is_clean &&
 	test_cmp ../expect.grep ../actual.grep

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 12/39] t7201: abstract away SHA-1-specific constants
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (10 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 11/39] t7063: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 13/39] t7102: " brian m. carlson
                   ` (26 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7201-co.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index b696bae5f5..d4fd760915 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -230,9 +230,10 @@ test_expect_success 'switch to another branch while carrying a deletion' '
 test_expect_success 'checkout to detach HEAD (with advice declined)' '
 
 	git config advice.detachedHead false &&
+	rev=$(git rev-parse --short renamer^) &&
 	git checkout -f renamer && git clean -f &&
 	git checkout renamer^ 2>messages &&
-	test_i18ngrep "HEAD is now at 7329388" messages &&
+	test_i18ngrep "HEAD is now at $rev" messages &&
 	test_line_count = 1 messages &&
 	H=$(git rev-parse --verify HEAD) &&
 	M=$(git show-ref -s --verify refs/heads/master) &&
@@ -250,7 +251,7 @@ test_expect_success 'checkout to detach HEAD' '
 	git config advice.detachedHead true &&
 	git checkout -f renamer && git clean -f &&
 	GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages &&
-	grep "HEAD is now at 7329388" messages &&
+	grep "HEAD is now at $rev" messages &&
 	test_line_count -gt 1 messages &&
 	H=$(git rev-parse --verify HEAD) &&
 	M=$(git show-ref -s --verify refs/heads/master) &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 13/39] t7102: abstract away SHA-1-specific constants
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (11 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 12/39] t7201: abstract away SHA-1-specific constants brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 14/39] t7400: make hash size independent brian m. carlson
                   ` (25 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7102-reset.sh | 93 +++++++++++++++++++++++++++---------------------
 1 file changed, 53 insertions(+), 40 deletions(-)

diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 97be0d968d..22161b3b2d 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -37,17 +37,23 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "2nd line 1st file" >>first &&
 	git commit -a -m "modify 1st file" &&
+	head5p2=$(git rev-parse --verify HEAD) &&
+	head5p2f=$(git rev-parse --short HEAD:first) &&
 
 	git rm first &&
 	git mv second secondfile &&
 	git commit -a -m "remove 1st and rename 2nd" &&
+	head5p1=$(git rev-parse --verify HEAD) &&
+	head5p1s=$(git rev-parse --short HEAD:secondfile) &&
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	# "git commit -m" would break MinGW, as Windows refuse to pass
 	# $test_encoding encoded parameter to git.
 	commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - &&
-	head5=$(git rev-parse --verify HEAD)
+	head5=$(git rev-parse --verify HEAD) &&
+	head5s=$(git rev-parse --short HEAD:secondfile) &&
+	head5sl=$(git rev-parse HEAD:secondfile)
 '
 # git log --pretty=oneline # to see those SHA1 involved
 
@@ -94,7 +100,7 @@ test_expect_success 'giving a non existing revision should fail' '
 
 test_expect_success 'reset --soft with unmerged index should fail' '
 	touch .git/MERGE_HEAD &&
-	echo "100644 44c5b5884550c17758737edcced463447b91d42b 1	un" |
+	echo "100644 $head5sl 1	un" |
 		git update-index --index-info &&
 	test_must_fail git reset --soft HEAD &&
 	rm .git/MERGE_HEAD &&
@@ -192,7 +198,7 @@ test_expect_success \
 >.diff_expect
 cat >.cached_expect <<EOF
 diff --git a/secondfile b/secondfile
-index 1bbba79..44c5b58 100644
+index $head5p1s..$head5s 100644
 --- a/secondfile
 +++ b/secondfile
 @@ -1 +1,2 @@
@@ -207,7 +213,7 @@ secondfile:
 EOF
 test_expect_success '--soft reset only should show changes in diff --cached' '
 	git reset --soft HEAD^ &&
-	check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&
+	check_changes $head5p1 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -242,7 +248,7 @@ EOF
 test_expect_success \
 	'--hard reset should change the files and undo commits permanently' '
 	git reset --hard HEAD~2 &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
+	check_changes $head5p2 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head4
 '
@@ -251,7 +257,7 @@ test_expect_success \
 cat >.cached_expect <<EOF
 diff --git a/first b/first
 deleted file mode 100644
-index 8206c22..0000000
+index $head5p2f..0000000
 --- a/first
 +++ /dev/null
 @@ -1,2 +0,0 @@
@@ -259,14 +265,14 @@ index 8206c22..0000000
 -2nd line 1st file
 diff --git a/second b/second
 deleted file mode 100644
-index 1bbba79..0000000
+index $head5p1s..0000000
 --- a/second
 +++ /dev/null
 @@ -1 +0,0 @@
 -2nd file
 diff --git a/secondfile b/secondfile
 new file mode 100644
-index 0000000..44c5b58
+index 0000000..$head5s
 --- /dev/null
 +++ b/secondfile
 @@ -0,0 +1,2 @@
@@ -286,13 +292,13 @@ test_expect_success \
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	git add secondfile &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e
+	check_changes $head5p2
 '
 
 cat >.diff_expect <<EOF
 diff --git a/first b/first
 deleted file mode 100644
-index 8206c22..0000000
+index $head5p2f..0000000
 --- a/first
 +++ /dev/null
 @@ -1,2 +0,0 @@
@@ -300,7 +306,7 @@ index 8206c22..0000000
 -2nd line 1st file
 diff --git a/second b/second
 deleted file mode 100644
-index 1bbba79..0000000
+index $head5p1s..0000000
 --- a/second
 +++ /dev/null
 @@ -1 +0,0 @@
@@ -314,9 +320,8 @@ secondfile:
 EOF
 test_expect_success '--mixed reset to HEAD should unadd the files' '
 	git reset &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
-	test "$(git rev-parse ORIG_HEAD)" = \
-			ddaefe00f1da16864591c61fdc7adb5d7cd6b74e
+	check_changes $head5p2 &&
+	test "$(git rev-parse ORIG_HEAD)" = $head5p2
 '
 
 >.diff_expect
@@ -328,7 +333,7 @@ secondfile:
 EOF
 test_expect_success 'redoing the last two commits should succeed' '
 	git add secondfile &&
-	git reset --hard ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
+	git reset --hard $head5p2 &&
 
 	git rm first &&
 	git mv second secondfile &&
@@ -389,47 +394,55 @@ test_expect_success \
 	check_changes $head5
 '
 
-cat > expect << EOF
-diff --git a/file1 b/file1
-index d00491f..7ed6ff8 100644
---- a/file1
-+++ b/file1
-@@ -1 +1 @@
--1
-+5
-diff --git a/file2 b/file2
-deleted file mode 100644
-index 0cfbf08..0000000
---- a/file2
-+++ /dev/null
-@@ -1 +0,0 @@
--2
-EOF
-cat > cached_expect << EOF
-diff --git a/file4 b/file4
-new file mode 100644
-index 0000000..b8626c4
---- /dev/null
-+++ b/file4
-@@ -0,0 +1 @@
-+4
-EOF
 test_expect_success 'test --mixed <paths>' '
 	echo 1 > file1 &&
 	echo 2 > file2 &&
 	git add file1 file2 &&
 	test_tick &&
 	git commit -m files &&
+	before1=$(git rev-parse --short HEAD:file1) &&
+	before2=$(git rev-parse --short HEAD:file2) &&
 	git rm file2 &&
 	echo 3 > file3 &&
 	echo 4 > file4 &&
 	echo 5 > file1 &&
+	after1=$(git rev-parse --short $(git hash-object file1)) &&
+	after4=$(git rev-parse --short $(git hash-object file4)) &&
 	git add file1 file3 file4 &&
 	git reset HEAD -- file1 file2 file3 &&
 	test_must_fail git diff --quiet &&
 	git diff > output &&
+
+	cat > expect <<-EOF &&
+	diff --git a/file1 b/file1
+	index $before1..$after1 100644
+	--- a/file1
+	+++ b/file1
+	@@ -1 +1 @@
+	-1
+	+5
+	diff --git a/file2 b/file2
+	deleted file mode 100644
+	index $before2..0000000
+	--- a/file2
+	+++ /dev/null
+	@@ -1 +0,0 @@
+	-2
+	EOF
+
 	test_cmp expect output &&
 	git diff --cached > output &&
+
+	cat > cached_expect <<-EOF &&
+	diff --git a/file4 b/file4
+	new file mode 100644
+	index 0000000..$after4
+	--- /dev/null
+	+++ b/file4
+	@@ -0,0 +1 @@
+	+4
+	EOF
+
 	test_cmp cached_expect output
 '
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 14/39] t7400: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (12 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 13/39] t7102: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 15/39] t7405: " brian m. carlson
                   ` (24 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Instead of using cut with hard-coded hash sizes, use cut with fields, or
where that's not possible, sed with $OID_REGEX, so that the tests are
independent of hash size.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7400-submodule-basic.sh | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 956e17abb3..fec7e0299d 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1231,7 +1231,7 @@ test_expect_success 'submodule helper list is not confused by common prefixes' '
 	git submodule add /dir1/b dir1/b &&
 	git submodule add /dir2/b dir2/b &&
 	git commit -m "first submodule commit" &&
-	git submodule--helper list dir1/b |cut -c51- >actual &&
+	git submodule--helper list dir1/b | cut -f 2 >actual &&
 	echo "dir1/b" >expect &&
 	test_cmp expect actual
 '
@@ -1260,7 +1260,7 @@ test_expect_success 'submodule update --init with a specification' '
 	pwd=$(pwd) &&
 	git clone file://"$pwd"/multisuper multisuper_clone &&
 	git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
-	git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect actual
 '
 
@@ -1271,7 +1271,7 @@ test_expect_success 'submodule update --init with submodule.active set' '
 	git -C multisuper_clone config submodule.active "." &&
 	git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
 	git -C multisuper_clone submodule update --init &&
-	git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect actual
 '
 
@@ -1290,7 +1290,7 @@ test_expect_success 'submodule update and setting submodule.<name>.active' '
 	-sub3
 	EOF
 	git -C multisuper_clone submodule update &&
-	git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect actual
 '
 
@@ -1307,12 +1307,12 @@ test_expect_success 'clone active submodule without submodule url set' '
 		git submodule update &&
 		git submodule status >actual_raw &&
 
-		cut -c 1,43- actual_raw >actual &&
+		cut -d" " -f3- actual_raw >actual &&
 		cat >expect <<-\EOF &&
-		 sub0 (test2)
-		 sub1 (test2)
-		 sub2 (test2)
-		 sub3 (test2)
+		sub0 (test2)
+		sub1 (test2)
+		sub2 (test2)
+		sub3 (test2)
 		EOF
 		test_cmp expect actual
 	)
@@ -1328,7 +1328,7 @@ test_expect_success 'clone --recurse-submodules with a pathspec works' '
 	EOF
 
 	git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
-	git -C multisuper_clone submodule status |cut -c1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expected actual
 '
 
@@ -1345,7 +1345,7 @@ test_expect_success 'clone with multiple --recurse-submodules options' '
 		  --recurse-submodules=":(exclude)sub0" \
 		  --recurse-submodules=":(exclude)sub2" \
 		  multisuper multisuper_clone &&
-	git -C multisuper_clone submodule status |cut -c1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect actual
 '
 
@@ -1373,7 +1373,7 @@ test_expect_success 'clone and subsequent updates correctly auto-initialize subm
 		  --recurse-submodules=":(exclude)sub4" \
 		  multisuper multisuper_clone &&
 
-	git -C multisuper_clone submodule status |cut -c1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect actual &&
 
 	git -C multisuper submodule add ../sub1 sub4 &&
@@ -1382,7 +1382,7 @@ test_expect_success 'clone and subsequent updates correctly auto-initialize subm
 	# obtain the new superproject
 	git -C multisuper_clone pull &&
 	git -C multisuper_clone submodule update --init &&
-	git -C multisuper_clone submodule status |cut -c1,43- >actual &&
+	git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
 	test_cmp expect2 actual
 '
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 15/39] t7405: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (13 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 14/39] t7400: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 16/39] t7506: avoid checking for SHA-1-specific constants brian m. carlson
                   ` (23 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Use $ZERO_OID instead of hard-coding a fixed size all-zeros object ID.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7405-submodule-merge.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh
index aa33978ed2..6a1e5f8232 100755
--- a/t/t7405-submodule-merge.sh
+++ b/t/t7405-submodule-merge.sh
@@ -195,7 +195,7 @@ test_expect_success 'git submodule status should display the merge conflict prop
        url = $TRASH_DIRECTORY/sub
 EOF
        cat >expect <<EOF &&
-U0000000000000000000000000000000000000000 sub
+U$ZERO_OID sub
 EOF
        git submodule status > actual &&
        test_cmp expect actual &&
@@ -214,7 +214,7 @@ test_expect_success 'git submodule status should display the merge conflict prop
        url = $TRASH_DIRECTORY/sub
 EOF
        cat >expect <<EOF &&
-U0000000000000000000000000000000000000000 sub
+U$ZERO_OID sub
 EOF
        git submodule status > actual &&
        test_cmp expect actual &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 16/39] t7506: avoid checking for SHA-1-specific constants
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (14 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 15/39] t7405: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 17/39] t7508: use $ZERO_OID instead of hard-coded constant brian m. carlson
                   ` (22 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Adjust the test to sanitize the diffs and strip out object IDs from
them, as it does for other object IDs, since we are not interested in
the particular values used.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7506-status-submodule.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 08629a6e70..3fcb44767f 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -22,6 +22,10 @@ sanitize_output () {
 	mv output2 output
 }
 
+sanitize_diff () {
+	sed -e "/^index [0-9a-f,]*\.\.[0-9a-f]*/d" "$1"
+}
+
 
 test_expect_success 'setup' '
 	test_create_repo_with_commit sub &&
@@ -269,7 +273,6 @@ short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD)
 short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD)
 cat >diff_expect <<\EOF
 diff --cc .gitmodules
-index badaa4c,44f999a..0000000
 --- a/.gitmodules
 +++ b/.gitmodules
 @@@ -1,3 -1,3 +1,9 @@@
@@ -286,7 +289,6 @@ EOF
 
 cat >diff_submodule_expect <<\EOF
 diff --cc .gitmodules
-index badaa4c,44f999a..0000000
 --- a/.gitmodules
 +++ b/.gitmodules
 @@@ -1,3 -1,3 +1,9 @@@
@@ -306,7 +308,8 @@ test_expect_success 'diff with merge conflict in .gitmodules' '
 		cd super &&
 		git diff >../diff_actual 2>&1
 	) &&
-	test_cmp diff_expect diff_actual
+	sanitize_diff diff_actual >diff_sanitized &&
+	test_cmp diff_expect diff_sanitized
 '
 
 test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
@@ -314,7 +317,8 @@ test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
 		cd super &&
 		git diff --submodule >../diff_submodule_actual 2>&1
 	) &&
-	test_cmp diff_submodule_expect diff_submodule_actual
+	sanitize_diff diff_submodule_actual >diff_sanitized &&
+	test_cmp diff_submodule_expect diff_sanitized
 '
 
 # We'll setup different cases for further testing:

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 17/39] t7508: use $ZERO_OID instead of hard-coded constant
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (15 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 16/39] t7506: avoid checking for SHA-1-specific constants brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 18/39] t8002: make hash size independent brian m. carlson
                   ` (21 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Use the ZERO_OID variable to abbreviate the all-zeros object ID for
maintainability and to avoid depending on a specific size for the hash.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t7508-status.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 8e969f3e36..e81759319f 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -837,7 +837,7 @@ EOF
 '
 
 cat >expect <<EOF
-:100644 100644 $EMPTY_BLOB 0000000000000000000000000000000000000000 M	dir1/modified
+:100644 100644 $EMPTY_BLOB $ZERO_OID M	dir1/modified
 EOF
 test_expect_success 'status refreshes the index' '
 	touch dir2/added &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 18/39] t8002: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (16 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 17/39] t7508: use $ZERO_OID instead of hard-coded constant brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 19/39] t8003: " brian m. carlson
                   ` (20 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Compute the length of an object ID instead of of hard-coding 40-based
values.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t8002-blame.sh | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index eea048e52c..557c886559 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,6 +6,10 @@ test_description='git blame'
 PROG='git blame -c'
 . "$TEST_DIRECTORY"/annotate-tests.sh
 
+test_expect_success 'setup' '
+	test_oid_init
+'
+
 test_expect_success 'blame untracked file in empty repo' '
 	>untracked &&
 	test_must_fail git blame untracked
@@ -105,17 +109,18 @@ test_expect_success 'blame --abbrev=<n> works' '
 '
 
 test_expect_success 'blame -l aligns regular and boundary commits' '
-	check_abbrev 40 -l HEAD &&
-	check_abbrev 39 -l ^HEAD
+	hexsz=$(test_oid hexsz) &&
+	check_abbrev $hexsz         -l HEAD &&
+	check_abbrev $((hexsz - 1)) -l ^HEAD
 '
 
-test_expect_success 'blame --abbrev=40 behaves like -l' '
-	check_abbrev 40 --abbrev=40 HEAD &&
-	check_abbrev 39 --abbrev=40 ^HEAD
+test_expect_success 'blame --abbrev with full length behaves like -l' '
+	check_abbrev $hexsz         --abbrev=$hexsz HEAD &&
+	check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
 '
 
-test_expect_success '--no-abbrev works like --abbrev=40' '
-	check_abbrev 40 --no-abbrev
+test_expect_success '--no-abbrev works like --abbrev with full length' '
+	check_abbrev $hexsz --no-abbrev
 '
 
 test_expect_success '--exclude-promisor-objects does not BUG-crash' '

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 19/39] t8003: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (17 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 18/39] t8002: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 20/39] t8011: " brian m. carlson
                   ` (19 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

One assertion in this test invokes git with core.abbrev set to "40".
Since we're expecting the full hash length, use test_oid to look up the
full hash length for the hash in use.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t8003-blame-corner-cases.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
index 9130b887d2..ebe79aa4ea 100755
--- a/t/t8003-blame-corner-cases.sh
+++ b/t/t8003-blame-corner-cases.sh
@@ -6,6 +6,7 @@ test_description='git blame corner cases'
 pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
 
 test_expect_success setup '
+	test_oid_init &&
 
 	echo A A A A A >one &&
 	echo B B B B B >two &&
@@ -306,7 +307,7 @@ test_expect_success 'blame coalesce' '
 	$oid 1) ABC
 	$oid 2) DEF
 	EOF
-	git -c core.abbrev=40 blame -s giraffe >actual &&
+	git -c core.abbrev=$(test_oid hexsz) blame -s giraffe >actual &&
 	test_cmp expect actual
 '
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 20/39] t8011: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (18 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 19/39] t8003: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 21/39] t9300: abstract away SHA-1-specific constants brian m. carlson
                   ` (18 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Allow lines which start with either a 40- or 64-character hex object ID,
to allow for both SHA-1 and SHA-256.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t8011-blame-split-file.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t8011-blame-split-file.sh b/t/t8011-blame-split-file.sh
index 831125047b..8a4626d496 100755
--- a/t/t8011-blame-split-file.sh
+++ b/t/t8011-blame-split-file.sh
@@ -54,7 +54,7 @@ test_expect_success 'setup simulated porcelain' '
 	cat >read-porcelain.pl <<-\EOF
 	my $field = shift;
 	while (<>) {
-		if (/^[0-9a-f]{40} /) {
+		if (/^[0-9a-f]{40,64} /) {
 			flush();
 			$hash = $&;
 		} elsif (/^$field (.*)/) {

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 21/39] t9300: abstract away SHA-1-specific constants
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (19 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 20/39] t8011: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 22/39] t9300: use $ZERO_OID instead of hard-coded object ID brian m. carlson
                   ` (17 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9300-fast-import.sh | 107 ++++++++++++++++++++++-------------------
 1 file changed, 58 insertions(+), 49 deletions(-)

diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index e151df81c0..69d6fa4127 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -285,7 +285,7 @@ test_expect_success 'A: verify pack' '
 
 test_expect_success 'A: verify diff' '
 	cat >expect <<-EOF &&
-	:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A	copy-of-file2
+	:000000 100755 0000000000000000000000000000000000000000 $(git rev-parse --verify master:file2) A	copy-of-file2
 	EOF
 	git diff-tree -M -r master verify--import-marks >actual &&
 	compare_diff_raw expect actual &&
@@ -528,6 +528,7 @@ test_expect_success 'B: fail on invalid committer (5)' '
 test_expect_success 'C: incremental import create pack from stdin' '
 	newf=$(echo hi newf | git hash-object -w --stdin) &&
 	oldf=$(git rev-parse --verify master:file2) &&
+	thrf=$(git rev-parse --verify master:file3) &&
 	test_tick &&
 	cat >input <<-INPUT_END &&
 	commit refs/heads/branch
@@ -570,10 +571,11 @@ test_expect_success 'C: verify commit' '
 '
 
 test_expect_success 'C: validate rename result' '
+	zero=$ZERO_OID &&
 	cat >expect <<-EOF &&
-	:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A	file2/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100	file2	file2/oldf
-	:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D	file3
+	:000000 100755 $zero $newf A	file2/newf
+	:100644 100644 $oldf $oldf R100	file2	file2/oldf
+	:100644 000000 $thrf $zero D	file3
 	EOF
 	git diff-tree -M -r master branch >actual &&
 	compare_diff_raw expect actual
@@ -614,9 +616,11 @@ test_expect_success 'D: verify pack' '
 '
 
 test_expect_success 'D: validate new files added' '
+	f5id=$(echo "$file5_data" | git hash-object --stdin) &&
+	f6id=$(echo "$file6_data" | git hash-object --stdin) &&
 	cat >expect <<-EOF &&
-	:000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A	newdir/exec.sh
-	:000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A	newdir/interesting
+	:000000 100755 0000000000000000000000000000000000000000 $f6id A	newdir/exec.sh
+	:000000 100644 0000000000000000000000000000000000000000 $f5id A	newdir/interesting
 	EOF
 	git diff-tree -M -r branch^ branch >actual &&
 	compare_diff_raw expect actual
@@ -779,12 +783,13 @@ test_expect_success 'H: verify pack' '
 '
 
 test_expect_success 'H: validate old files removed, new files added' '
+	f4id=$(git rev-parse HEAD:file4) &&
 	cat >expect <<-EOF &&
-	:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D	file2/newf
-	:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D	file2/oldf
-	:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D	file4
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100	newdir/interesting	h/e/l/lo
-	:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D	newdir/exec.sh
+	:100755 000000 $newf $zero D	file2/newf
+	:100644 000000 $oldf $zero D	file2/oldf
+	:100755 000000 $f4id $zero D	file4
+	:100644 100644 $f5id $f5id R100	newdir/interesting	h/e/l/lo
+	:100755 000000 $f6id $zero D	newdir/exec.sh
 	EOF
 	git diff-tree -M -r H^ H >actual &&
 	compare_diff_raw expect actual
@@ -935,14 +940,15 @@ test_expect_success 'L: verify internal tree sorting' '
 	INPUT_END
 
 	cat >expect <<-EXPECT_END &&
-	:100644 100644 4268632... 55d3a52... M	b.
-	:040000 040000 0ae5cac... 443c768... M	b
-	:100644 100644 4268632... 55d3a52... M	ba
+	:100644 100644 M	b.
+	:040000 040000 M	b
+	:100644 100644 M	ba
 	EXPECT_END
 
 	git fast-import <input &&
 	GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
-	test_cmp expect output
+	cut -d" " -f1,2,5 output >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'L: nested tree copy does not corrupt deltas' '
@@ -1004,7 +1010,7 @@ test_expect_success 'M: rename file in same subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	file2/newf	file2/n.e.w.f
+	:100755 100755 $newf $newf R100	file2/newf	file2/n.e.w.f
 	EOF
 	git fast-import <input &&
 	git diff-tree -M -r M1^ M1 >actual &&
@@ -1025,7 +1031,7 @@ test_expect_success 'M: rename file to new subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	file2/newf	i/am/new/to/you
+	:100755 100755 $newf $newf R100	file2/newf	i/am/new/to/you
 	EOF
 	git fast-import <input &&
 	git diff-tree -M -r M2^ M2 >actual &&
@@ -1046,7 +1052,7 @@ test_expect_success 'M: rename subdirectory to new subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	i/am/new/to/you	other/sub/am/new/to/you
+	:100755 100755 $newf $newf R100	i/am/new/to/you	other/sub/am/new/to/you
 	EOF
 	git fast-import <input &&
 	git diff-tree -M -r M3^ M3 >actual &&
@@ -1067,11 +1073,11 @@ test_expect_success 'M: rename root to subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100	file2/oldf	sub/file2/oldf
-	:100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100	file4	sub/file4
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	i/am/new/to/you	sub/i/am/new/to/you
-	:100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100	newdir/exec.sh	sub/newdir/exec.sh
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100	newdir/interesting	sub/newdir/interesting
+	:100644 100644 $oldf $oldf R100	file2/oldf	sub/file2/oldf
+	:100755 100755 $f4id $f4id R100	file4	sub/file4
+	:100755 100755 $newf $newf R100	i/am/new/to/you	sub/i/am/new/to/you
+	:100755 100755 $f6id $f6id R100	newdir/exec.sh	sub/newdir/exec.sh
+	:100644 100644 $f5id $f5id R100	newdir/interesting	sub/newdir/interesting
 	EOF
 	git fast-import <input &&
 	git diff-tree -M -r M4^ M4 >actual &&
@@ -1097,7 +1103,7 @@ test_expect_success 'N: copy file in same subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file2/n.e.w.f
+	:100755 100755 $newf $newf C100	file2/newf	file2/n.e.w.f
 	EOF
 	git fast-import <input &&
 	git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
@@ -1129,9 +1135,9 @@ test_expect_success 'N: copy then modify subdirectory' '
 	INPUT_END
 
 	cat >expect <<-EOF &&
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100	newdir/interesting	file3/file5
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	:100644 100644 $f5id $f5id C100	newdir/interesting	file3/file5
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	git fast-import <input &&
 	git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
@@ -1162,9 +1168,9 @@ test_expect_success 'N: copy dirty subdirectory' '
 '
 
 test_expect_success 'N: copy directory by id' '
-	cat >expect <<-\EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	cat >expect <<-EOF &&
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 	cat >input <<-INPUT_END &&
@@ -1183,9 +1189,9 @@ test_expect_success 'N: copy directory by id' '
 '
 
 test_expect_success PIPE 'N: read and copy directory' '
-	cat >expect <<-\EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	cat >expect <<-EOF &&
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	git update-ref -d refs/heads/N4 &&
 	rm -f backflow &&
@@ -1254,9 +1260,9 @@ test_expect_success PIPE 'N: empty directory reads as missing' '
 '
 
 test_expect_success 'N: copy root directory by tree hash' '
-	cat >expect <<-\EOF &&
-	:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D	file3/newf
-	:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D	file3/oldf
+	cat >expect <<-EOF &&
+	:100755 000000 $newf $zero D	file3/newf
+	:100644 000000 $oldf $zero D	file3/oldf
 	EOF
 	root=$(git rev-parse refs/heads/branch^0^{tree}) &&
 	cat >input <<-INPUT_END &&
@@ -1275,12 +1281,12 @@ test_expect_success 'N: copy root directory by tree hash' '
 '
 
 test_expect_success 'N: copy root by path' '
-	cat >expect <<-\EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	oldroot/file2/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	oldroot/file2/oldf
-	:100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100	file4	oldroot/file4
-	:100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100	newdir/exec.sh	oldroot/newdir/exec.sh
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100	newdir/interesting	oldroot/newdir/interesting
+	cat >expect <<-EOF &&
+	:100755 100755 $newf $newf C100	file2/newf	oldroot/file2/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	oldroot/file2/oldf
+	:100755 100755 $f4id $f4id C100	file4	oldroot/file4
+	:100755 100755 $f6id $f6id C100	newdir/exec.sh	oldroot/newdir/exec.sh
+	:100644 100644 $f5id $f5id C100	newdir/interesting	oldroot/newdir/interesting
 	EOF
 	cat >input <<-INPUT_END &&
 	commit refs/heads/N-copy-root-path
@@ -1340,10 +1346,10 @@ test_expect_success 'N: delete directory by copying' '
 '
 
 test_expect_success 'N: modify copied tree' '
-	cat >expect <<-\EOF &&
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100	newdir/interesting	file3/file5
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	cat >expect <<-EOF &&
+	:100644 100644 $f5id $f5id C100	newdir/interesting	file3/file5
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 	cat >input <<-INPUT_END &&
@@ -3117,6 +3123,9 @@ test_expect_success 'U: initialize for U tests' '
 
 	INPUT_END
 
+	f7id=$(echo "blob 1" | git hash-object --stdin) &&
+	f8id=$(echo "sleep well" | git hash-object --stdin) &&
+	f9id=$(echo "au revoir" | git hash-object --stdin) &&
 	git fast-import <input
 '
 
@@ -3137,7 +3146,7 @@ test_expect_success 'U: filedelete file succeeds' '
 
 test_expect_success 'U: validate file delete result' '
 	cat >expect <<-EOF &&
-	:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D	good/night.txt
+	:100644 000000 $f8id $ZERO_OID D	good/night.txt
 	EOF
 
 	git diff-tree -M -r U^1 U >actual &&
@@ -3162,7 +3171,7 @@ test_expect_success 'U: filedelete directory succeeds' '
 
 test_expect_success 'U: validate directory delete result' '
 	cat >expect <<-EOF &&
-	:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D	good/bye.txt
+	:100644 000000 $f9id $ZERO_OID D	good/bye.txt
 	EOF
 
 	git diff-tree -M -r U^1 U >actual &&
@@ -3187,7 +3196,7 @@ test_expect_success 'U: filedelete root succeeds' '
 
 test_expect_success 'U: validate root delete result' '
 	cat >expect <<-EOF &&
-	:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D	hello.c
+	:100644 000000 $f7id $ZERO_OID D	hello.c
 	EOF
 
 	git diff-tree -M -r U^1 U >actual &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 22/39] t9300: use $ZERO_OID instead of hard-coded object ID
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (20 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 21/39] t9300: abstract away SHA-1-specific constants brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 23/39] t9301: make hash size independent brian m. carlson
                   ` (16 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9300-fast-import.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 69d6fa4127..f4b3f5eaf9 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -92,7 +92,7 @@ test_expect_success 'A: create pack from stdin' '
 	EOF
 
 	reset refs/tags/to-be-deleted
-	from 0000000000000000000000000000000000000000
+	from $ZERO_OID
 
 	tag nested
 	mark :6
@@ -102,7 +102,7 @@ test_expect_success 'A: create pack from stdin' '
 	EOF
 
 	reset refs/tags/nested
-	from 0000000000000000000000000000000000000000
+	from $ZERO_OID
 
 	tag nested
 	mark :7
@@ -285,7 +285,7 @@ test_expect_success 'A: verify pack' '
 
 test_expect_success 'A: verify diff' '
 	cat >expect <<-EOF &&
-	:000000 100755 0000000000000000000000000000000000000000 $(git rev-parse --verify master:file2) A	copy-of-file2
+	:000000 100755 $ZERO_OID $(git rev-parse --verify master:file2) A	copy-of-file2
 	EOF
 	git diff-tree -M -r master verify--import-marks >actual &&
 	compare_diff_raw expect actual &&
@@ -364,7 +364,7 @@ test_expect_success 'B: fail on invalid blob sha1' '
 	COMMIT
 
 	from refs/heads/master
-	M 755 0000000000000000000000000000000000000001 zero1
+	M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
 
 	INPUT_END
 
@@ -619,8 +619,8 @@ test_expect_success 'D: validate new files added' '
 	f5id=$(echo "$file5_data" | git hash-object --stdin) &&
 	f6id=$(echo "$file6_data" | git hash-object --stdin) &&
 	cat >expect <<-EOF &&
-	:000000 100755 0000000000000000000000000000000000000000 $f6id A	newdir/exec.sh
-	:000000 100644 0000000000000000000000000000000000000000 $f5id A	newdir/interesting
+	:000000 100755 $ZERO_OID $f6id A	newdir/exec.sh
+	:000000 100644 $ZERO_OID $f5id A	newdir/interesting
 	EOF
 	git diff-tree -M -r branch^ branch >actual &&
 	compare_diff_raw expect actual
@@ -2732,7 +2732,7 @@ test_expect_success 'R: corrupt lines do not mess marks file' '
 	rm -f io.marks &&
 	blob=$(echo hi | git hash-object --stdin) &&
 	cat >expect <<-EOF &&
-	:3 0000000000000000000000000000000000000000
+	:3 $ZERO_OID
 	:1 $blob
 	:2 $blob
 	EOF
@@ -3083,7 +3083,7 @@ test_expect_success 'T: delete branch' '
 	git branch to-delete &&
 	git fast-import <<-EOF &&
 	reset refs/heads/to-delete
-	from 0000000000000000000000000000000000000000
+	from $ZERO_OID
 	EOF
 	test_must_fail git rev-parse --verify refs/heads/to-delete
 '

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 23/39] t9301: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (21 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 22/39] t9300: use $ZERO_OID instead of hard-coded object ID brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 24/39] t9350: " brian m. carlson
                   ` (15 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Instead of using a hard-coded all-zeros object ID, use $ZERO_OID.
Compute the length of the object IDs in use and use this instead of
hard-coding the constant 40.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9301-fast-import-notes.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh
index ca223dca98..9d1aaac980 100755
--- a/t/t9301-fast-import-notes.sh
+++ b/t/t9301-fast-import-notes.sh
@@ -71,7 +71,7 @@ EOF
 INPUT_END
 
 test_expect_success 'set up master branch' '
-
+	test_oid_init &&
 	git fast-import <input &&
 	git whatchanged master
 '
@@ -470,12 +470,13 @@ test_expect_success 'add lots of commits and notes' '
 '
 
 test_expect_success 'verify that lots of notes trigger a fanout scheme' '
+	hexsz=$(test_oid hexsz) &&
 
 	# None of the entries in the top-level notes tree should be a full SHA1
 	git ls-tree --name-only refs/notes/many_notes |
 	while read path
 	do
-		if test $(expr length "$path") -ge 40
+		if test $(expr length "$path") -ge $hexsz
 		then
 			return 1
 		fi
@@ -518,7 +519,7 @@ test_expect_success 'verify that importing a notes tree respects the fanout sche
 	git ls-tree --name-only refs/notes/other_notes |
 	while read path
 	do
-		if test $(expr length "$path") -ge 40
+		if test $(expr length "$path") -ge $hexsz
 		then
 			return 1
 		fi
@@ -593,7 +594,7 @@ test_expect_success 'verify that changing notes respect existing fanout' '
 	git ls-tree --name-only refs/notes/many_notes |
 	while read path
 	do
-		if test $(expr length "$path") -ge 40
+		if test $(expr length "$path") -ge $hexsz
 		then
 			return 1
 		fi
@@ -616,7 +617,7 @@ i=$(($num_commits - $remaining_notes))
 for sha1 in $(git rev-list -n $i refs/heads/many_commits)
 do
 	cat >>input <<INPUT_END
-N 0000000000000000000000000000000000000000 $sha1
+N $ZERO_OID $sha1
 INPUT_END
 done
 
@@ -646,7 +647,6 @@ test_expect_success 'remove lots of notes' '
 '
 
 test_expect_success 'verify that removing notes trigger fanout consolidation' '
-
 	# All entries in the top-level notes tree should be a full SHA1
 	git ls-tree --name-only -r refs/notes/many_notes |
 	while read path
@@ -656,7 +656,7 @@ test_expect_success 'verify that removing notes trigger fanout consolidation' '
 		test "$path" = "deadbeef" && continue
 		test "$path" = "de/adbeef" && continue
 
-		if test $(expr length "$path") -ne 40
+		if test $(expr length "$path") -ne $hexsz
 		then
 			return 1
 		fi

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 24/39] t9350: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (22 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 23/39] t9301: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 25/39] t9500: ensure that algorithm info is preserved in config brian m. carlson
                   ` (14 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

This test checks for several commit object sizes to verify that objects
are encoded as expected. However, the size of a commit object differs
between SHA-1 and SHA-256, since each contains a hex representation of
the tree's object ID. Since these are root commits, compute the size of
each commit by using a constant plus the size of a single hex object ID.

In addition, use $ZERO_OID instead of a hard-coded object ID.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9350-fast-export.sh | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index 690c90fb82..ba79db6a17 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -7,6 +7,7 @@ test_description='git fast-export'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
+	test_oid_init &&
 
 	echo break it > file0 &&
 	git add file0 &&
@@ -132,12 +133,12 @@ test_expect_success 'reencoding iso-8859-7' '
 	sed "s/wer/i18n/" iso-8859-7.fi |
 		(cd new &&
 		 git fast-import &&
-		 # The commit object, if not re-encoded, would be 240 bytes.
+		 # The commit object, if not re-encoded, would be 200 bytes plus hash.
 		 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
 		 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
 		 # to \xCF\x80 (\317\200) in UTF-8 adds a byte.  Check for
 		 # the expected size.
-		 test 221 -eq "$(git cat-file -s i18n)" &&
+		 test $(($(test_oid hexsz) + 181)) -eq "$(git cat-file -s i18n)" &&
 		 # ...and for the expected translation of bytes.
 		 git cat-file commit i18n >actual &&
 		 grep $(printf "\317\200") actual &&
@@ -164,12 +165,12 @@ test_expect_success 'preserving iso-8859-7' '
 	sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
 		(cd new &&
 		 git fast-import &&
-		 # The commit object, if not re-encoded, is 240 bytes.
+		 # The commit object, if not re-encoded, is 200 bytes plus hash.
 		 # Removing the "encoding iso-8859-7\n" header would drops 20
 		 # bytes.  Re-encoding the Pi character from \xF0 (\360) in
 		 # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
 		 # Check for the expected size...
-		 test 240 -eq "$(git cat-file -s i18n-no-recoding)" &&
+		 test $(($(test_oid hexsz) + 200)) -eq "$(git cat-file -s i18n-no-recoding)" &&
 		 # ...as well as the expected byte.
 		 git cat-file commit i18n-no-recoding >actual &&
 		 grep $(printf "\360") actual &&
@@ -192,7 +193,7 @@ test_expect_success 'encoding preserved if reencoding fails' '
 		 grep ^encoding actual &&
 		 # Verify that the commit has the expected size; i.e.
 		 # that no bytes were re-encoded to a different encoding.
-		 test 252 -eq "$(git cat-file -s i18n-invalid)" &&
+		 test $(($(test_oid hexsz) + 212)) -eq "$(git cat-file -s i18n-invalid)" &&
 		 # ...and check for the original special bytes
 		 grep $(printf "\360") actual &&
 		 grep $(printf "\377") actual)
@@ -694,7 +695,7 @@ test_expect_success 'delete ref because entire history excluded' '
 	git fast-export to-delete ^to-delete >actual &&
 	cat >expected <<-EOF &&
 	reset refs/heads/to-delete
-	from 0000000000000000000000000000000000000000
+	from $ZERO_OID
 
 	EOF
 	test_cmp expected actual
@@ -704,7 +705,7 @@ test_expect_success 'delete refspec' '
 	git fast-export --refspec :refs/heads/to-delete >actual &&
 	cat >expected <<-EOF &&
 	reset refs/heads/to-delete
-	from 0000000000000000000000000000000000000000
+	from $ZERO_OID
 
 	EOF
 	test_cmp expected actual

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 25/39] t9500: ensure that algorithm info is preserved in config
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (23 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 24/39] t9350: " brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 26/39] t9700: make hash size independent brian m. carlson
                   ` (13 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

When we use a hash algorithm other than SHA-1, it's important to
preserve the hash-related values in the config file, but this test
overwrites the config file with a new one. Ensure we copy these values
properly from the old config to the new one so that the repository can
be read if it's using SHA-256.

Note that if there is no extensions.objectFormat value set, git config
will return unsuccessfully if we try to read it; since this is not an
error for us, use test_might_fail.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9500-gitweb-standalone-no-errors.sh | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 267ddc997d..b484e3e250 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -621,12 +621,22 @@ test_expect_success \
 	 git config gitweb.snapshot "zip,tgz, tbz2" &&
 	 gitweb_run "p=.git;a=tree"'
 
-cat >.git/config <<\EOF
-# testing noval and alternate separator
-[gitweb]
-	blame
-	snapshot = zip tgz
-EOF
+test_expect_success 'setup' '
+	version=$(git config core.repositoryformatversion) &&
+	algo=$(test_might_fail git config extensions.objectformat) &&
+	cat >.git/config <<-\EOF &&
+	# testing noval and alternate separator
+	[gitweb]
+		blame
+		snapshot = zip tgz
+	EOF
+	git config core.repositoryformatversion "$version" &&
+	if test -n "$algo"
+	then
+		git config extensions.objectformat "$algo"
+	fi
+'
+
 test_expect_success \
 	'config override: tree view, features enabled in repo config (2)' \
 	'gitweb_run "p=.git;a=tree"'

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 26/39] t9700: make hash size independent
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (24 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 25/39] t9500: ensure that algorithm info is preserved in config brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 27/39] t5308: make test work with SHA-256 brian m. carlson
                   ` (12 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

The Perl test script for t9700 was matching on exactly 40 hex
characters.  With SHA-256, we'll have 64 hex-character object IDs.
Create a variable with a regex which matches exactly 40 or 64 hex
characters and use that to match the output.  Note that both of the uses
of this can be anchored, which makes the code simpler, so do that as
well.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t9700/test.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t9700/test.pl b/t/t9700/test.pl
index 34cd01366f..071ff6d82a 100755
--- a/t/t9700/test.pl
+++ b/t/t9700/test.pl
@@ -23,6 +23,8 @@ sub adjust_dirsep {
 	return $path;
 }
 
+my $oid_re = qr/^[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?$/;
+
 BEGIN { use_ok('Git') }
 
 # set up
@@ -93,7 +95,7 @@ sub adjust_dirsep {
 open TEMPFILE, ">$tmpfile" or die "Can't open $tmpfile: $!";
 print TEMPFILE my $test_text = "test blob, to be inserted\n";
 close TEMPFILE or die "Failed writing to $tmpfile: $!";
-like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
+like(our $newhash = $r->hash_and_insert_object($tmpfile), $oid_re,
      "hash_and_insert_object: returns hash");
 open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
 is($r->cat_blob($newhash, \*TEMPFILE), length $test_text, "cat_blob: roundtrip size");
@@ -119,7 +121,7 @@ sub adjust_dirsep {
 
 # commands in sub directory
 my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD));
-like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
+like($last_commit, $oid_re, 'rev-parse returned hash');
 my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
 isnt($last_commit, $dir_commit, 'log . does not show last commit');
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 27/39] t5308: make test work with SHA-256
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (25 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 26/39] t9700: make hash size independent brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 28/39] t0410: mark test with SHA1 prerequisite brian m. carlson
                   ` (11 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

This test needs multiple object IDs that have the same first byte.
Update the pack test code to generate a suitable packed value for
SHA-256.  Update the test to use this value when using SHA-256.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/lib-pack.sh                     |  8 ++++++++
 t/t5308-pack-detect-duplicates.sh | 20 ++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/t/lib-pack.sh b/t/lib-pack.sh
index f3463170b3..0c799d53c6 100644
--- a/t/lib-pack.sh
+++ b/t/lib-pack.sh
@@ -93,6 +93,14 @@ pack_obj () {
 			;;
 		esac
 		;;
+	# blob containing "\3\326"
+	471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe)
+		case "$2" in
+		'')
+			printf '\062\170\234\143\276\006\000\000\336\000\332'
+			return
+			;;
+		esac
 	esac
 
 	# If it's not a delta, we can convince pack-objects to generate a pack
diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh
index 6845c1f3c3..693b2411c8 100755
--- a/t/t5308-pack-detect-duplicates.sh
+++ b/t/t5308-pack-detect-duplicates.sh
@@ -4,23 +4,27 @@ test_description='handling of duplicate objects in incoming packfiles'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-pack.sh
 
-if ! test_have_prereq SHA1
-then
-       skip_all='not using SHA-1 for objects'
-       test_done
-fi
+test_expect_success 'setup' '
+	test_oid_cache <<-EOF
+	lo_oid sha1:e68fe8129b546b101aee9510c5328e7f21ca1d18
+	lo_oid sha256:471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe
+
+	missing_oid sha1:e69d000000000000000000000000000000000000
+	missing_oid sha256:4720000000000000000000000000000000000000000000000000000000000000
+	EOF
+'
 
 # The sha1s we have in our pack. It's important that these have the same
 # starting byte, so that they end up in the same fanout section of the index.
 # That lets us make sure we are exercising the binary search with both sets.
-LO_SHA1=e68fe8129b546b101aee9510c5328e7f21ca1d18
-HI_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+LO_SHA1=$(test_oid lo_oid)
+HI_SHA1=$EMPTY_BLOB
 
 # And here's a "missing sha1" which will produce failed lookups. It must also
 # be in the same fanout section, and should be between the two (so that during
 # our binary search, we are sure to end up looking at one or the other of the
 # duplicate runs).
-MISSING_SHA1='e69d000000000000000000000000000000000000'
+MISSING_SHA1=$(test_oid missing_oid)
 
 # git will never intentionally create packfiles with
 # duplicate objects, so we have to construct them by hand.

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 28/39] t0410: mark test with SHA1 prerequisite
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (26 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 27/39] t5308: make test work with SHA-256 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 29/39] http-fetch: set up git directory before parsing pack hashes brian m. carlson
                   ` (10 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

These tests try to check that we behave properly if we encounter a
repository with version 0 but an extension.  This is a laudable goal,
but the test cannot work with SHA-256, since SHA-256 repositories always
have an existing extension and are never version 0.

Add a SHA1 prerequisite to these tests.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t0410-partial-clone.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index 6aa0f313bd..a5ebdf9ff3 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -42,7 +42,7 @@ test_expect_success 'convert shallow clone to partial clone' '
 	test_cmp_config -C client 1 core.repositoryformatversion
 '
 
-test_expect_success 'convert to partial clone with noop extension' '
+test_expect_success SHA1 'convert to partial clone with noop extension' '
 	rm -fr server client &&
 	test_create_repo server &&
 	test_commit -C server my_commit 1 &&
@@ -53,7 +53,7 @@ test_expect_success 'convert to partial clone with noop extension' '
 	git -C client fetch --unshallow --filter="blob:none"
 '
 
-test_expect_success 'converting to partial clone fails with unrecognized extension' '
+test_expect_success SHA1 'converting to partial clone fails with unrecognized extension' '
 	rm -fr server client &&
 	test_create_repo server &&
 	test_commit -C server my_commit 1 &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 29/39] http-fetch: set up git directory before parsing pack hashes
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (27 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 28/39] t0410: mark test with SHA1 prerequisite brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option brian m. carlson
                   ` (9 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

In dd4b732df7 ("upload-pack: send part of packfile response as uri",
2020-06-10), the git http-fetch code learned how to take  ac --packfile
option.  This option takes an argument, which is the name of a packfile
hash, and parses it using parse_oid_hex.  It does so before calling
setup_git_directory.

However, in a SHA-256 repository this fails to work, since we have not
set the hash algorithm in use and parse_oid_hex fails as a consequence.
To ensure that we can parse packfile hashes of the right length, let's
set up the git directory before we start parsing arguments.
---
 http-fetch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/http-fetch.c b/http-fetch.c
index 1df376e745..8db7eb669f 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -86,6 +86,8 @@ int cmd_main(int argc, const char **argv)
 	int packfile = 0;
 	struct object_id packfile_hash;
 
+	setup_git_directory();
+
 	while (arg < argc && argv[arg][0] == '-') {
 		const char *p;
 
@@ -115,8 +117,6 @@ int cmd_main(int argc, const char **argv)
 	if (argc != arg + 2 - (commits_on_stdin || packfile))
 		usage(http_fetch_usage);
 
-	setup_git_directory();
-
 	git_config(git_default_config, NULL);
 
 	if (packfile) {

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (28 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 29/39] http-fetch: set up git directory before parsing pack hashes brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  4:54   ` Eric Sunshine
  2020-07-23  1:09 ` [PATCH v3 31/39] bundle: add new version for use with SHA-256 brian m. carlson
                   ` (8 subsequent siblings)
  38 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

A recently added test in t5702 started using git verify-pack outside of
a repository.  While this poses no problems with SHA-1, with SHA-256 we
implicitly rely on the setup of the repository to initialize our hash
algorithm settings.

Since we're not in a repository here, we need to provide git verify-pack
help to set things up properly.  git index-pack already knows an
--object-format option, so let's accept one as well and pass it down to
our git index-pack invocation.  Since this argument is optional, let's
dynamically determine the proper location to insert it into the array.
Finally, let's make t5702 pass the proper argument on down to its git
verify-pack caller.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/verify-pack.c  | 25 +++++++++++++++++--------
 t/t5702-protocol-v2.sh |  2 +-
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c2a1a5c504..c4090102a9 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -7,21 +7,27 @@
 #define VERIFY_PACK_VERBOSE 01
 #define VERIFY_PACK_STAT_ONLY 02
 
-static int verify_one_pack(const char *path, unsigned int flags)
+static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
 {
 	struct child_process index_pack = CHILD_PROCESS_INIT;
-	const char *argv[] = {"index-pack", NULL, NULL, NULL };
-	struct strbuf arg = STRBUF_INIT;
+	const char *argv[] = {"index-pack", NULL, NULL, NULL, NULL };
+	struct strbuf arg = STRBUF_INIT, hash_arg = STRBUF_INIT;
 	int verbose = flags & VERIFY_PACK_VERBOSE;
 	int stat_only = flags & VERIFY_PACK_STAT_ONLY;
 	int err;
+	int argno = 1;
 
 	if (stat_only)
-		argv[1] = "--verify-stat-only";
+		argv[argno++] = "--verify-stat-only";
 	else if (verbose)
-		argv[1] = "--verify-stat";
+		argv[argno++] = "--verify-stat";
 	else
-		argv[1] = "--verify";
+		argv[argno++] = "--verify";
+
+	if (hash_algo) {
+		strbuf_addf(&hash_arg, "--object-format=%s", hash_algo);
+		argv[argno++] = hash_arg.buf;
+	}
 
 	/*
 	 * In addition to "foo.pack" we accept "foo.idx" and "foo";
@@ -31,7 +37,7 @@ static int verify_one_pack(const char *path, unsigned int flags)
 	if (strbuf_strip_suffix(&arg, ".idx") ||
 	    !ends_with(arg.buf, ".pack"))
 		strbuf_addstr(&arg, ".pack");
-	argv[2] = arg.buf;
+	argv[argno++] = arg.buf;
 
 	index_pack.argv = argv;
 	index_pack.git_cmd = 1;
@@ -60,12 +66,15 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
 {
 	int err = 0;
 	unsigned int flags = 0;
+	const char *object_format = NULL;
 	int i;
 	const struct option verify_pack_options[] = {
 		OPT_BIT('v', "verbose", &flags, N_("verbose"),
 			VERIFY_PACK_VERBOSE),
 		OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
 			VERIFY_PACK_STAT_ONLY),
+		OPT_STRING(0, "object-format", &object_format, N_("hash"),
+			   N_("specify the hash algorithm to use")),
 		OPT_END()
 	};
 
@@ -75,7 +84,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
 	if (argc < 1)
 		usage_with_options(verify_pack_usage, verify_pack_options);
 	for (i = 0; i < argc; i++) {
-		if (verify_one_pack(argv[i], flags))
+		if (verify_one_pack(argv[i], flags, object_format))
 			err = 1;
 	}
 
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index 1b54c35b01..7fc22171e7 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -829,7 +829,7 @@ test_expect_success 'part of packfile response provided as URI' '
 	# Ensure that my-blob and other-blob are in separate packfiles.
 	for idx in http_child/.git/objects/pack/*.idx
 	do
-		git verify-pack --verbose $idx >out &&
+		git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
 		{
 			grep "^[0-9a-f]\{16,\} " out || :
 		} >out.objectlist &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 31/39] bundle: add new version for use with SHA-256
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (29 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  5:31   ` Eric Sunshine
  2020-07-23  1:09 ` [PATCH v3 32/39] setup: add support for reading extensions.objectformat brian m. carlson
                   ` (7 subsequent siblings)
  38 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor

Currently we detect the hash algorithm in use by the length of the
object ID.  This is inelegant and prevents us from using a different
hash algorithm that is also 256 bits in length.

Since we cannot extend the v2 format in a backward-compatible way, let's
add a v3 format, which is identical, except for the addition of
capabilities, which are prefixed by an at sign.  We add "object-format"
as the only capability and reject unknown capabilities, since we do not
have a network connection and therefore cannot negotiate with the other
side.

For compatibility, default to the v2 format for SHA-1 and require v3
for SHA-256.

In t5510, always use format v3 so we can be sure we produce consistent
results across hash algorithms.  Note here that head -n N lists the top
N lines, whereas we want to check only the given line, so while we're at
it, switch to use sed to make sure we're checking only the line we care
about for a match.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 Documentation/git-bundle.txt              |  9 ++-
 Documentation/technical/bundle-format.txt | 30 +++++++-
 builtin/bundle.c                          |  5 +-
 bundle.c                                  | 85 +++++++++++++++++------
 bundle.h                                  |  4 +-
 t/t5510-fetch.sh                          | 11 +--
 t/t5607-clone-bundle.sh                   | 29 ++++++++
 7 files changed, 142 insertions(+), 31 deletions(-)

diff --git a/Documentation/git-bundle.txt b/Documentation/git-bundle.txt
index d34b0964be..53804cad4b 100644
--- a/Documentation/git-bundle.txt
+++ b/Documentation/git-bundle.txt
@@ -9,7 +9,8 @@ git-bundle - Move objects and refs by archive
 SYNOPSIS
 --------
 [verse]
-'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] <file> <git-rev-list-args>
+'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied]
+		    [--version=<version>] <file> <git-rev-list-args>
 'git bundle' verify [-q | --quiet] <file>
 'git bundle' list-heads <file> [<refname>...]
 'git bundle' unbundle <file> [<refname>...]
@@ -102,6 +103,12 @@ unbundle <file>::
 	is activated.  Unlike --all-progress this flag doesn't actually
 	force any progress display by itself.
 
+--version=<version>::
+	Specify the bundle version.  Version 2 is the older format and can only be
+	used with SHA-1 repositories; the newer version 3 contains capabilities that
+	permit extensions. The default is the oldest supported format, based on the
+	hash algorithm in use.
+
 -q::
 --quiet::
 	This flag makes the command not to report its progress
diff --git a/Documentation/technical/bundle-format.txt b/Documentation/technical/bundle-format.txt
index 0e828151a5..01b76e6be6 100644
--- a/Documentation/technical/bundle-format.txt
+++ b/Documentation/technical/bundle-format.txt
@@ -7,6 +7,8 @@ The Git bundle format is a format that represents both refs and Git objects.
 We will use ABNF notation to define the Git bundle format. See
 protocol-common.txt for the details.
 
+A v2 bundle looks like this:
+
 ----
 bundle    = signature *prerequisite *reference LF pack
 signature = "# v2 git bundle" LF
@@ -18,9 +20,28 @@ reference    = obj-id SP refname LF
 pack         = ... ; packfile
 ----
 
+A v3 bundle looks like this:
+
+----
+bundle    = signature *capability *prerequisite *reference LF pack
+signature = "# v3 git bundle" LF
+
+capability   = "@" key ["=" value] LF
+prerequisite = "-" obj-id SP comment LF
+comment      = *CHAR
+reference    = obj-id SP refname LF
+key          = 1*(ALPHA / DIGIT / "-")
+value        = *(%01-09 / %0b-FF)
+
+pack         = ... ; packfile
+----
+
 == Semantics
 
-A Git bundle consists of three parts.
+A Git bundle consists of four parts.
+
+* "Capabilities", which are only in the v3 format, indicate functionality that
+	the bundle requires to be read properly.
 
 * "Prerequisites" lists the objects that are NOT included in the bundle and the
   reader of the bundle MUST already have, in order to use the data in the
@@ -46,3 +67,10 @@ put any string here. The reader of the bundle MUST ignore the comment.
 Note that the prerequisites does not represent a shallow-clone boundary. The
 semantics of the prerequisites and the shallow-clone boundaries are different,
 and the Git bundle v2 format cannot represent a shallow clone repository.
+
+== Capabilities
+
+Because there is no opportunity for negotiation, unknown capabilities cause 'git
+bundle' to abort.  The only known capability is `object-format`, which specifies
+the hash algorithm in use, and can take the same values as the
+`extensions.objectFormat` configuration value.
diff --git a/builtin/bundle.c b/builtin/bundle.c
index f049d27a14..e1a85e7dcc 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -60,6 +60,7 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
 	int all_progress_implied = 0;
 	int progress = isatty(STDERR_FILENO);
 	struct argv_array pack_opts;
+	int version = -1;
 
 	struct option options[] = {
 		OPT_SET_INT('q', "quiet", &progress,
@@ -71,6 +72,8 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
 		OPT_BOOL(0, "all-progress-implied",
 			 &all_progress_implied,
 			 N_("similar to --all-progress when progress meter is shown")),
+		OPT_INTEGER(0, "version", &version,
+			    N_("specify bundle format version")),
 		OPT_END()
 	};
 	const char* bundle_file;
@@ -91,7 +94,7 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
 
 	if (!startup_info->have_repository)
 		die(_("Need a repository to create a bundle."));
-	return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts);
+	return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version);
 }
 
 static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
diff --git a/bundle.c b/bundle.c
index 2a0d744d3f..5c1cc8f4a8 100644
--- a/bundle.c
+++ b/bundle.c
@@ -12,7 +12,16 @@
 #include "refs.h"
 #include "argv-array.h"
 
-static const char bundle_signature[] = "# v2 git bundle\n";
+
+static const char v2_bundle_signature[] = "# v2 git bundle\n";
+static const char v3_bundle_signature[] = "# v3 git bundle\n";
+static struct {
+	int version;
+	const char *signature;
+} bundle_sigs[] = {
+	{ 2, v2_bundle_signature },
+	{ 3, v3_bundle_signature },
+};
 
 static void add_to_ref_list(const struct object_id *oid, const char *name,
 		struct ref_list *list)
@@ -23,15 +32,30 @@ static void add_to_ref_list(const struct object_id *oid, const char *name,
 	list->nr++;
 }
 
-static const struct git_hash_algo *detect_hash_algo(struct strbuf *buf)
+static int parse_capability(struct bundle_header *header, const char *capability)
 {
-	size_t len = strcspn(buf->buf, " \n");
-	int algo;
+	const char *arg;
+	if (skip_prefix(capability, "object-format=", &arg)) {
+		int algo = hash_algo_by_name(arg);
+		if (algo == GIT_HASH_UNKNOWN)
+			return error(_("unable to detect hash algorithm"));
+		header->hash_algo = &hash_algos[algo];
+		return 0;
+	}
+	return error(_("unknown capability '%s'"), capability);
+}
 
-	algo = hash_algo_by_length(len / 2);
-	if (algo == GIT_HASH_UNKNOWN)
-		return NULL;
-	return &hash_algos[algo];
+static int parse_bundle_signature(struct bundle_header *header, const char *line)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) {
+		if (!strcmp(line, bundle_sigs[i].signature)) {
+			header->version = bundle_sigs[i].version;
+			return 0;
+		}
+	}
+	return -1;
 }
 
 static int parse_bundle_header(int fd, struct bundle_header *header,
@@ -42,14 +66,16 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
 
 	/* The bundle header begins with the signature */
 	if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
-	    strcmp(buf.buf, bundle_signature)) {
+	    parse_bundle_signature(header, buf.buf)) {
 		if (report_path)
-			error(_("'%s' does not look like a v2 bundle file"),
+			error(_("'%s' does not look like a v2 or v3 bundle file"),
 			      report_path);
 		status = -1;
 		goto abort;
 	}
 
+	header->hash_algo = the_hash_algo;
+
 	/* The bundle header ends with an empty line */
 	while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
 	       buf.len && buf.buf[0] != '\n') {
@@ -57,21 +83,21 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
 		int is_prereq = 0;
 		const char *p;
 
+		if (header->version == 3 && *buf.buf == '@') {
+			buf.buf[--buf.len] = '\0';
+			if (parse_capability(header, buf.buf + 1)) {
+				status = -1;
+				break;
+			}
+			continue;
+		}
+
 		if (*buf.buf == '-') {
 			is_prereq = 1;
 			strbuf_remove(&buf, 0, 1);
 		}
 		strbuf_rtrim(&buf);
 
-		if (!header->hash_algo) {
-			header->hash_algo = detect_hash_algo(&buf);
-			if (!header->hash_algo) {
-				error(_("unknown hash algorithm length"));
-				status = -1;
-				break;
-			}
-		}
-
 		/*
 		 * Tip lines have object name, SP, and refname.
 		 * Prerequisites have object name that is optionally
@@ -449,13 +475,14 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 }
 
 int create_bundle(struct repository *r, const char *path,
-		  int argc, const char **argv, struct argv_array *pack_options)
+		  int argc, const char **argv, struct argv_array *pack_options, int version)
 {
 	struct lock_file lock = LOCK_INIT;
 	int bundle_fd = -1;
 	int bundle_to_stdout;
 	int ref_count = 0;
 	struct rev_info revs;
+	int default_version = the_hash_algo == &hash_algos[GIT_HASH_SHA1] ? 2 : 3;
 
 	bundle_to_stdout = !strcmp(path, "-");
 	if (bundle_to_stdout)
@@ -464,8 +491,22 @@ int create_bundle(struct repository *r, const char *path,
 		bundle_fd = hold_lock_file_for_update(&lock, path,
 						      LOCK_DIE_ON_ERROR);
 
-	/* write signature */
-	write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
+	if (version == -1)
+		version = default_version;
+
+	if (version < 2 || version > 3) {
+		die(_("unsupported bundle version %d"), version);
+	} else if (version < default_version) {
+		die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name);
+	} else if (version == 2) {
+		write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature));
+	} else {
+		const char *capability = "@object-format=";
+		write_or_die(bundle_fd, v3_bundle_signature, strlen(v3_bundle_signature));
+		write_or_die(bundle_fd, capability, strlen(capability));
+		write_or_die(bundle_fd, the_hash_algo->name, strlen(the_hash_algo->name));
+		write_or_die(bundle_fd, "\n", 1);
+	}
 
 	/* init revs to list objects for pack-objects later */
 	save_commit_buffer = 0;
diff --git a/bundle.h b/bundle.h
index 2dc9442024..70c84cab08 100644
--- a/bundle.h
+++ b/bundle.h
@@ -13,6 +13,7 @@ struct ref_list {
 };
 
 struct bundle_header {
+	unsigned version;
 	struct ref_list prerequisites;
 	struct ref_list references;
 	const struct git_hash_algo *hash_algo;
@@ -21,7 +22,8 @@ struct bundle_header {
 int is_bundle(const char *path, int quiet);
 int read_bundle_header(const char *path, struct bundle_header *header);
 int create_bundle(struct repository *r, const char *path,
-		  int argc, const char **argv, struct argv_array *pack_options);
+		  int argc, const char **argv, struct argv_array *pack_options,
+		  int version);
 int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
 #define BUNDLE_VERBOSE 1
 int unbundle(struct repository *r, struct bundle_header *header,
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index a66dbe0bde..2039a2b352 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -281,15 +281,16 @@ test_expect_success 'create bundle 1' '
 	cd "$D" &&
 	echo >file updated again by origin &&
 	git commit -a -m "tip" &&
-	git bundle create bundle1 master^..master
+	git bundle create --version=3 bundle1 master^..master
 '
 
 test_expect_success 'header of bundle looks right' '
 	head -n 4 "$D"/bundle1 &&
-	head -n 1 "$D"/bundle1 | grep "^#" &&
-	head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
-	head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
-	head -n 4 "$D"/bundle1 | grep "^$"
+	sed -n -e 1p "$D"/bundle1 | grep "^#" &&
+	sed -n -e 2p "$D"/bundle1 | grep "^@object-format=" &&
+	sed -n -e 3p "$D"/bundle1 | grep "^-$OID_REGEX " &&
+	sed -n -e 4p "$D"/bundle1 | grep "^$OID_REGEX " &&
+	sed -n -e 5p "$D"/bundle1 | grep "^$"
 '
 
 test_expect_success 'create bundle 2' '
diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
index 6d5a977fcb..9d6d0eebb1 100755
--- a/t/t5607-clone-bundle.sh
+++ b/t/t5607-clone-bundle.sh
@@ -4,6 +4,10 @@ test_description='some bundle related tests'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
+	test_oid_cache <<-EOF &&
+	version sha1:2
+	version sha256:3
+	EOF
 	test_commit initial &&
 	test_tick &&
 	git tag -m tag tag &&
@@ -94,4 +98,29 @@ test_expect_success 'fetch SHA-1 from bundle' '
 	git fetch --no-tags foo/tip.bundle "$(cat hash)"
 '
 
+test_expect_success 'git bundle uses expected default format' '
+	git bundle create bundle HEAD^.. &&
+	head -n1 bundle | grep "^# v$(test_oid version) git bundle$"
+'
+
+test_expect_success 'git bundle v3 has expected contents' '
+	git branch side HEAD &&
+	git bundle create --version=3 bundle HEAD^..side &&
+	head -n2 bundle >actual &&
+	cat >expect <<-EOF &&
+	# v3 git bundle
+	@object-format=$(test_oid algo)
+	EOF
+	test_cmp actual expect &&
+	git bundle verify bundle
+'
+
+test_expect_success 'git bundle v3 rejects unknown extensions' '
+	head -n2 bundle >new &&
+	echo "@unknown=silly" >>new &&
+	sed "1,2d" bundle >>new &&
+	test_must_fail git bundle verify new 2>output &&
+	test_i18ngrep "unknown capability .unknown=silly." output
+'
+
 test_done

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 32/39] setup: add support for reading extensions.objectformat
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (30 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 31/39] bundle: add new version for use with SHA-256 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  2:04   ` Junio C Hamano
  2020-07-23  1:09 ` [PATCH v3 33/39] Enable SHA-256 support by default brian m. carlson
                   ` (6 subsequent siblings)
  38 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

The transition plan specifies extensions.objectFormat as the indication
that we're using a given hash in a certain repo.  Read this as one of
the extensions we support.  If the user has specified an invalid value,
fail.

Ensure that we reject the extension if the repository format version is
0.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 setup.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/setup.c b/setup.c
index 3a81307602..94e68bb4f4 100644
--- a/setup.c
+++ b/setup.c
@@ -470,7 +470,16 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
 			data->partial_clone = xstrdup(value);
 		} else if (!strcmp(ext, "worktreeconfig"))
 			data->worktree_config = git_config_bool(var, value);
-		else
+		else if (!strcmp(ext, "objectformat")) {
+			int format;
+
+			if (!value)
+				return config_error_nonbool(var);
+			format = hash_algo_by_name(value);
+			if (format == GIT_HASH_UNKNOWN)
+				return error("invalid value for 'extensions.objectformat'");
+			data->hash_algo = format;
+		} else
 			string_list_append(&data->unknown_extensions, ext);
 	}
 
@@ -613,6 +622,11 @@ int verify_repository_format(const struct repository_format *format,
 		return -1;
 	}
 
+	if (format->version <= 0 && format->hash_algo != GIT_HASH_SHA1) {
+		strbuf_addstr(err, _("extensions.objectFormat is not valid in repo v0"));
+		return -1;
+	}
+
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 33/39] Enable SHA-256 support by default
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (31 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 32/39] setup: add support for reading extensions.objectformat brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 34/39] t: add test_oid option to select hash algorithm brian m. carlson
                   ` (5 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Now that the we have a complete SHA-256 implementation in Git, let's
enable it so people can use it.  Remove the ENABLE_SHA256 define
constant everywhere it's used.  Add tests for initializing a repository
with SHA-256.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/init-db.c |  5 -----
 config.mak.dev    |  2 --
 repository.c      |  4 ----
 t/t0001-init.sh   | 29 +++++++++++++++++++++++++++++
 4 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index cee64823cb..f70076d38e 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -183,11 +183,6 @@ void initialize_repository_version(int hash_algo)
 	char repo_version_string[10];
 	int repo_version = GIT_REPO_VERSION;
 
-#ifndef ENABLE_SHA256
-	if (hash_algo != GIT_HASH_SHA1)
-		die(_("The hash algorithm %s is not supported in this build."), hash_algos[hash_algo].name);
-#endif
-
 	if (hash_algo != GIT_HASH_SHA1)
 		repo_version = GIT_REPO_VERSION_READ;
 
diff --git a/config.mak.dev b/config.mak.dev
index cd4a82a9eb..89b218d11a 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -16,8 +16,6 @@ DEVELOPER_CFLAGS += -Wstrict-prototypes
 DEVELOPER_CFLAGS += -Wunused
 DEVELOPER_CFLAGS += -Wvla
 
-DEVELOPER_CFLAGS += -DENABLE_SHA256
-
 ifndef COMPILER_FEATURES
 COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
 endif
diff --git a/repository.c b/repository.c
index 6f7f6f002b..a4174ddb06 100644
--- a/repository.c
+++ b/repository.c
@@ -89,10 +89,6 @@ void repo_set_gitdir(struct repository *repo,
 void repo_set_hash_algo(struct repository *repo, int hash_algo)
 {
 	repo->hash_algo = &hash_algos[hash_algo];
-#ifndef ENABLE_SHA256
-	if (hash_algo != GIT_HASH_SHA1)
-		die(_("The hash algorithm %s is not supported in this build."), repo->hash_algo->name);
-#endif
 }
 
 /*
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 6d2467995e..10ed9d9235 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -441,6 +441,35 @@ test_expect_success 're-init from a linked worktree' '
 	)
 '
 
+test_expect_success 'init honors GIT_DEFAULT_HASH' '
+	GIT_DEFAULT_HASH=sha1 git init sha1 &&
+	git -C sha1 rev-parse --show-object-format >actual &&
+	echo sha1 >expected &&
+	test_cmp expected actual &&
+	GIT_DEFAULT_HASH=sha256 git init sha256 &&
+	git -C sha256 rev-parse --show-object-format >actual &&
+	echo sha256 >expected &&
+	test_cmp expected actual
+'
+
+test_expect_success 'init honors --object-format' '
+	git init --object-format=sha256 explicit &&
+	git -C explicit rev-parse --show-object-format >actual &&
+	echo sha256 >expected &&
+	test_cmp expected actual
+'
+
+test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
+	git init --object-format=sha256 explicit-v0 &&
+	git -C explicit-v0 config core.repositoryformatversion 0 &&
+	test_must_fail git -C explicit-v0 rev-parse --show-object-format
+'
+
+test_expect_success 'init rejects attempts to initialize with different hash' '
+	test_must_fail git -C sha1 init --object-format=sha256 &&
+	test_must_fail git -C sha256 init --object-format=sha1
+'
+
 test_expect_success MINGW 'core.hidedotfiles = false' '
 	git config --global core.hidedotfiles false &&
 	rm -rf newdir &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 34/39] t: add test_oid option to select hash algorithm
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (32 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 33/39] Enable SHA-256 support by default brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  4:51   ` Eric Sunshine
  2020-07-23  1:09 ` [PATCH v3 35/39] t: allow testing different hash algorithms via environment brian m. carlson
                   ` (4 subsequent siblings)
  38 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

In some tests, we have data files which are written with a particular
hash algorithm. Instead of keeping two copies of the test files, we can
keep one, and translate the value on the fly.

In order to do so, we'll need to read both the source algorithm and the
current algorithm, so add an optional flag to the test_oid helper that
lets us read look up a value for a specified hash algorithm. This should
not cause any conflicts with existing tests, since key arguments to
test_oid are allowed to contains only shell identifier characters.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t0000-basic.sh        | 11 +++++++++++
 t/test-lib-functions.sh | 12 +++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 2ff176cd5d..47d6b502c2 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
 	test "$hexsz" -eq 64
 '
 
+test_expect_success 'test_oid can look up data a specified algorithm' '
+	rawsz="$(test_oid --hash=sha1 rawsz)" &&
+	hexsz="$(test_oid --hash=sha1 hexsz)" &&
+	test "$rawsz" -eq 20 &&
+	test "$hexsz" -eq 40 &&
+	rawsz="$(test_oid --hash=sha256 rawsz)" &&
+	hexsz="$(test_oid --hash=sha256 hexsz)" &&
+	test "$rawsz" -eq 32 &&
+	test "$hexsz" -eq 64
+'
+
 test_expect_success 'test_bool_env' '
 	(
 		sane_unset envvar &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 3103be8a32..d243ff43f3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1468,7 +1468,17 @@ test_oid_cache () {
 # Look up a per-hash value based on a key ($1).  The value must have been loaded
 # by test_oid_init or test_oid_cache.
 test_oid () {
-	local var="test_oid_${test_hash_algo}_$1" &&
+	local algo="${test_hash_algo}" &&
+
+	case "$1" in
+		--hash=*)
+			algo="${1#--hash=}" &&
+			shift;;
+		*)
+			;;
+	esac &&
+
+	local var="test_oid_${algo}_$1" &&
 
 	# If the variable is unset, we must be missing an entry for this
 	# key-hash pair, so exit with an error.

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 35/39] t: allow testing different hash algorithms via environment
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (33 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 34/39] t: add test_oid option to select hash algorithm brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 36/39] t: make SHA1 prerequisite depend on default hash brian m. carlson
                   ` (3 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

To allow developers to run the testsuite with a different algorithm than
the default, provide an environment variable, GIT_TEST_DEFAULT_HASH, to
specify the algorithm to use. Compute the fixed constants using
test_oid. Move the constant initialization down below the point where
test-lib-functions.sh is loaded so the functions are defined.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/test-lib-functions.sh | 4 +---
 t/test-lib.sh           | 3 +++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d243ff43f3..8848ad568a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1417,9 +1417,7 @@ test_set_hash () {
 
 # Detect the hash algorithm in use.
 test_detect_hash () {
-	# Currently we only support SHA-1, but in the future this function will
-	# actually detect the algorithm in use.
-	test_hash_algo='sha1'
+	test_hash_algo="${GIT_TEST_DEFAULT_HASH:-sha1}"
 }
 
 # Load common hash metadata and common placeholder object IDs for use with
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 618a7c8d5b..307bb2207e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -452,6 +452,9 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
 export EDITOR
 
+GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}"
+export GIT_DEFAULT_HASH
+
 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
 GIT_TRACE_BARE=1
 export GIT_TRACE_BARE

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 36/39] t: make SHA1 prerequisite depend on default hash
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (34 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 35/39] t: allow testing different hash algorithms via environment brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 37/39] ci: run tests with SHA-256 brian m. carlson
                   ` (2 subsequent siblings)
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Currently, the SHA1 prerequisite depends on the output of git
hash-object.  However, in order for that to produce sane behavior, we
must be in a repository.  If we are not, the default will remain SHA-1,
and we'll produce wrong results if we're using SHA-256 for the testsuite
but the test assertion starts when we're not in a repository.

Check the environment variable we use for this purpose, leaving it to
default to SHA-1 if none is specified.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/test-lib.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 307bb2207e..ea2d308f62 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1689,7 +1689,8 @@ test_lazy_prereq CURL '
 # which will not work with other hash algorithms and tests that work but don't
 # test anything meaningful (e.g. special values which cause short collisions).
 test_lazy_prereq SHA1 '
-	test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+	test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+	{ test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"; }
 '
 
 test_lazy_prereq REBASE_P '

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 37/39] ci: run tests with SHA-256
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (35 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 36/39] t: make SHA1 prerequisite depend on default hash brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 38/39] docs: add documentation for extensions.objectFormat brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 39/39] t: remove test_oid_init in tests brian m. carlson
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Now that we have Git supporting SHA-256, we'd like to make sure that we
don't regress that state.  Unfortunately, it's easy to do so, so to
help, let's add code to run one of our CI jobs with SHA-256 as the
default hash.  This will help us detect any problems that may occur.

We pick the linux-clang job because it's relatively fast and the
linux-gcc job already runs the testsuite twice.  We want our tests to
run as fast as possible, so we wouldn't want to add a third run to the
linux-gcc job.  To make sure we properly exercise the code, let's run
the tests in the default mode (SHA-1) first and then run a second time
with SHA-256.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 ci/run-build-and-tests.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh
index 17e25aade9..a1a6a28791 100755
--- a/ci/run-build-and-tests.sh
+++ b/ci/run-build-and-tests.sh
@@ -24,6 +24,11 @@ linux-gcc)
 	export GIT_TEST_ADD_I_USE_BUILTIN=1
 	make test
 	;;
+linux-clang)
+	make test
+	export GIT_TEST_DEFAULT_HASH=sha256
+	make test
+	;;
 linux-gcc-4.8)
 	# Don't run the tests; we only care about whether Git can be
 	# built with GCC 4.8, as it errors out on some undesired (C99)

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 38/39] docs: add documentation for extensions.objectFormat
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (36 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 37/39] ci: run tests with SHA-256 brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  2020-07-23  1:09 ` [PATCH v3 39/39] t: remove test_oid_init in tests brian m. carlson
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Document the extensions.objectFormat config setting.  Warn users not to
modify it themselves.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 Documentation/config.txt            | 2 ++
 Documentation/config/extensions.txt | 8 ++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 Documentation/config/extensions.txt

diff --git a/Documentation/config.txt b/Documentation/config.txt
index ef0768b91a..3042d80978 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -348,6 +348,8 @@ include::config/diff.txt[]
 
 include::config/difftool.txt[]
 
+include::config/extensions.txt[]
+
 include::config/fastimport.txt[]
 
 include::config/feature.txt[]
diff --git a/Documentation/config/extensions.txt b/Documentation/config/extensions.txt
new file mode 100644
index 0000000000..e97a78bdd6
--- /dev/null
+++ b/Documentation/config/extensions.txt
@@ -0,0 +1,8 @@
+extensions.objectFormat::
+	Specify the hash algorithm to use.  The acceptable values are `sha1` and
+	`sha256`.  If not specified, `sha1` is assumed.  It is an error to specify
+	this key unless `core.repositoryformatversion` is 1.
++
+Note that this setting should only be set by linkgit:git-init[1] or
+linkgit:git-clone[1].  Trying to change it after initialization will not
+work and will produce hard-to-diagnose issues.

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH v3 39/39] t: remove test_oid_init in tests
  2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
                   ` (37 preceding siblings ...)
  2020-07-23  1:09 ` [PATCH v3 38/39] docs: add documentation for extensions.objectFormat brian m. carlson
@ 2020-07-23  1:09 ` brian m. carlson
  38 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  1:09 UTC (permalink / raw)
  To: git

Now that we call test_oid_init in the setup for all test scripts,
there's no point in calling it individually.  Remove all of the places
where we've done so to help keep tests tidy.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/lib-pack.sh                          | 3 ---
 t/lib-submodule-update.sh              | 1 -
 t/t0000-basic.sh                       | 4 ----
 t/t1006-cat-file.sh                    | 2 --
 t/t1050-large.sh                       | 1 -
 t/t1410-reflog.sh                      | 1 -
 t/t1450-fsck.sh                        | 1 -
 t/t1500-rev-parse.sh                   | 1 -
 t/t3305-notes-fanout.sh                | 1 -
 t/t3308-notes-merge.sh                 | 1 -
 t/t3404-rebase-interactive.sh          | 1 -
 t/t3600-rm.sh                          | 1 -
 t/t3800-mktag.sh                       | 1 -
 t/t4002-diff-basic.sh                  | 2 --
 t/t4027-diff-submodule.sh              | 1 -
 t/t4134-apply-submodule.sh             | 1 -
 t/t4200-rerere.sh                      | 1 -
 t/t4211-line-log.sh                    | 1 -
 t/t5300-pack-object.sh                 | 3 +--
 t/t5302-pack-index.sh                  | 1 -
 t/t5313-pack-bounds-checks.sh          | 1 -
 t/t5318-commit-graph.sh                | 3 +--
 t/t5319-multi-pack-index.sh            | 1 -
 t/t5324-split-commit-graph.sh          | 1 -
 t/t5504-fetch-receive-strict.sh        | 1 -
 t/t5530-upload-pack-error.sh           | 1 -
 t/t5562-http-backend-content-length.sh | 1 -
 t/t5702-protocol-v2.sh                 | 1 -
 t/t5703-upload-pack-ref-in-want.sh     | 1 -
 t/t6006-rev-list-format.sh             | 1 -
 t/t6301-for-each-ref-errors.sh         | 1 -
 t/t6501-freshen-objects.sh             | 4 ----
 t/t7003-filter-branch.sh               | 1 -
 t/t8002-blame.sh                       | 4 ----
 t/t8003-blame-corner-cases.sh          | 2 --
 t/t9301-fast-import-notes.sh           | 1 -
 t/t9350-fast-export.sh                 | 2 --
 37 files changed, 2 insertions(+), 54 deletions(-)

diff --git a/t/lib-pack.sh b/t/lib-pack.sh
index 0c799d53c6..bb8938ccbe 100644
--- a/t/lib-pack.sh
+++ b/t/lib-pack.sh
@@ -35,8 +35,6 @@ pack_header () {
 # have hardcoded some well-known objects. See the case statements below for the
 # complete list.
 pack_obj () {
-	test_oid_init
-
 	case "$1" in
 	# empty blob
 	$EMPTY_BLOB)
@@ -121,7 +119,6 @@ pack_obj () {
 
 # Compute and append pack trailer to "$1"
 pack_trailer () {
-	test_oid_init &&
 	test-tool $(test_oid algo) -b <"$1" >trailer.tmp &&
 	cat trailer.tmp >>"$1" &&
 	rm -f trailer.tmp
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 07c822c8ff..87a759149f 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -196,7 +196,6 @@ test_git_directory_exists () {
 # the submodule repo if it doesn't exist and configures the most problematic
 # settings for diff.ignoreSubmodules.
 prolog () {
-	test_oid_init &&
 	(test -d submodule_update_repo || create_lib_submodule_repo) &&
 	test_config_global diff.ignoreSubmodules all &&
 	test_config diff.ignoreSubmodules all
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 47d6b502c2..34c64c59f3 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -891,10 +891,6 @@ test_expect_success 'test_atexit is run' "
 	test_path_is_missing also-clean-atexit
 "
 
-test_expect_success 'test_oid setup' '
-	test_oid_init
-'
-
 test_expect_success 'test_oid provides sane info by default' '
 	test_oid zero >actual &&
 	grep "^00*\$" actual &&
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index 43c4be1e5e..2f501d2dc9 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -140,8 +140,6 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
 	test_cmp expect actual
 '
 
-test_oid_init
-
 tree_sha1=$(git write-tree)
 tree_size=$(($(test_oid rawsz) + 13))
 tree_pretty_content="100644 blob $hello_sha1	hello"
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index 6a56d1ca24..61e89a8071 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -12,7 +12,6 @@ file_size () {
 }
 
 test_expect_success setup '
-	test_oid_init &&
 	# clone does not allow us to pass core.bigfilethreshold to
 	# new repos, so set core.bigfilethreshold globally
 	git config --global core.bigfilethreshold 200k &&
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 76d9b744a6..730a43d9dd 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -54,7 +54,6 @@ check_dont_have () {
 }
 
 test_expect_success setup '
-	test_oid_init &&
 	mkdir -p A/B &&
 	echo rat >C &&
 	echo ox >A/D &&
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 344a2aad82..e81f1cbf0e 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -9,7 +9,6 @@ test_description='git fsck random collection of tests
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_oid_init &&
 	git config gc.auto 0 &&
 	git config i18n.commitencoding ISO-8859-1 &&
 	test_commit A fileA one &&
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 603019b541..408b97d5af 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -59,7 +59,6 @@ test_rev_parse () {
 ROOT=$(pwd)
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	mkdir -p sub/dir work &&
 	cp -R .git repo.git
 '
diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh
index d5a94b7174..94c1b02251 100755
--- a/t/t3305-notes-fanout.sh
+++ b/t/t3305-notes-fanout.sh
@@ -31,7 +31,6 @@ all_notes_have_fanout() {
 }
 
 test_expect_success 'tweak test environment' '
-	test_oid_init &&
 	git checkout -b nondeterminism &&
 	test_commit A &&
 	git checkout --orphan with_notes;
diff --git a/t/t3308-notes-merge.sh b/t/t3308-notes-merge.sh
index 790e292966..d69c84c640 100755
--- a/t/t3308-notes-merge.sh
+++ b/t/t3308-notes-merge.sh
@@ -22,7 +22,6 @@ test_expect_success setup '
 	# Copy notes to remote-notes
 	git fetch . refs/notes/*:refs/remote-notes/origin/* &&
 
-	test_oid_init &&
 	test_oid_cache <<-EOF
 	hash4a sha1:5e93d24084d32e1cb61f7070505b9d2530cca987
 	hash3a sha1:8366731eeee53787d2bdf8fc1eff7d94757e8da0
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 2fb2c581cb..9744e88760 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -30,7 +30,6 @@ Initial setup:
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	test_commit A file1 &&
 	test_commit B file1 &&
 	test_commit C file2 &&
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index f2c0168941..efec8d13b6 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -241,7 +241,6 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
-	test_oid_init &&
 	git reset -q --hard &&
 	test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
 	i=0 &&
diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh
index 64dcc5ec28..d696aa4e52 100755
--- a/t/t3800-mktag.sh
+++ b/t/t3800-mktag.sh
@@ -23,7 +23,6 @@ check_verify_failure () {
 # first create a commit, so we have a valid object/type
 # for the tag.
 test_expect_success 'setup' '
-	test_oid_init &&
 	echo Hello >A &&
 	git update-index --add A &&
 	git commit -m "Initial commit" &&
diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh
index cbcdd10464..6a9f010197 100755
--- a/t/t4002-diff-basic.sh
+++ b/t/t4002-diff-basic.sh
@@ -10,8 +10,6 @@ test_description='Test diff raw-output.
 
 . "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh
 
-test_oid_init
-
 test_oid_cache <<\EOF
 aa_1 sha1:ccba72ad3888a3520b39efcf780b9ee64167535d
 aa_1 sha256:9febfbf18197819b2735c45291f138525d2476d59470f98239647544586ba403
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index e29deaf4a5..d7145ccca4 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -6,7 +6,6 @@ test_description='difference in submodules'
 . "$TEST_DIRECTORY"/diff-lib.sh
 
 test_expect_success setup '
-	test_oid_init &&
 	test_tick &&
 	test_create_repo sub &&
 	(
diff --git a/t/t4134-apply-submodule.sh b/t/t4134-apply-submodule.sh
index 99ed4cc546..d1c16ba33c 100755
--- a/t/t4134-apply-submodule.sh
+++ b/t/t4134-apply-submodule.sh
@@ -8,7 +8,6 @@ test_description='git apply submodule tests'
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_oid_init &&
 	cat > create-sm.patch <<EOF &&
 diff --git a/dir/sm b/dir/sm
 new file mode 160000
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 831d424c47..d94d25e4f0 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -25,7 +25,6 @@ test_description='git rerere
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	cat >a1 <<-\EOF &&
 	Some title
 	==========
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index e186c83250..2d1d7b5d19 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -4,7 +4,6 @@ test_description='test log -L'
 . ./test-lib.sh
 
 test_expect_success 'setup (import history)' '
-	test_oid_init &&
 	git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
 	git reset --hard
 '
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index 746cdb626e..cf9f91c941 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -12,8 +12,7 @@ TRASH=$(pwd)
 
 test_expect_success \
     'setup' \
-    'test_oid_init &&
-     rm -f .git/index* &&
+    'rm -f .git/index* &&
      perl -e "print \"a\" x 4096;" > a &&
      perl -e "print \"b\" x 4096;" > b &&
      perl -e "print \"c\" x 4096;" > c &&
diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh
index 8981c9b90e..119494bd64 100755
--- a/t/t5302-pack-index.sh
+++ b/t/t5302-pack-index.sh
@@ -7,7 +7,6 @@ test_description='pack index with 64-bit offsets and object CRC'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	rawsz=$(test_oid rawsz) &&
 	rm -rf .git &&
 	git init &&
diff --git a/t/t5313-pack-bounds-checks.sh b/t/t5313-pack-bounds-checks.sh
index 2a4557efc2..535313e4dc 100755
--- a/t/t5313-pack-bounds-checks.sh
+++ b/t/t5313-pack-bounds-checks.sh
@@ -45,7 +45,6 @@ extended_table () {
 }
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	test_oid_cache <<-EOF
 	oid000 sha1:1485
 	oid000 sha256:4222
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index 26f332d6a3..67f2663c7c 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -10,8 +10,7 @@ test_expect_success 'setup full repo' '
 	cd "$TRASH_DIRECTORY/full" &&
 	git init &&
 	git config core.commitGraph true &&
-	objdir=".git/objects" &&
-	test_oid_init
+	objdir=".git/objects"
 '
 
 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 7214cab36c..7dfff0f8f4 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -29,7 +29,6 @@ midx_read_expect () {
 }
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	test_oid_cache <<-EOF
 	idxoff sha1:2999
 	idxoff sha256:3739
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 269d0964a3..3a63639fbc 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -12,7 +12,6 @@ test_expect_success 'setup repo' '
 	git config gc.writeCommitGraph false &&
 	infodir=".git/objects/info" &&
 	graphdir="$infodir/commit-graphs" &&
-	test_oid_init &&
 	test_oid_cache <<-EOM
 	shallow sha1:1760
 	shallow sha256:2064
diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
index a32efe2b6c..1a16ac4c0d 100755
--- a/t/t5504-fetch-receive-strict.sh
+++ b/t/t5504-fetch-receive-strict.sh
@@ -4,7 +4,6 @@ test_description='fetch/receive strict mode'
 . ./test-lib.sh
 
 test_expect_success 'setup and inject "corrupt or missing" object' '
-	test_oid_init &&
 	echo hello >greetings &&
 	git add greetings &&
 	git commit -m greetings &&
diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh
index 4ce9a9f704..205a2631e7 100755
--- a/t/t5530-upload-pack-error.sh
+++ b/t/t5530-upload-pack-error.sh
@@ -14,7 +14,6 @@ corrupt_repo () {
 }
 
 test_expect_success 'setup and corrupt repository' '
-	test_oid_init &&
 	echo file >file &&
 	git add file &&
 	git rev-parse :file &&
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
index c6ec625497..e5d3d15ba8 100755
--- a/t/t5562-http-backend-content-length.sh
+++ b/t/t5562-http-backend-content-length.sh
@@ -46,7 +46,6 @@ ssize_b100dots() {
 }
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	HTTP_CONTENT_ENCODING="identity" &&
 	export HTTP_CONTENT_ENCODING &&
 	git config http.receivepack true &&
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index 7fc22171e7..5a60fbe3ed 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -13,7 +13,6 @@ start_git_daemon --export-all --enable=receive-pack
 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
 
 test_expect_success 'create repo to be served by git-daemon' '
-	test_oid_init &&
 	git init "$daemon_parent" &&
 	test_commit -C "$daemon_parent" one
 '
diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 748282f058..d9ecf0f4a9 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -43,7 +43,6 @@ write_command () {
 #             \ | /
 #               a
 test_expect_success 'setup repository' '
-	test_oid_init &&
 	test_commit a &&
 	git checkout -b o/foo &&
 	test_commit b &&
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 7e82e43a63..bc95da8a5f 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -32,7 +32,6 @@ changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
 truncate_count=20
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	: >foo &&
 	git add foo &&
 	git config i18n.commitEncoding $test_encoding &&
diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
index d545a725a5..809854fc0c 100755
--- a/t/t6301-for-each-ref-errors.sh
+++ b/t/t6301-for-each-ref-errors.sh
@@ -7,7 +7,6 @@ test_description='for-each-ref errors for broken refs'
 ZEROS=$ZERO_OID
 
 test_expect_success setup '
-	test_oid_init &&
 	MISSING=$(test_oid deadbeef) &&
 	git commit --allow-empty -m "Initial" &&
 	git tag testtag &&
diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh
index 7416ed5ffe..8a3bb4105b 100755
--- a/t/t6501-freshen-objects.sh
+++ b/t/t6501-freshen-objects.sh
@@ -45,10 +45,6 @@ maybe_repack () {
 	fi
 }
 
-test_expect_success 'setup' '
-	test_oid_init
-'
-
 for repack in '' true; do
 	title=${repack:+repack}
 	title=${title:-loose}
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index beeb2b855a..36477cb1f4 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -5,7 +5,6 @@ test_description='git filter-branch'
 . "$TEST_DIRECTORY/lib-gpg.sh"
 
 test_expect_success 'setup' '
-	test_oid_init &&
 	test_commit A &&
 	GIT_COMMITTER_DATE="@0 +0000" GIT_AUTHOR_DATE="@0 +0000" &&
 	test_commit --notick B &&
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 557c886559..aed4a923a3 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,10 +6,6 @@ test_description='git blame'
 PROG='git blame -c'
 . "$TEST_DIRECTORY"/annotate-tests.sh
 
-test_expect_success 'setup' '
-	test_oid_init
-'
-
 test_expect_success 'blame untracked file in empty repo' '
 	>untracked &&
 	test_must_fail git blame untracked
diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
index ebe79aa4ea..b871dd4f86 100755
--- a/t/t8003-blame-corner-cases.sh
+++ b/t/t8003-blame-corner-cases.sh
@@ -6,8 +6,6 @@ test_description='git blame corner cases'
 pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
 
 test_expect_success setup '
-	test_oid_init &&
-
 	echo A A A A A >one &&
 	echo B B B B B >two &&
 	echo C C C C C >tres &&
diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh
index 9d1aaac980..ff3338abc0 100755
--- a/t/t9301-fast-import-notes.sh
+++ b/t/t9301-fast-import-notes.sh
@@ -71,7 +71,6 @@ EOF
 INPUT_END
 
 test_expect_success 'set up master branch' '
-	test_oid_init &&
 	git fast-import <input &&
 	git whatchanged master
 '
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index ba79db6a17..210b9bc4b6 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -7,8 +7,6 @@ test_description='git fast-export'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	test_oid_init &&
-
 	echo break it > file0 &&
 	git add file0 &&
 	test_tick &&

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 32/39] setup: add support for reading extensions.objectformat
  2020-07-23  1:09 ` [PATCH v3 32/39] setup: add support for reading extensions.objectformat brian m. carlson
@ 2020-07-23  2:04   ` Junio C Hamano
  2020-07-23  2:39     ` brian m. carlson
  0 siblings, 1 reply; 52+ messages in thread
From: Junio C Hamano @ 2020-07-23  2:04 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> @@ -613,6 +622,11 @@ int verify_repository_format(const struct repository_format *format,
>  		return -1;
>  	}
>  
> +	if (format->version <= 0 && format->hash_algo != GIT_HASH_SHA1) {
> +		strbuf_addstr(err, _("extensions.objectFormat is not valid in repo v0"));
> +		return -1;
> +	}
> +
>  	return 0;
>  }
>  

By declaring that the repository is invalid if its version is less
than 1 and objectFormat extension defined, we prevent unwanted
upgrading from happening by mistake.

OK.


^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 32/39] setup: add support for reading extensions.objectformat
  2020-07-23  2:04   ` Junio C Hamano
@ 2020-07-23  2:39     ` brian m. carlson
  2020-07-23  4:15       ` Junio C Hamano
  0 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23  2:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 2020-07-23 at 02:04:52, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > @@ -613,6 +622,11 @@ int verify_repository_format(const struct repository_format *format,
> >  		return -1;
> >  	}
> >  
> > +	if (format->version <= 0 && format->hash_algo != GIT_HASH_SHA1) {
> > +		strbuf_addstr(err, _("extensions.objectFormat is not valid in repo v0"));
> > +		return -1;
> > +	}
> > +
> >  	return 0;
> >  }
> >  
> 
> By declaring that the repository is invalid if its version is less
> than 1 and objectFormat extension defined, we prevent unwanted
> upgrading from happening by mistake.

Yes, and more specifically:

* If the repository is v0 and has an objectFormat set, we fail in newer
  versions of Git (i.e., after this series).  Older versions which do
  not support the extension will see breakage (because unknown
  extensions are not fatal in v0), but we hope by adding this check that
  nobody will ever configure a repo this way, since it will be totally
  nonfunctional in this state, regardless of version.
* If the repository is v1 and has an objectFormat set, we work with
  newer Git and everything is great.  Older Git versions fail hard here,
  and the user gets a moderately helpful error message.

v2 of the series just ignored the setting in v0, which would make it
equally broken in older and newer versions, but would provide a less
useful error message (probably about a corrupt index).
-- 
brian m. carlson: Houston, Texas, US

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 32/39] setup: add support for reading extensions.objectformat
  2020-07-23  2:39     ` brian m. carlson
@ 2020-07-23  4:15       ` Junio C Hamano
  2020-07-25  1:59         ` brian m. carlson
  0 siblings, 1 reply; 52+ messages in thread
From: Junio C Hamano @ 2020-07-23  4:15 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

>> By declaring that the repository is invalid if its version is less
>> than 1 and objectFormat extension defined, we prevent unwanted
>> upgrading from happening by mistake.
>
> Yes, and more specifically:
>
> * If the repository is v0 and has an objectFormat set, we fail in newer
>   versions of Git (i.e., after this series).  Older versions which do
>   not support the extension will see breakage (because unknown
>   extensions are not fatal in v0), but we hope by adding this check that
>   nobody will ever configure a repo this way, since it will be totally
>   nonfunctional in this state, regardless of version.
> * If the repository is v1 and has an objectFormat set, we work with
>   newer Git and everything is great.  Older Git versions fail hard here,
>   and the user gets a moderately helpful error message.
>
> v2 of the series just ignored the setting in v0, which would make it
> equally broken in older and newer versions, but would provide a less
> useful error message (probably about a corrupt index).

Peff's 'jk/reject-newer-extensions-in-v0' uses a bit refactored code
to make it easier to add only-v1-and-later extensions while rejecting
them, even if the code knows about them, in v0 repository.  Even
though the mechanism is a bit different, the spirit is quite the
same as this step.

Please double check origin/seen:setup.c to see if I resolved textual
conflicts in a sensible way.

Thanks.

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 34/39] t: add test_oid option to select hash algorithm
  2020-07-23  1:09 ` [PATCH v3 34/39] t: add test_oid option to select hash algorithm brian m. carlson
@ 2020-07-23  4:51   ` Eric Sunshine
  2020-07-23 23:38     ` brian m. carlson
  0 siblings, 1 reply; 52+ messages in thread
From: Eric Sunshine @ 2020-07-23  4:51 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List

On Wed, Jul 22, 2020 at 9:11 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> In some tests, we have data files which are written with a particular
> hash algorithm. Instead of keeping two copies of the test files, we can
> keep one, and translate the value on the fly.
>
> In order to do so, we'll need to read both the source algorithm and the
> current algorithm, so add an optional flag to the test_oid helper that
> lets us read look up a value for a specified hash algorithm. This should

Readers trip over confusing grammar: "lets us read look up a value"

> not cause any conflicts with existing tests, since key arguments to
> test_oid are allowed to contains only shell identifier characters.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
> @@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
> +test_expect_success 'test_oid can look up data a specified algorithm' '

Readers trip over confusing grammar: "can look up data a specified".

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -1468,7 +1468,17 @@ test_oid_cache () {
>  # Look up a per-hash value based on a key ($1).  The value must have been loaded
>  # by test_oid_init or test_oid_cache.
>  test_oid () {

Should the function documentation be updated to talk about the new
--hash option?

> +       case "$1" in
> +               --hash=*)
> +                       algo="${1#--hash=}" &&

Bikeshedding: I wonder if this should be named "--algo"?

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option
  2020-07-23  1:09 ` [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option brian m. carlson
@ 2020-07-23  4:54   ` Eric Sunshine
  0 siblings, 0 replies; 52+ messages in thread
From: Eric Sunshine @ 2020-07-23  4:54 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List

On Wed, Jul 22, 2020 at 9:10 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> Since we're not in a repository here, we need to provide git verify-pack
> help to set things up properly.  git index-pack already knows an
> --object-format option, so let's accept one as well and pass it down to
> our git index-pack invocation.  Since this argument is optional, let's
> dynamically determine the proper location to insert it into the array.
> Finally, let's make t5702 pass the proper argument on down to its git
> verify-pack caller.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
> @@ -7,21 +7,27 @@
> +static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
>  {
> -       const char *argv[] = {"index-pack", NULL, NULL, NULL };
> +       const char *argv[] = {"index-pack", NULL, NULL, NULL, NULL };
> +       int argno = 1;
>
> +       if (hash_algo) {
> +               strbuf_addf(&hash_arg, "--object-format=%s", hash_algo);
> +               argv[argno++] = hash_arg.buf;
> +       }

This seems like a good candidate for 'struct argv_array' (but perhaps
that's too significant a change or out of scope of this patch?).

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 31/39] bundle: add new version for use with SHA-256
  2020-07-23  1:09 ` [PATCH v3 31/39] bundle: add new version for use with SHA-256 brian m. carlson
@ 2020-07-23  5:31   ` Eric Sunshine
  2020-07-23  5:40     ` Eric Sunshine
  2020-07-24  1:11     ` brian m. carlson
  0 siblings, 2 replies; 52+ messages in thread
From: Eric Sunshine @ 2020-07-23  5:31 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List, Junio C Hamano, SZEDER Gábor

On Wed, Jul 22, 2020 at 9:10 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> [...]
> Since we cannot extend the v2 format in a backward-compatible way, let's
> add a v3 format, which is identical, except for the addition of
> capabilities, which are prefixed by an at sign.  We add "object-format"
> as the only capability and reject unknown capabilities, since we do not
> have a network connection and therefore cannot negotiate with the other
> side.
> [...]
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/Documentation/technical/bundle-format.txt b/Documentation/technical/bundle-format.txt
> @@ -7,6 +7,8 @@ The Git bundle format is a format that represents both refs and Git objects.
>  == Semantics
>
> -A Git bundle consists of three parts.
> +A Git bundle consists of four parts.

Rather than having to worry about updating this each time the format
changes, perhaps just say:

    A Git bundle consists of several parts.

> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
> @@ -281,15 +281,16 @@ test_expect_success 'create bundle 1' '
>  test_expect_success 'header of bundle looks right' '
>         head -n 4 "$D"/bundle1 &&
> -       head -n 1 "$D"/bundle1 | grep "^#" &&
> -       head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
> -       head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
> -       head -n 4 "$D"/bundle1 | grep "^$"
> +       sed -n -e 1p "$D"/bundle1 | grep "^#" &&
> +       sed -n -e 2p "$D"/bundle1 | grep "^@object-format=" &&
> +       sed -n -e 3p "$D"/bundle1 | grep "^-$OID_REGEX " &&
> +       sed -n -e 4p "$D"/bundle1 | grep "^$OID_REGEX " &&
> +       sed -n -e 5p "$D"/bundle1 | grep "^$"
>  '

I wonder if it would be simpler and cleaner to do something like this instead:

    cat >expect <<\-EOF &&
    # v3 git bundle
    @object-format=sha256
    -[OID] message
    [OID] refs/head/master

    EOF
    head -n 5 "$D"/bundle1 | sanitize_oid >actual &&
    test_cmp expect actual

where sanitize_oid() is a function which converts a hex OID into the
literal string "[OID]" (or whatever). I believe I've seen you employ
such sanitization functions already in these series in cases when you
want to verify that an OID is present in some output but don't care
about the actual value.

Or perhaps this approach is overkill?

Reading further in this patch, I see that you actually do employ this
technique in a new test you add to t5607, though you don't bother with
OID sanitation in that test.

> diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
> @@ -94,4 +98,29 @@ test_expect_success 'fetch SHA-1 from bundle' '
> +test_expect_success 'git bundle v3 has expected contents' '
> +       git branch side HEAD &&
> +       git bundle create --version=3 bundle HEAD^..side &&
> +       head -n2 bundle >actual &&
> +       cat >expect <<-EOF &&
> +       # v3 git bundle
> +       @object-format=$(test_oid algo)
> +       EOF
> +       test_cmp actual expect &&

I think you want to swap the 'actual' and 'expect' arguments.

> +       git bundle verify bundle
> +'
> +
> +test_expect_success 'git bundle v3 rejects unknown extensions' '
> +       head -n2 bundle >new &&
> +       echo "@unknown=silly" >>new &&
> +       sed "1,2d" bundle >>new &&
> +       test_must_fail git bundle verify new 2>output &&
> +       test_i18ngrep "unknown capability .unknown=silly." output
> +'

I worry about passing binary bundle data through 'sed' like this.
Historically, some 'sed' implementations would drop the last part of a
file if it didn't end with a newline. Even today, not all 'sed'
implementations necessarily pass the binary data through unmolested.
For instance, on Mac OS, 'sed' adds a newline at the end of the file
if the binary bundle blob didn't end with a newline. Perhaps a more
reliable approach would be to use Perl to read the entire bundle in as
a blob, use s/// to munge the @object-format= line into the @unknown=
line, and write it out.

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 31/39] bundle: add new version for use with SHA-256
  2020-07-23  5:31   ` Eric Sunshine
@ 2020-07-23  5:40     ` Eric Sunshine
  2020-07-24  1:11     ` brian m. carlson
  1 sibling, 0 replies; 52+ messages in thread
From: Eric Sunshine @ 2020-07-23  5:40 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List, Junio C Hamano, SZEDER Gábor

On Thu, Jul 23, 2020 at 1:31 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, Jul 22, 2020 at 9:10 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > +test_expect_success 'git bundle v3 rejects unknown extensions' '

By the way, should this be s/extensions/capabilities/ ?

> > +       head -n2 bundle >new &&
> > +       echo "@unknown=silly" >>new &&
> > +       sed "1,2d" bundle >>new &&
> > +       test_must_fail git bundle verify new 2>output &&
> > +       test_i18ngrep "unknown capability .unknown=silly." output
> > +'
>
> I worry about passing binary bundle data through 'sed' like this.

Thinking on this further: Since you are only interested in whether or
not "git bundle verify" correctly complains about the unknown
capabilities, you really don't even need any of the binary bundle data
which follows the header. As such, you could just hand-craft the bogus
bundle, perhaps like this:

    cat >new <<\-EOF &&
    # v3 git bundle
    @object-format=sha256
    @unknown=silly
    EOF
    test_must_fail git bundle verify new 2>output &&
    test_i18ngrep "unknown capability .unknown=silly." output

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 34/39] t: add test_oid option to select hash algorithm
  2020-07-23  4:51   ` Eric Sunshine
@ 2020-07-23 23:38     ` brian m. carlson
  2020-07-23 23:46       ` Eric Sunshine
  0 siblings, 1 reply; 52+ messages in thread
From: brian m. carlson @ 2020-07-23 23:38 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

[-- Attachment #1: Type: text/plain, Size: 2087 bytes --]

On 2020-07-23 at 04:51:32, Eric Sunshine wrote:
> On Wed, Jul 22, 2020 at 9:11 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > In some tests, we have data files which are written with a particular
> > hash algorithm. Instead of keeping two copies of the test files, we can
> > keep one, and translate the value on the fly.
> >
> > In order to do so, we'll need to read both the source algorithm and the
> > current algorithm, so add an optional flag to the test_oid helper that
> > lets us read look up a value for a specified hash algorithm. This should
> 
> Readers trip over confusing grammar: "lets us read look up a value"
> 
> > not cause any conflicts with existing tests, since key arguments to
> > test_oid are allowed to contains only shell identifier characters.
> >
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> > ---
> > diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
> > @@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
> > +test_expect_success 'test_oid can look up data a specified algorithm' '
> 
> Readers trip over confusing grammar: "can look up data a specified".

Yeah, these are both typos.  Will fix.

> > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> > @@ -1468,7 +1468,17 @@ test_oid_cache () {
> >  # Look up a per-hash value based on a key ($1).  The value must have been loaded
> >  # by test_oid_init or test_oid_cache.
> >  test_oid () {
> 
> Should the function documentation be updated to talk about the new
> --hash option?

Sure.

> > +       case "$1" in
> > +               --hash=*)
> > +                       algo="${1#--hash=}" &&
> 
> Bikeshedding: I wonder if this should be named "--algo"?

We already have a use of this in t5515; I appear to have accidentally
sent it in an earlier series.  I can, of course, change it, but I don't
feel strongly that one or the other is better.  If you do feel strongly,
or you think it's confusing, I'm happy to change it.
-- 
brian m. carlson: Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 34/39] t: add test_oid option to select hash algorithm
  2020-07-23 23:38     ` brian m. carlson
@ 2020-07-23 23:46       ` Eric Sunshine
  2020-07-24  0:05         ` Junio C Hamano
  0 siblings, 1 reply; 52+ messages in thread
From: Eric Sunshine @ 2020-07-23 23:46 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List

On Thu, Jul 23, 2020 at 7:39 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> On 2020-07-23 at 04:51:32, Eric Sunshine wrote:
> > On Wed, Jul 22, 2020 at 9:11 PM brian m. carlson
> > <sandals@crustytoothpaste.net> wrote:
> > > +               --hash=*)
> > > +                       algo="${1#--hash=}" &&
> >
> > Bikeshedding: I wonder if this should be named "--algo"?
>
> We already have a use of this in t5515; I appear to have accidentally
> sent it in an earlier series.  I can, of course, change it, but I don't
> feel strongly that one or the other is better.  If you do feel strongly,
> or you think it's confusing, I'm happy to change it.

I don't feel strongly about it and wouldn't insist that it be changed.

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 34/39] t: add test_oid option to select hash algorithm
  2020-07-23 23:46       ` Eric Sunshine
@ 2020-07-24  0:05         ` Junio C Hamano
  0 siblings, 0 replies; 52+ messages in thread
From: Junio C Hamano @ 2020-07-24  0:05 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: brian m. carlson, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Thu, Jul 23, 2020 at 7:39 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
>> On 2020-07-23 at 04:51:32, Eric Sunshine wrote:
>> > On Wed, Jul 22, 2020 at 9:11 PM brian m. carlson
>> > <sandals@crustytoothpaste.net> wrote:
>> > > +               --hash=*)
>> > > +                       algo="${1#--hash=}" &&
>> >
>> > Bikeshedding: I wonder if this should be named "--algo"?
>>
>> We already have a use of this in t5515; I appear to have accidentally
>> sent it in an earlier series.  I can, of course, change it, but I don't
>> feel strongly that one or the other is better.  If you do feel strongly,
>> or you think it's confusing, I'm happy to change it.
>
> I don't feel strongly about it and wouldn't insist that it be changed.

I am in favor of "algo", but let's leave the patch noise outside the
series.  It is something we can do after the dust settles.

And when such a clean-up comes, I'll try to remember pointing out
the case/arms)/esac indentation rule ;-)

Thanks.

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 31/39] bundle: add new version for use with SHA-256
  2020-07-23  5:31   ` Eric Sunshine
  2020-07-23  5:40     ` Eric Sunshine
@ 2020-07-24  1:11     ` brian m. carlson
  1 sibling, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-24  1:11 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Junio C Hamano, SZEDER Gábor

[-- Attachment #1: Type: text/plain, Size: 2035 bytes --]

On 2020-07-23 at 05:31:15, Eric Sunshine wrote:
> Rather than having to worry about updating this each time the format
> changes, perhaps just say:
> 
>     A Git bundle consists of several parts.

Seems prudent.  The reader probably doesn't care exactly how many parts
there are, and if they do, they can count for themselves.

> I wonder if it would be simpler and cleaner to do something like this instead:
> 
>     cat >expect <<\-EOF &&
>     # v3 git bundle
>     @object-format=sha256
>     -[OID] message
>     [OID] refs/head/master
> 
>     EOF
>     head -n 5 "$D"/bundle1 | sanitize_oid >actual &&
>     test_cmp expect actual
> 
> where sanitize_oid() is a function which converts a hex OID into the
> literal string "[OID]" (or whatever). I believe I've seen you employ
> such sanitization functions already in these series in cases when you
> want to verify that an OID is present in some output but don't care
> about the actual value.
> 
> Or perhaps this approach is overkill?
> 
> Reading further in this patch, I see that you actually do employ this
> technique in a new test you add to t5607, though you don't bother with
> OID sanitation in that test.

Sure, I can do that.

> I worry about passing binary bundle data through 'sed' like this.
> Historically, some 'sed' implementations would drop the last part of a
> file if it didn't end with a newline. Even today, not all 'sed'
> implementations necessarily pass the binary data through unmolested.
> For instance, on Mac OS, 'sed' adds a newline at the end of the file
> if the binary bundle blob didn't end with a newline. Perhaps a more
> reliable approach would be to use Perl to read the entire bundle in as
> a blob, use s/// to munge the @object-format= line into the @unknown=
> line, and write it out.

Yeah, I was slightly worried about that, but as you mentioned in the
followup email, it's probably fine to just parse the header and verify
we reject that.
-- 
brian m. carlson: Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH v3 32/39] setup: add support for reading extensions.objectformat
  2020-07-23  4:15       ` Junio C Hamano
@ 2020-07-25  1:59         ` brian m. carlson
  0 siblings, 0 replies; 52+ messages in thread
From: brian m. carlson @ 2020-07-25  1:59 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]

On 2020-07-23 at 04:15:37, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> >> By declaring that the repository is invalid if its version is less
> >> than 1 and objectFormat extension defined, we prevent unwanted
> >> upgrading from happening by mistake.
> >
> > Yes, and more specifically:
> >
> > * If the repository is v0 and has an objectFormat set, we fail in newer
> >   versions of Git (i.e., after this series).  Older versions which do
> >   not support the extension will see breakage (because unknown
> >   extensions are not fatal in v0), but we hope by adding this check that
> >   nobody will ever configure a repo this way, since it will be totally
> >   nonfunctional in this state, regardless of version.
> > * If the repository is v1 and has an objectFormat set, we work with
> >   newer Git and everything is great.  Older Git versions fail hard here,
> >   and the user gets a moderately helpful error message.
> >
> > v2 of the series just ignored the setting in v0, which would make it
> > equally broken in older and newer versions, but would provide a less
> > useful error message (probably about a corrupt index).
> 
> Peff's 'jk/reject-newer-extensions-in-v0' uses a bit refactored code
> to make it easier to add only-v1-and-later extensions while rejecting
> them, even if the code knows about them, in v0 repository.  Even
> though the mechanism is a bit different, the spirit is quite the
> same as this step.
> 
> Please double check origin/seen:setup.c to see if I resolved textual
> conflicts in a sensible way.

Yes, this seems quite sensible, and exactly the resolution I was hoping
for.
-- 
brian m. carlson: Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 52+ messages in thread

end of thread, other threads:[~2020-07-25  1:59 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23  1:09 [PATCH v3 00/39] SHA-256, part 3/3 brian m. carlson
2020-07-23  1:09 ` [PATCH v3 01/39] t: make test-bloom initialize repository brian m. carlson
2020-07-23  1:09 ` [PATCH v3 02/39] t1001: use $ZERO_OID brian m. carlson
2020-07-23  1:09 ` [PATCH v3 03/39] t3305: make hash agnostic brian m. carlson
2020-07-23  1:09 ` [PATCH v3 04/39] t3404: prepare 'short SHA-1 collision' tests for SHA-256 brian m. carlson
2020-07-23  1:09 ` [PATCH v3 05/39] t6100: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 06/39] t6101: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 07/39] t6301: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 08/39] t6500: specify test values for SHA-256 brian m. carlson
2020-07-23  1:09 ` [PATCH v3 09/39] t6501: avoid hard-coded objects brian m. carlson
2020-07-23  1:09 ` [PATCH v3 10/39] t7003: compute appropriate length constant brian m. carlson
2020-07-23  1:09 ` [PATCH v3 11/39] t7063: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 12/39] t7201: abstract away SHA-1-specific constants brian m. carlson
2020-07-23  1:09 ` [PATCH v3 13/39] t7102: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 14/39] t7400: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 15/39] t7405: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 16/39] t7506: avoid checking for SHA-1-specific constants brian m. carlson
2020-07-23  1:09 ` [PATCH v3 17/39] t7508: use $ZERO_OID instead of hard-coded constant brian m. carlson
2020-07-23  1:09 ` [PATCH v3 18/39] t8002: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 19/39] t8003: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 20/39] t8011: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 21/39] t9300: abstract away SHA-1-specific constants brian m. carlson
2020-07-23  1:09 ` [PATCH v3 22/39] t9300: use $ZERO_OID instead of hard-coded object ID brian m. carlson
2020-07-23  1:09 ` [PATCH v3 23/39] t9301: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 24/39] t9350: " brian m. carlson
2020-07-23  1:09 ` [PATCH v3 25/39] t9500: ensure that algorithm info is preserved in config brian m. carlson
2020-07-23  1:09 ` [PATCH v3 26/39] t9700: make hash size independent brian m. carlson
2020-07-23  1:09 ` [PATCH v3 27/39] t5308: make test work with SHA-256 brian m. carlson
2020-07-23  1:09 ` [PATCH v3 28/39] t0410: mark test with SHA1 prerequisite brian m. carlson
2020-07-23  1:09 ` [PATCH v3 29/39] http-fetch: set up git directory before parsing pack hashes brian m. carlson
2020-07-23  1:09 ` [PATCH v3 30/39] builtin/verify-pack: implement an --object-format option brian m. carlson
2020-07-23  4:54   ` Eric Sunshine
2020-07-23  1:09 ` [PATCH v3 31/39] bundle: add new version for use with SHA-256 brian m. carlson
2020-07-23  5:31   ` Eric Sunshine
2020-07-23  5:40     ` Eric Sunshine
2020-07-24  1:11     ` brian m. carlson
2020-07-23  1:09 ` [PATCH v3 32/39] setup: add support for reading extensions.objectformat brian m. carlson
2020-07-23  2:04   ` Junio C Hamano
2020-07-23  2:39     ` brian m. carlson
2020-07-23  4:15       ` Junio C Hamano
2020-07-25  1:59         ` brian m. carlson
2020-07-23  1:09 ` [PATCH v3 33/39] Enable SHA-256 support by default brian m. carlson
2020-07-23  1:09 ` [PATCH v3 34/39] t: add test_oid option to select hash algorithm brian m. carlson
2020-07-23  4:51   ` Eric Sunshine
2020-07-23 23:38     ` brian m. carlson
2020-07-23 23:46       ` Eric Sunshine
2020-07-24  0:05         ` Junio C Hamano
2020-07-23  1:09 ` [PATCH v3 35/39] t: allow testing different hash algorithms via environment brian m. carlson
2020-07-23  1:09 ` [PATCH v3 36/39] t: make SHA1 prerequisite depend on default hash brian m. carlson
2020-07-23  1:09 ` [PATCH v3 37/39] ci: run tests with SHA-256 brian m. carlson
2020-07-23  1:09 ` [PATCH v3 38/39] docs: add documentation for extensions.objectFormat brian m. carlson
2020-07-23  1:09 ` [PATCH v3 39/39] t: remove test_oid_init in tests brian m. carlson

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 NNTP newsgroup(s).