From afdb29732ca24242f1a2e94f98e90034f9925f46 Mon Sep 17 00:00:00 2001 From: Steve McIntyre <93sam> Date: Wed, 30 May 2018 02:26:19 +0000 Subject: Major updates to perl scripts Add new git backend in VCS_git.pm Switch from an old-style set of function calls to an OO API. This allows for initialisation and some state to be kept in the VCS_git.pm module - namely a per-file cache of commit hashes for a massive performance boost when doing lots of lookups. Extend the API with 2 new utility functions: * get_oldest_revision() * next_revision() Extended the vcs_cmp_rev() function to take a filename too. Add a test harness to validate the git and cvs backends. Add switch_to_git_translations.pl to walk the tree and switch from cvs revisions to git commit hashes in translation-check headers. Change all of our local scripts to use the new Local::VCS frontend *where it makes sense*. Some scripts will behave slightly differently, as the new world can't exactly match the old behaviour. CVS version numbers check_desc_trans.pl: 1.9 -> 1.10 check_trans.pl: 1.93 -> 1.94 copypage.pl: 1.42 -> 1.43 karma.pl: 1.6 -> 1.7 remove_stale.pl: 1.22 -> 1.23 smart_change.pl: 1.8 -> 1.9 stattrans.pl: 1.127 -> 1.128 switch_to_git_translations.pl: INITIAL -> 1.1 touch_translations.pl: 1.9 -> 1.10 vcs-test.pl: INITIAL -> 1.1 Perl/Local/Util.pm: 1.4 -> 1.5 Perl/Local/VCS.pm: 1.3 -> 1.4 Perl/Local/VCS_CVS.pm: 1.13 -> 1.14 Perl/Local/VCS_git.pm: 1.12 -> 1.13 Perl/Webwml/Langs.pm: 1.5 -> 1.6 Perl/Webwml/TransIgnore.pm: 1.3 -> 1.4 --- copypage.pl | 86 +++---------------------------------------------------------- 1 file changed, 4 insertions(+), 82 deletions(-) (limited to 'copypage.pl') diff --git a/copypage.pl b/copypage.pl index 982fe168ea7..8394ad44750 100755 --- a/copypage.pl +++ b/copypage.pl @@ -21,7 +21,7 @@ FindBin::again(); use lib "$FindBin::Bin/Perl"; use File::Path; -use Local::VCS qw(vcs_file_info); +use Local::VCS; use File::Temp qw/tempfile/; use Getopt::Std; @@ -53,6 +53,8 @@ if (exists $ENV{DWWW_MAINT}) $maintainer = $ENV{DWWW_MAINT}; } +my $VCS = Local::VCS->new(); + # Options our ($opt_n, $opt_t, $opt_l); getopts('nm:l:'); @@ -85,7 +87,6 @@ if ($#ARGV == -1) print "\t\t(overwrites language.conf definition\n"; print "\tDWWW_MAINT\tSets maintainer for the translation\n"; print "Options:\n"; - print "\t-n\tDoes not check status of target files in CVS\n"; print "\t-m\tSets the maintainer for the translation (overwrites environment)\n"; print "\t-l\tSets the language for the translation (overwrites environment)\n"; print "\n"; @@ -190,9 +191,7 @@ sub copy } # Retrieve VCS revision number - my %vcsinfo = vcs_file_info( $srcfile ); - - find_files_attic ( $dstfile ) if ! $opt_n; + my %vcsinfo = $VCS->file_info( $srcfile ); if ( not %vcsinfo or not exists $vcsinfo{'cmt_rev'} ) { @@ -247,80 +246,3 @@ sub copy print "and to remove $dsttitle when finished\n" if defined $dsttitle; } - -# Find for old translations in the CVS Attic -sub find_files_attic -{ - my ($file) = @_; - $file =~ s/'//; - print "Checking CVS information for $file...\n"; - - # Create a temporary file for the cvs results - my ($tempfh, $tmpfile) = tempfile("cvsinfo.XXXXXX", DIR => File::Spec->tmpdir, UNLINK => 0) ; - close $tempfh; - - # Run 'cvs status'. Unfortunately, this is the only way - # to look for files in the Attic - system "LC_ALL=C cvs status '$file' >$tmpfile 2>&1"; - - if ( $? != 0 ) - { - # CVS returns an error, then cleanup and return - # Do not complain because this might happen just because we - # have no network access, just cleanup the temporary file - unlink $tmpfile; - return 0; - } - - # If CVS does not return an error then there is a file in CVS - # even if $dstfile is not in the filesystem - # There could be two reasons for this: - # - The user has removed it but somebody else put it in CVS - # - It resides in the Attic - my $deleted_version = ""; - my $previous_version = ""; - my $cvs_location = ""; - - # Parse the result of cvs status - open(TF, $tmpfile) || die ("Cannot open temporary file: $?"); - while ($line = ) { - chomp $line; - if ( $line =~ /Repository revision:\s+(\d+)\.(\d+)\s+(.*)$/ ) { - $cvs_location = $3; - $deleted_version = $1.".".$2 ; - $previous_version = $1.".".($2-1); - } - } - close TF; - unlink $tmpfile; # File is not used from here on, delete it - - # Now determine in which situation we are in: - - if ( $cvs_location eq "" ) - { -# Situation 0 - This happens when the return text is -# "Repository revision: No revision control file" - return 0; # Nothing to do here - - } - - if ( $cvs_location =~ /Attic\// ) - { -# Situation 1 - There is a translation in the Attic -# Give information on how to restore - - print STDERR "ERROR: An old translation exists in the Attic, you should restore it using:\n"; - print STDERR "\tcvs update -j $deleted_version -j $previous_version $dstfile\n"; - print STDERR "\t[Edit and update the file]\n"; - print STDERR "\tcvs ci $dstfile\n"; - die ("Old translation found\n"); - } - - # Situation 2 - There is already a file in CVS with this - # name, since it does not exist in the local copy maybe - # the local copy is not up to date - print STDERR "ERROR: A translation already exist in CVS for this file.\n"; - print STDERR "\tPlease update your CVS copy using 'cvs update'.\n"; - die ("Translation already exists\n"); - -} -- cgit v1.2.3