From: Zachary Stevens Date: Sun, 8 Nov 2009 15:44:06 +0000 (+0000) Subject: Migrate search and reflog to new model. X-Git-Tag: 0.000000_01~61 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8abdf1cd357564b8e9e7b2c766feb9990a941fb;p=catagits%2FGitalist.git Migrate search and reflog to new model. --- diff --git a/lib/Gitalist/Controller/Root.pm b/lib/Gitalist/Controller/Root.pm index 0b2733a..5a75fe7 100644 --- a/lib/Gitalist/Controller/Root.pm +++ b/lib/Gitalist/Controller/Root.pm @@ -329,8 +329,8 @@ Expose the local reflog. This may go away. sub reflog : Local { my ( $self, $c ) = @_; - - my @log = $c->model()->reflog( + $c->stash(current_model => 'GitRepos'); + my @log = $c->stash->{Project}->reflog( '--since=yesterday' ); @@ -342,7 +342,8 @@ sub reflog : Local { sub search : Local { my($self, $c) = @_; - + $c->stash(current_action => 'GitRepos'); + my $project = $c->stash->{Project}; my $commit = $self->_get_commit($c); # Lifted from /shortlog. my %logargs = ( @@ -358,7 +359,7 @@ sub search : Local { $c->stash( commit => $commit, - results => [$c->model()->list_revs(%logargs)], + results => [$project->list_revs(%logargs)], action => 'search', # This could be added - page => $page, ); diff --git a/lib/Gitalist/Git/Project.pm b/lib/Gitalist/Git/Project.pm index 844dcf3..60a813b 100644 --- a/lib/Gitalist/Git/Project.pm +++ b/lib/Gitalist/Git/Project.pm @@ -382,6 +382,50 @@ The keys for each item will be: return @ret; } + method reflog (@logargs) { + my @entries + = $self->run_cmd(qw(log -g), @logargs) + =~ /(^commit.+?(?:(?=^commit)|(?=\z)))/msg; + +=pod + commit 02526fc15beddf2c64798a947fecdd8d11bf993d + Reflog: HEAD@{14} (The Git Server ) + Reflog message: push + Author: Foo Barsby + Date: Thu Sep 17 12:26:05 2009 +0100 + + Merge branch 'abc123' + +=cut + + return map { + # XXX Stuff like this makes me want to switch to Git::PurePerl + my($sha1, $type, $author, $date) + = m{ + ^ commit \s+ ($SHA1RE)$ + .*? + Reflog[ ]message: \s+ (.+?)$ \s+ + Author: \s+ ([^<]+) <.*?$ \s+ + Date: \s+ (.+?)$ + }xms; + + pos($_) = index($_, $date) + length $date; + + # Yeah, I just did that. + my($msg) = /\G\s+(\S.*)/sg; + { + hash => $sha1, + type => $type, + author => $author, + + # XXX Add DateTime goodness. + date => $date, + message => $msg, + } + ; + } @entries; + } + # Compatibility =head2 info diff --git a/t/01app.t b/t/01app.t index 6a3fdce..2c2d9e5 100644 --- a/t/01app.t +++ b/t/01app.t @@ -24,9 +24,11 @@ is request('/summary?p=DoesNotExist')->code, 404, test('/summary'); test('/shortlog'); test('/log'); + test('/reflog'); test('/commit'); test('/commitdiff', 'h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); test('/tree', 'h=145dc3ef5d307be84cb9b325d70bd08aeed0eceb;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818'); + test('/search', 'h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818&f=&type=commit&text=added'); } done_testing;