git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Quick description of possible gitattributes system

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 2, 2007, 21:02 UTC
Message-ID
<Pine.LNX.4.64.0703021249010.3953@woody.linux-foundation.org>
In-Reply-To
<200703021937.33648.andyparkins@gmail.com>
On Fri, 2 Mar 2007, Andy Parkins wrote:
Show 5 quoted lines
> On Friday 2007, March 02, Linus Torvalds wrote:
> 
> > Yes. How about just having the built-in git pager do the right thing?
> 
> Perfect.  This is absolutely the right thing to do I think.

Well, it would be perfect, except it's rather hard to do. Right now we simply don't have any way to tell the pager what to do with the data, and we'd need to do some communications passing thing to let it know.

It *could* just look at the data directly, but that's actually hard: if we start looking at the data, there's no way to push the data back onto the head of a pipe, and there's no really good way to tell an external pager to "start off with this data that I already read earlier to figure out the type, and then continue with that other file descriptor that I'm passing in".

So then we'd have to have a totally useless process in between the git process and the external pager to just feed the data from one pipe to the other..

Doing the pager internally would obviously solve that issue, but I really don't think we want to do that, especially since it's very system-dependent. And temporary files suck for all the other reasons (incrementally generated data).

So we're in the situation where:
 - the pager process *will* wait until actual data is starting to appear,
   so we *can* have some side-band channel to tell it "oh, btw, if there 
   is a pager, this is going to be image data, so start up an external 
   image viewer instead". 
 - but I don't have a good clue what side-band to use. We could use 
   a special "FILE *pagerdata", of course (which would just be fd#3 in 
   the pager). Then, "git show" could just do something like
	if (pager_in_use)
		fprintf(pagerdata, "'%s'\n", type);
   and we could change pager.c to do something like the appended patch.
but I have to say, it looks a bit strange.
		Linus
---
diff --git a/pager.c b/pager.c
index 5f280ab..b71dd44 100644
--- a/pager.c
+++ b/pager.c
@@ -9,6 +9,8 @@
 
 static void run_pager(const char *pager)
 {
+	static char input_type[100] = "text";
+
 	/*
 	 * Work around bug in "less" by not starting it until we
 	 * have real input
@@ -17,7 +19,16 @@ static void run_pager(const char *pager)
 
 	FD_ZERO(&in);
 	FD_SET(0, &in);
-	select(1, &in, NULL, &in, NULL);
+	FD_SET(3, &in);
+	select(4, &in, NULL, &in, NULL);
+	if (FS_ISSET(3, &in)) {
+		int n = read(3, input_type, sizeof(input_type)-1);
+		if (n > 0)
+			input_type[n] = 0;
+	}
+	close(3);
+
+	pager = select_pager(input_type, pager);
 
 	execlp(pager, pager, NULL);
 	execl("/bin/sh", "sh", "-c", pager, NULL);
Previous: Andy ParkinsNext: Johannes Schindelin
Message 15 of 20 in “Quick description of possible gitattributes system”
  1. Quick description of possible gitattributes systemAndy Parkins, Mar 1, 2007
  2. Brian GernhardtMar 1, 2007
  3. Andy ParkinsMar 2, 2007
  4. Brian GernhardtMar 2, 2007
  5. Andy ParkinsMar 2, 2007
  6. Brian GernhardtMar 2, 2007
  7. Robin RosenbergMar 1, 2007
  8. Junio C HamanoMar 2, 2007
  9. Junio C HamanoMar 2, 2007
  10. Andy ParkinsMar 2, 2007
  11. Andy ParkinsMar 2, 2007
  12. Jakub NarebskiMar 2, 2007
  13. Linus TorvaldsMar 2, 2007
  14. Andy ParkinsMar 2, 2007
  15. Linus TorvaldsMar 2, 2007
  16. Johannes SchindelinMar 2, 2007
  17. Andy ParkinsMar 2, 2007
  18. Andy ParkinsMar 2, 2007
  19. Junio C HamanoMar 3, 2007
  20. Jakub NarebskiMar 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.