git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
To: git@vger.kernel.org, gitster@pobox.com
Cc: pclouds@gmail.com, j.sixt@viscovery.net,
	"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
Subject: [PATCH v7a 2/9] diff --stat: use the full terminal width
Date: Thu,  1 Mar 2012 13:26:39 +0100	[thread overview]
Message-ID: <1330604806-30288-2-git-send-email-zbyszek@in.waw.pl> (raw)
In-Reply-To: <1330604806-30288-1-git-send-email-zbyszek@in.waw.pl>

Default to the real terminal width for diff --stat output, instead
of the hard-coded 80 columns.

Some projects (especially in Java), have long filename paths, with
nested directories or long individual filenames. When files are
renamed, the filename part in stat output can be almost useless. If
the middle part between { and } is long (because the file was moved to
a completely different directory), then most of the path would be
truncated.

It makes sense to detect and use the full terminal width and display
full filenames if possible.

The are commands like diff, show, and log, which can adapt the output
to the terminal width. There are also commands like format-patch,
whose output should be independent of the terminal width. Since it is
safer to use the 80-column default, the real terminal width is only
used if requested by the calling code by setting diffopts.stat_width=-1.
Normally this value is 0, and can be set by the user only to a
non-negative value, so -1 is safe to use internally.

This patch only changes the diff builtin to use the full terminal width.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/diff.c         |    3 +++
 diff.c                 |    5 ++++-
 t/t4052-stat-output.sh |   11 +++++++++--
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/builtin/diff.c b/builtin/diff.c
index 387afa7..81b6bae 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -285,6 +285,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	/* Otherwise, we are doing the usual "git" diff */
 	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
 
+	/* Scale to real terminal size */
+	rev.diffopt.stat_width = -1;
+
 	/* Default to let external and textconv be used */
 	DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
 	DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
diff --git a/diff.c b/diff.c
index e0590a3..7478277 100644
--- a/diff.c
+++ b/diff.c
@@ -1343,7 +1343,10 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 		line_prefix = msg->buf;
 	}
 
-	width = options->stat_width ? options->stat_width : 80;
+	if (options->stat_width == -1)
+		width = term_columns();
+	else
+		width = options->stat_width ? options->stat_width : 80;
 	name_width = options->stat_name_width ? options->stat_name_width : 50;
 	count = options->stat_count ? options->stat_count : data->nr;
 
diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
index f766c47..29c06e5 100755
--- a/t/t4052-stat-output.sh
+++ b/t/t4052-stat-output.sh
@@ -83,6 +83,10 @@ cat >expect80 <<'EOF'
  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 EOF
 
+cat >expect200 <<'EOF'
+ abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+EOF
+
 while read verb expect cmd args
 do
 	test_expect_success "$cmd $verb COLUMNS (big change)" '
@@ -92,7 +96,7 @@ do
 	'
 done <<\EOF
 ignores expect80 format-patch -1 --stdout
-ignores expect80 diff HEAD^ HEAD --stat
+respects expect200 diff HEAD^ HEAD --stat
 ignores expect80 show --stat
 ignores expect80 log -1 --stat
 EOF
@@ -146,6 +150,9 @@ EOF
 cat >expect80 <<'EOF'
  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 EOF
+cat >expect200 <<'EOF'
+ ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+EOF
 while read verb expect cmd args
 do
 	test_expect_success "$cmd $verb COLUMNS (long filename)" '
@@ -155,7 +162,7 @@ do
 	'
 done <<\EOF
 ignores expect80 format-patch -1 --stdout
-ignores expect80 diff HEAD^ HEAD --stat
+respects expect200 diff HEAD^ HEAD --stat
 ignores expect80 show --stat
 ignores expect80 log -1 --stat
 EOF
-- 
1.7.9.2.399.gdf4d.dirty

  reply	other threads:[~2012-03-01 12:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28  6:53 Incremental updates to What's cooking Junio C Hamano
2012-02-29  7:37 ` Zbigniew Jędrzejewski-Szmek
2012-02-29  8:39   ` Junio C Hamano
2012-02-29 13:50     ` Zbigniew Jędrzejewski-Szmek
2012-02-29 19:28       ` Junio C Hamano
2012-02-29 20:19         ` Zbigniew Jędrzejewski-Szmek
2012-02-29 20:48           ` Junio C Hamano
2012-03-01 12:26             ` [PATCH v7a 1/9] diff --stat: tests for long filenames and big change counts Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` Zbigniew Jędrzejewski-Szmek [this message]
2012-03-01 12:26               ` [PATCH v7a 3/9] show --stat: use the full terminal width Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` [PATCH v7a 4/9] log " Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` [PATCH v7a 5/9] merge " Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` [PATCH v7a 6/9] diff --stat: use a maximum of 5/8 for the filename part Zbigniew Jędrzejewski-Szmek
2012-03-01 17:18                 ` Junio C Hamano
2012-03-26 23:45                 ` Jeff King
2012-03-27  5:10                   ` [PATCH] t4052: unset $COLUMNS inherited from environment Zbigniew Jędrzejewski-Szmek
2012-03-27  5:17                     ` Jeff King
2012-03-27  6:22                       ` [PATCH v2] tests: unset COLUMNS " Zbigniew Jędrzejewski-Szmek
2012-03-27 18:44                         ` Jeff King
2012-03-27  5:32                     ` [PATCH] t4052: unset $COLUMNS " Johannes Sixt
2012-03-01 12:26               ` [PATCH v7a 7/9] diff --stat: add a test for output with COLUMNS=40 Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` [PATCH v7a 8/9] diff --stat: enable limiting of the graph part Zbigniew Jędrzejewski-Szmek
2012-03-01 12:26               ` [PATCH v7a 9/9] diff --stat: add config option to limit graph width Zbigniew Jędrzejewski-Szmek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1330604806-30288-2-git-send-email-zbyszek@in.waw.pl \
    --to=zbyszek@in.waw.pl \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).