Skip to content

Commit 43a42aa

Browse files
committed
Merge branch 'ew/build-time-pager-tweaks'
The build procedure learned PAGER_ENV knob that lists what default environment variable settings to export for popular pagers. This mechanism is used to tweak the default settings to MORE on FreeBSD. * ew/build-time-pager-tweaks: pager: move pager-specific setup into the build
2 parents dc7e09a + 995bc22 commit 43a42aa

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ all::
370370
# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
371371
#
372372
# Define HAVE_GETDELIM if your system has the getdelim() function.
373+
#
374+
# Define PAGER_ENV to a SP separated VAR=VAL pairs to define
375+
# default environment variables to be passed when a pager is spawned, e.g.
376+
#
377+
# PAGER_ENV = LESS=FRX LV=-c
378+
#
379+
# to say "export LESS=FRX (and LV=-c) if the environment variable
380+
# LESS (and LV) is not set, respectively".
373381

374382
GIT-VERSION-FILE: FORCE
375383
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1501,6 +1509,10 @@ ifeq ($(PYTHON_PATH),)
15011509
NO_PYTHON = NoThanks
15021510
endif
15031511

1512+
ifndef PAGER_ENV
1513+
PAGER_ENV = LESS=FRX LV=-c
1514+
endif
1515+
15041516
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
15051517
QUIET_SUBDIR1 =
15061518

@@ -1630,6 +1642,11 @@ ifdef DEFAULT_HELP_FORMAT
16301642
BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
16311643
endif
16321644

1645+
PAGER_ENV_SQ = $(subst ','\'',$(PAGER_ENV))
1646+
PAGER_ENV_CQ = "$(subst ",\",$(subst \,\\,$(PAGER_ENV)))"
1647+
PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
1648+
BASIC_CFLAGS += -DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
1649+
16331650
ALL_CFLAGS += $(BASIC_CFLAGS)
16341651
ALL_LDFLAGS += $(BASIC_LDFLAGS)
16351652

@@ -1754,7 +1771,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
17541771

17551772
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
17561773
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
1757-
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP)
1774+
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV)
17581775
define cmd_munge_script
17591776
$(RM) $@ $@+ && \
17601777
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@@ -1767,6 +1784,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
17671784
-e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
17681785
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
17691786
-e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
1787+
-e 's|@@PAGER_ENV@@|$(PAGER_ENV_SQ)|g' \
17701788
$@.sh >$@+
17711789
endef
17721790

@@ -2174,6 +2192,7 @@ GIT-BUILD-OPTIONS: FORCE
21742192
@echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+
21752193
@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+
21762194
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
2195+
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
21772196
ifdef TEST_OUTPUT_DIRECTORY
21782197
@echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
21792198
endif

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ ifeq ($(uname_S),FreeBSD)
209209
HAVE_PATHS_H = YesPlease
210210
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
211211
HAVE_BSD_SYSCTL = YesPlease
212+
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
212213
endif
213214
ifeq ($(uname_S),OpenBSD)
214215
NO_STRCASESTR = YesPlease

git-sh-setup.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ git_pager() {
163163
else
164164
GIT_PAGER=cat
165165
fi
166-
: "${LESS=-FRX}"
167-
: "${LV=-c}"
168-
export LESS LV
166+
for vardef in @@PAGER_ENV@@
167+
do
168+
var=${vardef%%=*}
169+
eval ": \"\${$vardef}\" && export $var"
170+
done
169171
170172
eval "$GIT_PAGER" '"$@"'
171173
}

pager.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,38 @@ const char *git_pager(int stdout_is_tty)
6363
return pager;
6464
}
6565

66+
static void setup_pager_env(struct argv_array *env)
67+
{
68+
const char **argv;
69+
int i;
70+
char *pager_env = xstrdup(PAGER_ENV);
71+
int n = split_cmdline(pager_env, &argv);
72+
73+
if (n < 0)
74+
die("malformed build-time PAGER_ENV: %s",
75+
split_cmdline_strerror(n));
76+
77+
for (i = 0; i < n; i++) {
78+
char *cp = strchr(argv[i], '=');
79+
80+
if (!cp)
81+
die("malformed build-time PAGER_ENV");
82+
83+
*cp = '\0';
84+
if (!getenv(argv[i])) {
85+
*cp = '=';
86+
argv_array_push(env, argv[i]);
87+
}
88+
}
89+
free(pager_env);
90+
free(argv);
91+
}
92+
6693
void prepare_pager_args(struct child_process *pager_process, const char *pager)
6794
{
6895
argv_array_push(&pager_process->args, pager);
6996
pager_process->use_shell = 1;
70-
if (!getenv("LESS"))
71-
argv_array_push(&pager_process->env_array, "LESS=FRX");
72-
if (!getenv("LV"))
73-
argv_array_push(&pager_process->env_array, "LV=-c");
97+
setup_pager_env(&pager_process->env_array);
7498
}
7599

76100
void setup_pager(void)

t/t7006-pager.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ test_expect_success TTY 'LESS and LV envvars are set for pagination' '
4949
grep ^LV= pager-env.out
5050
'
5151

52+
test_expect_success !MINGW,TTY 'LESS and LV envvars set by git-sh-setup' '
53+
(
54+
sane_unset LESS LV &&
55+
PAGER="env >pager-env.out; wc" &&
56+
export PAGER &&
57+
PATH="$(git --exec-path):$PATH" &&
58+
export PATH &&
59+
test_terminal sh -c ". git-sh-setup && git_pager"
60+
) &&
61+
grep ^LESS= pager-env.out &&
62+
grep ^LV= pager-env.out
63+
'
64+
5265
test_expect_success TTY 'some commands do not use a pager' '
5366
rm -f paginated.out &&
5467
test_terminal git rev-list HEAD &&

0 commit comments

Comments
 (0)