@matheusbsbs / matheus-bagliano / commits / 85fb65ed6e
Fork 0

"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 <junkio@cox.net>

Junio C Hamano committed Jun 6, 2006 at 16:58 UTC 85fb65ed6e41e93760a91b33b512d3d9dc67ac66
4 files changed +11 -1
cache.h
+1
@@ -382,6 +382,7 @@ extern int receive_keep_pack(int fd[2], const char *me, int quiet, int);
382
383 /* pager.c */
384 extern void setup_pager(void);
385 +extern int pager_in_use;
386
387 /* base85 */
388 int decode_85(char *dst, char *line, int linelen);
diff.c
+1 -1
@@ -112,7 +112,7 @@ int git_diff_config(const char *var, const char *value)
112 diff_use_color_default = 1; /* bool */
113 else if (!strcasecmp(value, "auto")) {
114 diff_use_color_default = 0;
115 - if (isatty(1)) {
115 + if (isatty(1) || pager_in_use) {
116 char *term = getenv("TERM");
117 if (term && strcmp(term, "dumb"))
118 diff_use_color_default = 1;
git.c
+5
@@ -251,6 +251,11 @@ int main(int argc, const char **argv, char **envp)
251 cmd = *++argv;
252 argc--;
253
254 + if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
255 + setup_pager();
256 + continue;
257 + }
258 +
259 if (strncmp(cmd, "--", 2))
260 break;
261
pager.c
+4
@@ -5,6 +5,8 @@
5 * something different on Windows, for example.
6 */
7
8 +int pager_in_use;
9 +
10 static void run_pager(const char *pager)
11 {
12 execlp(pager, pager, NULL);
@@ -24,6 +26,8 @@ void setup_pager(void)
26 else if (!*pager || !strcmp(pager, "cat"))
27 return;
28
29 + pager_in_use = 1; /* means we are emitting to terminal */
30 +
31 if (pipe(fd) < 0)
32 return;
33 pid = fork();