Skip to content

Commit fa6edee

Browse files
avargitster
authored andcommitted
cache-tree tests: use a sub-shell with less indirection
Change a "cd xyz && work && cd .." pattern introduced in 9c4d6c0 (cache-tree: Write updated cache-tree after commit, 2014-07-13) to use a sub-shell instead with less indirection. We did actually recover correctly if we failed in this function since we were wrapped in a subshell one function call up. Let's just use the sub-shell at the point where we want to change the directory instead. It's important that the "|| return 1" is outside the subshell. Normally, we `exit 1` from within subshells[1], but that wouldn't help us exit this loop early[1][2]. Since we can get rid of the wrapper function let's rename the main function to drop the "rec" (for "recursion") suffix[3]. 1. https://lore.kernel.org/git/CAPig+cToj8nQmyBCqC1k7DXF2vXaonCEA-fCJ4x7JBZG2ixYBw@mail.gmail.com/ 2. https://lore.kernel.org/git/[email protected]/ 3. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3226725 commit fa6edee

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

t/t0090-cache-tree.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cmp_cache_tree () {
1717
# We don't bother with actually checking the SHA1:
1818
# test-tool dump-cache-tree already verifies that all existing data is
1919
# correct.
20-
generate_expected_cache_tree_rec () {
20+
generate_expected_cache_tree () {
2121
dir="$1${1:+/}" &&
2222
# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
2323
# We want to count only foo because it's the only direct child
@@ -28,18 +28,13 @@ generate_expected_cache_tree_rec () {
2828
printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
2929
for subtree in $subtrees
3030
do
31-
cd "$subtree"
32-
generate_expected_cache_tree_rec "$dir$subtree" || return 1
33-
cd ..
31+
(
32+
cd "$subtree" &&
33+
generate_expected_cache_tree "$dir$subtree"
34+
) || return 1
3435
done
3536
}
3637

37-
generate_expected_cache_tree () {
38-
(
39-
generate_expected_cache_tree_rec
40-
)
41-
}
42-
4338
test_cache_tree () {
4439
generate_expected_cache_tree >expect &&
4540
cmp_cache_tree expect

0 commit comments

Comments
 (0)