Re: [PATCH/RFC] Fix for default pager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 6/8/2010 7:29, schrieb Jeff King:
> On Mon, Jun 07, 2010 at 08:58:08PM -0300, Dario Rodriguez wrote:
>> +#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 };
> 
> ...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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]