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 <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Shumaker committed
Apr 27, 2021 at 15:17 UTC
534ff90dbd74a81beee357220cfa026efc18fea6
1 file changed
+21
-1
contrib/subtree/git-subtree.sh
+21
-1
@@ -67,7 +67,27 @@ debug () {
67
progress () {
68
if test -z "$GIT_QUIET"
69
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
91
fi
92
}
93