Skip to content

Commit f9efd76

Browse files
committed
diff: turn on rename detection progress reporting
Since all of the progress happens before we generate any output, this looks OK, even when output goes to a pager. We do the usual --progress/--no-progress options and check isatty(2) to enable the feature. The argument parsing is a little ad-hoc, but we currently have no parse-options infrastructure here at all. However, it should be safe to parse like this, because the prior call to setup_revisions will have removed any options that take an argument, and our parsing removes --progress from argv for later parsers. The one exception is diff_no_index, which may get called early, and needs to learn to ignore --progress. Signed-off-by: Jeff King <peff@peff.net>
1 parent 5bd5c48 commit f9efd76

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Documentation/git-diff.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ section "3-Way Merge" for detailed information.
152152
"Unmerged". Can be used only when comparing the working tree
153153
with the index.
154154
155+
`--no-progress`::
156+
`--progress`::
157+
Disable or enable progress reporting during long computations;
158+
the default is to enable progress reporting when stderr is a
159+
terminal. Currently the only computation with progress support
160+
is inexact rename detection.
161+
155162
`<path>...`::
156163
The _<path>_ parameters, when given, are used to limit
157164
the diff to the named paths (you can give directory

builtin/diff.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ int cmd_diff(int argc,
410410
int nongit = 0, no_index = 0;
411411
int result;
412412
struct symdiff sdiff;
413+
int progress = -1;
414+
int unknown_argc, parsed_argc;
413415

414416
/*
415417
* We could get N tree-ish in the rev.pending_objects list.
@@ -539,6 +541,32 @@ int cmd_diff(int argc,
539541
diff_setup_done(&rev.diffopt);
540542
}
541543

544+
parsed_argc = 0;
545+
for (unknown_argc = i = 1; i < argc; i++) {
546+
const char *arg = argv[i];
547+
if (!strcmp(arg, "--") || arg[0] != '-') {
548+
int j;
549+
for (j = i; j < argc; j++)
550+
argv[unknown_argc++] = argv[j];
551+
break;
552+
}
553+
else if (!strcmp(argv[i], "--progress"))
554+
progress = 1;
555+
else if (!strcmp(argv[i], "--no-progress"))
556+
progress = 0;
557+
else {
558+
argv[unknown_argc++] = argv[i];
559+
continue;
560+
}
561+
parsed_argc++;
562+
}
563+
argc -= parsed_argc;
564+
565+
if (progress == -1)
566+
progress = isatty(2);
567+
if (progress)
568+
rev.diffopt.show_rename_progress = 1;
569+
542570
rev.diffopt.flags.recursive = 1;
543571
rev.diffopt.rotate_to_strict = 1;
544572

0 commit comments

Comments
 (0)