Skip to content

Commit 0f03ca9

Browse files
Peter BaumannJunio C Hamano
authored andcommitted
config option log.showroot to show the diff of root commits
This allows one to see a root commit as a diff in commands like git-log, git-show and git-whatchanged. Signed-off-by: Peter Baumann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fbe2d5 commit 0f03ca9

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ i18n.commitEncoding::
219219
browser (and possibly at other places in the future or in other
220220
porcelains). See e.g. gitlink:git-mailinfo[1]. Defaults to 'utf-8'.
221221

222+
log.showroot::
223+
If true, the initial commit will be shown as a big creation event.
224+
This is equivalent to a diff against an empty tree.
225+
Tools like gitlink:git-log[1] or gitlink:git-whatchanged[1], which
226+
normally hide the root commit will now show it. True by default.
227+
222228
merge.summary::
223229
Whether to include summaries of merged commits in newly created
224230
merge commit messages. False by default.

builtin-log.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <time.h>
1414
#include <sys/time.h>
1515

16+
static int default_show_root = 1;
17+
1618
/* this is in builtin-diff.c */
1719
void add_head(struct rev_info *revs);
1820

@@ -22,6 +24,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
2224
rev->abbrev = DEFAULT_ABBREV;
2325
rev->commit_format = CMIT_FMT_DEFAULT;
2426
rev->verbose_header = 1;
27+
rev->show_root_diff = default_show_root;
2528
argc = setup_revisions(argc, argv, rev, "HEAD");
2629
if (rev->diffopt.pickaxe || rev->diffopt.filter)
2730
rev->always_show_header = 0;
@@ -44,11 +47,20 @@ static int cmd_log_walk(struct rev_info *rev)
4447
return 0;
4548
}
4649

50+
static int git_log_config(const char *var, const char *value)
51+
{
52+
if (!strcmp(var, "log.showroot")) {
53+
default_show_root = git_config_bool(var, value);
54+
return 0;
55+
}
56+
return git_diff_ui_config(var, value);
57+
}
58+
4759
int cmd_whatchanged(int argc, const char **argv, const char *prefix)
4860
{
4961
struct rev_info rev;
5062

51-
git_config(git_diff_ui_config);
63+
git_config(git_log_config);
5264
init_revisions(&rev, prefix);
5365
rev.diff = 1;
5466
rev.diffopt.recursive = 1;
@@ -63,7 +75,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
6375
{
6476
struct rev_info rev;
6577

66-
git_config(git_diff_ui_config);
78+
git_config(git_log_config);
6779
init_revisions(&rev, prefix);
6880
rev.diff = 1;
6981
rev.diffopt.recursive = 1;
@@ -80,7 +92,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
8092
{
8193
struct rev_info rev;
8294

83-
git_config(git_diff_ui_config);
95+
git_config(git_log_config);
8496
init_revisions(&rev, prefix);
8597
rev.always_show_header = 1;
8698
cmd_log_init(argc, argv, prefix, &rev);
@@ -109,7 +121,7 @@ static int git_format_config(const char *var, const char *value)
109121
if (!strcmp(var, "diff.color")) {
110122
return 0;
111123
}
112-
return git_diff_ui_config(var, value);
124+
return git_log_config(var, value);
113125
}
114126

115127

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ test_expect_success setup '
7373
for i in 1 2; do echo $i; done >>dir/sub &&
7474
git update-index file0 dir/sub &&
7575
76+
git repo-config log.showroot false &&
7677
git commit --amend &&
7778
git show-branch
7879
'

0 commit comments

Comments
 (0)