Fixed src and dst in diff data for files that had been added/deleted/etc.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Fragment / Ref.pm
index 7a63a95..e537896 100644 (file)
@@ -10,13 +10,15 @@ with qw/
 
 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
 
-after diff => sub {
+sub _diff {
     my ($self, $c) = @_;
     my $commit = $c->stash->{Commit};
+    my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
     my($tree, $patch) = $c->stash->{Repository}->diff(
         commit => $commit,
-        parent => $c->req->param('hp') || undef,
+        parent => $c->stash->{parent},
         patch  => 1,
+        %filename,
     );
     $c->stash(
       diff_tree => $tree,
@@ -24,17 +26,19 @@ after diff => sub {
       # XXX Hack hack hack, see View::SyntaxHighlight
       blobs     => [map $_->{diff}, @$patch],
       language  => 'Diff',
+      %filename,
     );
-};
+}
 
 after diff_fancy => sub {
     my ($self, $c) = @_;
+    $self->_diff($c);
     $c->forward('View::SyntaxHighlight');
 };
 
 after diff_plain => sub {
     my ($self, $c) = @_;
-    $c->response->content_type('text/plain; charset=utf-8');
+    $self->_diff($c);
 };
 
 after tree => sub {
@@ -48,7 +52,6 @@ after tree => sub {
     $c->stash(
         tree      => $tree,
         tree_list => [$repository->list_tree($tree->sha1)],
-        path      => $c->stash->{filename}, # FIXME?
     );
 };
 
@@ -86,4 +89,34 @@ after blob => sub {
         unless $c->stash->{no_wrapper};
 };
 
+after history => sub {
+    my ($self, $c) = @_;
+    my $repository  = $c->stash->{Repository};
+    my $filename    = $c->stash->{filename};
+
+    my %logargs = (
+       sha1   => $c->stash->{Commit}->sha1,
+       count  => 25, #Gitalist->config->{paging}{log} || 25,
+       ($filename ? (file => $filename) : ())
+    );
+
+    my $file = $repository->get_object(
+        $repository->hash_by_path(
+            $repository->head_hash,
+            $filename
+        )
+    );
+
+    my $page = $c->req->param('pg') || 0;
+    $logargs{skip} = $c->req->param('pg') * $logargs{count}
+        if $c->req->param('pg');
+
+    $c->stash(
+       log_lines => [$repository->list_revs(%logargs)],
+       refs      => $repository->references,
+       filename  => $filename,
+       filetype  => $file->type,
+    );
+};
+
 __PACKAGE__->meta->make_immutable;