* blameview and file contents
@ 2007-01-30 6:46 Aneesh Kumar
2007-01-30 6:54 ` Shawn O. Pearce
0 siblings, 1 reply; 5+ messages in thread
From: Aneesh Kumar @ 2007-01-30 6:46 UTC (permalink / raw)
To: Git Mailing List
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
Hi,
I guess blame view need to pull the file content from the repository
rather than opening it directly. If i have a working copy that is not
yet committed it gives wrong results. I tried some changes as below.
But i guess there should be a much easier way.
-aneesh
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: blameview.diff --]
[-- Type: text/x-patch; name="blameview.diff", Size: 2187 bytes --]
diff --git a/contrib/blameview/blameview.perl b/contrib/blameview/blameview.perl
index a55f799..a7505da 100755
--- a/contrib/blameview/blameview.perl
+++ b/contrib/blameview/blameview.perl
@@ -3,6 +3,7 @@
use Gtk2 -init;
use Gtk2::SimpleList;
+our $GIT="git";
my $fn = shift or die "require filename to blame";
Gtk2::Rc->parse_string(<<'EOS');
@@ -13,6 +14,50 @@ style "treeview_style"
class "GtkTreeView" style "treeview_style"
EOS
+sub get_file_handle
+{
+ my ($commit_hash, $filename) = @_;
+ my (@path_comp, $hash_line, @hash_line, $path);
+ my ($tree_hash, $hash);
+ my @file_contents;
+ @path_comp = split(/\//, $filename);
+start:
+ chomp($commit_hash);
+ open my $fd, "-|", "$GIT cat-file -t $commit_hash" or
+ die("Execute git-cat-file failed.");
+ $hash_line = <$fd>;
+ chomp($hash_line);
+ if ($hash_line =~ m/commit/) {
+
+ open my $fd, "-|", "$GIT cat-file commit $commit_hash | grep tree" or
+ die("Execute git-cat-file failed.");
+ $hash_line = <$fd>;
+ close($fd);
+ @hash_line = split(/[\t ]+/, $hash_line);
+ $tree_hash = $hash_line[1];
+ } elsif ($hash_line =~ m/tree/) {
+ $tree_hash = $hash_line;
+ } else {
+ die("Need to specify either a tree or a commit hash");
+ }
+
+ foreach $path (@path_comp) {
+ chomp($tree_hash);
+ open my $fd, "-|", "$GIT ls-tree $tree_hash | grep $path\$" or
+ die("Execute git-ls-tree failed.");
+ $hash_line = <$fd>;
+ close($fd);
+ @hash_line = split(/[\t ]+/, $hash_line);
+ if ($hash_line[1] =~ m/tree/) {
+ $tree_hash = $hash_line[2];
+ next;
+ } elsif ($hash_line[1] =~ m/blob/) {
+ open my $fd, "-|", "$GIT cat-file blob $hash_line[2]" or
+ die("Execute git-cat-file failed.");
+ return $fd;
+ }
+ }
+}
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect(destroy => sub { Gtk2->main_quit });
my $scrolled_window = Gtk2::ScrolledWindow->new;
@@ -28,8 +73,7 @@ $fileview->get_column(0)->set_spacing(0);
$fileview->set_size_request(1024, 768);
$fileview->set_rules_hint(1);
-open(my $fh, '<', $fn)
- or die "unable to open $fn: $!";
+$fh = get_file_handle("HEAD", $fn);
while(<$fh>) {
chomp;
$fileview->{data}->[$.] = ['HEAD', '?', "$fn:$.", $_];
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: blameview and file contents
2007-01-30 6:46 blameview and file contents Aneesh Kumar
@ 2007-01-30 6:54 ` Shawn O. Pearce
2007-01-30 7:22 ` Aneesh Kumar
0 siblings, 1 reply; 5+ messages in thread
From: Shawn O. Pearce @ 2007-01-30 6:54 UTC (permalink / raw)
To: Aneesh Kumar; +Cc: Git Mailing List
Aneesh Kumar <aneesh.kumar@gmail.com> wrote:
> I guess blame view need to pull the file content from the repository
> rather than opening it directly. If i have a working copy that is not
> yet committed it gives wrong results. I tried some changes as below.
> But i guess there should be a much easier way.
> -open(my $fh, '<', $fn)
> - or die "unable to open $fn: $!";
> +$fh = get_file_handle("HEAD", $fn);
> while(<$fh>) {
> chomp;
> $fileview->{data}->[$.] = ['HEAD', '?', "$fn:$.", $_];
Doesn't the following work just as well, and use a lot less code?
open(my $fh, '|-', 'git', 'cat-file', 'blob', "HEAD:$fn")
?
--
Shawn.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: blameview and file contents
2007-01-30 6:54 ` Shawn O. Pearce
@ 2007-01-30 7:22 ` Aneesh Kumar
2007-01-30 7:29 ` Shawn O. Pearce
0 siblings, 1 reply; 5+ messages in thread
From: Aneesh Kumar @ 2007-01-30 7:22 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Git Mailing List
On 1/30/07, Shawn O. Pearce <spearce@spearce.org> wrote:
> Aneesh Kumar <aneesh.kumar@gmail.com> wrote:
> > I guess blame view need to pull the file content from the repository
> > rather than opening it directly. If i have a working copy that is not
> > yet committed it gives wrong results. I tried some changes as below.
> > But i guess there should be a much easier way.
>
> > -open(my $fh, '<', $fn)
> > - or die "unable to open $fn: $!";
> > +$fh = get_file_handle("HEAD", $fn);
> > while(<$fh>) {
> > chomp;
> > $fileview->{data}->[$.] = ['HEAD', '?', "$fn:$.", $_];
>
> Doesn't the following work just as well, and use a lot less code?
>
> open(my $fh, '|-', 'git', 'cat-file', 'blob', "HEAD:$fn")
>
> ?
>
See i said that there should be a simple way. Can we get this
documented in git-cat-file man page
-aneesh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: blameview and file contents
2007-01-30 7:22 ` Aneesh Kumar
@ 2007-01-30 7:29 ` Shawn O. Pearce
2007-01-30 8:30 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Shawn O. Pearce @ 2007-01-30 7:29 UTC (permalink / raw)
To: Aneesh Kumar; +Cc: Git Mailing List
Aneesh Kumar <aneesh.kumar@gmail.com> wrote:
> See i said that there should be a simple way. Can we get this
> documented in git-cat-file man page
Well, this isn't the git-cat-file man page, but we do suggest people
use `git show HEAD:foo.c` to get foo.c from HEAD in an interactive
setting. The git-show manpage refers people to git-rev-parse,
which has the following:
* A suffix ':' followed by a path; this names the blob or tree
at the given path in the tree-ish object named by the part
before the colon.
In a non-interactive case, well, that's what git-cat-file is for.
And <object> typically is meant to mean what git-rev-parse will
parse...
But if you submit a documentation update to git-cat-file's manpage
that points off to the same section of git-rev-parse, folks may
appreciate it. :-)
--
Shawn.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: blameview and file contents
2007-01-30 7:29 ` Shawn O. Pearce
@ 2007-01-30 8:30 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2007-01-30 8:30 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git, Aneesh Kumar
"Shawn O. Pearce" <spearce@spearce.org> writes:
> Aneesh Kumar <aneesh.kumar@gmail.com> wrote:
>> See i said that there should be a simple way. Can we get this
>> documented in git-cat-file man page
>
> Well, this isn't the git-cat-file man page, but we do suggest people
> use `git show HEAD:foo.c` to get foo.c from HEAD in an interactive
> setting. The git-show manpage refers people to git-rev-parse,
> which has the following:
>
> * A suffix ':' followed by a path; this names the blob or tree
> at the given path in the tree-ish object named by the part
> before the colon.
> ...
> But if you submit a documentation update to git-cat-file's manpage
> that points off to the same section of git-rev-parse, folks may
> appreciate it. :-)
My feeling is that adding "See SPECIFYING REVISIONS section" to
Porcelain documentation is a very good idea, but unwanted
baggage for plumbing descriptions if added everywhere. The
target audience of the latter is supposed to know what "object
name" is, so:
<object>::
- The sha1 identifier of the object.
+ The name of the object to show.
should be sufficient.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-01-30 8:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-30 6:46 blameview and file contents Aneesh Kumar
2007-01-30 6:54 ` Shawn O. Pearce
2007-01-30 7:22 ` Aneesh Kumar
2007-01-30 7:29 ` Shawn O. Pearce
2007-01-30 8:30 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox