]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: rewrite less history during purge
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 4 Apr 2018 21:24:58 +0000 (21:24 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 4 Apr 2018 21:54:42 +0000 (21:54 +0000)
We do not need to rewrite old commits unaffected by the object_id
purge, only newer commits.  This was a state management bug :x

We will also return the new commit ID of rewritten history to
aid in incremental indexing of mirrors for the next change.

lib/PublicInbox/Import.pm
lib/PublicInbox/V2Writable.pm
t/v2writable.t

index b2aae9a7a800c8dbc0d738a8ef63eeea6e2f104d..73290eed5a04d37a8328eb39bd217cf2258fd6a7 100644 (file)
@@ -476,6 +476,7 @@ sub purge_oids {
        my @buf;
        my $npurge = 0;
        my @oids;
+       my ($done, $mark);
        my $tree = $self->{-tree};
        while (<$rd>) {
                if (/^reset (?:.+)/) {
@@ -506,14 +507,20 @@ sub purge_oids {
                        my $path = $1;
                        push @buf, $_ if $tree->{$path};
                } elsif ($_ eq "\n") {
-                       my $out = join('', @buf);
-                       $out =~ s/^/# /sgm;
-                       warn "purge rewriting\n", $out, "\n";
-                       clean_purge_buffer(\@oids, \@buf);
-                       $out = join('', @buf);
+                       if (@oids) {
+                               my $out = join('', @buf);
+                               $out =~ s/^/# /sgm;
+                               warn "purge rewriting\n", $out, "\n";
+                               clean_purge_buffer(\@oids, \@buf);
+                               $npurge++;
+                       }
                        $w->print(@buf, "\n") or wfail;
                        @buf = ();
-                       $npurge++;
+               } elsif ($_ eq "done\n") {
+                       $done = 1;
+               } elsif (/^mark :(\d+)$/) {
+                       push @buf, $_;
+                       $mark = $1;
                } else {
                        push @buf, $_;
                }
@@ -521,7 +528,9 @@ sub purge_oids {
        if (@buf) {
                $w->print(@buf) or wfail;
        }
-       $w = $r = undef;
+       die 'done\n not seen from fast-export' unless $done;
+       chomp(my $cmt = $self->get_mark(":$mark")) if $npurge;
+       $self->{nchg} = 0; # prevent _update_git_info until update-ref:
        $self->done;
        my @git = ('git', "--git-dir=$git->{git_dir}");
 
@@ -540,7 +549,9 @@ sub purge_oids {
                        $err++;
                }
        }
+       _update_git_info($self, 0);
        die "Failed to purge $err object(s)\n" if $err;
+       $cmt;
 }
 
 1;
index 479e2b5daafbd25c0868a0a762fea6edee65a794..b6532ac5c9476540017f9ee9757cdc7c533cfb46 100644 (file)
@@ -224,11 +224,13 @@ sub purge_oids {
        my ($self, $purge) = @_; # $purge = { $object_id => 1, ... }
        $self->done;
        my $pfx = "$self->{-inbox}->{mainrepo}/git";
+       my $purges = [];
        foreach my $i (0..$self->{max_git}) {
                my $git = PublicInbox::Git->new("$pfx/$i.git");
                my $im = $self->import_init($git, 0);
-               $im->purge_oids($purge);
+               $purges->[$i] = $im->purge_oids($purge);
        }
+       $purges;
 }
 
 sub remove_internal {
@@ -285,7 +287,7 @@ sub remove_internal {
                $self->barrier;
        }
        if ($purge && scalar keys %$purge) {
-               purge_oids($self, $purge);
+               return purge_oids($self, $purge);
        }
        $removed;
 }
index 2f8397764dae098923e5a5723d06313b238df417..e49c06b98c0efde79faf596f22891bddc0cdc084 100644 (file)
@@ -248,7 +248,8 @@ EOF
 {
        ok($im->add($mime), 'add message to be purged');
        local $SIG{__WARN__} = sub {};
-       ok($im->purge($mime), 'purged message');
+       ok(my $cmts = $im->purge($mime), 'purged message');
+       like($cmts->[0], qr/\A[a-f0-9]{40}\z/, 'purge returned current commit');
        $im->done;
 }