diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-07-08 13:15:06 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-07-08 13:15:06 -0700 |
commit | 32d62802266328f0beb8aede853f6e25e8cbc00f (patch) | |
tree | fa98f0774d67be3b61e59d4a9e313b34a5489fac | |
parent | Merge branch 'dd/document-log-decorate-default' (diff) | |
parent | pager: avoid setting COLUMNS when we're guessing its value (diff) | |
download | tgif-32d62802266328f0beb8aede853f6e25e8cbc00f.tar.xz |
Merge branch 'js/stop-exporting-bogus-columns'
When we cannot figure out how wide the terminal is, we use a
fallback value of 80 ourselves (which cannot be avoided), but when
we run the pager, we export it in COLUMNS, which forces the pager
to use the hardcoded value, even when the pager is perfectly
capable to figure it out itself. Stop exporting COLUMNS when we
fall back on the hardcoded default value for our own use.
* js/stop-exporting-bogus-columns:
pager: avoid setting COLUMNS when we're guessing its value
-rw-r--r-- | pager.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -11,6 +11,10 @@ static struct child_process pager_process = CHILD_PROCESS_INIT; static const char *pager_program; +/* Is the value coming back from term_columns() just a guess? */ +static int term_columns_guessed; + + static void close_pager_fds(void) { /* signal EOF to pager */ @@ -114,7 +118,8 @@ void setup_pager(void) { char buf[64]; xsnprintf(buf, sizeof(buf), "%d", term_columns()); - setenv("COLUMNS", buf, 0); + if (!term_columns_guessed) + setenv("COLUMNS", buf, 0); } setenv("GIT_PAGER_IN_USE", "true", 1); @@ -158,15 +163,20 @@ int term_columns(void) return term_columns_at_startup; term_columns_at_startup = 80; + term_columns_guessed = 1; col_string = getenv("COLUMNS"); - if (col_string && (n_cols = atoi(col_string)) > 0) + if (col_string && (n_cols = atoi(col_string)) > 0) { term_columns_at_startup = n_cols; + term_columns_guessed = 0; + } #ifdef TIOCGWINSZ else { struct winsize ws; - if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) + if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) { term_columns_at_startup = ws.ws_col; + term_columns_guessed = 0; + } } #endif |