* Sort out commitdiff so conflicted merges have an equivalent display to gitweb (d7f39bebabeb31ce9a7b4f1b6f3db9f391b78c3e as a reference)
+* Need to sanitise the input ...
Static::Simple
StackTrace/;
-use Class::C3::Adopt::NEXT -no_warn;
-
our $VERSION = '0.01';
# Bring in the libified gitweb.cgi.
# Start the application
__PACKAGE__->setup();
-sub uri_for {
- my $p = ref $_[-1] eq 'HASH'
- ? $_[-1]
- : push(@_, {}) && $_[-1];
- $p->{p} = $_[0]->model('Git')->project;
-
- (my $uri = $_[0]->NEXT::uri_for(@_[1 .. $#_]))
- # Ampersand! What is this, the 90s?
- =~ s/&/;/g;
- return $uri;
-}
+around uri_for => sub {
+ my ($orig, $c) = (shift, shift);
+ my $params = Catalyst::Utils::merge_hashes(
+ { p => $c->model('Git')->project },
+ ref($_[-1]) eq 'HASH' ? pop @_ : {}
+ );
+ (my $uri = $c->$orig(@_, $params))
+ =~ tr[&][;];
+ return $uri;
+};
=head1 NAME
}
sub search : Local {
- Carp::croak "Not implemented.";
+ my($self, $c) = @_;
+
+ my $commit = $self->_get_commit($c);
+ # Lifted from /shortlog.
+ my %logargs = (
+ sha1 => $commit->sha1,
+ count => Gitalist->config->{paging}{log},
+ ($c->req->param('f') ? (file => $c->req->param('f')) : ()),
+ search => {
+ type => $c->req->param('type'),
+ text => $c->req->param('text'),
+ regexp => $c->req->param('regexp') || 0,
+ }
+ );
+
+ $c->stash(
+ commit => $commit,
+ results => [$c->model('Git')->list_revs(%logargs)],
+ action => 'search',
+ # This could be added - page => $page,
+ );
}
sub search_help : Local {
sub parse_rev_list {
my ($self, $output) = @_;
- my @ret;
-
- my @revs = split /\0/, $output;
-
- for my $rev (split /\0/, $output) {
- for my $line (split /\n/, $rev, 6) {
- chomp $line;
- next unless $line;
- if ($self->valid_rev($line)) {
- push @ret, $self->get_object($line);
- }
- }
- }
-
- return @ret;
+ return
+ map $self->get_object($_),
+ grep $self->valid_rev($_),
+ map split(/\n/, $_, 6), split /\0/, $output;
}
=head2 list_revs
sub list_revs {
my ($self, %args) = @_;
- $args{sha1} ||= $self->head_hash($args{project});
+ $args{sha1} = $self->head_hash($args{sha1})
+ if !$args{sha1} || $args{sha1} !~ $SHA1RE;
+
+ my @search_opts;
+ if($args{search}) {
+ my $sargs = $args{search};
+ $sargs->{type} = 'grep'
+ if $sargs->{type} eq 'commit';
+ @search_opts = (
+ # This seems a little fragile ...
+ qq[--$sargs->{type}=$sargs->{text}],
+ '--regexp-ignore-case',
+ $sargs->{regexp} ? '--extended-regexp' : '--fixed-strings'
+ );
+ }
+ $DB::single=1;
my $output = $self->run_cmd_in($args{project} || $self->project, 'rev-list',
'--header',
- (defined $args{ count } ? "--max-count=$args{count}" : ()),
- (defined $args{ skip } ? "--skip=$args{skip}" : ()),
+ (defined $args{ count } ? "--max-count=$args{count}" : ()),
+ (defined $args{ skip } ? "--skip=$args{skip}" : ()),
+ @search_opts,
$args{sha1},
'--',
($args{file} ? $args{file} : ()),
END %]
</div>
-[% IF project AND have_search %]
-<div class="search">
- <form method="get" action="/" enctype="application/x-www-form-urlencoded">
- <input name="p" type="hidden" value="[% project %]" />
- <input name="a" type="hidden" value="search" />
- <input name="h" type="hidden" value="[% search_hash %]" />
- <select name="st" >
- <option value="commit">commit</option>
- <option value="grep">grep</option>
- <option value="author">author</option>
- <option value="committer">committer</option>
- <option value="pickaxe">pickaxe</option>
- </select><sup><a href="/search_help?p=[% project %]">?</a></sup> search:
- <input type="text" name="s" value="[% search_text %]"/>
- <span title="Extended regular expression"><label><input type="checkbox" name="sr" value="1" />re</label></span>
- </form>
-</div>
-[% END %]
-
-[%- # / git_header_html
--%]
[%
- IF page_nav;
- INCLUDE "page_nav.tt2";
+ IF project;
+ INCLUDE 'nav/search.tt2';
END;
+# / git_header_html
%]
<div id='body'>
[%
--- /dev/null
+<div class="search">
+ <form method="get" action="[% c.uri_for('search') %]" enctype="application/x-www-form-urlencoded">
+ <input name="p" type="hidden" value="[% project %]" />
+ <input name="a" type="hidden" value="search" />
+ <input name="h" type="hidden" value="[% commit.sha1 %]" />
+ <input name="f" type="hidden" value="[% c.req.param('f') %]" />
+ <select name="type" >
+ <option value="commit">commit</option>
+ <option value="author">author</option>
+ <option value="committer">committer</option>
+ <!-- Not supported, maybe later.
+ <option value="grep">grep</option>
+ <option value="pickaxe">pickaxe</option>
+ -->
+ </select><sup><a href="/search_help?p=[% project %]">?</a></sup> search:
+ <input type="text" name="text" value="[% search_text %]"/>
+ <span title="Extended regular expression"><label><input type="checkbox" name="regexp" value="1" />re</label></span>
+ </form>
+</div>
+++ /dev/null
-<div class="page_nav">
- [% nav_links %]
- <br/>[% extra %]<br/>
-</div>
--- /dev/null
+[% INCLUDE 'nav/actions.tt2' object = commit %]
+
+[%# INCLUDE '_log_pager.tt2' %]
+
+[%# XXX Nabbed the HTML below from gitweb's log action. %]
+[% FOREACH result IN results %]
+<div class="header">
+ <a class="title" href="[% c.uri_for('commit', {h=result.sha1}) %]">
+ <span class="age">[% result.authored_time %]</span>
+ [% result.comment.substr(0, 50) | html %]
+ </a>
+</div>
+
+<div class="title_text">
+ <div class="log_link">
+ <a href="[% c.uri_for('commit', {h=result.sha1}) %]">commit</a>
+ | <a href="[% c.uri_for('commitdiff', {h=result.sha1}) %]">commitdiff</a>
+ | <a href="[% c.uri_for('tree', {h=result.tree_sha1, hb=line.sha1}) %]">tree</a>
+ </div>
+ <i>[% result.author.name | html %] [% line.authored_time %]</i>
+</div>
+
+<div class="log_body">
+ [%
+ # XXX This is fragile at best.
+ html_comment = result.comment | html;
+ html_comment.replace(
+ c.req.param('text'), '<span class="match">' _ c.req.param('text') _ '</span>'
+ );
+ %]
+</div>
+[% END %]
+
+[%# INCLUDE '_log_pager.tt2' %]