Skip to content

Commit 2ded109

Browse files
danny0838gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16018ae commit 2ded109

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,21 @@ prefix=
5151
debug()
5252
{
5353
if [ -n "$debug" ]; then
54-
echo "$@" >&2
54+
printf "%s\n" "$*" >&2
5555
fi
5656
}
5757

5858
say()
5959
{
6060
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
6269
fi
6370
}
6471

@@ -599,7 +606,7 @@ cmd_split()
599606
eval "$grl" |
600607
while read rev parents; do
601608
revcount=$(($revcount + 1))
602-
say -n "$revcount/$revmax ($createcount)"
609+
progress "$revcount/$revmax ($createcount)"
603610
debug "Processing commit: $rev"
604611
exists=$(cache_get $rev)
605612
if [ -n "$exists" ]; then

0 commit comments

Comments
 (0)