chiark / gitweb /
dgit: Introduce $uhead and $uhead_whatshort
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 36e0a2b6afba0e14da5a9a7574c00424b7ccc71a..a168384441455ecbd73c246abea5773da7165529 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -80,6 +80,8 @@ our $rmchanges;
 our $overwrite_version; # undef: not specified; '': check changelog
 our $quilt_mode;
 our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|dpm|unapplied';
+our $splitview_mode;
+our $splitview_modes_re = qr{auto|always|never};
 our $dodep14tag;
 our %internal_object_save;
 our $we_are_responder;
@@ -177,7 +179,7 @@ our $do_split_brain;
 
 # Interactions between quilt mode and split brain
 # (currently, split brain only implemented iff
-#  madformat_wantfixup && quiltmode_splitbrain)
+#  madformat_wantfixup && quiltmode_splitting)
 #
 #   source format        sane           `3.0 (quilt)'
 #                                       madformat_wantfixup()
@@ -291,7 +293,7 @@ sub deliberately_not_fast_forward () {
     }
 }
 
-sub quiltmode_splitbrain () {
+sub quiltmode_splitting () {
     $quilt_mode =~ m/gbp|dpm|unapplied/;
 }
 
@@ -969,11 +971,26 @@ sub notpushing () {
 
 sub determine_whether_split_brain () {
     my ($format,) = get_source_format();
+
+    {
+       local $access_forpush;
+       default_from_access_cfg(\$splitview_mode, 'split-view', 'auto',
+                               $splitview_modes_re);
+       $do_split_brain = 1 if $splitview_mode eq 'always';
+    }
+
     printdebug "format $format, quilt mode $quilt_mode\n";
-    if (madformat_wantfixup($format) && quiltmode_splitbrain()) {
+
+    if (madformat_wantfixup($format) && quiltmode_splitting()) {
+       $splitview_mode ne 'never' or
+           fail f_ "dgit: quilt mode \`%s' (for format \`%s')".
+                   " implies split view, but split-view set to \`%s'",
+                   $quilt_mode, $format, $splitview_mode;
        $do_split_brain = 1;
     }
     $do_split_brain //= 0;
+
+    return ($format);
 }
 
 sub supplementary_message ($) {
@@ -2097,11 +2114,6 @@ END
     }
 }
 
-sub make_commit ($) {
-    my ($file) = @_;
-    return cmdoutput @git, qw(hash-object -w -t commit), $file;
-}
-
 sub clogp_authline ($) {
     my ($clogp) = @_;
     my $author = getfield $clogp, 'Maintainer';
@@ -2513,7 +2525,7 @@ sub generate_commits_from_dsc () {
            printdebug "import tartree $tt->{F} $tt->{Tree}\n";
 
            my $mbody = f_ "Import %s", $tt->{F};
-           $tt->{Commit} = make_commit_text($tt->{Orig} ? <<END_O : <<END_T);
+           $tt->{Commit} = hash_commit_text($tt->{Orig} ? <<END_O : <<END_T);
 tree $tt->{Tree}
 author $r1authline
 committer $r1authline
@@ -2552,14 +2564,14 @@ $changes
 END
 
     close C or confess "$!";
-    my $rawimport_hash = make_commit qw(../commit.tmp);
+    my $rawimport_hash = hash_commit qw(../commit.tmp);
 
     if (madformat $dsc->{format}) {
        printdebug "import apply patches...\n";
 
        # regularise the state of the working tree so that
        # the checkout of $rawimport_hash works nicely.
-       my $dappliedcommit = make_commit_text(<<END);
+       my $dappliedcommit = hash_commit_text(<<END);
 tree $dappliedtree
 author $authline
 committer $authline
@@ -3409,7 +3421,7 @@ END
        }
 
        close MC or confess "$!";
-       $hash = make_commit $mcf;
+       $hash = hash_commit $mcf;
     } else {
        $hash = $mergeinputs[0]{Commit};
     }
@@ -3770,7 +3782,7 @@ sub fork_for_multisuite ($) {
        $commit .=
            "author $authline\n".
            "committer $authline\n\n";
-       $output = make_commit_text $commit.$msg;
+       $output = hash_commit_text $commit.$msg;
        printdebug "multisuite merge generated $output\n";
     }
 
@@ -4097,7 +4109,7 @@ END
     return $i_arch_v;
 }
 
-sub pseudomerge_make_commit ($$$$ $$) {
+sub pseudomerge_hash_commit ($$$$ $$) {
     my ($clogp, $dgitview, $archive_hash, $i_arch_v,
        $msg_cmd, $msg_msg) = @_;
     progress f_ "Declaring that HEAD includes all changes in %s...",
@@ -4129,7 +4141,7 @@ $msg_msg
 END
     close MC or confess "$!";
 
-    return make_commit($pmf);
+    return hash_commit($pmf);
 }
 
 sub splitbrain_pseudomerge ($$$$) {
@@ -4187,7 +4199,7 @@ ENDT
     }
 
     my $arch_v = $i_arch_v->[0];
-    my $r = pseudomerge_make_commit
+    my $r = pseudomerge_hash_commit
        $clogp, $dgitview, $archive_hash, $i_arch_v,
        "dgit --quilt=$quilt_mode",
        (defined $overwrite_version
@@ -4211,7 +4223,7 @@ sub plain_overwrite_pseudomerge ($$$) {
 
     my $m = f_ "Declare fast forward from %s", $i_arch_v->[0];
 
-    my $r = pseudomerge_make_commit
+    my $r = pseudomerge_hash_commit
        $clogp, $head, $archive_hash, $i_arch_v,
        "dgit", $m;
 
@@ -4444,7 +4456,7 @@ END
     my $actualhead = git_rev_parse('HEAD');
 
     if (branch_is_gdr_unstitched_ff($symref, $actualhead, $archive_hash)) {
-       if (quiltmode_splitbrain()) {
+       if (quiltmode_splitting()) {
            my ($ffq_prev, $gdrlast) = branch_gdr_info($symref, $actualhead);
            fail f_ <<END, $ffq_prev, $quilt_mode;
 Branch is managed by git-debrebase (%s
@@ -4839,7 +4851,7 @@ sub cmd_pull {
     if (do_split_brain()) {
        my ($format, $fopts) = get_source_format();
        madformat($format) and fail f_ <<END, $quilt_mode
-dgit pull not yet supported in split view mode (--quilt=%s)
+dgit pull not yet supported in split view mode (including with view-splitting quilt modes)
 END
     }
     pull();
@@ -5342,7 +5354,7 @@ sub quiltify_tree_sentinelfiles ($) {
     return $r;
 }
 
-sub quiltify_splitbrain ($$$$$$$) {
+sub quiltify_splitting ($$$$$$$) {
     my ($clogp, $unapplied, $headref, $oldtiptree, $diffbits,
        $editedignores, $cachekey) = @_;
     my $gitignore_special = 1;
@@ -5773,7 +5785,7 @@ sub build_maybe_quilt_fixup () {
        fail f_
  "quilt mode %s does not make sense (or is not supported) with single-debian-patch",
            $quilt_mode
-           if quiltmode_splitbrain();
+           if quiltmode_splitting();
        quilt_fixup_singlepatch($clogp, $headref, $upstreamversion);
     } else {
        quilt_fixup_multipatch($clogp, $headref, $upstreamversion,
@@ -6155,15 +6167,18 @@ END
     # We calculate some guesswork now about what kind of tree this might
     # be.  This is mostly for error reporting.
 
+    my $uheadref = $headref;
+    my $uhead_whatshort = 'HEAD';
+
     my %editedignores;
     my @unrepres;
     my $diffbits = {
         # H = user's HEAD
         # O = orig, without patches applied
         # A = "applied", ie orig with H's debian/patches applied
-        O2H => quiltify_trees_differ($unapplied,$headref,   1,
+        O2H => quiltify_trees_differ($unapplied,$uheadref,   1,
                                     \%editedignores, \@unrepres),
-        H2A => quiltify_trees_differ($headref,  $oldtiptree,1),
+        H2A => quiltify_trees_differ($uheadref, $oldtiptree,1),
         O2A => quiltify_trees_differ($unapplied,$oldtiptree,1),
     };
 
@@ -6180,9 +6195,9 @@ END
               $us, $unapplied, $oldtiptree;
     progress f_
 "%s: quilt differences: src:  %s orig %s     gitignores:  %s orig %s\n".
-"%s: quilt differences:      HEAD %s o+d/p               HEAD %s o+d/p",
+"%s: quilt differences: %9.00009s %s o+d/p          %9.00009s %s o+d/p",
   $us,                      $dl[0], $dl[1],              $dl[3], $dl[4],
-  $us,                          $dl[2],                     $dl[5];
+  $us,        $uhead_whatshort, $dl[2],   $uhead_whatshort, $dl[5];
 
     if (@unrepres) {
        print STDERR f_ "dgit:  cannot represent change: %s: %s\n",
@@ -6211,10 +6226,10 @@ END
     push @failsuggestion, [ 'origs', __
  "Maybe orig tarball(s) are not identical to git representation?" ];
 
-    if (quiltmode_splitbrain()) {
-       quiltify_splitbrain($clogp, $unapplied, $headref, $oldtiptree,
-                            $diffbits, \%editedignores,
-                           $splitbrain_cachekey);
+    if (quiltmode_splitting()) {
+       quiltify_splitting($clogp, $unapplied, $headref, $oldtiptree,
+                          $diffbits, \%editedignores,
+                          $splitbrain_cachekey);
        return;
     }
 
@@ -6371,9 +6386,10 @@ sub build_or_push_prep_early () {
 }
 
 sub build_or_push_prep_modes () {
-    determine_whether_split_brain();
+    my ($format,) = determine_whether_split_brain();
 
-    fail __ "dgit: --include-dirty is not supported in split view quilt mode"
+    fail __ "dgit: --include-dirty is not supported with split view".
+            " (including with view-splitting quilt modes)"
        if do_split_brain() && $includedirty;
 }
 
@@ -7074,7 +7090,7 @@ END
            my $version = getfield $dsc, 'Version';
            my $clogp = commit_getclogp $newhash;
            my $authline = clogp_authline $clogp;
-           $newhash = make_commit_text <<ENDU
+           $newhash = hash_commit_text <<ENDU
 tree $tree
 parent $newhash
 parent $oldhash
@@ -7324,6 +7340,12 @@ sub parseopts () {
            } elsif (m/^--overwrite$/s) {
                push @ropts, $_;
                $overwrite_version = '';
+           } elsif (m/^--split-(?:view|brain)$/s) {
+               push @ropts, $_;
+               $splitview_mode = 'always';
+           } elsif (m/^--split-(?:view|brain)=($splitview_modes_re)$/s) {
+               push @ropts, $_;
+               $splitview_mode = $1;
            } elsif (m/^--overwrite=(.+)$/s) {
                push @ropts, $_;
                $overwrite_version = $1;