our @ropts;
our $sign = 1;
-our $dryrun = 0;
+our $dryrun_level = 0;
our $changesfile;
our $new_package = 0;
our $ignoredirty = 0;
our $existing_package = 'dpkg';
our $cleanmode = 'dpkg-source';
our $we_are_responder;
+our $initiator_tempdir;
our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
sub changesopts () { return @changesopts[1..$#changesopts]; }
our $us = 'dgit';
-our $debugprefix = ' ';
+our $debugprefix = '';
sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
return "+".rrref().":".lrref();
}
+sub changedir ($) {
+ my ($newdir) = @_;
+ printdebug "CD $newdir\n";
+ chdir $newdir or die "chdir: $newdir: $!";
+}
+
#---------- remote protocol support, common ----------
# remote push initiator/responder protocol:
my ($y,$l) = protocol_expect {
m/^data-block (.*})$|data-end$/;
length $1 ? (1,$1) : (0);
- } \*STDIN;
+ } $fh;
last unless $y;
- my $d = protocol_read_bytes \*STDIN, $1;
+ my $d = protocol_read_bytes $fh, $1;
print PF $d or die $!;
}
printdebug "received into $ourfn\n";
failedcmd @_ if system @_;
}
+sub act_local () { return $dryrun_level <= 1; }
+sub act_scary () { return !$dryrun_level; }
+
sub printdone {
- if (!$dryrun) {
+ if (!$dryrun_level) {
progress "dgit ok: @_";
} else {
progress "would be ok: @_ (but dry run only)";
}
sub runcmd_ordryrun {
- if (!$dryrun) {
+ if (act_scary()) {
runcmd @_;
} else {
dryrun_report @_;
}
sub runcmd_ordryrun_local {
- if ($dryrun <= 1) {
+ if (act_local()) {
runcmd @_;
} else {
dryrun_report @_;
die unless @dirs==1;
$dirs[0] =~ m#^([^/]+)/\.$# or die;
my $dir = $1;
- chdir $dir or die "$dir $!";
+ changedir $dir;
fail "source package contains .git directory" if stat '.git';
die $! unless $!==&ENOENT;
runcmd qw(git init -q);
sub generate_commit_from_dsc () {
prep_ud();
- chdir $ud or die $!;
+ changedir $ud;
my @files;
foreach my $f (dsc_files()) {
die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
$outputhash = $lastpush_hash;
}
}
- chdir '../../../..' or die $!;
+ changedir '../../../..';
runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
'DGIT_ARCHIVE', $outputhash;
cmdoutput @git, qw(log -n2), $outputhash;
}
if ($lastpush_hash ne $hash) {
my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
- if ($dryrun <= 1) {
+ if (act_local()) {
cmdoutput @upd_cmd;
} else {
dryrun_report @upd_cmd;
sub clone ($) {
my ($dstdir) = @_;
canonicalise_suite();
- badusage "dry run makes no sense with clone" if $dryrun > 1;
+ badusage "dry run makes no sense with clone" unless act_local();
mkdir $dstdir or die "$dstdir $!";
- chdir "$dstdir" or die "$dstdir $!";
+ changedir $dstdir;
runcmd @git, qw(init -q);
runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
open H, "> .git/HEAD" or die $!;
push @sign_cmd, qw(-u),$keyid if defined $keyid;
push @sign_cmd, $tfn->('.tmp');
runcmd_ordryrun @sign_cmd;
- if (!$dryrun) {
+ if (act_scary()) {
$tagobjfn = $tfn->('.signed.tmp');
runcmd shell_cmd "exec >$tagobjfn", qw(cat --),
$tfn->('.tmp'), $tfn->('.tmp.asc');
commit_quilty_patch();
}
check_not_dirty();
- chdir $ud or die $!;
+ changedir $ud;
progress "checking that $dscfn corresponds to HEAD";
runcmd qw(dpkg-source -x --), "../../../../$dscfn";
my ($tree,$dir) = mktree_in_ud_from_only_subdir();
- chdir '../../../..' or die $!;
+ changedir '../../../..';
my @diffcmd = (@git, qw(diff --exit-code), $tree);
printcmd \*DEBUG,$debugprefix."+",@diffcmd;
$!=0; $?=0;
runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD';
if (!$we_are_responder) {
- if ($dryrun <= 1) {
+ if (act_local()) {
rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
} else {
progress "[new .dsc left in $dscfn.tmp]";
}
if ($we_are_responder) {
- my $dryrunsuffix = $dryrun > 1 ? ".tmp" : "";
+ my $dryrunsuffix = act_local() ? "" : ".tmp";
responder_receive_files('signed-dsc-changes',
"../$dscfn$dryrunsuffix",
"$changesfile$dryrunsuffix");
@ARGV = @ARGV[$nrargs..$#ARGV];
die unless @rargs;
my ($dir) = @rargs;
- chdir $dir or die "$dir: $!";
- $we_are_responder = 1;
$debugprefix = ' ';
+ changedir $dir;
+ $we_are_responder = 1;
autoflush STDOUT 1;
responder_send_command("dgit-remote-push-ready");
&cmd_push;
sub i_cleanup {
local ($@);
return unless defined $i_tmp;
- chdir "/" or die $!;
+ return if defined $initiator_tempdir;
+ changedir "/";
eval { rmtree $i_tmp; };
}
my @cmd = (@ssh, $host, shellquote @rdgit);
printcmd \*DEBUG,$debugprefix."+",@cmd;
eval {
- $i_tmp = tempdir();
+ if (defined $initiator_tempdir) {
+ rmtree $initiator_tempdir;
+ mkdir $initiator_tempdir, 0700 or die "$initiator_tempdir: $!";
+ $i_tmp = $initiator_tempdir;
+ } else {
+ $i_tmp = tempdir();
+ }
my $pid = open2(\*RO, \*RI, @cmd);
- chdir $i_tmp or die "$i_tmp $!";
+ changedir $i_tmp;
initiator_expect { m/^dgit-remote-push-ready/ };
for (;;) {
my ($icmd,$iargs) = initiator_expect {
}
my $pwd = cmdoutput qw(env - pwd);
my $leafdir = basename $pwd;
- chdir ".." or die $!;
+ changedir "..";
runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
- chdir $pwd or die $!;
+ changedir $pwd;
runcmd_ordryrun_local qw(sh -ec),
'exec >$1; shift; exec "$@"','x',
"../$sourcechanges",
sub cmd_sbuild {
build_source();
- chdir ".." or die $!;
+ changedir "..";
my $pat = "${package}_".(stripepoch $version)."_*.changes";
- if ($dryrun <= 1) {
+ if (act_local()) {
stat $dscfn or fail "$dscfn (in parent directory): $!";
stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
foreach my $cf (glob $pat) {
unlink $cf or fail "remove $cf: $!";
}
}
- runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
- runcmd_ordryrun @mergechanges, glob $pat;
+ runcmd_ordryrun_local @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
+ runcmd_ordryrun_local @mergechanges, glob $pat;
my $multichanges = "${package}_".(stripepoch $version)."_multi.changes";
- if ($dryrun <= 1) {
+ if (act_local()) {
stat $multichanges or fail "$multichanges: $!";
}
printdone "build successful, results in $multichanges\n" or die $!;
if (m/^--/) {
if (m/^--dry-run$/) {
push @ropts, $_;
- $dryrun=2;
+ $dryrun_level=2;
} elsif (m/^--damp-run$/) {
push @ropts, $_;
- $dryrun=1;
+ $dryrun_level=1;
} elsif (m/^--no-sign$/) {
push @ropts, $_;
$sign=0;
} elsif (m/^--existing-package=(.*)/s) {
push @ropts, $_;
$existing_package = $1;
+ } elsif (m/^--initiator-tempdir=(.*)/s) {
+ $initiator_tempdir = $1;
+ $initiator_tempdir =~ m#^/# or
+ badusage "--initiator-tempdir must be used specify an".
+ " absolute, not relative, directory."
} elsif (m/^--distro=(.*)/s) {
push @ropts, $_;
$idistro = $1;
while (m/^-./s) {
if (s/^-n/-/) {
push @ropts, $&;
- $dryrun=2;
+ $dryrun_level=2;
} elsif (s/^-L/-/) {
push @ropts, $&;
- $dryrun=1;
+ $dryrun_level=1;
} elsif (s/^-h/-/) {
cmd_help();
} elsif (s/^-D/-/) {
delete $ENV{'DGET_UNPACK'};
parseopts();
-print STDERR "DRY RUN ONLY\n" if $dryrun > 1;
-print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n" if $dryrun == 1;
+print STDERR "DRY RUN ONLY\n" if $dryrun_level > 1;
+print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n"
+ if $dryrun_level == 1;
if (!@ARGV) {
print STDERR $helpmsg or die $!;
exit 8;