X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=git-debrebase;h=225f0c5bbb212473e5157a0fe028ca2183bfbe23;hb=ca10b89a6d58b656251ecf0f564cd40f720d9239;hp=f16b9b590de949f1e18a45df360886d6d28470b2;hpb=150aff96f5a8740d928e2f677f987bb821b54b4b;p=dgit.git diff --git a/git-debrebase b/git-debrebase index f16b9b59..225f0c5b 100755 --- a/git-debrebase +++ b/git-debrebase @@ -104,14 +104,15 @@ use strict; +use Debian::Dgit qw(:DEFAULT :playground); +setup_sigwarn(); + use Memoize; use Carp; use POSIX; use Data::Dumper; use Getopt::Long qw(:config posix_default gnu_compat bundling); -use Debian::Dgit qw(:DEFAULT :playground); - sub badusage ($) { my ($m) = @_; die "bad usage: $m\n"; @@ -211,7 +212,7 @@ sub get_differs ($$) { } die unless s{^debian/patches/}{}; my $ok; - if ($mode eq 'A' && !m/(?:^|\.)series$/s) { + if ($mode eq 'A' && !m/\.series$/s) { $ok = 1; } elsif ($mode eq 'M' && $_ eq 'series') { my $x_s = git_cat_file "$x:debian/patches/series", 'blob'; @@ -264,6 +265,7 @@ sub calculate_committer_authline () { # # Types: # Packaging +# Changelog # Upstream # AddPatches # Mixed @@ -303,7 +305,7 @@ sub classify ($) { push @p, { Ix => $#p, CommitId => $ph, - Differs => (get_differs $t, $ph), + Differs => (get_differs $ph, $t), }; } @@ -337,7 +339,11 @@ sub classify ($) { } elsif ($d & DS_DEB and !($d & ~DS_DEB)) { my ($ty,$dummy) = git_cat_file "$ph[0]:debian"; if ($ty eq 'tree') { - return $classify->(qw(Packaging)); + if ($d == D_DEB_CLOG) { + return $classify->(qw(Changelog)); + } else { + return $classify->(qw(Packaging)); + } } elsif ($ty eq 'missing') { return $classify->(qw(BreakwaterStart)); } else { @@ -494,7 +500,7 @@ sub walk ($;$$) { $cur = $p0; $rewrite_from_here->(); next; - } elsif ($ty eq 'Packaging') { + } elsif ($ty eq 'Packaging' or $ty eq 'Changelog') { push @brw_cl, $cl; $cur = $p0; next; @@ -685,7 +691,14 @@ sub get_head () { return git_rev_parse qw(HEAD); } sub update_head ($$$) { my ($old, $new, $mrest) = @_; - runcmd @git, qw(update-ref -m), "git-debrebase $mrest", $new, $old; + runcmd @git, qw(update-ref -m), "debrebase: $mrest", 'HEAD', $new, $old; +} + +sub update_head_checkout ($$$) { + my ($old, $new, $mrest) = @_; + my $symref = git_get_symref(); + runcmd @git, qw(checkout), $new, qw(.); + update_head $old, $new, $mrest; } sub cmd_launder () { @@ -711,6 +724,55 @@ sub cmd_analyse () { STDOUT->error and die $!; } +sub cmd_downstream_rebase_launder_v0 () { + badusage "needs 1 argument, the baseline" unless @ARGV==1; + my ($base) = @ARGV; + $base = git_rev_parse $base; + my $old_head = get_head(); + my $current = $old_head; + my $topmost_keep; + for (;;) { + if ($current eq $base) { + $topmost_keep //= $current; + print " $current BASE stop\n"; + last; + } + my $cl = classify $current; + print " $current $cl->{Type}"; + my $keep = 0; + my $p0 = $cl->{Parents}[0]{CommitId}; + my $next; + if ($cl->{Type} eq 'Pseudomerge') { + print " ^".($cl->{Contributor}{Ix}+1); + $next = $cl->{Contributor}{CommitId}; + } elsif ($cl->{Type} eq 'AddPatches' or + $cl->{Type} eq 'Changelog') { + print " strip"; + $next = $p0; + } else { + print " keep"; + $next = $p0; + $keep = 1; + } + print "\n"; + if ($keep) { + $topmost_keep //= $current; + } else { + die "to-be stripped changes not on top of the branch\n" + if $topmost_keep; + } + $current = $next; + } + if ($topmost_keep eq $old_head) { + print "unchanged\n"; + } else { + print "updating to $topmost_keep\n"; + update_head_checkout + $old_head, $topmost_keep, + 'downstream-rebase-launder-v0'; + } +} + GetOptions("D+" => \$debuglevel) or die badusage "bad options\n"; initdebug('git-debrebase '); enabledebug if $debuglevel;