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
This commit is contained in:
Junio C Hamano 2021-07-08 13:15:06 -07:00
commit 32d6280226

16
pager.c
View File

@ -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