On Fri, Nov 04, 2016 at 02:06:25PM -0700, Jeremy Evans wrote:
> This is not a great patch, at least because if other non REVISION
> changes are made, it won't bump revision even if set so.  Also, perl is
> not my native language, so this may be very ugly to someone who actually
> knows perl.

Being a perl programmer, I probably would have done something like:

        if ($opt_r and !$nchanges) {
                        # If bumping REVISION and REVISION is not present
                        # then REVISION needs to be added.
                        open my $in, '<', $outpath
                            or die "cannot open output file $outpath: $!";
                        open my $out, '>', "$outpath.bump"
                            or die "cannot open output file $outpath.bump: $!";
                        while (readline($in)) {
                                print $out $_;
                                if (!$nchanges and 
/^(?:DIST|(FULL)?PKG)NAME.+$/) {
                                        print $out "REVISION =\t0\n";
                                        $nchanges++;
                                }
                        }
                        close $in;
                        close $out;
                        warn "Couldn't insert revision in $outpath!"
                            unless $nchanges;
                }

> However, I think this is still better than what we have now.

So not significantly different, but does provide feedback if it failed.
One thing with perl programmers, the important thing is that it gets the
job done and you get to go home at the end of the day, the rest is
style, to be argued over beer.

> Thoughts? OKs?

OK by me.  But I would suggest a complaining if it didn't work,
especially since it *should* always work now.


> Jeremy
> 
> Index: portbump
> ===================================================================
> RCS file: /cvs/ports/infrastructure/bin/portbump,v
> retrieving revision 1.12
> diff -u -p -u -p -r1.12 portbump
> --- portbump  20 Mar 2016 17:19:49 -0000      1.12
> +++ portbump  4 Nov 2016 20:49:02 -0000
> @@ -1016,6 +1016,23 @@ for my $dir (keys %allpkgs) {
>               unlink $outpath;
>               $exitstatus = 1;
>       } elsif (!defined $opt_o) {
> +             if ($opt_r && !$nchanges) {
> +                     # If bumping REVISION and REVISION is not present
> +                     # then REVISION needs to be added.
> +                     local $/=undef;
> +                     open (my $in, '<', $outpath) or
> +                             die "cannot open output file $outpath";
> +                     open (my $out, '>', "$outpath.bump") or
> +                             die "cannot open output file $outpath";
> +                     $_ = <$in>;
> +                     $nchanges++ if 
> s/^((DIST|(FULL)?PKG)NAME.+)$/$1\nREVISION =     0/m;
> +                     print $out $_;
> +                     close($in);
> +                     close($out);
> +                     rename("$outpath.bump", $outpath) or
> +                             die "cannot move $outpath.bump to $outpath"
> +             }
> +
>               if (!$nchanges) {
>                       print STDERR "nothing to do in $dir\n" if $opt_v;
>                       unlink $outpath;
> 

Reply via email to