Commit->sha_by_path now returns an object.
Zachary Stevens [Sun, 27 Jun 2010 01:06:32 +0000 (02:06 +0100)]
lib/Gitalist/Controller/Fragment/Ref.pm
lib/Gitalist/Git/Object/Commit.pm
lib/Gitalist/URIStructure/Ref.pm
t/02git_Repository.t

index 3485d24..6345746 100644 (file)
@@ -49,7 +49,7 @@ after tree => sub {
     my $repository = $c->stash->{Repository};
     my $commit  = $c->stash->{Commit};
     my $tree_obj    = $c->stash->{filename}
-      ? $repository->get_object($commit->sha_by_path($c->stash->{filename}))
+      ? $commit->sha_by_path($c->stash->{filename})
       : $commit->tree->[0]
     ;
     $c->stash(
@@ -99,7 +99,7 @@ after history => sub {
     );
 
     my $commit = $repository->get_object('HEAD');
-    my $file = $repository->get_object($commit->sha_by_path($filename));
+    my $file = $commit->sha_by_path($filename);
 
     my $page = $c->req->param('pg') || 0;
     $logargs{skip} = $c->req->param('pg') * $logargs{count}
index e9350a9..f8e2e4f 100644 (file)
@@ -37,7 +37,7 @@ class Gitalist::Git::Object::Commit
             #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa     panic.c'
             $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
             my $sha1 = $3;
-            return $sha1;
+            return $self->repository->get_object($sha1);
     }
 
         method get_patch ( Maybe[NonEmptySimpleStr] $parent_hash?,
index 9ce2457..8335098 100644 (file)
@@ -63,15 +63,20 @@ sub tree : Chained('find') Does('FilenameArgs') Args() {}
 sub find_blob : Action {
     my ($self, $c) = @_;
     my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
+
     # FIXME - Eugh!
-    my $h  = $object->isa('Gitalist::Git::Object::Commit')
-           ? $object->sha_by_path($c->stash->{filename})
-           : $object->isa('Gitalist::Git::Object::Blob')
-             ? $object->sha1
-             : die "Unknown object type for '${\$object->sha1}'";
+    my $blob;
+    if ($object->isa('Gitalist::Git::Object::Commit')) {
+        $blob = $object->sha_by_path($c->stash->{filename});
+    } elsif ($object->isa('Gitalist::Git::Object::Blob')) {
+        $blob = $object;
+    } else {
+        die "Unknown object type for '${\$object->sha1}'";
+    }
     die "No file or sha1 provided."
-        unless $h;
-    $c->stash(blob => $repo->get_object($h)->content);
+        unless $blob;
+
+    $c->stash(blob => $blob->content);
 }
 
 sub blob : Chained('find') Does('FilenameArgs') Args() {
index e60f0bf..5d0b2e2 100644 (file)
@@ -65,8 +65,7 @@ isa_ok($obj1, 'Gitalist::Git::Object::Tree');
 my $obj3 = $proj->get_object($proj->head_hash);
 isa_ok($obj3, 'Gitalist::Git::Object::Commit');
 
-my $hbp_sha1 = $obj3->sha_by_path('dir1/file2');
-my $obj2 = $proj->get_object($hbp_sha1);
+my $obj2 = $obj3->sha_by_path('dir1/file2');
 isa_ok($obj2, 'Gitalist::Git::Object::Blob');
 is($obj2->type, 'blob', 'sha_by_path obj is a blob');
 is($obj2->content, "foo\n", 'sha_by_path obj content is correct');