Skip to content

Commit da89f7d

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 5fa0f52 commit da89f7d

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

Documentation/git-commit-graph.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git commit-graph read' [--object-dir <dir>]
13-
'git commit-graph verify' [--object-dir <dir>] [--shallow]
13+
'git commit-graph verify' [--object-dir <dir>] [--shallow] [--[no-]progress]
1414
'git commit-graph write' <options> [--object-dir <dir>]
1515

1616

@@ -29,6 +29,8 @@ 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+
Toggle whether to show progress or not.
3234

3335
COMMANDS
3436
--------

builtin/commit-graph.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
#include "repository.h"
77
#include "commit-graph.h"
88
#include "object-store.h"
9+
#include "unistd.h"
910

1011
static char const * const builtin_commit_graph_usage[] = {
1112
N_("git commit-graph [--object-dir <objdir>]"),
1213
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>"),
14+
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
15+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
1516
NULL
1617
};
1718

1819
static const char * const builtin_commit_graph_verify_usage[] = {
19-
N_("git commit-graph verify [--object-dir <objdir>] [--shallow]"),
20+
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
2021
NULL
2122
};
2223

@@ -26,7 +27,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
2627
};
2728

2829
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>"),
30+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
3031
NULL
3132
};
3233

@@ -38,6 +39,7 @@ static struct opts_commit_graph {
3839
int append;
3940
int split;
4041
int shallow;
42+
int progress;
4143
} opts;
4244

4345
static int graph_verify(int argc, const char **argv)
@@ -48,16 +50,20 @@ static int graph_verify(int argc, const char **argv)
4850
int fd;
4951
struct stat st;
5052
int flags = 0;
51-
53+
int defaultProgressState = isatty(2);
54+
5255
static struct option builtin_commit_graph_verify_options[] = {
5356
OPT_STRING(0, "object-dir", &opts.obj_dir,
5457
N_("dir"),
5558
N_("The object directory to store the graph")),
5659
OPT_BOOL(0, "shallow", &opts.shallow,
5760
N_("if the commit-graph is split, only verify the tip file")),
61+
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
5862
OPT_END(),
5963
};
6064

65+
opts.progress = defaultProgressState;
66+
6167
argc = parse_options(argc, argv, NULL,
6268
builtin_commit_graph_verify_options,
6369
builtin_commit_graph_verify_usage, 0);
@@ -66,7 +72,9 @@ static int graph_verify(int argc, const char **argv)
6672
opts.obj_dir = get_object_directory();
6773
if (opts.shallow)
6874
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
69-
75+
if (opts.progress)
76+
flags |= COMMIT_GRAPH_PROGRESS;
77+
7078
graph_name = get_commit_graph_filename(opts.obj_dir);
7179
open_ok = open_commit_graph(graph_name, &fd, &st);
7280
if (!open_ok && errno != ENOENT)
@@ -154,8 +162,9 @@ static int graph_write(int argc, const char **argv)
154162
struct string_list *commit_hex = NULL;
155163
struct string_list lines;
156164
int result = 0;
157-
unsigned int flags = COMMIT_GRAPH_PROGRESS;
158-
165+
unsigned int flags = 0;
166+
int defaultProgressState = isatty(2);
167+
159168
static struct option builtin_commit_graph_write_options[] = {
160169
OPT_STRING(0, "object-dir", &opts.obj_dir,
161170
N_("dir"),
@@ -168,6 +177,7 @@ static int graph_write(int argc, const char **argv)
168177
N_("start walk at commits listed by stdin")),
169178
OPT_BOOL(0, "append", &opts.append,
170179
N_("include all commits already in the commit-graph file")),
180+
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
171181
OPT_BOOL(0, "split", &opts.split,
172182
N_("allow writing an incremental commit-graph file")),
173183
OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
@@ -179,6 +189,7 @@ static int graph_write(int argc, const char **argv)
179189
OPT_END(),
180190
};
181191

192+
opts.progress = defaultProgressState;
182193
split_opts.size_multiple = 2;
183194
split_opts.max_commits = 0;
184195
split_opts.expire_time = 0;
@@ -195,6 +206,8 @@ static int graph_write(int argc, const char **argv)
195206
flags |= COMMIT_GRAPH_APPEND;
196207
if (opts.split)
197208
flags |= COMMIT_GRAPH_SPLIT;
209+
if (opts.progress)
210+
flags |= COMMIT_GRAPH_PROGRESS;
198211

199212
read_replace_refs = 0;
200213

commit-graph.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,14 +1986,17 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
19861986
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
19871987
return verify_commit_graph_error;
19881988

1989-
progress = start_progress(_("Verifying commits in commit graph"),
1990-
g->num_commits);
1989+
if (flags & COMMIT_GRAPH_PROGRESS)
1990+
progress = start_progress(_("Verifying commits in commit graph"),
1991+
g->num_commits);
1992+
19911993
for (i = 0; i < g->num_commits; i++) {
19921994
struct commit *graph_commit, *odb_commit;
19931995
struct commit_list *graph_parents, *odb_parents;
19941996
uint32_t max_generation = 0;
19951997

19961998
display_progress(progress, i + 1);
1999+
19972000
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
19982001

19992002
graph_commit = lookup_commit(r, &cur_oid);

t/t5318-commit-graph.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,42 @@ test_expect_success 'Add more commits' '
116116
git repack
117117
'
118118

119+
test_expect_success 'commit-graph write progress off by default for stderr' '
120+
cd "$TRASH_DIRECTORY/full" &&
121+
git commit-graph write 2>err &&
122+
test_line_count = 0 err
123+
'
124+
125+
test_expect_success 'commit-graph write force progress on for stderr' '
126+
cd "$TRASH_DIRECTORY/full" &&
127+
git commit-graph write --progress 2>err &&
128+
test_file_not_empty err
129+
'
130+
131+
test_expect_success 'commit-graph write with the --no-progress option' '
132+
cd "$TRASH_DIRECTORY/full" &&
133+
git commit-graph write --no-progress 2>err &&
134+
test_line_count = 0 err
135+
'
136+
137+
test_expect_success 'commit-graph verify progress off by default for stderr' '
138+
cd "$TRASH_DIRECTORY/full" &&
139+
git commit-graph verify 2>err &&
140+
test_line_count = 0 err
141+
'
142+
143+
test_expect_success 'commit-graph verify force progress on for stderr' '
144+
cd "$TRASH_DIRECTORY/full" &&
145+
git commit-graph verify --progress 2>err &&
146+
test_file_not_empty err
147+
'
148+
149+
test_expect_success 'commit-graph verify with the --no-progress option' '
150+
cd "$TRASH_DIRECTORY/full" &&
151+
git commit-graph verify --no-progress 2>err &&
152+
test_line_count = 0 err
153+
'
154+
119155
# Current graph structure:
120156
#
121157
# __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)