X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FGit.pm;h=395add1fecee08305e6748b989a341b89b0b526d;hb=6dec9bf8c0e1b859703d7a5dfb87052cf4e87846;hp=309f80dbfcf001e51f130cddee1a14ee38303dd3;hpb=8d2513221e73649aed85ce8c3f37f7025ec1fec9;p=public-inbox.git diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 309f80db..395add1f 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2021 all contributors +# Copyright (C) all contributors # License: GPLv2 or later # # Used to read files from a git repository without excessive forking. @@ -66,7 +66,7 @@ sub new { $git_dir =~ tr!/!/!s; $git_dir =~ s!/*\z!!s; # may contain {-tmp} field for File::Temp::Dir - bless { git_dir => $git_dir, alt_st => '', -git_path => {} }, $class + bless { git_dir => $git_dir }, $class } sub git_path ($$) { @@ -90,10 +90,17 @@ sub alternates_changed { # can't rely on 'q' on some 32-bit builds, but `d' works my $st = pack('dd', $st[10], $st[7]); # 10: ctime, 7: size - return 0 if $self->{alt_st} eq $st; + return 0 if ($self->{alt_st} // '') eq $st; $self->{alt_st} = $st; # always a true value } +sub object_format { + $_[0]->{object_format} //= do { + my $fmt = $_[0]->qx(qw(config extensions.objectformat)); + $fmt eq "sha256\n" ? \'sha256' : \undef; + } +} + sub last_check_err { my ($self) = @_; my $fh = $self->{err_c} or return; @@ -342,7 +349,7 @@ sub async_abort ($) { while (scalar(@{$self->{inflight_c} // []}) || scalar(@{$self->{inflight} // []})) { for my $c ('', '_c') { - my $q = $self->{"inflight$c"}; + my $q = $self->{"inflight$c"} or next; while (@$q) { my ($req, $cb, $arg) = splice(@$q, 0, 3); $req = $$req if ref($req); @@ -456,6 +463,16 @@ sub host_prefix_url ($$) { "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url; } +sub base_url { # for coderepos, PSGI-only + my ($self, $env) = @_; # env - PSGI env + my $url = host_prefix_url($env, ''); + # for mount in Plack::Builder + $url .= '/' if substr($url, -1, 1) ne '/'; + $url . $self->{nick} . '/'; +} + +sub isrch {} # TODO + sub pub_urls { my ($self, $env) = @_; if (my $urls = $self->{cgit_url}) { @@ -491,6 +508,33 @@ sub modified ($) { (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON } +sub try_cat { + my ($path) = @_; + open(my $fh, '<', $path) or return ''; + local $/; + <$fh> // ''; +} + +sub cat_desc ($) { + my $desc = try_cat($_[0]); + chomp $desc; + utf8::decode($desc); + $desc =~ s/\s+/ /smg; + $desc eq '' ? undef : $desc; +} + +sub description { + cat_desc("$_[0]->{git_dir}/description") // 'Unnamed repository'; +} + +sub cloneurl { + my ($self, $env) = @_; + $self->{cloneurl} // do { + my @urls = split(/\s+/s, try_cat("$self->{git_dir}/cloneurl")); + scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef; + } // [ substr(base_url($self, $env), 0, -1) ]; +} + # for grokmirror, which doesn't read gitweb.description # templates/hooks--update.sample and git-multimail in git.git # only match "Unnamed repository", not the full contents of @@ -513,14 +557,8 @@ sub manifest_entry { chomp(my $owner = $self->qx('config', 'gitweb.owner')); utf8::decode($owner); $ent->{owner} = $owner eq '' ? undef : $owner; - my $desc = ''; - if (open($fh, '<', "$git_dir/description")) { - local $/ = "\n"; - chomp($desc = <$fh>); - utf8::decode($desc); - } - $desc = 'Unnamed repository' if $desc eq ''; - if (defined $epoch && $desc =~ /\AUnnamed repository/) { + my $desc = description($self); + if (defined $epoch && index($desc, 'Unnamed repository') == 0) { $desc = "$default_desc [epoch $epoch]"; } $ent->{description} = $desc;