- my ($self) = @_;
- my $modified = 0;
- my $fh = popen($self, qw(rev-parse --branches));
- local $/ = "\n";
- while (my $oid = <$fh>) {
- chomp $oid;
- cat_async($self, $oid, \&extract_cmt_time, \$modified);
- }
- cat_async_wait($self);
- $modified || time;
+ # committerdate:unix is git 2.9.4+ (2017-05-05), so using raw instead
+ my $fh = popen($_[0], qw[for-each-ref --sort=-committerdate
+ --format=%(committerdate:raw) --count=1]);
+ (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) ];