]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: set {head} from manifest
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:32:22 +0000 (05:32 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:38:59 +0000 (23:38 +0000)
We handle symbolic refs properly, at least.  It's also possible
for $GIT_DIR/HEAD to contain a full SHA-1/SHA-256, and we'll
support that by using update-ref --no-deref

lib/PublicInbox/LeiMirror.pm

index f7db5a494e09f36ffdd0780379270298bdbf9355..fc5bc88d86acba0edff1f3c68c13ed9caf93a0a6 100644 (file)
@@ -678,6 +678,23 @@ sub update_ent {
                my $done = PublicInbox::OnDestroy->new($$, \&up_fp_done, $self);
                start_cmd($self, $cmd, $opt, $done);
        }
+
+       $new = $self->{-ent}->{head};
+       $cur = $self->{-local_manifest}->{$key}->{head} // "\0";
+       if (defined($new) && $new ne $cur) {
+               # n.b. grokmirror writes raw contents to $dst/HEAD w/o locking
+               my $cmd = [ 'git', "--git-dir=$dst" ];
+               if ($new =~ s/\Aref: //) {
+                       push @$cmd, qw(symbolic-ref HEAD), $new;
+               } elsif ($new =~ /\A[a-f0-9]{40,}\z/) {
+                       push @$cmd, qw(update-ref --no-deref HEAD), $new;
+               } else {
+                       undef $cmd;
+                       warn "W: $key: {head} => `$new' not understood\n";
+               }
+               start_cmd($self, $cmd, { 2 => $self->{lei}->{2} }) if $cmd;
+       }
+
        $new = $self->{-ent}->{owner} // return;
        $cur = $self->{-local_manifest}->{$key}->{owner} // "\0";
        return if $cur eq $new;