Skip to content

Commit 44a4693

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9f6f3b commit 44a4693

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Documentation/git.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ other
544544
a pager. See also the `core.pager` option in
545545
linkgit:git-config[1].
546546

547+
`GIT_PROGRESS_DELAY`::
548+
A number controlling how many seconds to delay before showing
549+
optional progress indicators. Defaults to 2.
550+
547551
`GIT_EDITOR`::
548552
This environment variable overrides `$EDITOR` and `$VISUAL`.
549553
It is used by several Git commands when, on interactive mode,

progress.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "strbuf.h"
1515
#include "trace.h"
1616
#include "utf8.h"
17+
#include "config.h"
1718

1819
#define TP_IDX_MAX 8
1920

@@ -267,9 +268,19 @@ static struct progress *start_progress_delay(const char *title, uint64_t total,
267268
return progress;
268269
}
269270

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+
270281
struct progress *start_delayed_progress(const char *title, uint64_t total)
271282
{
272-
return start_progress_delay(title, total, 2, 0);
283+
return start_progress_delay(title, total, get_default_delay(), 0);
273284
}
274285

275286
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)
294305
struct progress *start_delayed_sparse_progress(const char *title,
295306
uint64_t total)
296307
{
297-
return start_progress_delay(title, total, 2, 1);
308+
return start_progress_delay(title, total, get_default_delay(), 1);
298309
}
299310

300311
static void finish_if_sparse(struct progress *progress)

t/t5318-commit-graph.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ test_expect_success 'commit-graph write progress off for redirected stderr' '
132132

133133
test_expect_success 'commit-graph write force progress on for stderr' '
134134
cd "$TRASH_DIRECTORY/full" &&
135-
git commit-graph write --progress 2>err &&
135+
GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
136136
test_file_not_empty err
137137
'
138138

@@ -150,7 +150,7 @@ test_expect_success 'commit-graph verify progress off for redirected stderr' '
150150

151151
test_expect_success 'commit-graph verify force progress on for stderr' '
152152
cd "$TRASH_DIRECTORY/full" &&
153-
git commit-graph verify --progress 2>err &&
153+
GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
154154
test_file_not_empty err
155155
'
156156

t/t6500-gc.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre
103103
'
104104

105105
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 &&
107107
test_must_be_empty stdout &&
108-
test_line_count = 1 stderr &&
109108
test_i18ngrep "Computing commit graph generation numbers" stderr
110109
'
111110

0 commit comments

Comments
 (0)