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 <gitster@pobox.com>
Junio C Hamano committed
Mar 29, 2016 at 15:49 UTC
0893eec85fca0f76039a96cbbcd3592ff8571c24
6 files changed
+28
-9
Documentation/pretty-options.txt
+6
@@ -43,9 +43,15 @@ people using 80-column terminals.
43
commit may be copied to the output.
44
45
--expand-tabs::
46
+--no-expand-tabs::
47
Perform a tab expansion (replace each tab with enough spaces
48
to fill to the next display column that is multiple of 8)
49
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.
55
56
ifndef::git-rev-list[]
57
--notes[=<ref>]::
builtin/log.c
+1
@@ -1281,6 +1281,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1281
git_config(git_format_config, NULL);
1282
init_revisions(&rev, prefix);
1283
rev.commit_format = CMIT_FMT_EMAIL;
1284
+ rev.expand_tabs_in_log_default = 0;
1285
rev.verbose_header = 1;
1286
rev.diff = 1;
1287
rev.max_parents = 1;
pretty.c
+11
-7
@@ -16,6 +16,7 @@ static struct cmt_fmt_map {
16
const char *name;
17
enum cmit_fmt format;
18
int is_tformat;
19
+ int expand_tabs_in_log;
20
int is_alias;
21
const char *user_format;
22
} *commit_formats;
@@ -87,13 +88,13 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
88
static void setup_commit_formats(void)
89
{
90
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 }
98
};
99
commit_formats_len = ARRAY_SIZE(builtin_formats);
100
builtin_formats_len = commit_formats_len;
@@ -172,6 +173,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
173
174
rev->commit_format = commit_format->format;
175
rev->use_terminator = commit_format->is_tformat;
176
+ rev->expand_tabs_in_log_default = commit_format->expand_tabs_in_log;
177
if (commit_format->format == CMIT_FMT_USERFORMAT) {
178
save_user_format(rev, commit_format->user_format,
179
commit_format->is_tformat);
@@ -1720,6 +1722,8 @@ void pp_remainder(struct pretty_print_context *pp,
1722
strbuf_grow(sb, linelen + indent + 20);
1723
if (indent)
1724
pp_handle_indent(pp, sb, indent, line, linelen);
1725
+ else if (pp->expand_tabs_in_log)
1726
+ strbuf_add_tabexpand(sb, line, linelen);
1727
else
1728
strbuf_add(sb, line, linelen);
1729
strbuf_addch(sb, '\n');
revision.c
+7
@@ -1412,8 +1412,10 @@ void init_revisions(struct rev_info *revs, const char *prefix)
1412
revs->skip_count = -1;
1413
revs->max_count = -1;
1414
revs->max_parents = -1;
1415
+ revs->expand_tabs_in_log = -1;
1416
1417
revs->commit_format = CMIT_FMT_DEFAULT;
1418
+ revs->expand_tabs_in_log_default = 1;
1419
1420
init_grep_defaults();
1421
grep_init(&revs->grep_filter, prefix);
@@ -1917,6 +1919,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1919
get_commit_format(arg+9, revs);
1920
} else if (!strcmp(arg, "--expand-tabs")) {
1921
revs->expand_tabs_in_log = 1;
1922
+ } else if (!strcmp(arg, "--no-expand-tabs")) {
1923
+ revs->expand_tabs_in_log = 0;
1924
} else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
1925
revs->show_notes = 1;
1926
revs->show_notes_given = 1;
@@ -2390,6 +2394,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
2394
if (revs->first_parent_only && revs->bisect)
2395
die(_("--first-parent is incompatible with --bisect"));
2396
2397
+ if (revs->expand_tabs_in_log < 0)
2398
+ revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
2399
+
2400
return left;
2401
}
2402
revision.h
+2
-1
@@ -133,7 +133,6 @@ struct rev_info {
133
show_notes_given:1,
134
show_signature:1,
135
pretty_given:1,
136
- expand_tabs_in_log:1,
136
abbrev_commit:1,
137
abbrev_commit_given:1,
138
zero_commit:1,
@@ -149,6 +148,8 @@ struct rev_info {
148
linear:1;
149
150
struct date_mode date_mode;
151
+ int expand_tabs_in_log; /* unset if negative */
152
+ int expand_tabs_in_log_default;
153
154
unsigned int abbrev;
155
enum cmit_fmt commit_format;
t/t4201-shortlog.sh
+1
-1
@@ -115,7 +115,7 @@ EOF
115
'
116
117
test_expect_success !MINGW 'shortlog from non-git directory' '
118
- git log HEAD >log &&
118
+ git log --no-expand-tabs HEAD >log &&
119
GIT_DIR=non-existing git shortlog -w <log >out &&
120
test_cmp expect out
121
'