Skip to content

Commit 18b33bf

Browse files
committed
Merge branch 'nk/blame-abbrev'
* nk/blame-abbrev: blame: add --abbrev command line option and make it honor core.abbrev
2 parents fcbf164 + 84393bf commit 18b33bf

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Documentation/git-blame.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m]
12-
[-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
12+
[-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [--abbrev=<n>]
1313
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
1414

1515
DESCRIPTION
@@ -73,6 +73,11 @@ include::blame-options.txt[]
7373
Ignore whitespace when comparing the parent's version and
7474
the child's to find where the lines came from.
7575

76+
--abbrev=<n>::
77+
Instead of using the default 7+1 hexadecimal digits as the
78+
abbreviated object name, use <n>+1 digits. Note that 1 column
79+
is used for a caret to mark the boundary commit.
80+
7681

7782
THE PORCELAIN FORMAT
7883
--------------------

builtin/blame.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static int reverse;
4141
static int blank_boundary;
4242
static int incremental;
4343
static int xdl_opts;
44+
static int abbrev = -1;
4445

4546
static enum date_mode blame_date_mode = DATE_ISO8601;
4647
static size_t blame_date_width;
@@ -1670,7 +1671,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
16701671
cp = nth_line(sb, ent->lno);
16711672
for (cnt = 0; cnt < ent->num_lines; cnt++) {
16721673
char ch;
1673-
int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8;
1674+
int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : abbrev;
16741675

16751676
if (suspect->commit->object.flags & UNINTERESTING) {
16761677
if (blank_boundary)
@@ -2310,6 +2311,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
23102311
{ OPTION_CALLBACK, 'C', NULL, &opt, "score", "Find line copies within and across files", PARSE_OPT_OPTARG, blame_copy_callback },
23112312
{ OPTION_CALLBACK, 'M', NULL, &opt, "score", "Find line movements within and across files", PARSE_OPT_OPTARG, blame_move_callback },
23122313
OPT_CALLBACK('L', NULL, &bottomtop, "n,m", "Process only line range n,m, counting from 1", blame_bottomtop_callback),
2314+
OPT__ABBREV(&abbrev),
23132315
OPT_END()
23142316
};
23152317

@@ -2345,6 +2347,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
23452347
parse_done:
23462348
argc = parse_options_end(&ctx);
23472349

2350+
if (abbrev == -1)
2351+
abbrev = default_abbrev;
2352+
/* one more abbrev length is needed for the boundary commit */
2353+
abbrev++;
2354+
23482355
if (revs_file && read_ancestry(revs_file))
23492356
die_errno("reading graft file '%s' failed", revs_file);
23502357

0 commit comments

Comments
 (0)