chiark / gitweb /
dgit: factor out build_or_push_prep_early sub
authorSean Whitton <spwhitton@spwhitton.name>
Sun, 12 Feb 2017 23:14:24 +0000 (16:14 -0700)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 26 Jul 2017 21:52:28 +0000 (22:52 +0100)
This is to permit code deduplication between the commands for pushing
and building.  Both these sets of commands deny usage of -p, and set
$isuite, $package and $version based on the changelog.

In particular, a command that will perform a build /and/ a push can
first perform the check for -p, set $package and then call functions
to do the build.  These latter functions will not complain that
$package is set thanks to the $build_or_push_prep_early_done logic.

No functional change.

Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Acked-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index c17b42a967645446189383765216bce9a61ddb46..d772a9037c7b9aab429ccc0e2df9ad39f4754bf8 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -4494,10 +4494,9 @@ END
 
 sub prep_push () {
     parseopts();
-    badusage "-p is not allowed with dgit $subcommand" if defined $package;
+    build_or_push_prep_early();
+    pushing();
     check_not_dirty();
-    my $clogp = parsechangelog();
-    $package = getfield $clogp, 'Source';
     my $specsuite;
     if (@ARGV==0) {
     } elsif (@ARGV==1) {
@@ -4505,8 +4504,6 @@ sub prep_push () {
     } else {
        badusage "incorrect arguments to dgit $subcommand";
     }
-    $isuite = getfield $clogp, 'Distribution';
-    pushing();
     if ($new_package) {
        local ($package) = $existing_package; # this is a hack
        canonicalise_suite();
@@ -5822,14 +5819,18 @@ sub cmd_clean () {
     maybe_unapply_patches_again();
 }
 
-sub build_prep_early () {
-    our $build_prep_early_done //= 0;
-    return if $build_prep_early_done++;
-    badusage "-p is not allowed when building" if defined $package;
+sub build_or_push_prep_early () {
+    our $build_or_push_prep_early_done //= 0;
+    return if $build_or_push_prep_early_done++;
+    badusage "-p is not allowed with dgit $subcommand" if defined $package;
     my $clogp = parsechangelog();
     $isuite = getfield $clogp, 'Distribution';
     $package = getfield $clogp, 'Source';
     $version = getfield $clogp, 'Version';
+}
+
+sub build_prep_early () {
+    build_or_push_prep_early();
     notpushing();
     check_not_dirty();
 }