+sub local_nick ($) {
+ my ($self) = @_;
+ my $ret = '???';
+ # don't show full FS path, basename should be OK:
+ if ($self->{git_dir} =~ m!/([^/]+)(?:/\.git)?\z!) {
+ $ret = "/path/to/$1";
+ }
+ wantarray ? ($ret) : $ret;
+}
+
+sub host_prefix_url ($$) {
+ my ($env, $url) = @_;
+ return $url if index($url, '//') >= 0;
+ my $scheme = $env->{'psgi.url_scheme'};
+ my $host_port = $env->{HTTP_HOST} ||
+ "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
+ "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url;
+}
+
+sub pub_urls {
+ my ($self, $env) = @_;
+ if (my $urls = $self->{cgit_url}) {
+ return map { host_prefix_url($env, $_) } @$urls;
+ }
+ local_nick($self);
+}
+
+sub cat_async_begin {
+ my ($self) = @_;
+ cleanup($self) if alternates_changed($self);
+ batch_prepare($self);
+ die 'BUG: already in async' if $self->{inflight};
+ $self->{inflight} = [];
+}
+
+sub cat_async ($$$;$) {
+ my ($self, $oid, $cb, $arg) = @_;
+ my $inflight = $self->{inflight} or die 'BUG: not in async';
+ if (scalar(@$inflight) >= MAX_INFLIGHT) {
+ _cat_async_step($self, $inflight, $self->{in});
+ }
+
+ $self->{out}->print($oid, "\n") or fail($self, "write error: $!");
+ push(@$inflight, [ $cb, $arg ]);
+}
+
+sub commit_title ($$) {
+ my ($self, $oid) = @_; # PublicInbox::Git, $sha1hex
+ my $buf = cat_file($self, $oid) or return;
+ utf8::decode($$buf);
+ ($$buf =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/)[0]
+}
+
+# returns the modified time of a git repo, same as the "modified" field
+# of a grokmirror manifest
+sub modified ($) {
+ my ($self) = @_;
+ my $modified = 0;
+ my $fh = popen($self, qw(rev-parse --branches));
+ defined $fh or return $modified;
+ local $/ = "\n";
+ foreach my $oid (<$fh>) {
+ chomp $oid;
+ my $buf = cat_file($self, $oid) or next;
+ $$buf =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm or next;
+ my $cmt_time = $1 + 0;
+ $modified = $cmt_time if $cmt_time > $modified;
+ }
+ $modified || time;
+}
+