Fleshed out the /tree action and fixed paging.
broquaint [Wed, 28 Oct 2009 21:51:47 +0000 (21:51 +0000)]
Also tidied added to diff tree output.

12 files changed:
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
root/static/css/site.css
templates/_diff_tree.tt2
templates/_log_pager.tt2
templates/_shortlog.tt2
templates/_tree.tt2
templates/commit-nav.tt2
templates/commit.tt2
templates/shortlog.tt2
templates/summary.tt2
templates/tree.tt2

index 9ec74e1..394d64d 100644 (file)
@@ -58,9 +58,9 @@ sub run_gitweb {
 }
 
 sub _get_commit {
-  my($self, $c) = @_;
+  my($self, $c, $haveh) = @_;
 
-  my $h = $c->req->param('h');
+  my $h = $haveh || $c->req->param('h');
   my $f = $c->req->param('f');
   my $m = $c->model('Git');
 
@@ -273,7 +273,7 @@ sub shortlog : Local {
       log_lines => [$c->model('Git')->list_revs(%logargs)],
       refs      => $c->model('Git')->references,
       action    => 'shortlog',
-      page      => $page + 1,
+      page      => $page,
   );
 }
 
@@ -296,12 +296,14 @@ The tree of a given commit.
 sub tree : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $self->_get_commit($c);
+  my $commit = $self->_get_commit($c, $c->req->param('hb'));
+  my $tree   = $c->model('Git')->get_object($c->req->param('h') || $commit->tree_sha1);
   $c->stash(
       # XXX Useful defaults needed ...
       commit    => $commit,
-      tree      => $c->model('Git')->get_object($c->req->param('hb')),
-      tree_list => [$c->model('Git')->list_tree($commit->sha1)],
+      tree      => $tree,
+      tree_list => [$c->model('Git')->list_tree($tree->sha1)],
+         path      => $c->req->param('f') || '',
       action    => 'tree',
   );
 }
index 8c6f23b..814321a 100644 (file)
@@ -538,16 +538,19 @@ sub parse_diff_tree {
 
   my @keys = qw(modesrc modedst sha1src sha1dst status src dst);
   my @ret;
-  while($diff->[0] =~ /^:\d+/) {
-       local $_ = shift @$diff;
+  while(@$diff and $diff->[0] =~ /^:\d+/) {
+       my $line = shift @$diff;
     # see. man git-diff-tree for more info
     # mode src, mode dst, sha1 src, sha1 dst, status, src[, dst]
-    my @vals = /^:(\d+) (\d+) ($SHA1RE) ($SHA1RE) ([ACDMRTUX])\t([^\t]+)(?:\t([^\n]+))?$/;
+    my @vals = $line =~ /^:(\d+) (\d+) ($SHA1RE) ($SHA1RE) ([ACDMRTUX]\d*)\t([^\t]+)(?:\t([^\n]+))?$/;
     my %line = zip @keys, @vals;
     # Some convenience keys
     $line{file}   = $line{src};
     $line{sha1}   = $line{sha1dst};
-    $line{is_new} = $line{sha1src} =~ /^0+$/;
+    $line{is_new} = $line{sha1src} =~ /^0+$/
+               if $line{sha1src};
+       @line{qw/status sim/} = $line{status} =~ /(R)(\d+)/
+      if $line{status} =~ /^R/;
     push @ret, \%line;
   }
 
index e06ec3d..f62959e 100644 (file)
@@ -1,26 +1,34 @@
+/* XXX A good framework would be handy */
+/* XXX Also colours. Lots of colours. */
 #body {
-    margin: 1em;
+  margin: 1em;
 }
 
 #commit-nav {
-    padding-bottom: 4px;
-    border-bottom: solid 1px #ccc;
-    font-style: italic;
+  padding-bottom: 4px;
+  border-bottom: solid 1px #ccc;
+  font-style: italic;
+}
+
+thead, tfoot {
+  color: #ddd;
+  font-size: small;
+  font-weight: bold;
 }
 
 /* /commit page */
 .commit-message {
-    font-family: monospace;
+  font-family: monospace;
 }
 div.commit-message {
-    background-color: #ddd;
-    padding: 5px;
+  background-color: #ddd;
+  padding: 5px;
 }
 .commit-info dt {
-    font-weight: bold;
+  font-weight: bold;
 }
 .commit-info dd {
-    font-family: monospace;
+  font-family: monospace;
 }
 
 .filename {
@@ -31,25 +39,25 @@ div.commit-message {
 }
 
 .path {
-    border-bottom: solid 1px #ddd;
-    padding: 3px 0;
-    font-weight: bold;
+  border-bottom: solid 1px #ddd;
+  padding: 3px 0;
+  font-weight: bold;
 }
 
 /* /heads */
 .heads .head {
-    font-weight: bold;
+  font-weight: bold;
 }
 .heads .current {
-    text-decoration: underline;
+  text-decoration: underline;
 }
 
 /* /blob */
 pre.blob {
-    background-color: #333;
-    color: #ddd;
-    border-left: solid 3px #c33;
-    padding: 5px;
-    padding-left: 15px;
-    margin: 10px 15px;
+  background-color: #333;
+  color: #ddd;
+  border-left: solid 3px #c33;
+  padding: 5px;
+  padding-left: 15px;
+  margin: 10px 15px;
 }
index c46bbb2..7544ab4 100644 (file)
@@ -2,13 +2,28 @@
  <thead>
   <tr>
    <td>file</td>
+   <td>status</td>
    <td>actions</td>
   </tr>
  </thead>
  <tbody>
-  [% FOREACH line IN diff_tree %]
+  [% FOREACH line IN diff_tree -%]
   <tr>
-   <td class='filename'>[% line.src %]</td>
+   <td class='filename'>
+    [% line.file %]
+   </td>
+   <td class='status'>
+    [%
+    SWITCH line.status;
+      CASE 'R';
+        '[moved from ' _ line.src _ ' with ' _ line.sim _ '% similarity]';
+      CASE 'A';
+        '[new file with mode: ' _ line.modedst _ ']';
+      CASE 'D';
+        '[deleted file]';
+    END;
+    %]
+   </td>
    <td class='action-list'>
      [% IF !line.is_new %]<a href="/blobdiff?p=[% project %];f=[% line.file %];h=[% commit.sha1 %];hp=[% commit.parent_sha1 %]">diff</a>[% END %]
      <a href="/blob?p=[% project %];f=[% line.file %];h=[% line.sha1 %];hb=[% commit.sha1 %]">blob</a>
@@ -20,6 +35,7 @@
  <tfoot>
   <tr>
    <td>file</td>
+   <td>status</td>
    <td>actions</td>
   </tr>
  </tfoot>
index d91c406..3c4c1d9 100644 (file)
@@ -1,9 +1,9 @@
 <div class='pager'>
  <a href='/[% action %]?p=[% project %];h=[% HEAD %]'>HEAD</a>
  [% IF log_lines.size == 50 %]
- <a href='/[% action %]?p=[% project %];h=[% commit.sha1 %];pg=[% page %]'>next</a>
+ <a href='/[% action %]?p=[% project %];h=[% commit.sha1 %];pg=[% page + 1 %]'>next</a>
  [% END %]
- [% IF log_lines.first.sha1 != HEAD %]
+ [% IF log_lines.first.sha1 != commit.sha1 %]
  <a href='/[% action %]?p=[% project %];h=[% commit.sha1 %];pg=[% page - 1 %]'>prev</a>
  [% END %]
 </div>
index 5d96591..329dcd1 100644 (file)
@@ -1,4 +1,3 @@
-[% INCLUDE '_log_pager.tt2' %]
 <table>
  <thead>
   <tr>
@@ -45,4 +44,3 @@
   </tr>
  </tfoot>
 </table>
-[% INCLUDE '_log_pager.tt2' %]
index e39b1a5..f7f1bb1 100644 (file)
@@ -13,7 +13,7 @@
    <td>[% item.modestr %]</td>
    [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
    <td class='filename'>
-    <a href="/[% theact %]?h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% item.file %]</a>
+    <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% IF path; path _ '/'; END; item.file %]">[% item.file %]</a>
    </td>
    <td class='action-list'>
      <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% theact %]</a>
@@ -32,4 +32,3 @@
   </tr>
  </tfoot>
 </table>
-
index 4954dfb..24f38bb 100644 (file)
@@ -4,5 +4,5 @@
     <a href="/log?p=[% project %];h=[% object.sha1 %]">log</a> |
     <a href="/commit?p=[% project %];h=[% object.sha1 %]">commit</a> |
     <a href="/commitdiff?p=[% project %];h=[% object.sha1 %]">commitdiff</a> |
-    <a href="/tree?p=[% project %];h=[% object.tree_sha1 %]">tree</a>
+    <a href="/tree?p=[% project %];h=[% object.tree_sha1 %];hb=[% object.sha1 %]">tree</a>
 </div>
index 97294f0..c671f41 100644 (file)
@@ -17,7 +17,9 @@
  <dt>commit</dt>
   <dd>[% commit.sha1 %]</dd>
  <dt>tree</dt>
-  <dd>[% commit.tree_sha1 %] <a href="/tree?p=[% project %];h=[% commit.sha1 %];hb=[% commit.tree_sha1 %]">tree</a></dd>
+  <dd>[% commit.tree_sha1 %]
+      <span class='action-list'><a href="/tree?p=[% project %];h=[% commit.tree_sha1 %];hb=[% commit.sha1 %]">tree</a></span>
+  </dd>
  [% FOREACH parent IN commit.parents %]
  <dt>parent</dt>
   <dd>[% parent %]
index b49e0e8..c8e9ef2 100644 (file)
@@ -4,4 +4,8 @@
 [% project %]
 </div>
 
-[% INCLUDE '_shortlog.tt2' %]
+[%
+INCLUDE '_log_pager.tt2';
+INCLUDE '_shortlog.tt2';
+INCLUDE '_log_pager.tt2';
+%]
index 2eb2e8a..f320ffc 100644 (file)
@@ -9,11 +9,11 @@
 </div>
 
 <div class='shortlog'>
-<h2>shortlog</h2>
+<h2><a href='/shortlog?p=[% project %]'>shortlog</a></h2>
 [% INCLUDE '_shortlog.tt2' %]
 </div>
 
 <div class='heads'>
-<h2>heads</h2>
+<h2><a href='/heads?p=[% project %]'>heads</a></h2>
 [% INCLUDE '_heads.tt2' %]
 </div>
index 8583cae..7b55830 100644 (file)
@@ -4,4 +4,15 @@
 [% commit.comment.substr(0, 85) %] ...
 </div>
 
+[% IF path -%]
+<div>
+ <a href='/tree?p=[% project %];hb=[% commit.sha1 %]'>[% project %]</a>
+ [% fullpath = ''-%]
+ [% FOREACH part IN path.split('/') -%]
+ / <a href='/tree?p=[% project %];h=[% tree.sha1 %];hb=[% commit.sha1 %];f=[% fullpath _ part %]'>[% part %]</a>
+ [% fullpath = fullpath _ part _ '/'; %]
+ [% END -%]
+</div>
+[% END -%]
+
 [% INCLUDE '_tree.tt2' %]