X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=git-debrebase;h=932a3b7a6aed3b67fe40d9846aa5366da1432d78;hp=5adbb8fecdfcc702b5822b1ea7e118942369bbd4;hb=c386ae2688431a622f9d41b3668755420fcbed39;hpb=0ec2b529f2c6579ee279666b079d9b91c393365a diff --git a/git-debrebase b/git-debrebase index 5adbb8fe..932a3b7a 100755 --- a/git-debrebase +++ b/git-debrebase @@ -28,11 +28,13 @@ # # git-debrebase [ --] [] # git-debrebase [] analyse +# git-debrebase [] breakwater # prints breakwater tip only # git-debrebase [] launder # prints breakwater tip etc. # git-debrebase [] stitch [--prose=] # git-debrebase [] downstream-rebase-launder-v0 # experimental # -# git-debrebase [] convert-from-gbp +# git-debrebase [] convert-from-gbp [] +# git-debrebase [] convert-to-gbp # problems / outstanding questions: # @@ -317,7 +319,6 @@ sub any_fproblems () { # Upstream # AddPatches # Mixed -# Unknown # # Pseudomerge # has additional entres in classification result @@ -331,6 +332,10 @@ sub any_fproblems () { # BreakwaterUpstreamMerge # has additional entry in classification result # OrigParents = [ subset of Parents ] # singleton list +# +# Unknown +# has additional entry in classification result +# Why => "prose" sub parsecommit ($;$) { my ($objid, $p_ref) = @_; @@ -389,7 +394,7 @@ sub classify ($) { }; my $unknown = sub { my ($why) = @_; - $r = { %$r, Type => qw(Unknown) }; + $r = { %$r, Type => qw(Unknown), Why => $why }; printdebug " ** Unknown\n"; return $r; }; @@ -445,15 +450,24 @@ sub classify ($) { Contributor => $identical[0]); } if (@p == 2 && @identical == 2) { - my @bytime = nsort_by { - my ($ph,$pm) = get_commit $_->{CommitId}; + my $get_t = sub { + my ($ph,$pm) = get_commit $_[0]{CommitId}; $ph =~ m/^committer .* (\d+) [-+]\d+$/m or die "$_->{CommitId} ?"; $1; - } @p; + }; + my @bytime = @p; + my $order = $get_t->($bytime[0]) <=> $get_t->($bytime[1]); + if ($order > 0) { # newer first + } elsif ($order < 0) { + @bytime = reverse @bytime; + } else { + # same age, default to order made by -s ours + # that is, commit was made by someone who preferred L + } return $classify->(qw(Pseudomerge), SubType => qw(Ambiguous), - Overwritten => [ $bytime[0] ], - Contributor => $bytime[1]); + Contributor => $bytime[0], + Overwritten => [ $bytime[1] ]); } foreach my $p (@p) { my ($p_h, $p_m) = get_commit $p->{CommitId}; @@ -505,6 +519,42 @@ sub classify ($) { return $unknown->("complex merge"); } +sub breakwater_of ($) { + my ($head) = @_; # must be laundered + my $breakwater; + my $unclean = sub { + my ($why) = @_; + fail "branch needs laundering (run git-debrebase): $why"; + }; + for (;;) { + my $cl = classify $head; + my $ty = $cl->{Type}; + if ($ty eq 'Packaging' or + $ty eq 'Changelog') { + $breakwater //= $head; + } elsif ($ty eq 'BreakwaterUpstreamMerge' or + $ty eq 'BreakwaterStart') { + $breakwater //= $head; + last; + } elsif ($ty eq 'Upstream') { + $unclean->("packaging change ($breakwater)". + " follows upstream change (eg $head)") + if defined $breakwater; + } elsif ($ty eq 'Mixed') { + $unclean->('found mixed upstream/packaging commit ($head)'); + } elsif ($ty eq 'Pseudomerge' or + $ty eq 'AddPatches') { + $unclean->("found interchange conversion commit ($ty, $head)"); + } elsif ($ty eq 'DgitImportUnpatched') { + $unclean->("found dgit dsc import ($head)"); + } else { + fail "found unprocessable commit, cannot cope: $head; $cl->{Why}"; + } + $head = $cl->{Parents}[0]{CommitId}; + } + return $breakwater; +} + sub walk ($;$$); sub walk ($;$$) { my ($input, @@ -549,13 +599,16 @@ sub walk ($;$$) { my $bomb = sub { # usage: return $bomb->(); print $report " Unprocessable" if $report; + print $report " ($cl->{Why})" if $report && defined $cl->{Why}; $prprdelim->(); if ($nogenerate) { return (undef,undef); } die "commit $cur: Cannot cope with this commit (d.". (join ' ', map { sprintf "%#x", $_->{Differs} } - @{ $cl->{Parents} }). ")"; + @{ $cl->{Parents} }). + (defined $cl->{Why} ? "; $cl->{Why}": ''). + ")"; }; my $build; @@ -1130,6 +1183,12 @@ sub cmd_record_ffq_prev () { } } +sub cmd_breakwater () { + badusage "no arguments allowed" if @ARGV; + my $bw = breakwater_of git_rev_parse 'HEAD'; + print "$bw\n" or die $!; +} + sub cmd_stitch () { my $prose = ''; GetOptions('prose=s', \$prose) or die badusage("bad options to stitch"); @@ -1231,6 +1290,36 @@ sub cmd_convert_from_gbp () { update_head_checkout $old_head, $work, 'convert-from-gbp'; } +sub cmd_convert_to_gbp () { + badusage "no arguments allowed" if @ARGV; + my $head = get_head(); + my $ffq = (ffq_prev_branchinfo())[3]; + my $bw = breakwater_of $head; + fresh_workarea(); + my $out; + in_workarea sub { + runcmd @git, qw(checkout -q -b bw), $bw; + runcmd @git, qw(checkout -q -b patch-queue/bw), $head; + runcmd qw(gbp pq export); + runcmd @git, qw(add debian/patches); + $out = make_commit ['HEAD'], [ + 'Commit patch queue (converted from git-debrebase format)', + '[git-debrebase convert-to-gbp: commit patches]', + ]; + }; + if (defined $ffq) { + runcmd @git, qw(update-ref -m), + "debrebase: converting corresponding main branch to gbp format", + $ffq, $git_null_obj; + } + update_head_checkout $head, $out, "convert to gbp (v0)"; + print <