X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FObject.pm;h=7d46632b465268e1f51638d9e21cff1fb98633db;hb=96410fb53cae4b097d227548ef75600f5d8f19b4;hp=154f0126ba13ef456d6f3b5ccf4ed866818b7c5f;hpb=aa7f1f929582c285407f62cda02d8208f7eab85c;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Object.pm b/lib/Gitalist/Git/Object.pm index 154f012..7d46632 100644 --- a/lib/Gitalist/Git/Object.pm +++ b/lib/Gitalist/Git/Object.pm @@ -1,13 +1,15 @@ use MooseX::Declare; use Moose::Autobox; -class Gitalist::Git::Object { +class Gitalist::Git::Object with Gitalist::Git::Serializable is dirty { + use MooseX::Storage::Meta::Attribute::Trait::DoNotSerialize; + use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/; use MooseX::Types::Common::String qw/NonEmptySimpleStr/; - use File::Stat::ModeString qw/mode_to_string/; + use overload '""' => '_to_string', fallback => 1; - # project and sha1 are required initargs - has project => ( isa => 'Gitalist::Git::Project', + # repository and sha1 are required initargs + has repository => ( isa => 'Gitalist::Git::Repository', required => 1, is => 'ro', weak_ref => 1, @@ -32,12 +34,12 @@ class Gitalist::Git::Object { lazy_build => 1 ) for qw/modestr size/; - has _gpp_obj => ( isa => 'Git::PurePerl::Object', - required => 1, - is => 'ro', + has _gpp_obj => ( isa => 'Git::PurePerl::Object', + required => 1, + is => 'ro', lazy_build => 1, - handles => [ 'content', - ], + handles => [ 'content' ], + traits => ['DoNotSerialize'] ); # objects can't determine their mode or filename @@ -52,6 +54,9 @@ class Gitalist::Git::Object { method BUILD { $self->$_() for qw/_gpp_obj size modestr/ } ## Private methods + method _to_string { + return $self->sha1; + }; ## Builders method _build__gpp_obj { @@ -64,13 +69,77 @@ class Gitalist::Git::Object { return $v; } + method _cat_file_with_flag ($flag) { + $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1}) + } + method _build_modestr { - my $modestr = mode_to_string($self->mode); - return $modestr; + return _mode_str($self->mode); } - method _cat_file_with_flag ($flag) { - $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1}) + # via gitweb.pm circa line 1305 + use Fcntl ':mode'; + use constant { + S_IFINVALID => 0030000, + S_IFGITLINK => 0160000, + }; + + # submodule/subrepository, a commit object reference + sub S_ISGITLINK($) { + return (($_[0] & S_IFMT) == S_IFGITLINK) + } + + # convert file mode in octal to symbolic file mode string + sub _mode_str { + my $mode = shift; + + if (S_ISGITLINK($mode)) { + return 'm---------'; + } elsif (S_ISDIR($mode & S_IFMT)) { + return 'drwxr-xr-x'; + } elsif ($^O ne 'MSWin32' and S_ISLNK($mode)) { # this is ENOLINKS country, we can't stop here! + return 'lrwxrwxrwx'; + } elsif (S_ISREG($mode)) { + # git cares only about the executable bit + if ($mode & S_IXUSR) { + return '-rwxr-xr-x'; + } else { + return '-rw-r--r--'; + } + } else { + return '----------'; + } } } # end class + +__END__ + +=head1 NAME + +Gitalist::Git::Object - Model of a git object. + +=head1 SYNOPSIS + + my $object = Repository->get_object($sha1); + +=head1 DESCRIPTION + +Abstract base class for git objects. + + +=head1 ATTRIBUTES + + +=head1 METHODS + + +=head1 AUTHORS + +See L for authors. + +=head1 LICENSE + +See L for the license. + +=cut