SHA-256, part 3/3
v2 cover SHA-256, part 3/3
This is the final part required for the stage 4 implementation of SHA-256.
Note that the bundle code will necessarily conflict with the fixup patch I sent earlier today because this series removes the code. The correct resolution is to just remove the code altogether. Note that the bundle code is not reachable for SHA-256 because SHA-256 repositories cannot yet be created, so dropping support for SHA-256 bundles in the v2 format does not cause compatibility concerns.
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.
Range-diff below.
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 | 9 ++ 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 | 69 ++++++---- bundle.h | 4 +- ci/run-build-and-tests.sh | 5 + config.mak.dev | 2 - http-fetch.c | 4 +- repository.c | 4 - setup.c | 12 +- 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 | 31 +++++ t/t0410-partial-clone.sh | 2 +- 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 | 9 +- t/t5530-upload-pack-error.sh | 1 - t/t5562-http-backend-content-length.sh | 1 - t/t5607-clone-bundle.sh | 27 ++++ 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, 598 insertions(+), 353 deletions(-) create mode 100644 Documentation/config/extensions.txt
Range-diff against v1:
1: 11bb3918df = 1: 11bb3918df t: make test-bloom initialize repository
2: bff32965d2 = 2: bff32965d2 t1001: use $ZERO_OID
3: 03f49899e0 = 3: 03f49899e0 t3305: make hash agnostic
4: d6c75da18f = 4: d6c75da18f t3404: prepare 'short SHA-1 collision' tests for SHA-256
5: 31cbce9d44 = 5: 31cbce9d44 t6100: make hash size independent
6: bc21adaf33 = 6: bc21adaf33 t6101: make hash size independent
7: 31a1c614cf = 7: 31a1c614cf t6301: make hash size independent
8: 4c19b39507 = 8: 4c19b39507 t6500: specify test values for SHA-256
9: cd43450d20 = 9: cd43450d20 t6501: avoid hard-coded objects
10: 2f7ef3bd9d = 10: 2f7ef3bd9d t7003: compute appropriate length constant
11: 15b046720c ! 11: 96b29887b0 t7063: make hash size independent
@@ t/t7063-status-untracked-cache.sh: test_expect_success 'move two from tracked to
+/dtwo/ $ZERO_OID recurse check_only valid
two
EOF
-- test_cmp ../expect ../actual
-+ test_might_fail test_cmp ../expect ../actual
- '
-
- test_expect_success 'status after the move' '
+ test_cmp ../expect ../actual
@@ t/t7063-status-untracked-cache.sh: EOF
test_expect_success 'verify untracked cache dump' '
test-tool dump-untracked-cache >../actual &&
@@ t/t7063-status-untracked-cache.sh: test_expect_success 'move two from untracked
+/dtwo/ $ZERO_OID recurse check_only valid
two
EOF
-- test_cmp ../expect ../actual
-+ test_might_fail test_cmp ../expect ../actual
- '
-
- test_expect_success 'status after the move' '
+ test_cmp ../expect ../actual
@@ t/t7063-status-untracked-cache.sh: EOF
test_expect_success 'verify untracked cache dump' '
test-tool dump-untracked-cache >../actual &&
12: d1e337a599 = 12: d67c1e49d0 t7201: abstract away SHA-1-specific constants
13: 96f2727d48 = 13: 48b254250b t7102: abstract away SHA-1-specific constants
14: 85c9ac34f0 = 14: cfc96d8181 t7400: make hash size independent
15: 9cbe6d9627 = 15: 187f3bf5c1 t7405: make hash size independent
16: 5aa1be2acf = 16: 0d91991588 t7506: avoid checking for SHA-1-specific constants
17: 62ff93bafd = 17: e22ec03788 t7508: use $ZERO_OID instead of hard-coded constant
18: f7bf7bf486 = 18: bfd9a593a7 t8002: make hash size independent
19: cd7840d3ef = 19: d4ca86e473 t8003: make hash size independent
20: 407be13d21 ! 20: 28d1b7bf0b t8011: make hash size independent @@ Commit message
t8011: make hash size independent
Allow lines which start with either a 40- or 64-character hex object ID,
- to allow for both SHA-1 and NewHash.
+ to allow for both SHA-1 and SHA-256.
21: a29656ccfb = 21: c982602ffa t9300: abstract away SHA-1-specific constants 22: 5c58ffc462 = 22: 503be79740 t9300: use $ZERO_OID instead of hard-coded object ID 23: 60f571ec20 = 23: bdede03ff0 t9301: make hash size independent 24: 89af756277 = 24: a50d67d7bd t9350: make hash size independent 25: a770492eba = 25: acea64aa18 t9500: ensure that algorithm info is preserved in config 26: c9ef0e4de8 ! 26: 0b5bb05dea t9700: make hash size independent
@@ Commit message
t9700: make hash size independent
The Perl test script for t9700 was matching on exactly 40 hex
- characters. With NewHash, we'll have 64 hex-character object IDs.
+ 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
27: 963673a704 = 27: 41a1e3a78f t5308: make test work with SHA-256
28: 10af46914d = 28: 70f77a2508 t0410: mark test with SHA1 prerequisite
29: 25377eac9e = 29: 1c619ed160 http-fetch: set up git directory before parsing pack hashes
30: 52e957865e = 30: cd643a0b1d builtin/verify-pack: implement an --object-format option
-: ---------- > 31: 611ad8ffd0 bundle: add new version for use with SHA-256
31: dcd6a91833 = 32: f299f46406 setup: add support for reading extensions.objectformat
32: 6949426537 = 33: 59652ad4e7 Enable SHA-256 support by default
33: 916458875a = 34: 90d38c1f09 t: add test_oid option to select hash algorithm
34: 361cce1e6a = 35: 8eb68c2895 t: allow testing different hash algorithms via environment
35: 9bdcdfe2a7 ! 36: b0b832f3d8 t: make SHA1 prerequisite depend on default hash
@@ t/test-lib.sh: test_lazy_prereq CURL '
test_lazy_prereq SHA1 '
- test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+ test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
-+ ([ -z "$GIT_DEFAULT_HASH" ] || [ "$GIT_DEFAULT_HASH" = "sha1" ])
++ { test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"; }
'
test_lazy_prereq REBASE_P '
36: 7dbc2a5a58 < -: ---------- ci: run tests with SHA-256
-: ---------- > 37: f6fdad20d2 ci: run tests with SHA-256
37: 1dc23e970b ! 38: dce20fcd6e docs: add documentation for extensions.objectFormat @@ Documentation/config.txt: include::config/diff.txt[]
## Documentation/config/extensions.txt (new) ##
@@
+extensions.objectFormat::
-+ Specify the hash algorithm to use. The acceptable values are sha1
-+ and (if supported) sha256. If not specified, sha1 is assumed.
++ 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.
++
-+Note that this setting should only by set by linkgit:git-init[1] or ++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.
38: f2c01f33d7 = 39: 42d1c5b8d1 t: remove test_oid_init in tests
PATCH v2 1/39 t: make test-bloom initialize repository
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.
--- t/helper/test-bloom.c | 2 ++ 1 file changed, 2 insertions(+)
t/helper/test-bloom.c +2 -0
@@ -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);
PATCH v2 2/39 t1001: use $ZERO_OID
In reply to brian m. carlsonUse $ZERO_OID to make the test hash independent.
--- t/t1091-sparse-checkout-builtin.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t1091-sparse-checkout-builtin.sh +2 -2
@@ -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 &&
PATCH v2 3/39 t3305: make hash agnostic
In reply to brian m. carlsonWhen 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.
--- t/t3305-notes-fanout.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t3305-notes-fanout.sh +2 -1
@@ -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;
PATCH v2 4/39 t3404: prepare 'short SHA-1 collision' tests for SHA-256
In reply to brian m. carlsonFrom: Johannes Schindelin <[email protected]>
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".
--- t/t3404-rebase-interactive.sh | 50 ++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-)
t/t3404-rebase-interactive.sh +41 -9
@@ -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 ) &&
PATCH v2 5/39 t6100: make hash size independent
In reply to brian m. carlsonInstead of hard-coding a constant 40, split the output of rev-list by field.
--- t/t6100-rev-list-in-order.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t6100-rev-list-in-order.sh +2 -2
@@ -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}
PATCH v2 6/39 t6101: make hash size independent
In reply to brian m. carlsonUse $OID_REGEX instead of a hard-coded regular expression.
--- t/t6101-rev-parse-parents.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t6101-rev-parse-parents.sh +1 -1
@@ -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' '
PATCH v2 7/39 t6301: make hash size independent
In reply to brian m. carlsonInstead 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.
--- t/t6301-for-each-ref-errors.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t6301-for-each-ref-errors.sh +2 -1
@@ -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 &&
PATCH v2 8/39 t6500: specify test values for SHA-256
In reply to brian m. carlsonIn 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.
--- t/t6500-gc.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
t/t6500-gc.sh +22 -5
@@ -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 &&
PATCH v2 9/39 t6501: avoid hard-coded objects
In reply to brian m. carlsonThis 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.
--- t/t6501-freshen-objects.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
t/t6501-freshen-objects.sh +11 -7
@@ -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 <[email protected]> 1234 -0000 committer whatever <[email protected]> 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 <[email protected]> 1234 -0000
PATCH v2 10/39 t7003: compute appropriate length constant
In reply to brian m. carlsonInstead of using a specific invalid hard-coded object ID, look one up from the translation table.
--- t/t7003-filter-branch.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
t/t7003-filter-branch.sh +3 -1
@@ -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) '
PATCH v2 11/39 t7063: make hash size independent
In reply to brian m. carlsonUse test_oid instead of hard-coding a fixed size all-zeros object ID.
--- t/t7063-status-untracked-cache.sh | 151 ++++++++++++++++-------------- 1 file changed, 81 insertions(+), 70 deletions(-)
t/t7063-status-untracked-cache.sh +81 -70
@@ -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
PATCH v2 12/39 t7201: abstract away SHA-1-specific constants
In reply to brian m. carlsonAdjust the test so that it computes variables for object IDs instead of using hard-coded hashes.
--- t/t7201-co.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
t/t7201-co.sh +3 -2
@@ -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) &&
PATCH v2 13/39 t7102: abstract away SHA-1-specific constants
In reply to brian m. carlsonAdjust the test so that it computes variables for object IDs instead of using hard-coded hashes.
--- t/t7102-reset.sh | 93 +++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 40 deletions(-)
t/t7102-reset.sh +53 -40
@@ -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 '
PATCH v2 14/39 t7400: make hash size independent
In reply to brian m. carlsonInstead 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.
--- t/t7400-submodule-basic.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
t/t7400-submodule-basic.sh +13 -13
@@ -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 '
PATCH v2 15/39 t7405: make hash size independent
In reply to brian m. carlsonUse $ZERO_OID instead of hard-coding a fixed size all-zeros object ID.
--- t/t7405-submodule-merge.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t7405-submodule-merge.sh +2 -2
@@ -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 &&
PATCH v2 16/39 t7506: avoid checking for SHA-1-specific constants
In reply to brian m. carlsonAdjust 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.
--- t/t7506-status-submodule.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
t/t7506-status-submodule.sh +8 -4
@@ -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:
PATCH v2 17/39 t7508: use $ZERO_OID instead of hard-coded constant
In reply to brian m. carlsonUse the ZERO_OID variable to abbreviate the all-zeros object ID for maintainability and to avoid depending on a specific size for the hash.
--- t/t7508-status.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t7508-status.sh +1 -1
@@ -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 &&
PATCH v2 18/39 t8002: make hash size independent
In reply to brian m. carlsonCompute the length of an object ID instead of of hard-coding 40-based values.
--- t/t8002-blame.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
t/t8002-blame.sh +12 -7
@@ -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' '
PATCH v2 19/39 t8003: make hash size independent
In reply to brian m. carlsonOne 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.
--- t/t8003-blame-corner-cases.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t8003-blame-corner-cases.sh +2 -1
@@ -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 '
PATCH v2 20/39 t8011: make hash size independent
In reply to brian m. carlsonAllow lines which start with either a 40- or 64-character hex object ID, to allow for both SHA-1 and SHA-256.
--- t/t8011-blame-split-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t8011-blame-split-file.sh +1 -1
@@ -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 (.*)/) {
PATCH v2 21/39 t9300: abstract away SHA-1-specific constants
In reply to brian m. carlsonAdjust the test so that it computes variables for object IDs instead of using hard-coded hashes.
--- t/t9300-fast-import.sh | 107 ++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 49 deletions(-)
t/t9300-fast-import.sh +58 -49
@@ -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 &&
PATCH v2 22/39 t9300: use $ZERO_OID instead of hard-coded object ID
In reply to brian m. carlson--- t/t9300-fast-import.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
t/t9300-fast-import.sh +8 -8
@@ -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 '
PATCH v2 23/39 t9301: make hash size independent
In reply to brian m. carlsonInstead 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.
--- t/t9301-fast-import-notes.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
t/t9301-fast-import-notes.sh +7 -7
@@ -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
PATCH v2 24/39 t9350: make hash size independent
In reply to brian m. carlsonThis 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.
--- t/t9350-fast-export.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
t/t9350-fast-export.sh +8 -7
@@ -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
PATCH v2 25/39 t9500: ensure that algorithm info is preserved in config
In reply to brian m. carlsonWhen 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.
--- t/t9500-gitweb-standalone-no-errors.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
t/t9500-gitweb-standalone-no-errors.sh +16 -6
@@ -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"'
PATCH v2 26/39 t9700: make hash size independent
In reply to brian m. carlsonThe 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.
--- t/t9700/test.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/t9700/test.pl +4 -2
@@ -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');
PATCH v2 27/39 t5308: make test work with SHA-256
In reply to brian m. carlsonThis 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.
--- t/lib-pack.sh | 8 ++++++++ t/t5308-pack-detect-duplicates.sh | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)
t/lib-pack.sh +8 -0
@@ -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
t/t5308-pack-detect-duplicates.sh +12 -8
@@ -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.
PATCH v2 28/39 t0410: mark test with SHA1 prerequisite
In reply to brian m. carlsonThis test tries to check that we fail 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. Consequently, even if we removed the check for format version 0, we'd still fail because it's completely acceptable to add extensions to a format version 1 repository.
Add a SHA1 prerequisite to this test.
--- t/t0410-partial-clone.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t0410-partial-clone.sh +1 -1
@@ -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 shallow clone to partial clone must fail with any extension' ' +test_expect_success SHA1 'convert shallow clone to partial clone must fail with any extension' ' rm -fr server client && test_create_repo server && test_commit -C server my_commit 1 &&
PATCH v2 29/39 http-fetch: set up git directory before parsing pack hashes
In reply to brian m. carlsonIn 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(-)
http-fetch.c +2 -2
@@ -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) {
PATCH v2 30/39 builtin/verify-pack: implement an --object-format option
In reply to brian m. carlsonA 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.
--- builtin/verify-pack.c | 25 +++++++++++++++++-------- t/t5702-protocol-v2.sh | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-)
builtin/verify-pack.c +17 -8
@@ -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 ; }
t/t5702-protocol-v2.sh +1 -1
@@ -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 &&
PATCH v2 31/39 bundle: add new version for use with SHA-256
In reply to brian m. carlsonCurrently 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.
--- Documentation/git-bundle.txt | 9 ++- Documentation/technical/bundle-format.txt | 30 +++++++++- builtin/bundle.c | 5 +- bundle.c | 69 +++++++++++++++-------- bundle.h | 4 +- t/t5510-fetch.sh | 9 +-- t/t5607-clone-bundle.sh | 27 +++++++++ 7 files changed, 122 insertions(+), 31 deletions(-)
Documentation/git-bundle.txt +8 -1
@@ -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
Documentation/technical/bundle-format.txt +29 -1
@@ -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.
builtin/bundle.c +4 -1
@@ -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) {
bundle.c +46 -23
126 lines not on this page · raw message
bundle.h +3 -1
@@ -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,
t/t5510-fetch.sh +5 -4
@@ -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 "^$" + 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 "^$" ' test_expect_success 'create bundle 2' '
t/t5607-clone-bundle.sh +27 -0
@@ -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,27 @@ 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 && + echo "# v3 git bundle" >expected && + echo "@object-format=$(test_oid algo)" >>expected && + test_cmp actual expected && + 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 && + test_must_fail git bundle verify new 2>output && + grep "unknown capability .unknown=silly." output +' + test_done
Re: [PATCH v2 31/39] bundle: add new version for use with SHA-256
Quoted 11 lines · brian m. carlson
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.
Quoted 8 lines
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.
Signed-off-by brian m. carlson <[email protected]>---
Wow, that was quick ;-)
Documentation/technical/bundle-format.txt reference = obj-id SP refname LF · line 34
Quoted 3 lines
Documentation/technical/bundle-format.txt +3
-0+capability = "@" key ["=" value] LF +key = 1*(ALPHA / DIGIT / "-") +value = *(%01-09 / %0b-FF)
OK.
Quoted 20 lines
builtin/bundle.c +3
-0@@ -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;
builtin/bundle.c static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { · line 97
Quoted 5 lines
builtin/bundle.c +1
-1@@ -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);
OK, so the builtin command itself does not know how the default version is picked; it is left to the code in bundle.c which is at a lower layer. Makes sense.
Quoted 20 lines
bundle.c +3
-2@@ -12,7 +12,8 @@#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 void add_to_ref_list (const struct object_id *oid,const char *name,struct ref_list *list)@@ -23,17 +24,20 @@ 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)
bundle.c static void add_to_ref_list(const struct object_id *oid, const char *name, · line 37
Quoted 10 lines
bundle.c +9
-0{ +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);
This certainly enforces the earlier EBNF we saw on the value side by the caller stopping at the first LF and feeding the bytes before it to the function, but there is no sanity checking for the key part.
In a sense, there is no need to. As we always reject what is unknown to us, the only thing we need is to ensure that skip_prefix() we use here are the syntactically correct key followed by '='.
bundle.c static void add_to_ref_list(const struct object_id *oid, const char *name, · line 43
Quoted 6 lines
bundle.c +1
-0} +static int parse_bundle_header (int fd,struct bundle_header *header,const char *report_path) {
I do not particularly mind two blank lines between functions but let's be consistent, and this patch is not the place to make that change.
Quoted 4 lines
bundle.c +0
-0@@ -42,14 +46,18 @@ 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') ||
bundle.c static int parse_bundle_header(int fd, struct bundle_header *header, · line 56
Quoted 10 lines
bundle.c +3
-2- strcmp(buf.buf, bundle_signature)) { + (strcmp(buf.buf, v2_bundle_signature) && + strcmp(buf.buf, v3_bundle_signature))) {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; }
OK.
bundle.c static int parse_bundle_header(int fd, struct bundle_header *header, · line 58
Quoted 1 line
bundle.c +1
-0+ header->version = buf.buf[3 ] -'0' ;
Hmmmmm. So in addition to the vN_bundle_signature[], the code also knows where the '2' and '3' are? It may be overkill to have a helper function just for this but
if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
parse_bundle_signature(buf.buf, header)) {
... does not look like a supported bundle file ...
}with
static struct {
int version;
const char *signature;
} bundle_sigs[] = {
{ 2, "# v2 git bundle\n" },
{ 3, "# v3 git bundle\n" },
};
static int parse_bundle_signature(const char *s, struct bundle_header *h)
{
int i;
for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) {
if (!strcmp(s, bundle_sigs[i].signature) {
h->version = bundle_sigs[i].version;
return 0;
}
}
return -1;
}or something like that?
bundle.c static int parse_bundle_header(int fd, struct bundle_header *header, · line 69
Quoted 11 lines
bundle.c +4
-0+ 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 +65,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 -1 ] ='\0' ;
This is chomping the final LF. I know the current code does not care, but after this, buf.len is inconsistent with buf.buf in that the NUL we placed here is not part of the payload on the line. Doing strbuf_rtrim(&buf) is certainly too much (it also drops trailing whitespaces), but it somewhat feels disturbing. It might be sufficient to say
buf.buf[--buf.len] = '\0';
to make it palatable. I dunno.
Quoted 53 lines
bundle.c +15
-12+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 +457,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 +473,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) {
bundle.c int create_bundle(struct repository *r, const char *path, · line 491
Quoted 10 lines
bundle.c +10
-0+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 ); + }
Quite straight-forward.
Quoted 13 lines
t/t5510-fetch.sh +1
-1@@ -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' '
t/t5510-fetch.sh test_expect_success 'create bundle 1' ' · line 294
Quoted 10 lines
t/t5510-fetch.sh +4
-3head -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 "^$" + 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 "^$" '
This is not new, but because "head -n $n" is not "look at the $n-th line", but "look at the first $n lines", the construct look somewhat bogus. Wouldn't we want something more like
sed -n -e 1p "$D/bundle1" | grep "^#" && sed -n -e 2p "$D/bundle1" | grep "^@object-format=" && ...
I wonder.
t/t5510-fetch.sh test_expect_success 'create bundle 1' '
Quoted 4 lines
t/t5510-fetch.sh +4
-0+test_expect_success 'git bundle uses expected default format' ' + git bundle create bundle HEAD^.. && + head -n1 bundle | grep "^# v$(test_oid version) git bundle$" +'
Nice.
t/t5510-fetch.sh
Quoted 6 lines
t/t5510-fetch.sh +6
-0+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 && + echo "# v3 git bundle" >expected && + echo "@object-format=$(test_oid algo)" >>expected &&
Rather than two separate echo,
cat >expect <<-EOF && # v3 git bundle @object-format=$(test_oid algo) EOF
might be more direct and easier to see what is expected.
t/t5510-fetch.sh
Quoted 8 lines
t/t5510-fetch.sh +8
-0+ test_cmp actual expected && + 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 &&
What are we feeding this sed? You meant to feed 'bundle'?
Quoted 5 lines
t/t5510-fetch.sh +4
-0+ test_must_fail git bundle verify new 2>output && + grep "unknown capability .unknown=silly." output +' + test_done
Re: [PATCH v2 31/39] bundle: add new version for use with SHA-256
In reply to brian m. carlsonQuoted 22 lines · brian m. carlson
bundle.c +9
-8@@ -23,17 +24,20 @@ 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; - - 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); +if (algo ==GIT_HASH_UNKNOWN ) +return error (_ ("unable to detect hash algorithm" )); + header->hash_algo = &hash_algos[algo]; +return 0 ; + }
bundle.c static void add_to_ref_list(const struct object_id *oid, const char *name,
Quoted 10 lines
bundle.c +7
-0+return error (_ ("unknown capability '%s'" ), capability); } +test_expect_success 'git bundle v3 rejects unknown extensions' ' + head -n2 bundle >new && + echo"@unknown=silly" >>new && + sed"1,2d" >>new && + test_must_fail git bundle verify new 2>output && + grep"unknown capability .unknown=silly." output
This "unknown capability" error message is translated, so it should be checked with 'test_i18ngrep'.
Quoted 3 lines
+'
+
test_done
Re: [PATCH v2 31/39] bundle: add new version for use with SHA-256
Hi,
Quoted 27 lines · SZEDER Gábor
Quoted 24 lines · brian m. carlson
(quoted diff) +10
-8@@ -23,17 +24,20 @@ 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; - - 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); + 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); }
Quoted 9 lines
Review static void add_to_ref_list(const struct object_id *oid, const char *name,
Quoted 6 lines
(quoted diff) +6
-0+test_expect_success 'git bundle v3 rejects unknown extensions' ' + head -n2 bundle >new && + echo "@unknown=silly" >>new && + sed "1,2d" >>new && + test_must_fail git bundle verify new 2>output && + grep "unknown capability .unknown=silly." outputThis "unknown capability" error message is translated, so it should be checked with '
test_i18ngrep'.
In other words, this patch (which makes things work over here):
-- snipsnap --
Subject: [PATCH] fixup! bundle: add new version for use with SHA-256
--- t/t5607-clone-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t5607-clone-bundle.sh +1 -1
@@ -118,7 +118,7 @@ test_expect_success 'git bundle v3 rejects unknown extensions' ' echo "@unknown=silly" >>new && sed "1,2d" >>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
--
2.26.0.windows.1
Re: [PATCH v2 31/39] bundle: add new version for use with SHA-256
Quoted 4 lines · Johannes Schindelin
Quoted 2 lines
This "unknown capability" error message is translated, so it should be checked with '
test_i18ngrep'.In other words, this patch (which makes things work over here):
Thanks.
Quoted 23 lines
-- snipsnap --
Subject: [PATCH] fixup! bundle: add new version for use with SHA-256--- t/t5607-clone-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t5607-clone-bundle.sh +1
-2@@ -118,7 +118,7 @@ test_expect_success 'git bundle v3 rejects unknown extensions' ' echo "@unknown=silly" >>new && sed "1,2d" >>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 --2.26.0.windows.1
PATCH v2 32/39 setup: add support for reading extensions.objectformat
In reply to brian m. carlsonThe 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 don't use the value of the extension if the repository format version is 0.
--- setup.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
setup.c +11 -1
@@ -471,7 +471,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); }
@@ -515,6 +524,7 @@ 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 ; }string_list_clear (&candidate->unknown_extensions,0 );
PATCH v2 33/39 Enable SHA-256 support by default
In reply to brian m. carlsonNow 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.
--- builtin/init-db.c | 5 ----- config.mak.dev | 2 -- repository.c | 4 ---- t/t0001-init.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-)
builtin/init-db.c +0 -5
@@ -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 ;
config.mak.dev +0 -2
@@ -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
repository.c +0 -4
@@ -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 }/*
t/t0001-init.sh +31 -0
@@ -441,6 +441,37 @@ 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 honored 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 +' + +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 &&
PATCH v2 34/39 t: add test_oid option to select hash algorithm
In reply to brian m. carlsonIn 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.
--- t/t0000-basic.sh | 11 +++++++++++ t/test-lib-functions.sh | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
t/t0000-basic.sh +11 -0
@@ -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 &&
t/test-lib-functions.sh +11 -1
@@ -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.
PATCH v2 35/39 t: allow testing different hash algorithms via environment
In reply to brian m. carlsonTo 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.
--- t/test-lib-functions.sh | 4 +--- t/test-lib.sh | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-)
t/test-lib-functions.sh +1 -3
@@ -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
t/test-lib.sh +3 -0
@@ -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
PATCH v2 36/39 t: make SHA1 prerequisite depend on default hash
In reply to brian m. carlsonCurrently, 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.
--- t/test-lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/test-lib.sh +2 -1
@@ -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 '
PATCH v2 37/39 ci: run tests with SHA-256
In reply to brian m. carlsonNow 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.
--- ci/run-build-and-tests.sh | 5 +++++ 1 file changed, 5 insertions(+)
ci/run-build-and-tests.sh +5 -0
@@ -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)
PATCH v2 38/39 docs: add documentation for extensions.objectFormat
In reply to brian m. carlsonDocument the extensions.objectFormat config setting. Warn users not to modify it themselves.
--- Documentation/config.txt | 2 ++ Documentation/config/extensions.txt | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 Documentation/config/extensions.txt
Documentation/config.txt +2 -0
@@ -348,6 +348,8 @@ include::config/diff.txt[] include::config/difftool.txt[] +include::config/extensions.txt[] + include::config/fastimport.txt[] include::config/feature.txt[]
Documentation/config/extensions.txt new file +9 -0
@@ -0,0 +1,9 @@ +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. ++ +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.
PATCH v2 39/39 t: remove test_oid_init in tests
In reply to brian m. carlsonNow 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.
--- 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(-)
t/lib-pack.sh +0 -3
@@ -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
t/lib-submodule-update.sh +0 -1
@@ -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
t/t0000-basic.sh +0 -4
@@ -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 &&
t/t1006-cat-file.sh +0 -2
@@ -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"
t/t1050-large.sh +0 -1
@@ -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 &&
t/t1410-reflog.sh +0 -1
@@ -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 &&
t/t1450-fsck.sh +0 -1
@@ -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 &&
t/t1500-rev-parse.sh +0 -1
@@ -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 '
t/t3305-notes-fanout.sh +0 -1
@@ -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;
t/t3308-notes-merge.sh +0 -1
@@ -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
t/t3404-rebase-interactive.sh +0 -1
@@ -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 &&
t/t3600-rm.sh +0 -1
@@ -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 &&
t/t3800-mktag.sh +0 -1
@@ -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" &&
t/t4002-diff-basic.sh +0 -2
@@ -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
t/t4027-diff-submodule.sh +0 -1
@@ -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 && (
t/t4134-apply-submodule.sh +0 -1
@@ -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
t/t4200-rerere.sh +0 -1
@@ -25,7 +25,6 @@ test_description='git rerere . ./test-lib.sh test_expect_success 'setup' ' - test_oid_init && cat >a1 <<-\EOF && Some title ==========
t/t4211-line-log.sh +0 -1
@@ -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 '
t/t5300-pack-object.sh +1 -2
@@ -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 &&
t/t5302-pack-index.sh +0 -1
@@ -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 &&
t/t5313-pack-bounds-checks.sh +0 -1
@@ -45,7 +45,6 @@ extended_table () { } test_expect_success 'setup' ' - test_oid_init && test_oid_cache <<-EOF oid000 sha1:1485 oid000 sha256:4222
t/t5318-commit-graph.sh +1 -2
@@ -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' '
t/t5319-multi-pack-index.sh +0 -1
@@ -29,7 +29,6 @@ midx_read_expect () { } test_expect_success 'setup' ' - test_oid_init && test_oid_cache <<-EOF idxoff sha1:2999 idxoff sha256:3739
t/t5324-split-commit-graph.sh +0 -1
@@ -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
t/t5504-fetch-receive-strict.sh +0 -1
@@ -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 &&
t/t5530-upload-pack-error.sh +0 -1
@@ -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 &&
t/t5562-http-backend-content-length.sh +0 -1
@@ -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 &&
t/t5702-protocol-v2.sh +0 -1
@@ -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 '
t/t5703-upload-pack-ref-in-want.sh +0 -1
@@ -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 &&
t/t6006-rev-list-format.sh +0 -1
@@ -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 &&
t/t6301-for-each-ref-errors.sh +0 -1
@@ -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 &&
t/t6501-freshen-objects.sh +0 -4
@@ -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}
t/t7003-filter-branch.sh +0 -1
@@ -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 &&
t/t8002-blame.sh +0 -4
@@ -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
t/t8003-blame-corner-cases.sh +0 -2
@@ -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 &&
t/t9301-fast-import-notes.sh +0 -1
@@ -71,7 +71,6 @@ EOF INPUT_END test_expect_success 'set up master branch' ' - test_oid_init && git fast-import <input && git whatchanged master '
t/t9350-fast-export.sh +0 -2
@@ -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 &&