Skip to content

Commit 434ea3c

Browse files
peffgitster
authored andcommitted
rev-list: add optional progress reporting
It's easy to ask rev-list to do a traversal that may takes many seconds (e.g., by calling "--objects --all"). In theory you can monitor its progress by the output you get to stdout, but this isn't always easy. Some operations, like "--count", don't make any output until the end. And some callers, like check_everything_connected(), are using it just for the error-checking of the traversal, and throw away stdout entirely. This patch adds a "--progress" option which can be used to give some eye-candy for a user waiting for a long traversal. This is just a rev-list option and not a regular traversal option, because it needs cooperation from the callbacks in builtin/rev-list.c to do the actual count. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f26eef3 commit 434ea3c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Documentation/rev-list-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ ifdef::git-rev-list[]
274274
Try to speed up the traversal using the pack bitmap index (if
275275
one is available). Note that when traversing with `--objects`,
276276
trees and blobs will not have their associated path printed.
277+
278+
--progress=<header>::
279+
Show progress reports on stderr as objects are considered. The
280+
`<header>` text will be printed with each progress update.
277281
endif::git-rev-list[]
278282

279283
--

builtin/rev-list.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "log-tree.h"
1010
#include "graph.h"
1111
#include "bisect.h"
12+
#include "progress.h"
1213

1314
static const char rev_list_usage[] =
1415
"git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -49,12 +50,17 @@ static const char rev_list_usage[] =
4950
" --bisect-all"
5051
;
5152

53+
static struct progress *progress;
54+
static unsigned progress_counter;
55+
5256
static void finish_commit(struct commit *commit, void *data);
5357
static void show_commit(struct commit *commit, void *data)
5458
{
5559
struct rev_list_info *info = data;
5660
struct rev_info *revs = info->revs;
5761

62+
display_progress(progress, ++progress_counter);
63+
5864
if (info->flags & REV_LIST_QUIET) {
5965
finish_commit(commit, data);
6066
return;
@@ -190,6 +196,7 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
190196
{
191197
struct rev_list_info *info = cb_data;
192198
finish_object(obj, name, cb_data);
199+
display_progress(progress, ++progress_counter);
193200
if (info->flags & REV_LIST_QUIET)
194201
return;
195202
show_object_with_name(stdout, obj, name);
@@ -276,6 +283,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
276283
int bisect_show_vars = 0;
277284
int bisect_find_all = 0;
278285
int use_bitmap_index = 0;
286+
const char *show_progress = NULL;
279287

280288
git_config(git_default_config, NULL);
281289
init_revisions(&revs, prefix);
@@ -325,6 +333,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
325333
test_bitmap_walk(&revs);
326334
return 0;
327335
}
336+
if (skip_prefix(arg, "--progress=", &arg)) {
337+
show_progress = arg;
338+
continue;
339+
}
328340
usage(rev_list_usage);
329341

330342
}
@@ -355,6 +367,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
355367
if (bisect_list)
356368
revs.limited = 1;
357369

370+
if (show_progress)
371+
progress = start_progress_delay(show_progress, 0, 0, 2);
372+
358373
if (use_bitmap_index && !revs.prune) {
359374
if (revs.count && !revs.left_right && !revs.cherry_mark) {
360375
uint32_t commit_count;
@@ -392,6 +407,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
392407

393408
traverse_commit_list(&revs, show_commit, show_object, &info);
394409

410+
stop_progress(&progress);
411+
395412
if (revs.count) {
396413
if (revs.left_right && revs.cherry_mark)
397414
printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);

0 commit comments

Comments
 (0)