Now heads show up in the shortlog and the current head is marked up in the heads...
[catagits/Gitalist.git] / lib / Gitalist / Model / Git.pm
index e147f9b..a7165f1 100644 (file)
@@ -85,7 +85,8 @@ A wrapper for the equivalent L<Git::PurePerl> method.
 =cut
 
 sub get_object {
-  $_[0]->gpp->get_object($_[1]);
+  # We either want an object or undef, *not* an empty list.
+  return $_[0]->gpp->get_object($_[1]) || undef;
 }
 
 =head2 is_git_repo
@@ -276,14 +277,14 @@ sub dir_from_project_name {
 
 =head2 head_hash
 
-Find the C<HEAD> of given (or current) project.
+Find the hash of a given head (defaults to HEAD) of given (or current) project.
 
 =cut
 
 sub head_hash {
-  my ($self, $project) = @_;
+  my ($self, $head, $project) = @_;
 
-  my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify HEAD/ );
+  my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify/, $head || 'HEAD' );
   return unless defined $output;
 
   my ($head) = $output =~ /^($SHA1RE)$/;
@@ -317,6 +318,7 @@ sub list_tree {
 
     push @ret, {
       mode    => oct $mode,
+         # XXX I wonder why directories always turn up as 040000 ...
       modestr => $self->get_object_mode_string({mode=>oct $mode}),
       type    => $type,
       object  => $object,
@@ -420,7 +422,7 @@ sub raw_diff {
     || scalar @revs > 2
     || any { !$self->valid_rev($_) } @revs;
 
-  return $self->command(diff => @revs);
+  return $self->command(diff => '--full-index', @revs);
 }
 
 =begin
@@ -459,11 +461,11 @@ sub diff {
   my @diff = $self->raw_diff(@revs);
 
   my @ret;
-  for my $line (@diff) {
+  for (@diff) {
        # This regex is a little pathological.
-       if($line =~ m{^diff --git (a/(.*?)) (b/\2)}) {
+       if(m{^diff --git (a/(.*?)) (b/\2)}) {
       push @ret, {
-       head => $line,
+       head => $_,
        a    => $1,
        b    => $3,
                file => $2,
@@ -472,7 +474,7 @@ sub diff {
          next;
        }
 
-       if($line =~ /^index (\w+)\.\.(\w+) (\d+)$/) {
+       if(/^index (\w+)\.\.(\w+) (\d+)$/) {
          @{$ret[-1]}{qw(index src dst mode)} = ($_, $1, $2, $3);
          next
     }
@@ -481,7 +483,7 @@ sub diff {
          unless @ret;
 
        # XXX Somewhat hacky. Ahem.
-       $ret[-1]{diff} .= "$line\n";
+       $ret[-1]{diff} .= "$_\n";
   }
 
   return @ret;
@@ -523,13 +525,13 @@ array of hashes.
 sub list_revs {
   my ($self, %args) = @_;
 
-  $args{rev} ||= $self->head_hash($args{project});
+  $args{sha1} ||= $self->head_hash($args{project});
 
   my $output = $self->run_cmd_in($args{project} || $self->project, 'rev-list',
     '--header',
     (defined $args{ count } ? "--max-count=$args{count}" : ()),
     (defined $args{ skip  } ? "--skip=$args{skip}"       : ()),
-    $args{rev},
+    $args{sha1},
     '--',
     ($args{file} ? $args{file} : ()),
   );