diff options
author | edwin <edwin@FreeBSD.org> | 2008-07-06 10:00:52 +0800 |
---|---|---|
committer | edwin <edwin@FreeBSD.org> | 2008-07-06 10:00:52 +0800 |
commit | 84429f28e828f2d4eebd16a8e6d61225129913ce (patch) | |
tree | 4e569c59f5baa097fa4cb859041dc65f30baaed1 /Tools | |
parent | 0b96cbb6aa4dcdebf437d7b4b3af765961d41d33 (diff) | |
download | freebsd-ports-gnome-84429f28e828f2d4eebd16a8e6d61225129913ce.tar.gz freebsd-ports-gnome-84429f28e828f2d4eebd16a8e6d61225129913ce.tar.zst freebsd-ports-gnome-84429f28e828f2d4eebd16a8e6d61225129913ce.zip |
[PATCH] Tools/scripts: Some cleanups, additions to bump_version.pl
- added -c, doesn't change anything
- added -n, deal with an already checkouted tree
- removed negative logic in favor of 'unless'
- switch to 3 arg form of open()
- don't use globs for filehandles, this is been obsolete
since at least 5.6.1
- handle possible errors in close()
- allow CVSROOT to be overriden in the ENV
PR: ports/125025
Submitted by: "Philip M. Gollucci" <pgollucci@p6m7g8.com>
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/bump_revision.pl | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/Tools/scripts/bump_revision.pl b/Tools/scripts/bump_revision.pl index 6e47e6f13443..7fe997c20aa8 100755 --- a/Tools/scripts/bump_revision.pl +++ b/Tools/scripts/bump_revision.pl @@ -10,15 +10,18 @@ use Getopt::Std; use strict; use Cwd; use Data::Dumper; +use File::Basename; -use vars qw/$opt_i $opt_u/; +use vars qw/$opt_c $opt_n $opt_i $opt_u/; sub usage { print <<EOF; Usage: $0 [options] [<category>/]<portname> - -u <username> - Your freebsd.org username. Defaults to \$ENV{USER}. - -i <filename> - Use this for INDEX name. Defaults to /usr/ports/INDEX. + -c - Just check + -n - No tmpdir, just use dirname(INDEX) + -u <username> - Your freebsd.org username. Defaults to \$ENV{USER}. + -i <filename> - Use this for INDEX name. Defaults to /usr/ports/INDEX. Questions, suggestions etc -> edwin\@freebsd.org EOF @@ -30,16 +33,16 @@ my $USER = $ENV{USER}; { $opt_i = ""; $opt_u = ""; - getopts("i:u:"); + getopts("cni:u:"); $INDEX = $opt_i if ($opt_i); $USER = $opt_u if ($opt_u); - die "$INDEX doesn't seem to exist. Please check the value supplied with -i or use -i." if (! -f $INDEX); + die "$INDEX doesn't seem to exist. Please check the value supplied with -i or use -i." unless(-f $INDEX); } my $PORT = $ARGV[0]; -usage() if (!$PORT); +usage() unless($PORT); -my $CVSROOT = ":ext:$USER\@pcvs.freebsd.org:/home/pcvs"; +my $CVSROOT = $ENV{CVSROOT} // ':ext:$USER\@pcvs.freebsd.org:/home/pcvs'; # # Read the index, save some interesting keys @@ -47,10 +50,10 @@ my $CVSROOT = ":ext:$USER\@pcvs.freebsd.org:/home/pcvs"; my %index = (); { print "Reading $INDEX\n"; - open(FIN, "$INDEX") or die "Cannot open $INDEX for reading."; - my @lines = <FIN>; + open(my $fin, '<', "$INDEX") or die "Cannot open $INDEX for reading."; + my @lines = <$fin>; chomp(@lines); - close(FIN); + close($fin); foreach my $line (@lines) { my @a = split(/\|/, $line); @@ -80,9 +83,7 @@ my %index = (); # If specified as category/portname, that should be enough. # If specified as portname, check all indexes for existence or duplicates. # -if (defined $index{$PORT}) { - # all okay -} else { +unless (defined $index{$PORT}) { my $count = 0; my $n = ""; foreach my $p (keys(%index)) { @@ -126,13 +127,15 @@ my $ports = ""; # Create a temp directory and cvs checkout the ports # (don't do error checking, too complicated right now) # -my $TMPDIR = getcwd()."/.tmpdir.$$"; -{ - mkdir($TMPDIR, 0755); - chdir($TMPDIR); - `cvs -d $CVSROOT co -T $ports`; + +my $TMPDIR = File::Basename::dirname($INDEX); +unless ($opt_n) { + $TMPDIR = getcwd() . "/.tmpdir.$$"; + mkdir($TMPDIR, 0755); + chdir($TMPDIR); + system "cvs -d $CVSROOT co -T $ports"; + chdir($TMPDIR); } -chdir($TMPDIR); # # Bump portrevisions @@ -143,13 +146,15 @@ chdir($TMPDIR); my $makefile = "ports/$p/Makefile"; print "- Updating Makefile of $p\n"; + next if $opt_c; - if (!open(FIN, $makefile)) { + my $fin; + unless(open($fin, $makefile)) { print "-- Cannot open Makefile of $p, ignored.\n"; next; } - my @lines = <FIN>; - close(FIN); + my @lines = <$fin>; + close($fin) or die "Can't close $makefile b/c $!"; chomp(@lines); my $revision = 1; @@ -160,28 +165,28 @@ chdir($TMPDIR); } my $printedrev = 0; - open(FOUT, ">$makefile"); + open(my $fout, '>', "$makefile"); foreach my $line (@lines) { if (!$printedrev) { if ($line =~ /^CATEGORIES??=/ || $line =~ /^PORTEPOCH??=/) { - print FOUT "PORTREVISION= $revision\n"; + print $fout "PORTREVISION= $revision\n"; $printedrev = 1; # Fall through! } if ($line =~ /^PORTREVISION\?=/) { - print FOUT "PORTREVISION?= $revision\n"; + print $fout "PORTREVISION?= $revision\n"; $printedrev = 1; next; } if ($line =~ /^PORTREVISION=/) { - print FOUT "PORTREVISION= $revision\n"; + print $fout "PORTREVISION= $revision\n"; $printedrev = 1; next; } } - print FOUT "$line\n"; + print $fout "$line\n"; } - close(FOUT); + close($fout) or die "Can't close $makefile b/c $!"; } } |