git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] tag: fix column output not using all terminal space

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 11, 2018, 07:56 UTC
Message-ID
<20180511075602.9182-1-pclouds@gmail.com>

git-tag runs a separate git-column command via run_column_filter(). This makes the new 'git-column' process fail to pick up the terminal width for some reason and fall back to default width. Just explicitly pass terminal width and avoid this terminal width detection business in subprocesses.

While at there, fix an off-by-one column setting in git-column. We do not want to use up _all_ terminal columns because the last character is going hit the border and wrap. Keep it at term_columns() - 1 like print_columns() does. This affects the test in t7004 because effective column width before was 40 but now 39 so we need to adjust it back.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/column.c | 2 +-
 column.c         | 2 ++
 t/t7004-tag.sh   | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin/column.c b/builtin/column.c
index 0c3223d64b..182c84f778 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -42,7 +42,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
 		git_config(column_config, NULL);
 
 	memset(&copts, 0, sizeof(copts));
-	copts.width = term_columns();
+	copts.width = term_columns() - 1;
 	copts.padding = 1;
 	argc = parse_options(argc, argv, "", options, builtin_column_usage, 0);
 	if (argc)
diff --git a/column.c b/column.c
index 49ab85b769..382537b324 100644
--- a/column.c
+++ b/column.c
@@ -381,6 +381,8 @@ int run_column_filter(int colopts, const struct column_options *opts)
 	argv_array_pushf(argv, "--raw-mode=%d", colopts);
 	if (opts && opts->width)
 		argv_array_pushf(argv, "--width=%d", opts->width);
+	else
+		argv_array_pushf(argv, "--width=%d", term_columns() - 1);
 	if (opts && opts->indent)
 		argv_array_pushf(argv, "--indent=%s", opts->indent);
 	if (opts && opts->padding)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index e3f1e014aa..d7b319e919 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -363,7 +363,7 @@ test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documenta
 '
 
 test_expect_success 'listing tags in column' '
-	COLUMNS=40 git tag -l --column=row >actual &&
+	COLUMNS=41 git tag -l --column=row >actual &&
 	cat >expected <<\EOF &&
 a1      aa1     cba     t210    t211
 v0.2.1  v1.0    v1.0.1  v1.1.3
-- 
2.17.0.705.g3525833791
Next: Jeff King
Message 1 of 6 in “tag: fix column output not using all terminal space”
  1. tag: fix column output not using all terminal spaceNguyễn Thái Ngọc Duy, May 11, 2018
  2. Jeff KingMay 11, 2018
  3. Duy NguyenMay 11, 2018
  4. pager: set COLUMNS to term_columns()Jeff King, May 11, 2018
  5. column: fix off-by-one default widthNguyễn Thái Ngọc Duy, May 11, 2018
  6. Duy NguyenMay 11, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.