Skip to content

Commit

Permalink
scripts: remove_stale_hints: make it faster
Browse files Browse the repository at this point in the history
  • Loading branch information
mtzguido committed Oct 24, 2024
1 parent 265b01e commit 364a3e2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions .scripts/remove_stale_hints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ if [ $# -gt 0 ] && [ $1 == "list" ]; then
list=true
fi

declare -A files # Store all basenames in repo
declare -A hints # Store all paths of hints in repo
declare -A files # Store all basenames for non-hint files in repo (value = 1, this is just a set)
declare -A hints # Store a map from hint paths into basenames (turns out basename computation was a bottleneck)

trap 'RC=$?; rm -f .filelist; exit $RC' EXIT INT

# Find all (normal) files, not descending into .git, and store in
# the array. Using a pipe here would be better, but a pipe creates a
# subshell, so changes to the variables won't have any effect in the
# parent.
find . -name '.git' -prune -o \( -type f \) > .filelist
find . -name '.git' -prune -false -o \( -type f -name '*.hints' \) > .filelist
while read f0; do
f="$(basename "${f0}")"
files[$f]=1;
if [[ "$f0" == *.hints ]]; then
hints[$f0]=1
fi
hints[$f0]=$f
done < .filelist

find . -name '.git' -prune -false -o \( -type f -not -name '*.hints' \) -printf '%f\n' > .filelist
while read f; do
files[$f]=1
done < .filelist

rm -f .filelist

for h0 in "${!hints[@]}"; do
h="$(basename "${h0}")"
h=${hints[$h0]}
h="${h%.hints}"
# Given a/b/c/Foo.Bar.fst.hints, if there is no Foo.Bar.fst
# anywhere, then delete the hint file.
Expand Down

0 comments on commit 364a3e2

Please sign in to comment.