about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-11 23:30:45 +0000
committerEric Wong <e@80x24.org>2021-09-12 02:09:43 +0000
commit610d89af015337ac0ba09dedeb71d1ff1d2326ea (patch)
tree4be7ec334765ebfc14183a6c88c0ab92982b183c /lib/PublicInbox/Git.pm
parentaa500f0243133f2e9e0c912eea3497e52ebc1903 (diff)
downloadpublic-inbox-610d89af015337ac0ba09dedeb71d1ff1d2326ea.tar.gz
When generating per-inbox manifests, we were forgetting to
cleanup per-epoch "git cat-file --batch" processes.  Our
previous method of generating modified times was also stupidly
inefficient, so replace the pipeline with a single
"git for-each-ref" invocation.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm25
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index e557f6d6..219a1732 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -16,7 +16,7 @@ use Errno qw(EINTR EAGAIN);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
 use File::Spec ();
 use Time::HiRes qw(stat);
-use PublicInbox::Spawn qw(popen_rd);
+use PublicInbox::Spawn qw(popen_rd spawn);
 use PublicInbox::Tmpfile;
 use IO::Poll qw(POLLIN);
 use Carp qw(croak);
@@ -466,28 +466,13 @@ sub cat_async ($$$;$) {
         push(@$inflight, $oid, $cb, $arg);
 }
 
-sub extract_cmt_time {
-        my ($bref, undef, undef, undef, $modified) = @_;
-
-        if ($$bref =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm) {
-                my $cmt_time = $1 + 0;
-                $$modified = $cmt_time if $cmt_time > $$modified;
-        }
-}
-
 # 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));
-        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
 }
 
 # for grokmirror, which doesn't read gitweb.description