Fix a load of links, and fix blob/blame/raw/history actions to (semi) work + tests
Tomas Doran [Wed, 20 Jan 2010 23:46:21 +0000 (23:46 +0000)]
lib/Gitalist/Controller/Commit.pm
lib/Gitalist/URIStructure/Commit.pm
root/_diff.tt2
root/_diff_tree.tt2
root/commit/diff_fancy.tt2
root/fragment/commit/diff_fancy.tt2
root/fragment/commit/tree.tt2
root/fragment/repository/shortlog.tt2
root/nav/actions.tt2
t/01app.t

index a2a3b49..1165bea 100644 (file)
@@ -8,8 +8,9 @@ with 'Gitalist::URIStructure::Commit';
 
 sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
 
-sub blob_plain : Chained('find_blob') Does('FilenameArgs') Args() {
+sub raw : Chained('find') Does('FilenameArgs') Args() {
     my ($self, $c) = @_;
+    $c->forward('find_blob');
 
     $c->response->content_type('text/plain; charset=utf-8');
     $c->response->body(delete $c->stash->{blob});
index c711937..584b471 100644 (file)
@@ -28,7 +28,7 @@ sub commit : Chained('find') PathPart('') Args(0) {}
 
 sub tree : Chained('find') Does('FilenameArgs') Args() {}
 
-sub find_blob : Chained('find') PathPart('') CaptureArgs(0) {
+sub find_blob : Action {
     my ($self, $c) = @_;
     # FIXME - Eugh!
     my $h  = $c->stash->{Repository}->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename})
@@ -36,14 +36,15 @@ sub find_blob : Chained('find') PathPart('') CaptureArgs(0) {
     $c->stash(blob => $c->stash->{Repository}->get_object($h)->content);
 }
 
-sub blob : Chained('find_blob') Does('FilenameArgs') Args() {}
+sub blob : Chained('find') Does('FilenameArgs') Args() {
+    my ($self, $c) = @_;
+    $c->forward('find_blob');
+}
 
 sub blame : Chained('find') Does('FilenameArgs') Args() {}
 
 sub history : Chained('find') Does('FilenameArgs') Args() {}
 
-sub raw : Chained('find') Does('FilenameArgs') Args() {}
-
 sub shortlog : Chained('find') Does('FilenameArgs') Args() {}
 
 1;
index b3062eb..8577bf6 100644 (file)
@@ -2,8 +2,8 @@
 [% FOREACH item IN diff %]
 <div class='diff-head'>
  diff --git
- <a href='[% c.uri_for("blob", {h=item.src, f=item.file}) %]'>[% item.a %]</a>
- <a href='[% c.uri_for("blob", {h=item.dst, f=item.file}) %]'>[% item.b %]</a>
+ <a href='[% c.uri_for_action("/commit/blob", [Repository.name, item.src], item.file) %]'>[% item.a %]</a>
+ <a href='[% c.uri_for_action("/commit/blob", [Repository.name, item.dst], item.file) %]'>[% item.b %]</a>
 </div>
 <div class='diff-index'>
  [% item.index %]
index 2057772..afcc1db 100644 (file)
@@ -32,9 +32,9 @@
     %]
    </td>
    <td class='action-list'>
-     [% IF !line.is_new %]<a href="[% c.uri_for("blobdiff", {hp=commit.parent_sha1, h=commit.sha1, f=line.file}) %]">diff</a>[% END %]
-     <a href="[% c.uri_for("blob", {h=line.sha1, hb=commit.sha1, f=line.file}) %]">blob</a>
-     [% IF !line.is_new %]<a href="[% c.uri_for("shortlog", {hb=commit.sha1, f=line.file}) %]">history</a>[% END %]
+     [% IF !line.is_new %]<a href="[% c.uri_for_action("/commit/diff", [Repository.name, Commit.sha1], line.file.to_path) %]">diff</a>[% END %]
+     <a href="[% c.uri_for_action("/commit/blob", [Repository.name, Commit.sha1], line.file.to_path) %]">blob</a>
+     [% IF !line.is_new %]<a href="[% c.uri_for("/commit/shortlog", [Repository.name, Commit.sha1], line.file.to_path) %]">history</a>[% END %]
    </td>
   </tr>
   [% END %]
index 716e61a..a2ce0bd 100644 (file)
@@ -10,5 +10,5 @@
   </div>
 
 
-  [% subinclude('/fragment/commit/diff_fancy', c.req.captures) %]
+  [% subinclude('/fragment/commit/diff_fancy', c.req.captures c.req.args.to_path) %]
 </div>
index bb44da2..58a3943 100644 (file)
@@ -1,4 +1,4 @@
-[%
+MOO[%
   # In the case of merge commits there will be no diff tree.
   IF diff_tree.size > 0;
     INCLUDE '_diff_tree.tt2';
index 16f7ae8..fc3c695 100644 (file)
@@ -19,8 +19,8 @@
    <td class='file-mode'>[% item.modestr %]</td>
    [%-
         action_type = item.type == 'tree' ? 'tree' : 'blob';
-        action_for_link = item.type == 'tree' ? c.action : c.controller.action_for('blob');
-        blob_or_tree_link = c.uri_for(action_for_link, c.req.captures, c.req.args.to_path(item.file))
+        action_for_link = item.type == 'tree' ? '/commit/tree' : '/commit/blob';
+        blob_or_tree_link = c.uri_for_action(action_for_link, c.req.captures, c.req.args.to_path(item.file))
    -%]
    <td class='file-name'>
     <a href="[% blob_or_tree_link %]">[% item.file %]</a>
@@ -28,6 +28,7 @@
    <td class='action-list'>
      <a href="[% blob_or_tree_link %]">[% theact %]</a>
          [% IF item.type == 'blob' %]
+         <a href="[% c.uri_for_action('/commit/blob', c.req.captures, c.req.args.to_path(item.file)) %]">blob</a>
          <a href="[% c.uri_for_action('/commit/blame', c.req.captures, c.req.args.to_path(item.file)) %]">blame</a>
          [% END %]
      <a href="[% c.uri_for_action('/commit/history', c.req.captures, c.req.args.to_path(item.file)) %]">history</a>
index fa88a3b..6008dbd 100644 (file)
@@ -32,7 +32,7 @@
    </td>
    <td class='action-list'>
      <a href="[% c.uri_for_action("/commit/commit", [Repository.name, line.sha1]) %]">commit</a>
-     <a href="[% c.uri_for_action("/commit/diff", [Repository.name, line.sha1]) %]">commitdiff</a>
+     <a href="[% c.uri_for_action("/commit/diff_fancy", [Repository.name, line.sha1]) %]">commitdiff</a>
      <a href="[% c.uri_for_action("/commit/tree", [Repository.name, line.sha1]) %]">tree</a>
    </td>
   </tr>
index 4ed51ee..aa3fa0e 100644 (file)
@@ -12,7 +12,7 @@
     [% IF filename %]
     &sect;
     <a href="[% c.uri_for_action('/commit/blob', [c.req.captures.0, Commit.sha1], filename) %]">blob</a> &bull;
-    <a href="[% c.uri_for_action('/commit/blob_plain', [c.req.captures.0, Commit.sha1], filename) %]">raw</a> &bull;
+    <a href="[% c.uri_for_action('/commit/raw', [c.req.captures.0, Commit.sha1], filename) %]">raw</a> &bull;
     <a href="[% c.uri_for_action('/commit/blame', [c.req.captures.0, Commit.sha1], filename)  %]">blame</a> &bull;
     <a href="[% c.uri_for_action('/commit/shortlog', [c.req.captures.0, Commit.sha1], filename)  %]">history</a> &bull;
     <a href="[% c.uri_for(c.controller.action_for('commit'), [c.req.captures.0, Repository.head_hash]) %]">HEAD</a>
index 57dba80..68d3bf4 100644 (file)
--- a/t/01app.t
+++ b/t/01app.t
@@ -33,14 +33,15 @@ like $response->content, qr/Page not found/, 'invalid repository handled correct
   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patch');
   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patches/1');
   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patches/2');
-  
+  test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/history/dir1');
+  test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/blame/file1');
+  test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/raw/file1');
+  test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/blob/file1');
+
   TODO: {
       local $TODO = "FIXME";
       test('search', 'type=commit&text=added');
 
-
-      test('blob', 'f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
-
       # FIXME - What's the difference here?
       #test('patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e');
       #test('patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e;hp=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');