Skip to content

Commit 534ff90

Browse files
LukeShugitster
authored andcommitted
subtree: don't let debug and progress output clash
Currently, debug output (triggered by passing '-d') and progress output stomp on each other. The debug output is just streamed as lines to stderr, and the progress output is sent to stderr as '%s\r'. When writing to a file, it is awkward to read and difficult to distinguish between the debug output and a progress line. When writing to a terminal the debug lines hide progress lines. So, when '-d' has been passed, spit out progress as 'progress: %s\n', instead of as '%s\r', so that it can be detected, and so that the debug lines don't overwrite the progress when written to a terminal. Signed-off-by: Luke Shumaker <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5cdae0f commit 534ff90

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,27 @@ debug () {
6767
progress () {
6868
if test -z "$GIT_QUIET"
6969
then
70-
printf "%s\r" "$*" >&2
70+
if test -z "$arg_debug"
71+
then
72+
# Debug mode is off.
73+
#
74+
# Print one progress line that we keep updating (use
75+
# "\r" to return to the beginning of the line, rather
76+
# than "\n" to start a new line). This only really
77+
# works when stderr is a terminal.
78+
printf "%s\r" "$*" >&2
79+
else
80+
# Debug mode is on. The `debug` function is regularly
81+
# printing to stderr.
82+
#
83+
# Don't do the one-line-with-"\r" thing, because on a
84+
# terminal the debug output would overwrite and hide the
85+
# progress output. Add a "progress:" prefix to make the
86+
# progress output and the debug output easy to
87+
# distinguish. This ensures maximum readability whether
88+
# stderr is a terminal or a file.
89+
printf "progress: %s\n" "$*" >&2
90+
fi
7191
fi
7292
}
7393

0 commit comments

Comments
 (0)