X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit-badcommit-fixup;h=bab8605aed270ea83d96f8f3c47ea8896b96fd10;hp=f507e48c28072bfcb5e4cfb1ff7c1ba3af622ff0;hb=191a070be86cf2dda2da63b089ef9b6c45d3c1db;hpb=86cbeb5e4396d0722aaf3049cc01d084117bb8a4 diff --git a/dgit-badcommit-fixup b/dgit-badcommit-fixup index f507e48c..bab8605a 100755 --- a/dgit-badcommit-fixup +++ b/dgit-badcommit-fixup @@ -79,6 +79,7 @@ sub rewrite_commit ($) { my $m = \ $memo{$obj}; return $$m if defined $$m; my $olddata = getobj $obj, 'commit'; +#print STDERR ">$obj|$olddata<\n"; $olddata =~ m/(?<=\n)(?=\n)/ or die "$obj ?"; my $msg = $'; local $_ = $`; @@ -104,10 +105,36 @@ sub rewrite_commit ($) { return $newobj; } -sub rewrite_commit_adddummy ($$$) { - my ($ref, $veryold, $old) = @_; +our @updates; + +sub filter_updates () { + @updates = grep { $_->[1] ne $_->[2] } @updates; +} + +sub rewrite_tag ($) { + my ($obj) = @_; + $_ = getobj $obj, 'tag'; + m/^type (\w+)\n/m or die "$obj ?"; + if ($1 ne 'commit') { + $count{"oddtags $1"}++; + return $obj; + } + m/^object (\w+)\n/m or die "$obj ?"; + my $oldref = $1; + my $newref = rewrite_commit $oldref; + if ($oldref eq $newref) { + return $obj; + } + s/^(object )\w+$/ $1.$newref /me or die "$obj ($_) ?"; + s/^-----BEGIN PGP SIGNATURE-----\n.*^-----END PGP SIGNATURE-----\n$//sm; + return hashobj $_, 'tag'; +} + +sub edit_rewrite_map ($) { + my ($old) = @_; - die "$bare ?" unless $bare eq 'true'; + filter_updates(); + return $old unless @updates; my $td = 'dgit-broken-fixup.tmp'; runcmd qw(rm -rf), $td; @@ -117,45 +144,39 @@ sub rewrite_commit_adddummy ($$$) { runcmd qw(git config gc.auto 0); runcmd qw(rm -rf .git/objects); symlink "../../objects", ".git/objects" or die $!; - runcmd qw(git checkout -q), $old; - open C, "debian/changelog" or die $!; - my $clog = do { - local $/ = undef; - ; - }; - C->error and die $!; - close C or die $!; - defined $clog or die $!; + my %map; - $!=0; $?=0; - my $v = `dpkg-parsechangelog`; - die "$ref $veryold $old $? $!" if $?; - $v =~ m/^Source: (\S+)$/m or die "$ref $veryold $old ?"; - my $pkg = $1; - $v =~ m/^Version: (\S+)$/m or die "$ref $veryold $old ?"; - my $vsn = $1; - $vsn .= "+~dgitfix"; - - open C, ">", "debian/changelog" or die $!; - print C <) { + m/^(\w+)(?:\s+(\w+))?$/ or die; + $map{$1} = $2; + $count{rewrite_map_previous}++; + } + M->error and die $!; + close M or die $!; + } - * Additional commit, with slightly incremented version number, - to override bad commits generated by dgit due to #849041. - * No changes to the package. - * Not uploaded anywhere. + foreach my $up (@updates) { + $map{ $up->[1] } = $up->[2]; + } - -- Ian Jackson Thu, 05 Jan 2017 17:58:21 +0000 + open M, ">", "map" or die $!; + printf M "%s%s\n", + $_, (defined $map{$_} ? " $map{$_}" : "") + or die $! + foreach keys %map; + close M or die $!; -END - print C $clog or die $!; - close C or die $!; + if (!$old) { + runcmd qw(git add map); + } runcmd qw(git commit -q), - '--author=Ian Jackson ', - qw(-m), 'Dummy changelog entry to work around #849041 fallout', - qw(debian/changelog); + qw(-m), 'dgit-badcommit-fixup', + qw(map); $!=0; $?=0; my $new = `git rev-parse HEAD`; @@ -165,60 +186,53 @@ END chdir '..' or die $!; runcmd qw(rm -rf), $td; - $count{dummyadded}++; + $count{rewrite_map_updated}++; return $new; } -sub rewrite_tag ($) { - my ($obj) = @_; - $_ = getobj $obj, 'tag'; - m/^type (\w+)\n/m or die "$obj ?"; - if ($1 ne 'commit') { - $count{"oddtags $1"}++; - return $obj; - } - m/^object (\w+)\n/m or die "$obj ?"; - my $oldref = $1; - my $newref = rewrite_commit $oldref; - if ($oldref eq $newref) { - return $obj; - } - s/^(object )\w+$/ $1.$newref /me or die "$obj ($_) ?"; - s/^-----BEGIN PGP SIGNATURE-----\n.*^-----END PGP SIGNATURE-----\n$//sm; - return hashobj $_, 'tag'; -} - $!=0; $?=0; my $refs=`git for-each-ref`; die "$? $!" if $?; chomp $refs; -our @updates; +our $org_rewrite_map; foreach my $rline (split /\n/, $refs) { my ($obj, $type, $refname) = $rline =~ m/^(\w+)\s+(\w+)\s+(\S.*)/ or die "$_ ?"; + if ($refname eq 'refs/dgit-rewrite/map') { + $org_rewrite_map = $obj; + continue; + } my $rewrite; if ($type eq 'commit') { $rewrite = rewrite_commit($obj); - if ($refname =~ m{^refs/dgit/[^/]+$} && - $rewrite ne $obj) { - $rewrite = rewrite_commit_adddummy $refname, $obj, $rewrite; - } } elsif ($type eq 'tag') { $rewrite = rewrite_tag($obj); } else { warn "ref $refname refers to $type\n"; next; } - next if $rewrite eq $obj; push @updates, [ $refname, $obj, $rewrite ]; } -our $worktree; +if ($bare eq 'true') { + my $new_rewrite_map = edit_rewrite_map($org_rewrite_map); + push @updates, [ 'refs/dgit-rewrite/map', + ($org_rewrite_map // '0'x40), + ($new_rewrite_map // '0'x40), + 1 ]; +} + +filter_updates(); + +if (!@updates) { + print Dumper(\%count), "nothing to do\n"; + exit 0; +} #print Dumper(\@updates); @@ -230,12 +244,14 @@ if ($real && $bare eq 'false') { } for my $up (@updates) { - my ($ref, $old, $new) = @$up; + my ($ref, $old, $new, $nobackup) = @$up; my $otherref = $ref; $otherref =~ s{^refs/}{}; if ($real) { - print U <