BEGIN { extends 'Gitalist::Controller' }
+my %LEGACY_DISPATCH = (
+ opml => sub { '/opml/opml' },
+ project_index => sub { '/legacyuri/project_index' },
+ '(?:summary|heads|tags)' => sub {
+ my($c, $action, $repos) = @_;
+ return "/repository/$action", [$repos];
+ },
+ blob => sub {
+ my($c, $action, $repos) = @_;
+ my $ref = $c->req->param('hb') || $c->req->param('h');
+ return '/ref/blob', [$repos, $ref], $c->req->param('f');
+ },
+);
+
+sub _legacy_uri {
+ my($self, $c, $repos, $action) = @_;
+
+ return
+ unless $action;
+
+ my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH;
+ die "Matched too many actions for '$a' - @result"
+ if @result > 1;
+
+ return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos)
+ if $result[0];
+}
+
sub handler : Chained('/base') PathPart('legacy') Args() {
my ( $self, $c, $repos ) = @_;
- my ($action, @captures);
- if (my $a = $c->req->param('a')) {
- $a eq 'opml' && do { $action = '/opml/opml'; };
- $a eq 'project_index' && do { $action = '/legacyuri/project_index'; };
- $a =~ /^(summary|heads|tags)$/ && do { $action = "/repository/$1"; push(@captures, $repos); };
- }
- die("Not supported") unless $action;
- $c->res->redirect($c->uri_for_action($action, \@captures));
+
+ my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a'));
+
+ die("Not supported")
+ unless $action;
+
+ $c->res->redirect($c->uri_for_action($action, $captures || [], @args));
$c->res->status(301);
}
sub find_blob : Action {
my ($self, $c) = @_;
+ my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
# FIXME - Eugh!
- my $h = $c->stash->{Repository}->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename})
- || die "No file or sha1 provided.";
- $c->stash(blob => $c->stash->{Repository}->get_object($h)->content);
+ my $h = $object->isa('Gitalist::Git::Object::Commit')
+ ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
+ : $object->isa('Gitalist::Git::Object::Blob')
+ ? $object->sha1
+ : die "Unknown object type for '${\$object->sha1}'";
+ die "No file or sha1 provided."
+ unless $h;
+ $c->stash(blob => $repo->get_object($h)->content);
}
sub blob : Chained('find') Does('FilenameArgs') Args() {
<span class='refs'>
[% FOREACH ref IN refs.${object.sha1} %]
<span class='[% ref.search('^remotes/') ? 'remote' : 'head' %]'>
- <a href='[% c.uri_for("shortlog", {h='refs/' _ ref}) %]'>[% ref.replace('^(remote|head)s/', '') %]</a>
+ <a href='[% c.uri_for_action("/repository/shortlog", [ref.match('(\w+)$').0]) %]'>[% ref.replace('^(remote|head)s/', '') %]</a>
</span>
[% END %]
</span>
test('/', 'a=summary');
test('/', 'a=heads');
test('/', 'a=tags');
-{
-
- local $TODO = 'FIXME';
test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD');
test('/', 'a=blob;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
+{
+
+ local $TODO = 'FIXME';
+
test('/', 'a=blob_plain;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
test('/', 'a=blob_plain;f=dir1/file2;hb=HEAD');
test('/', 'a=blob_plain;f=dir1/file2;hb=master');