gitweb: Make it possible to use pre-parsed info in git_difftree_body
Make it possible to use pre-parsed, or generated by hand, difftree info in git_difftree_body, similarly to how was and is it done in git_patchset_body. Use just introduced feature in git_commitdiff to parse difftree info (raw diff output) only once: difftree info is now parsed in git_commitdiff directly, and parsed information is passed to both git_difftree_body and git_patchset_body. (Till now only git_blobdiff made use of git_patchset_body ability to use pre-parsed or hand generated info.) Additionally this makes rename info for combined diff with renames (or copies) calculated only once in git_difftree_body; the $difftree is modified and git_patchset_body makes use of added info. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
e72c0eaf9b
commit
493e01db51
@ -2330,7 +2330,13 @@ sub git_difftree_body {
|
|||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
my $patchno = 0;
|
my $patchno = 0;
|
||||||
foreach my $line (@{$difftree}) {
|
foreach my $line (@{$difftree}) {
|
||||||
my %diff = parse_difftree_raw_line($line);
|
my $diff;
|
||||||
|
if (ref($line) eq "HASH") {
|
||||||
|
# pre-parsed (or generated by hand)
|
||||||
|
$diff = $line;
|
||||||
|
} else {
|
||||||
|
$diff = parse_difftree_raw_line($line);
|
||||||
|
}
|
||||||
|
|
||||||
if ($alternate) {
|
if ($alternate) {
|
||||||
print "<tr class=\"dark\">\n";
|
print "<tr class=\"dark\">\n";
|
||||||
@ -2339,21 +2345,22 @@ sub git_difftree_body {
|
|||||||
}
|
}
|
||||||
$alternate ^= 1;
|
$alternate ^= 1;
|
||||||
|
|
||||||
if (exists $diff{'nparents'}) { # combined diff
|
if (exists $diff->{'nparents'}) { # combined diff
|
||||||
|
|
||||||
fill_from_file_info(\%diff, @parents);
|
fill_from_file_info($diff, @parents)
|
||||||
|
unless exists $diff->{'from_file'};
|
||||||
|
|
||||||
if ($diff{'to_id'} ne ('0' x 40)) {
|
if ($diff->{'to_id'} ne ('0' x 40)) {
|
||||||
# file exists in the result (child) commit
|
# file exists in the result (child) commit
|
||||||
print "<td>" .
|
print "<td>" .
|
||||||
$cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
$cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
file_name=>$diff{'to_file'},
|
file_name=>$diff->{'to_file'},
|
||||||
hash_base=>$hash),
|
hash_base=>$hash),
|
||||||
-class => "list"}, esc_path($diff{'to_file'})) .
|
-class => "list"}, esc_path($diff->{'to_file'})) .
|
||||||
"</td>\n";
|
"</td>\n";
|
||||||
} else {
|
} else {
|
||||||
print "<td>" .
|
print "<td>" .
|
||||||
esc_path($diff{'to_file'}) .
|
esc_path($diff->{'to_file'}) .
|
||||||
"</td>\n";
|
"</td>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2368,11 +2375,11 @@ sub git_difftree_body {
|
|||||||
|
|
||||||
my $has_history = 0;
|
my $has_history = 0;
|
||||||
my $not_deleted = 0;
|
my $not_deleted = 0;
|
||||||
for (my $i = 0; $i < $diff{'nparents'}; $i++) {
|
for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
|
||||||
my $hash_parent = $parents[$i];
|
my $hash_parent = $parents[$i];
|
||||||
my $from_hash = $diff{'from_id'}[$i];
|
my $from_hash = $diff->{'from_id'}[$i];
|
||||||
my $from_path = $diff{'from_file'}[$i];
|
my $from_path = $diff->{'from_file'}[$i];
|
||||||
my $status = $diff{'status'}[$i];
|
my $status = $diff->{'status'}[$i];
|
||||||
|
|
||||||
$has_history ||= ($status ne 'A');
|
$has_history ||= ($status ne 'A');
|
||||||
$not_deleted ||= ($status ne 'D');
|
$not_deleted ||= ($status ne 'D');
|
||||||
@ -2388,17 +2395,17 @@ sub git_difftree_body {
|
|||||||
"blob" . ($i+1)) .
|
"blob" . ($i+1)) .
|
||||||
" | </td>\n";
|
" | </td>\n";
|
||||||
} else {
|
} else {
|
||||||
if ($diff{'to_id'} eq $from_hash) {
|
if ($diff->{'to_id'} eq $from_hash) {
|
||||||
print "<td class=\"link nochange\">";
|
print "<td class=\"link nochange\">";
|
||||||
} else {
|
} else {
|
||||||
print "<td class=\"link\">";
|
print "<td class=\"link\">";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"blobdiff",
|
print $cgi->a({-href => href(action=>"blobdiff",
|
||||||
hash=>$diff{'to_id'},
|
hash=>$diff->{'to_id'},
|
||||||
hash_parent=>$from_hash,
|
hash_parent=>$from_hash,
|
||||||
hash_base=>$hash,
|
hash_base=>$hash,
|
||||||
hash_parent_base=>$hash_parent,
|
hash_parent_base=>$hash_parent,
|
||||||
file_name=>$diff{'to_file'},
|
file_name=>$diff->{'to_file'},
|
||||||
file_parent=>$from_path)},
|
file_parent=>$from_path)},
|
||||||
"diff" . ($i+1)) .
|
"diff" . ($i+1)) .
|
||||||
" | </td>\n";
|
" | </td>\n";
|
||||||
@ -2408,15 +2415,15 @@ sub git_difftree_body {
|
|||||||
print "<td class=\"link\">";
|
print "<td class=\"link\">";
|
||||||
if ($not_deleted) {
|
if ($not_deleted) {
|
||||||
print $cgi->a({-href => href(action=>"blob",
|
print $cgi->a({-href => href(action=>"blob",
|
||||||
hash=>$diff{'to_id'},
|
hash=>$diff->{'to_id'},
|
||||||
file_name=>$diff{'to_file'},
|
file_name=>$diff->{'to_file'},
|
||||||
hash_base=>$hash)},
|
hash_base=>$hash)},
|
||||||
"blob");
|
"blob");
|
||||||
print " | " if ($has_history);
|
print " | " if ($has_history);
|
||||||
}
|
}
|
||||||
if ($has_history) {
|
if ($has_history) {
|
||||||
print $cgi->a({-href => href(action=>"history",
|
print $cgi->a({-href => href(action=>"history",
|
||||||
file_name=>$diff{'to_file'},
|
file_name=>$diff->{'to_file'},
|
||||||
hash_base=>$hash)},
|
hash_base=>$hash)},
|
||||||
"history");
|
"history");
|
||||||
}
|
}
|
||||||
@ -2429,29 +2436,29 @@ sub git_difftree_body {
|
|||||||
|
|
||||||
my ($to_mode_oct, $to_mode_str, $to_file_type);
|
my ($to_mode_oct, $to_mode_str, $to_file_type);
|
||||||
my ($from_mode_oct, $from_mode_str, $from_file_type);
|
my ($from_mode_oct, $from_mode_str, $from_file_type);
|
||||||
if ($diff{'to_mode'} ne ('0' x 6)) {
|
if ($diff->{'to_mode'} ne ('0' x 6)) {
|
||||||
$to_mode_oct = oct $diff{'to_mode'};
|
$to_mode_oct = oct $diff->{'to_mode'};
|
||||||
if (S_ISREG($to_mode_oct)) { # only for regular file
|
if (S_ISREG($to_mode_oct)) { # only for regular file
|
||||||
$to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
|
$to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
|
||||||
}
|
}
|
||||||
$to_file_type = file_type($diff{'to_mode'});
|
$to_file_type = file_type($diff->{'to_mode'});
|
||||||
}
|
}
|
||||||
if ($diff{'from_mode'} ne ('0' x 6)) {
|
if ($diff->{'from_mode'} ne ('0' x 6)) {
|
||||||
$from_mode_oct = oct $diff{'from_mode'};
|
$from_mode_oct = oct $diff->{'from_mode'};
|
||||||
if (S_ISREG($to_mode_oct)) { # only for regular file
|
if (S_ISREG($to_mode_oct)) { # only for regular file
|
||||||
$from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
|
$from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
|
||||||
}
|
}
|
||||||
$from_file_type = file_type($diff{'from_mode'});
|
$from_file_type = file_type($diff->{'from_mode'});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($diff{'status'} eq "A") { # created
|
if ($diff->{'status'} eq "A") { # created
|
||||||
my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
|
my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
|
||||||
$mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
|
$mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
|
||||||
$mode_chng .= "]</span>";
|
$mode_chng .= "]</span>";
|
||||||
print "<td>";
|
print "<td>";
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
hash_base=>$hash, file_name=>$diff{'file'}),
|
hash_base=>$hash, file_name=>$diff->{'file'}),
|
||||||
-class => "list"}, esc_path($diff{'file'}));
|
-class => "list"}, esc_path($diff->{'file'}));
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print "<td>$mode_chng</td>\n";
|
print "<td>$mode_chng</td>\n";
|
||||||
print "<td class=\"link\">";
|
print "<td class=\"link\">";
|
||||||
@ -2461,17 +2468,17 @@ sub git_difftree_body {
|
|||||||
print $cgi->a({-href => "#patch$patchno"}, "patch");
|
print $cgi->a({-href => "#patch$patchno"}, "patch");
|
||||||
print " | ";
|
print " | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
hash_base=>$hash, file_name=>$diff{'file'})},
|
hash_base=>$hash, file_name=>$diff->{'file'})},
|
||||||
"blob");
|
"blob");
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
} elsif ($diff{'status'} eq "D") { # deleted
|
} elsif ($diff->{'status'} eq "D") { # deleted
|
||||||
my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
|
my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
|
||||||
print "<td>";
|
print "<td>";
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
|
||||||
hash_base=>$parent, file_name=>$diff{'file'}),
|
hash_base=>$parent, file_name=>$diff->{'file'}),
|
||||||
-class => "list"}, esc_path($diff{'file'}));
|
-class => "list"}, esc_path($diff->{'file'}));
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print "<td>$mode_chng</td>\n";
|
print "<td>$mode_chng</td>\n";
|
||||||
print "<td class=\"link\">";
|
print "<td class=\"link\">";
|
||||||
@ -2481,22 +2488,22 @@ sub git_difftree_body {
|
|||||||
print $cgi->a({-href => "#patch$patchno"}, "patch");
|
print $cgi->a({-href => "#patch$patchno"}, "patch");
|
||||||
print " | ";
|
print " | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
|
||||||
hash_base=>$parent, file_name=>$diff{'file'})},
|
hash_base=>$parent, file_name=>$diff->{'file'})},
|
||||||
"blob") . " | ";
|
"blob") . " | ";
|
||||||
if ($have_blame) {
|
if ($have_blame) {
|
||||||
print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
|
print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
|
||||||
file_name=>$diff{'file'})},
|
file_name=>$diff->{'file'})},
|
||||||
"blame") . " | ";
|
"blame") . " | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
|
print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
|
||||||
file_name=>$diff{'file'})},
|
file_name=>$diff->{'file'})},
|
||||||
"history");
|
"history");
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
} elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
|
} elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
|
||||||
my $mode_chnge = "";
|
my $mode_chnge = "";
|
||||||
if ($diff{'from_mode'} != $diff{'to_mode'}) {
|
if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
|
||||||
$mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
|
$mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
|
||||||
if ($from_file_type ne $to_file_type) {
|
if ($from_file_type ne $to_file_type) {
|
||||||
$mode_chnge .= " from $from_file_type to $to_file_type";
|
$mode_chnge .= " from $from_file_type to $to_file_type";
|
||||||
@ -2511,9 +2518,9 @@ sub git_difftree_body {
|
|||||||
$mode_chnge .= "]</span>\n";
|
$mode_chnge .= "]</span>\n";
|
||||||
}
|
}
|
||||||
print "<td>";
|
print "<td>";
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
hash_base=>$hash, file_name=>$diff{'file'}),
|
hash_base=>$hash, file_name=>$diff->{'file'}),
|
||||||
-class => "list"}, esc_path($diff{'file'}));
|
-class => "list"}, esc_path($diff->{'file'}));
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print "<td>$mode_chnge</td>\n";
|
print "<td>$mode_chnge</td>\n";
|
||||||
print "<td class=\"link\">";
|
print "<td class=\"link\">";
|
||||||
@ -2522,70 +2529,70 @@ sub git_difftree_body {
|
|||||||
$patchno++;
|
$patchno++;
|
||||||
print $cgi->a({-href => "#patch$patchno"}, "patch") .
|
print $cgi->a({-href => "#patch$patchno"}, "patch") .
|
||||||
" | ";
|
" | ";
|
||||||
} elsif ($diff{'to_id'} ne $diff{'from_id'}) {
|
} elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
|
||||||
# "commit" view and modified file (not onlu mode changed)
|
# "commit" view and modified file (not onlu mode changed)
|
||||||
print $cgi->a({-href => href(action=>"blobdiff",
|
print $cgi->a({-href => href(action=>"blobdiff",
|
||||||
hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
|
hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
|
||||||
hash_base=>$hash, hash_parent_base=>$parent,
|
hash_base=>$hash, hash_parent_base=>$parent,
|
||||||
file_name=>$diff{'file'})},
|
file_name=>$diff->{'file'})},
|
||||||
"diff") .
|
"diff") .
|
||||||
" | ";
|
" | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
hash_base=>$hash, file_name=>$diff{'file'})},
|
hash_base=>$hash, file_name=>$diff->{'file'})},
|
||||||
"blob") . " | ";
|
"blob") . " | ";
|
||||||
if ($have_blame) {
|
if ($have_blame) {
|
||||||
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
|
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
|
||||||
file_name=>$diff{'file'})},
|
file_name=>$diff->{'file'})},
|
||||||
"blame") . " | ";
|
"blame") . " | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
|
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
|
||||||
file_name=>$diff{'file'})},
|
file_name=>$diff->{'file'})},
|
||||||
"history");
|
"history");
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
} elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
|
} elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
|
||||||
my %status_name = ('R' => 'moved', 'C' => 'copied');
|
my %status_name = ('R' => 'moved', 'C' => 'copied');
|
||||||
my $nstatus = $status_name{$diff{'status'}};
|
my $nstatus = $status_name{$diff->{'status'}};
|
||||||
my $mode_chng = "";
|
my $mode_chng = "";
|
||||||
if ($diff{'from_mode'} != $diff{'to_mode'}) {
|
if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
|
||||||
# mode also for directories, so we cannot use $to_mode_str
|
# mode also for directories, so we cannot use $to_mode_str
|
||||||
$mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
|
$mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
|
||||||
}
|
}
|
||||||
print "<td>" .
|
print "<td>" .
|
||||||
$cgi->a({-href => href(action=>"blob", hash_base=>$hash,
|
$cgi->a({-href => href(action=>"blob", hash_base=>$hash,
|
||||||
hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
|
hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
|
||||||
-class => "list"}, esc_path($diff{'to_file'})) . "</td>\n" .
|
-class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
|
||||||
"<td><span class=\"file_status $nstatus\">[$nstatus from " .
|
"<td><span class=\"file_status $nstatus\">[$nstatus from " .
|
||||||
$cgi->a({-href => href(action=>"blob", hash_base=>$parent,
|
$cgi->a({-href => href(action=>"blob", hash_base=>$parent,
|
||||||
hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
|
hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
|
||||||
-class => "list"}, esc_path($diff{'from_file'})) .
|
-class => "list"}, esc_path($diff->{'from_file'})) .
|
||||||
" with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
|
" with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
|
||||||
"<td class=\"link\">";
|
"<td class=\"link\">";
|
||||||
if ($action eq 'commitdiff') {
|
if ($action eq 'commitdiff') {
|
||||||
# link to patch
|
# link to patch
|
||||||
$patchno++;
|
$patchno++;
|
||||||
print $cgi->a({-href => "#patch$patchno"}, "patch") .
|
print $cgi->a({-href => "#patch$patchno"}, "patch") .
|
||||||
" | ";
|
" | ";
|
||||||
} elsif ($diff{'to_id'} ne $diff{'from_id'}) {
|
} elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
|
||||||
# "commit" view and modified file (not only pure rename or copy)
|
# "commit" view and modified file (not only pure rename or copy)
|
||||||
print $cgi->a({-href => href(action=>"blobdiff",
|
print $cgi->a({-href => href(action=>"blobdiff",
|
||||||
hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
|
hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
|
||||||
hash_base=>$hash, hash_parent_base=>$parent,
|
hash_base=>$hash, hash_parent_base=>$parent,
|
||||||
file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
|
file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
|
||||||
"diff") .
|
"diff") .
|
||||||
" | ";
|
" | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
|
print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
|
||||||
hash_base=>$parent, file_name=>$diff{'to_file'})},
|
hash_base=>$parent, file_name=>$diff->{'to_file'})},
|
||||||
"blob") . " | ";
|
"blob") . " | ";
|
||||||
if ($have_blame) {
|
if ($have_blame) {
|
||||||
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
|
print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
|
||||||
file_name=>$diff{'to_file'})},
|
file_name=>$diff->{'to_file'})},
|
||||||
"blame") . " | ";
|
"blame") . " | ";
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
|
print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
|
||||||
file_name=>$diff{'to_file'})},
|
file_name=>$diff->{'to_file'})},
|
||||||
"history");
|
"history");
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
@ -4401,7 +4408,7 @@ sub git_commitdiff {
|
|||||||
chomp $line;
|
chomp $line;
|
||||||
# empty line ends raw part of diff-tree output
|
# empty line ends raw part of diff-tree output
|
||||||
last unless $line;
|
last unless $line;
|
||||||
push @difftree, $line;
|
push @difftree, scalar parse_difftree_raw_line($line);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif ($format eq 'plain') {
|
} elsif ($format eq 'plain') {
|
||||||
|
Loading…
Reference in New Issue
Block a user