+sub check_series_has_all_patches ($) {
+ my ($head) = @_;
+ my $seriesfn = 'debian/patches/series';
+ my ($dummy, $series) = git_cat_file "$head:$seriesfn",
+ [qw(blob missing)];
+ $series //= '';
+ my %series;
+ our $comments_snagged;
+ foreach my $f (grep /\S/, grep {!m/^\s\#/} split /\n/, $series) {
+ if ($f =~ m/^\s*\#/) {
+ snag 'series-comments',
+ "$seriesfn contains comments, which will be discarded"
+ unless $comments_snagged++;
+ next;
+ }
+ fail "patch $f repeated in $seriesfn !" if $series{$f}++;
+ }
+ foreach my $patchfile (get_tree "$head:debian/patches", 1,1) {
+ my ($f,$i) = @$patchfile;
+ next if $series{$f};
+ next if $f eq 'series';
+ snag 'unused-patches', "Unused patch file $f will be discarded";
+ }
+}
+
+sub begin_convert_from () {
+ my $head = get_head();
+ my ($ffqs, $ffqm, $symref, $ffq_prev, $gdrlast) = ffq_prev_branchinfo();
+
+ fail "ffq-prev exists, this is already managed by git-debrebase!"
+ if $ffq_prev && git_get_ref $ffq_prev;
+
+ my $gdrlast_obj = $gdrlast && git_get_ref $gdrlast;
+ snag 'already-converted',
+ "ahead of debrebase-last, this is already managed by git-debrebase!"
+ if $gdrlast_obj && is_fast_fwd $gdrlast_obj, $head;
+ return ($head, { LastRef => $gdrlast, LastObj => $gdrlast_obj });
+}
+
+sub complete_convert_from ($$$$) {
+ my ($old_head, $new_head, $gi, $mrest) = @_;
+ ffq_check $new_head;
+ record_gdrlast $gi->{LastRef}, $new_head, $gi->{LastObj}
+ if $gi->{LastRef};
+ snags_maybe_bail();
+ update_head_checkout $old_head, $new_head, $mrest;
+}
+