is => 'ro',
lazy => 1,
default => sub {
- -d $_[0]->path->parent->subdir->($_[0]->name)
+ -d $_[0]->path->parent->subdir($_[0]->name)
? 1 : 0
},
);
lazy_build => 1 );
method BUILD {
- $self->$_() for qw/last_change owner description/; # Ensure to build early.
+ $self->$_() for qw/last_change owner description /; # Ensure to build early.
}
## Public methods
+
+ method get_object_or_head (NonEmptySimpleStr $ref) {
+ my $sha1 = is_SHA1($ref) ? $ref : $self->head_hash($ref);
+ $self->get_object($sha1);
+ }
+
method head_hash (Str $head?) {
my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
confess("No such head: " . $head) unless defined $output;
chomp($type);
my $class = 'Gitalist::Git::Object::' . ucfirst($type);
$class->new(
- project => $self,
+ repository => $self,
sha1 => $sha1,
type => $type,
);
}
- method hash_by_path ($base, $path = '', $type?) {
+ 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)
#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
$line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
- return defined $type && $type ne $2
- ? ()
- : $3;
+ return $3;
}
method list_revs ( NonEmptySimpleStr :$sha1!,
if !$sha1 || $sha1 !~ $SHA1RE;
my @search_opts;
- if ($search) {
+ if ($search and exists $search->{text}) {
$search->{type} = 'grep'
if $search->{type} eq 'commit';
@search_opts = (
# TODO - support compressed archives
}
- method diff ( Gitalist::Git::Object :$commit!,
- Bool :$patch?,
- Maybe[NonEmptySimpleStr] :$parent?,
- NonEmptySimpleStr :$file?
- ) {
- return $commit->diff( patch => $patch,
- parent => $parent,
- file => $file);
- }
-
method reflog (@logargs) {
my @entries
= $self->run_cmd(qw(log -g), @logargs)
## BUILDERS
method _build_util {
Gitalist::Git::Util->new(
- project => $self,
+ repository => $self,
);
}
$description = $self->path->file('description')->slurp;
chomp $description;
};
+ $description = "Unnamed repository, edit the .git/description file to set a description"
+ if $description eq "Unnamed repository; edit this file 'description' to name the repository.";
return $description;
}
=head1 SYNOPSIS
my $gitrepo = dir('/repo/base/Gitalist');
- my $project = Gitalist::Git::Repository->new($gitrepo);
- $project->name; # 'Gitalist'
- $project->path; # '/repo/base/Gitalist/.git'
- $project->description; # 'Unnamed repository.'
+ my $repository = Gitalist::Git::Repository->new($gitrepo);
+ $repository->name; # 'Gitalist'
+ $repository->path; # '/repo/base/Gitalist/.git'
+ $repository->description; # 'Unnamed repository.'
=head1 DESCRIPTION
This class models a git repository, referred to in Gitalist
-as a "Project".
+as a "Repository".
=head1 ATTRIBUTES
=head2 name
-The name of the Project. If unspecified, this will be derived from the path to the git repository.
+The name of the Repository. If unspecified, this will be derived from the path to the git repository.
=head2 path
Return an appropriate subclass of L<Gitalist::Git::Object> for the given sha1.
-=head2 hash_by_path ($sha1, $path, $type?)
+=head2 hash_by_path ($commit, $path)
-Returns the sha1 for a given path, optionally limited by type.
+Returns the tree/file sha1 for a given path in a commit.
=head2 list_revs ($sha1, $count?, $skip?, \%search?, $file?)