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 $quilt_upstream_commitish;
+our $quilt_upstream_commitish_used;
+our $quilt_upstream_commitish_message;
+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;
our %internal_object_save;
our $we_are_responder;
our $supplementary_message = '';
our $made_split_brain = 0;
-our $do_split_brain = 0;
+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()
#
# no split no q cache no q cache forbidden,
# brain PM on master q fixup on master prevented
-# !$do_split_brain PM on master
+# !do_split_brain() PM on master
#
# split brain no q cache q fixup cached, to dgit view
# PM in dgit view PM in dgit view
$absurdity =~ s{/[^/]+$}{/absurd} or die;
}
-sub debiantag ($$) {
- my ($v,$distro) = @_;
- return debiantag_new($v, $distro);
-}
-
sub madformat ($) { $_[0] eq '3.0 (quilt)' }
sub lbranch () { return "$branchprefix/$csuite"; }
}
}
-sub quiltmode_splitbrain () {
- $quilt_mode =~ m/gbp|dpm|unapplied/;
+sub quiltmode_splitting () {
+ $quilt_mode =~ m/gbp|dpm|unapplied|baredebian/;
}
+sub do_split_brain () { !!($do_split_brain // confess) }
+
sub opts_opt_multi_cmd {
my $extra = shift;
my @cmd;
parseopts_late_defaults();
}
+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_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 ($) {
my ($msg) = @_;
if (!$we_are_responder) {
}
}
-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';
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
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
# deliberately-not-ff, in which case we must fetch everything.
my @specs = deliberately_not_fast_forward ? qw(tags/*) :
- map { "tags/$_" }
- (quiltmode_splitbrain
- ? (map { $_->('*',access_nomdistro) }
- \&debiantag_new, \&debiantag_maintview)
- : debiantags('*',access_nomdistro));
+ map { "tags/$_" } debiantags('*',access_nomdistro);
push @specs, server_branch($csuite);
push @specs, $rewritemap;
push @specs, qw(heads/*) if deliberately_not_fast_forward;
}
close MC or confess "$!";
- $hash = make_commit $mcf;
+ $hash = hash_commit $mcf;
} else {
$hash = $mergeinputs[0]{Commit};
}
$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";
}
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...",
END
close MC or confess "$!";
- return make_commit($pmf);
+ return hash_commit($pmf);
}
sub splitbrain_pseudomerge ($$$$) {
}
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
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;
if (!$we_are_initiator) {
# rpush initiator can't do this because it doesn't have $isuite yet
- my $tag = debiantag($cversion, access_nomdistro);
+ my $tag = debiantag_new($cversion, access_nomdistro);
runcmd @git, qw(check-ref-format), $tag;
}
my ($cversion, $dgithead, $maintviewhead, $tfbase) = @_;
my @tagwants;
push @tagwants, {
- TagFn => \&debiantag,
+ TagFn => \&debiantag_new,
Objid => $dgithead,
TfSuffix => '',
View => 'dgit',
TfSuffix => '-maintview',
View => 'maint',
};
- } elsif ($dodep14tag eq 'no' ? 0
- : $dodep14tag eq 'want' ? 1
- : $dodep14tag eq 'always' ? 1
- : die "$dodep14tag ?") {
+ } elsif ($dodep14tag ne 'no') {
push @tagwants, {
TagFn => \&debiantag_maintview,
Objid => $dgithead,
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
if (madformat_wantfixup($format)) {
# user might have not used dgit build, so maybe do this now:
- if ($do_split_brain) {
+ if (do_split_brain()) {
changedir $playground;
my $cachekey;
($dgithead, $cachekey) =
perhaps HEAD changed since dgit build[-source] ?",
$quilt_mode;
}
- if (!$do_split_brain) {
+ if (!do_split_brain()) {
# In split brain mode, do not attempt to incorporate dirty
# stuff from the user's working tree. That would be mad.
commit_quilty_patch();
}
}
- if ($do_split_brain) {
+ if (do_split_brain()) {
$made_split_brain = 1;
$dgithead = splitbrain_pseudomerge($clogp,
$actualhead, $dgithead,
}
}
- confess unless !!$made_split_brain == !!$do_split_brain;
+ confess unless !!$made_split_brain == do_split_brain();
changedir $playground;
progress f_ "checking that %s corresponds to HEAD", $dscfn;
sub cmd_pull {
parseopts();
fetchpullargs();
- if (quiltmode_splitbrain()) {
+ determine_whether_split_brain();
+ 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();
return $r;
}
-sub quiltify_splitbrain ($$$$$$$) {
+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;
local $ENV{GIT_AUTHOR_EMAIL} = $authline[1];
local $ENV{GIT_AUTHOR_DATE} = $authline[2];
- confess unless $do_split_brain;
+ confess unless do_split_brain();
my $fulldiffhint = sub {
my ($x,$y) = @_;
$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?";
}
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 $version = getfield $clogp, 'Version';
+ my $upsversion = upstreamversion $version;
+ my $merge = make_commit
+ [ $headref, $quilt_upstream_commitish ],
+ [ +(f_ <<ENDT, $upsversion), $quilt_upstream_commitish_message, <<ENDU ];
+Combine debian/ with upstream source for %s
+ENDT
+[dgit ($our_version) baredebian-merge $version $quilt_upstream_commitish_used]
+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);
my $splitbrain_cachekey;
- if ($do_split_brain) {
+ if (do_split_brain()) {
my $cachehit;
($cachehit, $splitbrain_cachekey) =
quilt_check_splitbrain_cache($headref, $upstreamversion);
}
unpack_playtree_need_cd_work($headref);
- if ($do_split_brain) {
+ if (do_split_brain()) {
runcmd @git, qw(checkout -q -b dgit-view);
# so long as work is not deleted, its current branch will
# remain dgit-view, rather than master, so subsequent calls to
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,
$splitbrain_cachekey);
}
- if ($do_split_brain) {
+ if (do_split_brain()) {
my $dgitview = git_rev_parse 'HEAD';
changedir $maindir;
push @cachekey, $upstreamversion;
push @cachekey, $quilt_mode;
push @cachekey, $headref;
+ push @cachekey, $quilt_upstream_commitish // '-';
push @cachekey, hashfile('fake.dsc');
# 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;
+ # TRANSLATORS: this translation must fit in the ASCII art
+ # quilt differences display. The untranslated display
+ # says %9.9s, so with that display it must be at most 9
+ # characters.
+ $uhead_whatshort = __ 'upstream';
+ }
+
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),
};
progress f_
"%s: base trees orig=%.20s o+d/p=%.20s",
$us, $unapplied, $oldtiptree;
+ # TRANSLATORS: Try to keep this ascii-art layout right. The 0s in
+ # %9.00009s will be ignored and are there to make the format the
+ # same length (9 characters) as the output it generates. If you
+ # change the value 9, your translation of "upstream" must fit into
+ # the new length, and you should change the number of 0s. Do
+ # not reduce it below 4 as HEAD has to fit too.
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) {
+ 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;
}
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})) {
if stat_exists '.gitattributes';
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);
+ "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,
+ $diffbits, \%editedignores,
+ $splitbrain_cachekey);
return;
}
progress f_ "starting quiltify (multiple patches, %s mode)", $quilt_mode;
quiltify($clogp,$headref,$oldtiptree,\@failsuggestion);
- runcmd @git, qw(checkout -q), (qw(master dgit-view)[!!$do_split_brain]);
+ runcmd @git, qw(checkout -q), (qw(master dgit-view)[do_split_brain()]);
if (!open P, '>>', ".pc/applied-patches") {
$!==&ENOENT or confess "$!";
}
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.
sub clean_tree () {
# We always clean the tree ourselves, rather than leave it to the
# builder (dpkg-source, or soemthing which calls dpkg-source).
+ if ($quilt_mode =~ m/baredebian/ and $cleanmode =~ m/git/) {
+ fail f_ <<END, $quilt_mode, $cleanmode;
+quilt mode %s (generally needs untracked upstream files)
+contradicts clean mode %s (which would delete them)
+END
+ # This is not 100% true: dgit build-source and push-source
+ # (for example) could operate just fine with no upstream
+ # source in the working tree. But it doesn't seem likely that
+ # the user wants dgit to proactively delete such things.
+ # -wn, for example, would produce identical output without
+ # deleting anything from the working tree.
+ }
if ($cleanmode =~ m{^dpkg-source}) {
my @cmd = @dpkgbuildpackage;
push @cmd, qw(-d) if $cleanmode =~ m{^dpkg-source-d};
}
sub build_or_push_prep_modes () {
- my ($format,) = get_source_format();
- printdebug "format $format, quilt mode $quilt_mode\n";
- if (madformat_wantfixup($format) && quiltmode_splitbrain()) {
- $do_split_brain = 1;
+ my ($format,) = determine_whether_split_brain();
+
+ fail __ "dgit: --include-dirty is not supported with split view".
+ " (including with view-splitting quilt modes)"
+ if do_split_brain() && $includedirty;
+
+ if (madformat_wantfixup $format and $quilt_mode =~ m/baredebian$/) {
+ ($quilt_upstream_commitish, $quilt_upstream_commitish_used,
+ $quilt_upstream_commitish_message)
+ = resolve_upstream_version
+ $quilt_upstream_commitish, upstreamversion $version;
+ progress f_ "dgit: --quilt=%s, %s", $quilt_mode,
+ $quilt_upstream_commitish_message;
+ } elsif (defined $quilt_upstream_commitish) {
+ fail __
+ "dgit: --upstream-commitish only makes sense with --quilt=baredebian"
}
- fail __ "dgit: --include-dirty is not supported in split view quilt mode"
- if $do_split_brain && $includedirty;
}
sub build_prep_early () {
unlink "$buildproductsdir/$sourcechanges" or $!==ENOENT
or fail f_ "remove %s: %s", $sourcechanges, $!;
}
-# confess unless !!$made_split_brain == !!$do_split_brain;
+# confess unless !!$made_split_brain == do_split_brain();
my @cmd = (@dpkgsource, qw(-b --));
my $leafdir;
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
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) {
} 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;
} elsif (m/^--delayed=(\d+)$/s) {
push @ropts, $_;
push @dput, $_;
+ } elsif (m/^--upstream-commitish=(.+)$/s) {
+ push @ropts, $_;
+ $quilt_upstream_commitish = $1;
} elsif (m/^--save-(dgit-view)=(.+)$/s ||
m/^--(dgit-view)-save=(.+)$/s
) {