From: broquaint Date: Fri, 23 Oct 2009 14:21:16 +0000 (+0100) Subject: Tidied up the /blob action and the commit-nav.tt2 links. X-Git-Tag: 0.000000_01~108^2~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c8870bd37732961cdb6c22994839c8b43c33cc7a;hp=b3ad9e63b0e079a3e7599734ccd6244ca5921601;p=catagits%2FGitalist.git Tidied up the /blob action and the commit-nav.tt2 links. --- diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 4f9228c..06c0a8e 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -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 diff --git a/lib/Gitalist/Model/Git.pm b/lib/Gitalist/Model/Git.pm index abc212b..0233981 100644 --- a/lib/Gitalist/Model/Git.pm +++ b/lib/Gitalist/Model/Git.pm @@ -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; diff --git a/lib/Gitalist/View/SyntaxHighlight.pm b/lib/Gitalist/View/SyntaxHighlight.pm index 02845c6..c030f03 100644 --- a/lib/Gitalist/View/SyntaxHighlight.pm +++ b/lib/Gitalist/View/SyntaxHighlight.pm @@ -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 => { - "<" => "<", - ">" => ">", - "&" => "&", - q{'} => "'", - q{"} => """, - }, - format_table => { - # convert Kate's internal representation into - # value - map { - $_ => [ qq{}, '' ] - } - 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 => { + "<" => "<", + ">" => ">", + "&" => "&", + q{'} => "'", + q{"} => """, + }, + format_table => { + # convert Kate's internal representation into + # value + map { + $_ => [ qq{}, '' ] + } + 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'); } diff --git a/root/static/css/site.css b/root/static/css/site.css index e2bdefd..2941275 100644 --- a/root/static/css/site.css +++ b/root/static/css/site.css @@ -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; +} diff --git a/templates/blob.tt2 b/templates/blob.tt2 index b860c91..4c2a5bb 100644 --- a/templates/blob.tt2 +++ b/templates/blob.tt2 @@ -1,7 +1,121 @@ -[% INCLUDE 'commit-nav.tt2' %] +[% PROCESS 'commit-nav.tt2' object = head %] +
+[% head.comment.substr(0, 85) %] ... +
+
+ [% project %] + [% # XXX The last part should link to blob_plain (or something) but doesn't ATM + FOREACH part IN filename.split('/') %] + / [% part %] + [% END %] +
-
-[% blob %]
-
+
[% blob %]
+ + diff --git a/templates/commit-nav.tt2 b/templates/commit-nav.tt2 index 34106e7..4954dfb 100644 --- a/templates/commit-nav.tt2 +++ b/templates/commit-nav.tt2 @@ -1,21 +1,8 @@
- [%# 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 %] summary | - [% END %] - [% IF c.req.param('hb') %] - shortlog | - [% END %] - [% IF c.req.param('hb') %] - log | - [% END %] - [% IF c.req.param('h') %] - commit | - [% END %] - [% IF c.req.param('h') %] - commitdiff | - [% END %] - [% IF t %] - tree - [% END %] + shortlog | + log | + commit | + commitdiff | + tree
diff --git a/templates/commit.tt2 b/templates/commit.tt2 index 7cefc5c..bb029eb 100644 --- a/templates/commit.tt2 +++ b/templates/commit.tt2 @@ -1,4 +1,4 @@ -[% INCLUDE 'commit-nav.tt2' %] +[% INCLUDE 'commit-nav.tt2' object = commit %]
[% commit.comment.substr(0, 50) %] ... [% FOREACH ref IN c.model('Git').refs_for(commit.sha1) %] @@ -23,9 +23,7 @@ [% END %] -
-[% commit.comment %]
-
+
[% commit.comment %]
@@ -37,9 +35,9 @@ [% END %]
[% line.src %] - [% IF !line.is_new %]diff[% END %] - blob - [% IF !line.is_new %]history[% END %] + [% IF !line.is_new %]diff[% END %] + blob + [% IF !line.is_new %]history[% END %]