Fixed parameter handling for tree & shortlog so they DTRT WRT filename param.
Dan Brook [Sun, 22 Nov 2009 12:31:24 +0000 (12:31 +0000)]
Used standard path nav in tree template.

lib/Gitalist/Controller/Root.pm
root/_tree.tt2
root/tree.tt2

index 12701c2..cd09a42 100644 (file)
@@ -39,10 +39,10 @@ sub _get_object {
           # XXX This could definitely use more context.
           || Carp::croak("Couldn't find a hash for the commit object!");
 
-  my $commit = $m->get_object($hash)
-    or Carp::croak("Couldn't find a commit object for '$hash' in '$pd'!");
+  my $obj = $m->get_object($hash)
+    or Carp::croak("Couldn't find a object for '$hash' in '$pd'!");
 
-  return $commit;
+  return $obj;
 }
 
 =head2 index
@@ -336,7 +336,7 @@ sub shortlog : Local {
   my ( $self, $c ) = @_;
 
   my $project  = $c->stash->{Project};
-  my $commit   = $self->_get_object($c);
+  my $commit   = $self->_get_object($c, $c->req->param('hb'));
   my $filename = $c->req->param('f') || '';
 
   my %logargs = (
@@ -371,7 +371,7 @@ sub log : Local {
 
 # For legacy support.
 sub history : Local {
-  $_[0]->shortlog(@_[1 .. $#_]);
+  $_[1]->forward('shortlog');
 }
 
 =head2 tree
@@ -384,7 +384,11 @@ sub tree : Local {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   my $commit  = $self->_get_object($c, $c->req->param('hb'));
-  my $tree    = $self->_get_object($c, $c->req->param('h') || $commit->tree_sha1);
+  my $filename = $c->req->param('f') || '';
+  my $tree    = $filename
+    ? $project->get_object($project->hash_by_path($commit->sha1, $filename))
+    : $project->get_object($commit->tree_sha1)
+  ;
   $c->stash(
       commit    => $commit,
       tree      => $tree,
index d6c8f41..176f36a 100644 (file)
   <tr>
    <td class='file-mode'>[% item.modestr %]</td>
    [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
+   [% fullpath = path ? path _ '/' _ item.file : item.file %]
    <td class='file-name'>
-    <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=(path ? path _ '/' _ item.file : item.file)}) %]">[% item.file %]</a>
+    <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% item.file %]</a>
    </td>
    <td class='action-list'>
-     <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=item.file}) %]">[% theact %]</a>
-     <a href="[% c.uri_for('history', {h=item.sha1, hb=commit.sha1, f=item.file}) %]">history</a>
+     <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% theact %]</a>
+     <a href="[% c.uri_for('shortlog', {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">history</a>
      [% IF item.type == 'blob' %]
-     <a href="[% c.uri_for('raw', {hb=commit.sha1, f=item.file}) %]">raw</a>
+     <a href="[% c.uri_for('raw', {hb=commit.sha1, f=fullpath}) %]">raw</a>
      [% END %]
    </td>
   </tr>
index b82a117..18a3abf 100644 (file)
@@ -4,15 +4,10 @@
 [% short_cmt(commit.comment) | html %] ...
 </div>
 
-[% IF path -%]
-<div>
- <a href='[% c.uri_for("tree", {hb=commit.sha1}) %]'>[% Project.name %]</a>
- [% fullpath = ''-%]
- [% FOREACH part IN path.split('/') -%]
- / <a href='[% c.uri_for("tree", {h=tree.sha1, hb=commit.sha1, f=fullpath _ part}) %]'>[% part %]</a>
- [% fullpath = fullpath _ part _ '/'; %]
- [% END -%]
-</div>
-[% END -%]
+[%
+  IF path;
+    INCLUDE 'nav/path.tt2' filename = path, head = commit;
+  END;
 
-[% INCLUDE '_tree.tt2' %]
+  INCLUDE '_tree.tt2';
+%]