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

Re: [PATCH 2/3] gitweb: add output buffering and associated functions

From
Jakub Narebski <jnareb@gmail.com>
Date
Oct 28, 2010, 09:56 UTC
Message-ID
<m3bp6eiqu5.fsf@localhost.localdomain>
In-Reply-To
<1288226574-19068-3-git-send-email-warthog9@eaglescrag.net>
"John 'Warthog9' Hawley" <warthog9@eaglescrag.net> writes:
Show 10 quoted lines
> This adds output buffering for gitweb, mainly in preparation for
> caching support.  This is a dramatic change to how caching was being
> done, mainly in passing around the variable manually and such.
> 
> This centrally flips the entire STDOUT to a variable, which after the
> completion of the run, flips it back and does a print on the resulting
> data.
> 
> This should save on the previous 10K line patch (or so) that adds more
> explicit output passing.
Signoff?
Show 40 quoted lines
> ---
>  gitweb/gitweb.perl |   29 +++++++++++++++++++++++++++++
>  1 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 215a4e9..757ef46 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -30,6 +30,9 @@ BEGIN {
>  
>  our $version = "++GIT_VERSION++";
>  
> +# Output buffer variable
> +$output = "";
> +
>  our ($my_url, $my_uri, $base_url, $path_info, $home_link);
>  sub evaluate_uri {
>  	our $cgi;
> @@ -1151,6 +1154,25 @@ sub evaluate_argv {
>  	);
>  }
>  
> +sub change_output {
> +	our $output;
> +
> +	# Trap the 'proper' STDOUT to STDOUT_REAL for things like error messages and such
> +	open(STDOUT_REAL,">&STDOUT") or die "Unable to capture STDOUT $!\n";
> +
> +	# Close STDOUT, so that it isn't being used anymore.
> +	close STDOUT;
> +
> +	# Trap STDOUT to the $output variable, which is what I was using in the original
> +	# patch anyway.
> +	open(STDOUT,">", \$output) || die "Unable to open STDOUT: $!"; #open STDOUT handle to use $var
> +}
> +
> +sub reset_output {
> +	# This basically takes STDOUT_REAL and puts it back as STDOUTl
> +	open(STDOUT,">&STDOUT_REAL");
> +}

Nice solution. I'll steal it for GitwebCache::Capture::Redirect (or something like that, instead of relying on a bit cryptic select($fh)).

Show 8 quoted lines
> @@ -1163,7 +1185,10 @@ sub run {
>  		$pre_dispatch_hook->()
>  			if $pre_dispatch_hook;
>  
> +		change_output();
>  		run_request();
> +		reset_output();
> +		print $output;
Doesn't this enable capture unconditionally?  

Wouldn't that screw-up the blame_data part of blame_interactive Ajax-y view? Wouldn't that decrease perceived responsiveness of gitweb?

Show 11 quoted lines
>  
>  		$post_dispatch_hook->()
>  			if $post_dispatch_hook;
> @@ -3673,6 +3698,10 @@ sub die_error {
>  		500 => '500 Internal Server Error',
>  		503 => '503 Service Unavailable',
>  	);
> +	# Reset the output so that we are actually going to STDOUT as opposed
> +	# to buffering the output.
> +	reset_output();
> +
Good.
>  	git_header_html($http_responses{$status}, undef, %opts);
>  	print <<EOF;
>  <div class="page_body">
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: John 'Warthog9' HawleyNext: John 'Warthog9' Hawley
Message 6 of 43 in “Gitweb caching v7”
  1. 0/3 Gitweb caching v7John 'Warthog9' Hawley, Oct 28, 2010
  2. 1/3 gitweb: Add option to force version matchJohn 'Warthog9' Hawley, Oct 28, 2010
  3. Jakub NarebskiOct 28, 2010
  4. Junio C HamanoOct 28, 2010
  5. 2/3 gitweb: add output buffering and associated functionsJohn 'Warthog9' Hawley, Oct 28, 2010
  6. Jakub NarebskiOct 28, 2010
  7. 3/3 gitweb: File based caching layer (from git.kernel.org)John 'Warthog9' Hawley, Oct 28, 2010
  8. Jakub NarebskiOct 28, 2010
  9. Junio C HamanoOct 28, 2010
  10. Junio C HamanoOct 29, 2010
  11. Jakub NarebskiOct 30, 2010
  12. Junio C HamanoOct 31, 2010
  13. Jakub NarebskiOct 31, 2010
  14. 0/4 Gitweb caching v7.1Jakub Narebski, Nov 1, 2010
  15. 0/4 Gitweb caching v7.2Jakub Narebski, Nov 12, 2010
  16. 1/4 gitweb: Prepare for splitting gitwebJakub Narebski, Nov 12, 2010
  17. Junio C HamanoNov 17, 2010
  18. Jakub NarebskiNov 18, 2010
  19. 1/4 gitweb: Prepare for splitting gitwebJakub Narebski, Dec 2, 2010
  20. Junio C HamanoDec 2, 2010
  21. Jakub NarebskiDec 2, 2010
  22. Junio C HamanoDec 2, 2010
  23. Jakub NarebskiDec 2, 2010
  24. 2/4 gitweb: add output buffering and associated functionsJakub Narebski, Nov 12, 2010
  25. 3/4 gitweb: File based caching layer (from git.kernel.org)Jakub Narebski, Nov 12, 2010
  26. 3/4 gitweb: File based caching layer (from git.kernel.org)Jakub Narebski, Nov 28, 2010
  27. Jakub NarebskiNov 28, 2010
  28. Junio C HamanoNov 29, 2010
  29. Junio C HamanoNov 29, 2010
  30. 3/4 gitweb: File based caching layer (from git.kernel.org)Jakub Narebski, Nov 29, 2010
  31. Junio C HamanoNov 30, 2010
  32. Jakub NarebskiNov 30, 2010
  33. demerphqNov 29, 2010
  34. demerphqNov 29, 2010
  35. Jakub NarebskiNov 29, 2010
  36. 4/4 gitweb: Minimal testing of gitweb cachingJakub Narebski, Nov 13, 2010
  37. Junio C HamanoNov 17, 2010
  38. Jakub NarebskiNov 17, 2010
  39. 1/4 gitweb: Prepare for splitting gitwebJakub Narebski, Nov 1, 2010
  40. 1/4 gitweb: Prepare for splitting gitwebJakub Narebski, Nov 1, 2010
  41. 2/4 gitweb: add output buffering and associated functionsJakub Narebski, Nov 1, 2010
  42. 3/4 gitweb: File based caching layer (from git.kernel.org)Jakub Narebski, Nov 1, 2010
  43. 4/4 gitweb: Minimal testing of gitweb cachingJakub Narebski, Nov 1, 2010

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.