$self->{-git_path}->{$path} ||= do {
local $/ = "\n";
chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
+
+ # git prior to 2.5.0 did not understand --git-path
+ if ($str eq "--git-path\n$path") {
+ $str = "$self->{git_dir}/$path";
+ }
$str;
};
}
}
return;
}
- $head =~ /^[0-9a-f]{40} \S+ (\d+)$/ or
+ $head =~ /^[0-9a-f]{40} \S+ ([0-9]+)$/ or
fail($self, "Unexpected result from git cat-file: $head");
my $size = $1;
}
sub _destroy {
- my ($self, $in, $out, $pid) = @_;
+ my ($self, $in, $out, $pid, $err) = @_;
my $p = delete $self->{$pid} or return;
- foreach my $f ($in, $out) {
- delete $self->{$f};
- }
+ delete @$self{($in, $out)};
+ delete $self->{$err} if $err; # `err_c'
waitpid $p, 0;
}
<$fh>
}
+# returns true if there are pending "git cat-file" processes
sub cleanup {
my ($self) = @_;
_destroy($self, qw(in out pid));
- _destroy($self, qw(in_c out_c pid_c));
+ _destroy($self, qw(in_c out_c pid_c err_c));
+ !!($self->{pid} || $self->{pid_c});
}
# assuming a well-maintained repo, this should be a somewhat
local_nick($self);
}
+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) = @_;
+ my ($self, $env) = @_;
if (my $urls = $self->{cgit_url}) {
- return @$urls;
+ return map { host_prefix_url($env, $_) } @$urls;
}
local_nick($self);
}
+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;
+}
+
1;
__END__
=pod