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

Re: [PATCH] gitweb: Refactor git_header_html

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 21, 2011, 23:48 UTC
Message-ID
<7v4o3i7nkt.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110621183550.9315.21922.stgit@localhost.localdomain>
Jakub Narebski <jnareb@gmail.com> writes:
> P.S. I wonder if print_search_form() should also get passed %opts as
> one of its parameters...
I do not particularly care for this:
	sub foo {
        	my %opts = @_;
		if ($opts{-option} eq 'bar') {
                	... do this ...
style, which lets a caller pass any random typo to the callee, like so:
	foo(-optoin => 'value');
But maybe it is just me.
Show 16 quoted lines
> +sub print_header_links {
> +	my %opts = @_;
> +
> +	# print out each stylesheet that exist, providing backwards capability
> +	# for those people who defined $stylesheet in a config file
> +	if (defined $stylesheet) {
> +		print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
> +	} else {
> +		foreach my $stylesheet (@stylesheets) {
> +			next unless $stylesheet;
> +			print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
> +		}
> +	}
> +	if ($opts{'-feed'}) {
> +		print_feed_meta();
> +	}

Here, we refrain from showing the <link> elements that are related to the RSS/Atom feeds (if we know what $project we are talking about), or <link> elements that are related to the project list (html top page and opml) if we are not showing a normal return, as $opts{'-feed'} is true only when we are returning '200 OK'.

The original implementation, even though it used statement modifiers after this print_feed_meta(), was much easier to follow, at least for me. The association between "feed-meta" and "200 OK" was close together and more direct.

Show 5 quoted lines
> ...
> -		}
> -	}
> -	print_feed_meta()
> -		if ($status eq '200 OK');

Other than that, this looks a correct no-op patch that makes the resulting smaller functions easier to grok.

Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 4 in “gitweb: Refactor git_header_html”
  1. gitweb: Refactor git_header_htmlJakub Narebski, Jun 21, 2011
  2. Junio C HamanoJun 21, 2011
  3. Jakub NarebskiJun 22, 2011
  4. [PATCHv2] gitweb: Refactor git_header_htmlJakub Narebski, Jun 22, 2011

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.