my $h = $haveh || $c->req->param('h') || '';
my $f = $c->req->param('f');
- my $m = $c->model();
+
+ # FIXME this can die when everything is migrated
+ my ($m, $pd);
+ if ($c->stash->{current_model} eq 'GitRepos') {
+ $m = $c->model()->project($c->stash->{project});
+ $pd = $m->path;
+ } else {
+ $m = $c->model();
+ ($pd = $m->project_dir( $m->project )) =~ s{/\.git$}();
+ }
# Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
my $hash = ($h =~ /[^a-f0-9]/ ? $m->head_hash($h) : $h)
# XXX This could definitely use more context.
|| Carp::croak("Couldn't find a hash for the commit object!");
-
- (my $pd = $m->project_dir( $m->project )) =~ s{/\.git$}();
my $commit = $m->get_object($hash)
or Carp::croak("Couldn't find a commit object for '$hash' in '$pd'!");
sub heads : Local {
my ( $self, $c ) = @_;
-
+ $c->stash( current_model => 'GitRepos' );
+ my $project = $c->model()->project( $c->stash->{project} );
$c->stash(
commit => $self->_get_commit($c),
- heads => [$c->model()->heads],
+ heads => [$project->heads],
action => 'heads',
);
}
my ($self, $c) = @_;
# Give project views the current HEAD.
if ($c->stash->{project}) {
- $c->stash->{HEAD} = $c->model()->head_hash;
+ if ($c->stash->{current_model} eq 'GitRepos') {
+ my $project = $c->model()->project($c->stash->{project});
+ $c->stash->{HEAD} = $project->head_hash;
+ } else {
+ $c->stash->{HEAD} = $c->model()->head_hash;
+ }
}
}
is => 'ro',
handles => [ 'run_cmd' ],
);
- has sha1 ( isa => Str,
+ has sha1 => ( isa => Str,
required => 1,
is => 'ro' );
$self->$_() for qw/_util last_change owner description/; # Ensure to build early.
}
+ method _project_dir {
+ -f $self->{path}->file('.git', 'HEAD')
+ ? $self->{path}->subdir('.git')
+ : $self->{path};
+ }
+
method _build__util {
Gitalist::Git::Util->new(
- gitdir => $self->path,
+ gitdir => $self->_project_dir($self->path),
);
}
return $last_change;
}
+ method heads {
+ my $cmdout = $self->run_cmd(qw/for-each-ref --sort=-committerdate /, '--format=%(objectname)%00%(refname)%00%(committer)', 'refs/heads');
+ my @output = $cmdout ? split(/\n/, $cmdout) : ();
+ my @ret;
+ for my $line (@output) {
+ my ($rev, $head, $commiter) = split /\0/, $line, 3;
+ $head =~ s!^refs/heads/!!;
+
+ push @ret, { sha1 => $rev, name => $head };
+
+ #FIXME: That isn't the time I'm looking for..
+ if (my ($epoch, $tz) = $line =~ /\s(\d+)\s+([+-]\d+)$/) {
+ my $dt = DateTime->from_epoch(epoch => $epoch);
+ $dt->set_time_zone($tz);
+ $ret[-1]->{last_change} = $dt;
+ }
+ }
+
+ return @ret;
+ }
+
+
=head2 head_hash
Find the hash of a given head (defaults to HEAD).
is($proj->info->{name}, qw/repo1/, 'repo name in info hash');
+ok($proj->heads, '->heads returns stuff');
+
is($proj->head_hash, qw/36c6c6708b8360d7023e8a1649c45bcf9b3bd818/, 'head_hash for HEAD is correct');
is(scalar $proj->list_tree, 2, 'expected number of entries in tree');