Add the serializeable role everywhere
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index 0269853..1d7500c 100644 (file)
@@ -10,20 +10,13 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     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;
     use Gitalist::Git::Object::Tag;
+    
+    with 'Gitalist::Serializeable';
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
 
@@ -83,6 +76,12 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     }
 
     ## 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;
@@ -134,7 +133,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 = (
@@ -182,16 +181,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 :$file?
-              ) {
-              return $commit->diff( patch => $patch,
-                                    parent => $parent,
-                                    file => $file);
-    }
-
     method reflog (@logargs) {
         my @entries
             =  $self->run_cmd(qw(log -g), @logargs)
@@ -246,11 +235,13 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
             $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;
     }
 
     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;
     }