sub _get_commit {
my($self, $c) = @_;
+ my $h = $c->req->param('h');
+ my $f = $c->req->param('f');
+
# 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')) : '')
+ my $hash = ($h =~ /[^a-f0-9]/ ? $c->model('Git')->head_hash($h) : $h)
+ || ($f && $c->model('Git')->hash_by_path($f))
|| $c->model('Git')->head_hash
# XXX This could definitely use more context.
|| Carp::croak("Couldn't find a hash for the commit object!");
$c->stash(
commit => $commit,
info => $c->model('Git')->project_info($c->model('Git')->project),
- log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1, count => 17)],
+ log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1, count => 16)],
+ refs => $c->model('Git')->references,
heads => [$c->model('Git')->heads],
+ HEAD => $c->model('Git')->head_hash,
action => 'summary',
);
}
$c->stash(
commit => $self->_get_commit($c),
heads => [$c->model('Git')->heads],
+ HEAD => $c->model('Git')->head_hash,
action => 'heads',
);
}
# XXX Needs paging.
$c->stash(
commit => $commit,
- log_lines => [$c->model('Git')->list_revs(rev => $commit->sha1)],
+ log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1)],
+ refs => $c->model('Git')->references,
action => 'shortlog',
);
}
=head2 head_hash
-Find the C<HEAD> of given (or current) project.
+Find the hash of a given head (defaults to HEAD) of given (or current) project.
=cut
sub head_hash {
- my ($self, $project) = @_;
+ my ($self, $head, $project) = @_;
- my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify HEAD/ );
+ my $output = $self->run_cmd_in($project || $self->project, qw/rev-parse --verify/, $head || 'HEAD' );
return unless defined $output;
my ($head) = $output =~ /^($SHA1RE)$/;
push @ret, {
mode => oct $mode,
+ # XXX I wonder why directories always turn up as 040000 ...
modestr => $self->get_object_mode_string({mode=>oct $mode}),
type => $type,
object => $object,
sub list_revs {
my ($self, %args) = @_;
- $args{rev} ||= $self->head_hash($args{project});
+ $args{sha1} ||= $self->head_hash($args{project});
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}" : ()),
- $args{rev},
+ $args{sha1},
'--',
($args{file} ? $args{file} : ()),
);
padding: 3px 0;
font-weight: bold;
}
+
+/* /heads */
+.heads .head {
+ font-weight: bold;
+}
+.heads .current {
+ text-decoration: underline;
+}
# Liberally borrowed from rafl's gitweb
my $repo = 'repo1';
-like($m->head_hash($repo), qr/^([0-9a-fA-F]{40})$/, 'get_head_hash');
+like($m->head_hash('HEAD', $repo), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
{
my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', $repo);
-<table>
+<table class='heads'>
<thead>
<tr>
<td>age</td>
[% FOREACH head IN heads %]
<tr>
<td>[% head.last_change %]</td>
- <td>[% head.name %]</td>
+ <td class='head[% head.sha1 == HEAD ? ' current' : '' %]'>[% head.name %]</td>
<td class='action-list'>
<a href="/shortlog?p=[% project %];h=[% head.sha1 %]">shortlog</a>
<a href="/log?p=[% project %];h=[% head.sha1 %]">log</a>
<td>[% line.sha1.substr(0, 6) %]</td>
<td>[% line.authored_time %]</td>
<td>[% line.author.name | html %]</td>
- <td class='commit-message'>[% line.comment.substr(0, 50) | html %]</td>
+ <td>
+ [% line.comment.substr(0, 50) | html %]
+ <span class='refs'>
+ [% FOREACH ref IN refs.${line.sha1} %]
+ <span class='[% ref.search('^remotes/') ? 'remote' : 'head' %]'>
+ <a href='/shortlog?p=[% project %];h=refs/[% ref %]'>[% ref.replace('^(remote|head)s/', '') %]</a>
+ </span>
+ [% END %]
+ </span>
+ </td>
<td class='action-list'>
<a href="/commit?p=[% project %];h=[% line.sha1 %]">commit</a>
<a href="/commitdiff?p=[% project %];h=[% line.sha1 %]">commitdiff</a>