Re: New copyright program - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: New copyright program
Date
Msg-id 201108192331.p7JNViu08867@momjian.us
Whole thread Raw
In response to Re: New copyright program  (Kris Jurka <books@ejurka.com>)
Responses Re: New copyright program
List pgsql-hackers
Kris Jurka wrote:
>
>
> On Fri, 19 Aug 2011, Bruce Momjian wrote:
>
> > Was able to reproduce the error you reported with Perl 5.10.  I then
> > tried the single-quote idea I got from Googling, but then got an error
> > about TIEARRAY being missing, so I recoded it as a simple file
> > open/close.  I also incorported your regex fix.  Path attached and
> > applied.  Thanks.
> >
>
> Did you also try the "use Tie::File" addition in my fix because your
> current coding doesn't work at all.  The tie operation is key to actually
> writing out the modified copyright notice.  Your version just updates the
> copyright year in memory, but never gets it back to the file.

Ah, that did fix it;  thanks.  I am attached the updated committed
copyright.pl.  I also skipped symlinks.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
#!/usr/bin/perl
#################################################################
# copyright.pl -- update copyright notices throughout the source tree, idempotently.
#
# Copyright (c) 2011, PostgreSQL Global Development Group
#
# src/tools/copyright.pl
#################################################################

use strict;
use warnings;

use File::Find;
use Tie::File;

my $pgdg = 'PostgreSQL Global Development Group';
my $cc = 'Copyright \(c\) ';
# year-1900 is what localtime(time) puts in element 5
my $year = 1900 + ${[localtime(time)]}[5];

print "Using current year:  $year\n";

find({wanted => \&wanted, no_chdir => 1}, '.');

sub wanted {
    return if ! -f $File::Find::name || -l $File::Find::name;

    my @lines;
    tie @lines, "Tie::File", $File::Find::name;

    foreach my $line (@lines) {
        # We only care about lines with a copyright notice.
        next unless $line =~ m/$cc.*$pgdg/;
        # We stop when we've done one substitution.  This is both for
        # efficiency and, at least in the case of this program, for
        # correctness.
        last if $line =~ m/$cc.*$year.*$pgdg/;
        last if $line =~ s/($cc\d{4})(, $pgdg)/$1-$year$2/;
        last if $line =~ s/($cc\d{4})-\d{4}(, $pgdg)/$1-$year$2/;
    }
    untie @lines;
}

print "Manually update doc/src/sgml/legal.sgml and src/interfaces/libpq/libpq.rc.in too\n";


pgsql-hackers by date:

Previous
From: Kris Jurka
Date:
Subject: Re: New copyright program
Next
From: Andrew Dunstan
Date:
Subject: Re: New copyright program