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