#
# git-debrebase [<options> --] [<git-rebase options...>]
# git-debrebase [<options>] analyse
+# git-debrebase [<options>] breakwater # prints breakwater tip only
# git-debrebase [<options>] launder # prints breakwater tip etc.
# git-debrebase [<options>] stitch [--prose=<for commit message>]
# git-debrebase [<options>] downstream-rebase-launder-v0 # experimental
#
-# git-debrebase [<options>] convert-from-gbp <upstream-git-rev>
+# git-debrebase [<options>] convert-from-gbp [<upstream-git-rev>]
+# git-debrebase [<options>] convert-to-gbp
# problems / outstanding questions:
#
fail "missing required git config $k" unless $optional;
return ();
}
- return split /\0/, $out;
+ my @l = split /\0/, $out;
+ return wantarray ? @l : $l[0];
}
memoize('cfg');
# Upstream
# AddPatches
# Mixed
-# Unknown
#
# Pseudomerge
# has additional entres in classification result
# 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) = @_;
};
my $unknown = sub {
my ($why) = @_;
- $r = { %$r, Type => qw(Unknown) };
+ $r = { %$r, Type => qw(Unknown), Why => $why };
printdebug " ** Unknown\n";
return $r;
};
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};
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,
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;
return ('weird-symref', 'HEAD symref is not to refs/')
unless $current =~ m{^refs/};
my $ffq_prev = "refs/$ffq_refprefix/$'";
+ printdebug "ffq_prev_branchinfo branch current $current\n";
return ('branch', undef, $current, $ffq_prev);
}
my @check_specs = split /\;/, (cfg "branch.$branch.ffq-ffrefs",1) // '*';
my %checked;
+ printdebug "ffq check_specs @check_specs\n";
+
my $check = sub {
my ($lrref, $desc) = @_;
+ printdebug "ffq might check $lrref ($desc)\n";
my $invert;
for my $chk (@check_specs) {
my $glob = $chk;
- $invert = $glob =~ s{^[^!]}{};
+ $invert = $glob =~ s{^[!^]}{};
last if fnmatch $glob, $lrref;
}
return if $invert;
if (is_fast_fwd $lrval, $currentval) {
print "OK, you are ahead of $lrref\n" or die $!;
$checked{$lrref} = 1;
- } if (is_fast_fwd $currentval, $lrval) {
+ } elsif (is_fast_fwd $currentval, $lrval) {
$checked{$lrref} = -1;
fproblem 'behind', "you are behind $lrref, divergence risk";
} else {
};
my $merge = cfg "branch.$branch.merge",1;
- if (defined $merge && $merge =~ m{^refs/heads/}) {
+ if (defined $merge and $merge =~ m{^refs/heads/}) {
my $rhs = $';
+ printdebug "ffq merge $rhs\n";
my $check_remote = sub {
- my ($remote, $desc) = (@_);
+ my ($remote, $desc) = @_;
+ printdebug "ffq check_remote ".($remote//'undef')." $desc\n";
return unless defined $remote;
$check->("refs/remotes/$remote/$rhs", $desc);
};
- $check_remote->((cfg "branch.$branch.remote",1),
+ $check_remote->((scalar cfg "branch.$branch.remote",1),
'remote fetch/merge branch');
- $check_remote->((cfg "branch.$branch.pushRemote",1) //
- (cfg "branch.$branch.pushDefault",1),
+ $check_remote->((scalar cfg "branch.$branch.pushRemote",1) //
+ (scalar cfg "branch.$branch.pushDefault",1),
'remote push branch');
}
if ($branch =~ m{^dgit/}) {
- $check->("remotes/dgit/$branch", 'remote dgit branch');
+ $check->("refs/remotes/dgit/$branch", 'remote dgit branch');
} elsif ($branch =~ m{^master$}) {
- $check->("remotes/dgit/dgit/sid", 'remote dgit branch for sid');
+ $check->("refs/remotes/dgit/dgit/sid", 'remote dgit branch for sid');
}
fproblems_maybe_bail();
}
}
+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");
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 <<END or die $!;
+git-debrebase: converted to git-buildpackage branch format
+git-debrebase: WARNING: do not now run "git-debrebase" any more
+git-debrebase: WARNING: doing so would drop all upstream patches!
+END
+}
+
sub cmd_downstream_rebase_launder_v0 () {
badusage "needs 1 argument, the baseline" unless @ARGV==1;
my ($base) = @ARGV;