chiark / gitweb /
do not use git-show-ref as it is hopeless; just do it ourselves
[dgit.git] / dgit
1 #!/usr/bin/perl -w
2 # dgit
3 # Integration between git and Debian-style archives
4 #
5 # Copyright (C)2013 Ian Jackson
6 #
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.
11 #
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.
16 #
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/>.
19
20 use strict;
21
22 use IO::Handle;
23 use Data::Dumper;
24 use LWP::UserAgent;
25 use Dpkg::Control::Hash;
26 use File::Path;
27 use POSIX;
28
29 our $suite = 'sid';
30 our $package;
31
32 our $sign = 1;
33 our $dryrun = 0;
34 our $changesfile;
35 our $new_package = 0;
36 our $existing_package = 'dpkg';
37
38 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
39
40 our (@git) = qw(git);
41 our (@dget) = qw(dget);
42 our (@dput) = qw(dput);
43 our (@debsign) = qw(debsign);
44 our $keyid;
45
46 our $debug = 0;
47 open DEBUG, ">/dev/null" or die $!;
48
49 our %opts_opt_map = ('dget' => \@dget,
50                      'dput' => \@dput,
51                      'debsign' => \@debsign);
52
53 our $remotename = 'dgit';
54 our $ourdscfield = 'Vcs-Dgit-Master';
55 our $branchprefix = 'dgit';
56
57 sub lbranch () { return "$branchprefix/$suite"; }
58 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
59 sub lref () { return "refs/heads/".lbranch(); }
60 sub lrref () { return "refs/remotes/$remotename/$suite"; }
61 sub rrref () { return "refs/$branchprefix/$suite"; }
62 sub debiantag ($) { return "debian/$_[0]"; }
63
64 sub fetchspec () {
65     local $suite = '*';
66     return  "+".rrref().":".lrref();
67 }
68
69 our $ua;
70
71 sub url_get {
72     if (!$ua) {
73         $ua = LWP::UserAgent->new();
74         $ua->env_proxy;
75     }
76     print "downloading @_...\n";
77     my $r = $ua->get(@_) or die $!;
78     die "$_[0]: ".$r->status_line."; failed.\n" unless $r->is_success;
79     return $r->decoded_content();
80 }
81
82 our ($dscdata,$dscurl,$dsc);
83
84 sub printcmd {
85     my $fh = shift @_;
86     my $intro = shift @_;
87     print $fh $intro or die $!;
88     local $_;
89     foreach my $a (@_) {
90         $_ = $a;
91         if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
92             print $fh " '$_'" or die $!;
93         } else {
94             print $fh " $_" or die $!;
95         }
96     }
97     print $fh "\n" or die $!;
98 }
99
100 sub runcmd {
101     printcmd(\*DEBUG,"+",@_) if $debug>0;
102     $!=0; $?=0;
103     die "@_ $! $?" if system @_;
104 }
105
106 sub cmdoutput_errok {
107     die Dumper(\@_)." ?" if grep { !defined } @_;
108     printcmd(\*DEBUG,"|",@_) if $debug>0;
109     open P, "-|", @_ or die $!;
110     my $d;
111     $!=0; $?=0;
112     { local $/ = undef; $d = <P>; }
113     die if P->error;
114     if (!close P) { print DEBUG "=>!$?\n" if $debug>0; return undef; }
115     chomp $d;
116     $d =~ m/^.*/;
117     print DEBUG "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
118     return $d;
119 }
120
121 sub cmdoutput {
122     my $d = cmdoutput_errok @_;
123     defined $d or die "@_ $? $!";
124     return $d;
125 }
126
127 sub dryrun_report {
128     printcmd(\*STDOUT,"#",@_);
129 }
130
131 sub runcmd_ordryrun {
132     if (!$dryrun) {
133         runcmd @_;
134     } else {
135         dryrun_report @_;
136     }
137 }
138
139 our %defcfg = ('dgit.default.distro' => 'debian',
140                'dgit.default.username' => '',
141                'dgit.default.archive-query-default-component' => 'main',
142                'dgit.default.ssh' => 'ssh',
143                'dgit-distro.debian.git-host' => 'git.debian.org',
144                'dgit-distro.debian.git-proto' => 'git+ssh://',
145                'dgit-distro.debian.git-path' => '/git/dgit-repos',
146                'dgit-distro.debian.git-check' => 'ssh-cmd',
147                'dgit-distro.debian.git-create' => 'ssh-cmd',
148                'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/');
149
150 sub cfg {
151     foreach my $c (@_) {
152         my $v;
153         {
154             local ($debug) = $debug-1;
155             $v = cmdoutput_errok(@git, qw(config --), $c);
156         };
157         if ($?==0) {
158             return $v;
159         } elsif ($?!=256) {
160             die "$c $?";
161         }
162         my $dv = $defcfg{$c};
163         return $dv if defined $dv;
164     }
165     return undef;
166 }
167
168 sub access_distro () {
169     return cfg("dgit-suite.$suite.distro",
170                "dgit.default.distro");
171 }
172
173 sub access_cfg ($) {
174     my ($key) = @_;
175     my $distro = access_distro();
176     my $value = cfg("dgit-distro.$distro.$key",
177                     "dgit.default.$key");
178     return $value;
179 }
180
181 sub access_gituserhost () {
182     my $user = access_cfg('git-user');
183     my $host = access_cfg('git-host');
184     return defined($user) && length($user) ? "$user\@$host" : $host;
185 }
186
187 sub access_giturl () {
188     my $url = access_cfg('git-url');
189     if (!defined $url) {
190         $url =
191             access_cfg('git-proto').
192             access_gituserhost().
193             access_cfg('git-path');
194     }
195     return "$url/$package.git";
196 }              
197
198 sub parsecontrol {
199     my $c = Dpkg::Control::Hash->new();
200     $c->load(@_) or return undef;
201     return $c;
202 }
203
204 sub parsechangelog {
205     my $c = Dpkg::Control::Hash->new();
206     my $p = new IO::Handle;
207     open $p, '-|', qw(dpkg-parsechangelog) or die $!;
208     $c->parse($p);
209     $?=0; $!=0; close $p or die "$! $?";
210     return $c;
211 }
212
213 our %rmad;
214
215 sub archive_query () {
216     my $query = access_cfg('archive-query');
217     $query ||= "madison:".access_distro();
218     $query =~ s/^(\w+):// or die "$query ?";
219     my $proto = $1;
220     my $url = $'; #';
221     die unless $proto eq 'madison';
222     $rmad{$package} ||= cmdoutput
223         qw(rmadison -asource),"-s$suite","-u$url",$package;
224     my $rmad = $rmad{$package};
225     if (!length $rmad) {
226         return ();
227     }
228     $rmad =~ m{^ \s*( [^ \t|]+ )\s* \|
229                  \s*( [^ \t|]+ )\s* \|
230                  \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
231                  \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
232     $1 eq $package or die "$rmad $package ?";
233     my $vsn = $2;
234     if ($suite ne $3) {
235         # madison canonicalises for us
236         print "canonical suite name for $suite is $3\n";
237         $suite = $3;
238     }
239     my $component;
240     if (defined $4) {
241         $component = $4;
242     } else {
243         $component = access_cfg('archive-query-default-component');
244     }
245     $5 eq 'source' or die "$rmad ?";
246     my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
247     my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc";
248     return ($vsn,$subpath);
249 }
250
251 sub canonicalise_suite () {
252     archive_query() or die;
253 }
254
255 sub get_archive_dsc () {
256     my ($vsn,$subpath) = archive_query();
257     if (!defined $vsn) { $dsc=undef; return undef; }
258     $dscurl = access_cfg('mirror').$subpath;
259     $dscdata = url_get($dscurl);
260     my $dscfh = new IO::File \$dscdata, '<' or die $!;
261     print DEBUG Dumper($dscdata) if $debug>1;
262     $dsc = Dpkg::Control::Hash->new(allow_pgp=>1);
263     $dsc->parse($dscfh, 'dsc') or die "parsing of $dscurl failed\n";
264     print DEBUG Dumper($dsc) if $debug>1;
265     my $fmt = $dsc->{Format};
266     die "unsupported format $fmt, sorry\n" unless $format_ok{$fmt};
267 }
268
269 sub check_for_git () {
270     # returns 0 or 1
271     my $how = access_cfg('git-check');
272     if ($how eq 'ssh-cmd') {
273         my $r= cmdoutput
274             (access_cfg('ssh'),access_gituserhost(),
275              " set -e; cd ".access_cfg('git-path').";".
276              " if test -d $package.git; then echo 1; else echo 0; fi");
277         print DEBUG "got \`$r'\n";
278         die "$r $! $?" unless $r =~ m/^[01]$/;
279         return $r+0;
280     } else {
281         die "unknown git-check $how ?";
282     }
283 }
284
285 sub create_remote_git_repo () {
286     my $how = access_cfg('git-create');
287     if ($how eq 'ssh-cmd') {
288         runcmd_ordryrun
289             (access_cfg('ssh'),access_gituserhost(),
290              "set -e; cd ".access_cfg('git-path').";".
291              " mkdir -p $package.git;".
292              " cd $package.git;".
293              " if ! test -d objects; then git init --bare; fi");
294     } else {
295         die "unknown git-create $how ?";
296     }
297 }
298
299 our ($dsc_hash,$upload_hash);
300
301 our $ud = '.git/dgit/unpack';
302
303 sub prep_ud () {
304     rmtree($ud);
305     mkpath '.git/dgit';
306     mkdir $ud or die $!;
307 }
308
309 sub mktree_in_ud_from_only_subdir () {
310     # changes into the subdir
311     my (@dirs) = <*/.>;
312     die unless @dirs==1;
313     $dirs[0] =~ m#^([^/]+)/\.$# or die;
314     my $dir = $1;
315     chdir $dir or die "$dir $!";
316     die if stat '.git';
317     die $! unless $!==&ENOENT;
318     runcmd qw(git init -q);
319     rmtree('.git/objects');
320     symlink '../../../../objects','.git/objects' or die $!;
321     runcmd @git, qw(add -Af);
322     my $tree = cmdoutput @git, qw(write-tree);
323     $tree =~ m/^\w+$/ or die "$tree ?";
324     return ($tree,$dir);
325 }
326
327 sub dsc_files () {
328     map {
329         m/^\w+ \d+ (\S+)$/ or die "$_ ?";
330         $1;
331     } grep m/\S/, split /\n/, ($dsc->{'Checksums-Sha256'} || $dsc->{Files});
332 }
333
334 sub is_orig_file ($) {
335     local ($_) = @_;
336     m/\.orig(?:-\w+)?\.tar\.\w+$/;
337 }
338
339 sub generate_commit_from_dsc () {
340     prep_ud();
341     chdir $ud or die $!;
342     my @files;
343     foreach my $f (dsc_files()) {
344         die if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
345         push @files, $f;
346         link "../../../$f", $f
347             or $!==&ENOENT
348             or die "$f $!";
349     }
350     runcmd @dget, qw(--), $dscurl;
351     foreach my $f (grep { is_orig_file($_) } @files) {
352         link $f, "../../../../$f"
353             or $!==&EEXIST
354             or die "$f $!";
355     }
356     my ($tree,$dir) = mktree_in_ud_from_only_subdir();
357     runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
358     my $clogp = parsecontrol('../changelog.tmp','changelog') or die;
359     my $date = cmdoutput qw(date), '+%s %z', qw(-d),$clogp->{Date};
360     my $author = $clogp->{Maintainer};
361     $author =~ s#,.*##ms;
362     my $authline = "$author $date";
363     $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or die $authline;
364     open C, ">../commit.tmp" or die $!;
365     print C "tree $tree\n" or die $!;
366     print C "parent $upload_hash\n" or die $! if $upload_hash;
367     print C <<END or die $!;
368 author $authline
369 committer $authline
370
371 $clogp->{Changes}
372
373 # imported from the archive
374 END
375     close C or die $!;
376     my $commithash = cmdoutput @git, qw(hash-object -w -t commit ../commit.tmp);
377     print "synthesised git commit from .dsc $clogp->{Version}\n";
378     chdir '../../../..' or die $!;
379     cmdoutput @git, qw(update-ref -m),"dgit synthesise $clogp->{Version}",
380               'DGIT_ARCHIVE', $commithash;
381     cmdoutput @git, qw(log -n2), $commithash;
382     # ... gives git a chance to complain if our commit is malformed
383     my $outputhash = $commithash;
384     if ($upload_hash) {
385         chdir "$ud/$dir" or die $!;
386         runcmd @git, qw(reset --hard), $upload_hash;
387         runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
388         my $oldclogp = Dpkg::Control::Hash->new();
389         $oldclogp->parse('../changelogold.tmp','previous changelog') or die;
390         my $vcmp =
391             version_compare_string($oldclogp->{Version}, $clogp->{Version});
392         if ($vcmp < 0) {
393             # git upload/ is earlier vsn than archive, use archive
394         } elsif ($vcmp >= 0) {
395             print STDERR <<END or die $!;
396 Version actually in archive:    $clogp->{Version} (older)
397 Last allegedly pushed/uploaded: $oldclogp->{Version} (newer or same)
398 Perhaps the upload is stuck in incoming.  Using the version from git.
399 END
400         } else {
401             die "version in archive is same as version in git".
402                 " to-be-uploaded (upload/) branch but archive".
403                 " version hash no commit hash?!\n";
404         }
405         chdir '../../../..' or die $!;
406     }
407     rmtree($ud);
408     return $outputhash;
409 }
410
411 sub ensure_we_have_orig () {
412     foreach my $f (dsc_files()) {
413         next unless is_orig_file($f);
414         if (stat "../$f") {
415             die "$f ?" unless -f _;
416         } else {
417             die "$f $!" unless $!==&ENOENT;
418         }
419         my $origurl = $dscurl;
420         $origurl =~ s{/[^/]+$}{};
421         $origurl .= "/$f";
422         die "$f ?" unless $f =~ m/^${package}_/;
423         die "$f ?" if $f =~ m#/#;
424         runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x',
425             @dget,'--',$origurl;
426     }
427 }
428
429 sub rev_parse ($) {
430     return cmdoutput @git, qw(rev-parse), "$_[0]~0";
431 }
432
433 sub is_fast_fwd ($$) {
434     my ($ancestor,$child) = @_;
435     my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child;
436     return rev_parse($mb) eq rev_parse($ancestor);
437 }
438
439 sub git_fetch_us () {
440     die "cannot dry run with fetch" if $dryrun;
441     runcmd @git, qw(fetch),access_giturl(),fetchspec();
442 }
443
444 sub fetch_from_archive () {
445     # ensures that lrref() is what is actually in the archive,
446     #  one way or another
447     get_archive_dsc() or return 0;
448     $dsc_hash = $dsc->{$ourdscfield};
449     if (defined $dsc_hash) {
450         $dsc_hash =~ m/\w+/ or die "$dsc_hash $?";
451         $dsc_hash = $&;
452         print "last upload to archive specified git hash\n";
453     } else {
454         print "last upload to archive has NO git hash\n";
455     }
456
457     my $lrref_fn = ".git/".lrref();
458     if (open H, $lrref_fn) {
459         $upload_hash = <H>;
460         chomp $upload_hash;
461         die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
462     } elsif ($! == &ENOENT) {
463         $upload_hash = '';
464     } else {
465         die "$lrref_fn $!";
466     }
467     print DEBUG "last upload hash $upload_hash\n";
468     my $hash;
469     if (defined $dsc_hash) {
470         die "missing git history even though dsc has hash"
471             unless $upload_hash;
472         $hash = $dsc_hash;
473         ensure_we_have_orig();
474     } else {
475         $hash = generate_commit_from_dsc();
476     }
477     if ($upload_hash) {
478         die "not fast forward on last upload branch!".
479             " (archive's version left in DGIT_ARCHIVE)"
480             unless is_fast_fwd($dsc_hash, $upload_hash);
481     }
482     if ($upload_hash ne $hash) {
483         my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
484         if (!$dryrun) {
485             cmdoutput @upd_cmd;
486         } else {
487             dryrun_report @upd_cmd;
488         }
489     }
490     return 1;
491 }
492
493 sub clone ($) {
494     my ($dstdir) = @_;
495     die "dry run makes no sense with clone" if $dryrun;
496     mkdir $dstdir or die "$dstdir $!";
497     chdir "$dstdir" or die "$dstdir $!";
498     runcmd @git, qw(init -q);
499     runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
500     open H, "> .git/HEAD" or die $!;
501     print H "ref: ".lref()."\n" or die $!;
502     close H or die $!;
503     runcmd @git, qw(remote add), 'origin', access_giturl();
504     if (check_for_git()) {
505         print "fetching existing git history\n";
506         git_fetch_us();
507         runcmd @git, qw(fetch origin);
508     } else {
509         print "starting new git history\n";
510     }
511     fetch_from_archive() or die;
512     runcmd @git, qw(reset --hard), lrref();
513     print "ready for work in $dstdir\n";
514 }
515
516 sub fetch () {
517     if (check_for_git()) {
518         git_fetch_us();
519     }
520     fetch_from_archive() or die;
521 }
522
523 sub pull () {
524     fetch();
525     runcmd_ordryrun @git, qw(merge -m),"Merge from $suite [dgit]",
526         lrref();
527 }
528
529 sub dopush () {
530     runcmd @git, qw(diff --quiet HEAD);
531     my $clogp = parsechangelog();
532     $package = $clogp->{Source};
533     my $dscfn = "${package}_$clogp->{Version}.dsc";
534     stat "../$dscfn" or die "$dscfn $!";
535     $dsc = parsecontrol("../$dscfn");
536     prep_ud();
537     chdir $ud or die $!;
538     print "checking that $dscfn corresponds to HEAD\n";
539     runcmd qw(dpkg-source -x --), "../../../../$dscfn";
540     my ($tree,$dir) = mktree_in_ud_from_only_subdir();
541     chdir '../../../..' or die $!;
542     runcmd @git, qw(diff --exit-code), $tree;
543 #fetch from alioth
544 #do fast forward check and maybe fake merge
545 #    if (!is_fast_fwd(mainbranch
546 #    runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
547 #        map { lref($_).":".rref($_) }
548 #        (uploadbranch());
549     $dsc->{$ourdscfield} = rev_parse('HEAD');
550     $dsc->save("../$dscfn.tmp") or die $!;
551     if (!$dryrun) {
552         rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
553     } else {
554         print "[new .dsc left in $dscfn.tmp]\n";
555     }
556     if (!$changesfile) {
557         my $pat = "../${package}_$clogp->{Version}_*.changes";
558         my @cs = glob $pat;
559         die "$pat ?" unless @cs==1;
560         ($changesfile) = @cs;
561     }
562     my $tag = debiantag($dsc->{Version});
563     if (!check_for_git()) {
564         create_remote_git_repo();
565     }
566     runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
567     if ($sign) {
568         my @tag_cmd = (@git, qw(tag -s -m),
569                        "Release $dsc->{Version} for $suite [dgit]");
570         push @tag_cmd, qw(-u),$keyid if defined $keyid;
571         push @tag_cmd, $tag;
572         runcmd_ordryrun @tag_cmd;
573         my @debsign_cmd = @debsign;
574         push @debsign_cmd, "-k$keyid" if defined $keyid;
575         push @debsign_cmd, $changesfile;
576         runcmd_ordryrun @debsign_cmd;
577     }
578     runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
579     my $host = access_cfg('upload-host');
580     my @hostarg = defined($host) ? ($host,) : ();
581     runcmd_ordryrun @dput, @hostarg, $changesfile;
582 }
583
584 sub cmd_clone {
585     parseopts();
586     my $dstdir;
587     die if defined $package;
588     if (@ARGV==1) {
589         ($package) = @ARGV;
590     } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
591         ($package,$suite) = @ARGV;
592     } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
593         ($package,$dstdir) = @ARGV;
594     } elsif (@ARGV==3) {
595         ($package,$suite,$dstdir) = @ARGV;
596     } else {
597         die;
598     }
599     $dstdir ||= "$package";
600     clone($dstdir);
601 }
602
603 sub branchsuite () {
604     my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
605     if ($branch =~ m#$lbranch_re#o) {
606         return $1;
607     } else {
608         return undef;
609     }
610 }
611
612 sub fetchpullargs () {
613     if (!defined $package) {
614         my $sourcep = parsecontrol('debian/control');
615         $package = $sourcep->{Source};
616     }
617     if (@ARGV==0) {
618         $suite = branchsuite();
619         if (!$suite) {
620             my $clogp = parsechangelog();
621             $suite = $clogp->{Distribution};
622         }
623         canonicalise_suite();
624         print "fetching from suite $suite\n";
625     } elsif (@ARGV==1) {
626         ($suite) = @ARGV;
627         canonicalise_suite();
628     } else {
629         die;
630     }
631 }
632
633 sub cmd_fetch {
634     parseopts();
635     fetchpullargs();
636     fetch();
637 }
638
639 sub cmd_pull {
640     parseopts();
641     fetchpullargs();
642     pull();
643 }
644
645 sub cmd_push {
646     parseopts();
647     die if defined $package;
648     my $clogp = parsechangelog();
649     $package = $clogp->{Source};
650     if (@ARGV==0) {
651         $suite = $clogp->{Distribution};
652         if ($new_package) {
653             local ($package) = $existing_package; # this is a hack
654             canonicalise_suite();
655         }
656     } else {
657         die;
658     }
659     if (fetch_from_archive()) {
660         is_fast_fwd(lrref(), 'HEAD') or die;
661     } else {
662         die unless $new_package;
663     }
664     dopush();
665 }
666
667 sub cmd_build {
668     # we pass further options and args to git-buildpackage
669     die if defined $package;
670     my $clogp = parsechangelog();
671     $suite = $clogp->{Distribution};
672     $package = $clogp->{Source};
673     runcmd_ordryrun
674         qw(git-buildpackage -us -uc --git-no-sign-tags),
675         '--git-builder=dpkg-buildpackage -i\.git/ -I.git',
676         "--git-debian-branch=".lbranch(),
677         @ARGV;
678 }
679
680 sub parseopts () {
681     my $om;
682     while (@ARGV) {
683         last unless $ARGV[0] =~ m/^-/;
684         $_ = shift @ARGV;
685         last if m/^--?$/;
686         if (m/^--/) {
687             if (m/^--dry-run$/) {
688                 $dryrun=1;
689             } elsif (m/^--no-sign$/) {
690                 $sign=0;
691             } elsif (m/^--new$/) {
692                 $new_package=1;
693             } elsif (m/^--(\w+)=(.*)/s && ($om = $opts_opt_map{$1})) {
694                 $om->[0] = $2;
695             } elsif (m/^--(\w+):(.*)/s && ($om = $opts_opt_map{$1})) {
696                 push @$om, $2;
697             } elsif (m/^--existing-package=(.*)/s) {
698                 $existing_package = $1;
699             } else {
700                 die "$_ ?";
701             }
702         } else {
703             while (m/^-./s) {
704                 if (s/^-n/-/) {
705                     $dryrun=1;
706                 } elsif (s/^-D/-/) {
707                     open DEBUG, ">&STDERR" or die $!;
708                     $debug++;
709                 } elsif (s/^-N/-/) {
710                     $new_package=1;
711                 } elsif (s/^-c(.*=.*)//s) {
712                     push @git, '-c', $1;
713                 } elsif (s/^-C(.*)//s) {
714                     $changesfile = $1;
715                 } elsif (s/^-k(.*)//s) {
716                     $keyid=$1;
717                 } else {
718                     die "$_ ?";
719                 }
720             }
721         }
722     }
723 }
724
725 parseopts();
726 die unless @ARGV;
727 my $cmd = shift @ARGV;
728
729 { no strict qw(refs); &{"cmd_$cmd"}(); }