Skip to content

Commit 72d2591

Browse files
committed
Merge branch 'ea/blame-progress'
"git blame" learned to produce the progress eye-candy when it takes too much time before emitting the first line of the result. * ea/blame-progress: blame: add support for --[no-]progress option
2 parents 187c0d3 + aba37f4 commit 72d2591

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

Documentation/blame-options.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ include::line-range-format.txt[]
6969
iso format is used. For supported values, see the discussion
7070
of the --date option at linkgit:git-log[1].
7171

72+
--[no-]progress::
73+
Progress status is reported on the standard error stream
74+
by default when it is attached to a terminal. This flag
75+
enables progress reporting even if not attached to a
76+
terminal. Can't use `--progress` together with `--porcelain`
77+
or `--incremental`.
78+
7279
-M|<num>|::
7380
Detect moved or copied lines within a file. When a commit
7481
moves or copies a block of lines (e.g. the original file

Documentation/git-blame.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ SYNOPSIS
1010
[verse]
1111
'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]
1212
[-L <range>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
13-
[--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>] [--] <file>
13+
[--progress] [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>]
14+
[--] <file>
1415

1516
DESCRIPTION
1617
-----------

builtin/blame.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "line-range.h"
2929
#include "line-log.h"
3030
#include "dir.h"
31+
#include "progress.h"
3132

3233
static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
3334

@@ -50,6 +51,7 @@ static int incremental;
5051
static int xdl_opts;
5152
static int abbrev = -1;
5253
static int no_whole_file_rename;
54+
static int show_progress;
5355

5456
static struct date_mode blame_date_mode = { DATE_ISO8601 };
5557
static size_t blame_date_width;
@@ -127,6 +129,11 @@ struct origin {
127129
char path[FLEX_ARRAY];
128130
};
129131

132+
struct progress_info {
133+
struct progress *progress;
134+
int blamed_lines;
135+
};
136+
130137
static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,
131138
xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)
132139
{
@@ -1746,7 +1753,8 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
17461753
* The blame_entry is found to be guilty for the range.
17471754
* Show it in incremental output.
17481755
*/
1749-
static void found_guilty_entry(struct blame_entry *ent)
1756+
static void found_guilty_entry(struct blame_entry *ent,
1757+
struct progress_info *pi)
17501758
{
17511759
if (incremental) {
17521760
struct origin *suspect = ent->suspect;
@@ -1758,6 +1766,8 @@ static void found_guilty_entry(struct blame_entry *ent)
17581766
write_filename_info(suspect->path);
17591767
maybe_flush_or_die(stdout, "stdout");
17601768
}
1769+
pi->blamed_lines += ent->num_lines;
1770+
display_progress(pi->progress, pi->blamed_lines);
17611771
}
17621772

17631773
/*
@@ -1768,6 +1778,11 @@ static void assign_blame(struct scoreboard *sb, int opt)
17681778
{
17691779
struct rev_info *revs = sb->revs;
17701780
struct commit *commit = prio_queue_get(&sb->commits);
1781+
struct progress_info pi = { NULL, 0 };
1782+
1783+
if (show_progress)
1784+
pi.progress = start_progress_delay(_("Blaming lines"),
1785+
sb->num_lines, 50, 1);
17711786

17721787
while (commit) {
17731788
struct blame_entry *ent;
@@ -1809,7 +1824,7 @@ static void assign_blame(struct scoreboard *sb, int opt)
18091824
suspect->guilty = 1;
18101825
for (;;) {
18111826
struct blame_entry *next = ent->next;
1812-
found_guilty_entry(ent);
1827+
found_guilty_entry(ent, &pi);
18131828
if (next) {
18141829
ent = next;
18151830
continue;
@@ -1825,6 +1840,8 @@ static void assign_blame(struct scoreboard *sb, int opt)
18251840
if (DEBUG) /* sanity */
18261841
sanity_check_refcnt(sb);
18271842
}
1843+
1844+
stop_progress(&pi.progress);
18281845
}
18291846

18301847
static const char *format_time(unsigned long time, const char *tz_str,
@@ -2520,6 +2537,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25202537
OPT_BOOL('b', NULL, &blank_boundary, N_("Show blank SHA-1 for boundary commits (Default: off)")),
25212538
OPT_BOOL(0, "root", &show_root, N_("Do not treat root commits as boundaries (Default: off)")),
25222539
OPT_BOOL(0, "show-stats", &show_stats, N_("Show work cost statistics")),
2540+
OPT_BOOL(0, "progress", &show_progress, N_("Force progress reporting")),
25232541
OPT_BIT(0, "score-debug", &output_option, N_("Show output score for blame entries"), OUTPUT_SHOW_SCORE),
25242542
OPT_BIT('f', "show-name", &output_option, N_("Show original filename (Default: auto)"), OUTPUT_SHOW_NAME),
25252543
OPT_BIT('n', "show-number", &output_option, N_("Show original linenumber (Default: off)"), OUTPUT_SHOW_NUMBER),
@@ -2555,6 +2573,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25552573

25562574
save_commit_buffer = 0;
25572575
dashdash_pos = 0;
2576+
show_progress = -1;
25582577

25592578
parse_options_start(&ctx, argc, argv, prefix, options,
25602579
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
@@ -2579,6 +2598,13 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25792598
DIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);
25802599
argc = parse_options_end(&ctx);
25812600

2601+
if (incremental || (output_option & OUTPUT_PORCELAIN)) {
2602+
if (show_progress > 0)
2603+
die("--progress can't be used with --incremental or porcelain formats");
2604+
show_progress = 0;
2605+
} else if (show_progress < 0)
2606+
show_progress = isatty(2);
2607+
25822608
if (0 < abbrev)
25832609
/* one more abbrev length is needed for the boundary commit */
25842610
abbrev++;
@@ -2828,11 +2854,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
28282854

28292855
read_mailmap(&mailmap, NULL);
28302856

2857+
assign_blame(&sb, opt);
2858+
28312859
if (!incremental)
28322860
setup_pager();
28332861

2834-
assign_blame(&sb, opt);
2835-
28362862
free(final_commit_name);
28372863

28382864
if (incremental)

0 commit comments

Comments
 (0)