From af9fedc12873bf331019a502ed1fc944fa986713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Mar 2012 13:26:39 +0100 Subject: diff --stat: use the full terminal width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- builtin/diff.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin') diff --git a/builtin/diff.c b/builtin/diff.c index 387afa7568..81b6baec74 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); -- cgit v1.2.3 From 666c92a229de10f8bbfc33cf6f92aad8733f0002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Mar 2012 13:26:40 +0100 Subject: show --stat: use the full terminal width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make show --stat behave like diff --stat and use the full terminal width. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- builtin/log.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index 7d1f6f88a0..d37ae2606e 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -447,6 +447,8 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.diff = 1; rev.always_show_header = 1; rev.no_walk = 1; + rev.diffopt.stat_width = -1; /* Scale to real terminal size */ + memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; opt.tweak = show_rev_tweak_rev; -- cgit v1.2.3 From 5e0ec15eb131075d0c3e61b33bcc7931bbc8bc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Mar 2012 13:26:41 +0100 Subject: log --stat: use the full terminal width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make log --stat behave like diff --stat and use the full terminal width. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- builtin/log.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index d37ae2606e..075a427b71 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -77,6 +77,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) get_commit_format(fmt_pretty, rev); rev->verbose_header = 1; DIFF_OPT_SET(&rev->diffopt, RECURSIVE); + rev->diffopt.stat_width = -1; /* use full terminal width */ rev->abbrev_commit = default_abbrev_commit; rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; -- cgit v1.2.3 From 7a7159ace6c93ea6c55086dfc7ba7533a3e3c07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Mar 2012 13:26:42 +0100 Subject: merge --stat: use the full terminal width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make merge --stat behave like diff --stat and use the full terminal width. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- builtin/merge.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin') diff --git a/builtin/merge.c b/builtin/merge.c index b4fbc60e6d..b1cd90ccc3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -399,6 +399,7 @@ static void finish(struct commit *head_commit, if (new_head && show_diffstat) { struct diff_options opts; diff_setup(&opts); + opts.stat_width = -1; /* use full terminal width */ opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; -- cgit v1.2.3 From df44483a5dde62f4b49c80fd90d7fe12ddcfb084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Mar 2012 13:26:46 +0100 Subject: diff --stat: add config option to limit graph width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Config option diff.statGraphWidth= is equivalent to --stat-graph-width=, except that the config option is ignored by format-patch. For the graph-width limiting to be usable, it should happen 'automatically' once configured, hence the config option. Nevertheless, graph width limiting only makes sense when used on a wide terminal, so it should not influence the output of format-patch, which adheres to the 80-column standard. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- builtin/diff.c | 3 ++- builtin/log.c | 1 + builtin/merge.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/diff.c b/builtin/diff.c index 81b6baec74..424c815f9b 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -285,8 +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 */ + /* Scale to real terminal size and respect statGraphWidth config */ rev.diffopt.stat_width = -1; + rev.diffopt.stat_graph_width = -1; /* Default to let external and textconv be used */ DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL); diff --git a/builtin/log.c b/builtin/log.c index 075a427b71..8a47012b0b 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -78,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) rev->verbose_header = 1; DIFF_OPT_SET(&rev->diffopt, RECURSIVE); rev->diffopt.stat_width = -1; /* use full terminal width */ + rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */ rev->abbrev_commit = default_abbrev_commit; rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; diff --git a/builtin/merge.c b/builtin/merge.c index b1cd90ccc3..34a5034a76 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -400,6 +400,7 @@ static void finish(struct commit *head_commit, struct diff_options opts; diff_setup(&opts); opts.stat_width = -1; /* use full terminal width */ + opts.stat_graph_width = -1; /* respect statGraphWidth config */ opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; -- cgit v1.2.3