Remove Repository->list_tree.
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index d6fefae..ffc0e89 100644 (file)
@@ -10,7 +10,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     use List::MoreUtils qw/any zip/;
     use DateTime;
     use Encode qw/decode/;
-#    use I18N::Langinfo qw/langinfo CODESET/;
+    use I18N::Langinfo qw/langinfo CODESET/;
     use Gitalist::Git::Object::Blob;
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
@@ -55,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
                          },
                      );
@@ -70,10 +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
+
+    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;
@@ -82,12 +88,6 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         return $sha1;
     }
 
-    method list_tree (SHA1 $sha1?) {
-        $sha1 ||= $self->head_hash;
-        my $object = $self->get_object($sha1);
-        return @{$object->tree};
-    }
-
     method get_object (NonEmptySimpleStr $sha1) {
         unless (is_SHA1($sha1)) {
             $sha1 = $self->head_hash($sha1);
@@ -102,20 +102,6 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         );
     }
 
-    method hash_by_path ($base, $path = '', $type?) {
-        $path =~ s{/+$}();
-        # FIXME should this really just take the first result?
-        my @paths = $self->run_cmd('ls-tree', $base, '--', $path)
-            or return;
-        my $line = $paths[0];
-
-        #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
-        $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
-        return defined $type && $type ne $2
-            ? ()
-                : $3;
-    }
-
     method list_revs ( NonEmptySimpleStr :$sha1!,
                        Int :$count?,
                        Int :$skip?,
@@ -125,7 +111,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 = (
@@ -173,16 +159,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)
@@ -237,17 +213,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 {
-       # XXX No I18N::Langinfo & getpwuid make win32 sad :(
-        # my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0];
-       my ($gecos, $name) = do {
-           local $@;
-           my($g,$n) = eval { (getpwuid $self->path->stat->uid)[6,0] };
-           !$@ ? ($g,$n) : qw(OwenEr GroUp);
-       };
+        my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0];
         $gecos =~ s/,+$//;
         return length($gecos) ? $gecos : $name;
     }
@@ -399,20 +371,10 @@ Hashref of ArrayRefs for each reference.
 
 Return the sha1 for HEAD, or any specified head.
 
-=head2 list_tree ($sha1?)
-
-Return an array of contents for a given tree.
-The tree is specified by sha1, and defaults to HEAD.
-Each item is a L<Gitalist::Git::Object>.
-
 =head2 get_object ($sha1)
 
 Return an appropriate subclass of L<Gitalist::Git::Object> for the given sha1.
 
-=head2 hash_by_path ($sha1, $path, $type?)
-
-Returns the sha1 for a given path, optionally limited by type.
-
 =head2 list_revs ($sha1, $count?, $skip?, \%search?, $file?)
 
 Returns a list of revs for the given head ($sha1).