Tidied up the /blob action and the commit-nav.tt2 links.
broquaint [Fri, 23 Oct 2009 14:21:16 +0000 (15:21 +0100)]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
lib/Gitalist/View/SyntaxHighlight.pm
root/static/css/site.css
templates/blob.tt2
templates/commit-nav.tt2
templates/commit.tt2

index 4f9228c..06c0a8e 100644 (file)
@@ -91,13 +91,21 @@ The blob action i.e the contents of a file.
 sub blob : Local {
   my ( $self, $c ) = @_;
 
+  my $h  = $c->req->param('h')
+       || $c->model('Git')->hash_by_path($c->req->param('f'))
+       || die "No file or sha1 provided.";
+  my $hb = $c->req->param('hb')
+       || $c->model('Git')->head_hash
+       || die "Couldn't discern the corresponding head.";
+
   $c->stash(
-    blob   => $c->model('Git')->get_object($c->req->param('h'))->content,
-    action => 'blob',
+    blob     => $c->model('Git')->get_object($h)->content,
+    head     => $c->model('Git')->get_object($hb),
+    filename => $c->req->param('f') || '',
+    action   => 'blob',
   );
 
-  $c->forward('View::Syntax')
-    if $c->req->param('f') and $c->req->param('f') =~ /\.p[lm]$/;
+  $c->forward('View::SyntaxHighlight');
 }
 
 =head2 reflog
index abc212b..0233981 100644 (file)
@@ -187,10 +187,10 @@ sub git_dir_from_project_name {
   return dir($self->repo_dir)->subdir($project);
 }
 
-sub get_head_hash {
+sub head_hash {
   my ($self, $project) = @_;
 
-  my $output = $self->run_cmd_in($self->project, qw/rev-parse --verify HEAD/ );
+  my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify HEAD/ );
   return unless defined $output;
 
   my ($head) = $output =~ /^($SHA1RE)$/;
@@ -200,7 +200,7 @@ sub get_head_hash {
 sub list_tree {
   my ($self, $project, $rev) = @_;
 
-  $rev ||= $self->get_head_hash($project);
+  $rev ||= $self->head_hash($project);
 
   my $output = $self->run_cmd_in($project, qw/ls-tree -z/, $rev);
   return unless defined $output;
@@ -237,19 +237,19 @@ sub get_object_type {
   return $output;
 }
 
-sub get_hash_by_path {
+sub hash_by_path {
   my($self, $base, $path, $type) = @_;
 
   $path =~ s{/+$}();
 
-  my $line = $self->run_cmd_in($self->project, 'ls-tree', $base, '--', $path)
+  my($line) = $self->command('ls-tree', $base, '--', $path)
     or return;
 
   #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa       panic.c'
   $line =~ m/^([0-9]+) (.+) ($SHA1RE)\t/;
   return defined $type && $type ne $2
     ? ()
-    : return $3;
+    : $3;
 }
 
 sub cat_file {
@@ -341,7 +341,7 @@ sub diff {
 sub list_revs {
   my ($self, $project, %args) = @_;
 
-  $args{rev} ||= $self->get_head_hash($project);
+  $args{rev} ||= $self->head_hash($project);
 
   my $output = $self->run_cmd_in($project, 'rev-list',
     '--header',
@@ -509,7 +509,7 @@ sub diff_tree {
                my %line = zip @keys, @vals;
                # Some convenience keys
                $line{file}   = $line{src};
-               $line{sha1}   = $line{sha1src};
+               $line{sha1}   = $line{sha1dst};
                $line{is_new} = $line{sha1src} =~ /^0+$/;
                \%line;
        } @dtout;
index 02845c6..c030f03 100644 (file)
@@ -8,40 +8,46 @@ extends 'Catalyst::View';
 use Syntax::Highlight::Engine::Kate ();
 use Syntax::Highlight::Engine::Kate::Perl ();
 
+use HTML::Entities qw(encode_entities);
+
 sub process {
     my($self, $c) = @_;
-    # via
-    # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
-    eval {
-        no warnings 'redefine';
-        local *Syntax::Highlight::Engine::Kate::Template::logwarning
-          = sub { die @_ }; # i really don't care
-        my $hl = Syntax::Highlight::Engine::Kate->new(
-            language      => 'Perl',
-            substitutions => {
-                "<"  => "&lt;",
-                ">"  => "&gt;",
-                "&"  => "&amp;",
-                q{'} => "&apos;",
-                q{"} => "&quot;",
-            },
-            format_table => {
-                # convert Kate's internal representation into
-                # <span class="<internal name>"> value </span>
-                map {
-                    $_ => [ qq{<span class="$_">}, '</span>' ]
-                }
-                  qw/Alert BaseN BString Char Comment DataType
-                     DecVal Error Float Function IString Keyword
-                     Normal Operator Others RegionMarker Reserved
-                     String Variable Warning/,
-            },
-        );
-
-        $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
-    };
-
-    warn $@ if $@;
+
+    if($c->stash->{filename} =~ /\.p[lm]$/) {
+        # via
+        # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
+        eval {
+            no warnings 'redefine';
+            local *Syntax::Highlight::Engine::Kate::Template::logwarning
+              = sub { die @_ }; # i really don't care
+            my $hl = Syntax::Highlight::Engine::Kate->new(
+                language      => 'Perl',
+                substitutions => {
+                    "<"  => "&lt;",
+                    ">"  => "&gt;",
+                    "&"  => "&amp;",
+                    q{'} => "&apos;",
+                    q{"} => "&quot;",
+                },
+                format_table => {
+                    # convert Kate's internal representation into
+                    # <span class="<internal name>"> value </span>
+                    map {
+                        $_ => [ qq{<span class="$_">}, '</span>' ]
+                    }
+                      qw/Alert BaseN BString Char Comment DataType
+                         DecVal Error Float Function IString Keyword
+                         Normal Operator Others RegionMarker Reserved
+                         String Variable Warning/,
+                },
+            );
+
+            $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
+        };
+        warn $@ if $@;
+    } else {
+        $c->stash->{blob} = encode_entities($c->stash->{blob});
+    }
 
     $c->forward('View::Default');
 }
index e2bdefd..2941275 100644 (file)
@@ -11,6 +11,8 @@
 /* /commit page */
 .commit-message {
     font-family: monospace;
+    background-color: #ddd;
+    padding: 5px;
 }
 .commit-info dt {
     font-weight: bold;
@@ -25,3 +27,9 @@
 .action-list {
   font-size: smaller;
 }
+
+.path {
+    border-bottom: solid 1px #ddd;
+    padding: 3px 0;
+    font-weight: bold;
+}
index b860c91..4c2a5bb 100644 (file)
@@ -1,7 +1,121 @@
-[% INCLUDE 'commit-nav.tt2' %]
+[% PROCESS 'commit-nav.tt2' object = head %]
 <link rel="stylesheet" type="text/css" href="/static/css/syntax-dark.css"/>
+<div class='commit-message'>
+[% head.comment.substr(0, 85) %] ...
+</div>
+<div class='path'>
+ <a href="/tree?p=[% project %];hb=[% head.sha1 %]">[% project %]</a>
+ [% # XXX The last part should link to blob_plain (or something) but doesn't ATM
+    FOREACH part IN filename.split('/') %]
+ / <a href="/tree?p=[% project %];hb=[% head.sha1 %]">[% part %]</a>
+ [% END %]
+</div>
 <div>
-<pre class='blob'>
-[% blob %]
-</pre>
+ <pre class='blob'>[% blob %]</pre>
 </div>
+
+<!--
+$Git_PurePerl_Object_Blob1 = bless( {
+                               content => "* Fix git_blob_plain i.e don't use the wrapper.\n",
+                               git     => bless( {
+                                            directory => {
+                                                           dirs     => [ '.' ],
+                                                           file_spec_class
+                                                                    => undef,
+                                                           volume   => ''
+                                                         },
+                                            gitdir    => {
+                                                           dirs     => [ '.git' ],
+                                                           file_spec_class
+                                                                    => undef,
+                                                           volume   => ''
+                                                         },
+                                            loose     => bless( { directory => {
+                                                           dirs     => [
+                                                                         '.git',
+                                                                         'objects'
+                                                                       ],
+                                                           file_spec_class
+                                                                    => undef,
+                                                           volume   => ''
+                                                         } }, 'Git::PurePerl::Loose' ),
+                                            packs     => [ bless( {
+                                                           fh      => bless( do{ require Symbol; Symbol::gensym }, 'IO::File' ),
+                                                           filename
+                                                                   => {
+                                                                        dir     => {
+                                                                                     dirs     => [
+                                                                                                   '.git',
+                                                                                                   'objects',
+                                                                                                   'pack'
+                                                                                                 ],
+                                                                                     file_spec_class
+                                                                                              => undef,
+                                                                                     volume   => ''
+                                                                                   },
+                                                                        file    => 'pack-76da0c32a0a4918d1828d110636caad32af6ec6c.pack',
+                                                                        file_spec_class
+                                                                                => undef
+                                                                      },
+                                                           index   => bless( {
+                                                                        fh       => bless( Symbol::gensym, 'IO::File' ),
+                                                                        filename => {
+                                                                                      dir     => {
+                                                                                                   dirs     => [
+                                                                                                                 '.git',
+                                                                                                                 'objects',
+                                                                                                                 'pack'
+                                                                                                               ],
+                                                                                                   file_spec_class
+                                                                                                            => undef,
+                                                                                                   volume   => ''
+                                                                                                 },
+                                                                                      file    => 'pack-76da0c32a0a4918d1828d110636caad32af6ec6c.idx',
+                                                                                      file_spec_class
+                                                                                              => undef
+                                                                                    },
+                                                                        offsets  => [
+                                                                                      ( 0 ) x 23,
+                                                                                      ( 1 ) x 29,
+                                                                                      ( 2 ) x 11,
+                                                                                      ( 3 ) x 6,
+                                                                                      ( 4 ) x 22,
+                                                                                      ( 5 ) x 51,
+                                                                                      ( 6 ) x 78,
+                                                                                      ( 7 ) x 3,
+                                                                                      ( 8 ) x 34
+                                                                                    ],
+                                                                        size     => 8
+                                                                      }, 'Git::PurePerl::PackIndex::Version2' ),
+                                                           index_filename
+                                                                   => {
+                                                                        dir     => {
+                                                                                     dirs     => [
+                                                                                                   '.git',
+                                                                                                   'objects',
+                                                                                                   'pack'
+                                                                                                 ],
+                                                                                     file_spec_class
+                                                                                              => undef,
+                                                                                     volume   => ''
+                                                                                   },
+                                                                        file    => 'pack-76da0c32a0a4918d1828d110636caad32af6ec6c.idx',
+                                                                        file_spec_class
+                                                                                => undef
+                                                                      }
+                                                         }, 'Git::PurePerl::Pack::WithIndex' ) ]
+                                          }, 'Git::PurePerl' ),
+                               kind    => 'blob',
+                               sha1    => '8976ebc7df65475b3def53a1653533c3f61070d0',
+                               size    => 48
+                             }, 'Git::PurePerl::Object::Blob' );
+bless( $Git_PurePerl_Object_Blob1->{git}{directory}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{gitdir}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{loose}{directory}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{filename}{dir}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{filename}, 'Path::Class::File' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{index}{filename}{dir}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{index}{filename}, 'Path::Class::File' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{index_filename}{dir}, 'Path::Class::Dir' );
+bless( $Git_PurePerl_Object_Blob1->{git}{packs}[0]{index_filename}, 'Path::Class::File' );
+-->
index 34106e7..4954dfb 100644 (file)
@@ -1,21 +1,8 @@
 <div id='commit-nav'>
-    [%# XXX For the record these params are wrong (i.e sha1 will probably be wrong) and the actions don't exist i.e this is a shim -%]
-    [% IF project %]
     <a href="/summary?p=[% project %]">summary</a> |
-    [% END %]
-    [% IF c.req.param('hb') %]
-    <a href="/shortlog?h=[% c.req.param('hb') %]">shortlog</a> |
-    [% END %]
-    [% IF c.req.param('hb') %]
-    <a href="/log?h=[% c.req.param('hb') %]">log</a> |
-    [% END %]
-    [% IF c.req.param('h') %]
-    <a href="/commit?h=[% c.req.param('h') %]">commit</a> |
-    [% END %]
-    [% IF c.req.param('h') %]
-    <a href="/commitdiff?h=[% c.req.param('h') %]">commitdiff</a> |
-    [% END %]
-    [% IF t %]
-    <a href="/tree?h=[% t %]">tree</a>
-    [% END %]
+    <a href="/shortlog?p=[% project %];h=[% object.sha1 %]">shortlog</a> |
+    <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>
 </div>
index 7cefc5c..bb029eb 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' %]
+[% INCLUDE 'commit-nav.tt2' object = commit %]
 <div class='commit-message'>
 [% commit.comment.substr(0, 50) %] ...
 [% FOREACH ref IN c.model('Git').refs_for(commit.sha1) %]
@@ -23,9 +23,7 @@
  [% END %]
 </dl>
 
-<pre class='commit-message'>
-[% commit.comment %]
-</pre>
+<pre class='commit-message'>[% commit.comment %]</pre>
 
 <table class='diff-tree'>
  <thead>
@@ -37,9 +35,9 @@
   <tr>
    <td class='filename'>[% line.src %]</td>
    <td class='action-list'>
-     [% IF !line.is_new %]<a href="/blobdiff?f=[% line.file %];h=[% line.sha1dst %];hp=[% sha1src %]">diff</a>[% END %]
-     <a href="/blob?f=[% line.file %];h=[% line.sha1 %];hb=[% commit.sha1 %]">blob</a>
-     [% IF !line.is_new %]<a href="/log?f=[% line.file %];hb[% commit.sha1 %]=">history</a>[% END %]
+     [% IF !line.is_new %]<a href="/blobdiff?p=[% project %];f=[% line.file %];h=[% line.sha1dst %];hp=[% sha1src %]">diff</a>[% END %]
+     <a href="/blob?p=[% project %];f=[% line.file %];h=[% line.sha1 %];hb=[% commit.sha1 %]">blob</a>
+     [% IF !line.is_new %]<a href="/log?p=[% project %];f=[% line.file %];hb[% commit.sha1 %]=">history</a>[% END %]
    </td>
   </tr>
   [% END %]