@matheusbsbs / matheus-bagliano / commits / 44a4693bfc
Fork 0

progress: create GIT_PROGRESS_DELAY

The start_delayed_progress() method is a preferred way to show optional progress to users as it ignores steps that take less than two seconds. However, this makes testing unreliable as tests expect to be very fast. In addition, users may want to decrease or increase this time interval depending on their preferences for terminal noise. Create the GIT_PROGRESS_DELAY environment variable to control the delay set during start_delayed_progress(). Set the value in some tests to guarantee their output remains consistent. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Nov 25, 2019 at 21:28 UTC 44a4693bfcec1876b29cdaec3625819d80ea1280
4 files changed +20 -6
Documentation/git.txt
+4
@@ -544,6 +544,10 @@ other
544 a pager. See also the `core.pager` option in
545 linkgit:git-config[1].
546
547 +`GIT_PROGRESS_DELAY`::
548 + A number controlling how many seconds to delay before showing
549 + optional progress indicators. Defaults to 2.
550 +
551 `GIT_EDITOR`::
552 This environment variable overrides `$EDITOR` and `$VISUAL`.
553 It is used by several Git commands when, on interactive mode,
progress.c
+13 -2
@@ -14,6 +14,7 @@
14 #include "strbuf.h"
15 #include "trace.h"
16 #include "utf8.h"
17 +#include "config.h"
18
19 #define TP_IDX_MAX 8
20
@@ -267,9 +268,19 @@ static struct progress *start_progress_delay(const char *title, uint64_t total,
268 return progress;
269 }
270
271 +static int get_default_delay(void)
272 +{
273 + static int delay_in_secs = -1;
274 +
275 + if (delay_in_secs < 0)
276 + delay_in_secs = git_env_ulong("GIT_PROGRESS_DELAY", 2);
277 +
278 + return delay_in_secs;
279 +}
280 +
281 struct progress *start_delayed_progress(const char *title, uint64_t total)
282 {
272 - return start_progress_delay(title, total, 2, 0);
283 + return start_progress_delay(title, total, get_default_delay(), 0);
284 }
285
286 struct progress *start_progress(const char *title, uint64_t total)
@@ -294,7 +305,7 @@ struct progress *start_sparse_progress(const char *title, uint64_t total)
305 struct progress *start_delayed_sparse_progress(const char *title,
306 uint64_t total)
307 {
297 - return start_progress_delay(title, total, 2, 1);
308 + return start_progress_delay(title, total, get_default_delay(), 1);
309 }
310
311 static void finish_if_sparse(struct progress *progress)
t/t5318-commit-graph.sh
+2 -2
@@ -132,7 +132,7 @@ test_expect_success 'commit-graph write progress off for redirected stderr' '
132
133 test_expect_success 'commit-graph write force progress on for stderr' '
134 cd "$TRASH_DIRECTORY/full" &&
135 - git commit-graph write --progress 2>err &&
135 + GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
136 test_file_not_empty err
137 '
138
@@ -150,7 +150,7 @@ test_expect_success 'commit-graph verify progress off for redirected stderr' '
150
151 test_expect_success 'commit-graph verify force progress on for stderr' '
152 cd "$TRASH_DIRECTORY/full" &&
153 - git commit-graph verify --progress 2>err &&
153 + GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
154 test_file_not_empty err
155 '
156
t/t6500-gc.sh
+1 -2
@@ -103,9 +103,8 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre
103 '
104
105 test_expect_success 'gc --no-quiet' '
106 - git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr &&
106 + GIT_PROGRESS_DELAY=0 git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr &&
107 test_must_be_empty stdout &&
108 - test_line_count = 1 stderr &&
108 test_i18ngrep "Computing commit graph generation numbers" stderr
109 '
110