summaryrefslogtreecommitdiff
path: root/scripts/Dpkg/Source/Package
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2012-12-30 02:49:36 +0100
committerGuillem Jover <guillem@debian.org>2013-04-29 18:45:54 +0200
commitf215ebacf1183e33da3287533c8eec60cc5af418 (patch)
tree458435c1647bf7845cec876d15d8c50d6a4d473e /scripts/Dpkg/Source/Package
parent193cfded7822eab6d63e200037ac86df6ba98521 (diff)
downloaddpkg-f215ebacf1183e33da3287533c8eec60cc5af418.tar.gz
scripts: Do not use "nested" functions as they are global
Even if these functions are defined inside another function, they are still global, make them proper global functions by moving the definition outside of the outter function and mark them explicitly as being private by using an underscore prefix. There's no point in making these anonymous nested functions, as they do not need to access any variable from the outter functions. Fixes Subroutines::ProhibitNestedSubs. Warned-by: perlcritic
Diffstat (limited to 'scripts/Dpkg/Source/Package')
-rw-r--r--scripts/Dpkg/Source/Package/V2.pm29
-rw-r--r--scripts/Dpkg/Source/Package/V3/quilt.pm44
2 files changed, 39 insertions, 34 deletions
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index de1274769..1021d9e80 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -602,22 +602,25 @@ sub register_patch {
return $patch;
}
+sub _is_bad_patch_name {
+ my ($dir, $patch_name) = @_;
+
+ return 1 if not defined($patch_name);
+ return 1 if not length($patch_name);
+
+ my $patch = File::Spec->catfile($dir, "debian", "patches", $patch_name);
+ if (-e $patch) {
+ warning(_g("cannot register changes in %s, this patch already exists"),
+ $patch);
+ return 1;
+ }
+ return 0;
+}
+
sub do_commit {
my ($self, $dir) = @_;
my ($patch_name, $tmpdiff) = @{$self->{'options'}{'ARGV'}};
- sub bad_patch_name {
- my ($dir, $patch_name) = @_;
- return 1 if not defined($patch_name);
- return 1 if not length($patch_name);
- my $patch = File::Spec->catfile($dir, "debian", "patches", $patch_name);
- if (-e $patch) {
- warning(_g("cannot register changes in %s, this patch already exists"), $patch);
- return 1;
- }
- return 0;
- }
-
$self->prepare_build($dir);
# Try to fix up a broken relative filename for the patch
@@ -645,7 +648,7 @@ sub do_commit {
info(_g("there are no local changes to record"));
return;
}
- while (bad_patch_name($dir, $patch_name)) {
+ while (_is_bad_patch_name($dir, $patch_name)) {
# Ask the patch name interactively
print STDOUT _g("Enter the desired patch name: ");
chomp($patch_name = <STDIN>);
diff --git a/scripts/Dpkg/Source/Package/V3/quilt.pm b/scripts/Dpkg/Source/Package/V3/quilt.pm
index 3b7d0e319..f32a49909 100644
--- a/scripts/Dpkg/Source/Package/V3/quilt.pm
+++ b/scripts/Dpkg/Source/Package/V3/quilt.pm
@@ -214,25 +214,27 @@ sub check_patches_applied {
$self->apply_patches($dir, usage => 'preparation', verbose => 1);
}
-sub register_patch {
- my ($self, $dir, $tmpdiff, $patch_name) = @_;
+sub _add_line {
+ my ($file, $line) = @_;
- sub add_line {
- my ($file, $line) = @_;
- open(my $file_fh, ">>", $file) || syserr(_g("cannot write %s"), $file);
- print $file_fh "$line\n";
- close($file_fh);
- }
+ open(my $file_fh, ">>", $file) || syserr(_g("cannot write %s"), $file);
+ print $file_fh "$line\n";
+ close($file_fh);
+}
- sub drop_line {
- my ($file, $re) = @_;
- open(my $file_fh, "<", $file) || syserr(_g("cannot read %s"), $file);
- my @lines = <$file_fh>;
- close($file_fh);
- open($file_fh, ">", $file) || syserr(_g("cannot write %s"), $file);
- print($file_fh $_) foreach grep { not /^\Q$re\E\s*$/ } @lines;
- close($file_fh);
- }
+sub _drop_line {
+ my ($file, $re) = @_;
+
+ open(my $file_fh, "<", $file) || syserr(_g("cannot read %s"), $file);
+ my @lines = <$file_fh>;
+ close($file_fh);
+ open($file_fh, ">", $file) || syserr(_g("cannot write %s"), $file);
+ print($file_fh $_) foreach grep { not /^\Q$re\E\s*$/ } @lines;
+ close($file_fh);
+}
+
+sub register_patch {
+ my ($self, $dir, $tmpdiff, $patch_name) = @_;
my $quilt = $self->build_quilt_object($dir);
@@ -255,8 +257,8 @@ sub register_patch {
$quilt->setup_db();
# Add patch to series file
if (not $has_patch) {
- add_line($series, $patch_name);
- add_line($applied, $patch_name);
+ _add_line($series, $patch_name);
+ _add_line($applied, $patch_name);
$quilt->load_series();
$quilt->load_db();
}
@@ -268,8 +270,8 @@ sub register_patch {
} else {
# Remove auto_patch from series
if ($has_patch) {
- drop_line($series, $patch_name);
- drop_line($applied, $patch_name);
+ _drop_line($series, $patch_name);
+ _drop_line($applied, $patch_name);
erasedir($quilt->get_db_file($patch_name));
$quilt->load_db();
$quilt->load_series();