chiark / gitweb /
Honour dgit-distros.DISTRO.cmd-CMD and .opts-CMD. Closes:#793427.
[dgit.git] / dgit
diff --git a/dgit b/dgit
index c652e5db10113279fc22aa6d20ece200a641342f..f9a67ce4ff7939a9c00e0b05e49a2e0c6dd4c26f 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -98,6 +98,8 @@ our %opts_opt_map = ('dget' => \@dget, # accept for compatibility
                      'mergechanges' => \@mergechanges);
 
 our %opts_opt_cmdonly = ('gpg' => 1);
                      'mergechanges' => \@mergechanges);
 
 our %opts_opt_cmdonly = ('gpg' => 1);
+our %opts_opt_cmdline_opts;
+sub finalise_opts_opts();
 
 our $keyid;
 
 
 our $keyid;
 
@@ -603,6 +605,11 @@ sub pushing () {
 Push failed, before we got started.
 You can retry the push, after fixing the problem, if you like.
 END
 Push failed, before we got started.
 You can retry the push, after fixing the problem, if you like.
 END
+    finalise_opts_opts();
+}
+
+sub notpushing () {
+    finalise_opts_opts();
 }
 
 sub supplementary_message ($) {
 }
 
 sub supplementary_message ($) {
@@ -638,7 +645,7 @@ sub access_distros () {
     @l;
 }
 
     @l;
 }
 
-sub access_cfg (@) {
+sub access_cfg_cfgs (@) {
     my (@keys) = @_;
     my @cfgs;
     # The nesting of these loops determines the search order.  We put
     my (@keys) = @_;
     my @cfgs;
     # The nesting of these loops determines the search order.  We put
@@ -665,6 +672,12 @@ sub access_cfg (@) {
     }
     push @cfgs, map { "dgit.default.$_" } @realkeys;
     push @cfgs, @rundef;
     }
     push @cfgs, map { "dgit.default.$_" } @realkeys;
     push @cfgs, @rundef;
+    return @cfgs;
+}
+
+sub access_cfg (@) {
+    my (@keys) = @_;
+    my (@cfgs) = access_cfg_cfgs(@keys);
     my $value = cfg(@cfgs);
     return $value;
 }
     my $value = cfg(@cfgs);
     return $value;
 }
@@ -2004,6 +2017,7 @@ END
 
 sub cmd_clone {
     parseopts();
 
 sub cmd_clone {
     parseopts();
+    notpushing();
     my $dstdir;
     badusage "-p is not allowed with clone; specify as argument instead"
        if defined $package;
     my $dstdir;
     badusage "-p is not allowed with clone; specify as argument instead"
        if defined $package;
@@ -2051,6 +2065,7 @@ sub branchsuite () {
 }
 
 sub fetchpullargs () {
 }
 
 sub fetchpullargs () {
+    notpushing();
     if (!defined $package) {
        my $sourcep = parsecontrol('debian/control','debian/control');
        $package = getfield $sourcep, 'Source';
     if (!defined $package) {
        my $sourcep = parsecontrol('debian/control','debian/control');
        $package = getfield $sourcep, 'Source';
@@ -2084,8 +2099,8 @@ sub cmd_pull {
 }
 
 sub cmd_push {
 }
 
 sub cmd_push {
-    pushing();
     parseopts();
     parseopts();
+    pushing();
     badusage "-p is not allowed with dgit push" if defined $package;
     check_not_dirty();
     my $clogp = parsechangelog();
     badusage "-p is not allowed with dgit push" if defined $package;
     check_not_dirty();
     my $clogp = parsechangelog();
@@ -2823,10 +2838,12 @@ sub clean_tree () {
 
 sub cmd_clean () {
     badusage "clean takes no additional arguments" if @ARGV;
 
 sub cmd_clean () {
     badusage "clean takes no additional arguments" if @ARGV;
+    notpushing();
     clean_tree();
 }
 
 sub build_prep () {
     clean_tree();
 }
 
 sub build_prep () {
+    notpushing();
     badusage "-p is not allowed when building" if defined $package;
     check_not_dirty();
     clean_tree();
     badusage "-p is not allowed when building" if defined $package;
     check_not_dirty();
     clean_tree();
@@ -3030,7 +3047,7 @@ sub parseopts () {
            } elsif (m/^--since-version=([^_]+|_)$/) {
                push @ropts, $_;
                $changes_since_version = $1;
            } elsif (m/^--since-version=([^_]+|_)$/) {
                push @ropts, $_;
                $changes_since_version = $1;
-           } elsif (m/^--([-0-9a-z]+)=(.*)/s &&
+           } elsif (m/^--([-0-9a-z]+)=(.+)/s &&
                     ($om = $opts_opt_map{$1}) &&
                     length $om->[0]) {
                push @ropts, $_;
                     ($om = $opts_opt_map{$1}) &&
                     length $om->[0]) {
                push @ropts, $_;
@@ -3039,7 +3056,7 @@ sub parseopts () {
                     !$opts_opt_cmdonly{$1} &&
                     ($om = $opts_opt_map{$1})) {
                push @ropts, $_;
                     !$opts_opt_cmdonly{$1} &&
                     ($om = $opts_opt_map{$1})) {
                push @ropts, $_;
-               push @$om, $2;
+               push @{ $opts_opt_cmdline_opts{$1} }, $2;
            } elsif (m/^--existing-package=(.*)/s) {
                push @ropts, $_;
                $existing_package = $1;
            } elsif (m/^--existing-package=(.*)/s) {
                push @ropts, $_;
                $existing_package = $1;
@@ -3146,6 +3163,38 @@ sub parseopts () {
     }
 }
 
     }
 }
 
+sub finalise_opts_opts () {
+    foreach my $k (keys %opts_opt_map) {
+       my $om = $opts_opt_map{$k};
+
+       my $v = access_cfg("cmd-$k", 'RETURN-UNDEF');
+       if (defined $v) {
+           badcfg "cannot set command for $k"
+               unless length $om->[0];
+           $om->[0] = $v;
+       }
+
+       foreach my $c (access_cfg_cfgs("opts-$k")) {
+           local ($debuglevel) = $debuglevel-2;
+           my @cmd = (@git, qw(config -z --get-all), $c);
+           my $vs = cmdoutput_errok @cmd;
+           if ($?==0) {
+               badcfg "cannot configure options for $k"
+                   if $opts_opt_cmdonly{$k};
+               push @$om, split /\0/, $vs;
+           } elsif ($?==256) {
+               die "$k $c ?" if length $vs;
+           } else {
+               failedcmd @cmd;
+           }
+       }
+    }
+
+    foreach my $k (keys %opts_opt_cmdline_opts) {
+       push @{ $opts_opt_map{$k} }, @{ $opts_opt_cmdline_opts{$k} };
+    }
+}
+
 if ($ENV{$fakeeditorenv}) {
     quilt_fixup_editor();
 }
 if ($ENV{$fakeeditorenv}) {
     quilt_fixup_editor();
 }