{"thread":{"id":"9651","subject":"[PATCH 2/4] gitweb: support filename prefix in git_patchset_body/git_difftree_body","startedAt":"2007-08-26T15:29:55Z","lastAt":"2007-08-26T15:29:55Z","messageCount":1,"participants":["Martin Koegler"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"51561","messageId":"11881421953009-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"9651","inReplyTo":null,"subject":"[PATCH 2/4] gitweb: support filename prefix in git_patchset_body/git_difftree_body","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2007-08-26T15:29:55Z","receivedAt":"2007-08-26T15:29:55Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"git_treediff supports comparing subdirectories. As the output of\ngit-difftree is missing the path to the compared directories,\nthe links in the output would be wrong.\n\nThe patch adds two new parameters to add the missing path prefix.\n\nSigned-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\nThis is an updated version. Please use this version\nfor repo.or.cz instead of the old one.\n\nI don't resend the rest of the series, as they are unchanged.\n\n gitweb/gitweb.perl |   88 +++++++++++++++++++++++++++++----------------------\n 1 files changed, 50 insertions(+), 38 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 90b90e8..c09ff9f 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1176,10 +1176,10 @@ sub format_diff_from_to_header {\n \t\t\t\t        $cgi->a({-href=>href(action=>\"blobdiff\",\n \t\t\t\t                             hash_parent=>$diffinfo->{'from_id'}[$i],\n \t\t\t\t                             hash_parent_base=>$parents[$i],\n-\t\t\t\t                             file_parent=>$from->{'file'}[$i],\n+\t\t\t\t                             file_parent=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i],\n \t\t\t\t                             hash=>$diffinfo->{'to_id'},\n \t\t\t\t                             hash_base=>$hash,\n-\t\t\t\t                             file_name=>$to->{'file'}),\n+\t\t\t\t                             file_name=>$diffinfo->{'to_prefix'}.$to->{'file'}),\n \t\t\t\t                 -class=>\"path\",\n \t\t\t\t                 -title=>\"diff\" . ($i+1)},\n \t\t\t\t                $i+1) .\n@@ -1222,7 +1222,7 @@ sub format_diff_cc_simplified {\n \t\t$result .= $cgi->a({-href => href(action=>\"blob\",\n \t\t                                  hash_base=>$hash,\n \t\t                                  hash=>$diffinfo->{'to_id'},\n-\t\t                                  file_name=>$diffinfo->{'to_file'}),\n+\t\t                                  file_name=>$diffinfo->{'to_prefix'}.$diffinfo->{'to_file'}),\n \t\t                    -class => \"path\"},\n \t\t                   esc_path($diffinfo->{'to_file'}));\n \t} else {\n@@ -2030,7 +2030,7 @@ sub parse_from_to_diffinfo {\n \t\t\t\t$from->{'href'}[$i] = href(action=>\"blob\",\n \t\t\t\t                           hash_base=>$parents[$i],\n \t\t\t\t                           hash=>$diffinfo->{'from_id'}[$i],\n-\t\t\t\t                           file_name=>$from->{'file'}[$i]);\n+\t\t\t\t                           file_name=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i]);\n \t\t\t} else {\n \t\t\t\t$from->{'href'}[$i] = undef;\n \t\t\t}\n@@ -2040,7 +2040,7 @@ sub parse_from_to_diffinfo {\n \t\tif ($diffinfo->{'status'} ne \"A\") { # not new (added) file\n \t\t\t$from->{'href'} = href(action=>\"blob\", hash_base=>$hash_parent,\n \t\t\t                       hash=>$diffinfo->{'from_id'},\n-\t\t\t                       file_name=>$from->{'file'});\n+\t\t\t                       file_name=>$diffinfo->{'from_prefix'}.$from->{'file'});\n \t\t} else {\n \t\t\tdelete $from->{'href'};\n \t\t}\n@@ -2050,7 +2050,7 @@ sub parse_from_to_diffinfo {\n \tif (!is_deleted($diffinfo)) { # file exists in result\n \t\t$to->{'href'} = href(action=>\"blob\", hash_base=>$hash,\n \t\t                     hash=>$diffinfo->{'to_id'},\n-\t\t                     file_name=>$to->{'file'});\n+\t\t                     file_name=>$diffinfo->{'to_prefix'}.$to->{'file'});\n \t} else {\n \t\tdelete $to->{'href'};\n \t}\n@@ -2798,9 +2798,13 @@ sub is_deleted {\n }\n \n sub git_difftree_body {\n-\tmy ($difftree, $hash, @parents) = @_;\n+\tmy ($difftree, $from_prefix, $to_prefix, $hash, @parents) = @_;\n \tmy ($parent) = $parents[0];\n \tmy ($have_blame) = gitweb_check_feature('blame');\n+\n+\t$from_prefix = !defined $from_prefix ? '' : $from_prefix.'/';\n+\t$to_prefix   = !defined $to_prefix   ? '' : $to_prefix . '/';\n+\n \tprint \"<div class=\\\"list_head\\\">\\n\";\n \tif ($#{$difftree} > 10) {\n \t\tprint(($#{$difftree} + 1) . \" files changed:\\n\");\n@@ -2857,7 +2861,7 @@ sub git_difftree_body {\n \t\t\t\t# file exists in the result (child) commit\n \t\t\t\tprint \"<td>\" .\n \t\t\t\t      $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t\t                             file_name=>$diff->{'to_file'},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'},\n \t\t\t\t                             hash_base=>$hash),\n \t\t\t\t              -class => \"list\"}, esc_path($diff->{'to_file'})) .\n \t\t\t\t      \"</td>\\n\";\n@@ -2894,7 +2898,7 @@ sub git_difftree_body {\n \t\t\t\t\t      $cgi->a({-href => href(action=>\"blob\",\n \t\t\t\t\t                             hash_base=>$hash,\n \t\t\t\t\t                             hash=>$from_hash,\n-\t\t\t\t\t                             file_name=>$from_path)},\n+\t\t\t\t\t                             file_name=>$from_prefix.$from_path)},\n \t\t\t\t\t              \"blob\" . ($i+1)) .\n \t\t\t\t\t      \" | </td>\\n\";\n \t\t\t\t} else {\n@@ -2908,8 +2912,8 @@ sub git_difftree_body {\n \t\t\t\t\t                             hash_parent=>$from_hash,\n \t\t\t\t\t                             hash_base=>$hash,\n \t\t\t\t\t                             hash_parent_base=>$hash_parent,\n-\t\t\t\t\t                             file_name=>$diff->{'to_file'},\n-\t\t\t\t\t                             file_parent=>$from_path)},\n+\t\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'},\n+\t\t\t\t\t                             file_parent=>$from_prefix.$from_path)},\n \t\t\t\t\t              \"diff\" . ($i+1)) .\n \t\t\t\t\t      \" | </td>\\n\";\n \t\t\t\t}\n@@ -2919,14 +2923,14 @@ sub git_difftree_body {\n \t\t\tif ($not_deleted) {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blob\",\n \t\t\t\t                             hash=>$diff->{'to_id'},\n-\t\t\t\t                             file_name=>$diff->{'to_file'},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'},\n \t\t\t\t                             hash_base=>$hash)},\n \t\t\t\t              \"blob\");\n \t\t\t\tprint \" | \" if ($has_history);\n \t\t\t}\n \t\t\tif ($has_history) {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"history\",\n-\t\t\t\t                             file_name=>$diff->{'to_file'},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'},\n \t\t\t\t                             hash_base=>$hash)},\n \t\t\t\t              \"history\");\n \t\t\t}\n@@ -2960,7 +2964,7 @@ sub git_difftree_body {\n \t\t\t$mode_chng   .= \"]</span>\";\n \t\t\tprint \"<td>\";\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t                             hash_base=>$hash, file_name=>$diff->{'file'}),\n+\t\t\t                             hash_base=>$hash, file_name=>$to_prefix.$diff->{'file'}),\n \t\t\t              -class => \"list\"}, esc_path($diff->{'file'}));\n \t\t\tprint \"</td>\\n\";\n \t\t\tprint \"<td>$mode_chng</td>\\n\";\n@@ -2972,7 +2976,7 @@ sub git_difftree_body {\n \t\t\t\tprint \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t                             hash_base=>$hash, file_name=>$diff->{'file'})},\n+\t\t\t                             hash_base=>$hash, file_name=>$to_prefix.$diff->{'file'})},\n \t\t\t              \"blob\");\n \t\t\tprint \"</td>\\n\";\n \n@@ -2980,7 +2984,7 @@ sub git_difftree_body {\n \t\t\tmy $mode_chng = \"<span class=\\\"file_status deleted\\\">[deleted $from_file_type]</span>\";\n \t\t\tprint \"<td>\";\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'from_id'},\n-\t\t\t                             hash_base=>$parent, file_name=>$diff->{'file'}),\n+\t\t\t                             hash_base=>$parent, file_name=>$from_prefix.$diff->{'file'}),\n \t\t\t               -class => \"list\"}, esc_path($diff->{'file'}));\n \t\t\tprint \"</td>\\n\";\n \t\t\tprint \"<td>$mode_chng</td>\\n\";\n@@ -2992,15 +2996,15 @@ sub git_difftree_body {\n \t\t\t\tprint \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'from_id'},\n-\t\t\t                             hash_base=>$parent, file_name=>$diff->{'file'})},\n+\t\t\t                             hash_base=>$parent, file_name=>$from_prefix.$diff->{'file'})},\n \t\t\t              \"blob\") . \" | \";\n \t\t\tif ($have_blame) {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blame\", hash_base=>$parent,\n-\t\t\t\t                             file_name=>$diff->{'file'})},\n+\t\t\t\t                             file_name=>$from_prefix.$diff->{'file'})},\n \t\t\t\t              \"blame\") . \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"history\", hash_base=>$parent,\n-\t\t\t                             file_name=>$diff->{'file'})},\n+\t\t\t                             file_name=>$from_prefix.$diff->{'file'})},\n \t\t\t              \"history\");\n \t\t\tprint \"</td>\\n\";\n \n@@ -3022,7 +3026,7 @@ sub git_difftree_body {\n \t\t\t}\n \t\t\tprint \"<td>\";\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t                             hash_base=>$hash, file_name=>$diff->{'file'}),\n+\t\t\t                             hash_base=>$hash, file_name=>$to_prefix.$diff->{'file'}),\n \t\t\t              -class => \"list\"}, esc_path($diff->{'file'}));\n \t\t\tprint \"</td>\\n\";\n \t\t\tprint \"<td>$mode_chnge</td>\\n\";\n@@ -3037,20 +3041,21 @@ sub git_difftree_body {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blobdiff\",\n \t\t\t\t                             hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},\n \t\t\t\t                             hash_base=>$hash, hash_parent_base=>$parent,\n-\t\t\t\t                             file_name=>$diff->{'file'})},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'file'},\n+\t\t\t\t                             file_parent=>$from_prefix.$diff->{'file'})},\n \t\t\t\t              \"diff\") .\n \t\t\t\t      \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t                             hash_base=>$hash, file_name=>$diff->{'file'})},\n+\t\t\t                             hash_base=>$hash, file_name=>$to_prefix.$diff->{'file'})},\n \t\t\t               \"blob\") . \" | \";\n \t\t\tif ($have_blame) {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blame\", hash_base=>$hash,\n-\t\t\t\t                             file_name=>$diff->{'file'})},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'file'})},\n \t\t\t\t              \"blame\") . \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"history\", hash_base=>$hash,\n-\t\t\t                             file_name=>$diff->{'file'})},\n+\t\t\t                             file_name=>$to_prefix.$diff->{'file'})},\n \t\t\t              \"history\");\n \t\t\tprint \"</td>\\n\";\n \n@@ -3064,11 +3069,11 @@ sub git_difftree_body {\n \t\t\t}\n \t\t\tprint \"<td>\" .\n \t\t\t      $cgi->a({-href => href(action=>\"blob\", hash_base=>$hash,\n-\t\t\t                             hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),\n+\t\t\t                             hash=>$diff->{'to_id'}, file_name=>$to_prefix.$diff->{'to_file'}),\n \t\t\t              -class => \"list\"}, esc_path($diff->{'to_file'})) . \"</td>\\n\" .\n \t\t\t      \"<td><span class=\\\"file_status $nstatus\\\">[$nstatus from \" .\n \t\t\t      $cgi->a({-href => href(action=>\"blob\", hash_base=>$parent,\n-\t\t\t                             hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),\n+\t\t\t                             hash=>$diff->{'from_id'}, file_name=>$from_prefix.$diff->{'from_file'}),\n \t\t\t              -class => \"list\"}, esc_path($diff->{'from_file'})) .\n \t\t\t      \" with \" . (int $diff->{'similarity'}) . \"% similarity$mode_chng]</span></td>\\n\" .\n \t\t\t      \"<td class=\\\"link\\\">\";\n@@ -3082,20 +3087,20 @@ sub git_difftree_body {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blobdiff\",\n \t\t\t\t                             hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},\n \t\t\t\t                             hash_base=>$hash, hash_parent_base=>$parent,\n-\t\t\t\t                             file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'}, file_parent=>$from_prefix.$diff->{'from_file'})},\n \t\t\t\t              \"diff\") .\n \t\t\t\t      \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"blob\", hash=>$diff->{'to_id'},\n-\t\t\t                             hash_base=>$parent, file_name=>$diff->{'to_file'})},\n+\t\t\t                             hash_base=>$parent, file_name=>$to_prefix.$diff->{'to_file'})},\n \t\t\t              \"blob\") . \" | \";\n \t\t\tif ($have_blame) {\n \t\t\t\tprint $cgi->a({-href => href(action=>\"blame\", hash_base=>$hash,\n-\t\t\t\t                             file_name=>$diff->{'to_file'})},\n+\t\t\t\t                             file_name=>$to_prefix.$diff->{'to_file'})},\n \t\t\t\t              \"blame\") . \" | \";\n \t\t\t}\n \t\t\tprint $cgi->a({-href => href(action=>\"history\", hash_base=>$hash,\n-\t\t\t                            file_name=>$diff->{'to_file'})},\n+\t\t\t                            file_name=>$to_prefix.$diff->{'to_file'})},\n \t\t\t              \"history\");\n \t\t\tprint \"</td>\\n\";\n \n@@ -3107,7 +3112,7 @@ sub git_difftree_body {\n }\n \n sub git_patchset_body {\n-\tmy ($fd, $difftree, $hash, @hash_parents) = @_;\n+\tmy ($fd, $difftree, $from_prefix, $to_prefix, $hash, @hash_parents) = @_;\n \tmy ($hash_parent) = $hash_parents[0];\n \n \tmy $patch_idx = 0;\n@@ -3116,6 +3121,9 @@ sub git_patchset_body {\n \tmy $diffinfo;\n \tmy (%from, %to);\n \n+\t$from_prefix = !defined $from_prefix ? '' : $from_prefix.'/';\n+\t$to_prefix   = !defined $to_prefix   ? '' : $to_prefix . '/';\n+\n \tprint \"<div class=\\\"patchset\\\">\\n\";\n \n \t# skip to first patch\n@@ -3163,6 +3171,8 @@ sub git_patchset_body {\n \t\t    $diffinfo->{'to_id'} eq $to_id) {\n \t\t\t# this is continuation of a split patch\n \t\t\tprint \"<div class=\\\"patch cont\\\">\\n\";\n+\t\t\t$diffinfo->{'from_prefix'} = $from_prefix;\n+\t\t\t$diffinfo->{'to_prefix'} = $to_prefix;\n \t\t} else {\n \t\t\t# advance raw git-diff output if needed\n \t\t\t$patch_idx++ if defined $diffinfo;\n@@ -3194,6 +3204,8 @@ sub git_patchset_body {\n \t\t\t\t}\n \t\t\t} until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||\n \t\t\t         $patch_idx > $#$difftree);\n+\t\t\t$diffinfo->{'from_prefix'} = $from_prefix;\n+\t\t\t$diffinfo->{'to_prefix'} = $to_prefix;\n \t\t\t# modifies %from, %to hashes\n \t\t\tparse_from_to_diffinfo($diffinfo, \\%from, \\%to, @hash_parents);\n \t\t\tif ($diffinfo->{'nparents'}) {\n@@ -3208,7 +3220,7 @@ sub git_patchset_body {\n \t\t\t\t\t\t$from{'href'}[$i] = href(action=>\"blob\",\n \t\t\t\t\t\t                         hash_base=>$hash_parents[$i],\n \t\t\t\t\t\t                         hash=>$diffinfo->{'from_id'}[$i],\n-\t\t\t\t\t\t                         file_name=>$from{'file'}[$i]);\n+\t\t\t\t\t\t                         file_name=>$from_prefix.$from{'file'}[$i]);\n \t\t\t\t\t} else {\n \t\t\t\t\t\t$from{'href'}[$i] = undef;\n \t\t\t\t\t}\n@@ -3218,7 +3230,7 @@ sub git_patchset_body {\n \t\t\t\tif ($diffinfo->{'status'} ne \"A\") { # not new (added) file\n \t\t\t\t\t$from{'href'} = href(action=>\"blob\", hash_base=>$hash_parent,\n \t\t\t\t\t                     hash=>$diffinfo->{'from_id'},\n-\t\t\t\t\t                     file_name=>$from{'file'});\n+\t\t\t\t\t                     file_name=>$from_prefix.$from{'file'});\n \t\t\t\t} else {\n \t\t\t\t\tdelete $from{'href'};\n \t\t\t\t}\n@@ -3228,7 +3240,7 @@ sub git_patchset_body {\n \t\t\tif (!is_deleted($diffinfo)) { # file exists in result\n \t\t\t\t$to{'href'} = href(action=>\"blob\", hash_base=>$hash,\n \t\t\t\t                   hash=>$diffinfo->{'to_id'},\n-\t\t\t\t                   file_name=>$to{'file'});\n+\t\t\t\t                   file_name=>$to_prefix.$to{'file'});\n \t\t\t} else {\n \t\t\t\tdelete $to{'href'};\n \t\t\t}\n@@ -4590,7 +4602,7 @@ sub git_commit {\n \tgit_print_log($co{'comment'});\n \tprint \"</div>\\n\";\n \n-\tgit_difftree_body(\\@difftree, $hash, @$parents);\n+\tgit_difftree_body(\\@difftree, undef, undef, $hash, @$parents);\n \n \tgit_footer_html();\n }\n@@ -4748,7 +4760,7 @@ sub git_blobdiff {\n \tif ($format eq 'html') {\n \t\tprint \"<div class=\\\"page_body\\\">\\n\";\n \n-\t\tgit_patchset_body($fd, [ \\%diffinfo ], $hash_base, $hash_parent_base);\n+\t\tgit_patchset_body($fd, [ \\%diffinfo ], undef, undef, $hash_base, $hash_parent_base);\n \t\tclose $fd;\n \n \t\tprint \"</div>\\n\"; # class=\"page_body\"\n@@ -4931,11 +4943,11 @@ TEXT\n \tif ($format eq 'html') {\n \t\tmy $use_parents = !defined $hash_parent ||\n \t\t\t$hash_parent eq '-c' || $hash_parent eq '--cc';\n-\t\tgit_difftree_body(\\@difftree, $hash,\n+\t\tgit_difftree_body(\\@difftree, undef, undef, $hash,\n \t\t                  $use_parents ? @{$co{'parents'}} : $hash_parent);\n \t\tprint \"<br/>\\n\";\n \n-\t\tgit_patchset_body($fd, \\@difftree, $hash,\n+\t\tgit_patchset_body($fd, \\@difftree, undef, undef, $hash,\n \t\t                  $use_parents ? @{$co{'parents'}} : $hash_parent);\n \t\tclose $fd;\n \t\tprint \"</div>\\n\"; # class=\"page_body\"\n-- \n1.5.3.rc0.843.g9779f\n"}]}