To get back to gitweb s{/(\w+)\?}(/?a=$1).
Straightened out the controller somewhat.
Fixed the model's get_object method to return undef when no object is available.
Created the partials _diff, _diff_tree & _tree.
The /diff view while simple, is approaching something useful.
}
}
+sub _get_commit {
+ my($self, $c) = @_;
+
+ # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
+ my $hash = $c->req->param('h')
+ || ($c->req->param('f') ? $c->model('Git')->hash_by_path($c->req->param('f')) : '')
+ || $c->model('Git')->head_hash
+ # XXX This could definitely use more context.
+ || Carp::croak("Couldn't find a hash for the commit object!");
+
+ my $commit = $c->model('Git')->get_object($hash)
+ or Carp::croak("Couldn't find a commit object for '$hash'!");
+
+ return $commit;
+}
+
=head2 index
Provides the project listing.
sub summary : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->model('Git')->head_hash);
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
info => $c->model('Git')->project_info($c->model('Git')->project),
my ( $self, $c ) = @_;
$c->stash(
- commit => $c->model('Git')->get_object($c->model('Git')->head_hash),
+ commit => $self->_get_commit($c),
heads => [$c->model('Git')->heads],
action => 'heads',
);
$c->forward('View::SyntaxHighlight');
}
-=head2 reflog
-
-Expose the local reflog. This may go away.
-
-=cut
-
-sub reflog : Local {
- my ( $self, $c ) = @_;
-
- my @log = $c->model('Git')->reflog(
- '--since=yesterday'
- );
-
- $c->stash(
- log => \@log,
- action => 'reflog',
- );
-}
-
=head2 commit
Exposes a given commit.
sub commit : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
diff_tree => [$c->model('Git')->diff_tree($commit)],
sub commitdiff : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
diff_tree => [$c->model('Git')->diff_tree($commit)],
sub shortlog : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
# XXX Needs paging.
$c->stash(
commit => $commit,
sub tree : Local {
my ( $self, $c ) = @_;
- my $commit = $c->model('Git')->get_object($c->req->param('h'));
+ my $commit = $self->_get_commit($c);
$c->stash(
# XXX Useful defaults needed ...
commit => $commit,
tree => $c->model('Git')->get_object($c->req->param('hb')),
- list_tree => [$c->model('Git')->list_tree($commit->sha1)],
+ tree_list => [$c->model('Git')->list_tree($commit->sha1)],
action => 'tree',
);
}
+=head2 reflog
+
+Expose the local reflog. This may go away.
+
+=cut
+
+sub reflog : Local {
+ my ( $self, $c ) = @_;
+
+ my @log = $c->model('Git')->reflog(
+ '--since=yesterday'
+ );
+
+ $c->stash(
+ log => \@log,
+ action => 'reflog',
+ );
+}
+
=head2 auto
Populate the header and footer. Perhaps not the best location.
=cut
sub get_object {
- $_[0]->gpp->get_object($_[1]);
+ # We either want an object or undef, *not* an empty list.
+ return $_[0]->gpp->get_object($_[1]) || undef;
}
=head2 is_git_repo
|| scalar @revs > 2
|| any { !$self->valid_rev($_) } @revs;
- return $self->command(diff => @revs);
+ return $self->command(diff => '--full-index', @revs);
}
=begin
my @diff = $self->raw_diff(@revs);
my @ret;
- for my $line (@diff) {
+ for (@diff) {
# This regex is a little pathological.
- if($line =~ m{^diff --git (a/(.*?)) (b/\2)}) {
+ if(m{^diff --git (a/(.*?)) (b/\2)}) {
push @ret, {
- head => $line,
+ head => $_,
a => $1,
b => $3,
file => $2,
next;
}
- if($line =~ /^index (\w+)\.\.(\w+) (\d+)$/) {
+ if(/^index (\w+)\.\.(\w+) (\d+)$/) {
@{$ret[-1]}{qw(index src dst mode)} = ($_, $1, $2, $3);
next
}
unless @ret;
# XXX Somewhat hacky. Ahem.
- $ret[-1]{diff} .= "$line\n";
+ $ret[-1]{diff} .= "$_\n";
}
return @ret;
--- /dev/null
+[% FOREACH item IN diff %]
+<div class='diff-head'>
+ diff --git
+ <a href='/blob?p=[% project %];f=[% item.file %];h=[% item.src %]'>[% item.a %]</a>
+ <a href='/blob?p=[% project %];f=[% item.file %];h=[% item.dst %]'>[% item.b %]</a>
+</div>
+<div class='diff-index'>
+ [% item.index %]
+</div>
+<div class='diff-patch'>
+ <pre>[% item.diff | html %]</pre>
+</div>
+[% END %]
--- /dev/null
+<table class='diff-tree'>
+ <thead>
+ <tr>
+ <td>file</td>
+ <td>actions</td>
+ </tr>
+ </thead>
+ <tbody>
+ [% FOREACH line IN diff_tree %]
+ <tr>
+ <td class='filename'>[% line.src %]</td>
+ <td class='action-list'>
+ [% IF !line.is_new %]<a href="/blobdiff?p=[% project %];f=[% line.file %];h=[% line.sha1dst %];hp=[% sha1src %]">diff</a>[% END %]
+ <a href="/blob?p=[% project %];f=[% line.file %];h=[% line.sha1 %];hb=[% commit.sha1 %]">blob</a>
+ [% IF !line.is_new %]<a href="/log?p=[% project %];f=[% line.file %];hb=[% commit.sha1 %]">history</a>[% END %]
+ </td>
+ </tr>
+ [% END %]
+ </tbody>
+ <tfoot>
+ <tr>
+ <td>file</td>
+ <td>actions</td>
+ </tr>
+ </tfoot>
+</table>
--- /dev/null
+<table>
+ <thead>
+ <tr>
+ <td>mode</td>
+ <td>file</td>
+ <td>actions</td>
+ </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH item IN tree_list %]
+ <tr>
+ <td>[% item.modestr %]</td>
+ [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
+ <td class='filename'>
+ <a href="/[% theact %]?h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% item.file %]</a>
+ </td>
+ <td class='action-list'>
+ <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% theact %]</a>
+ <a href="/history?p=[% project %];h=[% item.object %]">history</a>
+ <a href="/raw?p=[% project %];h=[% item.object %]">raw</a>
+ </td>
+ </tr>
+ [% END %]
+ </tbody>
+
+ <tfoot>
+ <tr>
+ <td>mode</td>
+ <td>file</td>
+ <td>actions</td>
+ </tr>
+ </tfoot>
+</table>
+
[% INCLUDE '_diff_tree.tt2' %]
-<div class='diff'>
-[% USE dumper;
-FOREACH file IN diff %]
-<pre>[% dumper.dump(file) | html %]</pre>
-[% END %]
-</div>
+[% INCLUDE '_diff.tt2' %]
USE Cycle('dark', 'light');
FOR p IN projects %]
<tr class="[% Cycle.next %]">
- <td><a class="list" href="/?p=[% p.name %];a=summary">[% p.name %]</a></td>
- <td><a class="list" title="[% p.description %]" href="/?p=[% p.name %];a=summary">[% p.description.substr(0, 20) %]</a></td>
+ <td><a class="list" href="/summary?p=[% p.name %]">[% p.name %]</a></td>
+ <td><a class="list" title="[% p.description %]" href="/summary?p=[% p.name %]">[% p.description.substr(0, 20) %]</a></td>
<td>[% p.owner %]</td>
<td class="age2">[% p.last_change %]</td>
- <td class="link"><a href="/?p=[% p.name %];a=summary">summary</a>
- | <a href="/?p=[% p.name %];a=shortlog">shortlog</a>
- | <a href="/?p=[% p.name %];a=log">log</a>
- | <a href="/?p=[% p.name %];a=tree">tree</a></td>
+ <td class="link"><a href="/summary?p=[% p.name %]">summary</a>
+ | <a href="/shortlog?p=[% p.name %]">shortlog</a>
+ | <a href="/log?p=[% p.name %]">log</a>
+ | <a href="/tree?p=[% p.name %]">tree</a></td>
</tr>
[% END %]
</tbody>
[% commit.comment.substr(0, 85) %] ...
</div>
-<table>
- <thead>
- <tr>
- <td>mode</td>
- <td>file</td>
- <td>actions</td>
- </tr>
- </thead>
-
- <tbody>
- [% FOREACH item IN list_tree %]
- <tr>
- <td>[% item.modestr %]</td>
- [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
- <td class='filename'>
- <a href="/[% theact %]?h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% item.file %]</a>
- </td>
- <td class='action-list'>
- <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% theact %]</a>
- <a href="/history?p=[% project %];h=[% item.object %]">history</a>
- <a href="/raw?p=[% project %];h=[% item.object %]">raw</a>
- </td>
- </tr>
- [% END %]
- </tbody>
-
- <tfoot>
- <tr>
- <td>mode</td>
- <td>file</td>
- <td>actions</td>
- </tr>
- </tfoot>
-</table>
+[% INCLUDE '_tree.tt2' %]