Skip to content

Commit 0b20f1a

Browse files
peffgitster
authored andcommitted
t1450: refactor loose-object removal
Commit 90cf590 (fsck: optionally show more helpful info for broken links, 2016-07-17) added a remove_loose_object() helper, but we already had a remove_object() helper that did the same thing. Let's combine these into one. The implementations had a few subtle differences, so I've tried to take the best of both: - the original used "sed", but the newer version avoids spawning an extra process - the original processed "$*", which was nonsense, as it assumed only a single sha1. Use "$1" to make that more clear. - the newer version ran an extra rev-parse, but it was not necessary; it's sole caller already converted the argument into a raw sha1 - the original used "rm -f", whereas the new one uses "rm". The latter is better because it may notice a bug or other unexpected failure in the test. (The original does check that the object exists before we remove it, which is good, but that's a subset of the possible unexpected conditions). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a274e0a commit 0b20f1a

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

t/t1450-fsck.sh

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ test_expect_success 'HEAD is part of refs, valid objects appear valid' '
4343

4444
test_expect_success 'setup: helpers for corruption tests' '
4545
sha1_file() {
46-
echo "$*" | sed "s#..#.git/objects/&/#"
46+
remainder=${1#??} &&
47+
firsttwo=${1%$remainder} &&
48+
echo ".git/objects/$firsttwo/$remainder"
4749
} &&
4850
4951
remove_object() {
50-
file=$(sha1_file "$*") &&
51-
test -e "$file" &&
52-
rm -f "$file"
52+
rm "$(sha1_file "$1")"
5353
}
5454
'
5555

@@ -535,13 +535,6 @@ test_expect_success 'fsck --connectivity-only' '
535535
)
536536
'
537537

538-
remove_loose_object () {
539-
sha1="$(git rev-parse "$1")" &&
540-
remainder=${sha1#??} &&
541-
firsttwo=${sha1%$remainder} &&
542-
rm .git/objects/$firsttwo/$remainder
543-
}
544-
545538
test_expect_success 'fsck --name-objects' '
546539
rm -rf name-objects &&
547540
git init name-objects &&
@@ -550,7 +543,7 @@ test_expect_success 'fsck --name-objects' '
550543
test_commit julius caesar.t &&
551544
test_commit augustus &&
552545
test_commit caesar &&
553-
remove_loose_object $(git rev-parse julius:caesar.t) &&
546+
remove_object $(git rev-parse julius:caesar.t) &&
554547
test_must_fail git fsck --name-objects >out &&
555548
tree=$(git rev-parse --verify julius:) &&
556549
grep "$tree (\(refs/heads/master\|HEAD\)@{[0-9]*}:" out

0 commit comments

Comments
 (0)