blame: add --abbrev command line option and make it honor core.abbrev
If user sets config.abbrev option, use it as if --abbrev was given. This is the default value and user can override different abbrev length by specifying the --abbrev=N command line option. Signed-off-by: Namhyung Kim <namhyung@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Namhyung Kim committed
Apr 6, 2011 at 11:20 UTC
84393bfd731c435120dc1dda63432a70124821cb
2 files changed
+14
-2
Documentation/git-blame.txt
+6
-1
@@ -9,7 +9,7 @@ SYNOPSIS
9
--------
10
[verse]
11
'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>]
13
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
14
15
DESCRIPTION
@@ -73,6 +73,11 @@ include::blame-options.txt[]
73
Ignore whitespace when comparing the parent's version and
74
the child's to find where the lines came from.
75
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
+
81
82
THE PORCELAIN FORMAT
83
--------------------
builtin/blame.c
+8
-1
@@ -41,6 +41,7 @@ static int reverse;
41
static int blank_boundary;
42
static int incremental;
43
static int xdl_opts;
44
+static int abbrev = -1;
45
46
static enum date_mode blame_date_mode = DATE_ISO8601;
47
static size_t blame_date_width;
@@ -1670,7 +1671,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1671
cp = nth_line(sb, ent->lno);
1672
for (cnt = 0; cnt < ent->num_lines; cnt++) {
1673
char ch;
1673
- int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8;
1674
+ int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : abbrev;
1675
1676
if (suspect->commit->object.flags & UNINTERESTING) {
1677
if (blank_boundary)
@@ -2310,6 +2311,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2311
{ OPTION_CALLBACK, 'C', NULL, &opt, "score", "Find line copies within and across files", PARSE_OPT_OPTARG, blame_copy_callback },
2312
{ OPTION_CALLBACK, 'M', NULL, &opt, "score", "Find line movements within and across files", PARSE_OPT_OPTARG, blame_move_callback },
2313
OPT_CALLBACK('L', NULL, &bottomtop, "n,m", "Process only line range n,m, counting from 1", blame_bottomtop_callback),
2314
+ OPT__ABBREV(&abbrev),
2315
OPT_END()
2316
};
2317
@@ -2345,6 +2347,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2347
parse_done:
2348
argc = parse_options_end(&ctx);
2349
2350
+ if (abbrev == -1)
2351
+ abbrev = default_abbrev;
2352
+ /* one more abbrev length is needed for the boundary commit */
2353
+ abbrev++;
2354
+
2355
if (revs_file && read_ancestry(revs_file))
2356
die_errno("reading graft file '%s' failed", revs_file);
2357