{"thread":{"id":"7804","subject":"[PATCH] gitweb: Support comparing blobs with different names","startedAt":"2007-04-23T20:55:47Z","lastAt":"2007-04-23T20:55:47Z","messageCount":1,"participants":["Martin Koegler"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"40238","messageId":"11773617471526-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"7804","inReplyTo":null,"subject":"[PATCH] gitweb: Support comparing blobs with different names","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2007-04-23T20:55:47Z","receivedAt":"2007-04-23T20:55:47Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Currently, blobdiff can only compare blobs with different file\nnames, if no hb/hpb parameters are present.\n\nThis patch adds support for comparing two blobs specified by any\ncombination of hb/f/h and hpb/fp/hp.\n\nSigned-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\nUpdated gitweb blobdiff patch to take advantage of my git-diff patch series.\n\n gitweb/gitweb.perl |  148 +++++++++++++++++++---------------------------------\n 1 files changed, 53 insertions(+), 95 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex cbd8d03..4b42f62 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3902,109 +3902,66 @@ sub git_blobdiff {\n \tmy $fd;\n \tmy @difftree;\n \tmy %diffinfo;\n-\tmy $expires;\n-\n-\t# preparing $fd and %diffinfo for git_patchset_body\n-\t# new style URI\n-\tif (defined $hash_base && defined $hash_parent_base) {\n-\t\tif (defined $file_name) {\n-\t\t\t# read raw output\n-\t\t\topen $fd, \"-|\", git_cmd(), \"diff-tree\", '-r', @diff_opts,\n-\t\t\t\t$hash_parent_base, $hash_base,\n-\t\t\t\t\"--\", (defined $file_parent ? $file_parent : ()), $file_name\n-\t\t\t\tor die_error(undef, \"Open git-diff-tree failed\");\n-\t\t\t@difftree = map { chomp; $_ } <$fd>;\n-\t\t\tclose $fd\n-\t\t\t\tor die_error(undef, \"Reading git-diff-tree failed\");\n-\t\t\t@difftree\n-\t\t\t\tor die_error('404 Not Found', \"Blob diff not found\");\n-\n-\t\t} elsif (defined $hash &&\n-\t\t         $hash =~ /[0-9a-fA-F]{40}/) {\n-\t\t\t# try to find filename from $hash\n-\n-\t\t\t# read filtered raw output\n-\t\t\topen $fd, \"-|\", git_cmd(), \"diff-tree\", '-r', @diff_opts,\n-\t\t\t\t$hash_parent_base, $hash_base, \"--\"\n-\t\t\t\tor die_error(undef, \"Open git-diff-tree failed\");\n-\t\t\t@difftree =\n-\t\t\t\t# ':100644 100644 03b21826... 3b93d5e7... M\tls-files.c'\n-\t\t\t\t# $hash == to_id\n-\t\t\t\tgrep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }\n-\t\t\t\tmap { chomp; $_ } <$fd>;\n-\t\t\tclose $fd\n-\t\t\t\tor die_error(undef, \"Reading git-diff-tree failed\");\n-\t\t\t@difftree\n-\t\t\t\tor die_error('404 Not Found', \"Blob diff not found\");\n-\n-\t\t} else {\n-\t\t\tdie_error('404 Not Found', \"Missing one of the blob diff parameters\");\n-\t\t}\n-\n-\t\tif (@difftree > 1) {\n-\t\t\tdie_error('404 Not Found', \"Ambiguous blob diff specification\");\n-\t\t}\n-\n-\t\t%diffinfo = parse_difftree_raw_line($difftree[0]);\n-\t\t$file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};\n-\t\t$file_name   ||= $diffinfo{'to_file'}   || $diffinfo{'file'};\n+\tmy $expires = '+1d';\n+\tmy $from, $to;\n \n-\t\t$hash_parent ||= $diffinfo{'from_id'};\n-\t\t$hash        ||= $diffinfo{'to_id'};\n+\t$file_parent ||= $file_name;\n \n-\t\t# non-textual hash id's can be cached\n-\t\tif ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&\n-\t\t    $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {\n-\t\t\t$expires = '+1d';\n-\t\t}\n+\t# non-textual hash id's can be cached\n+\tif (defined $hash && $hash !~ m/^[0-9a-fA-F]{40}$/) {\n+\t\t$expires = undef;\n+\t} elsif (defined $hash_parent && $hash_parent !~ m/^[0-9a-fA-F]{40}$/) {\n+\t\t$expires = undef;\n+\t} elsif (defined $hash_base && $hash_base !~ m/^[0-9a-fA-F]{40}$/) {\n+\t\t$expires = undef;\n+\t} elsif (defined $hash_parent_base && $hash_parent_base !~ m/^[0-9a-fA-F]{40}$/) {\n+\t\t$expires = undef;\n+\t}\n+\n+\t# if hash parameter is missing, read it from the commit.\n+\tif (defined $hash_base && defined $file_name && !defined $hash) {\n+\t\t$hash = git_get_hash_by_path($hash_base, $file_name);\n+\t}\n \n-\t\t# open patch output\n-\t\topen $fd, \"-|\", git_cmd(), \"diff-tree\", '-r', @diff_opts,\n-\t\t\t'-p', ($format eq 'html' ? \"--full-index\" : ()),\n-\t\t\t$hash_parent_base, $hash_base,\n-\t\t\t\"--\", (defined $file_parent ? $file_parent : ()), $file_name\n-\t\t\tor die_error(undef, \"Open git-diff-tree failed\");\n+\tif (defined $hash_parent_base && defined $file_parent && !defined $hash_parent) {\n+\t    $hash_parent = git_get_hash_by_path($hash_parent_base, $file_parent);\n+\t}\n+\t\n+\tif (!defined $hash || ! defined $hash_parent) {\n+\t\tdie_error('404 Not Found', \"Missing one of the blob diff parameters\");\n \t}\n \n-\t# old/legacy style URI\n-\tif (!%diffinfo && # if new style URI failed\n-\t    defined $hash && defined $hash_parent) {\n-\t\t# fake git-diff-tree raw output\n-\t\t$diffinfo{'from_mode'} = $diffinfo{'to_mode'} = \"blob\";\n-\t\t$diffinfo{'from_id'} = $hash_parent;\n-\t\t$diffinfo{'to_id'}   = $hash;\n-\t\tif (defined $file_name) {\n-\t\t\tif (defined $file_parent) {\n-\t\t\t\t$diffinfo{'status'} = '2';\n-\t\t\t\t$diffinfo{'from_file'} = $file_parent;\n-\t\t\t\t$diffinfo{'to_file'}   = $file_name;\n-\t\t\t} else { # assume not renamed\n-\t\t\t\t$diffinfo{'status'} = '1';\n-\t\t\t\t$diffinfo{'from_file'} = $file_name;\n-\t\t\t\t$diffinfo{'to_file'}   = $file_name;\n-\t\t\t}\n-\t\t} else { # no filename given\n-\t\t\t$diffinfo{'status'} = '2';\n-\t\t\t$diffinfo{'from_file'} = $hash_parent;\n-\t\t\t$diffinfo{'to_file'}   = $hash;\n-\t\t}\n+\tif (defined $hase_base && defined $file_name) {\n+\t\t$to = $hash_base . ':' . $file_name;\n+\t} else {\n+\t\t$to = $hash;\n+\t}\n \n-\t\t# non-textual hash id's can be cached\n-\t\tif ($hash =~ m/^[0-9a-fA-F]{40}$/ &&\n-\t\t    $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {\n-\t\t\t$expires = '+1d';\n-\t\t}\n+\tif (defined $hase_parent_base && defined $file_parent) {\n+\t\t$from = $hash_parent_base . ':' . $file_parent;\n+\t} else {\n+\t\t$from = $hash_parent;\n+\t}\n \n-\t\t# open patch output\n-\t\topen $fd, \"-|\", git_cmd(), \"diff\", @diff_opts,\n-\t\t\t'-p', ($format eq 'html' ? \"--full-index\" : ()),\n-\t\t\t$hash_parent, $hash, \"--\"\n-\t\t\tor die_error(undef, \"Open git-diff failed\");\n-\t} else  {\n-\t\tdie_error('404 Not Found', \"Missing one of the blob diff parameters\")\n-\t\t\tunless %diffinfo;\n+\t# fake git-diff-tree raw output\n+\t$diffinfo{'from_mode'} = $diffinfo{'to_mode'} = \"blob\";\n+\t$diffinfo{'from_id'} = $hash_parent;\n+\t$diffinfo{'to_id'}   = $hash;\n+\tif (defined $file_name) {\n+\t\t$diffinfo{'status'} = '2';\n+\t\t$diffinfo{'from_file'} = $file_parent;\n+\t\t$diffinfo{'to_file'}   = $file_name;\n+\t} else { # no filename given\n+\t\t$diffinfo{'status'} = '2';\n+\t\t$diffinfo{'from_file'} = $hash_parent;\n+\t\t$diffinfo{'to_file'}   = $hash;\n \t}\n \n+\t# open patch output\n+\topen $fd, \"-|\", git_cmd(), \"diff\", @diff_opts, '--raw', '-p', '--full-index',\n+\t$from, $to, \"--\"\n+\t\tor die_error(undef, \"Open git-diff failed\");\n+\n \t# header\n \tif ($format eq 'html') {\n \t\tmy $formats_nav =\n@@ -4028,11 +3985,12 @@ sub git_blobdiff {\n \t\t}\n \n \t} elsif ($format eq 'plain') {\n+\t\tmy $patch_file_name = $file_name || $hash;\n \t\tprint $cgi->header(\n \t\t\t-type => 'text/plain',\n \t\t\t-charset => 'utf-8',\n \t\t\t-expires => $expires,\n-\t\t\t-content_disposition => 'inline; filename=\"' . \"$file_name\" . '.patch\"');\n+\t\t\t-content_disposition => 'inline; filename=\"' . \"$patch_file_name\" . '.patch\"');\n \n \t\tprint \"X-Git-Url: \" . $cgi->self_url() . \"\\n\\n\";\n \n-- \n1.5.1.1.199.g1a18-dirty\n"}]}