From 7cc13c717b52d3539e76f087d747f96d0d24a914 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 16 Mar 2016 09:15:53 -0700 Subject: pretty: expand tabs in indented logs to make things line up properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A commit log message sometimes tries to line things up using tabs, assuming fixed-width font with the standard 8-place tab settings. Viewing such a commit however does not work well in "git log", as we indent the lines by prefixing 4 spaces in front of them. This should all line up: Column 1 Column 2 -------- -------- A B ABCD EFGH SPACES Instead of Tabs Even with multi-byte UTF8 characters: Column 1 Column 2 -------- -------- Ä B åäö 100 A Møøse once bit my sister.. Tab-expand the lines in "git log --expand-tabs" output before prefixing 4 spaces. This is based on the patch by Linus Torvalds, but at this step, we require an explicit command line option to enable the behaviour. Signed-off-by: Junio C Hamano --- revision.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'revision.c') diff --git a/revision.c b/revision.c index df56fcea0e..e662230ff1 100644 --- a/revision.c +++ b/revision.c @@ -1915,6 +1915,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->verbose_header = 1; revs->pretty_given = 1; get_commit_format(arg+9, revs); + } else if (!strcmp(arg, "--expand-tabs")) { + revs->expand_tabs_in_log = 1; } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { revs->show_notes = 1; revs->show_notes_given = 1; -- cgit v1.2.3 From 0893eec85fca0f76039a96cbbcd3592ff8571c24 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 29 Mar 2016 15:49:24 -0700 Subject: 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 --- revision.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'revision.c') diff --git a/revision.c b/revision.c index e662230ff1..da53b6ce35 100644 --- a/revision.c +++ b/revision.c @@ -1412,8 +1412,10 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->skip_count = -1; revs->max_count = -1; revs->max_parents = -1; + revs->expand_tabs_in_log = -1; revs->commit_format = CMIT_FMT_DEFAULT; + revs->expand_tabs_in_log_default = 1; init_grep_defaults(); grep_init(&revs->grep_filter, prefix); @@ -1917,6 +1919,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg get_commit_format(arg+9, revs); } else if (!strcmp(arg, "--expand-tabs")) { revs->expand_tabs_in_log = 1; + } else if (!strcmp(arg, "--no-expand-tabs")) { + revs->expand_tabs_in_log = 0; } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { revs->show_notes = 1; revs->show_notes_given = 1; @@ -2390,6 +2394,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s if (revs->first_parent_only && revs->bisect) die(_("--first-parent is incompatible with --bisect")); + if (revs->expand_tabs_in_log < 0) + revs->expand_tabs_in_log = revs->expand_tabs_in_log_default; + return left; } -- cgit v1.2.3 From fe37a9c586a65943e1bca327a1bbe1ca4a3d3023 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 29 Mar 2016 16:05:39 -0700 Subject: pretty: allow tweaking tabwidth in --expand-tabs When the local convention of the project is to use tab width that is not 8, it may make sense to allow "git log --expand-tabs=" to tweak the output to match it. Signed-off-by: Junio C Hamano --- revision.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index da53b6ce35..47e9ee7a14 100644 --- a/revision.c +++ b/revision.c @@ -1415,7 +1415,7 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->expand_tabs_in_log = -1; revs->commit_format = CMIT_FMT_DEFAULT; - revs->expand_tabs_in_log_default = 1; + revs->expand_tabs_in_log_default = 8; init_grep_defaults(); grep_init(&revs->grep_filter, prefix); @@ -1918,9 +1918,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->pretty_given = 1; get_commit_format(arg+9, revs); } else if (!strcmp(arg, "--expand-tabs")) { - revs->expand_tabs_in_log = 1; + revs->expand_tabs_in_log = 8; } else if (!strcmp(arg, "--no-expand-tabs")) { revs->expand_tabs_in_log = 0; + } else if (skip_prefix(arg, "--expand-tabs=", &arg)) { + int val; + if (strtol_i(arg, 10, &val) < 0 || val < 0) + die("'%s': not a non-negative integer", arg); + revs->expand_tabs_in_log = val; } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { revs->show_notes = 1; revs->show_notes_given = 1; -- cgit v1.2.3