Revert "Merge remote branch 't0m/json' into json"
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index 986180a..bcb36fa 100644 (file)
@@ -6,21 +6,11 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     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::MultiMethods;
     use Moose::Autobox;
     use List::MoreUtils qw/any zip/;
     use DateTime;
     use Encode qw/decode/;
-
-    use if $^O ne 'MSWin32', 'I18N::Langinfo', => qw/langinfo CODESET/;
-    BEGIN {
-        no strict 'subs';
-        *__owner = defined &langinfo
-            ? sub { map { decode(langinfo(CODESET), $_) } (getpwuid $_[0]->path->stat->uid)[6,0] }
-            : sub { return qw/OwnEr GroUp/ }
-        ;
-    }
-
+    use I18N::Langinfo qw/langinfo CODESET/;
     use Gitalist::Git::Object::Blob;
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
@@ -65,7 +55,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                      is => 'ro',
                      lazy => 1,
                      default => sub {
-                         -d $_[0]->path->parent->subdir->($_[0]->name)
+                         -d $_[0]->path->parent->subdir($_[0]->name)
                              ? 1 : 0
                          },
                      );
@@ -80,19 +70,16 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                         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
 
-    multi method get_object_or_head (SHA1 $sha1) {
+    method get_object_or_head (NonEmptySimpleStr $ref) {
+        my $sha1 = is_SHA1($ref) ? $ref : $self->head_hash($ref);
         $self->get_object($sha1);
     }
-    multi method get_object_or_head (NonEmptySimpleStr $ref) {
-        my $sha1 = $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;
@@ -144,7 +131,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
             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 = (
@@ -192,16 +179,6 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         # TODO - support compressed archives
     }
 
-    method diff ( Gitalist::Git::Object :$commit!,
-                  Bool :$patch?,
-                  Maybe[NonEmptySimpleStr] :$parent?,
-                  NonEmptySimpleStr :$filename?
-              ) {
-              return $commit->diff( patch => $patch,
-                                    parent => $parent,
-                                    filename => $filename);
-    }
-
     method reflog (@logargs) {
         my @entries
             =  $self->run_cmd(qw(log -g), @logargs)
@@ -262,7 +239,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     }
 
     method _build_owner {
-        my ($gecos, $name) = $self->__owner;
+        my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0];
         $gecos =~ s/,+$//;
         return length($gecos) ? $gecos : $name;
     }