my $repository = $c->stash->{Repository};
my $commit = $c->stash->{Commit};
my $tree = $c->stash->{filename}
- ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
+ ? $repository->get_object($commit->sha_by_path($c->stash->{filename}))
: $repository->get_object($commit->tree_sha1)
;
$c->stash(
($filename ? (file => $filename) : ())
);
- my $file = $repository->get_object(
- $repository->hash_by_path(
- $repository->head_hash,
- $filename
- )
- );
+ my $commit = $repository->get_object('HEAD');
+ my $file = $repository->get_object($commit->sha_by_path($filename));
my $page = $c->req->param('pg') || 0;
$logargs{skip} = $c->req->param('pg') * $logargs{count}
],
);
+ method sha_by_path ($path) {
+ $path =~ s{/+$}();
+ # FIXME should this really just take the first result?
+ my @paths = $self->repository->run_cmd('ls-tree', $self->sha1, '--', $path)
+ or return;
+ my $line = $paths[0];
+
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
+ $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
+ my $sha1 = $3;
+ return $sha1;
+ }
+
method get_patch ( Maybe[NonEmptySimpleStr] $parent_hash?,
Int $patch_count?) {
# assembling the git command to execute...
=head1 METHODS
+=head2 sha_by_path ($path)
+
+Returns the tree/file sha1 for a given path in a commit.
+
=head2 get_patch
=head2 diff
);
}
- method hash_by_path ($base, $path) {
- $path =~ s{/+$}();
- # FIXME should this really just take the first result?
- my @paths = $self->run_cmd('ls-tree', $base, '--', $path)
- or return;
- my $line = $paths[0];
-
- #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
- $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
- return $3;
- }
-
method list_revs ( NonEmptySimpleStr :$sha1!,
Int :$count?,
Int :$skip?,
Return an appropriate subclass of L<Gitalist::Git::Object> for the given sha1.
-=head2 hash_by_path ($commit, $path)
-
-Returns the tree/file sha1 for a given path in a commit.
-
=head2 list_revs ($sha1, $count?, $skip?, \%search?, $file?)
Returns a list of revs for the given head ($sha1).
my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
# FIXME - Eugh!
my $h = $object->isa('Gitalist::Git::Object::Commit')
- ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
+ ? $object->sha_by_path($c->stash->{filename})
: $object->isa('Gitalist::Git::Object::Blob')
? $object->sha1
: die "Unknown object type for '${\$object->sha1}'";
my $obj1 = $proj->get_object('729a7c3f6ba5453b42d16a43692205f67fb23bc1');
isa_ok($obj1, 'Gitalist::Git::Object::Tree');
-my $hbp_sha1 = $proj->hash_by_path('36c6c6708b8360d7023e8a1649c45bcf9b3bd818', 'dir1/file2');
+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);
isa_ok($obj2, 'Gitalist::Git::Object::Blob');
-is($obj2->type, 'blob', 'hash_by_path obj is a file');
-is($obj2->content, "foo\n", 'hash_by_path obj is a file');
+is($obj2->type, 'blob', 'sha_by_path obj is a blob');
+is($obj2->content, "foo\n", 'sha_by_path obj content is correct');
-my $obj3 = $proj->get_object($proj->head_hash);
-isa_ok($obj3, 'Gitalist::Git::Object::Commit');
like($proj->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash');