Skip to content

Commit 16e3315

Browse files
committed
Fix cleanup of cleanup list and reduce number of subshells launched
1 parent a93741f commit 16e3315

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

git-fmt-diff

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ gf_debug=0
1313
gf_no_term=
1414
gf_use_color=
1515
gf_warn_risky_stderr=
16+
1617
g_fmtprg_devnull="2> /dev/null"
1718

18-
g_rm_list="$(mktemp)"
19+
g_rm_list=""
1920

2021
# }}}
2122

2223
# helpers {{{1
2324

24-
abspath () (
25+
abspath () {
2526
if [ -d "$1" ]; then
2627
cd "$1" && pwd
2728
elif [ -f "$1" ]; then
@@ -33,9 +34,9 @@ abspath () (
3334
else
3435
warn "no such file or directory"
3536
fi
36-
)
37+
}
3738

38-
cleanup () (
39+
cleanup () {
3940
sed '1!G;h;$!d' "$g_rm_list" | while read -r path; do
4041
if [ -d "$path" ]; then
4142
for f in "$path"/*; do
@@ -46,7 +47,7 @@ cleanup () (
4647
rm "$path"
4748
fi
4849
done
49-
)
50+
}
5051

5152
debug () (
5253
[ "$3" != "--" ] && [ "$gf_debug" -eq 0 ] && return
@@ -57,11 +58,11 @@ debug () (
5758
)
5859
alias debug='debug "$FUNCNAME" "$LINENO"'
5960

60-
pat_list_to_case () (
61+
pat_list_to_case () {
6162
sed 's/\s*,\s*/|/g'
62-
)
63+
}
6364

64-
rm_list__push () (
65+
rm_list__push () {
6566
[ "$gf_debug" -eq 2 ] && return
6667
if [ -z "$g_rm_list" ]; then
6768
g_rm_list="$(mktemp)"
@@ -70,15 +71,15 @@ rm_list__push () (
7071
for f in "$@"; do
7172
echo "$f" >> "$g_rm_list"
7273
done
73-
)
74+
}
7475

75-
sed_esc () (
76+
sed_esc () {
7677
if [ "$1" = "-p" ]; then
7778
printf '%s\n' "$2" | sed -e 's/[]\/$*.^[]/\\&/g'
7879
elif [ "$1" = "-s" ]; then
7980
printf '%s\n' "$2" | sed -e 's/[\/&]/\\&/g'
8081
fi
81-
)
82+
}
8283

8384
sgr () {
8485
if [ "$gf_use_color" -eq 1 ]; then
@@ -88,12 +89,12 @@ sgr () {
8889
fi
8990
}
9091

91-
warn () (
92+
warn () {
9293
>&2 printf "%s: " "$(basename "$0")"
9394
# printf "\033[30m\033[103m"
9495
>&2 echo "$@"
9596
# printf "\033[0m"
96-
)
97+
}
9798

9899
# git config --get {{{1
99100

@@ -473,7 +474,7 @@ EOW
473474

474475
# }}}1
475476

476-
usage () (
477+
usage () {
477478
cat << EOU
478479
usage: git fmt-diff [<options>] [<commit>] [--] [<path>...]
479480
or: git fmt-diff [<options>] --cached [<commit>] [--] [<path>...]
@@ -491,7 +492,7 @@ options:
491492
--warn-risky-stderr redirects warning about potential unsolicited changes in suggestions to stderr;
492493
option not recommended as the warning blocks dangerous 'git apply'
493494
EOU
494-
)
495+
}
495496

496497
# parse options {{{2
497498
while :; do

0 commit comments

Comments
 (0)