3 # Integration between git and Debian-style archives
5 # Copyright (C)2013 Ian Jackson
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Dpkg::Control::Hash;
27 use File::Temp qw(tempdir);
33 our $our_version = 'UNRELEASED'; ###substituted###
35 our $isuite = 'unstable';
41 our $dryrun_level = 0;
46 our $existing_package = 'dpkg';
47 our $cleanmode = 'dpkg-source';
48 our $we_are_responder;
49 our $initiator_tempdir;
51 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
54 our (@dget) = qw(dget);
55 our (@dput) = qw(dput);
56 our (@debsign) = qw(debsign);
58 our (@sbuild) = qw(sbuild -A);
60 our (@dgit) = qw(dgit);
61 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
62 our (@dpkgsource) = qw(dpkg-source -i\.git/ -I.git);
63 our (@dpkggenchanges) = qw(dpkg-genchanges);
64 our (@mergechanges) = qw(mergechanges -f);
65 our (@changesopts) = ('');
67 our %opts_opt_map = ('dget' => \@dget,
69 'debsign' => \@debsign,
74 'dpkg-source' => \@dpkgsource,
75 'dpkg-buildpackage' => \@dpkgbuildpackage,
76 'dpkg-genchanges' => \@dpkggenchanges,
77 'ch' => \@changesopts,
78 'mergechanges' => \@mergechanges);
80 our %opts_opt_cmdonly = ('gpg' => 1);
85 open DEBUG, ">/dev/null" or die $!;
89 our $remotename = 'dgit';
90 our @ourdscfield = qw(Dgit Vcs-Dgit-Master);
91 our $branchprefix = 'dgit';
94 sub lbranch () { return "$branchprefix/$csuite"; }
95 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
96 sub lref () { return "refs/heads/".lbranch(); }
97 sub lrref () { return "refs/remotes/$remotename/$branchprefix/$csuite"; }
98 sub rrref () { return "refs/$branchprefix/$csuite"; }
113 return "${package}_".(stripepoch $vsn).".dsc";
116 sub changesopts () { return @changesopts[1..$#changesopts]; }
119 our $debugprefix = '';
121 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
123 sub fail { die "$us: @_\n"; }
125 sub badcfg { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
127 sub no_such_package () {
128 print STDERR "$us: package $package does not exist in suite $isuite\n";
134 return "+".rrref().":".lrref();
139 printdebug "CD $newdir\n";
140 chdir $newdir or die "chdir: $newdir: $!";
143 #---------- remote protocol support, common ----------
145 # remote push initiator/responder protocol:
146 # < dgit-remote-push-ready [optional extra info ignored by old initiators]
148 # > file parsed-changelog
149 # [indicates that output of dpkg-parsechangelog follows]
150 # > data-block NBYTES
151 # > [NBYTES bytes of data (no newline)]
152 # [maybe some more blocks]
164 # [indicates that signed tag is wanted]
165 # < data-block NBYTES
166 # < [NBYTES bytes of data (no newline)]
167 # [maybe some more blocks]
171 # > want signed-dsc-changes
172 # < data-block NBYTES [transfer of signed dsc]
174 # < data-block NBYTES [transfer of signed changes]
182 fail "connection lost: $!" if $fh->error;
183 fail "connection terminated" if $fh->eof;
184 fail "protocol violation; $m not expected";
187 sub protocol_expect (&$) {
188 my ($match, $fh) = @_;
191 defined && chomp or badproto $fh, "eof";
199 badproto $fh, "\`$_'";
202 sub protocol_send_file ($$) {
203 my ($fh, $ourfn) = @_;
204 open PF, "<", $ourfn or die "$ourfn: $!";
207 my $got = read PF, $d, 65536;
208 die "$ourfn: $!" unless defined $got;
210 print $fh "data-block ".length($d)."\n" or die $!;
213 PF->eof or die "$ourfn $!";
214 PF->error and die "$ourfn $!";
215 print $fh "data-end\n" or die $!;
219 sub protocol_read_bytes ($$) {
220 my ($fh, $nbytes) = @_;
221 $nbytes =~ m/^[1-9]\d{0,5}$/ or badproto \*RO, "bad byte count";
223 my $got = read $fh, $d, $nbytes;
224 $got==$nbytes or badproto $fh, "eof during data block";
228 sub protocol_receive_file ($$) {
229 my ($fh, $ourfn) = @_;
230 open PF, ">", $ourfn or die "$ourfn: $!";
232 my ($y,$l) = protocol_expect {
233 m/^data-block (.*)$/ ? (1,$1) :
234 m/^data-end$/ ? (0,) :
238 my $d = protocol_read_bytes $fh, $l;
239 print PF $d or die $!;
242 printdebug "() $ourfn\n";
245 #---------- remote protocol support, responder ----------
247 sub responder_send_command ($) {
249 return unless $we_are_responder;
250 # called even without $we_are_responder
251 printdebug "<< $command\n";
252 print $command, "\n" or die $!;
255 sub responder_send_file ($$) {
256 my ($keyword, $ourfn) = @_;
257 return unless $we_are_responder;
258 printdebug "[[ $keyword $ourfn\n";
259 responder_send_command "file $keyword";
260 protocol_send_file \*STDOUT, $ourfn;
263 sub responder_receive_files ($@) {
264 my ($keyword, @ourfns) = @_;
265 die unless $we_are_responder;
266 printdebug "]] $keyword @ourfns\n";
267 responder_send_command "want $keyword";
268 foreach my $fn (@ourfns) {
269 protocol_receive_file \*STDIN, $fn;
271 protocol_expect { m/^files-end$/ } \*STDIN;
274 #---------- remote protocol support, initiator ----------
276 sub initiator_expect (&) {
278 protocol_expect { &$match } \*RO;
281 #---------- end remote code ----------
284 if ($we_are_responder) {
286 responder_send_command "progress ".length($m) or die $!;
297 $ua = LWP::UserAgent->new();
301 progress "downloading $what...";
302 my $r = $ua->get(@_) or die $!;
303 return undef if $r->code == 404;
304 $r->is_success or fail "failed to fetch $what: ".$r->status_line;
305 return $r->decoded_content();
308 our ($dscdata,$dscurl,$dsc,$skew_warning_vsn);
315 if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
321 return join ' ', @out;
326 my $intro = shift @_;
327 print $fh $intro," " or die $!;
328 print $fh shellquote @_ or die $!;
329 print $fh "\n" or die $!;
333 { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; };
335 fail "failed to fork/exec: $!";
336 } elsif (!($? & 0xff)) {
337 fail "subprocess failed with error exit status ".($?>>8);
339 fail "subprocess crashed (wait status $?)";
341 fail "subprocess produced invalid output";
346 printcmd(\*DEBUG,$debugprefix."+",@_) if $debug>0;
348 failedcmd @_ if system @_;
351 sub act_local () { return $dryrun_level <= 1; }
352 sub act_scary () { return !$dryrun_level; }
355 if (!$dryrun_level) {
356 progress "dgit ok: @_";
358 progress "would be ok: @_ (but dry run only)";
362 sub cmdoutput_errok {
363 die Dumper(\@_)." ?" if grep { !defined } @_;
364 printcmd(\*DEBUG,$debugprefix."|",@_) if $debug>0;
365 open P, "-|", @_ or die $!;
368 { local $/ = undef; $d = <P>; }
370 if (!close P) { printdebug "=>!$?\n" if $debug>0; return undef; }
373 printdebug "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
378 my $d = cmdoutput_errok @_;
379 defined $d or failedcmd @_;
384 printcmd(\*STDERR,$debugprefix."#",@_);
387 sub runcmd_ordryrun {
395 sub runcmd_ordryrun_local {
404 my ($first_shell, @cmd) = @_;
405 return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd;
408 our $helpmsg = <<END;
410 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
411 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
412 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
413 dgit [dgit-opts] push [dgit-opts] [suite]
414 dgit [dgit-opts] rpush build-host:build-dir ...
415 important dgit options:
416 -k<keyid> sign tag and package with <keyid> instead of default
417 --dry-run -n do not change anything, but go through the motions
418 --damp-run -L like --dry-run but make local changes, without signing
419 --new -N allow introducing a new package
420 --debug -D increase debug level
421 -c<name>=<value> set git config option (used directly by dgit too)
424 our $later_warning_msg = <<END;
425 Perhaps the upload is stuck in incoming. Using the version from git.
429 print STDERR "$us: @_\n", $helpmsg or die $!;
434 @ARGV or badusage "too few arguments";
435 return scalar shift @ARGV;
439 print $helpmsg or die $!;
443 our %defcfg = ('dgit.default.distro' => 'debian',
444 'dgit.default.username' => '',
445 'dgit.default.archive-query-default-component' => 'main',
446 'dgit.default.ssh' => 'ssh',
447 'dgit-distro.debian.git-host' => 'git.debian.org',
448 'dgit-distro.debian.git-proto' => 'git+ssh://',
449 'dgit-distro.debian.git-path' => '/git/dgit-repos/repos',
450 'dgit-distro.debian.git-check' => 'ssh-cmd',
451 'dgit-distro.debian.git-create' => 'ssh-cmd',
452 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
453 'dgit-distro.debian.sshdakls-dir' =>
454 '/srv/ftp-master.debian.org/ftp/dists',
455 'dgit-distro.debian.upload-host' => 'ftp-master', # for dput
456 'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/');
460 return undef if $c =~ /RETURN-UNDEF/;
461 my @cmd = (@git, qw(config --), $c);
464 local ($debug) = $debug-1;
465 $v = cmdoutput_errok @cmd;
472 my $dv = $defcfg{$c};
473 return $dv if defined $dv;
475 badcfg "need value for one of: @_";
478 sub access_distro () {
479 return cfg("dgit-suite.$isuite.distro",
480 "dgit.default.distro");
485 my $distro = $idistro || access_distro();
486 my $value = cfg(map { ("dgit-distro.$distro.$_",
487 "dgit.default.$_") } @keys);
491 sub string_to_ssh ($) {
493 if ($spec =~ m/\s/) {
494 return qw(sh -ec), 'exec '.$spec.' "$@"', 'x';
500 sub access_cfg_ssh () {
501 my $gitssh = access_cfg('ssh', 'RETURN-UNDEF');
502 if (!defined $gitssh) {
505 return string_to_ssh $gitssh;
509 sub access_someuserhost ($) {
511 my $user = access_cfg("$some-user",'username');
512 my $host = access_cfg("$some-host");
513 return length($user) ? "$user\@$host" : $host;
516 sub access_gituserhost () {
517 return access_someuserhost('git');
520 sub access_giturl () {
521 my $url = access_cfg('git-url','RETURN-UNDEF');
524 access_cfg('git-proto').
525 access_gituserhost().
526 access_cfg('git-path');
528 return "$url/$package.git";
531 sub parsecontrolfh ($$@) {
532 my ($fh, $desc, @opts) = @_;
533 my %opts = ('name' => $desc, @opts);
534 my $c = Dpkg::Control::Hash->new(%opts);
535 $c->parse($fh) or die "parsing of $desc failed";
540 my ($file, $desc) = @_;
541 my $fh = new IO::Handle;
542 open $fh, '<', $file or die "$file: $!";
543 my $c = parsecontrolfh($fh,$desc);
544 $fh->error and die $!;
550 my ($dctrl,$field) = @_;
551 my $v = $dctrl->{$field};
552 return $v if defined $v;
553 fail "missing field $field in ".$v->get_option('name');
557 my $c = Dpkg::Control::Hash->new();
558 my $p = new IO::Handle;
559 my @cmd = (qw(dpkg-parsechangelog), @_);
560 open $p, '-|', @cmd or die $!;
562 $?=0; $!=0; close $p or failedcmd @cmd;
568 sub archive_query ($) {
570 my $query = access_cfg('archive-query','RETURN-UNDEF');
571 if (!defined $query) {
572 my $distro = access_distro();
573 if ($distro eq 'debian') {
574 $query = "sshdakls:".
575 access_someuserhost('sshdakls').':'.
576 access_cfg('sshdakls-dir');
578 $query = "madison:$distro";
581 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
584 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
587 sub archive_query_madison ($$) {
588 my ($proto,$data) = @_;
589 die unless $proto eq 'madison';
590 $rmad{$package} ||= cmdoutput
591 qw(rmadison -asource),"-s$isuite","-u$data",$package;
592 my $rmad = $rmad{$package};
593 return madison_parse($rmad);
596 sub archive_query_sshdakls ($$) {
597 my ($proto,$data) = @_;
598 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
599 my $dakls = cmdoutput
600 access_cfg_ssh, $data, qw(dak ls -asource),"-s$isuite",$package;
601 return madison_parse($dakls);
604 sub canonicalise_suite_sshdakls ($$) {
605 my ($proto,$data) = @_;
606 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
610 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
611 " if test -d $isuite; then echo $isuite; exit 0; fi;".
613 my $dakls = cmdoutput @cmd;
614 failedcmd @cmd unless $dakls =~ m/^\w/;
618 sub madison_parse ($) {
621 foreach my $l (split /\n/, $rmad) {
622 $l =~ m{^ \s*( [^ \t|]+ )\s* \|
623 \s*( [^ \t|]+ )\s* \|
624 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
625 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
626 $1 eq $package or die "$rmad $package ?";
633 $component = access_cfg('archive-query-default-component');
635 $5 eq 'source' or die "$rmad ?";
636 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
637 my $subpath = "/pool/$component/$prefix/$package/".dscfn($vsn);
638 push @out, [$vsn,$subpath,$newsuite];
640 return sort { -version_compare_string($a->[0],$b->[0]); } @out;
643 sub canonicalise_suite_madison ($$) {
644 my @r = archive_query_madison($_[0],$_[1]);
646 "unable to canonicalise suite using package $package".
647 " which does not appear to exist in suite $isuite;".
648 " --existing-package may help";
652 sub canonicalise_suite () {
653 return if defined $csuite;
654 fail "cannot operate on $isuite suite" if $isuite eq 'UNRELEASED';
655 $csuite = archive_query('canonicalise_suite');
656 if ($isuite ne $csuite) {
657 # madison canonicalises for us
658 progress "canonical suite name for $isuite is $csuite";
662 sub get_archive_dsc () {
663 canonicalise_suite();
664 my @vsns = archive_query('archive_query');
665 foreach my $vinfo (@vsns) {
666 my ($vsn,$subpath) = @$vinfo;
667 $dscurl = access_cfg('mirror').$subpath;
668 $dscdata = url_get($dscurl);
670 $skew_warning_vsn = $vsn if !defined $skew_warning_vsn;
673 my $dscfh = new IO::File \$dscdata, '<' or die $!;
674 printdebug Dumper($dscdata) if $debug>1;
675 $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1);
676 printdebug Dumper($dsc) if $debug>1;
677 my $fmt = getfield $dsc, 'Format';
678 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
684 sub check_for_git () {
686 my $how = access_cfg('git-check');
687 if ($how eq 'ssh-cmd') {
689 (access_cfg_ssh, access_gituserhost(),
690 " set -e; cd ".access_cfg('git-path').";".
691 " if test -d $package.git; then echo 1; else echo 0; fi");
692 my $r= cmdoutput @cmd;
693 failedcmd @cmd unless $r =~ m/^[01]$/;
696 badcfg "unknown git-check \`$how'";
700 sub create_remote_git_repo () {
701 my $how = access_cfg('git-create');
702 if ($how eq 'ssh-cmd') {
704 (access_cfg_ssh, access_gituserhost(),
705 "set -e; cd ".access_cfg('git-path').";".
706 " cp -a _template $package.git");
708 badcfg "unknown git-create \`$how'";
712 our ($dsc_hash,$lastpush_hash);
714 our $ud = '.git/dgit/unpack';
722 sub mktree_in_ud_from_only_subdir () {
723 # changes into the subdir
726 $dirs[0] =~ m#^([^/]+)/\.$# or die;
729 fail "source package contains .git directory" if stat '.git';
730 die $! unless $!==&ENOENT;
731 runcmd qw(git init -q);
732 rmtree('.git/objects');
733 symlink '../../../../objects','.git/objects' or die $!;
734 runcmd @git, qw(add -Af);
735 my $tree = cmdoutput @git, qw(write-tree);
736 $tree =~ m/^\w+$/ or die "$tree ?";
740 sub dsc_files_info () {
741 foreach my $csumi (['Checksums-Sha256','Digest::SHA', 'new(256)'],
742 ['Checksums-Sha1', 'Digest::SHA', 'new(1)'],
743 ['Files', 'Digest::MD5', 'new()']) {
744 my ($fname, $module, $method) = @$csumi;
745 my $field = $dsc->{$fname};
746 next unless defined $field;
747 eval "use $module; 1;" or die $@;
749 foreach (split /\n/, $field) {
751 m/^(\w+) (\d+) (\S+)$/ or
752 fail "could not parse .dsc $fname line \`$_'";
753 my $digester = eval "$module"."->$method;" or die $@;
758 Digester => $digester,
763 fail "missing any supported Checksums-* or Files field in ".
764 $dsc->get_option('name');
768 map { $_->{Filename} } dsc_files_info();
771 sub is_orig_file ($) {
773 m/\.orig(?:-\w+)?\.tar\.\w+$/;
776 sub make_commit ($) {
778 return cmdoutput @git, qw(hash-object -w -t commit), $file;
781 sub clogp_authline ($) {
783 my $author = getfield $clogp, 'Maintainer';
784 $author =~ s#,.*##ms;
785 my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
786 my $authline = "$author $date";
787 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
788 fail "unexpected commit author line format \`$authline'".
789 " (was generated from changelog Maintainer field)";
793 sub generate_commit_from_dsc () {
797 foreach my $f (dsc_files()) {
798 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
800 link "../../../$f", $f
804 runcmd @dget, qw(--), $dscurl;
805 foreach my $f (grep { is_orig_file($_) } @files) {
806 link $f, "../../../../$f"
810 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
811 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
812 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
813 my $authline = clogp_authline $clogp;
814 my $changes = getfield $clogp, 'Changes';
815 open C, ">../commit.tmp" or die $!;
816 print C <<END or die $!;
823 # imported from the archive
826 my $outputhash = make_commit qw(../commit.tmp);
827 my $cversion = getfield $clogp, 'Version';
828 progress "synthesised git commit from .dsc $cversion";
829 if ($lastpush_hash) {
830 runcmd @git, qw(reset --hard), $lastpush_hash;
831 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
832 my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
833 my $oversion = getfield $oldclogp, 'Version';
835 version_compare_string($oversion, $cversion);
837 # git upload/ is earlier vsn than archive, use archive
838 open C, ">../commit2.tmp" or die $!;
839 print C <<END or die $!;
841 parent $lastpush_hash
846 Record $package ($cversion) in archive suite $csuite
848 $outputhash = make_commit qw(../commit2.tmp);
849 } elsif ($vcmp > 0) {
850 print STDERR <<END or die $!;
852 Version actually in archive: $cversion (older)
853 Last allegedly pushed/uploaded: $oversion (newer or same)
856 $outputhash = $lastpush_hash;
858 $outputhash = $lastpush_hash;
861 changedir '../../../..';
862 runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
863 'DGIT_ARCHIVE', $outputhash;
864 cmdoutput @git, qw(log -n2), $outputhash;
865 # ... gives git a chance to complain if our commit is malformed
870 sub ensure_we_have_orig () {
871 foreach my $fi (dsc_files_info()) {
872 my $f = $fi->{Filename};
873 next unless is_orig_file($f);
874 if (open F, "<", "../$f") {
875 $fi->{Digester}->reset();
876 $fi->{Digester}->addfile(*F);
878 my $got = $fi->{Digester}->hexdigest();
879 $got eq $fi->{Hash} or
880 fail "existing file $f has hash $got but .dsc".
881 " demands hash $fi->{Hash}".
882 " (perhaps you should delete this file?)";
883 progress "using existing $f";
886 die "$f $!" unless $!==&ENOENT;
888 my $origurl = $dscurl;
889 $origurl =~ s{/[^/]+$}{};
891 die "$f ?" unless $f =~ m/^${package}_/;
892 die "$f ?" if $f =~ m#/#;
893 runcmd_ordryrun_local shell_cmd 'cd ..', @dget,'--',$origurl;
898 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
901 sub is_fast_fwd ($$) {
902 my ($ancestor,$child) = @_;
903 my @cmd = (@git, qw(merge-base), $ancestor, $child);
904 my $mb = cmdoutput_errok @cmd;
906 return rev_parse($mb) eq rev_parse($ancestor);
908 $?==256 or failedcmd @cmd;
913 sub git_fetch_us () {
914 runcmd_ordryrun_local @git, qw(fetch),access_giturl(),fetchspec();
917 sub fetch_from_archive () {
918 # ensures that lrref() is what is actually in the archive,
923 foreach my $field (@ourdscfield) {
924 $dsc_hash = $dsc->{$field};
925 last if defined $dsc_hash;
927 if (defined $dsc_hash) {
928 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
930 progress "last upload to archive specified git hash";
932 progress "last upload to archive has NO git hash";
935 progress "no version available from the archive";
938 my $lrref_fn = ".git/".lrref();
939 if (open H, $lrref_fn) {
940 $lastpush_hash = <H>;
941 chomp $lastpush_hash;
942 die "$lrref_fn $lastpush_hash ?" unless $lastpush_hash =~ m/^\w+$/;
943 } elsif ($! == &ENOENT) {
948 printdebug "previous reference hash=$lastpush_hash\n";
950 if (defined $dsc_hash) {
951 fail "missing git history even though dsc has hash -".
952 " could not find commit $dsc_hash".
953 " (should be in ".access_giturl()."#".rrref().")"
954 unless $lastpush_hash;
956 ensure_we_have_orig();
957 if ($dsc_hash eq $lastpush_hash) {
958 } elsif (is_fast_fwd($dsc_hash,$lastpush_hash)) {
959 print STDERR <<END or die $!;
961 Git commit in archive is behind the last version allegedly pushed/uploaded.
962 Commit referred to by archive: $dsc_hash
963 Last allegedly pushed/uploaded: $lastpush_hash
966 $hash = $lastpush_hash;
968 fail "archive's .dsc refers to ".$dsc_hash.
969 " but this is an ancestor of ".$lastpush_hash;
972 $hash = generate_commit_from_dsc();
973 } elsif ($lastpush_hash) {
974 # only in git, not in the archive yet
975 $hash = $lastpush_hash;
976 print STDERR <<END or die $!;
978 Package not found in the archive, but has allegedly been pushed using dgit.
982 printdebug "nothing found!\n";
983 if (defined $skew_warning_vsn) {
984 print STDERR <<END or die $!;
986 Warning: relevant archive skew detected.
987 Archive allegedly contains $skew_warning_vsn
988 But we were not able to obtain any version from the archive or git.
994 printdebug "current hash=$hash\n";
995 if ($lastpush_hash) {
996 fail "not fast forward on last upload branch!".
997 " (archive's version left in DGIT_ARCHIVE)"
998 unless is_fast_fwd($lastpush_hash, $hash);
1000 if (defined $skew_warning_vsn) {
1002 printdebug "SKEW CHECK WANT $skew_warning_vsn\n";
1003 my $clogf = ".git/dgit/changelog.tmp";
1004 runcmd shell_cmd "exec >$clogf",
1005 @git, qw(cat-file blob), "$hash:debian/changelog";
1006 my $gotclogp = parsechangelog("-l$clogf");
1007 my $got_vsn = getfield $gotclogp, 'Version';
1008 printdebug "SKEW CHECK GOT $got_vsn\n";
1009 if (version_compare_string($got_vsn, $skew_warning_vsn) < 0) {
1010 print STDERR <<END or die $!;
1012 Warning: archive skew detected. Using the available version:
1013 Archive allegedly contains $skew_warning_vsn
1014 We were able to obtain only $got_vsn
1019 if ($lastpush_hash ne $hash) {
1020 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
1024 dryrun_report @upd_cmd;
1032 canonicalise_suite();
1033 badusage "dry run makes no sense with clone" unless act_local();
1034 mkdir $dstdir or die "$dstdir $!";
1036 runcmd @git, qw(init -q);
1037 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
1038 open H, "> .git/HEAD" or die $!;
1039 print H "ref: ".lref()."\n" or die $!;
1041 runcmd @git, qw(remote add), 'origin', access_giturl();
1042 if (check_for_git()) {
1043 progress "fetching existing git history";
1045 runcmd_ordryrun_local @git, qw(fetch origin);
1047 progress "starting new git history";
1049 fetch_from_archive() or no_such_package;
1050 runcmd @git, qw(reset --hard), lrref();
1051 printdone "ready for work in $dstdir";
1055 if (check_for_git()) {
1058 fetch_from_archive() or no_such_package();
1059 printdone "fetched into ".lrref();
1064 runcmd_ordryrun_local @git, qw(merge -m),"Merge from $csuite [dgit]",
1066 printdone "fetched to ".lrref()." and merged into HEAD";
1069 sub check_not_dirty () {
1070 return if $ignoredirty;
1071 my @cmd = (@git, qw(diff --quiet HEAD));
1072 printcmd(\*DEBUG,$debugprefix."+",@cmd) if $debug>0;
1073 $!=0; $?=0; system @cmd;
1074 return if !$! && !$?;
1075 if (!$! && $?==256) {
1076 fail "working tree is dirty (does not match HEAD)";
1082 sub commit_quilty_patch () {
1083 my $output = cmdoutput @git, qw(status --porcelain);
1085 foreach my $l (split /\n/, $output) {
1086 next unless $l =~ m/\S/;
1087 if ($l =~ m{^(?:\?\?| M) (.pc|debian/patches)}) {
1092 progress "nothing quilty to commit, ok.";
1095 runcmd_ordryrun_local @git, qw(add), sort keys %adds;
1096 my $m = "Commit Debian 3.0 (quilt) metadata";
1098 runcmd_ordryrun_local @git, qw(commit -m), $m;
1103 return 0 unless $format eq '3.0 (quilt)';
1104 progress "Format \`$format', urgh";
1106 progress "Not doing any fixup of \`$format' due to --no-quilt-fixup";
1112 sub push_parse_changelog ($) {
1115 my $clogp = Dpkg::Control::Hash->new();
1116 $clogp->load($clogpfn) or die;
1118 $package = getfield $clogp, 'Source';
1119 my $cversion = getfield $clogp, 'Version';
1120 my $tag = debiantag($cversion);
1121 runcmd @git, qw(check-ref-format), $tag;
1123 my $dscfn = dscfn($cversion);
1125 return ($clogp, $cversion, $tag, $dscfn);
1128 sub push_parse_dsc ($$$) {
1129 my ($dscfn,$dscfnwhat, $cversion) = @_;
1130 $dsc = parsecontrol($dscfn,$dscfnwhat);
1131 my $dversion = getfield $dsc, 'Version';
1132 my $dscpackage = getfield $dsc, 'Source';
1133 ($dscpackage eq $package && $dversion eq $cversion) or
1134 fail "$dsc is for $dscpackage $dversion".
1135 " but debian/changelog is for $package $cversion";
1138 sub push_mktag ($$$$$$$$) {
1139 my ($head,$clogp,$tag,
1141 $changesfile,$changesfilewhat,
1144 $dsc->{$ourdscfield[0]} = $head;
1145 $dsc->save("$dscfn.tmp") or die $!;
1147 my $changes = parsecontrol($changesfile,$changesfilewhat);
1148 foreach my $field (qw(Source Distribution Version)) {
1149 $changes->{$field} eq $clogp->{$field} or
1150 fail "changes field $field \`$changes->{$field}'".
1151 " does not match changelog \`$clogp->{$field}'";
1154 my $cversion = getfield $clogp, 'Version';
1156 # We make the git tag by hand because (a) that makes it easier
1157 # to control the "tagger" (b) we can do remote signing
1158 my $authline = clogp_authline $clogp;
1159 open TO, '>', $tfn->('.tmp') or die $!;
1160 print TO <<END or die $!;
1166 $package release $cversion for $csuite [dgit]
1170 my $tagobjfn = $tfn->('.tmp');
1172 if (!defined $keyid) {
1173 $keyid = access_cfg('keyid','RETURN-UNDEF');
1175 unlink $tfn->('.tmp.asc') or $!==&ENOENT or die $!;
1176 my @sign_cmd = (@gpg, qw(--detach-sign --armor));
1177 push @sign_cmd, qw(-u),$keyid if defined $keyid;
1178 push @sign_cmd, $tfn->('.tmp');
1179 runcmd_ordryrun @sign_cmd;
1181 $tagobjfn = $tfn->('.signed.tmp');
1182 runcmd shell_cmd "exec >$tagobjfn", qw(cat --),
1183 $tfn->('.tmp'), $tfn->('.tmp.asc');
1190 sub sign_changes ($) {
1191 my ($changesfile) = @_;
1193 my @debsign_cmd = @debsign;
1194 push @debsign_cmd, "-k$keyid" if defined $keyid;
1195 push @debsign_cmd, "-p$gpg[0]" if $gpg[0] ne 'gpg';
1196 push @debsign_cmd, $changesfile;
1197 runcmd_ordryrun @debsign_cmd;
1202 printdebug "actually entering push\n";
1205 my $clogpfn = ".git/dgit/changelog.822.tmp";
1206 runcmd shell_cmd "exec >$clogpfn", qw(dpkg-parsechangelog);
1208 responder_send_file('parsed-changelog', $clogpfn);
1210 my ($clogp, $cversion, $tag, $dscfn) =
1211 push_parse_changelog("$clogpfn");
1214 fail "looked for .dsc $dscfn, but $!;".
1215 " maybe you forgot to build";
1217 responder_send_file('dsc', "../$dscfn");
1219 push_parse_dsc("../$dscfn", $dscfn, $cversion);
1221 my $format = getfield $dsc, 'Format';
1222 printdebug "format $format\n";
1223 if (madformat($format)) {
1224 commit_quilty_patch();
1228 progress "checking that $dscfn corresponds to HEAD";
1229 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
1230 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
1231 changedir '../../../..';
1232 my @diffcmd = (@git, qw(diff --exit-code), $tree);
1233 printcmd \*DEBUG,$debugprefix."+",@diffcmd;
1235 if (system @diffcmd) {
1236 if ($! && $?==256) {
1237 fail "$dscfn specifies a different tree to your HEAD commit;".
1238 " perhaps you forgot to build";
1244 #do fast forward check and maybe fake merge
1245 # if (!is_fast_fwd(mainbranch
1246 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
1247 # map { lref($_).":".rref($_) }
1249 my $head = rev_parse('HEAD');
1250 if (!$changesfile) {
1251 my $multi = "../${package}_".(stripepoch $cversion)."_multi.changes";
1252 if (stat "$multi") {
1253 $changesfile = $multi;
1255 $!==&ENOENT or die "$multi: $!";
1256 my $pat = "${package}_".(stripepoch $cversion)."_*.changes";
1257 my @cs = glob "../$pat";
1258 fail "failed to find unique changes file".
1259 " (looked for $pat in .., or $multi);".
1260 " perhaps you need to use dgit -C"
1262 ($changesfile) = @cs;
1266 responder_send_file('changes',$changesfile);
1268 my $tfn = sub { ".git/dgit/tag$_[0]"; };
1271 ? responder_receive_files('signed-tag', $tfn->('.signed.tmp'))
1272 : push_mktag($head,$clogp,$tag,
1274 $changesfile,$changesfile,
1277 my $tag_obj_hash = cmdoutput @git, qw(hash-object -w -t tag), $tagobjfn;
1278 runcmd_ordryrun @git, qw(verify-tag), $tag_obj_hash;
1279 runcmd_ordryrun_local @git, qw(update-ref), "refs/tags/$tag", $tag_obj_hash;
1280 runcmd_ordryrun @git, qw(tag -v --), $tag;
1282 if (!check_for_git()) {
1283 create_remote_git_repo();
1285 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
1286 runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD';
1288 if (!$we_are_responder) {
1290 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
1292 progress "[new .dsc left in $dscfn.tmp]";
1296 if ($we_are_responder) {
1297 my $dryrunsuffix = act_local() ? "" : ".tmp";
1298 responder_receive_files('signed-dsc-changes',
1299 "../$dscfn$dryrunsuffix",
1300 "$changesfile$dryrunsuffix");
1302 sign_changes $changesfile;
1305 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
1306 my $host = access_cfg('upload-host','RETURN-UNDEF');
1307 my @hostarg = defined($host) ? ($host,) : ();
1308 runcmd_ordryrun @dput, @hostarg, $changesfile;
1309 printdone "pushed and uploaded $cversion";
1311 responder_send_command("complete");
1317 badusage "-p is not allowed with clone; specify as argument instead"
1318 if defined $package;
1321 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
1322 ($package,$isuite) = @ARGV;
1323 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
1324 ($package,$dstdir) = @ARGV;
1325 } elsif (@ARGV==3) {
1326 ($package,$isuite,$dstdir) = @ARGV;
1328 badusage "incorrect arguments to dgit clone";
1330 $dstdir ||= "$package";
1334 sub branchsuite () {
1335 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
1336 if ($branch =~ m#$lbranch_re#o) {
1343 sub fetchpullargs () {
1344 if (!defined $package) {
1345 my $sourcep = parsecontrol('debian/control','debian/control');
1346 $package = getfield $sourcep, 'Source';
1349 # $isuite = branchsuite(); # this doesn't work because dak hates canons
1351 my $clogp = parsechangelog();
1352 $isuite = getfield $clogp, 'Distribution';
1354 canonicalise_suite();
1355 progress "fetching from suite $csuite";
1356 } elsif (@ARGV==1) {
1358 canonicalise_suite();
1360 badusage "incorrect arguments to dgit fetch or dgit pull";
1378 badusage "-p is not allowed with dgit push" if defined $package;
1380 my $clogp = parsechangelog();
1381 $package = getfield $clogp, 'Source';
1384 } elsif (@ARGV==1) {
1385 ($specsuite) = (@ARGV);
1387 badusage "incorrect arguments to dgit push";
1389 $isuite = getfield $clogp, 'Distribution';
1391 local ($package) = $existing_package; # this is a hack
1392 canonicalise_suite();
1394 if (defined $specsuite && $specsuite ne $isuite) {
1395 canonicalise_suite();
1396 $csuite eq $specsuite or
1397 fail "dgit push: changelog specifies $isuite ($csuite)".
1398 " but command line specifies $specsuite";
1400 if (check_for_git()) {
1403 if (fetch_from_archive()) {
1404 is_fast_fwd(lrref(), 'HEAD') or
1405 fail "dgit push: HEAD is not a descendant".
1406 " of the archive's version.\n".
1407 "$us: To overwrite it, use git-merge -s ours ".lrref().".";
1410 fail "package appears to be new in this suite;".
1411 " if this is intentional, use --new";
1416 #---------- remote commands' implementation ----------
1418 sub cmd_remote_push_responder {
1419 my ($nrargs) = shift @ARGV;
1420 my (@rargs) = @ARGV[0..$nrargs-1];
1421 @ARGV = @ARGV[$nrargs..$#ARGV];
1426 $we_are_responder = 1;
1428 responder_send_command("dgit-remote-push-ready");
1436 return unless defined $i_tmp;
1437 return if defined $initiator_tempdir;
1439 eval { rmtree $i_tmp; };
1443 my ($base,$selector,@args) = @_;
1444 $selector =~ s/\-/_/g;
1445 { no strict qw(refs); &{"${base}_${selector}"}(@args); }
1451 if ($host =~ m/^((?:[^][]|\[[^][]*\])*)\:/) {
1461 push @rdgit, @ropts;
1462 push @rdgit, qw(remote-push-responder), (scalar @rargs), @rargs;
1464 my @cmd = (@ssh, $host, shellquote @rdgit);
1465 printcmd \*DEBUG,$debugprefix."+",@cmd;
1467 if (defined $initiator_tempdir) {
1468 rmtree $initiator_tempdir;
1469 mkdir $initiator_tempdir, 0700 or die "$initiator_tempdir: $!";
1470 $i_tmp = $initiator_tempdir;
1474 my $pid = open2(\*RO, \*RI, @cmd);
1476 initiator_expect { m/^dgit-remote-push-ready/ };
1478 my ($icmd,$iargs) = initiator_expect {
1479 m/^(\S+)(?: (.*))?$/;
1482 i_method "i_resp", $icmd, $iargs;
1489 sub i_resp_progress ($) {
1491 my $msg = protocol_read_bytes \*RO, $rhs;
1495 sub i_resp_complete {
1500 sub i_resp_file ($) {
1502 my $localname = i_method "i_localname", $keyword;
1503 my $localpath = "$i_tmp/$localname";
1504 stat $localpath and badproto \*RO, "file $keyword ($localpath) twice";
1505 protocol_receive_file \*RO, $localpath;
1511 $_[0] =~ m/^(\S+) (.*)$/;
1517 sub i_resp_want ($) {
1519 die "$keyword ?" if $i_wanted{$keyword}++;
1520 my @localpaths = i_method "i_want", $keyword;
1521 printdebug "]] $keyword @localpaths\n";
1522 foreach my $localpath (@localpaths) {
1523 protocol_send_file \*RI, $localpath;
1525 print RI "end-files\n" or die $!;
1528 our ($i_clogp, $i_version, $i_tag, $i_dscfn);
1530 sub i_localname_parsed_changelog { return "remote-changelog.822"; }
1531 sub i_localname_changes { return "remote.changes"; }
1532 sub i_localname_dsc {
1533 ($i_clogp, $i_version, $i_tag, $i_dscfn) =
1534 push_parse_changelog "$i_tmp/remote-changelog.822";
1535 die if $i_dscfn =~ m#/|^\W#;
1539 sub i_want_signed_tag {
1540 defined $i_param{'head'} && defined $i_dscfn
1541 or badproto \*RO, "sequencing error";
1542 my $head = $i_param{'head'};
1543 die if $head =~ m/[^0-9a-f]/ || $head !~ m/^../;
1545 push_parse_dsc $i_dscfn, 'remote dsc',
1547 push_mktag $head, $i_clogp, $i_tag,
1549 'remote.changes', 'remote changes',
1555 sub i_want_signed_dsc_changes {
1556 rename "$i_dscfn.tmp","$i_dscfn" or die "$i_dscfn $!";
1557 sign_changes 'remote.changes';
1558 return ($i_dscfn, 'remote.changes');
1561 #---------- building etc. ----------
1567 our $fakeeditorenv = 'DGIT_FAKE_EDITOR_QUILT';
1569 sub build_maybe_quilt_fixup () {
1570 if (!open F, "debian/source/format") {
1571 die $! unless $!==&ENOENT;
1575 F->error and die $!;
1577 return unless madformat($_);
1579 my $clogp = parsechangelog();
1580 my $version = getfield $clogp, 'Version';
1581 my $author = getfield $clogp, 'Maintainer';
1582 my $headref = rev_parse('HEAD');
1585 my $patchname = "auto-$version-$headref-$time";
1586 my $msg = cmdoutput @git, qw(log), "-n$ncommits";
1588 my $descfn = ".git/dgit/quilt-description.tmp";
1589 open O, '>', $descfn or die "$descfn: $!";
1591 $msg =~ s/^\s+$/ ./mg;
1592 print O <<END or die $!;
1593 Description: Automatically generated patch ($clogp->{Version})
1594 Last (up to) $ncommits git changes, FYI:
1604 local $ENV{'EDITOR'} = cmdoutput qw(realpath --), $0;
1605 local $ENV{'VISUAL'} = $ENV{'EDITOR'};
1606 local $ENV{$fakeeditorenv} = cmdoutput qw(realpath --), $descfn;
1607 runcmd_ordryrun_local @dpkgsource, qw(--commit .), $patchname;
1610 if (!open P, '>>', ".pc/applied-patches") {
1611 $!==&ENOENT or die $!;
1616 commit_quilty_patch();
1619 sub quilt_fixup_editor () {
1620 my $descfn = $ENV{$fakeeditorenv};
1621 my $editing = $ARGV[$#ARGV];
1622 open I1, '<', $descfn or die "$descfn: $!";
1623 open I2, '<', $editing or die "$editing: $!";
1624 unlink $editing or die "$editing: $!";
1625 open O, '>', $editing or die "$editing: $!";
1626 while (<I1>) { print O or die $!; } I1->error and die $!;
1629 $copying ||= m/^\-\-\- /;
1630 next unless $copying;
1633 I2->error and die $!;
1639 badusage "-p is not allowed when building" if defined $package;
1641 my $clogp = parsechangelog();
1642 $isuite = getfield $clogp, 'Distribution';
1643 $package = getfield $clogp, 'Source';
1644 $version = getfield $clogp, 'Version';
1645 build_maybe_quilt_fixup();
1649 badusage "dgit build implies --clean=dpkg-source"
1650 if $cleanmode ne 'dpkg-source';
1652 runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV;
1653 printdone "build successful\n";
1657 badusage "dgit git-build implies --clean=dpkg-source"
1658 if $cleanmode ne 'dpkg-source';
1661 (qw(git-buildpackage -us -uc --git-no-sign-tags),
1662 "--git-builder=@dpkgbuildpackage");
1663 unless (grep { m/^--git-debian-branch|^--git-ignore-branch/ } @ARGV) {
1664 canonicalise_suite();
1665 push @cmd, "--git-debian-branch=".lbranch();
1667 push @cmd, changesopts();
1668 runcmd_ordryrun_local @cmd, @ARGV;
1669 printdone "build successful\n";
1674 $sourcechanges = "${package}_".(stripepoch $version)."_source.changes";
1675 $dscfn = dscfn($version);
1676 if ($cleanmode eq 'dpkg-source') {
1677 runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S)),
1680 if ($cleanmode eq 'git') {
1681 runcmd_ordryrun_local @git, qw(clean -xdf);
1682 } elsif ($cleanmode eq 'none') {
1686 my $pwd = cmdoutput qw(env - pwd);
1687 my $leafdir = basename $pwd;
1689 runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
1691 runcmd_ordryrun_local qw(sh -ec),
1692 'exec >$1; shift; exec "$@"','x',
1693 "../$sourcechanges",
1694 @dpkggenchanges, qw(-S), changesopts();
1698 sub cmd_build_source {
1699 badusage "build-source takes no additional arguments" if @ARGV;
1701 printdone "source built, results in $dscfn and $sourcechanges";
1707 my $pat = "${package}_".(stripepoch $version)."_*.changes";
1709 stat $dscfn or fail "$dscfn (in parent directory): $!";
1710 stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
1711 foreach my $cf (glob $pat) {
1712 next if $cf eq $sourcechanges;
1713 unlink $cf or fail "remove $cf: $!";
1716 runcmd_ordryrun_local @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
1717 runcmd_ordryrun_local @mergechanges, glob $pat;
1718 my $multichanges = "${package}_".(stripepoch $version)."_multi.changes";
1720 stat $multichanges or fail "$multichanges: $!";
1722 printdone "build successful, results in $multichanges\n" or die $!;
1725 sub cmd_quilt_fixup {
1726 badusage "incorrect arguments to dgit quilt-fixup" if @ARGV;
1727 my $clogp = parsechangelog();
1728 $version = getfield $clogp, 'Version';
1729 build_maybe_quilt_fixup();
1732 #---------- argument parsing and main program ----------
1735 print "dgit version $our_version\n" or die $!;
1742 if (defined $ENV{'DGIT_SSH'}) {
1743 @ssh = string_to_ssh $ENV{'DGIT_SSH'};
1744 } elsif (defined $ENV{'GIT_SSH'}) {
1745 @ssh = ($ENV{'GIT_SSH'});
1749 last unless $ARGV[0] =~ m/^-/;
1753 if (m/^--dry-run$/) {
1756 } elsif (m/^--damp-run$/) {
1759 } elsif (m/^--no-sign$/) {
1762 } elsif (m/^--help$/) {
1764 } elsif (m/^--version$/) {
1766 } elsif (m/^--new$/) {
1769 } elsif (m/^--(\w+)=(.*)/s &&
1770 ($om = $opts_opt_map{$1}) &&
1774 } elsif (m/^--(\w+):(.*)/s &&
1775 !$opts_opt_cmdonly{$1} &&
1776 ($om = $opts_opt_map{$1})) {
1779 } elsif (m/^--existing-package=(.*)/s) {
1781 $existing_package = $1;
1782 } elsif (m/^--initiator-tempdir=(.*)/s) {
1783 $initiator_tempdir = $1;
1784 $initiator_tempdir =~ m#^/# or
1785 badusage "--initiator-tempdir must be used specify an".
1786 " absolute, not relative, directory."
1787 } elsif (m/^--distro=(.*)/s) {
1790 } elsif (m/^--clean=(dpkg-source|git|none)$/s) {
1793 } elsif (m/^--clean=(.*)$/s) {
1794 badusage "unknown cleaning mode \`$1'";
1795 } elsif (m/^--ignore-dirty$/s) {
1798 } elsif (m/^--no-quilt-fixup$/s) {
1802 badusage "unknown long option \`$_'";
1809 } elsif (s/^-L/-/) {
1812 } elsif (s/^-h/-/) {
1814 } elsif (s/^-D/-/) {
1816 open DEBUG, ">&STDERR" or die $!;
1819 } elsif (s/^-N/-/) {
1822 } elsif (m/^-[vm]/) {
1824 push @changesopts, $_;
1826 } elsif (s/^-c(.*=.*)//s) {
1828 push @git, '-c', $1;
1829 } elsif (s/^-d(.*)//s) {
1832 } elsif (s/^-C(.*)//s) {
1835 } elsif (s/^-k(.*)//s) {
1837 } elsif (s/^-wn//s) {
1839 $cleanmode = 'none';
1840 } elsif (s/^-wg//s) {
1843 } elsif (s/^-wd//s) {
1845 $cleanmode = 'dpkg-source';
1847 badusage "unknown short option \`$_'";
1854 if ($ENV{$fakeeditorenv}) {
1855 quilt_fixup_editor();
1858 delete $ENV{'DGET_UNPACK'};
1861 print STDERR "DRY RUN ONLY\n" if $dryrun_level > 1;
1862 print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n"
1863 if $dryrun_level == 1;
1865 print STDERR $helpmsg or die $!;
1868 my $cmd = shift @ARGV;
1870 { no strict qw(refs); &{"cmd_$cmd"}(); }