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 <garima.singh@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Garima Singh committed
Aug 26, 2019 at 09:29 UTC
7371612255492f062ee905e6d88c6234c6d4752a
5 files changed
+60
-10
Documentation/git-commit-graph.txt
+5
-2
@@ -10,8 +10,8 @@ SYNOPSIS
10
--------
11
[verse]
12
'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]
15
16
17
DESCRIPTION
@@ -29,6 +29,9 @@ OPTIONS
29
commit-graph file is expected to be in the `<dir>/info` directory and
30
the packfiles are expected to be in `<dir>/pack`.
31
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.
35
36
COMMANDS
37
--------
builtin/commit-graph.c
+14
-5
@@ -10,13 +10,13 @@
10
static char const * const builtin_commit_graph_usage[] = {
11
N_("git commit-graph [--object-dir <objdir>]"),
12
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>"),
15
NULL
16
};
17
18
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]"),
20
NULL
21
};
22
@@ -26,7 +26,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
26
};
27
28
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>"),
30
NULL
31
};
32
@@ -38,6 +38,7 @@ static struct opts_commit_graph {
38
int append;
39
int split;
40
int shallow;
41
+ int progress;
42
} opts;
43
44
static int graph_verify(int argc, const char **argv)
@@ -55,9 +56,11 @@ static int graph_verify(int argc, const char **argv)
56
N_("The object directory to store the graph")),
57
OPT_BOOL(0, "shallow", &opts.shallow,
58
N_("if the commit-graph is split, only verify the tip file")),
59
+ OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
60
OPT_END(),
61
};
62
63
+ opts.progress = isatty(2);
64
argc = parse_options(argc, argv, NULL,
65
builtin_commit_graph_verify_options,
66
builtin_commit_graph_verify_usage, 0);
@@ -66,6 +69,8 @@ static int graph_verify(int argc, const char **argv)
69
opts.obj_dir = get_object_directory();
70
if (opts.shallow)
71
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
72
+ if (opts.progress)
73
+ flags |= COMMIT_GRAPH_WRITE_PROGRESS;
74
75
graph_name = get_commit_graph_filename(opts.obj_dir);
76
open_ok = open_commit_graph(graph_name, &fd, &st);
@@ -154,7 +159,7 @@ static int graph_write(int argc, const char **argv)
159
struct string_list *commit_hex = NULL;
160
struct string_list lines;
161
int result = 0;
157
- enum commit_graph_write_flags flags = COMMIT_GRAPH_WRITE_PROGRESS;
162
+ enum commit_graph_write_flags flags = 0;
163
164
static struct option builtin_commit_graph_write_options[] = {
165
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -168,6 +173,7 @@ static int graph_write(int argc, const char **argv)
173
N_("start walk at commits listed by stdin")),
174
OPT_BOOL(0, "append", &opts.append,
175
N_("include all commits already in the commit-graph file")),
176
+ OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
177
OPT_BOOL(0, "split", &opts.split,
178
N_("allow writing an incremental commit-graph file")),
179
OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
@@ -179,6 +185,7 @@ static int graph_write(int argc, const char **argv)
185
OPT_END(),
186
};
187
188
+ opts.progress = isatty(2);
189
split_opts.size_multiple = 2;
190
split_opts.max_commits = 0;
191
split_opts.expire_time = 0;
@@ -195,6 +202,8 @@ static int graph_write(int argc, const char **argv)
202
flags |= COMMIT_GRAPH_WRITE_APPEND;
203
if (opts.split)
204
flags |= COMMIT_GRAPH_WRITE_SPLIT;
205
+ if (opts.progress)
206
+ flags |= COMMIT_GRAPH_WRITE_PROGRESS;
207
208
read_replace_refs = 0;
209
commit-graph.c
+4
-2
@@ -1992,8 +1992,10 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
1992
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
1993
return verify_commit_graph_error;
1994
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
+
1999
for (i = 0; i < g->num_commits; i++) {
2000
struct commit *graph_commit, *odb_commit;
2001
struct commit_list *graph_parents, *odb_parents;
t/t5318-commit-graph.sh
+36
@@ -124,6 +124,42 @@ test_expect_success 'Add more commits' '
124
git repack
125
'
126
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
+
163
# Current graph structure:
164
#
165
# __M3___
t/t5324-split-commit-graph.sh
+1
-1
@@ -320,7 +320,7 @@ test_expect_success 'add octopus merge' '
320
git merge commits/3 commits/4 &&
321
git branch merge/octopus &&
322
git commit-graph write --reachable --split &&
323
- git commit-graph verify 2>err &&
323
+ git commit-graph verify --progress 2>err &&
324
test_line_count = 3 err &&
325
test_i18ngrep ! warning err &&
326
test_line_count = 3 $graphdir/commit-graph-chain