From: Eric Wong <hidden> Date: 2016-08-01 01:06:12
This series allows us to more easily configure platform-specific
defaults at build-time and also allow users to override them
at runtime via config.
Previous discussion in this thread:
https://public-inbox.org/git/52D87A79.6060600@rawbw.com/T/
The following changes since commit f8f7adce9fc50a11a764d57815602dcb818d1816:
Sync with maint (2016-07-28 14:21:18 -0700)
are available in the git repository at:
git://bogomips.org/git-svn.git pager-env
for you to fetch changes up to 1563ef177f9c1ee990bb3547f16bd7568a17379a:
pager: implement core.pagerEnv in config (2016-08-01 00:51:42 +0000)
----------------------------------------------------------------
Eric Wong (1):
pager: implement core.pagerEnv in config
Junio C Hamano (1):
pager: move pager-specific setup into the build
Documentation/config.txt | 7 +++++++
Makefile | 19 +++++++++++++++++--
config.mak.uname | 1 +
git-sh-setup.sh | 8 +++++---
pager.c | 35 +++++++++++++++++++++++++++++++----
t/t7006-pager.sh | 14 ++++++++++++++
6 files changed, 75 insertions(+), 9 deletions(-)
From: Eric Wong <hidden> Date: 2016-08-01 01:06:16
From: Junio C Hamano <redacted>
Allowing PAGER_ENV to be set at build-time allows us to move
pager-specific knowledge out of our build. Currently, this
allows us to set a better default for FreeBSD where more(1)
is the same binary as less(1).
This also prepares us for introducing a run-time config knob to
override the build-time environment in the next commit.
Originally-from:
https://public-inbox.org/git/xmqq61piw4yf.fsf@gitster.dls.corp.google.com/
Signed-off-by: Eric Wong <redacted>
---
Makefile | 19 +++++++++++++++++--
config.mak.uname | 1 +
git-sh-setup.sh | 8 +++++---
pager.c | 32 ++++++++++++++++++++++++++++----
4 files changed, 51 insertions(+), 9 deletions(-)
@@ -370,6 +370,14 @@ all::# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.## Define HAVE_GETDELIM if your system has the getdelim() function.+#+# Define PAGER_ENV to a SP separated VAR=VAL pairs to define+# default environment variables to be passed when a pager is spawned, e.g.+#+# PAGER_ENV = LESS=FRX LV=-c+#+# to say "export LESS=FRX (and LV=-c) if the environment variable+# LESS (and LV) is not set, respectively".GIT-VERSION-FILE:FORCE@$(SHELL_PATH)./GIT-VERSION-GEN
@@ -1500,6 +1508,10 @@ ifeq ($(PYTHON_PATH),)NO_PYTHON=NoThanksendif+ifndef PAGER_ENV+PAGER_ENV=LESS=FRXLV=-c+endif+QUIET_SUBDIR0=+$(MAKE)-C# space to separate -C and subdirQUIET_SUBDIR1=
@@ -1579,6 +1591,7 @@ PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))TCLTK_PATH_SQ=$(subst','\'',$(TCLTK_PATH))DIFF_SQ=$(subst','\'',$(DIFF))PERLLIB_EXTRA_SQ=$(subst','\'',$(PERLLIB_EXTRA))+PAGER_ENV_SQ=$(subst','\'',$(PAGER_ENV))# We must filter out any object files from $(GITLIBS),# as it is typically used like:
@@ -1591,7 +1604,7 @@ PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))LIBS=$(filter-out%.o,$(GITLIBS))$(EXTLIBS)BASIC_CFLAGS+=-DSHA1_HEADER='$(SHA1_HEADER_SQ)'\-$(COMPAT_CFLAGS)+$(COMPAT_CFLAGS)-DPAGER_ENV='$(PAGER_ENV_SQ)'LIB_OBJS+=$(COMPAT_OBJS)# Quote for C
From: Eric Wong <hidden> Date: 2016-08-01 01:06:21
This allows overriding the build-time PAGER_ENV variable
at run-time.
Inspired by part 1 of an idea from Kyle J. McKay at:
https://public-inbox.org/git/62DB6DEF-8B39-4481-BA06-245BF45233E5@gmail.com/
Signed-off-by: Eric Wong <redacted>
---
Documentation/config.txt | 7 +++++++
pager.c | 5 ++++-
t/t7006-pager.sh | 14 ++++++++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
@@ -714,6 +714,13 @@ Likewise, when the `LV` environment variable is unset, Git sets it to `-c`. You can override this setting by exporting `LV` with another value or setting `core.pager` to `lv +c`.+core.pagerEnv::+ Environment for running `core.pager`.+++Defaults to the value set at build, usually `LESS=FRX LV=-c`.+On platforms where `more` and `less` are the same binary,+`LESS=FRX LV=-c MORE=FRX` is appropriate.+ core.whitespace:: A comma separated list of common whitespace problems to notice. 'git diff' will use `color.diff.whitespace` to
So it looks like this function splits on spaces but doesn't provide any
escaping mechanism. Is there any case in which we want to accept
environment variables containing whitespace? I ask this as someone that
has EDITOR set to "gvim -f" on occasion and seeing how tools sometimes
handle that poorly.
Even without that, I think this series is probably an improvement over
the status quo.
--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
From: Eric Wong <hidden> Date: 2016-08-01 07:01:11
"brian m. carlson" [off-list ref] wrote:
On Mon, Aug 01, 2016 at 01:05:56AM +0000, Eric Wong wrote:
quoted
+ while (*cp && *cp == ' ')
+ cp++;
So it looks like this function splits on spaces but doesn't provide any
escaping mechanism. Is there any case in which we want to accept
environment variables containing whitespace? I ask this as someone that
has EDITOR set to "gvim -f" on occasion and seeing how tools sometimes
handle that poorly.
Yes, it's only split on spaces right now. While I don't think
there's any current case where spaces would be useful/desirable;
I suppose a 3rd patch in this series could add support for using
split_cmdline (from alias.c)...
From: Jakub Narębski <hidden> Date: 2016-08-01 08:58:23
W dniu 01.08.2016 o 09:00, Eric Wong pisze:
"brian m. carlson" [off-list ref] wrote:
quoted
On Mon, Aug 01, 2016 at 01:05:56AM +0000, Eric Wong wrote:
quoted
+ while (*cp && *cp == ' ')
+ cp++;
So it looks like this function splits on spaces but doesn't provide any
escaping mechanism. Is there any case in which we want to accept
environment variables containing whitespace? I ask this as someone that
has EDITOR set to "gvim -f" on occasion and seeing how tools sometimes
handle that poorly.
This is to handle environment variables holding program options,
which are usually (but possibly not often) using single character
options bundled together, that is, not using spaces.
Moreover, it is about holding program options to pager.
Yes, it's only split on spaces right now. While I don't think
there's any current case where spaces would be useful/desirable;
I suppose a 3rd patch in this series could add support for using
split_cmdline (from alias.c)...
Is there any pager that needs spaces in options-set environment
variable? Does MORE allow option bundling?
--
Jakub Narębski
From: brian m. carlson <hidden> Date: 2016-08-01 10:41:48
On Mon, Aug 01, 2016 at 10:57:02AM +0200, Jakub Narębski wrote:
W dniu 01.08.2016 o 09:00, Eric Wong pisze:
quoted
"brian m. carlson" [off-list ref] wrote:
quoted
So it looks like this function splits on spaces but doesn't provide any
escaping mechanism. Is there any case in which we want to accept
environment variables containing whitespace? I ask this as someone that
has EDITOR set to "gvim -f" on occasion and seeing how tools sometimes
handle that poorly.
This is to handle environment variables holding program options,
which are usually (but possibly not often) using single character
options bundled together, that is, not using spaces.
Moreover, it is about holding program options to pager.
I understand that. My point is that we should consider corner cases
like how we're going to handle spaces.
quoted
Yes, it's only split on spaces right now. While I don't think
there's any current case where spaces would be useful/desirable;
I suppose a 3rd patch in this series could add support for using
split_cmdline (from alias.c)...
Is there any pager that needs spaces in options-set environment
variable? Does MORE allow option bundling?
We seem to accept GIT_PAGER="par | less" and par definitely accepts
spaces in its environment variables. That seems to be a corner case,
though, and I haven't seen par practically used in years.
We may also want to consider EXINIT for people who pipe to vi. Again,
I'm not sure this is very common; most people would use an .exrc or
.vimrc.
I'd say if we can't come up with any better examples, I'd skip handling
it for now. I'll try to come up with a patch to add it later.
--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
So it looks like this function splits on spaces but doesn't provide any
escaping mechanism. Is there any case in which we want to accept
environment variables containing whitespace? I ask this as someone that
has EDITOR set to "gvim -f" on occasion and seeing how tools sometimes
handle that poorly.
Even without that, I think this series is probably an improvement over
the status quo.
I'm not too worried about spaces here. This is a resurrection of an old
discussion, and in all that time, I think the only realistic suggestions
for built-in values have been pretty tame.
If this were used to parse arbitrary user-provided runtime values, I'd
be more concerned. But I'm not sure why we would need that. Your $EDITOR
example is arbitrary shell code, and we let the shell handle it (modulo
some efficiency shortcuts). Likewise, fancy runtime things should go in
GIT_PAGER, where you can not only set options with spaces, but do fancy
things like pipes, shell functions, etc.
The use of stringify() here is funny to me; I think there is a cpp
tokenizing step in the middle that will do things like gobble up
whitespace (but I'm not sure if it has other possible effects). I think
our more usual method here would be to C-quote in the Makefile (with the
equivalent of 's/\\/\\\\/g; s/"/\\"/g'), and then pass it to the
compiler as a string literal, like -DPAGER_ENV=\"$(PAGER_ENV_CQ_SQ\".
-Peff
On Mon, Aug 1, 2016 at 3:05 AM, Eric Wong [off-list ref] wrote:
From: Junio C Hamano <redacted>
Allowing PAGER_ENV to be set at build-time allows us to move
pager-specific knowledge out of our build. Currently, this
allows us to set a better default for FreeBSD where more(1)
is the same binary as less(1).
Nice. I was just too lazy to do something like this and "export
PAGER=less LESS=FRX" then ignored it :-P
Slightly off topic, but pagers like 'more' does not understand colors
either. But color.ui = auto does not know what and prints color code
anyway. It would be nice if we had some configuration to describe
"this pager can show colors, that pager does not" so I don't have to
maintain separate .gitconfig files on two platforms.
--
Duy
This commit message is missing the "why" (I tried to get it from the
referenced email, but I am still confused).
What does this buy you over:
GIT_PAGER='less -whatever-options-you-like'
? Sure, you have to say "less" there and not just "if we happen to be
using less, use these options with it". But that distinction is
important for a build-time default, not for a run-time one. And by
pointing people to GIT_PAGER, they can do a lot _more_ than they can
with PAGER_ENV, including the full power of the shell (brian gave an
example of "par | less" earlier; I use "diff-highlight | less").
-Peff
From: Jeff King <hidden> Date: 2016-08-01 17:59:07
On Mon, Aug 01, 2016 at 07:46:34PM +0200, Duy Nguyen wrote:
On Mon, Aug 1, 2016 at 3:05 AM, Eric Wong [off-list ref] wrote:
quoted
From: Junio C Hamano <redacted>
Allowing PAGER_ENV to be set at build-time allows us to move
pager-specific knowledge out of our build. Currently, this
allows us to set a better default for FreeBSD where more(1)
is the same binary as less(1).
Nice. I was just too lazy to do something like this and "export
PAGER=less LESS=FRX" then ignored it :-P
Slightly off topic, but pagers like 'more' does not understand colors
either. But color.ui = auto does not know what and prints color code
anyway. It would be nice if we had some configuration to describe
"this pager can show colors, that pager does not" so I don't have to
maintain separate .gitconfig files on two platforms.
If you are interested, I suggest you read the thread linked earlier:
https://public-inbox.org/git/52D87A79.6060600%40rawbw.com/T/#u
which discusses this and other issues. But basically, I think you cannot
really solve this without getting intimate with each pager (which people
seemed not to want to do).
-Peff
From: Jeff King <hidden> Date: 2016-08-01 18:07:15
On Mon, Aug 01, 2016 at 08:01:13PM +0200, Duy Nguyen wrote:
quoted
If you are interested, I suggest you read the thread linked earlier:
https://public-inbox.org/git/52D87A79.6060600%40rawbw.com/T/#u
which discusses this and other issues. But basically, I think you cannot
really solve this without getting intimate with each pager (which people
seemed not to want to do).
Cooking pager specifics in git does sound bad. But it does not have to
be that way. What if we delegate the decision whether to color or not
to a script (e.g. by setting color.ui= "script <path to the script>")?
The script has all the info (env variables, uname, user preference...)
and can make a better decision than 'is stdout a tty?'. It's not about
out of the box experience, more towards customization (without
fragmenting .gitconfig files too much).
It sounds like we are solving two separate problems.
I was mostly concerned with the out-of-the-box experience. E.g., you
build git and run "git log" and it prints out gibberish, either because
of your $PAGER or your $LESS settings (which you might have set years
ago).
For more advanced usage like yours, I'd shove any personal logic into a
wrapper around your pager script. I think the particular decision you
want, though, is related to color.pager, which is outside that scope.
I'm not sure exactly what your setup looks like, but I wonder if it
would be served by better config support (i.e., why do you need a script
to dynamically look at your pager and see if color.pager should be
turned on; can't you configure both at the same time?).
-Peff
On Mon, Aug 1, 2016 at 7:52 PM, Jeff King [off-list ref] wrote:
On Mon, Aug 01, 2016 at 07:46:34PM +0200, Duy Nguyen wrote:
quoted
On Mon, Aug 1, 2016 at 3:05 AM, Eric Wong [off-list ref] wrote:
quoted
From: Junio C Hamano <redacted>
Allowing PAGER_ENV to be set at build-time allows us to move
pager-specific knowledge out of our build. Currently, this
allows us to set a better default for FreeBSD where more(1)
is the same binary as less(1).
Nice. I was just too lazy to do something like this and "export
PAGER=less LESS=FRX" then ignored it :-P
Slightly off topic, but pagers like 'more' does not understand colors
either. But color.ui = auto does not know what and prints color code
anyway. It would be nice if we had some configuration to describe
"this pager can show colors, that pager does not" so I don't have to
maintain separate .gitconfig files on two platforms.
If you are interested, I suggest you read the thread linked earlier:
https://public-inbox.org/git/52D87A79.6060600%40rawbw.com/T/#u
which discusses this and other issues. But basically, I think you cannot
really solve this without getting intimate with each pager (which people
seemed not to want to do).
Cooking pager specifics in git does sound bad. But it does not have to
be that way. What if we delegate the decision whether to color or not
to a script (e.g. by setting color.ui= "script <path to the script>")?
The script has all the info (env variables, uname, user preference...)
and can make a better decision than 'is stdout a tty?'. It's not about
out of the box experience, more towards customization (without
fragmenting .gitconfig files too much).
--
Duy
From: Eric Wong <hidden> Date: 2016-08-01 22:00:35
Changes from v1:
* dropped stringify macro in favor for quoting in Makefile
(diff below)
I'm not sure I like this change, and might be inclined to
go in the opposite direction of using the stringify macro
more widely to simplify the Makefile; but that is a separate
topic.
* dropped 2/2, I don't have a good rationale for it, either,
other than "it seemed easy" after 1/2 :>
The following changes since commit f8f7adce9fc50a11a764d57815602dcb818d1816:
Sync with maint (2016-07-28 14:21:18 -0700)
are available in the git repository at:
git://bogomips.org/git-svn.git pager-env-v2
for you to fetch changes up to d3aed319c9abac006060bc81e865c93ff8363066:
pager: move pager-specific setup into the build (2016-08-01 21:46:25 +0000)
----------------------------------------------------------------
Junio C Hamano (1):
pager: move pager-specific setup into the build
Makefile | 20 +++++++++++++++++++-
config.mak.uname | 1 +
git-sh-setup.sh | 8 +++++---
pager.c | 29 +++++++++++++++++++++++++----
4 files changed, 50 insertions(+), 8 deletions(-)
interdiff from 1/1 v1:
@@ -1591,7 +1591,6 @@ PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))TCLTK_PATH_SQ=$(subst','\'',$(TCLTK_PATH))DIFF_SQ=$(subst','\'',$(DIFF))PERLLIB_EXTRA_SQ=$(subst','\'',$(PERLLIB_EXTRA))-PAGER_ENV_SQ=$(subst','\'',$(PAGER_ENV))# We must filter out any object files from $(GITLIBS),# as it is typically used like:
@@ -1604,7 +1603,7 @@ PAGER_ENV_SQ = $(subst ','\'',$(PAGER_ENV))LIBS=$(filter-out%.o,$(GITLIBS))$(EXTLIBS)BASIC_CFLAGS+=-DSHA1_HEADER='$(SHA1_HEADER_SQ)'\-$(COMPAT_CFLAGS)-DPAGER_ENV='$(PAGER_ENV_SQ)'+$(COMPAT_CFLAGS)LIB_OBJS+=$(COMPAT_OBJS)# Quote for C
From: Eric Wong <hidden> Date: 2016-08-01 22:01:02
From: Junio C Hamano <redacted>
Allowing PAGER_ENV to be set at build-time allows us to move
pager-specific knowledge out of our build. Currently, this
allows us to set a better default for FreeBSD where more(1)
is the same binary as less(1).
This also prepares us for introducing a run-time config knob to
override the build-time environment in the next commit.
Originally-from:
https://public-inbox.org/git/xmqq61piw4yf.fsf@gitster.dls.corp.google.com/
Signed-off-by: Eric Wong <redacted>
---
Makefile | 20 +++++++++++++++++++-
config.mak.uname | 1 +
git-sh-setup.sh | 8 +++++---
pager.c | 29 +++++++++++++++++++++++++----
4 files changed, 50 insertions(+), 8 deletions(-)
@@ -370,6 +370,14 @@ all::# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.## Define HAVE_GETDELIM if your system has the getdelim() function.+#+# Define PAGER_ENV to a SP separated VAR=VAL pairs to define+# default environment variables to be passed when a pager is spawned, e.g.+#+# PAGER_ENV = LESS=FRX LV=-c+#+# to say "export LESS=FRX (and LV=-c) if the environment variable+# LESS (and LV) is not set, respectively".GIT-VERSION-FILE:FORCE@$(SHELL_PATH)./GIT-VERSION-GEN
@@ -1500,6 +1508,10 @@ ifeq ($(PYTHON_PATH),)NO_PYTHON=NoThanksendif+ifndef PAGER_ENV+PAGER_ENV=LESS=FRXLV=-c+endif+QUIET_SUBDIR0=+$(MAKE)-C# space to separate -C and subdirQUIET_SUBDIR1=
From: Jeff King <hidden> Date: 2016-08-01 22:05:52
On Mon, Aug 01, 2016 at 09:49:36PM +0000, Eric Wong wrote:
Changes from v1:
* dropped stringify macro in favor for quoting in Makefile
(diff below)
I'm not sure I like this change, and might be inclined to
go in the opposite direction of using the stringify macro
more widely to simplify the Makefile; but that is a separate
topic.
I think that's a dangerous direction. Try this:
-- >8 --
cat >foo.c <<\EOF
#include <stdio.h>
#define stringify_(x) #x
#define stringify(x) stringify_(x)
int main(void)
{
printf("%s", stringify(FOO));
return 0;
}
EOF
while read -r input; do
gcc -Wall -Werror -DFOO="$input" foo.c
./a.out
done
-- 8< --
and then try input like:
this has a lot of spaces
this has a \backslash
You should see:
this has a lot of spaces
this has aackslash
I'll grant that backslashes and runs of whitespace are not things we'd
expect to find in most of our build-time config, but it still seems like
a bad direction to go (and actually, I wouldn't be surprised if
backslashes do end up in some of our build-time variables on Windows).
-Peff
argv_array handles its own allocation, so this leaks the detached
strbuf.
You'd want:
argv_array_push(env, buf.buf);
strbuf_release(&buf);
or just:
argv_array_pushf(env, "%.*s", (int)(cp - pager_env), pager_env);
Also:
+ strbuf_reset(&buf);
should this be strbuf_release()? If we didn't follow the conditional
above (because getenv() told us the variable was already set), then we
would not do do the detach/release there, and would finish the loop with
memory still allocated by "buf".
-Peff