summaryrefslogtreecommitdiff
path: root/Porting/bump-perl-version
diff options
context:
space:
mode:
authorLeon Brocard <acme@astray.com>2011-06-23 17:39:23 +0100
committerLeon Brocard <acme@astray.com>2011-06-23 17:39:23 +0100
commitdc40e4976a788b09d14895f13b26823be4d28994 (patch)
treed4809a3f07c3b26a8ccbeb49e5ec87470699004d /Porting/bump-perl-version
parent204fc54e940e5b5a12d014e3c3d16c06a0241ce8 (diff)
downloadperl-dc40e4976a788b09d14895f13b26823be4d28994.tar.gz
Seeing as Porting/bump-perl-version is run in a git directory,
instead of writing a diff file and then applying it, this adds a -i option which makes the changes inplace
Diffstat (limited to 'Porting/bump-perl-version')
-rw-r--r--Porting/bump-perl-version34
1 files changed, 28 insertions, 6 deletions
diff --git a/Porting/bump-perl-version b/Porting/bump-perl-version
index 2023ff8797..63cb5aed45 100644
--- a/Porting/bump-perl-version
+++ b/Porting/bump-perl-version
@@ -57,6 +57,7 @@ sub usage { die <<EOF }
usage: $0 -c <C.C.C>
-s <C.C.C> <N.N.N>
-u
+ -i <C.C.C> <N.N.N>
-c check files and warn if any known string values (eg
PERL_SUBVERSION) don't match the specified version
@@ -65,12 +66,14 @@ usage: $0 -c <C.C.C>
-u read in the scan file from stdin, and change all the lines specified
+ -i scan files and make changes inplace
+
C.C.C the current perl version, eg 5.10.0
N.N.N the new perl version, eg 5.10.1
EOF
my %opts;
-getopts('csu', \%opts) or usage;
+getopts('csui', \%opts) or usage;
if ($opts{u}) {
@ARGV == 0 or usage('no version version numbers should be specified');
# fake to stop warnings when calculating $oldx etc
@@ -83,7 +86,7 @@ elsif ($opts{c}) {
else {
@ARGV == 2 or usage('require two version numbers');
}
-usage('only one of -c, -s and -u') if keys %opts > 1;
+usage('only one of -c, -s, -u and -i') if keys %opts > 1;
my ($oldx, $oldy, $oldz) = $ARGV[0] =~ /^(\d+)\.(\d+)\.(\d+)$/
or usage("bad version: $ARGV[0]");
@@ -219,7 +222,7 @@ my @mani_files = sort keys %{ExtUtils::Manifest::maniread('MANIFEST')};
my %mani_files = map { ($_ => 1) } @mani_files;
die "No entries found in MANIFEST; aborting\n" unless @mani_files;
-if ($opts{c} or $opts{s}) {
+if ($opts{c} or $opts{s} or $opts{i}) {
do_scan();
}
elsif ($opts{u}) {
@@ -242,8 +245,13 @@ sub do_scan {
}
open my $fh, '<', $file;
my $header = 0;
+ my @stat = stat $file;
+ my $mode = $stat[2];
+ my $file_changed = 0;
+ my $new_contents = '';
while (<$fh>) {
+ my $line_changed;
for my $map (@maps) {
my ($pat, $sub, $expected, $file_pat) = @$map;
@@ -258,13 +266,27 @@ sub do_scan {
my $newstr = $_;
$newstr =~ s/$pat/$replacement/
or die "Internal error: substitution failed: [$pat]\n";
+ $new_contents .= $newstr if $opts{i};
if ($_ ne $newstr) {
- print "\n$file\n" unless $header;
- $header=1;
- printf "\n%5d: -%s +%s", $., $_, $newstr;
+ $file_changed = 1;
+ $line_changed = 1;
+ if ($opts{s}) {
+ print "\n$file\n" unless $header;
+ $header=1;
+ printf "\n%5d: -%s +%s", $., $_, $newstr;
+ }
}
last;
}
+ $new_contents .= $_ if $opts{i} && !$line_changed ;
+ }
+ if ($opts{i} && $file_changed) {
+ warn "Updating $file inplace\n";
+ open my $fh, '>', $file;
+ binmode $fh;
+ print $fh $new_contents;
+ close $fh;
+ chmod $mode & 0777, $file;
}
}
warn "(skipped $_/*)\n" for @SKIP_DIRS;