Added first cut of /shortlog action and simplified the parse_rev_list() method.
broquaint [Fri, 23 Oct 2009 16:16:39 +0000 (17:16 +0100)]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
lib/Gitalist/View/SyntaxHighlight.pm
root/static/css/site.css
templates/commit.tt2
templates/shortlog.tt2 [new file with mode: 0644]

index 06c0a8e..7fac165 100644 (file)
@@ -129,7 +129,7 @@ sub reflog : Local {
 
 =head2 commit
 
-Exposes a given commit. Probably too simple currently.
+Exposes a given commit.
 
 =cut
 
@@ -142,6 +142,21 @@ sub commit : Local {
   );
 }
 
+=head2 shortlog
+
+Expose an abbreviated log of a given sha1.
+
+=cut
+
+sub shortlog : Local {
+  my ( $self, $c ) = @_;
+
+  $c->stash(
+      commit => $c->model('Git')->get_object($c->req->param('h')),
+      action => 'shortlog',
+  );
+}
+
 =head2 auto
 
 Populate the header and footer. Perhaps not the best location.
index 0deef1a..aa45676 100644 (file)
@@ -425,62 +425,30 @@ sub diff {
   return $output;
 }
 
-{
-  my $formatter = DateTime::Format::Mail->new;
-
 =head2 parse_rev_list
 
 Given the output of the C<rev-list> command return a list of hashes.
 
 =cut
 
-  sub parse_rev_list {
-    my ($self, $output) = @_;
-    my @ret;
-
-    my @revs = split /\0/, $output;
-
-    for my $rev (split /\0/, $output) {
-      for my $line (split /\n/, $rev, 6) {
-        chomp $line;
-        next unless $line;
-
-        if ($self->valid_rev($line)) {
-          push @ret, {rev => $line};
-          next;
-        }
-
-        if (my ($key, $value) = $line =~ /^(tree|parent)\s+(.*)$/) {
-          $ret[-1]->{$key} = $value;
-          next;
-        }
-
-        if (my ($key, $value, $epoch, $tz) = $line =~ /^(author|committer)\s+(.*)\s+(\d+)\s+([+-]\d+)$/) {
-          $ret[-1]->{$key} = $value;
-          eval {
-            $ret[-1]->{ $key . "_datetime" } = DateTime->from_epoch(epoch => $epoch);
-            $ret[-1]->{ $key . "_datetime" }->set_time_zone($tz);
-            $ret[-1]->{ $key . "_datetime" }->set_formatter($formatter);
-            };
-
-          if ($@) {
-            $ret[-1]->{ $key . "_datetime" } = "$epoch $tz";
-          }
-
-          if (my ($name, $email) = $value =~ /^([^<]+)\s+<([^>]+)>$/) {
-            $ret[-1]->{ $key . "_name"  } = $name;
-            $ret[-1]->{ $key . "_email" } = $email;
-          }
-        }
-
-        $line =~ s/^\n?\s{4}//;
-        $ret[-1]->{longmessage} = $line;
-        $ret[-1]->{message} = (split /\n/, $line, 2)[0];
-      }
-    }
+sub parse_rev_list {
+  my ($self, $output) = @_;
+  my @ret;
+
+  my @revs = split /\0/, $output;
 
-    return @ret;
+  for my $rev (split /\0/, $output) {
+    for my $line (split /\n/, $rev, 6) {
+      chomp $line;
+      next unless $line;
+
+      if ($self->valid_rev($line)) {
+        push @ret, $self->get_object($line);
+      }
+       }
   }
+
+  return @ret;
 }
 
 =head2 list_revs
index c030f03..da9e6b7 100644 (file)
@@ -13,6 +13,8 @@ use HTML::Entities qw(encode_entities);
 sub process {
     my($self, $c) = @_;
 
+    # If we're not going to highlight the blob unsure that it's ready to go
+    # into HTML at least.
     if($c->stash->{filename} =~ /\.p[lm]$/) {
         # via
         # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
index 2941275..4d05680 100644 (file)
@@ -11,6 +11,8 @@
 /* /commit page */
 .commit-message {
     font-family: monospace;
+}
+div.commit-message {
     background-color: #ddd;
     padding: 5px;
 }
index bb029eb..82db3d7 100644 (file)
@@ -1,6 +1,6 @@
 [% INCLUDE 'commit-nav.tt2' object = commit %]
 <div class='commit-message'>
-[% commit.comment.substr(0, 50) %] ...
+[% commit.comment.substr(0, 85) %] ...
 [% FOREACH ref IN c.model('Git').refs_for(commit.sha1) %]
  <span class='refs'><a href='/shortlog?h=[% commit.sha1 %];hb=[% ref %]'>[% ref %]</a></span>
 [% END %]
 
 <table class='diff-tree'>
  <thead>
-  <td>file</td>
-  <td>actions</td>
+  <tr>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
  </thead>
  <tbody>
   [% FOREACH line IN c.model('Git').diff_tree(commit) %]
   [% END %]
  </tbody>
  <tfoot>
-  <td>file</td>
-  <td>actions</td>
+  <tr>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
  </tfoot>
 </table>
 
diff --git a/templates/shortlog.tt2 b/templates/shortlog.tt2
new file mode 100644 (file)
index 0000000..6211d3b
--- /dev/null
@@ -0,0 +1,40 @@
+[% INCLUDE 'commit-nav.tt2' object = commit %]
+
+<div>
+[% project %]
+</div>
+
+<table>
+ <thead>
+  <tr>
+   <td>time</td>
+   <td>author</td>
+   <td>message</td>
+   <td>actions</td>
+  </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH line IN c.model('Git').list_revs('rev', commit.sha1) %]
+  <tr>
+   <td>[% line.authored_time %]</td>
+   <td>[% line.author.name | html %]</td>
+   <td class='commit-message'>[% '[' _ line.sha1.substr(0, 6) _ '] ' _ line.comment.substr(0, 50) | html %]</td>
+   <td class='action-list'>
+     <a href="/commit?p=[% project %];h=[% line.sha1 %]">commit</a>
+     <a href="/commitdiff?p=[% project %];h=[% line.sha1 %]">commitdiff</a>
+     <a href="/tree?p=[% project %];h=[% line.sha1 %];hb=[% line.tree_sha1 %]">history</a>
+   </td>
+  </tr>
+ [% END %]
+ </tbody>
+
+ <tfoot>
+  <tr>
+   <td>time</td>
+   <td>author</td>
+   <td>message</td>
+   <td>actions</td>
+  </tr>
+ </tfoot>
+</table>