chiark / gitweb /
dgit: baredebian: New quilt mode
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Jun 2019 11:53:56 +0000 (12:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Jun 2019 11:59:37 +0000 (12:59 +0100)
This is the bulk of the implementation including all essential
changes.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index fb64dc2da8fc967051ce948eb6e8bd44d4c8dcf1..02cf97d846cd695f158245e6b3a4057dd4ab7958 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -80,7 +80,7 @@ our $rmchanges;
 our $overwrite_version; # undef: not specified; '': check changelog
 our $quilt_mode;
 our $quilt_upstream_commitish;
-our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|dpm|unapplied';
+our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|dpm|unapplied|baredebian';
 our $splitview_mode;
 our $splitview_modes_re = qr{auto|always|never};
 our $dodep14tag;
@@ -295,7 +295,7 @@ sub deliberately_not_fast_forward () {
 }
 
 sub quiltmode_splitting () {
-    $quilt_mode =~ m/gbp|dpm|unapplied/;
+    $quilt_mode =~ m/gbp|dpm|unapplied|baredebian/;
 }
 
 sub do_split_brain () { !!($do_split_brain // confess) }
@@ -5359,7 +5359,7 @@ sub quiltify_splitting ($$$$$$$) {
     my ($clogp, $unapplied, $headref, $oldtiptree, $diffbits,
        $editedignores, $cachekey) = @_;
     my $gitignore_special = 1;
-    if ($quilt_mode !~ m/gbp|dpm/) {
+    if ($quilt_mode !~ m/gbp|dpm|baredebian/) {
        # treat .gitignore just like any other upstream file
        $diffbits = { %$diffbits };
        $_ = !!$_ foreach values %$diffbits;
@@ -5384,14 +5384,14 @@ sub quiltify_splitting ($$$$$$$) {
                  $cmd;
     };
 
-    if ($quilt_mode =~ m/gbp|unapplied/ &&
+    if ($quilt_mode =~ m/gbp|unapplied|baredebian/ &&
        ($diffbits->{O2H} & 01)) {
        my $msg = f_
  "--quilt=%s specified, implying patches-unapplied git tree\n".
  " but git tree differs from orig in upstream files.",
                      $quilt_mode;
        $msg .= $fulldiffhint->($unapplied, 'HEAD');
-       if (!stat_exists "debian/patches") {
+       if (!stat_exists "debian/patches" and $quilt_mode !~ m/baredebian/) {
            $msg .= __
  "\n ... debian/patches is missing; perhaps this is a patch queue branch?";
        }  
@@ -5404,7 +5404,22 @@ sub quiltify_splitting ($$$$$$$) {
  but git tree differs from result of applying debian/patches to upstream
 END
     }
-    if ($quilt_mode =~ m/gbp|unapplied/ &&
+    if ($quilt_mode =~ m/baredebian/) {
+       # We need to construct a merge which has upstream files from
+       # upstream and debian/ files from HEAD.
+
+       read_tree_upstream $quilt_upstream_commitish, 1, $headref;
+       my $upsversion = upstreamversion getfield $clogp, 'Version';
+       my $merge = make_commit
+           [ $headref, $quilt_upstream_commitish ],
+           [ +(f_ <<ENDT, $upsversion), <<ENDU ];
+Combine debian/ with upstream source for %s
+ENDT
+[dgit ($our_version) baredebian-merge]
+ENDU
+       runcmd @git, qw(reset -q --hard), $merge;
+    }
+    if ($quilt_mode =~ m/gbp|unapplied|baredebian/ &&
        ($diffbits->{O2A} & 01)) { # some patches
        progress __ "dgit view: creating patches-applied version using gbp pq";
        runcmd shell_cmd 'exec >/dev/null', gbp_pq, qw(import);
@@ -6169,9 +6184,17 @@ END
     # We calculate some guesswork now about what kind of tree this might
     # be.  This is mostly for error reporting.
 
+    my $tentries = cmdoutput @git, qw(ls-tree --name-only -z), $headref;
+    my $onlydebian = $tentries eq "debian\0";
+
     my $uheadref = $headref;
     my $uhead_whatshort = 'HEAD';
 
+    if ($quilt_mode =~ m/baredebian/) {
+       $uheadref = $quilt_upstream_commitish;
+       $uhead_whatshort = __ 'upstream';
+    }
+
     my %editedignores;
     my @unrepres;
     my $diffbits = {
@@ -6201,7 +6224,10 @@ END
   $us,                      $dl[0], $dl[1],              $dl[3], $dl[4],
   $us,        $uhead_whatshort, $dl[2],   $uhead_whatshort, $dl[5];
 
-    if (@unrepres) {
+    if (@unrepres && $quilt_mode !~ m/baredebian/) {
+       # With baredebian, even if the upstream commitish has this
+       # problem, we don't want to print this message, as nothing
+       # is going to try to make a patch out of it anyway.
        print STDERR f_ "dgit:  cannot represent change: %s: %s\n",
                        $_->[1], $_->[0]
            foreach @unrepres;
@@ -6211,7 +6237,11 @@ END
     }
 
     my @failsuggestion;
-    if (!($diffbits->{O2H} & $diffbits->{O2A})) {
+    if ($onlydebian) {
+       push @failsuggestion, [ 'onlydebian', __
+ "This has only a debian/ directory; you probably want --quilt=bare debian." ]
+           unless $quilt_mode =~ m/baredebian/;
+    } elsif (!($diffbits->{O2H} & $diffbits->{O2A})) {
         push @failsuggestion, [ 'unapplied', __
  "This might be a patches-unapplied branch." ];
     } elsif (!($diffbits->{H2A} & $diffbits->{O2A})) {
@@ -6226,7 +6256,9 @@ END
        if stat_exists '.gitattributes';
 
     push @failsuggestion, [ 'origs', __
- "Maybe orig tarball(s) are not identical to git representation?" ];
+ "Maybe orig tarball(s) are not identical to git representation?" ]
+       unless $onlydebian && $quilt_mode !~ m/baredebian/;
+              # ^ in that case, we didn't really look properly
 
     if (quiltmode_splitting()) {
        quiltify_splitting($clogp, $unapplied, $headref, $oldtiptree,
@@ -6272,7 +6304,7 @@ sub quilt_fixup_editor () {
 }
 
 sub maybe_apply_patches_dirtily () {
-    return unless $quilt_mode =~ m/gbp|unapplied/;
+    return unless $quilt_mode =~ m/gbp|unapplied|baredebian/;
     print STDERR __ <<END or confess "$!";
 
 dgit: Building, or cleaning with rules target, in patches-unapplied tree.
@@ -7335,7 +7367,7 @@ sub parseopts () {
                push @ropts, $_;
                my $cmd = shift @$om;
                @$om = ($cmd, grep { $_ ne $2 } @$om);
-           } elsif (m/^--(gbp|dpm)$/s) {
+           } elsif (m/^--(gbp|dpm|baredebian)$/s) {
                push @ropts, "--quilt=$1";
                $quilt_mode = $1;
            } elsif (m/^--(?:ignore|include)-dirty$/s) {