blame: -b (blame.blankboundary) and --root (blame.showroot)
When blame.blankboundary is set (or -b option is given), commit object names are blanked out in the "human readable" output format for boundary commits. When blame.showroot is not set (or --root is not given), the root commits are treated as boundary commits. The code still attributes the lines to them, but with -b their object names are not shown. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 18, 2006 at 14:04 UTC
4c10a5caa7d5e481a2acefbae71b694ab7e57108
1 file changed
+31
-2
builtin-blame.c
+31
-2
@@ -22,7 +22,9 @@
22
static char blame_usage[] =
23
"git-blame [-c] [-l] [-t] [-f] [-n] [-p] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [commit] [--] file\n"
24
" -c, --compatibility Use the same output mode as git-annotate (Default: off)\n"
25
+" -b Show blank SHA-1 for boundary commits (Default: off)\n"
26
" -l, --long Show long commit SHA1 (Default: off)\n"
27
+" --root Do not treat root commits as boundaries (Default: off)\n"
28
" -t, --time Show raw timestamp (Default: off)\n"
29
" -f, --show-name Show original filename (Default: auto)\n"
30
" -n, --show-number Show original linenumber (Default: off)\n"
@@ -36,6 +38,8 @@ static int longest_author;
38
static int max_orig_digits;
39
static int max_digits;
40
static int max_score_digits;
41
+static int show_root;
42
+static int blank_boundary;
43
44
#ifndef DEBUG
45
#define DEBUG 0
@@ -1095,6 +1099,9 @@ static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
1099
if (commit->object.parsed)
1100
mark_parents_uninteresting(commit);
1101
}
1102
+ /* treat root commit as boundary */
1103
+ if (!commit->parents && !show_root)
1104
+ commit->object.flags |= UNINTERESTING;
1105
1106
/* Take responsibility for the remaining entries */
1107
for (ent = sb->ent; ent; ent = ent->next)
@@ -1318,8 +1325,12 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1325
int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8;
1326
1327
if (suspect->commit->object.flags & UNINTERESTING) {
1321
- length--;
1322
- putchar('^');
1328
+ if (!blank_boundary) {
1329
+ length--;
1330
+ putchar('^');
1331
+ }
1332
+ else
1333
+ memset(hex, ' ', length);
1334
}
1335
1336
printf("%.*s", length, hex);
@@ -1639,6 +1650,19 @@ static void prepare_blame_range(struct scoreboard *sb,
1650
usage(blame_usage);
1651
}
1652
1653
+static int git_blame_config(const char *var, const char *value)
1654
+{
1655
+ if (!strcmp(var, "blame.showroot")) {
1656
+ show_root = git_config_bool(var, value);
1657
+ return 0;
1658
+ }
1659
+ if (!strcmp(var, "blame.blankboundary")) {
1660
+ blank_boundary = git_config_bool(var, value);
1661
+ return 0;
1662
+ }
1663
+ return git_default_config(var, value);
1664
+}
1665
+
1666
int cmd_blame(int argc, const char **argv, const char *prefix)
1667
{
1668
struct rev_info revs;
@@ -1654,6 +1678,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
1678
char type[10];
1679
const char *bottomtop = NULL;
1680
1681
+ git_config(git_blame_config);
1682
save_commit_buffer = 0;
1683
1684
opt = 0;
@@ -1662,6 +1687,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
1687
const char *arg = argv[i];
1688
if (*arg != '-')
1689
break;
1690
+ else if (!strcmp("-b", arg))
1691
+ blank_boundary = 1;
1692
+ else if (!strcmp("--root", arg))
1693
+ show_root = 1;
1694
else if (!strcmp("-c", arg))
1695
output_option |= OUTPUT_ANNOTATE_COMPAT;
1696
else if (!strcmp("-t", arg))