chiark
/
gitweb
/
~ianmdlvl
/
dgit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix debugprefix
[dgit.git]
/
dgit
diff --git
a/dgit
b/dgit
index e46da88a00d4e8906722d4a288bd32e3a5061b94..e12bfdc86b6b0d78a647110388a407d41b1bdba1 100755
(executable)
--- a/
dgit
+++ b/
dgit
@@
-38,7
+38,7
@@
our $package;
our @ropts;
our $sign = 1;
our @ropts;
our $sign = 1;
-our $dryrun = 0;
+our $dryrun
_level
= 0;
our $changesfile;
our $new_package = 0;
our $ignoredirty = 0;
our $changesfile;
our $new_package = 0;
our $ignoredirty = 0;
@@
-46,6
+46,7
@@
our $noquilt = 0;
our $existing_package = 'dpkg';
our $cleanmode = 'dpkg-source';
our $we_are_responder;
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)");
our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
@@
-115,7
+116,7
@@
sub dscfn ($) {
sub changesopts () { return @changesopts[1..$#changesopts]; }
our $us = 'dgit';
sub changesopts () { return @changesopts[1..$#changesopts]; }
our $us = 'dgit';
-our $debugprefix = '
';
+our $debugprefix = '';
sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
@@
-133,6
+134,12
@@
sub fetchspec () {
return "+".rrref().":".lrref();
}
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:
#---------- remote protocol support, common ----------
# remote push initiator/responder protocol:
@@
-223,9
+230,9
@@
sub protocol_receive_file ($$) {
my ($y,$l) = protocol_expect {
m/^data-block (.*})$|data-end$/;
length $1 ? (1,$1) : (0);
my ($y,$l) = protocol_expect {
m/^data-block (.*})$|data-end$/;
length $1 ? (1,$1) : (0);
- }
\*STDIN
;
+ }
$fh
;
last unless $y;
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";
print PF $d or die $!;
}
printdebug "received into $ourfn\n";
@@
-337,8
+344,11
@@
sub runcmd {
failedcmd @_ if system @_;
}
failedcmd @_ if system @_;
}
+sub act_local () { return $dryrun_level <= 1; }
+sub act_scary () { return !$dryrun_level; }
+
sub printdone {
sub printdone {
- if (!$dryrun) {
+ if (!$dryrun
_level
) {
progress "dgit ok: @_";
} else {
progress "would be ok: @_ (but dry run only)";
progress "dgit ok: @_";
} else {
progress "would be ok: @_ (but dry run only)";
@@
-371,7
+381,7
@@
sub dryrun_report {
}
sub runcmd_ordryrun {
}
sub runcmd_ordryrun {
- if (
!$dryrun
) {
+ if (
act_scary()
) {
runcmd @_;
} else {
dryrun_report @_;
runcmd @_;
} else {
dryrun_report @_;
@@
-379,7
+389,7
@@
sub runcmd_ordryrun {
}
sub runcmd_ordryrun_local {
}
sub runcmd_ordryrun_local {
- if (
$dryrun <= 1
) {
+ if (
act_local()
) {
runcmd @_;
} else {
dryrun_report @_;
runcmd @_;
} else {
dryrun_report @_;
@@
-711,7
+721,7
@@
sub mktree_in_ud_from_only_subdir () {
die unless @dirs==1;
$dirs[0] =~ m#^([^/]+)/\.$# or die;
my $dir = $1;
die unless @dirs==1;
$dirs[0] =~ m#^([^/]+)/\.$# or die;
my $dir = $1;
- ch
dir $dir or die "$dir $!"
;
+ ch
angedir $dir
;
fail "source package contains .git directory" if stat '.git';
die $! unless $!==&ENOENT;
runcmd qw(git init -q);
fail "source package contains .git directory" if stat '.git';
die $! unless $!==&ENOENT;
runcmd qw(git init -q);
@@
-778,7
+788,7
@@
sub clogp_authline ($) {
sub generate_commit_from_dsc () {
prep_ud();
sub generate_commit_from_dsc () {
prep_ud();
- ch
dir $ud or die $!
;
+ ch
angedir $ud
;
my @files;
foreach my $f (dsc_files()) {
die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
my @files;
foreach my $f (dsc_files()) {
die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
@@
-844,7
+854,7
@@
END
$outputhash = $lastpush_hash;
}
}
$outputhash = $lastpush_hash;
}
}
- ch
dir '../../../..' or die $!
;
+ ch
angedir '../../../..'
;
runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
'DGIT_ARCHIVE', $outputhash;
cmdoutput @git, qw(log -n2), $outputhash;
runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
'DGIT_ARCHIVE', $outputhash;
cmdoutput @git, qw(log -n2), $outputhash;
@@
-1004,7
+1014,7
@@
END
}
if ($lastpush_hash ne $hash) {
my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
}
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;
cmdoutput @upd_cmd;
} else {
dryrun_report @upd_cmd;
@@
-1016,9
+1026,9
@@
END
sub clone ($) {
my ($dstdir) = @_;
canonicalise_suite();
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 $!";
mkdir $dstdir or die "$dstdir $!";
- ch
dir "$dstdir" or die "$dstdir $!"
;
+ ch
angedir $dstdir
;
runcmd @git, qw(init -q);
runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
open H, "> .git/HEAD" or die $!;
runcmd @git, qw(init -q);
runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
open H, "> .git/HEAD" or die $!;
@@
-1163,7
+1173,7
@@
END
push @sign_cmd, qw(-u),$keyid if defined $keyid;
push @sign_cmd, $tfn->('.tmp');
runcmd_ordryrun @sign_cmd;
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');
$tagobjfn = $tfn->('.signed.tmp');
runcmd shell_cmd "exec >$tagobjfn", qw(cat --),
$tfn->('.tmp'), $tfn->('.tmp.asc');
@@
-1210,11
+1220,11
@@
sub dopush () {
commit_quilty_patch();
}
check_not_dirty();
commit_quilty_patch();
}
check_not_dirty();
- ch
dir $ud or die $!
;
+ ch
angedir $ud
;
progress "checking that $dscfn corresponds to HEAD";
runcmd qw(dpkg-source -x --), "../../../../$dscfn";
my ($tree,$dir) = mktree_in_ud_from_only_subdir();
progress "checking that $dscfn corresponds to HEAD";
runcmd qw(dpkg-source -x --), "../../../../$dscfn";
my ($tree,$dir) = mktree_in_ud_from_only_subdir();
- ch
dir '../../../..' or die $!
;
+ ch
angedir '../../../..'
;
my @diffcmd = (@git, qw(diff --exit-code), $tree);
printcmd \*DEBUG,$debugprefix."+",@diffcmd;
$!=0; $?=0;
my @diffcmd = (@git, qw(diff --exit-code), $tree);
printcmd \*DEBUG,$debugprefix."+",@diffcmd;
$!=0; $?=0;
@@
-1272,7
+1282,7
@@
sub dopush () {
runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD';
if (!$we_are_responder) {
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]";
rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
} else {
progress "[new .dsc left in $dscfn.tmp]";
@@
-1280,7
+1290,7
@@
sub dopush () {
}
if ($we_are_responder) {
}
if ($we_are_responder) {
- my $dryrunsuffix =
$dryrun > 1 ? ".tmp" : "
";
+ my $dryrunsuffix =
act_local() ? "" : ".tmp
";
responder_receive_files('signed-dsc-changes',
"../$dscfn$dryrunsuffix",
"$changesfile$dryrunsuffix");
responder_receive_files('signed-dsc-changes',
"../$dscfn$dryrunsuffix",
"$changesfile$dryrunsuffix");
@@
-1407,9
+1417,9
@@
sub cmd_remote_push_responder {
@ARGV = @ARGV[$nrargs..$#ARGV];
die unless @rargs;
my ($dir) = @rargs;
@ARGV = @ARGV[$nrargs..$#ARGV];
die unless @rargs;
my ($dir) = @rargs;
- chdir $dir or die "$dir: $!";
- $we_are_responder = 1;
$debugprefix = ' ';
$debugprefix = ' ';
+ changedir $dir;
+ $we_are_responder = 1;
autoflush STDOUT 1;
responder_send_command("dgit-remote-push-ready");
&cmd_push;
autoflush STDOUT 1;
responder_send_command("dgit-remote-push-ready");
&cmd_push;
@@
-1420,7
+1430,8
@@
our $i_tmp;
sub i_cleanup {
local ($@);
return unless defined $i_tmp;
sub i_cleanup {
local ($@);
return unless defined $i_tmp;
- chdir "/" or die $!;
+ return if defined $initiator_tempdir;
+ changedir "/";
eval { rmtree $i_tmp; };
}
eval { rmtree $i_tmp; };
}
@@
-1449,9
+1460,15
@@
sub cmd_rpush {
my @cmd = (@ssh, $host, shellquote @rdgit);
printcmd \*DEBUG,$debugprefix."+",@cmd;
eval {
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);
my $pid = open2(\*RO, \*RI, @cmd);
- ch
dir $i_tmp or die "$i_tmp $!"
;
+ ch
angedir $i_tmp
;
initiator_expect { m/^dgit-remote-push-ready/ };
for (;;) {
my ($icmd,$iargs) = initiator_expect {
initiator_expect { m/^dgit-remote-push-ready/ };
for (;;) {
my ($icmd,$iargs) = initiator_expect {
@@
-1664,9
+1681,9
@@
sub build_source {
}
my $pwd = cmdoutput qw(env - pwd);
my $leafdir = basename $pwd;
}
my $pwd = cmdoutput qw(env - pwd);
my $leafdir = basename $pwd;
- ch
dir ".." or die $!
;
+ ch
angedir ".."
;
runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
- ch
dir $pwd or die $!
;
+ ch
angedir $pwd
;
runcmd_ordryrun_local qw(sh -ec),
'exec >$1; shift; exec "$@"','x',
"../$sourcechanges",
runcmd_ordryrun_local qw(sh -ec),
'exec >$1; shift; exec "$@"','x',
"../$sourcechanges",
@@
-1682,9
+1699,9
@@
sub cmd_build_source {
sub cmd_sbuild {
build_source();
sub cmd_sbuild {
build_source();
- ch
dir ".." or die $!
;
+ ch
angedir ".."
;
my $pat = "${package}_".(stripepoch $version)."_*.changes";
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) {
stat $dscfn or fail "$dscfn (in parent directory): $!";
stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
foreach my $cf (glob $pat) {
@@
-1692,10
+1709,10
@@
sub cmd_sbuild {
unlink $cf or fail "remove $cf: $!";
}
}
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";
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 $!;
stat $multichanges or fail "$multichanges: $!";
}
printdone "build successful, results in $multichanges\n" or die $!;
@@
-1731,10
+1748,10
@@
sub parseopts () {
if (m/^--/) {
if (m/^--dry-run$/) {
push @ropts, $_;
if (m/^--/) {
if (m/^--dry-run$/) {
push @ropts, $_;
- $dryrun=2;
+ $dryrun
_level
=2;
} elsif (m/^--damp-run$/) {
push @ropts, $_;
} elsif (m/^--damp-run$/) {
push @ropts, $_;
- $dryrun=1;
+ $dryrun
_level
=1;
} elsif (m/^--no-sign$/) {
push @ropts, $_;
$sign=0;
} elsif (m/^--no-sign$/) {
push @ropts, $_;
$sign=0;
@@
-1758,6
+1775,11
@@
sub parseopts () {
} elsif (m/^--existing-package=(.*)/s) {
push @ropts, $_;
$existing_package = $1;
} 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;
} elsif (m/^--distro=(.*)/s) {
push @ropts, $_;
$idistro = $1;
@@
-1779,10
+1801,10
@@
sub parseopts () {
while (m/^-./s) {
if (s/^-n/-/) {
push @ropts, $&;
while (m/^-./s) {
if (s/^-n/-/) {
push @ropts, $&;
- $dryrun=2;
+ $dryrun
_level
=2;
} elsif (s/^-L/-/) {
push @ropts, $&;
} elsif (s/^-L/-/) {
push @ropts, $&;
- $dryrun=1;
+ $dryrun
_level
=1;
} elsif (s/^-h/-/) {
cmd_help();
} elsif (s/^-D/-/) {
} elsif (s/^-h/-/) {
cmd_help();
} elsif (s/^-D/-/) {
@@
-1832,8
+1854,9
@@
if ($ENV{$fakeeditorenv}) {
delete $ENV{'DGET_UNPACK'};
parseopts();
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;
if (!@ARGV) {
print STDERR $helpmsg or die $!;
exit 8;