Skip to content

Commit 5109a07

Browse files
dschogitster
authored andcommitted
pager: do not unnecessarily set COLUMNS on Windows
Since gwsw/less@bb0ee4e76c2, `less` prefers the `COLUMNS` variable over asking ncurses itself. This is typically not a problem because we ask `TIOCGWINSZ` in Git, to determine the correct value for `COLUMNS`, and then set that environment variable. However, on Windows it _is_ a problem. The reason is that Git for Windows uses a version of `less` that relies on the MSYS2 runtime to interact with the pseudo terminal (typically inside a MinTTY window, which is also aware of the MSYS2 runtime). Both MinTTY and `less.exe` interact with that pseudo terminal via `ioctl()` calls (which the MSYS2 runtime emulates even if there is no such thing on Windows). But `git.exe` itself is _not_ aware of the MSYS2 runtime, or for that matter of that pseudo terminal, and has no way to call `ioctl()` or `TIOCGWINSZ`. Therefore, `git.exe` will fall back to hard-coding 80 columns, no matter what the actual terminal size is. But `less.exe` is totally able to interact with the MSYS2 runtime and would not actually require Git's help (which actually makes things worse here). So let's not override `COLUMNS` on Windows. Note: we do this _only_ on Windows, and _only_ if `TIOCGWINSZ` is not defined, to reduce any potential undesired fall-out from this patch. This fixes #3235 Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebf3c04 commit 5109a07

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pager.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ void setup_pager(void)
111111
* to get the terminal size. Let's grab it now, and then set $COLUMNS
112112
* to communicate it to any sub-processes.
113113
*/
114+
#if !defined(WIN32) || defined(TIOCGWINSZ)
114115
{
115116
char buf[64];
116117
xsnprintf(buf, sizeof(buf), "%d", term_columns());
117118
setenv("COLUMNS", buf, 0);
118119
}
120+
#endif
119121

120122
setenv("GIT_PAGER_IN_USE", "true", 1);
121123

0 commit comments

Comments
 (0)