Teach git var about GIT_PAGER
Expose the command found by setup_pager() for scripts to use. Scripts can use this to avoid repeating the logic to look for a proper pager in each command. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
44fcb4977c
commit
6361824589
@ -44,6 +44,12 @@ GIT_EDITOR::
|
|||||||
environment variable, then `core.editor` configuration, then
|
environment variable, then `core.editor` configuration, then
|
||||||
`$VISUAL`, then `$EDITOR`, and then finally 'vi'.
|
`$VISUAL`, then `$EDITOR`, and then finally 'vi'.
|
||||||
|
|
||||||
|
GIT_PAGER::
|
||||||
|
Text viewer for use by git commands (e.g., 'less'). The value
|
||||||
|
is meant to be interpreted by the shell. The order of preference
|
||||||
|
is the `$GIT_PAGER` environment variable, then `core.pager`
|
||||||
|
configuration, then `$PAGER`, and then finally 'less'.
|
||||||
|
|
||||||
Diagnostics
|
Diagnostics
|
||||||
-----------
|
-----------
|
||||||
You don't exist. Go away!::
|
You don't exist. Go away!::
|
||||||
|
1
cache.h
1
cache.h
@ -751,6 +751,7 @@ extern const char *git_committer_info(int);
|
|||||||
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
|
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
|
||||||
extern const char *fmt_name(const char *name, const char *email);
|
extern const char *fmt_name(const char *name, const char *email);
|
||||||
extern const char *git_editor(void);
|
extern const char *git_editor(void);
|
||||||
|
extern const char *git_pager(void);
|
||||||
|
|
||||||
struct checkout {
|
struct checkout {
|
||||||
const char *base_dir;
|
const char *base_dir;
|
||||||
|
18
pager.c
18
pager.c
@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)
|
|||||||
raise(signo);
|
raise(signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_pager(void)
|
const char *git_pager(void)
|
||||||
{
|
{
|
||||||
const char *pager = getenv("GIT_PAGER");
|
const char *pager;
|
||||||
|
|
||||||
if (!isatty(1))
|
if (!isatty(1))
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
|
pager = getenv("GIT_PAGER");
|
||||||
if (!pager) {
|
if (!pager) {
|
||||||
if (!pager_program)
|
if (!pager_program)
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
@ -60,6 +62,16 @@ void setup_pager(void)
|
|||||||
if (!pager)
|
if (!pager)
|
||||||
pager = "less";
|
pager = "less";
|
||||||
else if (!*pager || !strcmp(pager, "cat"))
|
else if (!*pager || !strcmp(pager, "cat"))
|
||||||
|
pager = NULL;
|
||||||
|
|
||||||
|
return pager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_pager(void)
|
||||||
|
{
|
||||||
|
const char *pager = git_pager();
|
||||||
|
|
||||||
|
if (!pager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spawned_pager = 1; /* means we are emitting to terminal */
|
spawned_pager = 1; /* means we are emitting to terminal */
|
||||||
|
10
var.c
10
var.c
@ -18,6 +18,15 @@ static const char *editor(int flag)
|
|||||||
return pgm;
|
return pgm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *pager(int flag)
|
||||||
|
{
|
||||||
|
const char *pgm = git_pager();
|
||||||
|
|
||||||
|
if (!pgm)
|
||||||
|
pgm = "cat";
|
||||||
|
return pgm;
|
||||||
|
}
|
||||||
|
|
||||||
struct git_var {
|
struct git_var {
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *(*read)(int);
|
const char *(*read)(int);
|
||||||
@ -26,6 +35,7 @@ static struct git_var git_vars[] = {
|
|||||||
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
||||||
{ "GIT_AUTHOR_IDENT", git_author_info },
|
{ "GIT_AUTHOR_IDENT", git_author_info },
|
||||||
{ "GIT_EDITOR", editor },
|
{ "GIT_EDITOR", editor },
|
||||||
|
{ "GIT_PAGER", pager },
|
||||||
{ "", NULL },
|
{ "", NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user