Skip to content

Commit 47cc99b

Browse files
committed
commit-graph: add --[no-]progress to write and verify.
Add --[no-]progress to git commit-graph write and verify. The progress feature was introduced in 7b0f229 ("commit-graph write: add progress output", 2018-09-17) but the ability to opt-out was overlooked. Signed-off-by: Garima Singh <[email protected]>
1 parent 745f681 commit 47cc99b

File tree

5 files changed

+61
-11
lines changed

5 files changed

+61
-11
lines changed

Documentation/git-commit-graph.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git commit-graph read' [--object-dir <dir>]
13-
'git commit-graph verify' [--object-dir <dir>] [--shallow]
14-
'git commit-graph write' <options> [--object-dir <dir>]
13+
'git commit-graph verify' [--object-dir <dir>] [--shallow] [--[no-]progress]
14+
'git commit-graph write' <options> [--object-dir <dir>] [--[no-]progress]
1515

1616

1717
DESCRIPTION
@@ -29,6 +29,9 @@ OPTIONS
2929
commit-graph file is expected to be in the `<dir>/info` directory and
3030
the packfiles are expected to be in `<dir>/pack`.
3131

32+
--[no-]progress::
33+
Turn progress on/off explicitly. If neither is specified, progress is
34+
shown if standard error is connected to a terminal.
3235

3336
COMMANDS
3437
--------

builtin/commit-graph.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
static char const * const builtin_commit_graph_usage[] = {
1111
N_("git commit-graph [--object-dir <objdir>]"),
1212
N_("git commit-graph read [--object-dir <objdir>]"),
13-
N_("git commit-graph verify [--object-dir <objdir>] [--shallow]"),
14-
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] <split options>"),
13+
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
14+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
1515
NULL
1616
};
1717

1818
static const char * const builtin_commit_graph_verify_usage[] = {
19-
N_("git commit-graph verify [--object-dir <objdir>] [--shallow]"),
19+
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
2020
NULL
2121
};
2222

@@ -26,7 +26,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
2626
};
2727

2828
static const char * const builtin_commit_graph_write_usage[] = {
29-
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] <split options>"),
29+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
3030
NULL
3131
};
3232

@@ -38,6 +38,7 @@ static struct opts_commit_graph {
3838
int append;
3939
int split;
4040
int shallow;
41+
int progress;
4142
} opts;
4243

4344
static int graph_verify(int argc, const char **argv)
@@ -55,9 +56,11 @@ static int graph_verify(int argc, const char **argv)
5556
N_("The object directory to store the graph")),
5657
OPT_BOOL(0, "shallow", &opts.shallow,
5758
N_("if the commit-graph is split, only verify the tip file")),
59+
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
5860
OPT_END(),
5961
};
6062

63+
opts.progress = isatty(2);
6164
argc = parse_options(argc, argv, NULL,
6265
builtin_commit_graph_verify_options,
6366
builtin_commit_graph_verify_usage, 0);
@@ -66,7 +69,9 @@ static int graph_verify(int argc, const char **argv)
6669
opts.obj_dir = get_object_directory();
6770
if (opts.shallow)
6871
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
69-
72+
if (opts.progress)
73+
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
74+
7075
graph_name = get_commit_graph_filename(opts.obj_dir);
7176
open_ok = open_commit_graph(graph_name, &fd, &st);
7277
if (!open_ok && errno != ENOENT)
@@ -154,7 +159,7 @@ static int graph_write(int argc, const char **argv)
154159
struct string_list *commit_hex = NULL;
155160
struct string_list lines;
156161
int result = 0;
157-
enum commit_graph_write_flags flags = COMMIT_GRAPH_WRITE_PROGRESS;
162+
enum commit_graph_write_flags flags = 0;
158163

159164
static struct option builtin_commit_graph_write_options[] = {
160165
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -168,6 +173,7 @@ static int graph_write(int argc, const char **argv)
168173
N_("start walk at commits listed by stdin")),
169174
OPT_BOOL(0, "append", &opts.append,
170175
N_("include all commits already in the commit-graph file")),
176+
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
171177
OPT_BOOL(0, "split", &opts.split,
172178
N_("allow writing an incremental commit-graph file")),
173179
OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
@@ -179,6 +185,7 @@ static int graph_write(int argc, const char **argv)
179185
OPT_END(),
180186
};
181187

188+
opts.progress = isatty(2);
182189
split_opts.size_multiple = 2;
183190
split_opts.max_commits = 0;
184191
split_opts.expire_time = 0;
@@ -195,6 +202,8 @@ static int graph_write(int argc, const char **argv)
195202
flags |= COMMIT_GRAPH_WRITE_APPEND;
196203
if (opts.split)
197204
flags |= COMMIT_GRAPH_WRITE_SPLIT;
205+
if (opts.progress)
206+
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
198207

199208
read_replace_refs = 0;
200209

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,8 +1992,10 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
19921992
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
19931993
return verify_commit_graph_error;
19941994

1995-
progress = start_progress(_("Verifying commits in commit graph"),
1996-
g->num_commits);
1995+
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
1996+
progress = start_progress(_("Verifying commits in commit graph"),
1997+
g->num_commits);
1998+
19971999
for (i = 0; i < g->num_commits; i++) {
19982000
struct commit *graph_commit, *odb_commit;
19992001
struct commit_list *graph_parents, *odb_parents;

t/t5318-commit-graph.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,42 @@ test_expect_success 'Add more commits' '
124124
git repack
125125
'
126126

127+
test_expect_success 'commit-graph write progress off for redirected stderr' '
128+
cd "$TRASH_DIRECTORY/full" &&
129+
git commit-graph write 2>err &&
130+
test_line_count = 0 err
131+
'
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 &&
136+
test_file_not_empty err
137+
'
138+
139+
test_expect_success 'commit-graph write with the --no-progress option' '
140+
cd "$TRASH_DIRECTORY/full" &&
141+
git commit-graph write --no-progress 2>err &&
142+
test_line_count = 0 err
143+
'
144+
145+
test_expect_success 'commit-graph verify progress off for redirected stderr' '
146+
cd "$TRASH_DIRECTORY/full" &&
147+
git commit-graph verify 2>err &&
148+
test_line_count = 0 err
149+
'
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 &&
154+
test_file_not_empty err
155+
'
156+
157+
test_expect_success 'commit-graph verify with the --no-progress option' '
158+
cd "$TRASH_DIRECTORY/full" &&
159+
git commit-graph verify --no-progress 2>err &&
160+
test_line_count = 0 err
161+
'
162+
127163
# Current graph structure:
128164
#
129165
# __M3___

t/t5324-split-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ test_expect_success 'add octopus merge' '
319319
git merge commits/3 commits/4 &&
320320
git branch merge/octopus &&
321321
git commit-graph write --reachable --split &&
322-
git commit-graph verify 2>err &&
322+
git commit-graph verify --progress 2>err &&
323323
test_line_count = 3 err &&
324324
test_i18ngrep ! warning err &&
325325
test_line_count = 3 $graphdir/commit-graph-chain

0 commit comments

Comments
 (0)