Skip to content

Commit

Permalink
Merge branch 'action-blame' of git://github.com/broquaint/Gitalist
Browse files Browse the repository at this point in the history
* 'action-blame' of git://github.com/broquaint/Gitalist:
  Fix the path in the /blob & /blame header.
  Made /blob & /blob_plain actions a little more robust.
  Added /project_index action.
  Switch from latin1 chars to the HTML escape char equivalents.
  • Loading branch information
bobtfish committed Nov 21, 2009
2 parents 17c71b4 + fed9966 commit 970ae5a
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 81 deletions.
69 changes: 51 additions & 18 deletions lib/Gitalist/Controller/Root.pm
Expand Up @@ -76,6 +76,20 @@ sub index :Path :Args(0) {
); );
} }


sub project_index : Local {
my ( $self, $c ) = @_;

my @list = @{ $c->model()->projects };
die 'No projects found in '. $c->model->repo_dir
unless @list;

$c->response->content_type('text/plain');
$c->response->body(
join "\n", map $_->name, @list
);
$c->response->status(200);
}

=head2 summary =head2 summary
A summary of what's happening in the repo. A summary of what's happening in the repo.
Expand Down Expand Up @@ -153,13 +167,7 @@ sub blame : Local {


} }


=head2 blob sub _blob_objs {
The blob action i.e the contents of a file.
=cut

sub blob : Local {
my ( $self, $c ) = @_; my ( $self, $c ) = @_;
my $project = $c->stash->{Project}; my $project = $c->stash->{Project};
my $h = $c->req->param('h') my $h = $c->req->param('h')
Expand All @@ -171,9 +179,27 @@ sub blob : Local {


my $filename = $c->req->param('f') || ''; my $filename = $c->req->param('f') || '';


my $blob = $project->get_object($h);
$blob = $project->get_object(
$project->hash_by_path($h || $hb, $filename)
) if $blob->type ne 'blob';

return $blob, $project->get_object($hb), $filename;
}

=head2 blob
The blob action i.e the contents of a file.
=cut

sub blob : Local {
my ( $self, $c ) = @_;

my($blob, $head, $filename) = $self->_blob_objs($c);
$c->stash( $c->stash(
blob => $project->get_object($h)->content, blob => $blob->content,
head => $project->get_object($hb), head => $head,
filename => $filename, filename => $filename,
# XXX Hack hack hack, see View::SyntaxHighlight # XXX Hack hack hack, see View::SyntaxHighlight
language => ($filename =~ /\.p[lm]$/ ? 'Perl' : ''), language => ($filename =~ /\.p[lm]$/ ? 'Perl' : ''),
Expand All @@ -184,23 +210,34 @@ sub blob : Local {
unless $c->stash->{no_wrapper}; unless $c->stash->{no_wrapper};
} }


=head2 blob_plain
The plain text version of blob, where file is rendered as is.
=cut

sub blob_plain : Local { sub blob_plain : Local {
my($self, $c) = @_; my($self, $c) = @_;


$c->stash(no_wrapper => 1); my($blob) = $self->_blob_objs($c);
$c->response->content_type('text/plain; charset=utf-8'); $c->response->content_type('text/plain; charset=utf-8');

$c->response->body($blob->content);
$c->forward('blob'); $c->response->status(200);
} }


=head2 blobdiff_plain
The plain text version of blobdiff.
=cut

sub blobdiff_plain : Local { sub blobdiff_plain : Local {
my($self, $c) = @_; my($self, $c) = @_;


$c->stash(no_wrapper => 1); $c->stash(no_wrapper => 1);
$c->response->content_type('text/plain; charset=utf-8'); $c->response->content_type('text/plain; charset=utf-8');


$c->forward('blobdiff'); $c->forward('blobdiff');

} }


=head2 blobdiff =head2 blobdiff
Expand Down Expand Up @@ -576,7 +613,7 @@ sub auto : Private {
short_cmt => sub { short_cmt => sub {
my $cmt = shift; my $cmt = shift;
my($line) = split /\n/, $cmt; my($line) = split /\n/, $cmt;
$line =~ s/^(.{70,80}\b).*/$1 /; $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/;
return $line; return $line;
}, },
abridged_description => sub { abridged_description => sub {
Expand All @@ -585,10 +622,6 @@ sub auto : Private {
); );
} }


sub project_index : Local {
# FIXME - implement snapshot
Carp::croak "Not implemented.";
}
sub opml : Local { sub opml : Local {
# FIXME - implement snapshot # FIXME - implement snapshot
Carp::croak "Not implemented."; Carp::croak "Not implemented.";
Expand Down
6 changes: 3 additions & 3 deletions root/_log_pager.tt2
@@ -1,9 +1,9 @@
<div class='pager'> <div class='pager'>
<a href='[% c.uri_for(action, {h=HEAD}) %]'>HEAD</a> § <a href='[% c.uri_for(action, {h=HEAD}) %]'>HEAD</a> &sect;
[% IF log_lines.first.sha1 != commit.sha1 %] [% IF log_lines.first.sha1 != commit.sha1 %]
<a href='[% c.uri_for(action, {pg=page - 1, h=commit.sha1}) %]'>« prev</a> <a href='[% c.uri_for(action, {pg=page - 1, h=commit.sha1}) %]'>&laquo; prev</a>
[% END %] [% END %]
[% IF log_lines.size == 50 %] [% IF log_lines.size == 50 %]
<a href='[% c.uri_for(action, {pg=page + 1, h=commit.sha1}) %]'>next »</a> <a href='[% c.uri_for(action, {pg=page + 1, h=commit.sha1}) %]'>next &raquo;</a>
[% END %] [% END %]
</div> </div>
2 changes: 1 addition & 1 deletion root/_shortlog.tt2
Expand Up @@ -26,7 +26,7 @@
<td class='time-since' title='[% line.authored_time %]'>[% time_since(line.authored_time) %]</td> <td class='time-since' title='[% line.authored_time %]'>[% time_since(line.authored_time) %]</td>
<td class='author'>[% line.author.name | html %]</td> <td class='author'>[% line.author.name | html %]</td>
<td> <td>
[% short_cmt(line.comment) | html %] [% short_cmt(line.comment) | html_entity %]
[% INCLUDE '_refs.tt2' object = line %] [% INCLUDE '_refs.tt2' object = line %]
</td> </td>
<td class='action-list'> <td class='action-list'>
Expand Down
2 changes: 1 addition & 1 deletion root/blame.tt2
Expand Up @@ -5,7 +5,7 @@
</div> </div>
[% END %] [% END %]


<h3>BLOB PATH</h3> [% INCLUDE 'nav/path.tt2' %]


<div id='blame'> <div id='blame'>
<table> <table>
Expand Down
16 changes: 5 additions & 11 deletions root/blob.tt2
@@ -1,18 +1,12 @@
<link rel="stylesheet" type="text/css" href="/static/css/syntax/[% language %].css"/> <link rel="stylesheet" type="text/css" href="/static/css/syntax/[% language %].css"/>


[% PROCESS 'nav/actions.tt2' object = head %] [% PROCESS 'nav/actions.tt2' object = head %]
[% IF object.type == 'commit' %] [% IF object.type == 'commit' %]
<div class='commit-message'> <div class='commit-message'>
[% head.comment.substr(0, 85) %] ... [% short_cmt(head.comment) %]
</div> </div>
[% END %] [% END %]
<div class='path'> [% INCLUDE 'nav/path.tt2' %]
<a href="[% c.uri_for("tree", {hb=head.sha1}) %]">[% Project.name %]</a>
[% # XXX The last part should link to blob_plain (or something) but doesn't ATM
FOREACH part IN filename.split('/') %]
/ <a href="[% c.uri_for("tree", {hb=head.sha1}) %]">[% part %]</a>
[% END %]
</div>
<div> <div>
<pre class='blob'>[% blob %]</pre> <pre class='blob'>[% blob %]</pre>
</div> </div>
1 change: 0 additions & 1 deletion root/blob_plain.tt2

This file was deleted.

6 changes: 3 additions & 3 deletions root/default.tt2
Expand Up @@ -5,8 +5,8 @@
<!-- git web interface version [% version %], (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke --> <!-- git web interface version [% version %], (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
<!-- git core binaries version [% git_version %] --> <!-- git core binaries version [% git_version %] -->
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="generator" content="gitweb/[% version %] git/[% git_version %][% mod_perl_version %]"/> <meta name="generator" content="gitweb/[% version %] git/[% git_version %][% mod_perl_version %]">
<meta name="robots" content="index, nofollow"/> <meta name="robots" content="index, nofollow">
<title>[%- <title>[%-
title = BLOCK; title = BLOCK;
c.config.sitename; c.config.sitename;
Expand Down Expand Up @@ -35,7 +35,7 @@
<a title="git homepage" href="http://git-scm.org"> <a title="git homepage" href="http://git-scm.org">
<img src="[% c.uri_for('/logo.png') %]" alt="git" class="logo"> <img src="[% c.uri_for('/logo.png') %]" alt="git" class="logo">
</a> </a>
<a href="[% c.uri_for('/') %]">A Gitalist</a> <a href="[% c.uri_for('/', {p=''}) %]">A Gitalist</a>
[%- IF Project %] [%- IF Project %]
/ <a href="[% c.uri_for('summary') %]">[% Project.name %]</a> / <a href="[% c.uri_for('summary') %]">[% Project.name %]</a>
[% IF action; " / " _ action; END; [% IF action; " / " _ action; END;
Expand Down
19 changes: 10 additions & 9 deletions root/nav/actions.tt2
@@ -1,17 +1,18 @@
<div class='actions'> <div class='actions'>
<a href="[% c.uri_for('summary') %]">summary</a> <a href="[% c.uri_for('summary') %]">summary</a> &bull;
<a href="[% c.uri_for('shortlog', {h=object.sha1}) %]">shortlog</a> <a href="[% c.uri_for('shortlog', {h=object.sha1}) %]">shortlog</a> &bull;
<a href="[% c.uri_for('log', {h=object.sha1}) %]">log</a> <a href="[% c.uri_for('log', {h=object.sha1}) %]">log</a> &bull;
<a href="[% c.uri_for('commit', {h=object.sha1}) %]">commit</a> <a href="[% c.uri_for('commit', {h=object.sha1}) %]">commit</a> &bull;
<a href="[% c.uri_for('commitdiff', {h=object.sha1}) %]">commitdiff</a> <a href="[% c.uri_for('commitdiff', {h=object.sha1}) %]">commitdiff</a>
[% IF object.type == 'commit' %] [% IF object.type == 'commit' %] &bull;
<a href="[% c.uri_for('tree', {h=object.tree_sha1, hb=object.sha1}) %]">tree</a> <a href="[% c.uri_for('tree', {h=object.tree_sha1, hb=object.sha1}) %]">tree</a>
[% END %] [% END %]
[% IF filename %] [% IF filename %]
§ &sect;
<a href="[% c.uri_for('blob', {h=object.sha1,f=filename}) %]">blob</a> • <a href="[% c.uri_for('blob', {h=object.sha1,f=filename}) %]">blob</a> &bull;
<a href="[% c.uri_for('blame', {h=object.sha1,f=filename}) %]">blame</a> • <a href="[% c.uri_for('blob_plain', {h=object.sha1,f=filename}) %]">raw</a> &bull;
<a href="[% c.uri_for('shortlog', {h=object.sha1,f=filename}) %]">history</a> • <a href="[% c.uri_for('blame', {h=object.sha1,f=filename}) %]">blame</a> &bull;
<a href="[% c.uri_for('shortlog', {h=object.sha1,f=filename}) %]">history</a> &bull;
<a href="[% c.uri_for(action, {f=filename}) %]">HEAD</a> <a href="[% c.uri_for(action, {f=filename}) %]">HEAD</a>
[% END %] [% END %]
<div class='chroma-hash'>[% INCLUDE '_chroma_hash.tt2' sha1 = object.sha1 %]</div> <div class='chroma-hash'>[% INCLUDE '_chroma_hash.tt2' sha1 = object.sha1 %]</div>
Expand Down
7 changes: 7 additions & 0 deletions root/nav/path.tt2
@@ -0,0 +1,7 @@
<div class='path'>
<a href="[% c.uri_for("tree", {hb=head.sha1}) %]">[% Project.name %]</a>
[% FOREACH part IN filename.split('/') %]
[% path = loop.first ? part : path _ '/' _ part %]
/ <a href="[% c.uri_for(loop.last ? 'blob' : 'tree', {hb=head.sha1,f=path}) %]">[% part %]</a>
[% END %]
</div>
14 changes: 7 additions & 7 deletions root/nav/search.tt2
@@ -1,10 +1,10 @@
<div id="page-search"> <div id="page-search">
<form method="get" action="[% c.uri_for('search') %]" enctype="application/x-www-form-urlencoded"> <form method="get" action="[% c.uri_for('search') %]" enctype="application/x-www-form-urlencoded">
<input name="p" type="hidden" value="[% Project.name %]" /> <input name="p" type="hidden" value="[% Project.name %]">
<input name="a" type="hidden" value="search" /> <input name="a" type="hidden" value="search">
<input name="h" type="hidden" value="[% commit.sha1 %]" /> <input name="h" type="hidden" value="[% commit.sha1 %]">
<input name="f" type="hidden" value="[% c.req.param('f') %]" /> <input name="f" type="hidden" value="[% c.req.param('f') %]">
<select name="type" > <select name="type">
<option value="commit">commit</option> <option value="commit">commit</option>
<option value="author">author</option> <option value="author">author</option>
<option value="committer">committer</option> <option value="committer">committer</option>
Expand All @@ -13,7 +13,7 @@
<option value="pickaxe">pickaxe</option> <option value="pickaxe">pickaxe</option>
--> -->
</select><sup><a href="[% c.uri_for('search_help') %]">?</a></sup> search: </select><sup><a href="[% c.uri_for('search_help') %]">?</a></sup> search:
<input type="text" name="text" value="[% c.req.param('s') %]"/> <input type="text" name="text" value="[% c.req.param('s') %]">
<span title="Extended regular expression"><label><input type="checkbox" name="regexp" value="1" />re</label></span> <span title="Extended regular expression"><label><input type="checkbox" name="regexp" value="1">re</label></span>
</form> </form>
</div> </div>
39 changes: 12 additions & 27 deletions t/03legacy_uri.t
Expand Up @@ -16,6 +16,7 @@ local *test = curry_test_uri('repo1');


test('/', 'a=summary'); test('/', 'a=summary');
test('/', 'a=heads'); test('/', 'a=heads');
test('/', 'a=tags');


test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD'); test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD');
Expand Down Expand Up @@ -229,38 +230,22 @@ test('/', 'a=rss;h=refs/heads/master');
test('/', 'a=rss;h=refs/heads/master;opt=--no-merges'); test('/', 'a=rss;h=refs/heads/master;opt=--no-merges');
test('/', 'a=rss;opt=--no-merges'); test('/', 'a=rss;opt=--no-merges');


TODO: { test('/', 'a=project_index');
local $TODO = 'The project_index action is yet to be implemented';
test('/', 'a=project_index');
}
TODO: { TODO: {
local $TODO = 'The opml action is yet to be implemented'; local $TODO = 'The opml action is yet to be implemented';
test('/', 'a=opml'); test('/', 'a=opml');
} }
TODO: {
local $TODO = 'The tags action is yet to be implemented';
test('/', 'a=tags');
}
TODO: {
local $TODO = 'The blame action is yet to be implemented';


test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=blame;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD'); test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=master'); test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=refs/heads/master'); test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
test('/', 'a=blame;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=HEAD');
test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99'); test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=master');
test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=257cc5642cb1a054f08cc83f2d943e56fd3ebe99'); test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/heads/master');
test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=5716ca5987cbf97d6bb54920bea6adde242d87e6');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=HEAD');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=master');
test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/heads/master');
test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
}


done_testing; done_testing;


Expand Down

0 comments on commit 970ae5a

Please sign in to comment.