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;
30 our $isuite = 'unstable';
37 our $existing_package = 'dpkg';
39 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
42 our (@dget) = qw(dget);
43 our (@dput) = qw(dput);
44 our (@debsign) = qw(debsign);
48 open DEBUG, ">/dev/null" or die $!;
50 our %opts_opt_map = ('dget' => \@dget,
52 'debsign' => \@debsign);
54 our $remotename = 'dgit';
55 our $ourdscfield = 'Vcs-Dgit-Master';
56 our $branchprefix = 'dgit';
59 sub lbranch () { return "$branchprefix/$csuite"; }
60 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
61 sub lref () { return "refs/heads/".lbranch(); }
62 sub lrref () { return "refs/remotes/$remotename/$csuite"; }
63 sub rrref () { return "refs/$branchprefix/$csuite"; }
64 sub debiantag ($) { return "debian/$_[0]"; }
68 sub fail () { die "$us: @_\n"; }
70 sub badcfg () { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
72 sub no_such_package () {
73 print STDERR "$us: package $package does not exist in suite $suite\n";
79 return "+".rrref().":".lrref();
86 $ua = LWP::UserAgent->new();
89 print "downloading @_...\n";
90 my $r = $ua->get(@_) or die $!;
91 fail $r->status_line."; failed." unless $r->is_success;
92 return $r->decoded_content();
95 our ($dscdata,$dscurl,$dsc);
100 print $fh $intro or die $!;
104 if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
105 print $fh " '$_'" or die $!;
107 print $fh " $_" or die $!;
110 print $fh "\n" or die $!;
115 printcmd \*STDERR, "$_[0]: failed command:", @_;
117 fail "failed to fork/exec: $!";
118 } elsif (!($? & 0xff)) {
119 fail "subprocess failed with error exit status ".($?>>8);
121 fail "subprocess crashed (wait status $?)";
123 fail "subprocess produced invalid output";
128 printcmd(\*DEBUG,"+",@_) if $debug>0;
130 failedcmd @_ if system @_;
135 print "dgit ok: @_\n";
137 print "would be ok: @_ (but dry run only)\n";
141 sub cmdoutput_errok {
142 die Dumper(\@_)." ?" if grep { !defined } @_;
143 printcmd(\*DEBUG,"|",@_) if $debug>0;
144 open P, "-|", @_ or die $!;
147 { local $/ = undef; $d = <P>; }
149 if (!close P) { print DEBUG "=>!$?\n" if $debug>0; return undef; }
152 print DEBUG "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
157 my $d = cmdoutput_errok @_;
158 defined $d or failedcmd @_;
163 printcmd(\*STDOUT,"#",@_);
166 sub runcmd_ordryrun {
174 our $helpmsg = <<END;
176 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
177 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
178 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
179 dgit [dgit-opts] push [dgit-opts] [suite]
180 important dgit options:
181 -k<keyid> sign tag and package with <keyid> instead of default
182 --dry-run -n do not change anything, but go through the motions
183 --new -N allow introducing a new package
184 --debug -D increase debug level
185 -c<name>=<value> set git config option (used directly by dgit too)
189 print STDERR "$us: @_\n", $helpmsg or die $!;
194 print $helpmsg or die $!;
198 our %defcfg = ('dgit.default.distro' => 'debian',
199 'dgit.default.username' => '',
200 'dgit.default.archive-query-default-component' => 'main',
201 'dgit.default.ssh' => 'ssh',
202 'dgit-distro.debian.git-host' => 'dgit.debian.net',
203 'dgit-distro.debian.git-proto' => 'git+ssh://',
204 'dgit-distro.debian.git-path' => '/git/dgit-repos',
205 'dgit-distro.debian.git-check' => 'ssh-cmd',
206 'dgit-distro.debian.git-create' => 'ssh-cmd',
207 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
208 'dgit-distro.debian.sshdakls-dir' =>
209 '/srv/ftp-master.debian.org/ftp/dists',
210 'dgit-distro.debian.mirror' => 'http://http.debian.net/debian/');
214 my @cmd = (@git, qw(config --), $c);
217 local ($debug) = $debug-1;
218 $v = cmdoutput_errok @cmd;
225 my $dv = $defcfg{$c};
226 return $dv if defined $dv;
231 sub access_distro () {
232 return cfg("dgit-suite.$isuite.distro",
233 "dgit.default.distro");
238 my $distro = access_distro();
239 my $value = cfg(map { ("dgit-distro.$distro.$_",
240 "dgit.default.$_") } @keys);
244 sub access_someuserhost ($) {
246 my $user = access_cfg("$some-user",'username');
247 my $host = access_cfg("$some-host");
248 return defined($user) && length($user) ? "$user\@$host" : $host;
251 sub access_gituserhost () {
252 return access_someuserhost('git');
255 sub access_giturl () {
256 my $url = access_cfg('git-url');
259 access_cfg('git-proto').
260 access_gituserhost().
261 access_cfg('git-path');
263 return "$url/$package.git";
267 my ($file, $desc) = @_;
268 my $c = Dpkg::Control::Hash->new({ 'name' => $desc });
269 my $fh = new IO::File '<', $file or die "$file: $!";
270 $c->parse($fh) or die "parsing of $desc failed";
271 $fh->error and die $!;
277 my $c = Dpkg::Control::Hash->new();
278 my $p = new IO::Handle;
279 my @cmd = qw(dpkg-parsechangelog);
280 open $p, '-|', @cmd or die $!;
282 $?=0; $!=0; close $p or failedcmd @cmd;
288 sub archive_query ($) {
290 my $query = access_cfg('archive-query');
292 my $distro = access_distro();
293 if ($distro eq 'debian') {
294 $query = "sshdakls:".
295 access_someuserhost('sshdakls').':'.
296 access_cfg('sshdakls-dir');
298 $query = "madison:$distro";
301 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
304 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
307 sub archive_query_madison ($$) {
308 my ($proto,$data) = @_;
309 die unless $proto eq 'madison';
310 $rmad{$package} ||= cmdoutput
311 qw(rmadison -asource),"-s$isuite","-u$data",$package;
312 my $rmad = $rmad{$package};
313 return madison_parse($rmad);
316 sub archive_query_sshdakls ($$) {
317 my ($proto,$data) = @_;
318 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
319 my $dakls = cmdoutput
320 access_cfg('ssh'), $data, qw(dak ls -asource),"-s$isuite",$package;
321 return madison_parse($dakls);
324 sub canonicalise_suite_sshdakls ($$) {
325 my ($proto,$data) = @_;
326 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
328 access_cfg('ssh'), $`,
330 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
331 " if test -d $isuite; then echo $isuite; exit 0; fi;".
333 my $dakls = cmdoutput @cmd;
334 failedcmd @cmd unless $dakls =~ m/^\w/;
338 sub madison_parse ($) {
343 $rmad =~ m{^ \s*( [^ \t|]+ )\s* \|
344 \s*( [^ \t|]+ )\s* \|
345 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
346 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
347 $1 eq $package or die "$rmad $package ?";
354 $component = access_cfg('archive-query-default-component');
356 $5 eq 'source' or die "$rmad ?";
357 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
358 my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc";
359 return ($vsn,$subpath,$newsuite);
362 sub canonicalise_suite_madison ($$) {
363 my @r = archive_query_madison($_[0],$_[1]);
365 "unable to canonialise suite using package $package".
366 " which does not appear to exist in suite $suite;".
367 " --existing-package may help";
371 sub canonicalise_suite () {
372 $csuite = archive_query('canonicalise_suite');
373 if ($isuite ne $csuite) {
374 # madison canonicalises for us
375 print "canonical suite name for $isuite is $csuite\n";
379 sub get_archive_dsc () {
380 my ($vsn,$subpath) = archive_query('archive_query');
381 canonicalise_suite();
382 if (!defined $vsn) { $dsc=undef; return undef; }
383 $dscurl = access_cfg('mirror').$subpath;
384 $dscdata = url_get($dscurl);
385 my $dscfh = new IO::File \$dscdata, '<' or die $!;
386 print DEBUG Dumper($dscdata) if $debug>1;
387 $dsc = Dpkg::Control::Hash->new(allow_pgp=>1);
388 $dsc->parse($dscfh, 'dsc') or fail "parsing of $dscurl failed";
389 print DEBUG Dumper($dsc) if $debug>1;
390 my $fmt = $dsc->{Format};
391 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
394 sub check_for_git () {
396 my $how = access_cfg('git-check');
397 if ($how eq 'ssh-cmd') {
399 (access_cfg('ssh'),access_gituserhost(),
400 " set -e; cd ".access_cfg('git-path').";".
401 " if test -d $package.git; then echo 1; else echo 0; fi");
402 my $r= cmdoutput @cmd;
403 failedcmd @cmd unless $r =~ m/^[01]$/;
406 badcfg "unknown git-check \`$how'";
410 sub create_remote_git_repo () {
411 my $how = access_cfg('git-create');
412 if ($how eq 'ssh-cmd') {
414 (access_cfg('ssh'),access_gituserhost(),
415 "set -e; cd ".access_cfg('git-path').";".
416 " mkdir -p $package.git;".
418 " if ! test -d objects; then git init --bare; fi");
420 badcfg "unknown git-create \`$how'";
424 our ($dsc_hash,$upload_hash);
426 our $ud = '.git/dgit/unpack';
434 sub mktree_in_ud_from_only_subdir () {
435 # changes into the subdir
438 $dirs[0] =~ m#^([^/]+)/\.$# or die;
440 chdir $dir or die "$dir $!";
442 die $! unless $!==&ENOENT;
443 runcmd qw(git init -q);
444 rmtree('.git/objects');
445 symlink '../../../../objects','.git/objects' or die $!;
446 runcmd @git, qw(add -Af);
447 my $tree = cmdoutput @git, qw(write-tree);
448 $tree =~ m/^\w+$/ or die "$tree ?";
454 m/^\w+ \d+ (\S+)$/ or
455 fail "could not parse .dsc Files/Checksums line \`$_'";
457 } grep m/\S/, split /\n/, ($dsc->{'Checksums-Sha256'} || $dsc->{Files});
460 sub is_orig_file ($) {
462 m/\.orig(?:-\w+)?\.tar\.\w+$/;
465 sub make_commit ($) {
467 return cmdoutput @git, qw(hash-object -w -t commit), $file;
470 sub generate_commit_from_dsc () {
474 foreach my $f (dsc_files()) {
475 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
477 link "../../../$f", $f
481 runcmd @dget, qw(--), $dscurl;
482 foreach my $f (grep { is_orig_file($_) } @files) {
483 link $f, "../../../../$f"
487 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
488 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
489 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
490 my $date = cmdoutput qw(date), '+%s %z', qw(-d),$clogp->{Date};
491 my $author = $clogp->{Maintainer};
492 $author =~ s#,.*##ms;
493 my $authline = "$author $date";
494 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
495 fail "unexpected commit author line format \`$authline'".
496 " (was generated from changelog Maintainer field)";
497 open C, ">../commit.tmp" or die $!;
498 print C <<END or die $!;
505 # imported from the archive
508 my $outputhash = make_commit qw(../commit.tmp);
509 print "synthesised git commit from .dsc $clogp->{Version}\n";
511 runcmd @git, qw(reset --hard), $upload_hash;
512 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
513 my $oldclogp = Dpkg::Control::Hash->new();
514 $oldclogp->load('../changelogold.tmp','previous changelog');
516 version_compare_string($oldclogp->{Version}, $clogp->{Version});
518 # git upload/ is earlier vsn than archive, use archive
519 open C, ">../commit2.tmp" or die $!;
520 print C <<END or die $!;
527 Record $package ($clogp->{Version}) in archive suite $csuite
529 $outputhash = make_commit qw(../commit2.tmp);
530 } elsif ($vcmp > 0) {
531 print STDERR <<END or die $!;
532 Version actually in archive: $clogp->{Version} (older)
533 Last allegedly pushed/uploaded: $oldclogp->{Version} (newer or same)
534 Perhaps the upload is stuck in incoming. Using the version from git.
536 $outputhash = $upload_hash;
537 } elsif ($outputhash ne $upload_hash) {
538 fail "version in archive ($clogp->{Version})".
539 " is same as version in git".
540 " to-be-uploaded (upload/) branch ($oldclogp->{Version})".
541 " but archive version hash no commit hash?!";
544 chdir '../../../..' or die $!;
545 runcmd @git, qw(update-ref -m),"dgit fetch import $clogp->{Version}",
546 'DGIT_ARCHIVE', $outputhash;
547 cmdoutput @git, qw(log -n2), $outputhash;
548 # ... gives git a chance to complain if our commit is malformed
553 sub ensure_we_have_orig () {
554 foreach my $f (dsc_files()) {
555 next unless is_orig_file($f);
557 die "$f ?" unless -f _;
559 die "$f $!" unless $!==&ENOENT;
561 my $origurl = $dscurl;
562 $origurl =~ s{/[^/]+$}{};
564 die "$f ?" unless $f =~ m/^${package}_/;
565 die "$f ?" if $f =~ m#/#;
566 runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x',
572 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
575 sub is_fast_fwd ($$) {
576 my ($ancestor,$child) = @_;
577 my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child;
578 return rev_parse($mb) eq rev_parse($ancestor);
581 sub git_fetch_us () {
582 badusage "cannot dry run with fetch" if $dryrun;
583 runcmd @git, qw(fetch),access_giturl(),fetchspec();
586 sub fetch_from_archive () {
587 # ensures that lrref() is what is actually in the archive,
589 get_archive_dsc() or return 0;
590 defined($dsc_hash = $dsc->{$ourdscfield}) or die;
591 if (defined $dsc_hash) {
592 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
594 print "last upload to archive specified git hash\n";
596 print "last upload to archive has NO git hash\n";
599 my $lrref_fn = ".git/".lrref();
600 if (open H, $lrref_fn) {
603 die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
604 } elsif ($! == &ENOENT) {
609 print DEBUG "previous reference hash $upload_hash\n";
611 if (defined $dsc_hash) {
612 fail "missing git history even though dsc has hash -"
613 " could not find commit $dsc_hash"
616 ensure_we_have_orig();
618 $hash = generate_commit_from_dsc();
620 print DEBUG "current hash $hash\n";
622 fail "not fast forward on last upload branch!".
623 " (archive's version left in DGIT_ARCHIVE)"
624 unless is_fast_fwd($upload_hash, $hash);
626 if ($upload_hash ne $hash) {
627 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
631 dryrun_report @upd_cmd;
639 canonicalise_suite();
640 badusage "dry run makes no sense with clone" if $dryrun;
641 mkdir $dstdir or die "$dstdir $!";
642 chdir "$dstdir" or die "$dstdir $!";
643 runcmd @git, qw(init -q);
644 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
645 open H, "> .git/HEAD" or die $!;
646 print H "ref: ".lref()."\n" or die $!;
648 runcmd @git, qw(remote add), 'origin', access_giturl();
649 if (check_for_git()) {
650 print "fetching existing git history\n";
652 runcmd @git, qw(fetch origin);
654 print "starting new git history\n";
656 fetch_from_archive() or no_such_package;
657 runcmd @git, qw(reset --hard), lrref();
658 printdone "ready for work in $dstdir";
662 if (check_for_git()) {
665 fetch_from_archive() or no_such_package();
666 printdone "fetched into ".lrref();
671 runcmd_ordryrun @git, qw(merge -m),"Merge from $csuite [dgit]",
673 printdone "fetched to ".lrref()." and merged into HEAD";
676 sub check_not_dirty () {
677 runcmd @git, qw(diff --quiet);
680 sub commit_quilty_patch ($) {
682 my $output = cmdoutput @git, qw(status --porcelain);
683 my %fixups = map {$_=>1}
684 (".pc/debian-changes-$vsn/","debian/patches/debian-changes-$vsn");
686 foreach my $l (split /\n/, $output) {
687 next unless $l =~ s/^\?\? //;
688 next unless $fixups{$l};
691 print DEBUG "checking for quilty\n", Dumper(\@files);
693 my $m = "Commit Debian 3.0 (quilt) metadata";
695 runcmd_ordryrun @git, qw(add), @files;
696 runcmd_ordryrun @git, qw(commit -m), $m;
701 print DEBUG "actually entering push\n";
702 my $clogp = parsechangelog();
703 $package = $clogp->{Source};
704 my $dscfn = "${package}_$clogp->{Version}.dsc";
706 fail "looked for .dsc $dscfn, but $!;".
707 " maybe you forgot to build";
708 $dsc = parsecontrol("../$dscfn");
709 print DEBUG "format $dsc->{Format}\n";
710 if ($dsc->{Format} eq '3.0 (quilt)') {
711 print "Format \`$dsc->{Format}', urgh\n";
712 commit_quilty_patch($dsc->{Version});
717 print "checking that $dscfn corresponds to HEAD\n";
718 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
719 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
720 chdir '../../../..' or die $!;
721 printcmd \@DEBUG,"+",@_;
722 my @diffcmd = (@git, qw(diff --exit-code), $tree);
724 if (system @diffcmd) {
726 fail "$dscfn specifies a different tree to your HEAD commit;".
727 " perhaps you forgot to build";
733 #do fast forward check and maybe fake merge
734 # if (!is_fast_fwd(mainbranch
735 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
736 # map { lref($_).":".rref($_) }
738 $dsc->{$ourdscfield} = rev_parse('HEAD');
739 $dsc->save("../$dscfn.tmp") or die $!;
741 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
743 print "[new .dsc left in $dscfn.tmp]\n";
746 my $pat = "${package}_$clogp->{Version}_*.changes";
747 my @cs = glob "../$pat";
748 fail "failed to find unique changes file".
749 " (looked for $pat in ..); perhaps you need to use dgit -C"
751 ($changesfile) = @cs;
753 my $tag = debiantag($dsc->{Version});
754 if (!check_for_git()) {
755 create_remote_git_repo();
757 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
759 my @tag_cmd = (@git, qw(tag -s -m),
760 "Release $dsc->{Version} for $csuite [dgit]");
761 push @tag_cmd, qw(-u),$keyid if defined $keyid;
763 runcmd_ordryrun @tag_cmd;
764 my @debsign_cmd = @debsign;
765 push @debsign_cmd, "-k$keyid" if defined $keyid;
766 push @debsign_cmd, $changesfile;
767 runcmd_ordryrun @debsign_cmd;
769 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
770 my $host = access_cfg('upload-host');
771 my @hostarg = defined($host) ? ($host,) : ();
772 runcmd_ordryrun @dput, @hostarg, $changesfile;
773 printdone "pushed and uploaded $dsc->{Version}";
779 badusage "-p is not allowed with clone; specify as argument instead"
783 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
784 ($package,$isuite) = @ARGV;
785 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
786 ($package,$dstdir) = @ARGV;
788 ($package,$isuite,$dstdir) = @ARGV;
790 badusage "incorrect arguments to dgit clone";
792 $dstdir ||= "$package";
797 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
798 if ($branch =~ m#$lbranch_re#o) {
805 sub fetchpullargs () {
806 if (!defined $package) {
807 my $sourcep = parsecontrol('debian/control');
808 $package = $sourcep->{Source};
811 # $isuite = branchsuite(); # this doesn't work because dak hates canons
813 my $clogp = parsechangelog();
814 $isuite = $clogp->{Distribution};
816 canonicalise_suite();
817 print "fetching from suite $csuite\n";
820 canonicalise_suite();
822 badusage "incorrect arguments to dgit fetch or dgit pull";
840 badusage "-p is not allowed with dgit push" if defined $package;
841 runcmd @git, qw(diff --quiet HEAD);
842 my $clogp = parsechangelog();
843 $package = $clogp->{Source};
845 $isuite = $clogp->{Distribution};
847 local ($package) = $existing_package; # this is a hack
848 canonicalise_suite();
851 badusage "incorrect arguments to dgit push";
853 if (fetch_from_archive()) {
854 is_fast_fwd(lrref(), 'HEAD') or die;
856 fail "package appears to be new in this suite;".
857 " if this is intentional, use --new";
863 # we pass further options and args to git-buildpackage
864 badusage "-p is not allowed with dgit build" if defined $package;
865 my $clogp = parsechangelog();
866 $isuite = $clogp->{Distribution};
867 $package = $clogp->{Source};
869 (qw(git-buildpackage -us -uc --git-no-sign-tags),
870 '--git-builder=dpkg-buildpackage -i\.git/ -I.git');
871 unless (grep { m/^--git-debian-branch/ } @ARGV) {
872 canonicalise_suite();
873 push @cmd, "--git-debian-branch=".lbranch();
875 runcmd_ordryrun @cmd, @ARGV;
878 sub cmd_quilt_fixup {
879 badusage "incorrect arguments to dgit quilt-fixup";
880 my $clogp = parsechangelog();
881 commit_quilty_patch($clogp->{Version});
887 last unless $ARGV[0] =~ m/^-/;
891 if (m/^--dry-run$/) {
893 } elsif (m/^--no-sign$/) {
895 } elsif (m/^--help$/) {
897 } elsif (m/^--new$/) {
899 } elsif (m/^--(\w+)=(.*)/s && ($om = $opts_opt_map{$1})) {
901 } elsif (m/^--(\w+):(.*)/s && ($om = $opts_opt_map{$1})) {
903 } elsif (m/^--existing-package=(.*)/s) {
904 $existing_package = $1;
906 badusage "unknown long option \`$_'";
915 open DEBUG, ">&STDERR" or die $!;
919 } elsif (s/^-c(.*=.*)//s) {
921 } elsif (s/^-C(.*)//s) {
923 } elsif (s/^-k(.*)//s) {
926 badusage "unknown shorrt option \`$_'";
934 print STDERR "DRY RUN ONLY\n" if $dryrun;
936 print STDERR $helpmsg or die $!;
939 my $cmd = shift @ARGV;
941 { no strict qw(refs); &{"cmd_$cmd"}(); }