diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index a4316fbb3..9d16e642f 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -272,6 +272,34 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
}
}
+ # Select the format to use
+ if (not defined $build_format) {
+ if (-e "$dir/debian/source/format") {
+ open(my $format_fh, '<', "$dir/debian/source/format")
+ or syserr(g_('cannot read %s'), "$dir/debian/source/format");
+ $build_format = <$format_fh>;
+ chomp($build_format) if defined $build_format;
+ error(g_('%s is empty'), "$dir/debian/source/format")
+ unless defined $build_format and length $build_format;
+ close($format_fh);
+ } else {
+ warning(g_('no source format specified in %s, ' .
+ 'see dpkg-source(1)'), 'debian/source/format')
+ if $options{opmode} eq 'build';
+ $build_format = '1.0';
+ }
+ }
+ $fields->{'Format'} = $build_format;
+ $srcpkg->upgrade_object_type(); # Fails if format is unsupported
+ # Parse command line options
+ $srcpkg->init_options();
+ $srcpkg->parse_cmdline_options(@cmdline_options);
+
+ if ($options{opmode} eq 'print-format') {
+ print $fields->{'Format'} . "\n";
+ exit(0);
+ }
+
# Scan control info of binary packages
my @pkglist;
foreach my $pkg ($control->get_packages()) {
@@ -394,33 +422,7 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
$fields->{'Binary'} =~ s/(.{0,980}), ?/$1,\n/g;
}
- # Select the format to use
- if (not defined $build_format) {
- if (-e "$dir/debian/source/format") {
- open(my $format_fh, '<', "$dir/debian/source/format")
- or syserr(g_('cannot read %s'), "$dir/debian/source/format");
- $build_format = <$format_fh>;
- chomp($build_format) if defined $build_format;
- error(g_('%s is empty'), "$dir/debian/source/format")
- unless defined $build_format and length $build_format;
- close($format_fh);
- } else {
- warning(g_('no source format specified in %s, ' .
- 'see dpkg-source(1)'), 'debian/source/format')
- if $options{opmode} eq 'build';
- $build_format = '1.0';
- }
- }
- $fields->{'Format'} = $build_format;
- $srcpkg->upgrade_object_type(); # Fails if format is unsupported
- # Parse command line options
- $srcpkg->init_options();
- $srcpkg->parse_cmdline_options(@cmdline_options);
-
- if ($options{opmode} eq 'print-format') {
- print $fields->{'Format'} . "\n";
- exit(0);
- } elsif ($options{opmode} eq 'before-build') {
+ if ($options{opmode} eq 'before-build') {
$srcpkg->before_build($dir);
exit(0);
} elsif ($options{opmode} eq 'after-build') {