- my $mkey = 'last_commit';
- my $last_commit = $xdb->get_metadata($mkey);
- my $lx = $last_commit;
- if ($reindex) {
- $lx = '';
- $mkey = undef if $last_commit ne '';
- }
- my $dbh;
+ my ($mkey, $last_commit, $lx, $xlog);
+ my $xdb = _xdb_acquire($self);
+ $xdb->begin_transaction;
+ do {
+ $xlog = undef;
+ $mkey = 'last_commit';
+ $last_commit = $xdb->get_metadata('last_commit');
+ $lx = $last_commit;
+ if ($reindex) {
+ $lx = '';
+ $mkey = undef if $last_commit ne '';
+ }
+ $xdb->cancel_transaction;
+ $xdb = _xdb_release($self);
+
+ # ensure we leak no FDs to "git log"
+ my $range = $lx eq '' ? $tip : "$lx..$tip";
+ $xlog = _git_log($self, $range);
+
+ $xdb = _xdb_acquire($self);
+ $xdb->begin_transaction;
+ } while ($xdb->get_metadata('last_commit') ne $last_commit);
+
+ my $mm = _msgmap_init($self);
+ my $dbh = $mm->{dbh} if $mm;