Now heads show up in the shortlog and the current head is marked up in the heads...
broquaint [Mon, 26 Oct 2009 22:13:43 +0000 (22:13 +0000)]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
root/static/css/site.css
t/model_Git.t
templates/_heads.tt2
templates/_shortlog.tt2

index dc79c49..ff5efac 100644 (file)
@@ -60,9 +60,12 @@ sub run_gitweb {
 sub _get_commit {
   my($self, $c) = @_;
 
+  my $h = $c->req->param('h');
+  my $f = $c->req->param('f');
+
   # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
-  my $hash = $c->req->param('h')
-          || ($c->req->param('f') ? $c->model('Git')->hash_by_path($c->req->param('f')) : '')
+  my $hash = ($h =~ /[^a-f0-9]/ ? $c->model('Git')->head_hash($h) : $h)
+          || ($f && $c->model('Git')->hash_by_path($f))
           || $c->model('Git')->head_hash
           # XXX This could definitely use more context.
           || Carp::croak("Couldn't find a hash for the commit object!");
@@ -111,8 +114,10 @@ sub summary : Local {
   $c->stash(
     commit    => $commit,
     info      => $c->model('Git')->project_info($c->model('Git')->project),
-    log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1, count => 17)],
+    log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1, count => 16)],
+    refs      => $c->model('Git')->references,
     heads     => [$c->model('Git')->heads],
+    HEAD      => $c->model('Git')->head_hash,
     action    => 'summary',
   );
 }
@@ -129,6 +134,7 @@ sub heads : Local {
   $c->stash(
     commit => $self->_get_commit($c),
     heads  => [$c->model('Git')->heads],
+    HEAD   => $c->model('Git')->head_hash,
     action => 'heads',
   );
 }
@@ -208,7 +214,8 @@ sub shortlog : Local {
   # XXX Needs paging.
   $c->stash(
       commit    => $commit,
-      log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1)],
+      log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1)],
+      refs      => $c->model('Git')->references,
       action    => 'shortlog',
   );
 }
index 953cfcb..a7165f1 100644 (file)
@@ -277,14 +277,14 @@ sub dir_from_project_name {
 
 =head2 head_hash
 
-Find the C<HEAD> of given (or current) project.
+Find the hash of a given head (defaults to HEAD) of given (or current) project.
 
 =cut
 
 sub head_hash {
-  my ($self, $project) = @_;
+  my ($self, $head, $project) = @_;
 
-  my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify HEAD/ );
+  my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify/, $head || 'HEAD' );
   return unless defined $output;
 
   my ($head) = $output =~ /^($SHA1RE)$/;
@@ -318,6 +318,7 @@ sub list_tree {
 
     push @ret, {
       mode    => oct $mode,
+         # XXX I wonder why directories always turn up as 040000 ...
       modestr => $self->get_object_mode_string({mode=>oct $mode}),
       type    => $type,
       object  => $object,
@@ -524,13 +525,13 @@ array of hashes.
 sub list_revs {
   my ($self, %args) = @_;
 
-  $args{rev} ||= $self->head_hash($args{project});
+  $args{sha1} ||= $self->head_hash($args{project});
 
   my $output = $self->run_cmd_in($args{project} || $self->project, 'rev-list',
     '--header',
     (defined $args{ count } ? "--max-count=$args{count}" : ()),
     (defined $args{ skip  } ? "--skip=$args{skip}"       : ()),
-    $args{rev},
+    $args{sha1},
     '--',
     ($args{file} ? $args{file} : ()),
   );
index 4d05680..d672ba2 100644 (file)
@@ -35,3 +35,11 @@ div.commit-message {
     padding: 3px 0;
     font-weight: bold;
 }
+
+/* /heads */
+.heads .head {
+    font-weight: bold;
+}
+.heads .current {
+    text-decoration: underline;
+}
index 09a4552..dc069c8 100644 (file)
@@ -31,7 +31,7 @@ is( $projectList->[0]->{name}, 'bare.git', 'list_projects has correct name for "
 # Liberally borrowed from rafl's gitweb
 my $repo = 'repo1';
 
-like($m->head_hash($repo), qr/^([0-9a-fA-F]{40})$/, 'get_head_hash');
+like($m->head_hash('HEAD', $repo), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
 
 {
     my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', $repo);
index 6d38e75..c8f4e61 100644 (file)
@@ -1,4 +1,4 @@
-<table>
+<table class='heads'>
  <thead>
   <tr>
    <td>age</td>
@@ -11,7 +11,7 @@
  [% FOREACH head IN heads %]
   <tr>
    <td>[% head.last_change %]</td>
-   <td>[% head.name %]</td>
+   <td class='head[% head.sha1 == HEAD ? ' current' : '' %]'>[% head.name %]</td>
    <td class='action-list'>
      <a href="/shortlog?p=[% project %];h=[% head.sha1 %]">shortlog</a>
      <a href="/log?p=[% project %];h=[% head.sha1 %]">log</a>
index 8f10392..7892534 100644 (file)
    <td>[% line.sha1.substr(0, 6) %]</td>
    <td>[% line.authored_time %]</td>
    <td>[% line.author.name | html %]</td>
-   <td class='commit-message'>[% line.comment.substr(0, 50) | html %]</td>
+   <td>
+    [% line.comment.substr(0, 50) | html %]
+    <span class='refs'>
+     [% FOREACH ref IN refs.${line.sha1} %]
+     <span class='[% ref.search('^remotes/') ? 'remote' : 'head' %]'>
+      <a href='/shortlog?p=[% project %];h=refs/[% ref %]'>[% ref.replace('^(remote|head)s/', '') %]</a>
+     </span>
+     [% END %]
+    </span>
+   </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>