From: Dan Brook Date: Sat, 6 Mar 2010 21:32:45 +0000 (+0000) Subject: Provided support for remaining legacy URIs. X-Git-Tag: 0.000006_01~1^2~1^2~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=commitdiff_plain;h=f3be32b45515f1784595ca6320288735c239465a;hp=65f0ead5fc1f51f92ed1a72109958b9d155ecb38 Provided support for remaining legacy URIs. * The newly supported legacy URIs are: atom blame commit commitdiff commitdiff_plain history log patch patches rss search_help shortlog snapshot tree * Fixed the snapshot action. * Added file support for atom/rss. --- diff --git a/lib/Gitalist/Controller/LegacyURI.pm b/lib/Gitalist/Controller/LegacyURI.pm index a902a83..dd0472b 100644 --- a/lib/Gitalist/Controller/LegacyURI.pm +++ b/lib/Gitalist/Controller/LegacyURI.pm @@ -26,7 +26,7 @@ my %LEGACY_DISPATCH = ( my($c, $action, $repos) = @_; my $ref = $c->req->param('hb') || $c->req->param('h'); my $compare = $c->req->param('hbp') || $c->req->param('hp'); - return '/ref/diff', [$repos, $ref], $compare, $c->req->param('f'); + return '/ref/diff_fancy', [$repos, $ref], $compare, $c->req->param('f'); }, blobdiff_plain => sub { my($c, $action, $repos) = @_; @@ -34,6 +34,72 @@ my %LEGACY_DISPATCH = ( my $compare = $c->req->param('hbp') || $c->req->param('hp'); return '/ref/diff_plain', [$repos, $ref], $compare, $c->req->param('f'); }, + commit => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/commit', [$repos, $ref]; + }, + # XXX These can be consolidated with the blob equivalents. + commitdiff => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + my $compare = $c->req->param('hbp') || $c->req->param('hp'); + return '/ref/diff_fancy', [$repos, $ref], $compare, $c->req->param('f'); + }, + commitdiff_plain => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h'); + my $compare = $c->req->param('hbp') || $c->req->param('hp'); + return '/ref/diff_plain', [$repos, $ref || 'HEAD'], $compare, $c->req->param('f'); + }, + history => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/history', [$repos, $ref], $c->req->param('f'); + }, + log => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/longlog', [$repos, $ref]; + }, + patch => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/patch', [$repos, $ref]; + }, + patches => sub { + my($c, $action, $repos) = @_; + # XXX Is the arg there wrong? It's just copying G::C::R::patch. + return '/ref/patches', [$repos, $c->req->param('h') || 'HEAD'], 1; + }, + search_help => sub { + return '/search_help'; + }, + shortlog => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/shortlog', [$repos, $ref]; + }, + snapshot => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('h') || 'HEAD'; + return '/ref/snapshot', [$repos, $ref], $c->req->param('sf'); + }, + tree => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h') || 'HEAD'; + return '/ref/tree', [$repos, $ref], $c->req->param('f'); + }, + '(?:atom|rss)' => sub { + my($c, $action, $repos) = @_; + # XXX No support for arbitrary branches or merges/nomerges option :( + return "/repository/$action", [$repos], $c->req->param('f'); + }, + blame => sub { + my($c, $action, $repos) = @_; + my $ref = $c->req->param('hb') || $c->req->param('h'); + return '/ref/blame', [$repos, $ref], $c->req->param('f'); + }, ); sub _legacy_uri { @@ -46,8 +112,12 @@ sub _legacy_uri { die "Matched too many actions for '$a' - @result" if @result > 1; - return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos) - if $result[0]; + return + unless $result[0]; + + my($real_action, $captures, @args) = $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos); + + return $real_action, $captures || [], grep defined, @args; } sub handler : Chained('/base') PathPart('legacy') Args() { @@ -58,7 +128,7 @@ sub handler : Chained('/base') PathPart('legacy') Args() { die("Not supported") unless $action; - $c->res->redirect($c->uri_for_action($action, $captures || [], @args)); + $c->res->redirect($c->uri_for_action($action, $captures, @args)); $c->res->status(301); } diff --git a/lib/Gitalist/Controller/Ref.pm b/lib/Gitalist/Controller/Ref.pm index 1b36d4a..e43bd98 100644 --- a/lib/Gitalist/Controller/Ref.pm +++ b/lib/Gitalist/Controller/Ref.pm @@ -30,7 +30,7 @@ Provides a snapshot of a given commit. =cut -sub snapshot : Chained('base') Args() { +sub snapshot : Chained('find') PathPart('snapshot') Args() { my ($self, $c, $format) = @_; $format ||= 'tgz'; my @snap = $c->stash->{Repository}->snapshot( diff --git a/lib/Gitalist/Controller/Repository.pm b/lib/Gitalist/Controller/Repository.pm index fd27563..410f0a2 100644 --- a/lib/Gitalist/Controller/Repository.pm +++ b/lib/Gitalist/Controller/Repository.pm @@ -62,7 +62,7 @@ Provides an atom feed for a given repository. =cut -sub atom : Chained('find') Args(0) { +sub atom : Chained('find') Does('FilenameArgs') Args() { my ($self, $c) = @_; my $host = lc hostname(); @@ -73,8 +73,9 @@ sub atom : Chained('find') Args(0) { my $repository = $c->stash->{Repository}; my %logargs = ( - sha1 => $repository->head_hash, - count => Gitalist->config->{paging}{log} || 25, + sha1 => $repository->head_hash, + count => Gitalist->config->{paging}{log} || 25, + ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()), ); my @revs; @@ -100,7 +101,7 @@ Provides an RSS feed for a given repository. =cut -sub rss : Chained('find') Args(0) { +sub rss : Chained('find') Does('FilenameArgs') Args() { my ($self, $c) = @_; my $repository = $c->stash->{Repository}; @@ -116,7 +117,7 @@ sub rss : Chained('find') Args(0) { my %logargs = ( sha1 => $repository->head_hash, count => Gitalist->config->{paging}{log} || 25, -# ($c->req->param('f') ? (file => $c->req->param('f')) : ()) + ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()), ); my @revs; my $mk_title = $c->stash->{short_cmt}; diff --git a/root/ref/diff_plain.tt2 b/root/ref/diff_plain.tt2 index 2d01f98..0f98a04 100644 --- a/root/ref/diff_plain.tt2 +++ b/root/ref/diff_plain.tt2 @@ -1,3 +1,2 @@ -
-[% subinclude('/fragment/ref/diff_plain', c.req.captures) %]
-
+[% subinclude('/fragment/' _ c.action, c.req.captures, c.req.args.0 c.req.args.1) %] + diff --git a/t/03legacy_uri.t b/t/03legacy_uri.t index cdcf974..839d794 100644 --- a/t/03legacy_uri.t +++ b/t/03legacy_uri.t @@ -74,10 +74,6 @@ test('/', 'a=blobdiff_plain;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;h test('/', 'a=blobdiff_plain;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hp=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD;hpb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); test('/', 'a=blobdiff_plain;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hp=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=master;hpb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); -{ - - local $TODO = 'FIXME'; - test('/', 'a=commit'); test('/', 'a=commit;h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=commit;h=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); @@ -115,7 +111,6 @@ test('/', 'a=commitdiff_plain;h=master;hp=3f7567c7bdf7e7ebf410926493b92d39833311 test('/', 'a=commitdiff_plain;h=refs/heads/master'); test('/', 'a=commitdiff_plain;h=refs/heads/master;hp=3f7567c7bdf7e7ebf410926493b92d398333116e'); - test('/', 'a=history;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/', 'a=history;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD'); test('/', 'a=history;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=master'); @@ -219,7 +214,6 @@ test('/', 'a=tree;hb=HEAD'); test('/', 'a=tree;hb=master'); test('/', 'a=tree;hb=refs/heads/master'); - test('/', 'a=atom'); test('/', 'a=atom;f=dir1'); test('/', 'a=atom;f=dir1/file2'); @@ -260,7 +254,4 @@ test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/he test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e'); -} - done_testing; -