Skip to content

Commit 6ae683c

Browse files
kzysgitster
authored andcommitted
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 / compact combined diff. Signed-off-by: Kato Kazuyoshi <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0e6e29 commit 6ae683c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

gitweb/gitweb.perl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7164,6 +7164,7 @@ sub git_blobdiff {
71647164
my $formats_nav =
71657165
$cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
71667166
"raw");
7167+
$formats_nav .= diff_style_nav($diff_style);
71677168
git_header_html(undef, $expires);
71687169
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
71697170
git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
@@ -7221,6 +7222,27 @@ sub git_blobdiff_plain {
72217222
git_blobdiff('plain');
72227223
}
72237224

7225+
# assumes that it is added as later part of already existing navigation,
7226+
# so it returns "| foo | bar" rather than just "foo | bar"
7227+
sub diff_style_nav {
7228+
my ($diff_style, $is_combined) = @_;
7229+
$diff_style ||= 'inline';
7230+
7231+
return "" if ($is_combined);
7232+
7233+
my @styles = (inline => 'inline', 'sidebyside' => 'side by side');
7234+
my %styles = @styles;
7235+
@styles =
7236+
@styles[ map { $_ * 2 } 0..$#styles/2 ];
7237+
7238+
return join '',
7239+
map { " | ".$_ }
7240+
map {
7241+
$_ eq $diff_style ? $styles{$_} :
7242+
$cgi->a({-href => href(-replay=>1, diff_style => $_)}, $styles{$_})
7243+
} @styles;
7244+
}
7245+
72247246
sub git_commitdiff {
72257247
my %params = @_;
72267248
my $format = $params{-format} || 'html';
@@ -7250,6 +7272,7 @@ sub git_commitdiff {
72507272
$cgi->a({-href => href(action=>"patch", -replay=>1)},
72517273
"patch");
72527274
}
7275+
$formats_nav .= diff_style_nav($diff_style, @{$co{'parents'}} > 1);
72537276

72547277
if (defined $hash_parent &&
72557278
$hash_parent ne '-c' && $hash_parent ne '--cc') {

0 commit comments

Comments
 (0)