]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
git: calculate modified time of repository
[public-inbox.git] / lib / PublicInbox / Git.pm
index 8a96e10c1139be7d4d1b44e959e1ea9e3d676f38..236f70c165af6a275ab0898486cb7992700bae09 100644 (file)
@@ -312,6 +312,24 @@ sub commit_title ($$) {
        ($$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 .*?> (\d+) [\+\-]?\d+/sm or next;
+               my $cmt_time = $1;
+               $modified = $cmt_time if $cmt_time > $modified;
+       }
+       $modified || time;
+}
+
 1;
 __END__
 =pod