From 8be9f0a1c1a9ada71aa38f8210e72ac9db375b75 Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Tue, 25 Oct 2011 00:05:35 +0200 Subject: [PATCH] gitweb: Add navigation to select side-by-side diff Add to the lower part of navigation bar (the action specific part) links allowing to switch between 'inline' (ordinary) diff and 'side by side' style diff. It is not shown for combined diff. *NOTE* that because gitweb does not use href(-replay=>1,...) thorougly, following some navigation links might lose diff style. Signed-off-by: Jakub Narebski --- gitweb/gitweb.perl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index af4f67b114..5970eafc81 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -7150,6 +7150,7 @@ sub git_blobdiff { my $formats_nav = $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)}, "raw"); + $formats_nav .= diff_style_nav($diff_style); git_header_html(undef, $expires); if (defined $hash_base && (my %co = parse_commit($hash_base))) { git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav); @@ -7207,6 +7208,27 @@ sub git_blobdiff_plain { git_blobdiff('plain'); } +# assumes that it is added as later part of already existing navigation, +# so it returns "| foo | bar" rather than just "foo | bar" +sub diff_style_nav { + my ($diff_style, $is_combined) = @_; + $diff_style ||= 'inline'; + + return "" if ($is_combined); + + my @styles = (inline => 'inline', 'sidebyside' => 'side by side'); + my %styles = @styles; + @styles = + @styles[ map { $_ * 2 } 0..$#styles/2 ]; + + return join '', + map { " | ".$_ } + map { + $_ eq $diff_style ? $styles{$_} : + $cgi->a({-href => href(-replay=>1, diff_style => $_)}, $styles{$_}) + } @styles; +} + sub git_commitdiff { my %params = @_; my $format = $params{-format} || 'html'; @@ -7236,6 +7258,7 @@ sub git_commitdiff { $cgi->a({-href => href(action=>"patch", -replay=>1)}, "patch"); } + $formats_nav .= diff_style_nav($diff_style, @{$co{'parents'}} > 1); if (defined $hash_parent && $hash_parent ne '-c' && $hash_parent ne '--cc') { -- 2.11.4.GIT