2011-07-24 18:59:13 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='
|
|
|
|
Miscellaneous tests for git ls-tree.
|
|
|
|
|
|
|
|
1. git ls-tree fails in presence of tree damage.
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2021-10-12 16:56:39 +03:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2011-07-24 18:59:13 +04:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
mkdir a &&
|
|
|
|
touch a/one &&
|
|
|
|
git add a/one &&
|
|
|
|
git commit -m test
|
|
|
|
'
|
|
|
|
|
2011-07-24 18:59:14 +04:00
|
|
|
test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
|
2018-05-13 05:24:22 +03:00
|
|
|
tree=$(git rev-parse HEAD:a) &&
|
|
|
|
rm -f .git/objects/$(echo $tree | sed -e "s,^\(..\),\1/,") &&
|
2011-07-24 18:59:13 +04:00
|
|
|
test_must_fail git ls-tree -r HEAD
|
|
|
|
'
|
|
|
|
|
2022-03-23 12:13:08 +03:00
|
|
|
for opts in \
|
2022-03-23 12:13:14 +03:00
|
|
|
"--long --name-only" \
|
|
|
|
"--name-only --name-status" \
|
ls-tree: support --object-only option for "git-ls-tree"
'--object-only' is an alias for '--format=%(objectname)'. It cannot
be used together other format-altering options like '--name-only',
'--long' or '--format', they are mutually exclusive.
The "--name-only" option outputs <filepath> only. Likewise, <objectName>
is another high frequency used field, so implement '--object-only' option
will bring intuitive and clear semantics for this scenario. Using
'--format=%(objectname)' we can achieve a similar effect, but the former
is with a lower learning cost(without knowing the format requirement
of '--format' option).
Even so, if a user is prefer to use "--format=%(objectname)", this is entirely
welcome because they are not only equivalent in function, but also have almost
identical performance. The reason is this commit also add the specific of
"--format=%(objectname)" to the current fast-pathes (builtin formats) to
avoid running unnecessary parsing mechanisms.
The following performance benchmarks are based on torvalds/linux.git:
When hit the fast-path:
Benchmark 1: /opt/git/ls-tree-oid-only/bin/git ls-tree -r --object-only HEAD
Time (mean ± σ): 83.6 ms ± 2.0 ms [User: 59.4 ms, System: 24.1 ms]
Range (min … max): 80.4 ms … 87.2 ms 35 runs
Benchmark 1: /opt/git/ls-tree-oid-only/bin/git ls-tree -r --format='%(objectname)' HEAD
Time (mean ± σ): 84.1 ms ± 1.8 ms [User: 61.7 ms, System: 22.3 ms]
Range (min … max): 80.9 ms … 87.5 ms 35 runs
But for a customized format, it will be slower:
Benchmark 1: /opt/git/ls-tree-oid-only/bin/git ls-tree -r --format='oid: %(objectname)' HEAD
Time (mean ± σ): 96.5 ms ± 2.5 ms [User: 72.9 ms, System: 23.5 ms]
Range (min … max): 93.1 ms … 104.1 ms 31 runs
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-03-23 12:13:13 +03:00
|
|
|
"--name-status --object-only" \
|
2022-03-23 12:13:14 +03:00
|
|
|
"--object-only --long"
|
2022-03-23 12:13:08 +03:00
|
|
|
do
|
|
|
|
test_expect_success "usage: incompatible options: $opts" '
|
|
|
|
test_expect_code 129 git ls-tree $opts $tree
|
2022-03-23 12:13:14 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
one_opt=$(echo "$opts" | cut -d' ' -f1)
|
|
|
|
test_expect_success "usage: incompatible options: $one_opt and --format" '
|
|
|
|
test_expect_code 129 git ls-tree $one_opt --format=fmt $tree
|
|
|
|
'
|
2022-03-23 12:13:08 +03:00
|
|
|
done
|
2011-07-24 18:59:13 +04:00
|
|
|
test_done
|