Skip to content

Commit

Permalink
"git -p cmd" to page anywhere
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 9, 2006
1 parent cfc01c0 commit 85fb65e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 85fb65e

Please sign in to comment.