Subject: Re: [PATCH 3/8] gitweb: Move HTML-formatting diff line back to process_diff_line()

From: Jakub Narebski <[email-masked]>
Date: Sat, 11 Feb 2012 08:02:57 -0800 (PST)

Michał Kiedrowicz <[email-masked]> writes:

> Commit 6ba1eb51b (gitweb: Add a feature to show side-by-side diff,
> 2011-10-31) for no special reason moved wrapping diff line in <div> out
> of format_diff_line(). Bring back old behavior.
> 
> This simplifies code in git_patchset_body() and keeps formatting of a
> diff line in one place.
> 
> The more long-term purpose of this patch is to move formatting diff
> lines down to print_diff_chunk(), to allow processing lines without
> HTML-formatting.
> 
> This is just a refactoring patch. It's not meant to change gitweb
> output.

Gah, I don't remember why we ended with change in behavior when adding
side-by-side diff support to gitweb.
 
> Signed-off-by: Michał Kiedrowicz <[email-masked]>

  Acked-by: Jakub Narębski <[email-masked]>

> ---
>  gitweb/gitweb.perl |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index ed63261..d2f75c4 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -2332,14 +2332,18 @@ sub process_diff_line {
>  
>  	if ($from && $to && $line =~ m/^\@{2} /) {
>  		$line = format_unidiff_chunk_header($line, $from, $to);
> -		return $diff_class, $line;
>  
>  	} elsif ($from && $to && $line =~ m/^\@{3}/) {
>  		$line = format_cc_diff_chunk_header($line, $from, $to);
> -		return $diff_class, $line;
> -
> +	} else {
> +		$line = esc_html($line, -nbsp=>1);
>  	}
> -	return $diff_class, esc_html($line, -nbsp=>1);
> +
> +	my $diff_classes = "diff";
> +	$diff_classes .= " $diff_class" if ($diff_class);
> +	$line = "<div class=\"$diff_classes\">$line</div>\n";
> +
> +	return $diff_class, $line;
>  }
>  
>  # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
> @@ -5104,9 +5108,6 @@ sub git_patchset_body {
>  			next PATCH if ($patch_line =~ m/^diff /);
>  
>  			my ($class, $line) = process_diff_line($patch_line, \%from, \%to);
> -			my $diff_classes = "diff";
> -			$diff_classes .= " $class" if ($class);
> -			$line = "<div class=\"$diff_classes\">$line</div>\n";
>  
>  			if ($class eq 'chunk_header') {
>  				print_diff_chunk($diff_style, $is_combined, @chunk);
> -- 
> 1.7.3.4
> 

-- 
Jakub Narębski