contrib/subtree: portability fix for string printing
'echo -n' is not portable, but this script used it as a way to give a string followed by a carriage return for progress messages. Introduce a new helper shell function "progress" and use printf as a more portable way to do this. As a side effect, this makes it unnecessary to have a raw CR in our source, which can be munged in some shells. For example, MsysGit trims CR before executing a shell script file in order to make it work right on Windows even if it uses CRLF as linefeeds. While at it, replace "echo" using printf in debug() and say() to eliminate the temptation of reintroducing the same bug. Signed-off-by: Danny Lin <danny0838@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Danny Lin committed
May 8, 2015 at 08:56 UTC
2ded109b51878fb0bc131945676c90f1d1051213
1 file changed
+10
-3
contrib/subtree/git-subtree.sh
+10
-3
@@ -51,14 +51,21 @@ prefix=
51
debug()
52
{
53
if [ -n "$debug" ]; then
54
- echo "$@" >&2
54
+ printf "%s\n" "$*" >&2
55
fi
56
}
57
58
say()
59
{
60
if [ -z "$quiet" ]; then
61
- echo "$@" >&2
61
+ printf "%s\n" "$*" >&2
62
+ fi
63
+}
64
+
65
+progress()
66
+{
67
+ if [ -z "$quiet" ]; then
68
+ printf "%s\r" "$*" >&2
69
fi
70
}
71
@@ -599,7 +606,7 @@ cmd_split()
606
eval "$grl" |
607
while read rev parents; do
608
revcount=$(($revcount + 1))
602
- say -n "$revcount/$revmax ($createcount)
"
609
+ progress "$revcount/$revmax ($createcount)"
610
debug "Processing commit: $rev"
611
exists=$(cache_get $rev)
612
if [ -n "$exists" ]; then