@matheusbsbs / matheus-bagliano / commits / b4657e7759
Fork 0

gitweb: Add diff tree, with links to patches, to commitdiff view

Added/uncommented git_difftree_body invocation in git_commitdiff. Added anchors (via 'id' attribute) to patches in patchset. git_difftree_body is modified to link to patch anchor when called from git_commitdiff, instead of link to blobdiff. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Aug 28, 2006 at 14:48 UTC b4657e7759fa5f3b1ef09d147c2fd0254f8fcb2d
1 file changed +49 -22
gitweb/gitweb.perl
+49 -22
@@ -1460,6 +1460,7 @@ sub git_difftree_body {
1460
1461 print "<table class=\"diff_tree\">\n";
1462 my $alternate = 0;
1463 + my $patchno = 0;
1464 foreach my $line (@{$difftree}) {
1465 my %diff = parse_difftree_raw_line($line);
1466
@@ -1500,8 +1501,14 @@ sub git_difftree_body {
1501 "<td class=\"link\">" .
1502 $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1503 hash_base=>$hash, file_name=>$diff{'file'})},
1503 - "blob") .
1504 - "</td>\n";
1504 + "blob");
1505 + if ($action == "commitdiff") {
1506 + # link to patch
1507 + $patchno++;
1508 + print " | " .
1509 + $cgi->a({-href => "#patch$patchno"}, "patch");
1510 + }
1511 + print "</td>\n";
1512
1513 } elsif ($diff{'status'} eq "D") { # deleted
1514 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
@@ -1515,8 +1522,14 @@ sub git_difftree_body {
1522 $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
1523 hash_base=>$parent, file_name=>$diff{'file'})},
1524 "blob") .
1518 - " | " .
1519 - $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1525 + " | ";
1526 + if ($action == "commitdiff") {
1527 + # link to patch
1528 + $patchno++;
1529 + print " | " .
1530 + $cgi->a({-href => "#patch$patchno"}, "patch");
1531 + }
1532 + print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
1533 file_name=>$diff{'file'})},
1534 "history") .
1535 "</td>\n";
@@ -1552,16 +1565,23 @@ sub git_difftree_body {
1565 print "</td>\n" .
1566 "<td>$mode_chnge</td>\n" .
1567 "<td class=\"link\">" .
1555 - $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1556 - hash_base=>$hash, file_name=>$diff{'file'})},
1557 - "blob");
1568 + $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
1569 + hash_base=>$hash, file_name=>$diff{'file'})},
1570 + "blob");
1571 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1559 - print " | " .
1560 - $cgi->a({-href => href(action=>"blobdiff",
1561 - hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1562 - hash_base=>$hash, hash_parent_base=>$parent,
1563 - file_name=>$diff{'file'})},
1564 - "diff");
1572 + if ($action == "commitdiff") {
1573 + # link to patch
1574 + $patchno++;
1575 + print " | " .
1576 + $cgi->a({-href => "#patch$patchno"}, "patch");
1577 + } else {
1578 + print " | " .
1579 + $cgi->a({-href => href(action=>"blobdiff",
1580 + hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1581 + hash_base=>$hash, hash_parent_base=>$parent,
1582 + file_name=>$diff{'file'})},
1583 + "diff");
1584 + }
1585 }
1586 print " | " .
1587 $cgi->a({-href => href(action=>"history",
@@ -1591,12 +1611,19 @@ sub git_difftree_body {
1611 hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
1612 "blob");
1613 if ($diff{'to_id'} ne $diff{'from_id'}) {
1594 - print " | " .
1595 - $cgi->a({-href => href(action=>"blobdiff",
1596 - hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1597 - hash_base=>$hash, hash_parent_base=>$parent,
1598 - file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1599 - "diff");
1614 + if ($action == "commitdiff") {
1615 + # link to patch
1616 + $patchno++;
1617 + print " | " .
1618 + $cgi->a({-href => "#patch$patchno"}, "patch");
1619 + } else {
1620 + print " | " .
1621 + $cgi->a({-href => href(action=>"blobdiff",
1622 + hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
1623 + hash_base=>$hash, hash_parent_base=>$parent,
1624 + file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
1625 + "diff");
1626 + }
1627 }
1628 print "</td>\n";
1629
@@ -1629,7 +1656,7 @@ sub git_patchset_body {
1656 # first patch in patchset
1657 $patch_found = 1;
1658 }
1632 - print "<div class=\"patch\">\n";
1659 + print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1660
1661 if (ref($difftree->[$patch_idx]) eq "HASH") {
1662 $diffinfo = $difftree->[$patch_idx];
@@ -2977,8 +3004,8 @@ TEXT
3004
3005 # write patch
3006 if ($format eq 'html') {
2980 - #git_difftree_body(\@difftree, $hash, $hash_parent);
2981 - #print "<br/>\n";
3007 + git_difftree_body(\@difftree, $hash, $hash_parent);
3008 + print "<br/>\n";
3009
3010 git_patchset_body($fd, \@difftree, $hash, $hash_parent);
3011 close $fd;