$self->{cloneurl} = $url;
}
+sub tip {
+ my ($self) = @_;
+ $self->{-tip} ||= do {
+ if ($self->{vcs} eq 'git') {
+ my $t = $self->{git}->qx(qw(symbolic-ref --short HEAD));
+ chomp $t;
+ $t;
+ }
+ };
+}
+
1;
my $state = 0;
my $rel = $req->{relcmd};
my $repo = $req->{-repo};
+ my $tip = $repo->tip;
my $title = join('/', $repo->{repo}, @{$req->{extra}});
- $title = utf8_html("$title, $req->{-tip}");
+ $title = utf8_html("$title, $tip");
my $url = repo_root_url($self, $req);
my $hdr = {};
my $subtitle = $repo->desc_html;
my $git = $repo->{git};
my $env = $req->{env};
- my $tip = $req->{-tip};
+ my $tip = $req->{h} || $repo->tip;
my $read_log = sub {
my $cmd = $git->cmd(qw(log --no-notes --no-color
--abbrev-commit), $git->abbrev,
sub {
$env->{'qspawn.response'} = $_[0];
- return $read_log->() if $tip ne '';
-
- my $cmd = $git->cmd(qw(symbolic-ref --short HEAD));
- my $rdr = { 2 => $git->err_begin };
- my $qsp = PublicInbox::Qspawn->new($cmd, undef, undef, $rdr);
- $qsp->psgi_qx($env, undef, sub {
- chomp($tip = ${$_[0]});
- $read_log->();
- })
+ $read_log->();
}
}
sub call_git_blob {
my ($self, $req) = @_;
- my $git = $req->{-repo}->{git};
- my $id = $req->{-tip} . ':' . $req->{expath};
+ my $repo = $req->{-repo};
+ my $git = $repo->{git};
+ my $id = $repo->tip . ':' . $req->{expath};
my ($cat, $hex, $type, $size) = $git->cat_file_begin($id);
return unless defined $cat;
sub call_git_commit { # RepoBase calls this
my ($self, $req) = @_;
my $env = $req->{env};
- my $tip = $req->{-tip};
my $expath = $req->{expath};
if ($expath ne '') {
my $git = $req->{-repo}->{git};
my $cmd = $git->cmd(qw(show -z --numstat -p --encoding=UTF-8
--no-notes --no-color -c),
- $git->abbrev, GIT_FMT, $tip, '--');
+ $git->abbrev, GIT_FMT, $req->{-repo}->tip, '--');
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
$env->{'qspawn.quiet'} = 1;
sub git_diff_sed_init ($) {
my ($req) = @_;
$req->{dbuf} = '';
+ $req->{-tip} = $req->{-repo}->tip;
$req->{ndiff} = $req->{nchg} = $req->{nadd} = $req->{ndel} = 0;
$req->{dstate} = DSTATE_INIT;
}
$max = 50 if $max == 0;
my $env = $req->{env};
my $git = $repo->{git};
+ my $tip = $req->{-repo}->tip;
my $cmd = $git->cmd(qw(log --no-notes --no-color --abbrev-commit),
$git->abbrev, $LOG_FMT, "-$max",
- $req->{-tip}, '--');
+ $tip, '--');
my $rdr = { 2 => $git->err_begin };
my $title = "log: $repo->{repo}";
if (defined $h) {
$title .= ' ('. utf8_html($h). ')';
$req->{lpfx} = $req->{relcmd};
} else {
- $req->{lpfx} = $req->{relcmd}.$req->{-tip};
+ $req->{lpfx} = $req->{relcmd} . $tip;
}
$req->{lhtml} = $self->html_start($req, $title) . "\n\n";
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
sub call_git_patch {
my ($self, $req) = @_;
- my $git = $req->{-repo}->{git};
+ my $repo = $req->{-repo};
+ my $git = $repo->{git};
my $env = $req->{env};
- my $tip = $req->{-tip};
+ my $tip = $repo->tip;
$tip =~ /\A[\w-]+([~\^][~\^\d])*\z/;
# limit scope, don't take extra args to avoid wasting server
sub call_git_plain {
my ($self, $req) = @_;
- my $git = $req->{-repo}->{git};
- my $id = $req->{-tip} . ':' . $req->{expath};
+ my $repo = $req->{-repo};
+ my $git = $repo->{git};
+ my $id = $repo->tip . ':' . $req->{expath};
my ($cat, $hex, $type, $size) = $git->cat_file_begin($id);
return unless defined $cat;
sub call_git_snapshot ($$) { # invoked by PublicInbox::RepoBase::call
my ($self, $req) = @_;
- my $ref = $req->{-tip};
+ my $ref = $req->{h} || $req->{-repo}->tip;
my $orig_fn = $ref;
# just in case git changes refname rules, don't allow wonky filenames
my ($self, $req) = @_;
my $git = $req->{-repo}->{git};
my $env = $req->{env};
-
- # n.b. we would use %(HEAD) in for-each-ref --format if we could
- # rely on git 1.9.0+, but it's too soon for that in early 2017...
- my $cmd = $git->cmd(qw(symbolic-ref HEAD));
- my $rdr = { 2 => $git->err_begin };
- my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
sub {
my ($res) = @_; # Plack streaming callback
- $qsp->psgi_qx($env, undef, sub {
- chomp(my $head_ref = ${$_[0]});
- for_each_ref($self, $req, $res, $head_ref);
- });
+ for_each_ref($self, $req, $res, $req->{-repo}->tip);
}
}
sub readme_path_links {
my ($req, $rel, $readme) = @_;
my @path = split(m!/+!, $readme);
-
- my $s = "tree <a\nhref=\"${rel}tree/$req->{-tip}\">root</a>/";
+ my $tip = $req->{-repo}->tip;
+ my $s = "tree <a\nhref=\"${rel}tree/$tip\">root</a>/";
my @t;
$s .= join('/', (map {
push @t, $_;
my $e = PublicInbox::Hval->utf8($_, join('/', @t));
my $ep = $e->as_path;
my $eh = $e->as_html;
- $e = "<a\nhref=\"${rel}tree/$req->{-tip}/$ep\">$eh</a>";
+ $e = "<a\nhref=\"${rel}tree/$tip/$ep\">$eh</a>";
# bold the last one
scalar(@t) == scalar(@path) ? "<b>$e</b>" : $e;
} @path));
sub call_git_tree {
my ($self, $req) = @_;
my @extra = @{$req->{extra}};
- my $git = $req->{-repo}->{git};
- my $obj = "$req->{-tip}:$req->{expath}";
+ my $repo = $req->{-repo};
+ my $git = $repo->{git};
+ my $tip = $repo->tip;
+ my $obj = "$tip:$req->{expath}";
my ($hex, $type, $size) = $git->check($obj);
unless (defined($type)) {
my @ex = @{$req->{extra}} or return '<b>root</b>';
my $s;
- my $tip = $req->{-tip};
+ my $tip = $req->{-repo}->tip;
my $rel = $req->{relcmd};
# avoid relative paths, here, we don't want to propagate
# trailing-slash URLs although we tolerate them
my $text_p;
my $n = 0;
- my $tip = $req->{-tip};
my $rel = $req->{relcmd};
- my $plain = join('/', "${rel}plain/$tip", @{$req->{extra}});
+ my $plain = join('/',
+ "${rel}plain", $req->{-repo}->tip, @{$req->{extra}});
$plain = PublicInbox::Hval->utf8($plain)->as_path;
my $t = cur_path($req);
my $s = qq{\npath: $t\n\nblob $hex};
} elsif (defined(my $last = $req->{extra}->[-1])) {
$pfx = PublicInbox::Hval->utf8($last)->as_path;
} elsif (defined $req->{h}) {
- $pfx = $req->{-tip};
+ $pfx = $req->{-repo}->tip;
} else {
- $pfx = 'tree/' . $req->{-tip};
+ $pfx = 'tree/' . $req->{-repo}->tip;
}
$req->{tpfx} = $pfx;
my $env = $req->{env};
++$tslash;
}
$req->{h} = $h;
- $req->{-tip} = defined $h ? $h : 'HEAD';
return no_tslash($env) if ($tslash && $NO_TSLASH{$mod});
$req->{tslash} = $tslash;