our @deliberatelies;
our %previously;
our $existing_package = 'dpkg';
-our $cleanmode = 'dpkg-source';
+our $cleanmode;
our $changes_since_version;
our $quilt_mode;
our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck';
our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
our $suite_re = '[-+.0-9a-z]+';
+our $cleanmode_re = 'dpkg-source(?:-d)?|git|git-ff|check|none';
our (@git) = qw(git);
our (@dget) = qw(dget);
main usages:
dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
- dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
+ dgit [dgit-opts] build [dpkg-buildpackage-opts]
+ dgit [dgit-opts] sbuild [sbuild-opts]
dgit [dgit-opts] push [dgit-opts] [suite]
dgit [dgit-opts] rpush build-host:build-dir ...
important dgit options:
#----- other building -----
+our $suppress_clean;
+
sub clean_tree () {
+ return if $suppress_clean;
if ($cleanmode eq 'dpkg-source') {
runcmd_ordryrun_local @dpkgbuildpackage, qw(-T clean);
} elsif ($cleanmode eq 'dpkg-source-d') {
build_maybe_quilt_fixup();
}
-sub changesopts () {
+sub changesopts_initial () {
my @opts =@changesopts[1..$#changesopts];
+}
+
+sub changesopts_version () {
if (!defined $changes_since_version) {
my @vsns = archive_query('archive_query');
my @quirk = access_quirk();
}
}
if ($changes_since_version ne '_') {
- unshift @opts, "-v$changes_since_version";
+ return ("-v$changes_since_version");
+ } else {
+ return ();
}
- return @opts;
}
-sub massage_dbp_args ($) {
- my ($cmd) = @_;
- return unless $cleanmode =~ m/git|none/;
+sub changesopts () {
+ return (changesopts_initial(), changesopts_version());
+}
+
+sub massage_dbp_args ($;$) {
+ my ($cmd,$xargs) = @_;
+ if ($cleanmode eq 'dpkg-source') {
+ $suppress_clean = 1;
+ return;
+ }
debugcmd '#massaging#', @$cmd if $debuglevel>1;
my @newcmd = shift @$cmd;
# -nc has the side effect of specifying -b if nothing else specified
push @newcmd, '-nc';
# and some combinations of -S, -b, et al, are errors, rather than
# later simply overriding earlier
- push @newcmd, '-F' unless grep { m/^-[bBASF]$/ } @$cmd;
+ push @newcmd, '-F' unless grep { m/^-[bBASF]$/ } (@$cmd, @$xargs);
push @newcmd, @$cmd;
@$cmd = @newcmd;
}
sub cmd_build {
- build_prep();
- my @dbp = (@dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV);
+ my @dbp = (@dpkgbuildpackage, qw(-us -uc), changesopts_initial(), @ARGV);
massage_dbp_args \@dbp;
+ build_prep();
+ push @dbp, changesopts_version();
runcmd_ordryrun_local @dbp;
printdone "build successful\n";
}
-sub cmd_git_build {
- build_prep();
+sub cmd_gbp_build {
my @dbp = @dpkgbuildpackage;
- massage_dbp_args \@dbp;
- my @cmd =
- (qw(git-buildpackage -us -uc --git-no-sign-tags),
- "--git-builder=@dbp");
+ massage_dbp_args \@dbp, \@ARGV;
+
+ my @cmd;
+ if (length executable_on_path('git-buildpackage')) {
+ @cmd = qw(git-buildpackage);
+ } else {
+ @cmd = qw(gbp buildpackage);
+ }
+ push @cmd, (qw(-us -uc --git-no-sign-tags), "--git-builder=@dbp");
+
+ if ($cleanmode eq 'dpkg-source') {
+ $suppress_clean = 1;
+ } else {
+ push @cmd, '--git-cleaner=true';
+ }
+ build_prep();
unless (grep { m/^--git-debian-branch|^--git-ignore-branch/ } @ARGV) {
canonicalise_suite();
push @cmd, "--git-debian-branch=".lbranch();
runcmd_ordryrun_local @cmd, @ARGV;
printdone "build successful\n";
}
+sub cmd_git_build { cmd_gbp_build(); } # compatibility with <= 1.0
sub build_source {
+ if ($cleanmode =~ m/^dpkg-source/) {
+ # dpkg-source will clean, so we shouldn't
+ $suppress_clean = 1;
+ }
build_prep();
$sourcechanges = "${package}_".(stripepoch $version)."_source.changes";
$dscfn = dscfn($version);
exit 0;
}
+our (%valopts_long, %valopts_short);
+our @rvalopts;
+
+sub defvalopt ($$$&) {
+ my ($long,$short,$val_re,$fn) = @_;
+ my $oi = { Long => $long, Short => $short, Re => $val_re, Fn => $fn };
+ $valopts_long{$long} = $oi;
+ $valopts_short{$short} = $oi;
+ # $fn subref should:
+ # do whatever assignemnt or thing it likes with $_[0]
+ # if the option should not be passed on to remote, @rvalopts=()
+}
+
+defvalopt '--since-version', '-v', '[^_]+|_', sub {
+ ($changes_since_version) = @_;
+};
+
sub parseopts () {
my $om;
@ssh = ($ENV{'GIT_SSH'});
}
+ my $oi;
+
while (@ARGV) {
last unless $ARGV[0] =~ m/^-/;
$_ = shift @ARGV;
} elsif (m/^--new$/) {
push @ropts, $_;
$new_package=1;
- } elsif (m/^--since-version=([^_]+|_)$/) {
- push @ropts, $_;
- $changes_since_version = $1;
} elsif (m/^--([-0-9a-z]+)=(.+)/s &&
($om = $opts_opt_map{$1}) &&
length $om->[0]) {
} elsif (m/^--build-products-dir=(.*)/s) {
push @ropts, $_;
$buildproductsdir = $1;
- } elsif (m/^--clean=(dpkg-source(?:-d)?|git|git-ff|check|none)$/s) {
+ } elsif (m/^--clean=($cleanmode_re)$/os) {
push @ropts, $_;
$cleanmode = $1;
} elsif (m/^--clean=(.*)$/s) {
} elsif (m/^--deliberately-($deliberately_re)$/s) {
push @ropts, $_;
push @deliberatelies, $&;
+ } elsif (m/^(--[-0-9a-z]+)(=|$)/ && ($oi = $valopts_long{$1})) {
+ @rvalopts = ($_);
+ my $val = $'; #';
+ if ($2 eq '') {
+ badusage "$oi->{Long} needs a value" unless @ARGV;
+ $val = shift @ARGV;
+ push @rvalopts, $val;
+ }
+ badusage "bad value for $oi->{Long}" unless
+ $val =~ m/^$oi->{Re}$(?!\n)/s;
+ $oi->{Fn}($val);
+ push @ropts, @rvalopts;
} else {
badusage "unknown long option \`$_'";
}
} elsif (s/^-N/-/) {
push @ropts, $&;
$new_package=1;
- } elsif (s/^-v([^_]+|_)$//s) {
- push @ropts, $&;
- $changes_since_version = $1;
} elsif (m/^-m/) {
push @ropts, $&;
push @changesopts, $_;
}
} elsif (s/^-k(.+)//s) {
$keyid=$1;
- } elsif (m/^-[vdCk]$/) {
+ } elsif (m/^-[dCk]$/) {
badusage
"option \`$_' requires an argument (and no space before the argument)";
} elsif (s/^-wn$//s) {
} elsif (s/^-wc$//s) {
push @ropts, $&;
$cleanmode = 'check';
+ } elsif (m/^-[a-zA-Z]/ && ($oi = $valopts_short{$&})) {
+ @rvalopts = ($_);
+ my $val = $'; #';
+ if (!length $val) {
+ badusage "$oi->{Short} needs a value" unless @ARGV;
+ $val = shift @ARGV;
+ push @rvalopts, $val;
+ }
+ badusage "bad value for $oi->{Short}" unless
+ $val =~ m/^$oi->{Re}$(?!\n)/s;
+ $oi->{Fn}($val);
+ push @ropts, @rvalopts;
+ $_ = '';
} else {
badusage "unknown short option \`$_'";
}
$quilt_mode = $1;
}
+if (!defined $cleanmode) {
+ local $access_forpush;
+ $cleanmode = access_cfg('clean-mode', 'RETURN-UNDEF');
+ $cleanmode //= 'dpkg-source';
+
+ badcfg "unknown clean-mode \`$cleanmode'" unless
+ $cleanmode =~ m/^($cleanmode_re)$(?!\n)/s;
+}
+
my $fn = ${*::}{"cmd_$cmd"};
$fn or badusage "unknown operation $cmd";
$fn->();