Skip to contentSkip to conversation

Fix for default pager

PATCH/RFC Dario Rodriguez 12 participants 29 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

All commands using pager:

Default pager was 'less' even when some systems such AIX and other basic or old systems do NOT have 'less' installed. In such case, git just does not display anything in pager-enabled functionalities such as 'git log' or 'git show', exiting with status 0.

With this patch, git will not use DEFAULT_PAGER macro anymore, instead, git will look for 'less' and 'more' in the most common paths. If there is no pager, returns NULL as if it's 'cat'.

Obviously, the commit message needs to be rewritten :p

---
 pager.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 73 insertions(+), 7 deletions(-)
pager.c +73 -7
index dac358f..3cfbd73 100644
@@ -2,10 +2,19 @@
 #include "run-command.h"
 #include "sigchain.h"
 
-#ifndef DEFAULT_PAGER
-#define DEFAULT_PAGER "less"
+#ifndef GIT_PAGER_ENVIRONMENT
+#define GIT_PAGER_ENVIRONMENT "GIT_PAGER"
 #endif
 
+#ifndef GIT_PGR_LOOKUP_DBG_ENVIRONMENT
+#define GIT_PGR_LOOKUP_DBG_ENVIRONMENT "GIT_PAGER_LOOKUP_DEBUG"
+#endif
+
+#ifndef PAGER_ENVIRONMENT
+#define PAGER_ENVIRONMENT "PAGER"
+#endif
+
+
 /*
  * This is split up from the rest of git so that we can do
  * something different on Windows.
@@ -48,23 +57,80 @@ static void wait_for_pager_signal(int signo)
 	raise(signo);
 }
 
-const char *git_pager(int stdout_is_tty)
+static int is_executable(const char *name)
+{
+	struct stat st;
+
+	if (stat(name, &st) ||
+	    !S_ISREG(st.st_mode))
+		return 0;
+
+#ifdef WIN32
+{	/* cannot trust the executable bit, peek into the file instead */
+	char buf[3] = { 0 };
+	int n;
+	int fd = open(name, O_RDONLY);
+	st.st_mode &= ~S_IXUSR;
+	if (fd >= 0) {
+		n = read(fd, buf, 2);
+		if (n == 2)
+			/* DOS executables start with "MZ" */
+			if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+				st.st_mode |= S_IXUSR;
+		close(fd);
+	}
+}
+#endif
+	return st.st_mode & S_IXUSR;
+}
+
+const char *git_pager(int stdout_is_tty) 
 {
+	static const char *pager_bins[] =
+		{ "less", "more", NULL };
+	static const char *common_binary_paths[] =
+		{ "/bin/","/usr/bin/","/usr/local/bin/",NULL };
+
 	const char *pager;
+	char **p1,**p2,*pager_heap;
+	char exe_name[255];
+	int pager_lkp_dbg=0;
 
 	if (!stdout_is_tty)
 		return NULL;
 
-	pager = getenv("GIT_PAGER");
+	if(getenv(GIT_PGR_LOOKUP_DBG_ENVIRONMENT))
+		pager_lkp_dbg=1;
+
+	memset( exe_name,0,255 );
+	pager = getenv(GIT_PAGER_ENVIRONMENT);
 	if (!pager) {
 		if (!pager_program)
 			git_config(git_default_config, NULL);
 		pager = pager_program;
 	}
 	if (!pager)
-		pager = getenv("PAGER");
-	if (!pager)
-		pager = DEFAULT_PAGER;
+		pager = getenv(PAGER_ENVIRONMENT);
+	if (!pager) {
+
+		for (p1=(char**)pager_bins; (*p1)&&(!pager)
+			;p1++)
+			for (p2=(char**)common_binary_paths; (*p2)&&(!pager)
+				;p2++) {
+				sprintf( exe_name,"%s%s",
+					 *p2,*p1 );
+				if (is_executable(exe_name)) {
+					pager_heap = (char*) malloc(sizeof(exe_name));
+					strcpy(pager_heap,exe_name);
+					pager = pager_heap;
+				}
+			}
+
+		if (pager_lkp_dbg)
+			fprintf(stderr, "Debug: Lookup for existent pagers, got [%s]\n",
+				(pager==NULL)?"(null)":pager);
+
+	}
 	else if (!*pager || !strcmp(pager, "cat"))
 		pager = NULL;
 
Signature · 1 line
1.7.1.245.g7c42e.dirty
#1 lore raw

Excerpts from Dario Rodriguez's message of Mon Jun 07 19:58:08 -0400 2010:

Quoted 4 lines

Default pager was 'less' even when some systems such AIX and other basic or old systems do NOT have 'less' installed. In such case, git just does not display anything in pager-enabled functionalities such as 'git log' or 'git show', exiting with status 0.

Why not set a sensible DEFAULT_PAGER value for the system in your config.mak file instead?

Just curious.

Thanks
-Ben

Signature · 4 lines
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
#2 lore raw
Quoted 6 lines · Ben Walton

Why not set a sensible DEFAULT_PAGER value for the system in your config.mak file instead?

Just curious.

I was thinking about it before coding the patch, and found some consequences. First of all, the most important thing I should understand is that most users will install git from binary, precompiled packages instead of the good download and compile. So this is actually a good reason to not do it that way (config.mak)... Some users may download the compiled binary while it's actually calling it's default pager.

But this is not the only reason. Let me give you an example: We develop (I'm actually working at Accenture) using several machines. When we need some tool, we compile it in our first machine, and install it for an specific user. In some other environments we cannot compile things (testing environments) so we transfer (FTP) those binary files. It's just another case, and the default pager could cause problems here (in fact, i experienced such problems).

Another case (or something as the first one): If you installed less (via your package system), then git, and then you happen to uninstall less... should GIT be uninstalled in absence of it's default pager?

I think GIT must auto-detect it's pager based in what is on the system at runtime, don't you think so?

#3 lore raw
Quoted 8 lines · Dario Rodriguez
Quoted 6 lines · Ben Walton

Why not set a sensible DEFAULT_PAGER value for the system in your config.mak file instead?

Just curious.

Quoted 7 lines

I was thinking about it before coding the patch, and found some consequences. First of all, the most important thing I should understand is that most users will install git from binary, precompiled packages instead of the good download and compile. So this is actually a good reason to not do it that way (config.mak)... Some users may download the compiled binary while it's actually calling it's default pager.

If you are downloading a binary, the package compiler should do one of two things:

1. indicate a package dependency on 'less'

2. set DEFAULT_PAGER to 'more' (or whatever is appropriate for your system)

Yes, auto-detection means we can more flexibly "upgrade" to less when the package suddenly appears. But if you really care about your pager, why not just set $PAGER?

The most important thing is that users who _don't_ care don't see something broken, but the rules above already cover that with current git.

Quoted 7 lines

But this is not the only reason. Let me give you an example: We develop (I'm actually working at Accenture) using several machines. When we need some tool, we compile it in our first machine, and install it for an specific user. In some other environments we cannot compile things (testing environments) so we transfer (FTP) those binary files. It's just another case, and the default pager could cause problems here (in fact, i experienced such problems).

Then set DEFAULT_PAGER to 'more' (or 'cat' for that matter), and use $PAGER on machines that are more capable.

-Peff

#4 lore raw
Quoted 5 lines · Jeff King

If you are downloading a binary, the package compiler should do one of two things:

 1. indicate a package dependency on 'less'

but... git will be uninstalled if you happen to uninstall less.

Quoted 3 lines

 2. set DEFAULT_PAGER to 'more' (or whatever is appropriate for your system)

and I know it's a very nice fallback default, but you still depending on the pager, and will display nothing and return 0 if 'more' fails to execute.

Something needs to be changed... if the sane way is to keep default pager (almost setting 'more') instead of auto-detection... then we must say something to the user when the pager fails to execute. (*) Actually 'git' display nothing... and returns 0.

Quoted 4 lines

Yes, auto-detection means we can more flexibly "upgrade" to less when the package suddenly appears. But if you really care about your pager, why not just set $PAGER?

good point, I agree. But again, back to (*), we must correct something... the other way is that if pager fails to execute, we cannot simply return 0.

I could submit a patch for this, may be is a little bit better (or simpler).

#5 lore raw

Am 6/8/2010 15:49, schrieb Dario Rodriguez:

Quoted 3 lines

we must correct
something... the other way is that if pager fails to execute, we cannot simply return 0.

But we do not return 0:

 $ GIT_PAGER=/is/not/there git log
 $ echo $?
 141

That's SIGPIPE, just as I would expect.

And with this change

pager.c +0 -3
index dac358f..86519cc 100644
@@ -89,9 +89,6 @@ void setup_pager(void)
 		static const char *env[] = { "LESS=FRSX", NULL };
 		pager_process.env = env;
 	}
-#ifndef WIN32
-	pager_process.preexec_cb = pager_preexec;
-#endif
 	if (start_command(&pager_process))
 	return;
 

I get:

 $ GIT_PAGER=/is/not/there ./git log -1 --oneline
 error: cannot run /is/not/there: No such file or directory
 1a16cee merge-recursive: demonstrate an incorrect conflict with submodule

-- Hannes

#6 lore raw
Quoted 5 lines · Johannes Sixt

Am 6/8/2010 15:49, schrieb Dario Rodriguez:

Quoted 3 lines

we must correct
something... the other way is that if pager fails to execute, we cannot simply return 0.

Quoted 8 lines

But we do not return 0:

 $ GIT_PAGER=/is/not/there git log
 $ echo $?
 141

That's SIGPIPE, just as I would expect.

As I said in the original thread...

$ PAGER=/nothing/here ../git log
$ echo $?
0
$ GIT_PAGER=/nothing/here ../git log
$ echo $?
0

That's on AIX 5.2

Quoted 17 lines

And with this change

pager.c +0 -3
index dac358f..86519cc 100644
@@ -89,9 +89,6 @@ void setup_pager(void)
                static const char *env[] = { "LESS=FRSX", NULL };
                pager_process.env = env;
        }
-#ifndef WIN32
-       pager_process.preexec_cb = pager_preexec;
-#endif
        if (start_command(&pager_process))
        return;
 
Quoted 6 lines

I get:

 $ GIT_PAGER=/is/not/there ./git log -1 --oneline
 error: cannot run /is/not/there: No such file or directory
 1a16cee merge-recursive: demonstrate an incorrect conflict with submodule

Curious... I patched it on AIX and I get:

$ GIT_PAGER=/nothing/here ../git log
error: cannot run /nothing/here: No such file or directory
commit 3274a12f940680612e3bfd3d022a0eab460c0f1f
Author: usuario ####### <#######@Maquina01.(none)>
Date:   Thu Jun 3 20:02:23 2010 +0200

OtherCom

commit acf110f7c878a37e4a5af8499134df28da0e8ab3

Author: usuario ####### <#######@Maquina01.(none)>
Date:   Thu Jun 3 20:01:37 2010 +0200

inicial

However, the patch must delete the pager_preexec definition too... but I wonder, do somebody still need it?

btw: I still think 'more' is much more sane fallback default than 'less'... look (with your patch applied):

$ ../git log
error: cannot run less: No such file or directory
commit 3274a12f940680612e3bfd3d022a0eab460c0f1f
Author: ####### <#######@Maquina01.(none)>
Date:   Thu Jun 3 20:02:23 2010 +0200

OtherCom

commit acf110f7c878a37e4a5af8499134df28da0e8ab3

Author: ####### <#######@Maquina01.(none)>
Date:   Thu Jun 3 20:01:37 2010 +0200

inicial

#7 lore raw

Am 08.06.2010 16:39, schrieb Dario Rodriguez:

Quoted 5 lines · Johannes Sixt
Quoted 4 lines
  $ GIT_PAGER=/is/not/there git log
  $ echo $?
  141
Quoted 7 lines
Quoted 1 line

That's SIGPIPE, just as I would expect.

As I said in the original thread...

$ PAGER=/nothing/here ../git log
$ echo $?
0

That's no surprise with your toy repository: git-log has run to completion (without overrunning the pipe buffer) before the pager process that it forked can even execute its first instruction.

Quoted 9 lines

btw: I still think 'more' is much more sane fallback default than 'less'... look (with your patch applied):

$ ../git log
error: cannot run less: No such file or directory
commit 3274a12f940680612e3bfd3d022a0eab460c0f1f
Author: #######<#######@Maquina01.(none)>
Date:   Thu Jun 3 20:02:23 2010 +0200
Quoted 8 lines

OtherCom

commit acf110f7c878a37e4a5af8499134df28da0e8ab3

Author: #######<#######@Maquina01.(none)>
Date:   Thu Jun 3 20:01:37 2010 +0200

inicial

How is this an argument for 'more'? (Just asking; I don't see your point.)

-- Hannes

#8 lore raw
Quoted 13 lines · Johannes Sixt

Am 08.06.2010 16:39, schrieb Dario Rodriguez:

Quoted 12 lines
Quoted 6 lines · Johannes Sixt
 $ GIT_PAGER=/is/not/there git log
 $ echo $?
 141

That's SIGPIPE, just as I would expect.

As I said in the original thread...

Quoted 8 lines
Quoted 3 lines
$ PAGER=/nothing/here ../git log
$ echo $?
0

That's no surprise with your toy repository: git-log has run to completion (without overrunning the pipe buffer) before the pager process that it forked can even execute its first instruction.

I cannot understand what's the point... I'm running git without installing it, but why do you say "toy repository"?...

Quoted 11 lines
Quoted 11 lines

btw: I still think 'more' is much more sane fallback default than 'less'... look (with your patch applied):

$ ../git log
error: cannot run less: No such file or directory
commit 3274a12f940680612e3bfd3d022a0eab460c0f1f
Author: #######<#######@Maquina01.(none)>
Date:   Thu Jun 3 20:02:23 2010 +0200

    OtherCom

Quoted 9 lines
Quoted 6 lines

commit acf110f7c878a37e4a5af8499134df28da0e8ab3
Author: #######<#######@Maquina01.(none)>
Date:   Thu Jun 3 20:01:37 2010 +0200

    inicial

How is this an argument for 'more'? (Just asking; I don't see your point.)

No problem, let me explain: 'more' is older and standard while (correct me if not true) 'less' is not in POSIX:2008. I work in a lot of Unix-like systems and I found 'more' as a standard, while less is just sometimes installed... my error running 'less' is such an argument for 'more' because:

$ PAGER=more ../git log
commit fccd640197e34dbff72954924ed5c76c42a4aac7
Author: ###### <######@Maquina01.(none)>
Date:   Tue Jun 8 19:23:23 2010 +0200

commit
stdin: END

'more' is not a problem... and as a POSIX standard it's almost never a problem.

#9 lore raw

Am 08.06.2010 19:28, schrieb Dario Rodriguez:

Quoted 18 lines · Johannes Sixt
Quoted 17 lines

Am 08.06.2010 16:39, schrieb Dario Rodriguez:

Quoted 15 lines
Quoted 6 lines · Johannes Sixt
  $ GIT_PAGER=/is/not/there git log
  $ echo $?
  141

That's SIGPIPE, just as I would expect.

As I said in the original thread...

$ PAGER=/nothing/here ../git log
$ echo $?
0
Quoted 7 lines
Quoted 4 lines

That's no surprise with your toy repository: git-log has run to completion (without overrunning the pipe buffer) before the pager process that it forked can even execute its first instruction.

I cannot understand what's the point... I'm running git without installing it, but why do you say "toy repository"?...

Your repository has only 2 commits and its git log output is less than 1kB, i.e., sufficiently small to fit in a pipe's buffer.

git log calls start_command to fork() the pager. The OS's scheduler does not run the newly forked process immediately; rather, git log goes on with its own business, writing output to the pipe that connects to the pager. Because your repository is so small, git log never has to wait that the pager drains the pipe. git log finally reaches exit(0). At this time, an atexit() handler (wait_for_pager()) finally calls finish_command() to wait for the pager.

This is the first time that the forked child process can run. Only now it turns out that the pager cannot be run. The child process closes the pipe and exits with an error, but it is too late: wait_for_pager() drops the error return code of finish_command() to the floor. The parent process (git log) can complete with the exit code that it was given earlier, 0.

Repeat your experiment with ./git log in git.git itself to see the difference.

-- Hannes

#10 lore raw
Quoted 16 lines · Johannes Sixt

Your repository has only 2 commits and its git log output is less than 1kB, i.e., sufficiently small to fit in a pipe's buffer.

git log calls start_command to fork() the pager. The OS's scheduler does not run the newly forked process immediately; rather, git log goes on with its own business, writing output to the pipe that connects to the pager. Because your repository is so small, git log never has to wait that the pager drains the pipe. git log finally reaches exit(0). At this time, an atexit() handler (wait_for_pager()) finally calls finish_command() to wait for the pager.

This is the first time that the forked child process can run. Only now it turns out that the pager cannot be run. The child process closes the pipe and exits with an error, but it is too late: wait_for_pager() drops the error return code of finish_command() to the floor. The parent process (git log) can complete with the exit code that it was given earlier, 0.

Quoted 5 lines

Repeat your experiment with ./git log in git.git itself to see the difference.

-- Hannes

Capisco & touché, with much more than 1k of info, git show ends with a "Broken Pipe"... seems hard to detect for little, recently started projects since I added more than 60k of scripts and I need to do 'git show' to understand that the problem is a broken pipe.

Now, let me think about it... do we need the pager_preexec function? I mean... it works fine without it, and the function is there because of a faulty 'less'.

My problem is obvioulsly solved by adding PAGER=more in my default environment, but I think this could be a litle bit embarrassing for a new user, mostly in environments such this AIX :P

Cheers,
Dario

#11 lore raw
Quoted 28 lines · Dario Rodriguez
Quoted 16 lines · Johannes Sixt

Your repository has only 2 commits and its git log output is less than 1kB, i.e., sufficiently small to fit in a pipe's buffer.

git log calls start_command to fork() the pager. The OS's scheduler does not run the newly forked process immediately; rather, git log goes on with its own business, writing output to the pipe that connects to the pager. Because your repository is so small, git log never has to wait that the pager drains the pipe. git log finally reaches exit(0). At this time, an atexit() handler (wait_for_pager()) finally calls finish_command() to wait for the pager.

This is the first time that the forked child process can run. Only now it turns out that the pager cannot be run. The child process closes the pipe and exits with an error, but it is too late: wait_for_pager() drops the error return code of finish_command() to the floor. The parent process (git log) can complete with the exit code that it was given earlier, 0.

Quoted 5 lines

Repeat your experiment with ./git log in git.git itself to see the difference.

-- Hannes

Capisco& touché, with much more than 1k of info, git show ends with a "Broken Pipe"... seems hard to detect for little, recently started projects since I added more than 60k of scripts and I need to do 'git show' to understand that the problem is a broken pipe.

Quoted 8 lines

Now, let me think about it... do we need the pager_preexec function? I mean... it works fine without it, and the function is there because of a faulty 'less'.

My problem is obvioulsly solved by adding PAGER=more in my default environment, but I think this could be a litle bit embarrassing for a new user, mostly in environments such this AIX :P

Catering to AIX by default seems stupid beyond belief. AIX users today are, without fail, accustomed to having to tweak more or less everything to make the system run smoothly with modern applications (where "modern" is a generous term, including everything that's been written in the last 10 or so years).

Signature · 7 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.
#12 lore raw
Quoted 5 lines · Andreas Ericsson

Catering to AIX by default seems stupid beyond belief. AIX users today are, without fail, accustomed to having to tweak more or less everything to make the system run smoothly with modern applications (where "modern" is a generous term, including everything that's been written in the last 10 or so years).

BSD users are also accustomed to that to a smaller degree. But as long as they keep submitting portability patches to keep their ports up to date, I don't see why those patches shouldn't be accepted. If they're otherwise fit for inclusion that is.

#13 lore raw
In reply to Andreas Ericsson
Quoted 5 lines · Andreas Ericsson

Catering to AIX by default seems stupid beyond belief. AIX users today are, without fail, accustomed to having to tweak more or less everything to make the system run smoothly with modern applications (where "modern" is a generous term, including everything that's been written in the last 10 or so years).

AIX doesn't come with 'less', because it doesn't really need one. 'more' on AIX can page backwards/forwards in piped data (unlike 'more' on Linux etc.), thus negating the most common need for installing 'less' elsewhere. (The other big feature of less, that it by default clears the screen just as you had found what you wanted to read and were about to apply it to the command line before 'poof' - gone) is so annoying to me that I routinely sets PAGER=more before using Git.

If it's true that Git should demand 'less' to be installed before being usable out of the box.. well, that's just plain silly.

-Tor

#14 lore raw
Quoted 2 lines · Tor Arntsen

If it's true that Git should demand 'less' to be installed before being usable out of the box.. well, that's just plain silly.

It depends on how you define "out of the box". The person compiling it just needs to set DEFAULT_PAGER appropriately for their system. "less" is a sane choice for most modern systems. But we can make it even easier on AIX people with:

Makefile +1 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
 	HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+	DEFAULT_PAGER = more
 	NO_STRCASESTR=YesPlease
 	NO_MEMMEM = YesPlease
 	NO_MKDTEMP = YesPlease

That won't do automagic run-time detection if you have "less" installed, but given your claim that AIX's "more" actually doesn't suck, it's probably a good default. People who care can set their PAGER environment variable.

-Peff

#15 lore raw
Quoted 15 lines · Jeff King
Quoted 2 lines · Tor Arntsen

If it's true that Git should demand 'less' to be installed before being usable out of the box.. well, that's just plain silly.

It depends on how you define "out of the box". The person compiling it just needs to set DEFAULT_PAGER appropriately for their system. "less" is a sane choice for most modern systems. But we can make it even easier on AIX people with:

Makefile +0 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
Quoted 7 lines

       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+       DEFAULT_PAGER = more
       NO_STRCASESTR=YesPlease
       NO_MEMMEM = YesPlease
       NO_MKDTEMP = YesPlease

That looks good to me.

Quoted 3 lines

That won't do automagic run-time detection if you have "less" installed, but given your claim that AIX's "more" actually doesn't suck, it's probably a good default.

It does the paging just as 'less', yes. I can page 'git log' or any other output. backwards/forwards as I wish. I'm not aware of any 'more' other than the AIX one that does this. Even the archaic (pre-AIX5) versions did. The AIX 'more' also have several more in-buffer options compared to e.g. Linux 'more'. It sits somewhere between traditional 'more' and 'less', feature-wise. (The AIX 6 version even does the, to me, annoying less-style erase-screen, unless turned off by an option or environment variable.)

Quoted 2 lines

People who care can set their PAGER environment
variable.

-Tor

#16 lore raw
Quoted 1 line · Tor Arntsen

That looks good to me.

OK, here it is with a commit message. Other systems might want the same, I guess (Solaris, IRIX?). I'm cc'ing Brandon, who might have some input.

Note that this is completely untested by me, as all of my AIX boxen have gone away in the past few months (yay!).

-- >8 --
Subject: [PATCH] Makefile: default pager on AIX to "more"

AIX doesn't ship with "less" by default, and their "more" is more featureful than average, so the latter is a more sensible choice. People who really want less can set the compile-time option themselves, or users can set $PAGER.

---
 Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +1 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
 	HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+	DEFAULT_PAGER = more
 	NO_STRCASESTR=YesPlease
 	NO_MEMMEM = YesPlease
 	NO_MKDTEMP = YesPlease
Signature · 1 line
1.7.1.514.g71ed8
Tested-by
#17 lore raw
Quoted 9 lines · Jeff King
Quoted 1 line · Tor Arntsen

That looks good to me.

OK, here it is with a commit message. Other systems might want the same, I guess (Solaris, IRIX?). I'm cc'ing Brandon, who might have some input.

Note that this is completely untested by me, as all of my AIX boxen have gone away in the past few months (yay!).

I did a re-build and test. Everything works fine.

-Tor

-- >8 --
Subject: [PATCH] Makefile: default pager on AIX to "more"

AIX doesn't ship with "less" by default, and their "more" is more featureful than average, so the latter is a more sensible choice. People who really want less can set the compile-time option themselves, or users can set $PAGER.

---
 Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +1 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
 	HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+	DEFAULT_PAGER = more
 	NO_STRCASESTR=YesPlease
 	NO_MEMMEM = YesPlease
 	NO_MKDTEMP = YesPlease

-- 1.7.1.514.g71ed8

#18 lore raw
Quoted 35 lines · Tor Arntsen
Quoted 9 lines · Jeff King
Quoted 1 line · Tor Arntsen

That looks good to me.

OK, here it is with a commit message. Other systems might want the same, I guess (Solaris, IRIX?). I'm cc'ing Brandon, who might have some input.

Note that this is completely untested by me, as all of my AIX boxen have gone away in the past few months (yay!).

I did a re-build and test. Everything works fine.

-Tor

-- >8 --
Subject: [PATCH] Makefile: default pager on AIX to "more"

AIX doesn't ship with "less" by default, and their "more" is more featureful than average, so the latter is a more sensible choice.  People who really want less can set the compile-time option themselves, or users can set $PAGER.

---
 Makefile |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +0 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
Quoted 9 lines

       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+       DEFAULT_PAGER = more
       NO_STRCASESTR=YesPlease
       NO_MEMMEM = YesPlease
       NO_MKDTEMP = YesPlease
-- 1.7.1.514.g71ed8

It's ok for me, I will test it on AIX today, if I've some time.

Cheers,
Dario

#19 lore raw
In reply to Jeff King
Quoted 17 lines · Jeff King

Subject: [PATCH] Makefile: default pager on AIX to "more"

AIX doesn't ship with "less" by default, and their "more" is more featureful than average, so the latter is a more sensible choice. People who really want less can set the compile-time option themselves, or users can set $PAGER.

---
 Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +0 -0
index 34b7dd5..6ad0aca 100644

Makefile ifeq ($(uname_S),NetBSD) · line 936

Quoted 7 lines
Makefile +1 -0
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
 	HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+	DEFAULT_PAGER = more
 	NO_STRCASESTR=YesPlease
 	NO_MEMMEM = YesPlease
 	NO_MKDTEMP = YesPlease

A very sensible approach. Thanks.

#20 lore raw
In reply to Jeff King
Quoted 6 lines · Jeff King
Quoted 1 line · Tor Arntsen

That looks good to me.

OK, here it is with a commit message. Other systems might want the same, I guess (Solaris, IRIX?). I'm cc'ing Brandon, who might have some input.

Yes, I currently set DEFAULT_PAGER to 'more' in my config.mak file on both of these platforms. The 'more' on IRIX is decent (it can go backwards), but the 'more' on Solaris sucks. I've seen 'less' on some newer versions of Solaris. Is it a standard component yet?

So, I think it's appropriate to set DEFAULT_PAGER on IRIX. There can't be many users anyway. It's probably appropriate to set it on Solaris too, if 'less' is not a commonly installed component on modern systems. I wonder how surprised existing git users will be, for those on Solaris platforms that have 'less' installed, when Solaris's crappy 'more' becomes their pager.

Actually, there is a 'more' in /usr/xpg4/bin that is much better, but it is not being used when DEFAULT_PAGER is set to 'more'. Junio created the SANE_TOOL_PATH hack to add this additional path to the search path, but it is only implemented in git-sh-setup, so it only has effect for git scripts. Maybe it should be added to setup_path().

But, I also think it would be nice if git fell back to the 'cat' behavior when it fails to spawn the pager, because the following error is not very informative:

casey@<a_solaris_box> # git log
sh: less: not found
Broken Pipe

-brandon

Quoted 28 lines

Note that this is completely untested by me, as all of my AIX boxen have gone away in the past few months (yay!).

-- >8 --
Subject: [PATCH] Makefile: default pager on AIX to "more"

AIX doesn't ship with "less" by default, and their "more" is more featureful than average, so the latter is a more sensible choice. People who really want less can set the compile-time option themselves, or users can set $PAGER.

---
 Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +1 -0
index 34b7dd5..6ad0aca 100644
@@ -930,6 +930,7 @@ ifeq ($(uname_S),NetBSD)
 	HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
+	DEFAULT_PAGER = more
 	NO_STRCASESTR=YesPlease
 	NO_MEMMEM = YesPlease
 	NO_MKDTEMP = YesPlease
#21 lore raw
Quoted 6 lines · Brandon Casey

So, I think it's appropriate to set DEFAULT_PAGER on IRIX. There can't be many users anyway. It's probably appropriate to set it on Solaris too, if 'less' is not a commonly installed component on modern systems. I wonder how surprised existing git users will be, for those on Solaris platforms that have 'less' installed, when Solaris's crappy 'more' becomes their pager.

I'm a little worried about that, too. On the other hand, wouldn't people who actually care about less have set PAGER already, to use it for things like "man"?

Quoted 7 lines

But, I also think it would be nice if git fell back to the 'cat' behavior when it fails to spawn the pager, because the following error is not very informative:

casey@<a_solaris_box> # git log
sh: less: not found
Broken Pipe

The pager command is executed by the shell these days. Perhaps we should simply set DEFAULT_PAGER on these platforms to "less || more || cat", which seems to work from my simple tests. If that is too hack-ish (e.g., we really care about "does less exist", not "did it fail"), we can do a more invasive patch (or even provide a "git-pager" shell script helper to do a more thorough job).

-Peff

#22 lore raw
In reply to Brandon Casey
Quoted 4 lines · Brandon Casey

Yes, I currently set DEFAULT_PAGER to 'more' in my config.mak file on both of these platforms. The 'more' on IRIX is decent (it can go backwards), but the 'more' on Solaris sucks. I've seen 'less' on some newer versions of Solaris. Is it a standard component yet?

'less' appears to be standard on Solaris 10 (5.10). My older 5.8 box is offline so I can't check that one. AFAIK the difference between Solaris 8 and Solaris 10 is pretty big so I suspect there's no 'less' there but I can't say for certain. I could try to fire up that old box and check though.

-Tor

#23 lore raw
In reply to Brandon Casey
Quoted 3 lines · Brandon Casey

But, I also think it would be nice if git fell back to the 'cat' behavior when it fails to spawn the pager, because the following error is not very informative:

Falling back to 'cat' is nice except when you are on a remote machine with very bad latency.

nazri

#24 lore raw
In reply to Tor Arntsen
Quoted 4 lines · Tor Arntsen

AIX doesn't come with 'less', because it doesn't really need one. 'more' on AIX can page backwards/forwards in piped data (unlike 'more' on Linux etc.), thus negating the most common need for installing 'less' elsewhere.

Less has about a zillion features that more [traditionally] doesn't have, and even some of the more esoteric ones can be quite useful for git. For instance you can determine in a great deal of detail exactly how/when/if it clears the screen/shows a prompt/waits for user input before exiting, etc.

-Miles

Signature · 4 lines
(\(\
(^.^)
(")")
*This is the cute bunny virus, please copy this into your sig so it can spread.
#25 lore raw
In reply to Dario Rodriguez
Quoted 8 lines · Dario Rodriguez

Default pager was 'less' even when some systems such AIX and other basic or old systems do NOT have 'less' installed. In such case, git just does not display anything in pager-enabled functionalities such as 'git log' or 'git show', exiting with status 0.

With this patch, git will not use DEFAULT_PAGER macro anymore, instead, git will look for 'less' and 'more' in the most common paths. If there is no pager, returns NULL as if it's 'cat'.

Run-time pager detection seems like a reasonable goal, I guess, but...

Quoted 24 lines
pager.c +23 -1
-const char *git_pager(int stdout_is_tty)
+static int is_executable(const char *name)
+{
+	struct stat st;
+
+	if (stat(name, &st) ||
+	    !S_ISREG(st.st_mode))
+		return 0;
+
+#ifdef WIN32
+{	/* cannot trust the executable bit, peek into the file instead */
+	char buf[3] = { 0 };
+	int n;
+	int fd = open(name, O_RDONLY);
+	st.st_mode &= ~S_IXUSR;
+	if (fd >= 0) {
+		n = read(fd, buf, 2);
+		if (n == 2)
+			/* DOS executables start with "MZ" */
+			if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+				st.st_mode |= S_IXUSR;
+		close(fd);
+	}
+}

pager.c static void wait_for_pager_signal(int signo) · line 92

Quoted 10 lines
pager.c +9 -0
+#endif
+	return st.st_mode & S_IXUSR;
+}
+
+const char *git_pager(int stdout_is_tty) 
 {
+	static const char *pager_bins[] =
+		{ "less", "more", NULL };
+	static const char *common_binary_paths[] =
+		{ "/bin/","/usr/bin/","/usr/local/bin/",NULL };

...must we really add code with such ugliness as magic PATHs and DOS magic numbers?

Right now we fall back to just exec-ing "less". Could we instead just try to exec "less", if that fails then "more", and then finally "cat"?

That would have almost the same effect and would be much simpler, wouldn't it? The exceptions I can think of are:

- we would actually run "cat" in the final case, instead of optimizing it out.

- "git var GIT_PAGER" wouldn't handle this automatically

-Peff

#26 lore raw

Am 6/8/2010 7:29, schrieb Jeff King:

Quoted 21 lines · Dario Rodriguez
Quoted 20 lines
pager.c +20 -0
+#ifdef WIN32
+{	/* cannot trust the executable bit, peek into the file instead */
+	char buf[3] = { 0 };
+	int n;
+	int fd = open(name, O_RDONLY);
+	st.st_mode &= ~S_IXUSR;
+	if (fd >= 0) {
+		n = read(fd, buf, 2);
+		if (n == 2)
+			/* DOS executables start with "MZ" */
+			if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+				st.st_mode |= S_IXUSR;
+		close(fd);
+	}
+}
+#endif
+	return st.st_mode & S_IXUSR;
+}
+
+const char *git_pager(int stdout_is_tty) 
Quoted 8 lines

pager.c static void wait_for_pager_signal(int signo) · line 92

Quoted 5 lines

{

pager.c +4 -0
+	static const char *pager_bins[] =
+		{ "less", "more", NULL };
+	static const char *common_binary_paths[] =
+		{ "/bin/","/usr/bin/","/usr/local/bin/",NULL };

...must we really add code with such ugliness as magic PATHs and DOS magic numbers?

Yes and no.

Coding DOS magic numbers is bad because you could wrapped a real pager in a shell script (even on Windows).

These days, start_command() is able to report ENOENT if it cannot run a program because it does not exist. However, right in the case of git_pager() this capability is disabled because it sets this magic preexec_cb that waits for data in the child process before it execs the real pager.

If we could get rid of preexec_cb, we could make this work much more pleasantly. pager_preexec waits for data on stdin; Linus added it to work around a faulty 'less'. Do we still need it?

-- Hannes

#27 lore raw
In reply to Jeff King
Quoted 42 lines · Jeff King
Quoted 8 lines · Dario Rodriguez

Default pager was 'less' even when some systems such AIX and other basic or old systems do NOT have 'less' installed. In such case, git just does not display anything in pager-enabled functionalities such as 'git log' or 'git show', exiting with status 0.

With this patch, git will not use DEFAULT_PAGER macro anymore, instead, git will look for 'less' and 'more' in the most common paths. If there is no pager, returns NULL as if it's 'cat'.

Run-time pager detection seems like a reasonable goal, I guess, but...

Quoted 29 lines
pager.c +28 -1
-const char *git_pager(int stdout_is_tty)
+static int is_executable(const char *name)
+{
+     struct stat st;
+
+     if (stat(name, &st) ||
+         !S_ISREG(st.st_mode))
+             return 0;
+
+#ifdef WIN32
+{    /* cannot trust the executable bit, peek into the file instead */
+     char buf[3] = { 0 };
+     int n;
+     int fd = open(name, O_RDONLY);
+     st.st_mode &= ~S_IXUSR;
+     if (fd >= 0) {
+             n = read(fd, buf, 2);
+             if (n == 2)
+                     /* DOS executables start with "MZ" */
+                     if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+                             st.st_mode |= S_IXUSR;
+             close(fd);
+     }
+}
+#endif
+     return st.st_mode & S_IXUSR;
+}
+
+const char *git_pager(int stdout_is_tty)
Quoted 9 lines
Quoted 5 lines

 {
+     static const char *pager_bins[] =
+             { "less", "more", NULL };
+     static const char *common_binary_paths[] =
+             { "/bin/","/usr/bin/","/usr/local/bin/",NULL };

...must we really add code with such ugliness as magic PATHs and DOS magic numbers?

I copied the function 'is_executable' from 'help.c' so we already have such code... :p

Quoted 3 lines

Right now we fall back to just exec-ing "less". Could we instead just try to exec "less", if that fails then "more", and then finally "cat"?

is such a good idea but right now, 'git_pager' is not exec-ing, it's just setting up a pager. If you set-up the pager based on wich one fails in it's execution, you must avoid usage of this function, since it will always return 'less' (or 'more...). What I posted is transparent to any other function; 'git_pager' will be called returning an existent, working pager, so the flow is the same, however I like your proposal too, and should be considered.

Quoted 6 lines

That would have almost the same effect and would be much simpler, wouldn't it? The exceptions I can think of are:

 - we would actually run "cat" in the final case, instead of optimizing it out.

Actually pager is being set to NULL if it's 'cat'... what's git doing with a NULL pager?

Quoted 4 lines

 - "git var GIT_PAGER" wouldn't handle this automatically

-Peff

Blessing,
Dario

#28 lore raw
Quoted 53 lines · Dario Rodriguez
Quoted 42 lines · Jeff King
Quoted 8 lines · Dario Rodriguez

Default pager was 'less' even when some systems such AIX and other basic or old systems do NOT have 'less' installed. In such case, git just does not display anything in pager-enabled functionalities such as 'git log' or 'git show', exiting with status 0.

With this patch, git will not use DEFAULT_PAGER macro anymore, instead, git will look for 'less' and 'more' in the most common paths. If there is no pager, returns NULL as if it's 'cat'.

Run-time pager detection seems like a reasonable goal, I guess, but...

Quoted 29 lines
pager.c +28 -1
-const char *git_pager(int stdout_is_tty)
+static int is_executable(const char *name)
+{
+     struct stat st;
+
+     if (stat(name, &st) ||
+         !S_ISREG(st.st_mode))
+             return 0;
+
+#ifdef WIN32
+{    /* cannot trust the executable bit, peek into the file instead */
+     char buf[3] = { 0 };
+     int n;
+     int fd = open(name, O_RDONLY);
+     st.st_mode &= ~S_IXUSR;
+     if (fd >= 0) {
+             n = read(fd, buf, 2);
+             if (n == 2)
+                     /* DOS executables start with "MZ" */
+                     if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+                             st.st_mode |= S_IXUSR;
+             close(fd);
+     }
+}
+#endif
+     return st.st_mode & S_IXUSR;
+}
+
+const char *git_pager(int stdout_is_tty)
Quoted 9 lines
Quoted 5 lines

 {
+     static const char *pager_bins[] =
+             { "less", "more", NULL };
+     static const char *common_binary_paths[] =
+             { "/bin/","/usr/bin/","/usr/local/bin/",NULL };

...must we really add code with such ugliness as magic PATHs and DOS magic numbers?

Quoted 3 lines

I copied the function 'is_executable' from 'help.c' so we already have such code... :p

How about just un-staticifying the version in help.c instead of duplicating it, then? That way we'd have half the ugliness for this purpose...

Signature · 1 line
Erik "kusma" Faye-Lund