From 85fb65ed6e41e93760a91b33b512d3d9dc67ac66 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 6 Jun 2006 16:58:40 -0700 Subject: [PATCH] "git -p cmd" to page anywhere This allows you to say: git -p diff v2.6.16-rc5.. and the command pipes the output of any git command to your pager. [jc: this resurrects a month old RFC patch with improvement suggested by Linus to call it --paginate instead of --less.] Signed-off-by: Junio C Hamano --- cache.h | 1 + diff.c | 2 +- git.c | 5 +++++ pager.c | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index 7b5c91c996..b5e3f8fa21 100644 --- a/cache.h +++ b/cache.h @@ -382,6 +382,7 @@ extern int receive_keep_pack(int fd[2], const char *me, int quiet, int); /* pager.c */ extern void setup_pager(void); +extern int pager_in_use; /* base85 */ int decode_85(char *dst, char *line, int linelen); diff --git a/diff.c b/diff.c index 3e26180f08..a00f9d1e52 100644 --- a/diff.c +++ b/diff.c @@ -112,7 +112,7 @@ int git_diff_config(const char *var, const char *value) diff_use_color_default = 1; /* bool */ else if (!strcasecmp(value, "auto")) { diff_use_color_default = 0; - if (isatty(1)) { + if (isatty(1) || pager_in_use) { char *term = getenv("TERM"); if (term && strcmp(term, "dumb")) diff_use_color_default = 1; diff --git a/git.c b/git.c index 256730112e..49062ca66e 100644 --- a/git.c +++ b/git.c @@ -251,6 +251,11 @@ int main(int argc, const char **argv, char **envp) cmd = *++argv; argc--; + if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { + setup_pager(); + continue; + } + if (strncmp(cmd, "--", 2)) break; diff --git a/pager.c b/pager.c index 2d186e8bde..bb14e99735 100644 --- a/pager.c +++ b/pager.c @@ -5,6 +5,8 @@ * something different on Windows, for example. */ +int pager_in_use; + static void run_pager(const char *pager) { execlp(pager, pager, NULL); @@ -24,6 +26,8 @@ void setup_pager(void) else if (!*pager || !strcmp(pager, "cat")) return; + pager_in_use = 1; /* means we are emitting to terminal */ + if (pipe(fd) < 0) return; pid = fork(); -- 2.11.4.GIT