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 $changes_since_version;
49 our $we_are_responder;
50 our $initiator_tempdir;
52 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
55 our (@dget) = qw(dget);
56 our (@dput) = qw(dput);
57 our (@debsign) = qw(debsign);
59 our (@sbuild) = qw(sbuild -A);
61 our (@dgit) = qw(dgit);
62 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
63 our (@dpkgsource) = qw(dpkg-source -i\.git/ -I.git);
64 our (@dpkggenchanges) = qw(dpkg-genchanges);
65 our (@mergechanges) = qw(mergechanges -f);
66 our (@changesopts) = ('');
68 our %opts_opt_map = ('dget' => \@dget,
70 'debsign' => \@debsign,
75 'dpkg-source' => \@dpkgsource,
76 'dpkg-buildpackage' => \@dpkgbuildpackage,
77 'dpkg-genchanges' => \@dpkggenchanges,
78 'ch' => \@changesopts,
79 'mergechanges' => \@mergechanges);
81 our %opts_opt_cmdonly = ('gpg' => 1);
86 open DEBUG, ">/dev/null" or die $!;
90 our $remotename = 'dgit';
91 our @ourdscfield = qw(Dgit Vcs-Dgit-Master);
92 our $branchprefix = 'dgit';
95 sub lbranch () { return "$branchprefix/$csuite"; }
96 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
97 sub lref () { return "refs/heads/".lbranch(); }
98 sub lrref () { return "refs/remotes/$remotename/$branchprefix/$csuite"; }
99 sub rrref () { return "refs/$branchprefix/$csuite"; }
114 return "${package}_".(stripepoch $vsn).".dsc";
118 our $debugprefix = '';
120 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
123 die $us.($we_are_responder ? " (build host)" : "").": @_\n";
126 sub badcfg { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
128 sub no_such_package () {
129 print STDERR "$us: package $package does not exist in suite $isuite\n";
135 return "+".rrref().":".lrref();
140 printdebug "CD $newdir\n";
141 chdir $newdir or die "chdir: $newdir: $!";
144 #---------- remote protocol support, common ----------
146 # remote push initiator/responder protocol:
147 # < dgit-remote-push-ready [optional extra info ignored by old initiators]
149 # > file parsed-changelog
150 # [indicates that output of dpkg-parsechangelog follows]
151 # > data-block NBYTES
152 # > [NBYTES bytes of data (no newline)]
153 # [maybe some more blocks]
165 # [indicates that signed tag is wanted]
166 # < data-block NBYTES
167 # < [NBYTES bytes of data (no newline)]
168 # [maybe some more blocks]
172 # > want signed-dsc-changes
173 # < data-block NBYTES [transfer of signed dsc]
175 # < data-block NBYTES [transfer of signed changes]
183 fail "connection lost: $!" if $fh->error;
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 $!;
211 print $fh $d or die $!;
213 PF->error and die "$ourfn $!";
214 print $fh "data-end\n" or die $!;
218 sub protocol_read_bytes ($$) {
219 my ($fh, $nbytes) = @_;
220 $nbytes =~ m/^[1-9]\d{0,5}$/ or badproto \*RO, "bad byte count";
222 my $got = read $fh, $d, $nbytes;
223 $got==$nbytes or badproto $fh, "eof during data block";
227 sub protocol_receive_file ($$) {
228 my ($fh, $ourfn) = @_;
229 printdebug "() $ourfn\n";
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 $!;
244 #---------- remote protocol support, responder ----------
246 sub responder_send_command ($) {
248 return unless $we_are_responder;
249 # called even without $we_are_responder
250 printdebug ">> $command\n";
251 print PO $command, "\n" or die $!;
254 sub responder_send_file ($$) {
255 my ($keyword, $ourfn) = @_;
256 return unless $we_are_responder;
257 printdebug "]] $keyword $ourfn\n";
258 responder_send_command "file $keyword";
259 protocol_send_file \*PO, $ourfn;
262 sub responder_receive_files ($@) {
263 my ($keyword, @ourfns) = @_;
264 die unless $we_are_responder;
265 printdebug "[[ $keyword @ourfns\n";
266 responder_send_command "want $keyword";
267 foreach my $fn (@ourfns) {
268 protocol_receive_file \*PI, $fn;
271 protocol_expect { m/^files-end$/ } \*PI;
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 $!;
287 print PO $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 (m{[^-=_./0-9a-z]}i) {
322 return join ' ', @out;
327 my $intro = shift @_;
328 print $fh $intro," " or die $!;
329 print $fh shellquote @_ or die $!;
330 print $fh "\n" or die $!;
334 { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; };
336 fail "failed to fork/exec: $!";
337 } elsif (!($? & 0xff)) {
338 fail "subprocess failed with error exit status ".($?>>8);
340 fail "subprocess crashed (wait status $?)";
342 fail "subprocess produced invalid output";
347 printcmd(\*DEBUG,$debugprefix."+",@_) if $debug>0;
349 failedcmd @_ if system @_;
352 sub act_local () { return $dryrun_level <= 1; }
353 sub act_scary () { return !$dryrun_level; }
356 if (!$dryrun_level) {
357 progress "dgit ok: @_";
359 progress "would be ok: @_ (but dry run only)";
363 sub cmdoutput_errok {
364 die Dumper(\@_)." ?" if grep { !defined } @_;
365 printcmd(\*DEBUG,$debugprefix."|",@_) if $debug>0;
366 open P, "-|", @_ or die $!;
369 { local $/ = undef; $d = <P>; }
371 if (!close P) { printdebug "=>!$?\n" if $debug>0; return undef; }
374 printdebug "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
379 my $d = cmdoutput_errok @_;
380 defined $d or failedcmd @_;
385 printcmd(\*STDERR,$debugprefix."#",@_);
388 sub runcmd_ordryrun {
396 sub runcmd_ordryrun_local {
405 my ($first_shell, @cmd) = @_;
406 return qw(sh -ec), $first_shell.'; exec "$@"', 'x', @cmd;
409 our $helpmsg = <<END;
411 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
412 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
413 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
414 dgit [dgit-opts] push [dgit-opts] [suite]
415 dgit [dgit-opts] rpush build-host:build-dir ...
416 important dgit options:
417 -k<keyid> sign tag and package with <keyid> instead of default
418 --dry-run -n do not change anything, but go through the motions
419 --damp-run -L like --dry-run but make local changes, without signing
420 --new -N allow introducing a new package
421 --debug -D increase debug level
422 -c<name>=<value> set git config option (used directly by dgit too)
425 our $later_warning_msg = <<END;
426 Perhaps the upload is stuck in incoming. Using the version from git.
430 print STDERR "$us: @_\n", $helpmsg or die $!;
435 @ARGV or badusage "too few arguments";
436 return scalar shift @ARGV;
440 print $helpmsg or die $!;
444 our %defcfg = ('dgit.default.distro' => 'debian',
445 'dgit.default.username' => '',
446 'dgit.default.archive-query-default-component' => 'main',
447 'dgit.default.ssh' => 'ssh',
448 'dgit-distro.debian.git-host' => 'git.debian.org',
449 'dgit-distro.debian.git-proto' => 'git+ssh://',
450 'dgit-distro.debian.git-path' => '/git/dgit-repos/repos',
451 'dgit-distro.debian.git-check' => 'ssh-cmd',
452 'dgit-distro.debian.git-create' => 'ssh-cmd',
453 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
454 'dgit-distro.debian.sshdakls-dir' =>
455 '/srv/ftp-master.debian.org/ftp/dists',
456 'dgit-distro.debian.upload-host' => 'ftp-master', # for dput
457 'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/');
461 return undef if $c =~ /RETURN-UNDEF/;
462 my @cmd = (@git, qw(config --), $c);
465 local ($debug) = $debug-1;
466 $v = cmdoutput_errok @cmd;
473 my $dv = $defcfg{$c};
474 return $dv if defined $dv;
476 badcfg "need value for one of: @_";
479 sub access_distro () {
480 return cfg("dgit-suite.$isuite.distro",
481 "dgit.default.distro");
486 my $distro = $idistro || access_distro();
487 my $value = cfg(map { ("dgit-distro.$distro.$_",
488 "dgit.default.$_") } @keys);
492 sub string_to_ssh ($) {
494 if ($spec =~ m/\s/) {
495 return qw(sh -ec), 'exec '.$spec.' "$@"', 'x';
501 sub access_cfg_ssh () {
502 my $gitssh = access_cfg('ssh', 'RETURN-UNDEF');
503 if (!defined $gitssh) {
506 return string_to_ssh $gitssh;
510 sub access_someuserhost ($) {
512 my $user = access_cfg("$some-user",'username');
513 my $host = access_cfg("$some-host");
514 return length($user) ? "$user\@$host" : $host;
517 sub access_gituserhost () {
518 return access_someuserhost('git');
521 sub access_giturl () {
522 my $url = access_cfg('git-url','RETURN-UNDEF');
525 access_cfg('git-proto').
526 access_gituserhost().
527 access_cfg('git-path');
529 return "$url/$package.git";
532 sub parsecontrolfh ($$@) {
533 my ($fh, $desc, @opts) = @_;
534 my %opts = ('name' => $desc, @opts);
535 my $c = Dpkg::Control::Hash->new(%opts);
536 $c->parse($fh) or die "parsing of $desc failed";
541 my ($file, $desc) = @_;
542 my $fh = new IO::Handle;
543 open $fh, '<', $file or die "$file: $!";
544 my $c = parsecontrolfh($fh,$desc);
545 $fh->error and die $!;
551 my ($dctrl,$field) = @_;
552 my $v = $dctrl->{$field};
553 return $v if defined $v;
554 fail "missing field $field in ".$v->get_option('name');
558 my $c = Dpkg::Control::Hash->new();
559 my $p = new IO::Handle;
560 my @cmd = (qw(dpkg-parsechangelog), @_);
561 open $p, '-|', @cmd or die $!;
563 $?=0; $!=0; close $p or failedcmd @cmd;
569 sub archive_query ($) {
571 my $query = access_cfg('archive-query','RETURN-UNDEF');
572 if (!defined $query) {
573 my $distro = access_distro();
574 if ($distro eq 'debian') {
575 $query = "sshdakls:".
576 access_someuserhost('sshdakls').':'.
577 access_cfg('sshdakls-dir');
579 $query = "madison:$distro";
582 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
585 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
588 sub pool_dsc_subpath ($$) {
589 my ($vsn,$component) = @_; # $package is implict arg
590 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
591 return "/pool/$component/$prefix/$package/".dscfn($vsn);
594 sub archive_query_madison ($$) {
595 my ($proto,$data) = @_;
596 die unless $proto eq 'madison';
597 $rmad{$package} ||= cmdoutput
598 qw(rmadison -asource),"-s$isuite","-u$data",$package;
599 my $rmad = $rmad{$package};
600 return madison_parse($rmad);
603 sub archive_query_sshdakls ($$) {
604 my ($proto,$data) = @_;
605 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
606 my $dakls = cmdoutput
607 access_cfg_ssh, $data, qw(dak ls -asource),"-s$isuite",$package;
608 return madison_parse($dakls);
611 sub canonicalise_suite_sshdakls ($$) {
612 my ($proto,$data) = @_;
613 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
617 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
618 " if test -d $isuite; then echo $isuite; exit 0; fi;".
620 my $dakls = cmdoutput @cmd;
621 failedcmd @cmd unless $dakls =~ m/^\w/;
625 sub madison_parse ($) {
628 foreach my $l (split /\n/, $rmad) {
629 $l =~ m{^ \s*( [^ \t|]+ )\s* \|
630 \s*( [^ \t|]+ )\s* \|
631 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
632 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
633 $1 eq $package or die "$rmad $package ?";
640 $component = access_cfg('archive-query-default-component');
642 $5 eq 'source' or die "$rmad ?";
643 push @out, [$vsn,pool_dsc_subpath($vsn,$component),$newsuite];
645 return sort { -version_compare_string($a->[0],$b->[0]); } @out;
648 sub canonicalise_suite_madison ($$) {
649 my @r = archive_query_madison($_[0],$_[1]);
651 "unable to canonicalise suite using package $package".
652 " which does not appear to exist in suite $isuite;".
653 " --existing-package may help";
657 sub canonicalise_suite () {
658 return if defined $csuite;
659 fail "cannot operate on $isuite suite" if $isuite eq 'UNRELEASED';
660 $csuite = archive_query('canonicalise_suite');
661 if ($isuite ne $csuite) {
662 # madison canonicalises for us
663 progress "canonical suite name for $isuite is $csuite";
667 sub get_archive_dsc () {
668 canonicalise_suite();
669 my @vsns = archive_query('archive_query');
670 foreach my $vinfo (@vsns) {
671 my ($vsn,$subpath) = @$vinfo;
672 $dscurl = access_cfg('mirror').$subpath;
673 $dscdata = url_get($dscurl);
675 $skew_warning_vsn = $vsn if !defined $skew_warning_vsn;
678 my $dscfh = new IO::File \$dscdata, '<' or die $!;
679 printdebug Dumper($dscdata) if $debug>1;
680 $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1);
681 printdebug Dumper($dsc) if $debug>1;
682 my $fmt = getfield $dsc, 'Format';
683 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
689 sub check_for_git () {
691 my $how = access_cfg('git-check');
692 if ($how eq 'ssh-cmd') {
694 (access_cfg_ssh, access_gituserhost(),
695 " set -e; cd ".access_cfg('git-path').";".
696 " if test -d $package.git; then echo 1; else echo 0; fi");
697 my $r= cmdoutput @cmd;
698 failedcmd @cmd unless $r =~ m/^[01]$/;
701 badcfg "unknown git-check \`$how'";
705 sub create_remote_git_repo () {
706 my $how = access_cfg('git-create');
707 if ($how eq 'ssh-cmd') {
709 (access_cfg_ssh, access_gituserhost(),
710 "set -e; cd ".access_cfg('git-path').";".
711 " cp -a _template $package.git");
713 badcfg "unknown git-create \`$how'";
717 our ($dsc_hash,$lastpush_hash);
719 our $ud = '.git/dgit/unpack';
727 sub mktree_in_ud_from_only_subdir () {
728 # changes into the subdir
731 $dirs[0] =~ m#^([^/]+)/\.$# or die;
734 fail "source package contains .git directory" if stat '.git';
735 die $! unless $!==&ENOENT;
736 runcmd qw(git init -q);
737 rmtree('.git/objects');
738 symlink '../../../../objects','.git/objects' or die $!;
739 runcmd @git, qw(add -Af);
740 my $tree = cmdoutput @git, qw(write-tree);
741 $tree =~ m/^\w+$/ or die "$tree ?";
745 sub dsc_files_info () {
746 foreach my $csumi (['Checksums-Sha256','Digest::SHA', 'new(256)'],
747 ['Checksums-Sha1', 'Digest::SHA', 'new(1)'],
748 ['Files', 'Digest::MD5', 'new()']) {
749 my ($fname, $module, $method) = @$csumi;
750 my $field = $dsc->{$fname};
751 next unless defined $field;
752 eval "use $module; 1;" or die $@;
754 foreach (split /\n/, $field) {
756 m/^(\w+) (\d+) (\S+)$/ or
757 fail "could not parse .dsc $fname line \`$_'";
758 my $digester = eval "$module"."->$method;" or die $@;
763 Digester => $digester,
768 fail "missing any supported Checksums-* or Files field in ".
769 $dsc->get_option('name');
773 map { $_->{Filename} } dsc_files_info();
776 sub is_orig_file ($) {
778 m/\.orig(?:-\w+)?\.tar\.\w+$/;
781 sub make_commit ($) {
783 return cmdoutput @git, qw(hash-object -w -t commit), $file;
786 sub clogp_authline ($) {
788 my $author = getfield $clogp, 'Maintainer';
789 $author =~ s#,.*##ms;
790 my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
791 my $authline = "$author $date";
792 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
793 fail "unexpected commit author line format \`$authline'".
794 " (was generated from changelog Maintainer field)";
798 sub generate_commit_from_dsc () {
802 foreach my $f (dsc_files()) {
803 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
805 link "../../../$f", $f
809 runcmd @dget, qw(--), $dscurl;
810 foreach my $f (grep { is_orig_file($_) } @files) {
811 link $f, "../../../../$f"
815 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
816 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
817 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
818 my $authline = clogp_authline $clogp;
819 my $changes = getfield $clogp, 'Changes';
820 open C, ">../commit.tmp" or die $!;
821 print C <<END or die $!;
828 # imported from the archive
831 my $outputhash = make_commit qw(../commit.tmp);
832 my $cversion = getfield $clogp, 'Version';
833 progress "synthesised git commit from .dsc $cversion";
834 if ($lastpush_hash) {
835 runcmd @git, qw(reset --hard), $lastpush_hash;
836 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
837 my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
838 my $oversion = getfield $oldclogp, 'Version';
840 version_compare_string($oversion, $cversion);
842 # git upload/ is earlier vsn than archive, use archive
843 open C, ">../commit2.tmp" or die $!;
844 print C <<END or die $!;
846 parent $lastpush_hash
851 Record $package ($cversion) in archive suite $csuite
853 $outputhash = make_commit qw(../commit2.tmp);
854 } elsif ($vcmp > 0) {
855 print STDERR <<END or die $!;
857 Version actually in archive: $cversion (older)
858 Last allegedly pushed/uploaded: $oversion (newer or same)
861 $outputhash = $lastpush_hash;
863 $outputhash = $lastpush_hash;
866 changedir '../../../..';
867 runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
868 'DGIT_ARCHIVE', $outputhash;
869 cmdoutput @git, qw(log -n2), $outputhash;
870 # ... gives git a chance to complain if our commit is malformed
875 sub ensure_we_have_orig () {
876 foreach my $fi (dsc_files_info()) {
877 my $f = $fi->{Filename};
878 next unless is_orig_file($f);
879 if (open F, "<", "../$f") {
880 $fi->{Digester}->reset();
881 $fi->{Digester}->addfile(*F);
883 my $got = $fi->{Digester}->hexdigest();
884 $got eq $fi->{Hash} or
885 fail "existing file $f has hash $got but .dsc".
886 " demands hash $fi->{Hash}".
887 " (perhaps you should delete this file?)";
888 progress "using existing $f";
891 die "$f $!" unless $!==&ENOENT;
893 my $origurl = $dscurl;
894 $origurl =~ s{/[^/]+$}{};
896 die "$f ?" unless $f =~ m/^${package}_/;
897 die "$f ?" if $f =~ m#/#;
898 runcmd_ordryrun_local shell_cmd 'cd ..', @dget,'--',$origurl;
903 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
906 sub is_fast_fwd ($$) {
907 my ($ancestor,$child) = @_;
908 my @cmd = (@git, qw(merge-base), $ancestor, $child);
909 my $mb = cmdoutput_errok @cmd;
911 return rev_parse($mb) eq rev_parse($ancestor);
913 $?==256 or failedcmd @cmd;
918 sub git_fetch_us () {
919 runcmd_ordryrun_local @git, qw(fetch),access_giturl(),fetchspec();
922 sub fetch_from_archive () {
923 # ensures that lrref() is what is actually in the archive,
928 foreach my $field (@ourdscfield) {
929 $dsc_hash = $dsc->{$field};
930 last if defined $dsc_hash;
932 if (defined $dsc_hash) {
933 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
935 progress "last upload to archive specified git hash";
937 progress "last upload to archive has NO git hash";
940 progress "no version available from the archive";
943 my $lrref_fn = ".git/".lrref();
944 if (open H, $lrref_fn) {
945 $lastpush_hash = <H>;
946 chomp $lastpush_hash;
947 die "$lrref_fn $lastpush_hash ?" unless $lastpush_hash =~ m/^\w+$/;
948 } elsif ($! == &ENOENT) {
953 printdebug "previous reference hash=$lastpush_hash\n";
955 if (defined $dsc_hash) {
956 fail "missing git history even though dsc has hash -".
957 " could not find commit $dsc_hash".
958 " (should be in ".access_giturl()."#".rrref().")"
959 unless $lastpush_hash;
961 ensure_we_have_orig();
962 if ($dsc_hash eq $lastpush_hash) {
963 } elsif (is_fast_fwd($dsc_hash,$lastpush_hash)) {
964 print STDERR <<END or die $!;
966 Git commit in archive is behind the last version allegedly pushed/uploaded.
967 Commit referred to by archive: $dsc_hash
968 Last allegedly pushed/uploaded: $lastpush_hash
971 $hash = $lastpush_hash;
973 fail "archive's .dsc refers to ".$dsc_hash.
974 " but this is an ancestor of ".$lastpush_hash;
977 $hash = generate_commit_from_dsc();
978 } elsif ($lastpush_hash) {
979 # only in git, not in the archive yet
980 $hash = $lastpush_hash;
981 print STDERR <<END or die $!;
983 Package not found in the archive, but has allegedly been pushed using dgit.
987 printdebug "nothing found!\n";
988 if (defined $skew_warning_vsn) {
989 print STDERR <<END or die $!;
991 Warning: relevant archive skew detected.
992 Archive allegedly contains $skew_warning_vsn
993 But we were not able to obtain any version from the archive or git.
999 printdebug "current hash=$hash\n";
1000 if ($lastpush_hash) {
1001 fail "not fast forward on last upload branch!".
1002 " (archive's version left in DGIT_ARCHIVE)"
1003 unless is_fast_fwd($lastpush_hash, $hash);
1005 if (defined $skew_warning_vsn) {
1007 printdebug "SKEW CHECK WANT $skew_warning_vsn\n";
1008 my $clogf = ".git/dgit/changelog.tmp";
1009 runcmd shell_cmd "exec >$clogf",
1010 @git, qw(cat-file blob), "$hash:debian/changelog";
1011 my $gotclogp = parsechangelog("-l$clogf");
1012 my $got_vsn = getfield $gotclogp, 'Version';
1013 printdebug "SKEW CHECK GOT $got_vsn\n";
1014 if (version_compare_string($got_vsn, $skew_warning_vsn) < 0) {
1015 print STDERR <<END or die $!;
1017 Warning: archive skew detected. Using the available version:
1018 Archive allegedly contains $skew_warning_vsn
1019 We were able to obtain only $got_vsn
1024 if ($lastpush_hash ne $hash) {
1025 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
1029 dryrun_report @upd_cmd;
1037 canonicalise_suite();
1038 badusage "dry run makes no sense with clone" unless act_local();
1039 mkdir $dstdir or die "$dstdir $!";
1041 runcmd @git, qw(init -q);
1042 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
1043 open H, "> .git/HEAD" or die $!;
1044 print H "ref: ".lref()."\n" or die $!;
1046 runcmd @git, qw(remote add), 'origin', access_giturl();
1047 if (check_for_git()) {
1048 progress "fetching existing git history";
1050 runcmd_ordryrun_local @git, qw(fetch origin);
1052 progress "starting new git history";
1054 fetch_from_archive() or no_such_package;
1055 runcmd @git, qw(reset --hard), lrref();
1056 printdone "ready for work in $dstdir";
1060 if (check_for_git()) {
1063 fetch_from_archive() or no_such_package();
1064 printdone "fetched into ".lrref();
1069 runcmd_ordryrun_local @git, qw(merge -m),"Merge from $csuite [dgit]",
1071 printdone "fetched to ".lrref()." and merged into HEAD";
1074 sub check_not_dirty () {
1075 return if $ignoredirty;
1076 my @cmd = (@git, qw(diff --quiet HEAD));
1077 printcmd(\*DEBUG,$debugprefix."+",@cmd) if $debug>0;
1078 $!=0; $?=0; system @cmd;
1079 return if !$! && !$?;
1080 if (!$! && $?==256) {
1081 fail "working tree is dirty (does not match HEAD)";
1087 sub commit_quilty_patch () {
1088 my $output = cmdoutput @git, qw(status --porcelain);
1090 foreach my $l (split /\n/, $output) {
1091 next unless $l =~ m/\S/;
1092 if ($l =~ m{^(?:\?\?| M) (.pc|debian/patches)}) {
1097 progress "nothing quilty to commit, ok.";
1100 runcmd_ordryrun_local @git, qw(add), sort keys %adds;
1101 my $m = "Commit Debian 3.0 (quilt) metadata";
1103 runcmd_ordryrun_local @git, qw(commit -m), $m;
1108 return 0 unless $format eq '3.0 (quilt)';
1109 progress "Format \`$format', urgh";
1111 progress "Not doing any fixup of \`$format' due to --no-quilt-fixup";
1117 sub push_parse_changelog ($) {
1120 my $clogp = Dpkg::Control::Hash->new();
1121 $clogp->load($clogpfn) or die;
1123 $package = getfield $clogp, 'Source';
1124 my $cversion = getfield $clogp, 'Version';
1125 my $tag = debiantag($cversion);
1126 runcmd @git, qw(check-ref-format), $tag;
1128 my $dscfn = dscfn($cversion);
1130 return ($clogp, $cversion, $tag, $dscfn);
1133 sub push_parse_dsc ($$$) {
1134 my ($dscfn,$dscfnwhat, $cversion) = @_;
1135 $dsc = parsecontrol($dscfn,$dscfnwhat);
1136 my $dversion = getfield $dsc, 'Version';
1137 my $dscpackage = getfield $dsc, 'Source';
1138 ($dscpackage eq $package && $dversion eq $cversion) or
1139 fail "$dscfn is for $dscpackage $dversion".
1140 " but debian/changelog is for $package $cversion";
1143 sub push_mktag ($$$$$$$) {
1144 my ($head,$clogp,$tag,
1146 $changesfile,$changesfilewhat,
1149 $dsc->{$ourdscfield[0]} = $head;
1150 $dsc->save("$dscfn.tmp") or die $!;
1152 my $changes = parsecontrol($changesfile,$changesfilewhat);
1153 foreach my $field (qw(Source Distribution Version)) {
1154 $changes->{$field} eq $clogp->{$field} or
1155 fail "changes field $field \`$changes->{$field}'".
1156 " does not match changelog \`$clogp->{$field}'";
1159 my $cversion = getfield $clogp, 'Version';
1160 my $clogsuite = getfield $clogp, 'Distribution';
1162 # We make the git tag by hand because (a) that makes it easier
1163 # to control the "tagger" (b) we can do remote signing
1164 my $authline = clogp_authline $clogp;
1165 open TO, '>', $tfn->('.tmp') or die $!;
1166 print TO <<END or die $!;
1172 $package release $cversion for $clogsuite [dgit]
1176 my $tagobjfn = $tfn->('.tmp');
1178 if (!defined $keyid) {
1179 $keyid = access_cfg('keyid','RETURN-UNDEF');
1181 unlink $tfn->('.tmp.asc') or $!==&ENOENT or die $!;
1182 my @sign_cmd = (@gpg, qw(--detach-sign --armor));
1183 push @sign_cmd, qw(-u),$keyid if defined $keyid;
1184 push @sign_cmd, $tfn->('.tmp');
1185 runcmd_ordryrun @sign_cmd;
1187 $tagobjfn = $tfn->('.signed.tmp');
1188 runcmd shell_cmd "exec >$tagobjfn", qw(cat --),
1189 $tfn->('.tmp'), $tfn->('.tmp.asc');
1196 sub sign_changes ($) {
1197 my ($changesfile) = @_;
1199 my @debsign_cmd = @debsign;
1200 push @debsign_cmd, "-k$keyid" if defined $keyid;
1201 push @debsign_cmd, "-p$gpg[0]" if $gpg[0] ne 'gpg';
1202 push @debsign_cmd, $changesfile;
1203 runcmd_ordryrun @debsign_cmd;
1208 printdebug "actually entering push\n";
1211 my $clogpfn = ".git/dgit/changelog.822.tmp";
1212 runcmd shell_cmd "exec >$clogpfn", qw(dpkg-parsechangelog);
1214 responder_send_file('parsed-changelog', $clogpfn);
1216 my ($clogp, $cversion, $tag, $dscfn) =
1217 push_parse_changelog("$clogpfn");
1220 fail "looked for .dsc $dscfn, but $!;".
1221 " maybe you forgot to build";
1223 responder_send_file('dsc', "../$dscfn");
1225 push_parse_dsc("../$dscfn", $dscfn, $cversion);
1227 my $format = getfield $dsc, 'Format';
1228 printdebug "format $format\n";
1229 if (madformat($format)) {
1230 commit_quilty_patch();
1234 progress "checking that $dscfn corresponds to HEAD";
1235 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
1236 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
1237 changedir '../../../..';
1238 my @diffcmd = (@git, qw(diff --exit-code), $tree);
1239 printcmd \*DEBUG,$debugprefix."+",@diffcmd;
1241 if (system @diffcmd) {
1242 if ($! && $?==256) {
1243 fail "$dscfn specifies a different tree to your HEAD commit;".
1244 " perhaps you forgot to build";
1250 #do fast forward check and maybe fake merge
1251 # if (!is_fast_fwd(mainbranch
1252 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
1253 # map { lref($_).":".rref($_) }
1255 my $head = rev_parse('HEAD');
1256 if (!$changesfile) {
1257 my $multi = "../${package}_".(stripepoch $cversion)."_multi.changes";
1258 if (stat "$multi") {
1259 $changesfile = $multi;
1261 $!==&ENOENT or die "$multi: $!";
1262 my $pat = "${package}_".(stripepoch $cversion)."_*.changes";
1263 my @cs = glob "../$pat";
1264 fail "failed to find unique changes file".
1265 " (looked for $pat in .., or $multi);".
1266 " perhaps you need to use dgit -C"
1268 ($changesfile) = @cs;
1272 responder_send_file('changes',$changesfile);
1273 responder_send_command("param head $head");
1275 my $tfn = sub { ".git/dgit/tag$_[0]"; };
1278 if ($we_are_responder) {
1279 $tagobjfn = $tfn->('.signed.tmp');
1280 responder_receive_files('signed-tag', $tagobjfn);
1283 push_mktag($head,$clogp,$tag,
1285 $changesfile,$changesfile,
1289 my $tag_obj_hash = cmdoutput @git, qw(hash-object -w -t tag), $tagobjfn;
1290 runcmd_ordryrun @git, qw(verify-tag), $tag_obj_hash;
1291 runcmd_ordryrun_local @git, qw(update-ref), "refs/tags/$tag", $tag_obj_hash;
1292 runcmd_ordryrun @git, qw(tag -v --), $tag;
1294 if (!check_for_git()) {
1295 create_remote_git_repo();
1297 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
1298 runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD';
1300 if (!$we_are_responder) {
1302 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
1304 progress "[new .dsc left in $dscfn.tmp]";
1308 if ($we_are_responder) {
1309 my $dryrunsuffix = act_local() ? "" : ".tmp";
1310 responder_receive_files('signed-dsc-changes',
1311 "../$dscfn$dryrunsuffix",
1312 "$changesfile$dryrunsuffix");
1314 sign_changes $changesfile;
1317 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
1318 my $host = access_cfg('upload-host','RETURN-UNDEF');
1319 my @hostarg = defined($host) ? ($host,) : ();
1320 runcmd_ordryrun @dput, @hostarg, $changesfile;
1321 printdone "pushed and uploaded $cversion";
1323 responder_send_command("complete");
1329 badusage "-p is not allowed with clone; specify as argument instead"
1330 if defined $package;
1333 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
1334 ($package,$isuite) = @ARGV;
1335 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
1336 ($package,$dstdir) = @ARGV;
1337 } elsif (@ARGV==3) {
1338 ($package,$isuite,$dstdir) = @ARGV;
1340 badusage "incorrect arguments to dgit clone";
1342 $dstdir ||= "$package";
1346 sub branchsuite () {
1347 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
1348 if ($branch =~ m#$lbranch_re#o) {
1355 sub fetchpullargs () {
1356 if (!defined $package) {
1357 my $sourcep = parsecontrol('debian/control','debian/control');
1358 $package = getfield $sourcep, 'Source';
1361 # $isuite = branchsuite(); # this doesn't work because dak hates canons
1363 my $clogp = parsechangelog();
1364 $isuite = getfield $clogp, 'Distribution';
1366 canonicalise_suite();
1367 progress "fetching from suite $csuite";
1368 } elsif (@ARGV==1) {
1370 canonicalise_suite();
1372 badusage "incorrect arguments to dgit fetch or dgit pull";
1390 badusage "-p is not allowed with dgit push" if defined $package;
1392 my $clogp = parsechangelog();
1393 $package = getfield $clogp, 'Source';
1396 } elsif (@ARGV==1) {
1397 ($specsuite) = (@ARGV);
1399 badusage "incorrect arguments to dgit push";
1401 $isuite = getfield $clogp, 'Distribution';
1403 local ($package) = $existing_package; # this is a hack
1404 canonicalise_suite();
1406 if (defined $specsuite && $specsuite ne $isuite) {
1407 canonicalise_suite();
1408 $csuite eq $specsuite or
1409 fail "dgit push: changelog specifies $isuite ($csuite)".
1410 " but command line specifies $specsuite";
1412 if (check_for_git()) {
1415 if (fetch_from_archive()) {
1416 is_fast_fwd(lrref(), 'HEAD') or
1417 fail "dgit push: HEAD is not a descendant".
1418 " of the archive's version.\n".
1419 "$us: To overwrite it, use git-merge -s ours ".lrref().".";
1422 fail "package appears to be new in this suite;".
1423 " if this is intentional, use --new";
1428 #---------- remote commands' implementation ----------
1430 sub cmd_remote_push_responder {
1431 my ($nrargs) = shift @ARGV;
1432 my (@rargs) = @ARGV[0..$nrargs-1];
1433 @ARGV = @ARGV[$nrargs..$#ARGV];
1437 $we_are_responder = 1;
1439 open PI, "<&STDIN" or die $!;
1440 open STDIN, "/dev/null" or die $!;
1441 open PO, ">&STDOUT" or die $!;
1443 open STDOUT, ">&STDERR" or die $!;
1446 responder_send_command("dgit-remote-push-ready");
1458 printdebug "(killing remote child $i_child_pid)\n";
1459 kill 15, $i_child_pid;
1461 if (defined $i_tmp && !defined $initiator_tempdir) {
1463 eval { rmtree $i_tmp; };
1467 END { i_cleanup(); }
1470 my ($base,$selector,@args) = @_;
1471 $selector =~ s/\-/_/g;
1472 { no strict qw(refs); &{"${base}_${selector}"}(@args); }
1478 if ($host =~ m/^((?:[^][]|\[[^][]*\])*)\:/) {
1488 push @rdgit, @ropts;
1489 push @rdgit, qw(remote-push-responder), (scalar @rargs), @rargs;
1491 my @cmd = (@ssh, $host, shellquote @rdgit);
1492 printcmd \*DEBUG,$debugprefix."+",@cmd;
1494 if (defined $initiator_tempdir) {
1495 rmtree $initiator_tempdir;
1496 mkdir $initiator_tempdir, 0700 or die "$initiator_tempdir: $!";
1497 $i_tmp = $initiator_tempdir;
1501 $i_child_pid = open2(\*RO, \*RI, @cmd);
1503 initiator_expect { m/^dgit-remote-push-ready/ };
1505 my ($icmd,$iargs) = initiator_expect {
1506 m/^(\S+)(?: (.*))?$/;
1509 i_method "i_resp", $icmd, $iargs;
1513 sub i_resp_progress ($) {
1515 my $msg = protocol_read_bytes \*RO, $rhs;
1519 sub i_resp_complete {
1520 my $pid = $i_child_pid;
1521 $i_child_pid = undef; # prevents killing some other process with same pid
1522 printdebug "waiting for remote child $pid...\n";
1523 my $got = waitpid $pid, 0;
1524 die $! unless $got == $pid;
1525 die "remote child failed $?" if $?;
1528 printdebug "all done\n";
1532 sub i_resp_file ($) {
1534 my $localname = i_method "i_localname", $keyword;
1535 my $localpath = "$i_tmp/$localname";
1536 stat $localpath and badproto \*RO, "file $keyword ($localpath) twice";
1537 protocol_receive_file \*RO, $localpath;
1538 i_method "i_file", $keyword;
1543 sub i_resp_param ($) {
1544 $_[0] =~ m/^(\S+) (.*)$/ or badproto \*RO, "bad param spec";
1550 sub i_resp_want ($) {
1552 die "$keyword ?" if $i_wanted{$keyword}++;
1553 my @localpaths = i_method "i_want", $keyword;
1554 printdebug "[[ $keyword @localpaths\n";
1555 foreach my $localpath (@localpaths) {
1556 protocol_send_file \*RI, $localpath;
1558 print RI "files-end\n" or die $!;
1561 our ($i_clogp, $i_version, $i_tag, $i_dscfn, $i_changesfn);
1563 sub i_localname_parsed_changelog {
1564 return "remote-changelog.822";
1566 sub i_file_parsed_changelog {
1567 ($i_clogp, $i_version, $i_tag, $i_dscfn) =
1568 push_parse_changelog "$i_tmp/remote-changelog.822";
1569 die if $i_dscfn =~ m#/|^\W#;
1572 sub i_localname_dsc {
1573 defined $i_dscfn or badproto \*RO, "dsc (before parsed-changelog)";
1578 sub i_localname_changes {
1579 defined $i_dscfn or badproto \*RO, "dsc (before parsed-changelog)";
1580 $i_changesfn = $i_dscfn;
1581 $i_changesfn =~ s/\.dsc$/_dgit.changes/ or die;
1582 return $i_changesfn;
1584 sub i_file_changes { }
1586 sub i_want_signed_tag {
1587 printdebug Dumper(\%i_param, $i_dscfn);
1588 defined $i_param{'head'} && defined $i_dscfn && defined $i_clogp
1589 or badproto \*RO, "premature desire for signed-tag";
1590 my $head = $i_param{'head'};
1591 die if $head =~ m/[^0-9a-f]/ || $head !~ m/^../;
1593 push_parse_dsc $i_dscfn, 'remote dsc', $i_version;
1596 push_mktag $head, $i_clogp, $i_tag,
1598 $i_changesfn, 'remote changes',
1599 sub { "tag$_[0]"; };
1604 sub i_want_signed_dsc_changes {
1605 rename "$i_dscfn.tmp","$i_dscfn" or die "$i_dscfn $!";
1606 sign_changes $i_changesfn;
1607 return ($i_dscfn, $i_changesfn);
1610 #---------- building etc. ----------
1616 our $fakeeditorenv = 'DGIT_FAKE_EDITOR_QUILT';
1618 sub build_maybe_quilt_fixup () {
1619 if (!open F, "debian/source/format") {
1620 die $! unless $!==&ENOENT;
1624 F->error and die $!;
1626 return unless madformat($_);
1628 my $clogp = parsechangelog();
1629 my $version = getfield $clogp, 'Version';
1630 my $author = getfield $clogp, 'Maintainer';
1631 my $headref = rev_parse('HEAD');
1634 my $patchname = "auto-$version-$headref-$time";
1635 my $msg = cmdoutput @git, qw(log), "-n$ncommits";
1637 my $descfn = ".git/dgit/quilt-description.tmp";
1638 open O, '>', $descfn or die "$descfn: $!";
1640 $msg =~ s/^\s+$/ ./mg;
1641 print O <<END or die $!;
1642 Description: Automatically generated patch ($clogp->{Version})
1643 Last (up to) $ncommits git changes, FYI:
1653 local $ENV{'EDITOR'} = cmdoutput qw(realpath --), $0;
1654 local $ENV{'VISUAL'} = $ENV{'EDITOR'};
1655 local $ENV{$fakeeditorenv} = cmdoutput qw(realpath --), $descfn;
1656 runcmd_ordryrun_local @dpkgsource, qw(--commit .), $patchname;
1659 if (!open P, '>>', ".pc/applied-patches") {
1660 $!==&ENOENT or die $!;
1665 commit_quilty_patch();
1668 sub quilt_fixup_editor () {
1669 my $descfn = $ENV{$fakeeditorenv};
1670 my $editing = $ARGV[$#ARGV];
1671 open I1, '<', $descfn or die "$descfn: $!";
1672 open I2, '<', $editing or die "$editing: $!";
1673 unlink $editing or die "$editing: $!";
1674 open O, '>', $editing or die "$editing: $!";
1675 while (<I1>) { print O or die $!; } I1->error and die $!;
1678 $copying ||= m/^\-\-\- /;
1679 next unless $copying;
1682 I2->error and die $!;
1688 badusage "-p is not allowed when building" if defined $package;
1690 my $clogp = parsechangelog();
1691 $isuite = getfield $clogp, 'Distribution';
1692 $package = getfield $clogp, 'Source';
1693 $version = getfield $clogp, 'Version';
1694 build_maybe_quilt_fixup();
1697 sub changesopts () {
1698 my @opts =@changesopts[1..$#changesopts];
1699 if (!defined $changes_since_version) {
1700 my @vsns = archive_query('archive_query');
1702 @vsns = map { $_->[0] } @vsns;
1703 @vsns = sort { version_compare_string($a, $b) } @vsns;
1704 $changes_since_version = $vsns[0];
1705 progress "changelog will contain changes since $vsns[0]";
1707 $changes_since_version = '_';
1708 progress "package seems new, not specifying -v<version>";
1711 if ($changes_since_version ne '_') {
1712 unshift @opts, "-v$changes_since_version";
1718 badusage "dgit build implies --clean=dpkg-source"
1719 if $cleanmode ne 'dpkg-source';
1721 runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc), changesopts(), @ARGV;
1722 printdone "build successful\n";
1726 badusage "dgit git-build implies --clean=dpkg-source"
1727 if $cleanmode ne 'dpkg-source';
1730 (qw(git-buildpackage -us -uc --git-no-sign-tags),
1731 "--git-builder=@dpkgbuildpackage");
1732 unless (grep { m/^--git-debian-branch|^--git-ignore-branch/ } @ARGV) {
1733 canonicalise_suite();
1734 push @cmd, "--git-debian-branch=".lbranch();
1736 push @cmd, changesopts();
1737 runcmd_ordryrun_local @cmd, @ARGV;
1738 printdone "build successful\n";
1743 $sourcechanges = "${package}_".(stripepoch $version)."_source.changes";
1744 $dscfn = dscfn($version);
1745 if ($cleanmode eq 'dpkg-source') {
1746 runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S)),
1749 if ($cleanmode eq 'git') {
1750 runcmd_ordryrun_local @git, qw(clean -xdf);
1751 } elsif ($cleanmode eq 'none') {
1755 my $pwd = cmdoutput qw(env - pwd);
1756 my $leafdir = basename $pwd;
1758 runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
1760 runcmd_ordryrun_local qw(sh -ec),
1761 'exec >$1; shift; exec "$@"','x',
1762 "../$sourcechanges",
1763 @dpkggenchanges, qw(-S), changesopts();
1767 sub cmd_build_source {
1768 badusage "build-source takes no additional arguments" if @ARGV;
1770 printdone "source built, results in $dscfn and $sourcechanges";
1776 my $pat = "${package}_".(stripepoch $version)."_*.changes";
1778 stat $dscfn or fail "$dscfn (in parent directory): $!";
1779 stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
1780 foreach my $cf (glob $pat) {
1781 next if $cf eq $sourcechanges;
1782 unlink $cf or fail "remove $cf: $!";
1785 runcmd_ordryrun_local @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
1786 my @changesfiles = glob $pat;
1787 @changesfiles = sort {
1788 ($b =~ m/_source\.changes$/ <=> $a =~ m/_source\.changes$/)
1791 fail "wrong number of different changes files (@changesfiles)"
1792 unless @changesfiles;
1793 runcmd_ordryrun_local @mergechanges, @changesfiles;
1794 my $multichanges = "${package}_".(stripepoch $version)."_multi.changes";
1796 stat $multichanges or fail "$multichanges: $!";
1798 printdone "build successful, results in $multichanges\n" or die $!;
1801 sub cmd_quilt_fixup {
1802 badusage "incorrect arguments to dgit quilt-fixup" if @ARGV;
1803 my $clogp = parsechangelog();
1804 $version = getfield $clogp, 'Version';
1805 build_maybe_quilt_fixup();
1808 #---------- argument parsing and main program ----------
1811 print "dgit version $our_version\n" or die $!;
1818 if (defined $ENV{'DGIT_SSH'}) {
1819 @ssh = string_to_ssh $ENV{'DGIT_SSH'};
1820 } elsif (defined $ENV{'GIT_SSH'}) {
1821 @ssh = ($ENV{'GIT_SSH'});
1825 last unless $ARGV[0] =~ m/^-/;
1829 if (m/^--dry-run$/) {
1832 } elsif (m/^--damp-run$/) {
1835 } elsif (m/^--no-sign$/) {
1838 } elsif (m/^--help$/) {
1840 } elsif (m/^--version$/) {
1842 } elsif (m/^--new$/) {
1845 } elsif (m/^--since-version=([^_]+|_)$/) {
1847 $changes_since_version = $1;
1848 } elsif (m/^--(\w+)=(.*)/s &&
1849 ($om = $opts_opt_map{$1}) &&
1853 } elsif (m/^--(\w+):(.*)/s &&
1854 !$opts_opt_cmdonly{$1} &&
1855 ($om = $opts_opt_map{$1})) {
1858 } elsif (m/^--existing-package=(.*)/s) {
1860 $existing_package = $1;
1861 } elsif (m/^--initiator-tempdir=(.*)/s) {
1862 $initiator_tempdir = $1;
1863 $initiator_tempdir =~ m#^/# or
1864 badusage "--initiator-tempdir must be used specify an".
1865 " absolute, not relative, directory."
1866 } elsif (m/^--distro=(.*)/s) {
1869 } elsif (m/^--clean=(dpkg-source|git|none)$/s) {
1872 } elsif (m/^--clean=(.*)$/s) {
1873 badusage "unknown cleaning mode \`$1'";
1874 } elsif (m/^--ignore-dirty$/s) {
1877 } elsif (m/^--no-quilt-fixup$/s) {
1881 badusage "unknown long option \`$_'";
1888 } elsif (s/^-L/-/) {
1891 } elsif (s/^-h/-/) {
1893 } elsif (s/^-D/-/) {
1895 open DEBUG, ">&STDERR" or die $!;
1898 } elsif (s/^-N/-/) {
1901 } elsif (s/^-v([^_]+|_)$//s) {
1903 $changes_since_version = $1;
1906 push @changesopts, $_;
1908 } elsif (s/^-c(.*=.*)//s) {
1910 push @git, '-c', $1;
1911 } elsif (s/^-d(.*)//s) {
1914 } elsif (s/^-C(.*)//s) {
1917 } elsif (s/^-k(.*)//s) {
1919 } elsif (s/^-wn//s) {
1921 $cleanmode = 'none';
1922 } elsif (s/^-wg//s) {
1925 } elsif (s/^-wd//s) {
1927 $cleanmode = 'dpkg-source';
1929 badusage "unknown short option \`$_'";
1936 if ($ENV{$fakeeditorenv}) {
1937 quilt_fixup_editor();
1940 delete $ENV{'DGET_UNPACK'};
1943 print STDERR "DRY RUN ONLY\n" if $dryrun_level > 1;
1944 print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n"
1945 if $dryrun_level == 1;
1947 print STDERR $helpmsg or die $!;
1950 my $cmd = shift @ARGV;
1952 { no strict qw(refs); &{"cmd_$cmd"}(); }