+our $helpmsg = <<END;
+main usages:
+ dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
+ dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
+ dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
+ dgit [dgit-opts] push [dgit-opts] [suite]
+important dgit options:
+ -k<keyid> sign tag and package with <keyid> instead of default
+ --dry-run -n do not change anything, but go through the motions
+ --new -N allow introducing a new package
+ --debug -D increase debug level
+ -c<name>=<value> set git config option (used directly by dgit too)
+END
+
+sub badusage {
+ print STDERR "$us: @_\n", $helpmsg or die $!;
+ exit 8;
+}
+
+sub helponly () {
+ print $helpmsg or die $!;
+ exit 0;
+}
+
+our %defcfg = ('dgit.default.distro' => 'debian',
+ 'dgit.default.username' => '',
+ 'dgit.default.archive-query-default-component' => 'main',
+ 'dgit.default.ssh' => 'ssh',
+ 'dgit-distro.debian.git-host' => 'dgit.debian.net',
+ 'dgit-distro.debian.git-proto' => 'git+ssh://',
+ 'dgit-distro.debian.git-path' => '/git/dgit-repos',
+ 'dgit-distro.debian.git-check' => 'ssh-cmd',
+ 'dgit-distro.debian.git-create' => 'ssh-cmd',
+ 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
+ 'dgit-distro.debian.sshdakls-dir' =>
+ '/srv/ftp-master.debian.org/ftp/dists',
+ 'dgit-distro.debian.mirror' => 'http://http.debian.net/debian/');
+
+sub cfg {
+ foreach my $c (@_) {
+ return undef if $c =~ /RETURN-UNDEF/;
+ my @cmd = (@git, qw(config --), $c);
+ my $v;
+ {
+ local ($debug) = $debug-1;
+ $v = cmdoutput_errok @cmd;
+ };
+ if ($?==0) {
+ return $v;
+ } elsif ($?!=256) {
+ failedcmd @cmd;
+ }
+ my $dv = $defcfg{$c};
+ return $dv if defined $dv;
+ }
+ badcfg "need value for one of: @_";
+}
+
+sub access_distro () {
+ return cfg("dgit-suite.$isuite.distro",
+ "dgit.default.distro");
+}
+
+sub access_cfg (@) {
+ my (@keys) = @_;
+ my $distro = $idistro || access_distro();
+ my $value = cfg(map { ("dgit-distro.$distro.$_",
+ "dgit.default.$_") } @keys);
+ return $value;
+}
+
+sub access_someuserhost ($) {
+ my ($some) = @_;
+ my $user = access_cfg("$some-user",'username');
+ my $host = access_cfg("$some-host");
+ return length($user) ? "$user\@$host" : $host;
+}
+
+sub access_gituserhost () {
+ return access_someuserhost('git');
+}
+
+sub access_giturl () {
+ my $url = access_cfg('git-url','RETURN-UNDEF');
+ if (!defined $url) {
+ $url =
+ access_cfg('git-proto').
+ access_gituserhost().
+ access_cfg('git-path');
+ }
+ return "$url/$package.git";
+}
+
+sub parsecontrolfh ($$@) {
+ my ($fh, $desc, @opts) = @_;
+ my %opts = ('name' => $desc, @opts);
+ my $c = Dpkg::Control::Hash->new(%opts);
+ $c->parse($fh) or die "parsing of $desc failed";
+ return $c;
+}
+