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

Re: [PATCH/RFC 1/2] gitweb: change format_diff_line() to remove leading SP from $diff_class

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 17, 2011, 19:02 UTC
Message-ID
<7v62jnmog3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAFo4x0LP4fXgSNAnss_WRLo-TH_qe=esYn7P+=iS6t87tdzcbw@mail.gmail.com>
Kato Kazuyoshi <kato.kazuyoshi@gmail.com> writes:
> The format_diff_line() will return $diff_class and HTML in upcoming changes.

An auxiliary piece of information like this is fine at the end of the commit log message, but the patch itself wants to be justified standalone. Perhaps this should be sufficient:

	The $diff_class variable to classify the kind of line in the diff
	output was prefixed with a SP, only so that the code to synthesize
	value for "class" attribute can blindly concatenate it with
	another value "diff". This made the code unnecessarily ugly.
	Instead, add SP that separates the value of $diff_class from
	another class value "diff" where <div class="..."> string is
	created and drop the leading SP from the value of $diff_class.
	
Explained this way, it does not even have to mention that the return value
will be changed in a different patch.

We all know that the hidden motivation of this change is that the caller of this function, after it starts using the returned value of $diff_class, does not want to worry about the ugly SP prefix in that variable. Saying only "This function will return this variable in the future" still does not fully explain that hidden motivation unless you say "and the caller shouldn't have to worry about the leading SP", so let's not even mention it in the log message of this change.

> ---
Sign-off?
Show 11 quoted lines
>  gitweb/gitweb.perl |   24 +++++++++++++-----------
>  1 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 85d64b2..095adda 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -2235,28 +2235,30 @@ sub format_diff_line {
> ...
> +
> +	my $div_open = '<div class="' . (join ' ', ('diff', $diff_class)) . '">';

I think using a separate helper variable like this is a good change. You do not have to worry about the issue in three different places.

But doesn't join(" ", ("frotz", "")) still give you "frotz "? It is OK to punt and say

	my $div_open = '<div class="diff $diff_class">';

which would be far easier to read. It may sacrifice a bit of tidiness in the resulting HTML but the tidiness of the source outweighs it.

Of course, if you have tons of classes, it may be worth doing something like

	join(" ", grep { defined $_ && $_ ne ""}  @diff_classes);
but I do not think it is worth it in this particular case.
Thanks.
Previous: Kato KazuyoshiNext: Kato Kazuyoshi
Message 2 of 8 in “gitweb: change format_diff_line() to remove leading SP from $diff_class”
  1. 1/2 gitweb: change format_diff_line() to remove leading SP from $diff_classKato Kazuyoshi, Oct 17, 2011
  2. Junio C HamanoOct 17, 2011
  3. Kato KazuyoshiOct 17, 2011
  4. Jakub NarebskiOct 17, 2011
  5. Junio C HamanoOct 17, 2011
  6. Jakub NarebskiOct 17, 2011
  7. Junio C HamanoOct 17, 2011
  8. gitweb: Refactor diff body line classificationJakub Narebski, Oct 18, 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.