X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FRepository.pm;h=cb16eb2a561846723b53ce8b183fcc58ada5fe57;hb=6732f736698eece7a8a9baeb5c535a16aff7dd1e;hp=571656e29c7b48a25ff85788d3e233b3728482fb;hpb=dc8badf5e3050d832e552e8d7f37d6f9325ec457;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Repository.pm b/lib/Gitalist/Git/Repository.pm index 571656e..cb16eb2 100644 --- a/lib/Gitalist/Git/Repository.pm +++ b/lib/Gitalist/Git/Repository.pm @@ -1,16 +1,20 @@ use MooseX::Declare; -class Gitalist::Git::Repository with Gitalist::Git::HasUtils { - # FIXME, use Types::Path::Class and coerce +class Gitalist::Git::Repository with (Gitalist::Git::HasUtils, Gitalist::Git::Serializable) { + use MooseX::Storage::Meta::Attribute::Trait::DoNotSerialize; + use MooseX::Types::Common::String qw/NonEmptySimpleStr/; - use MooseX::Types::Path::Class qw/Dir/; - use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/; - use Gitalist::Git::Types qw/SHA1/; + use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/; + use Gitalist::Git::Types qw/SHA1 Dir/; + use MooseX::Types::DateTime qw/ DateTime /; + use Moose::Autobox; + use aliased 'DateTime' => 'DT'; use List::MoreUtils qw/any zip/; - use DateTime; - use Encode qw/decode/; - use I18N::Langinfo qw/langinfo CODESET/; + use Encode qw/decode/; + + use if $^O ne 'MSWin32' => 'I18N::Langinfo', qw/langinfo CODESET/; + use Gitalist::Git::Object::Blob; use Gitalist::Git::Object::Tree; use Gitalist::Git::Object::Commit; @@ -20,20 +24,20 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { our $SHA1RE = qr/[0-9a-fA-F]{40}/; - around BUILDARGS (ClassName $class: Dir $dir) { + around BUILDARGS (ClassName $class: Dir $dir, Str $override_name = '') { # Allows us to be called as Repository->new($dir) # Last path component becomes $self->name # Full path to git objects becomes $self->path my $name = $dir->dir_list(-1); - if(-f $dir->file('.git', 'HEAD')) { # Non-bare repo above .git - $dir = $dir->subdir('.git'); - $name = $dir->dir_list(-2, 1); # .../name/.git - } elsif('.git' eq $dir->dir_list(-1)) { # Non-bare repo in .git - $name = $dir->dir_list(-2); - } + if(-f $dir->file('.git', 'HEAD')) { # Non-bare repo above .git + $dir = $dir->subdir('.git'); + $name = $dir->dir_list(-2, 1); # .../name/.git + } elsif('.git' eq $dir->dir_list(-1)) { # Non-bare repo in .git + $name = $dir->dir_list(-2); + } confess("Can't find a git repository at " . $dir) - unless ( -f $dir->file('HEAD') ); - return $class->$orig(name => $name, + unless -f $dir->file('HEAD'); + return $class->$orig(name => $override_name || $name, path => $dir); } @@ -41,7 +45,8 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { is => 'ro', required => 1 ); has path => ( isa => Dir, - is => 'ro', required => 1); + is => 'ro', required => 1, + traits => ['DoNotSerialize'] ); has description => ( isa => Str, is => 'ro', @@ -53,7 +58,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { lazy_build => 1, ); - has last_change => ( isa => Maybe['DateTime'], + has last_change => ( isa => Maybe[DateTime], is => 'ro', lazy_build => 1, ); @@ -213,15 +218,18 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { my $description = ""; eval { $description = $self->path->file('description')->slurp; + utf8::decode($description); 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."; + $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; } method _build_owner { - my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0]; + return 'system' if $^O =~ 'MSWin32'; + + my ($gecos, $name) = map { decode(langinfo(CODESET()), $_) } (getpwuid $self->path->stat->uid)[6,0]; $gecos =~ s/,+$//; return length($gecos) ? $gecos : $name; } @@ -233,7 +241,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { --sort=-committerdate --count=1 refs/heads }); if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) { - my $dt = DateTime->from_epoch(epoch => $epoch); + my $dt = DT->from_epoch(epoch => $epoch); $dt->set_time_zone($tz); $last_change = $dt; } @@ -255,11 +263,10 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { '--format=%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) %(subject)%00%(creator)', 'refs/tags' ); - my @ret; - for my $line (@revlines) { - push @ret, Gitalist::Git::Tag->new($line); - } - return \@ret; + return [ + map Gitalist::Git::Tag->new($_), + grep Gitalist::Git::Tag::is_valid_tag($_), @revlines + ]; } method _build_references {