{"thread":{"id":"6577","subject":"blameview and file contents","startedAt":"2007-01-30T06:46:52Z","lastAt":"2007-01-30T08:30:25Z","messageCount":5,"participants":["Aneesh Kumar","Shawn O. Pearce","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"33005","messageId":"cc723f590701292246v282408d0o27a0d8320c027743@mail.gmail.com","threadId":"6577","inReplyTo":null,"subject":"blameview and file contents","fromName":"Aneesh Kumar","fromEmail":"aneesh.kumar@gmail.com","sentAt":"2007-01-30T06:46:52Z","receivedAt":"2007-01-30T06:46:52Z","isPatch":false,"sender":{"key":"aneesh.kumar@gmail.com","avatar":"https://gravatar.com/avatar/0621fc0b2f14ead1e9024382f16053a808c148596da30c1b92572fa075621f68?d=mp&s=160"},"body":"Hi,\n\nI guess blame view need to pull the file content from the repository\nrather than opening it directly. If i have a working copy that is not\nyet committed it gives wrong results. I tried some changes as below.\nBut i guess there should be a much easier way.\n\n-aneesh\n\n\ndiff --git a/contrib/blameview/blameview.perl b/contrib/blameview/blameview.perl\nindex a55f799..a7505da 100755\n--- a/contrib/blameview/blameview.perl\n+++ b/contrib/blameview/blameview.perl\n@@ -3,6 +3,7 @@\n use Gtk2 -init;\n use Gtk2::SimpleList;\n \n+our $GIT=\"git\";\n my $fn = shift or die \"require filename to blame\";\n \n Gtk2::Rc->parse_string(<<'EOS');\n@@ -13,6 +14,50 @@ style \"treeview_style\"\n class \"GtkTreeView\" style \"treeview_style\"\n EOS\n \n+sub get_file_handle\n+{\n+\tmy ($commit_hash, $filename) = @_;\n+\tmy (@path_comp, $hash_line, @hash_line, $path);\n+\tmy ($tree_hash, $hash);\n+\tmy @file_contents;\n+\t@path_comp = split(/\\//, $filename);\n+start:\n+\tchomp($commit_hash);\n+\topen my $fd, \"-|\", \"$GIT cat-file -t $commit_hash\" or\n+\t\t\t\tdie(\"Execute git-cat-file failed.\");\n+\t$hash_line = <$fd>;\n+\tchomp($hash_line);\n+\tif ($hash_line =~ m/commit/) {\n+\n+\t\topen my $fd, \"-|\", \"$GIT cat-file commit $commit_hash | grep tree\" or\n+\t\t\t\t\t\tdie(\"Execute git-cat-file failed.\");\n+\t\t$hash_line = <$fd>;\n+\t\tclose($fd);\n+\t\t@hash_line = split(/[\\t ]+/, $hash_line);\n+\t\t$tree_hash = $hash_line[1];\n+\t} elsif ($hash_line =~ m/tree/) {\n+\t\t$tree_hash = $hash_line;\n+\t} else {\n+\t\tdie(\"Need to specify either a tree or a commit hash\");\n+\t}\n+\n+\tforeach $path (@path_comp) {\n+\t\tchomp($tree_hash);\n+\t\topen my $fd, \"-|\", \"$GIT ls-tree $tree_hash | grep $path\\$\" or\n+\t\t\t\t\t\tdie(\"Execute git-ls-tree failed.\");\n+\t\t$hash_line = <$fd>;\n+\t\tclose($fd);\n+\t\t@hash_line = split(/[\\t ]+/, $hash_line);\n+\t\tif ($hash_line[1] =~ m/tree/) {\n+\t\t\t$tree_hash = $hash_line[2];\n+\t\t\tnext;\n+\t\t} elsif ($hash_line[1] =~ m/blob/)  {\n+\t\t\topen my $fd, \"-|\", \"$GIT cat-file blob $hash_line[2]\" or\n+\t\t\t\t\t\tdie(\"Execute git-cat-file failed.\");\n+\t\t\treturn $fd;\n+\t\t}\n+\t}\n+}\n my $window = Gtk2::Window->new('toplevel');\n $window->signal_connect(destroy => sub { Gtk2->main_quit });\n my $scrolled_window = Gtk2::ScrolledWindow->new;\n@@ -28,8 +73,7 @@ $fileview->get_column(0)->set_spacing(0);\n $fileview->set_size_request(1024, 768);\n $fileview->set_rules_hint(1);\n \n-open(my $fh, '<', $fn)\n-  or die \"unable to open $fn: $!\";\n+$fh = get_file_handle(\"HEAD\", $fn);\n while(<$fh>) {\n   chomp;\n   $fileview->{data}->[$.] = ['HEAD', '?', \"$fn:$.\", $_];\n"},{"id":"33006","messageId":"20070130065417.GA32640@spearce.org","threadId":"6577","inReplyTo":"cc723f590701292246v282408d0o27a0d8320c027743@mail.gmail.com","subject":"Re: blameview and file contents","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-30T06:54:17Z","receivedAt":"2007-01-30T06:54:17Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Aneesh Kumar <aneesh.kumar@gmail.com> wrote:\n> I guess blame view need to pull the file content from the repository\n> rather than opening it directly. If i have a working copy that is not\n> yet committed it gives wrong results. I tried some changes as below.\n> But i guess there should be a much easier way.\n\n> -open(my $fh, '<', $fn)\n> -  or die \"unable to open $fn: $!\";\n> +$fh = get_file_handle(\"HEAD\", $fn);\n>  while(<$fh>) {\n>    chomp;\n>    $fileview->{data}->[$.] = ['HEAD', '?', \"$fn:$.\", $_];\n\nDoesn't the following work just as well, and use a lot less code?\n\n  open(my $fh, '|-', 'git', 'cat-file', 'blob', \"HEAD:$fn\")\n\n?\n\n-- \nShawn.\n"},{"id":"33007","messageId":"cc723f590701292322q7365f99bg3b7c76834f6fbad8@mail.gmail.com","threadId":"6577","inReplyTo":"20070130065417.GA32640@spearce.org","subject":"Re: blameview and file contents","fromName":"Aneesh Kumar","fromEmail":"aneesh.kumar@gmail.com","sentAt":"2007-01-30T07:22:19Z","receivedAt":"2007-01-30T07:22:19Z","isPatch":false,"sender":{"key":"aneesh.kumar@gmail.com","avatar":"https://gravatar.com/avatar/0621fc0b2f14ead1e9024382f16053a808c148596da30c1b92572fa075621f68?d=mp&s=160"},"body":"On 1/30/07, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Aneesh Kumar <aneesh.kumar@gmail.com> wrote:\n> > I guess blame view need to pull the file content from the repository\n> > rather than opening it directly. If i have a working copy that is not\n> > yet committed it gives wrong results. I tried some changes as below.\n> > But i guess there should be a much easier way.\n>\n> > -open(my $fh, '<', $fn)\n> > -  or die \"unable to open $fn: $!\";\n> > +$fh = get_file_handle(\"HEAD\", $fn);\n> >  while(<$fh>) {\n> >    chomp;\n> >    $fileview->{data}->[$.] = ['HEAD', '?', \"$fn:$.\", $_];\n>\n> Doesn't the following work just as well, and use a lot less code?\n>\n>   open(my $fh, '|-', 'git', 'cat-file', 'blob', \"HEAD:$fn\")\n>\n> ?\n>\n\nSee i said that there should be a simple way. Can we get this\ndocumented in git-cat-file man page\n\n-aneesh\n"},{"id":"33009","messageId":"20070130072910.GB32640@spearce.org","threadId":"6577","inReplyTo":"cc723f590701292322q7365f99bg3b7c76834f6fbad8@mail.gmail.com","subject":"Re: blameview and file contents","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-30T07:29:10Z","receivedAt":"2007-01-30T07:29:10Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Aneesh Kumar <aneesh.kumar@gmail.com> wrote:\n> See i said that there should be a simple way. Can we get this\n> documented in git-cat-file man page\n\nWell, this isn't the git-cat-file man page, but we do suggest people\nuse `git show HEAD:foo.c` to get foo.c from HEAD in an interactive\nsetting.  The git-show manpage refers people to git-rev-parse,\nwhich has the following:\n\n\t* A suffix ':' followed by a path; this names the blob or tree\n\t  at the given path in the tree-ish object named by the part\n\t  before the colon.\n\nIn a non-interactive case, well, that's what git-cat-file is for.\nAnd <object> typically is meant to mean what git-rev-parse will\nparse... \n\nBut if you submit a documentation update to git-cat-file's manpage\nthat points off to the same section of git-rev-parse, folks may\nappreciate it.  :-)\n\n-- \nShawn.\n"},{"id":"33017","messageId":"7vveio5332.fsf@assigned-by-dhcp.cox.net","threadId":"6577","inReplyTo":"20070130072910.GB32640@spearce.org","subject":"Re: blameview and file contents","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-30T08:30:25Z","receivedAt":"2007-01-30T08:30:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Aneesh Kumar <aneesh.kumar@gmail.com> wrote:\n>> See i said that there should be a simple way. Can we get this\n>> documented in git-cat-file man page\n>\n> Well, this isn't the git-cat-file man page, but we do suggest people\n> use `git show HEAD:foo.c` to get foo.c from HEAD in an interactive\n> setting.  The git-show manpage refers people to git-rev-parse,\n> which has the following:\n>\n> \t* A suffix ':' followed by a path; this names the blob or tree\n> \t  at the given path in the tree-ish object named by the part\n> \t  before the colon.\n> ...\n> But if you submit a documentation update to git-cat-file's manpage\n> that points off to the same section of git-rev-parse, folks may\n> appreciate it.  :-)\n\nMy feeling is that adding \"See SPECIFYING REVISIONS section\" to\nPorcelain documentation is a very good idea, but unwanted\nbaggage for plumbing descriptions if added everywhere.  The\ntarget audience of the latter is supposed to know what \"object\nname\" is, so:\n\n <object>::\n-\tThe sha1 identifier of the object.\n+\tThe name of the object to show.\n\nshould be sufficient.\n"}]}