Skip to content

Commit 9870757

Browse files
committed
Merge branch 'jk/rename-progress' into HEAD
* jk/rename-progress: diff: turn on rename detection progress reporting show: turn on rename detection progress reporting progress: use pager's original_stderr if available pager: save the original stderr when redirecting to pager # Conflicts: # pager.c
2 parents f39c324 + e1328f9 commit 9870757

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

Documentation/git-diff.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ include::diff-options.txt[]
139139
"Unmerged". Can be used only when comparing the working tree
140140
with the index.
141141

142+
--no-progress::
143+
--progress::
144+
Disable or enable progress reporting during long computations;
145+
the default is to enable progress reporting when stderr is a
146+
terminal. Currently the only computation with progress support
147+
is inexact rename detection.
148+
142149
<path>...::
143150
The <paths> parameters, when given, are used to limit
144151
the diff to the named paths (you can give directory

Documentation/git-log.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ include::line-range-options.txt[]
109109
Paths may need to be prefixed with `--` to separate them from
110110
options or the revision range, when confusion arises.
111111

112+
--no-progress::
113+
--progress::
114+
Disable or enable progress reporting during long computations;
115+
the default is to enable progress reporting when stderr is a
116+
terminal. Currently the only computation with progress support
117+
is inexact rename detection.
118+
112119
include::rev-list-options.txt[]
113120

114121
include::pretty-formats.txt[]

builtin/diff.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
399399
int nongit = 0, no_index = 0;
400400
int result;
401401
struct symdiff sdiff;
402+
int progress = -1;
403+
int unknown_argc, parsed_argc;
402404

403405
/*
404406
* We could get N tree-ish in the rev.pending_objects list.
@@ -503,6 +505,32 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
503505
diff_setup_done(&rev.diffopt);
504506
}
505507

508+
parsed_argc = 0;
509+
for (unknown_argc = i = 1; i < argc; i++) {
510+
const char *arg = argv[i];
511+
if (!strcmp(arg, "--") || arg[0] != '-') {
512+
int j;
513+
for (j = i; j < argc; j++)
514+
argv[unknown_argc++] = argv[j];
515+
break;
516+
}
517+
else if (!strcmp(argv[i], "--progress"))
518+
progress = 1;
519+
else if (!strcmp(argv[i], "--no-progress"))
520+
progress = 0;
521+
else {
522+
argv[unknown_argc++] = argv[i];
523+
continue;
524+
}
525+
parsed_argc++;
526+
}
527+
argc -= parsed_argc;
528+
529+
if (progress == -1)
530+
progress = isatty(2);
531+
if (progress)
532+
rev.diffopt.show_rename_progress = 1;
533+
506534
rev.diffopt.flags.recursive = 1;
507535
rev.diffopt.rotate_to_strict = 1;
508536

builtin/log.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static const char *fmt_patch_subject_prefix = "PATCH";
6565
static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
6666
static char *fmt_pretty;
6767
static int format_no_prefix;
68+
static int progress = -1;
6869

6970
static const char * const builtin_log_usage[] = {
7071
N_("git log [<options>] [<revision-range>] [[--] <path>...]"),
@@ -263,6 +264,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
263264
OPT_CALLBACK('L', NULL, &line_cb, "range:file",
264265
N_("trace the evolution of line range <start>,<end> or function :<funcname> in <file>"),
265266
log_line_range_callback),
267+
OPT_SET_INT(0, "progress", &progress,
268+
"force progress reporting", 1),
266269
OPT_END()
267270
};
268271

@@ -309,6 +312,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
309312
read_mailmap(rev->mailmap);
310313
}
311314

315+
if (progress == -1)
316+
progress = isatty(2);
317+
312318
if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {
313319
/*
314320
* "log --pretty=raw" is special; ignore UI oriented
@@ -510,18 +516,25 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
510516
if (rev->early_output)
511517
finish_early_output(rev);
512518

519+
if (progress)
520+
rev->diffopt.show_rename_progress = 1;
521+
513522
/*
514523
* For --check and --exit-code, the exit code is based on CHECK_FAILED
515524
* and HAS_CHANGES being accumulated in rev->diffopt, so be careful to
516525
* retain that state information if replacing rev->diffopt in this loop
517526
*/
518527
while ((commit = get_revision(rev)) != NULL) {
519-
if (!log_tree_commit(rev, commit) && rev->max_count >= 0)
528+
int showed = log_tree_commit(rev, commit);
529+
if (!showed && rev->max_count >= 0)
520530
/*
521531
* We decremented max_count in get_revision,
522532
* but we didn't actually show the commit.
523533
*/
524534
rev->max_count++;
535+
/* Once we have output, progress will clutter the terminal. */
536+
if (showed)
537+
rev->diffopt.show_rename_progress = 0;
525538
if (!rev->reflog_info) {
526539
/*
527540
* We may show a given commit multiple times when

environment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ extern char *editor_program;
223223
extern char *askpass_program;
224224
extern const char *excludes_file;
225225

226+
extern FILE *original_stderr;
227+
extern int original_stderr_fd;
228+
226229
/*
227230
* Should we print an ellipsis after an abbreviated SHA-1 value
228231
* when doing diff-raw output or indicating a detached HEAD?

pager.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
#include "sigchain.h"
77
#include "alias.h"
88
#include "compat/pipe-id.h"
9+
#include "environment.h"
910

1011
int pager_use_color = 1;
1112

1213
#ifndef DEFAULT_PAGER
1314
#define DEFAULT_PAGER "less"
1415
#endif
1516

17+
FILE *original_stderr;
18+
int original_stderr_fd = -1;
1619
static struct child_process pager_process;
1720
static char *pager_program;
1821

@@ -143,8 +146,11 @@ void setup_pager(void)
143146

144147
/* original process continues, but writes to the pipe */
145148
dup2(pager_process.in, 1);
146-
if (isatty(2))
149+
if (isatty(2)) {
150+
original_stderr_fd = dup(2);
151+
original_stderr = fdopen(original_stderr_fd, "w");
147152
dup2(pager_process.in, 2);
153+
}
148154
close(pager_process.in);
149155

150156
pipe_id = pipe_id_get(1);

progress.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "trace2.h"
1919
#include "utf8.h"
2020
#include "parse.h"
21+
#include "environment.h"
2122

2223
#define TP_IDX_MAX 8
2324

@@ -108,6 +109,7 @@ static int is_foreground_fd(int fd)
108109

109110
static void display(struct progress *progress, uint64_t n, const char *done)
110111
{
112+
FILE *out = original_stderr ? original_stderr : stderr;
111113
const char *tp;
112114
struct strbuf *counters_sb = &progress->counters_sb;
113115
int show_update = 0;
@@ -137,7 +139,7 @@ static void display(struct progress *progress, uint64_t n, const char *done)
137139
}
138140

139141
if (show_update) {
140-
if (is_foreground_fd(fileno(stderr)) || done) {
142+
if (is_foreground_fd(fileno(out)) || done) {
141143
const char *eol = done ? done : "\r";
142144
size_t clear_len = counters_sb->len < last_count_len ?
143145
last_count_len - counters_sb->len + 1 :
@@ -148,20 +150,20 @@ static void display(struct progress *progress, uint64_t n, const char *done)
148150
int cols = term_columns();
149151

150152
if (progress->split) {
151-
fprintf(stderr, " %s%*s", counters_sb->buf,
153+
fprintf(out, " %s%*s", counters_sb->buf,
152154
(int) clear_len, eol);
153155
} else if (!done && cols < progress_line_len) {
154156
clear_len = progress->title_len + 1 < cols ?
155157
cols - progress->title_len - 1 : 0;
156-
fprintf(stderr, "%s:%*s\n %s%s",
158+
fprintf(out, "%s:%*s\n %s%s",
157159
progress->title, (int) clear_len, "",
158160
counters_sb->buf, eol);
159161
progress->split = 1;
160162
} else {
161-
fprintf(stderr, "%s: %s%*s", progress->title,
163+
fprintf(out, "%s: %s%*s", progress->title,
162164
counters_sb->buf, (int) clear_len, eol);
163165
}
164-
fflush(stderr);
166+
fflush(out);
165167
}
166168
progress_update = 0;
167169
}

0 commit comments

Comments
 (0)