chiark / gitweb /
Pseudomerge: pseudomerge_make_commit: Lift up some message generation
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 5dfd97c7fdc45d3a0f4b9f2f53d67669845d8681..0dea96c8f1a678ad9c6d223197caa66e57cb2c0c 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -537,11 +537,13 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               # old means "repo server accepts pushes with old dgit tags"
               # new means "repo server accepts pushes with new dgit tags"
               # maint means "repo server accepts split brain pushes"
+              # hist means "repo server may have old pushes without new tag"
+              #   ("hist" is implied by "old")
               'dgit-distro.debian.archive-query' => 'ftpmasterapi:',
               'dgit-distro.debian.git-check' => 'url',
               'dgit-distro.debian.git-check-suffix' => '/info/refs',
               'dgit-distro.debian.new-private-pushers' => 't',
-              'dgit-distro.debian.dgit-tag-format' => 'old',
+              'dgit-distro.debian.dgit-tag-format' => 'new',
               'dgit-distro.debian/push.git-url' => '',
               'dgit-distro.debian/push.git-host' => 'push.dgit.debian.org',
               'dgit-distro.debian/push.git-user-force' => 'dgit',
@@ -2395,6 +2397,53 @@ $anc->[1] ($anc->[0]) .. $desc->[1] ($desc->[0]) is not fast forward
 END
 };
 
+sub pseudomerge_version_check ($$) {
+    my ($clogp, $archive_hash) = @_;
+
+    my $arch_clogp = commit_getclogp $archive_hash;
+    my $i_arch_v = [ (getfield $arch_clogp, 'Version'),
+                    'version currently in archive' ];
+    if (defined $overwrite_version) {
+       infopair_cond_equal([ $overwrite_version, '--overwrite= version' ],
+                           $i_arch_v);
+    }
+    
+    printdebug "pseudomerge_version_check i_arch_v @$i_arch_v\n";
+    return $i_arch_v;
+}
+
+sub pseudomerge_make_commit ($$$$ $$) {
+    my ($clogp, $dgitview, $archive_hash, $i_arch_v,
+       $msg_cmd, $msg_msg) = @_;
+    progress "Declaring that HEAD inciudes all changes in $i_arch_v->[0]...";
+
+    my $tree = cmdoutput qw(git rev-parse), "${dgitview}:";
+    my $authline = clogp_authline $clogp;
+
+    chomp $msg_msg;
+    $msg_cmd .=
+       !defined $overwrite_version ? ""
+       : " --overwrite=".$overwrite_version;
+
+    mkpath '.git/dgit';
+    my $pmf = ".git/dgit/pseudomerge";
+    open MC, ">", $pmf or die "$pmf $!";
+    print MC <<END or die $!;
+tree $tree
+parent $dgitview
+parent $archive_hash
+author $authline
+commiter $authline
+
+$msg_msg
+
+[$msg_cmd]
+END
+    close MC or die $!;
+
+    return make_commit($pmf);
+}
+
 sub splitbrain_pseudomerge ($$$$) {
     my ($clogp, $maintview, $dgitview, $archive_hash) = @_;
     # => $merged_dgitview
@@ -2411,20 +2460,13 @@ sub splitbrain_pseudomerge ($$$$) {
     #   this:                                   $dgitview'
     #
 
-    my $arch_clogp = commit_getclogp $archive_hash;
-    my $i_arch_v = [ (getfield $arch_clogp, 'Version'),
-                    'version currently in archive' ];
-    
-    printdebug "splitbrain_pseudomerge i_arch_v @$i_arch_v\n";
+    printdebug "splitbrain_pseudomerge...\n";
+
+    my $i_arch_v = pseudomerge_version_check($clogp, $archive_hash);
 
     return $dgitview unless defined $archive_hash;
 
-    if (defined $overwrite_version) {
-       progress "Declaring that HEAD inciudes all changes in archive...";
-       progress "Checking that $overwrite_version does so...";
-       infopair_cond_equal([ $overwrite_version, '--overwrite= version' ],
-                           $i_arch_v);
-    } else {
+    if (!defined $overwrite_version) {
        progress "Checking that HEAD inciudes all changes in archive...";
     }
 
@@ -2442,38 +2484,49 @@ sub splitbrain_pseudomerge ($$$$) {
     infopair_cond_ff($i_dep14, $i_dgit);
     $overwrite_version // infopair_cond_ff($i_dep14, [ $maintview, 'HEAD' ]);
 
-    my $tree = cmdoutput qw(git rev-parse), "${dgitview}:";
-    my $authline = clogp_authline $clogp;
+    my $r = pseudomerge_make_commit
+       $clogp, $dgitview, $archive_hash, $i_arch_v,
+       "dgit --quilt=$quilt_mode",
+       (defined $overwrite_version ? <<END_OVERWR : <<END_MAKEFF);
+Declare fast forward from $overwrite_version
+END_OVERWR
+Make fast forward from $i_arch_v->[0]
+END_MAKEFF
 
-    mkpath '.git/dgit';
-    my $pmf = ".git/dgit/pseudomerge";
-    open MC, ">", $pmf or die "$pmf $!";
-    print MC <<END or die $!;
-tree $tree
-parent $dgitview
-parent $archive_hash
-author $authline
-commiter $authline
+    progress "Made pseudo-merge of $i_arch_v->[0] into dgit view.";
+    return $r;
+}      
 
-END
-    if (defined $overwrite_version) {
-       print MC <<END;
-Declare fast forward from $overwrite_version
+sub plain_overwrite_pseudomerge ($$$) {
+    my ($clogp, $head, $archive_hash) = @_;
 
-[dgit --quilt=$quilt_mode --overwrite-version=$overwrite_version]
-END
-    } else {
-       print MC <<END;
-Make fast forward from $i_arch_v->[0]
+    printdebug "plain_overwrite_pseudomerge...";
 
-[dgit --quilt=$quilt_mode]
-END
-    }
-    close MC or die $!;
+    my $i_arch_v = pseudomerge_version_check($clogp, $archive_hash);
 
-    progress "Making pseudo-merge of $i_arch_v->[0] into dgit view.";
-    return make_commit($pmf);
-}      
+    my @tagformats = access_cfg_tagformats();
+    my @t_overwr =
+       map { $_->($overwrite_version, access_basedistro) }
+       (grep { m/^(?:old|hist)$/ } @tagformats)
+       ? \&debiantags : \&debiantag_new;
+    my $i_overwr = infopair_lrf_tag_lookup \@t_overwr, "previous version tag";
+    my $i_archive = [ $archive_hash, "current archive contents" ];
+
+    infopair_cond_equal($i_overwr, $i_archive);
+
+    return $head if is_fast_fwd $archive_hash, $head;
+
+    my $m = "Declare fast forward from $overwrite_version";
+
+    my $r = pseudomerge_make_commit
+       $clogp, $head, $archive_hash, $i_arch_v,
+       "dgit", $m;
+
+    runcmd @git, qw(update-ref -m), $m, 'HEAD', $r, $head;
+
+    progress "Make pseudo-merge of $i_arch_v->[0] into your HEAD.";
+    return $r;
+}
 
 sub push_parse_changelog ($) {
     my ($clogpfn) = @_;
@@ -2702,6 +2755,12 @@ END
        }
     }
 
+    if (defined $overwrite_version && !defined $maintviewhead) {
+       $dgithead = plain_overwrite_pseudomerge($clogp,
+                                               $dgithead,
+                                               $archive_hash);
+    }
+
     check_not_dirty();
 
     my $forceflag = '';
@@ -2713,10 +2772,10 @@ END
        } else {
            fail "dgit push: HEAD is not a descendant".
                " of the archive's version.\n".
-               "dgit: To overwrite its contents,".
-               " use git merge -s ours ".lrref().".\n".
-               "dgit: To rewind history, if permitted by the archive,".
-               " use --deliberately-not-fast-forward";
+               "To overwrite the archive's contents,".
+               " pass --overwrite[=VERSION].\n".
+               "To rewind history, if permitted by the archive,".
+               " use --deliberately-not-fast-forward.";
        }
     }
 
@@ -4505,6 +4564,9 @@ sub parseopts () {
            } elsif (m/^--no-rm-on-error$/s) {
                push @ropts, $_;
                $rmonerror = 0;
+           } elsif (m/^--overwrite=(.*)$/s) {
+               push @ropts, $_;
+               $overwrite_version = $1;
            } elsif (m/^--(no-)?rm-old-changes$/s) {
                push @ropts, $_;
                $rmchanges = !$1;