@matheusbsbs / matheus-bagliano / commits / 4a4a1a53d1
Fork 0

gitweb: Separate printing difftree in git_commit into git_difftree_body

Separate printing difftree in git_commit into separate git_difftree_body subroutine. Add support for "C" (copied) status. For "M" and "C" add parameter 'fp' (filename parent) to the "diff" link; currently not supported by git_blobdiff ("blobdiff" action). Reindented, realigned, added comments. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Aug 14, 2006 at 02:18 UTC 4a4a1a53d1c4a272d4cf0d53116896d057174671
2 files changed +146 -95
gitweb/gitweb.css
+4
@@ -226,6 +226,10 @@ table.diff_tree span.file_status.mode_chnge {
226 color: #777777;
227 }
228
229 +table.diff_tree span.file_status.copied {
230 + color: #70a070;
231 +}
232 +
233 /* age2: 60*60*24*2 <= age */
234 table.project_list td.age2, table.blame td.age2 {
235 font-style: italic;
gitweb/gitweb.perl
+142 -95
@@ -1136,6 +1136,145 @@ sub git_print_page_path {
1136 ## ......................................................................
1137 ## functions printing large fragments of HTML
1138
1139 +sub git_difftree_body {
1140 + my ($difftree, $parent) = @_;
1141 +
1142 + print "<div class=\"list_head\">\n";
1143 + if ($#{$difftree} > 10) {
1144 + print(($#{$difftree} + 1) . " files changed:\n");
1145 + }
1146 + print "</div>\n";
1147 +
1148 + print "<table class=\"diff_tree\">\n";
1149 + my $alternate = 0;
1150 + foreach my $line (@{$difftree}) {
1151 + # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1152 + # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1153 + if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1154 + next;
1155 + }
1156 + my $from_mode = $1;
1157 + my $to_mode = $2;
1158 + my $from_id = $3;
1159 + my $to_id = $4;
1160 + my $status = $5;
1161 + my $similarity = $6; # score
1162 + my $file = validate_input(unquote($7));
1163 +
1164 + if ($alternate) {
1165 + print "<tr class=\"dark\">\n";
1166 + } else {
1167 + print "<tr class=\"light\">\n";
1168 + }
1169 + $alternate ^= 1;
1170 +
1171 + if ($status eq "A") { # created
1172 + my $mode_chng = "";
1173 + if (S_ISREG(oct $to_mode)) {
1174 + $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1175 + }
1176 + print "<td>" .
1177 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"),
1178 + -class => "list"}, esc_html($file)) .
1179 + "</td>\n" .
1180 + "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1181 + "<td class=\"link\">" .
1182 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") .
1183 + "</td>\n";
1184 +
1185 + } elsif ($status eq "D") { # deleted
1186 + print "<td>" .
1187 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"),
1188 + -class => "list"}, esc_html($file)) . "</td>\n" .
1189 + "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1190 + "<td class=\"link\">" .
1191 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") . " | " .
1192 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$parent;f=$file")}, "history") .
1193 + "</td>\n"
1194 +
1195 + } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1196 + my $mode_chnge = "";
1197 + if ($from_mode != $to_mode) {
1198 + $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1199 + if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1200 + $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1201 + }
1202 + if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1203 + if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1204 + $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1205 + } elsif (S_ISREG($to_mode)) {
1206 + $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1207 + }
1208 + }
1209 + $mode_chnge .= "]</span>\n";
1210 + }
1211 + print "<td>";
1212 + if ($to_id ne $from_id) { # modified
1213 + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"),
1214 + -class => "list"}, esc_html($file));
1215 + } else { # mode changed
1216 + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"),
1217 + -class => "list"}, esc_html($file));
1218 + }
1219 + print "</td>\n" .
1220 + "<td>$mode_chnge</td>\n" .
1221 + "<td class=\"link\">" .
1222 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1223 + if ($to_id ne $from_id) { # modified
1224 + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1225 + }
1226 + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
1227 + print "</td>\n";
1228 +
1229 + } elsif ($status eq "R") { # renamed
1230 + my ($from_file, $to_file) = split "\t", $file;
1231 + my $mode_chng = "";
1232 + if ($from_mode != $to_mode) {
1233 + $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1234 + }
1235 + print "<td>" .
1236 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"),
1237 + -class => "list"}, esc_html($to_file)) . "</td>\n" .
1238 + "<td><span class=\"file_status moved\">[moved from " .
1239 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"),
1240 + -class => "list"}, esc_html($from_file)) .
1241 + " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1242 + "<td class=\"link\">" .
1243 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1244 + if ($to_id ne $from_id) {
1245 + print " | " .
1246 + $cgi->a({-href => "$my_uri?" .
1247 + esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1248 + }
1249 + print "</td>\n";
1250 +
1251 + } elsif ($status eq "C") { # copied
1252 + my ($from_file, $to_file) = split "\t", $file;
1253 + my $mode_chng = "";
1254 + if ($from_mode != $to_mode) {
1255 + $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1256 + }
1257 + print "<td>" .
1258 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"),
1259 + -class => "list"}, esc_html($to_file)) . "</td>\n" .
1260 + "<td><span class=\"file_status copied\">[copied from " .
1261 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"),
1262 + -class => "list"}, esc_html($from_file)) .
1263 + " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1264 + "<td class=\"link\">" .
1265 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1266 + if ($to_id ne $from_id) {
1267 + print " | " .
1268 + $cgi->a({-href => "$my_uri?" .
1269 + esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1270 + }
1271 + print "</td>\n";
1272 + } # we should not encounter Unmerged (U) or Unknown (X) status
1273 + print "</tr>\n";
1274 + }
1275 + print "</table>\n";
1276 +}
1277 +
1278 sub git_shortlog_body {
1279 # uses global variable $project
1280 my ($revlist, $from, $to, $refs, $extra) = @_;
@@ -2089,101 +2228,9 @@ sub git_commit {
2228 }
2229 }
2230 print "</div>\n";
2092 - print "<div class=\"list_head\">\n";
2093 - if ($#difftree > 10) {
2094 - print(($#difftree + 1) . " files changed:\n");
2095 - }
2096 - print "</div>\n";
2097 - print "<table class=\"diff_tree\">\n";
2098 - my $alternate = 0;
2099 - foreach my $line (@difftree) {
2100 - # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2101 - # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2102 - if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2103 - next;
2104 - }
2105 - my $from_mode = $1;
2106 - my $to_mode = $2;
2107 - my $from_id = $3;
2108 - my $to_id = $4;
2109 - my $status = $5;
2110 - my $similarity = $6;
2111 - my $file = validate_input(unquote($7));
2112 - if ($alternate) {
2113 - print "<tr class=\"dark\">\n";
2114 - } else {
2115 - print "<tr class=\"light\">\n";
2116 - }
2117 - $alternate ^= 1;
2118 - if ($status eq "A") {
2119 - my $mode_chng = "";
2120 - if (S_ISREG(oct $to_mode)) {
2121 - $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2122 - }
2123 - print "<td>" .
2124 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
2125 - "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
2126 - "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2127 - } elsif ($status eq "D") {
2128 - print "<td>" .
2129 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
2130 - "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
2131 - "<td class=\"link\">" .
2132 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") .
2133 - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$parent;f=$file")}, "history") .
2134 - "</td>\n"
2135 - } elsif ($status eq "M" || $status eq "T") {
2136 - my $mode_chnge = "";
2137 - if ($from_mode != $to_mode) {
2138 - $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2139 - if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
2140 - $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
2141 - }
2142 - if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2143 - if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
2144 - $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2145 - } elsif (S_ISREG($to_mode)) {
2146 - $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2147 - }
2148 - }
2149 - $mode_chnge .= "]</span>\n";
2150 - }
2151 - print "<td>";
2152 - if ($to_id ne $from_id) {
2153 - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2154 - } else {
2155 - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2156 - }
2157 - print "</td>\n" .
2158 - "<td>$mode_chnge</td>\n" .
2159 - "<td class=\"link\">";
2160 - print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2161 - if ($to_id ne $from_id) {
2162 - print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2163 - }
2164 - print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2165 - print "</td>\n";
2166 - } elsif ($status eq "R") {
2167 - my ($from_file, $to_file) = split "\t", $file;
2168 - my $mode_chng = "";
2169 - if ($from_mode != $to_mode) {
2170 - $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2171 - }
2172 - print "<td>" .
2173 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html($to_file)) . "</td>\n" .
2174 - "<td><span class=\"file_status moved\">[moved from " .
2175 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"), -class => "list"}, esc_html($from_file)) .
2176 - " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2177 - "<td class=\"link\">" .
2178 - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2179 - if ($to_id ne $from_id) {
2180 - print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2181 - }
2182 - print "</td>\n";
2183 - }
2184 - print "</tr>\n";
2185 - }
2186 - print "</table>\n";
2231 +
2232 + git_difftree_body(\@difftree, $parent);
2233 +
2234 git_footer_html();
2235 }
2236