Skip to content

Commit 0893eec

Browse files
committed
pretty: enable --expand-tabs by default for selected pretty formats
"git log --pretty={medium,full,fuller}" and "git log" by default prepend 4 spaces to the log message, so it makes sense to enable the new "expand-tabs" facility by default for these formats. Add --no-expand-tabs option to override the new default. The change alone breaks a test in t4201 that runs "git shortlog" on the output from "git log", and expects that the output from "git log" does not do such a tab expansion. Adjust the test to explicitly disable expand-tabs with --no-expand-tabs. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7cc13c7 commit 0893eec

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

Documentation/pretty-options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ people using 80-column terminals.
4343
commit may be copied to the output.
4444

4545
--expand-tabs::
46+
--no-expand-tabs::
4647
Perform a tab expansion (replace each tab with enough spaces
4748
to fill to the next display column that is multiple of 8)
4849
in the log message before showing it in the output.
50+
+
51+
By default, tabs are expanded in pretty formats that indent the log
52+
message by 4 spaces (i.e. 'medium', which is the default, 'full',
53+
and 'fuller'). `--no-expand-tabs` option can be used to disable
54+
this.
4955

5056
ifndef::git-rev-list[]
5157
--notes[=<ref>]::

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
12811281
git_config(git_format_config, NULL);
12821282
init_revisions(&rev, prefix);
12831283
rev.commit_format = CMIT_FMT_EMAIL;
1284+
rev.expand_tabs_in_log_default = 0;
12841285
rev.verbose_header = 1;
12851286
rev.diff = 1;
12861287
rev.max_parents = 1;

pretty.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static struct cmt_fmt_map {
1616
const char *name;
1717
enum cmit_fmt format;
1818
int is_tformat;
19+
int expand_tabs_in_log;
1920
int is_alias;
2021
const char *user_format;
2122
} *commit_formats;
@@ -87,13 +88,13 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
8788
static void setup_commit_formats(void)
8889
{
8990
struct cmt_fmt_map builtin_formats[] = {
90-
{ "raw", CMIT_FMT_RAW, 0 },
91-
{ "medium", CMIT_FMT_MEDIUM, 0 },
92-
{ "short", CMIT_FMT_SHORT, 0 },
93-
{ "email", CMIT_FMT_EMAIL, 0 },
94-
{ "fuller", CMIT_FMT_FULLER, 0 },
95-
{ "full", CMIT_FMT_FULL, 0 },
96-
{ "oneline", CMIT_FMT_ONELINE, 1 }
91+
{ "raw", CMIT_FMT_RAW, 0, 0 },
92+
{ "medium", CMIT_FMT_MEDIUM, 0, 1 },
93+
{ "short", CMIT_FMT_SHORT, 0, 0 },
94+
{ "email", CMIT_FMT_EMAIL, 0, 0 },
95+
{ "fuller", CMIT_FMT_FULLER, 0, 1 },
96+
{ "full", CMIT_FMT_FULL, 0, 1 },
97+
{ "oneline", CMIT_FMT_ONELINE, 1, 0 }
9798
};
9899
commit_formats_len = ARRAY_SIZE(builtin_formats);
99100
builtin_formats_len = commit_formats_len;
@@ -172,6 +173,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
172173

173174
rev->commit_format = commit_format->format;
174175
rev->use_terminator = commit_format->is_tformat;
176+
rev->expand_tabs_in_log_default = commit_format->expand_tabs_in_log;
175177
if (commit_format->format == CMIT_FMT_USERFORMAT) {
176178
save_user_format(rev, commit_format->user_format,
177179
commit_format->is_tformat);
@@ -1720,6 +1722,8 @@ void pp_remainder(struct pretty_print_context *pp,
17201722
strbuf_grow(sb, linelen + indent + 20);
17211723
if (indent)
17221724
pp_handle_indent(pp, sb, indent, line, linelen);
1725+
else if (pp->expand_tabs_in_log)
1726+
strbuf_add_tabexpand(sb, line, linelen);
17231727
else
17241728
strbuf_add(sb, line, linelen);
17251729
strbuf_addch(sb, '\n');

revision.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,10 @@ void init_revisions(struct rev_info *revs, const char *prefix)
14121412
revs->skip_count = -1;
14131413
revs->max_count = -1;
14141414
revs->max_parents = -1;
1415+
revs->expand_tabs_in_log = -1;
14151416

14161417
revs->commit_format = CMIT_FMT_DEFAULT;
1418+
revs->expand_tabs_in_log_default = 1;
14171419

14181420
init_grep_defaults();
14191421
grep_init(&revs->grep_filter, prefix);
@@ -1917,6 +1919,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19171919
get_commit_format(arg+9, revs);
19181920
} else if (!strcmp(arg, "--expand-tabs")) {
19191921
revs->expand_tabs_in_log = 1;
1922+
} else if (!strcmp(arg, "--no-expand-tabs")) {
1923+
revs->expand_tabs_in_log = 0;
19201924
} else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
19211925
revs->show_notes = 1;
19221926
revs->show_notes_given = 1;
@@ -2390,6 +2394,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
23902394
if (revs->first_parent_only && revs->bisect)
23912395
die(_("--first-parent is incompatible with --bisect"));
23922396

2397+
if (revs->expand_tabs_in_log < 0)
2398+
revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
2399+
23932400
return left;
23942401
}
23952402

revision.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ struct rev_info {
133133
show_notes_given:1,
134134
show_signature:1,
135135
pretty_given:1,
136-
expand_tabs_in_log:1,
137136
abbrev_commit:1,
138137
abbrev_commit_given:1,
139138
zero_commit:1,
@@ -149,6 +148,8 @@ struct rev_info {
149148
linear:1;
150149

151150
struct date_mode date_mode;
151+
int expand_tabs_in_log; /* unset if negative */
152+
int expand_tabs_in_log_default;
152153

153154
unsigned int abbrev;
154155
enum cmit_fmt commit_format;

t/t4201-shortlog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ EOF
115115
'
116116

117117
test_expect_success !MINGW 'shortlog from non-git directory' '
118-
git log HEAD >log &&
118+
git log --no-expand-tabs HEAD >log &&
119119
GIT_DIR=non-existing git shortlog -w <log >out &&
120120
test_cmp expect out
121121
'

0 commit comments

Comments
 (0)