]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei_mirror: unlink FETCH_HEAD when fetching forkgroups
authorEric Wong <e@80x24.org>
Wed, 8 Mar 2023 11:02:58 +0000 (11:02 +0000)
committerEric Wong <e@80x24.org>
Thu, 9 Mar 2023 18:59:23 +0000 (18:59 +0000)
Apparently, --no-write-fetch-head is broken in current git[1].
It also wasn't in older git, at all.  So just unlink FETCH_HEAD
as we see it, but keep using --no-write-fetch-head to avoid the
syscall and I/O overhead when we can.

[1] https://yhbt.net/lore/git/20230308100438.908471-1-e@80x24.org/

lib/PublicInbox/LeiMirror.pm

index 8731119877d60029475074c89e70704a40ba5cf2..c148ebfd6a4b5b11fd29d049d5403cd7425a85d3 100644 (file)
@@ -358,11 +358,18 @@ sub pack_refs {
        start_cmd($self, $cmd, { 2 => $self->{lei}->{2} });
 }
 
+sub unlink_fetch_head ($) {
+       my ($git_dir) = @_;
+       return if unlink("$git_dir/FETCH_HEAD") || $!{ENOENT};
+       warn "W: unlink($git_dir/FETCH_HEAD): $!";
+}
+
 sub fgrpv_done {
        my ($fgrpv) = @_;
        return if !$LIVE;
        my $first = $fgrpv->[0] // die 'BUG: no fgrpv->[0]';
        return if !keep_going($first);
+       unlink_fetch_head($first->{-osdir}) if !$first->{dry_run};
        pack_refs($first, $first->{-osdir}); # objstore refs always packed
        for my $fgrp (@$fgrpv) {
                my $rn = $fgrp->{-remote};
@@ -817,6 +824,7 @@ sub v1_done { # called via OnDestroy
        return if $self->{dry_run} || !keep_going($self);
        _write_inbox_config($self);
        my $dst = $self->{cur_dst} // $self->{dst};
+       unlink_fetch_head($dst);
        update_ent($self) if $self->{-ent};
        my $o = "$dst/objects";
        if (open(my $fh, '<', my $fn = "$o/info/alternates")) {;