diff options
author | Steve McIntyre <93sam> | 2018-05-30 02:26:19 +0000 |
---|---|---|
committer | Steve McIntyre <93sam> | 2018-05-30 02:26:19 +0000 |
commit | afdb29732ca24242f1a2e94f98e90034f9925f46 (patch) | |
tree | e7fd6434eca8cdc6b4d1f8b917290cc45af5b374 /smart_change.pl | |
parent | 85831e64ab93ed694a25e2e6ccaaff73d9fddeea (diff) |
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
Diffstat (limited to 'smart_change.pl')
-rwxr-xr-x | smart_change.pl | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/smart_change.pl b/smart_change.pl index dcf2ce53527..c81df65ba10 100755 --- a/smart_change.pl +++ b/smart_change.pl @@ -12,11 +12,11 @@ use Getopt::Long; # These modules reside under webwml/Perl use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl"; -use Local::Cvsinfo; +use Local::VCS; use Webwml::TransCheck; use Webwml::Langs; -our ($opt_h, $opt_v, $opt_n, $opt_p, @opt_l, @opt_s); +our ($opt_h, $opt_v, $opt_n, @opt_l, @opt_s); sub usage { print <<'EOT'; @@ -25,11 +25,23 @@ Options: -h, --help display this message -v, --verbose run verbosely -n, --no-bump do not bump translation-check headers - -p, --previous get previous CVS revision -l, --lang=STRING process this language (may be used more than once) -s, --substitute=REGEXP Perl regexp applied to source files (may be used more than once) + +This is a *NEW* implementation of smart_change.pl which is limited to +supporting git commit hashes. To use this: + + 1. Make the changes to the original file(s), and commit + 2. Update translations + 3. Run smart_change.pl - it will pick up the changes and update + headers in the translation files + 4. Commit the translation changes + +This is more involved than previously (needing two commits), but +unavoidable... + EOT exit(0); } @@ -53,8 +65,7 @@ sub verbose { print STDERR $_[0] . "\n" if $opt_v; } -# We call constructor without argument. It means there must be a -# CVS/Repository file or program will abort. +# We call constructor without argument. if (not @opt_l) { my $l = Webwml::Langs->new(); @opt_l = $l->names(); @@ -71,21 +82,15 @@ die "Invalid -s option" if $@; foreach my $argfile (@ARGV) { $argfile =~ m+^(english.*)/(.*\.(wml|src))+ or die "unknown path '$argfile'"; - my ($path, $file) = ($1, $2); verbose("File: $argfile"); - my $cvs = Local::Cvsinfo->new(); - $cvs->options(matchfile => [ $file ]); - $cvs->readinfo($path); - my $origrev = $cvs->revision($argfile) || "1.0"; - if ($opt_p) { - $origrev =~ s/(\d+)$/($1 - 1)/e; - } + my $VCS = Local::VCS->new(); + my %file_info = $VCS->file_info($argfile); + my $origrev = $file_info{'cmt_rev'} or die "Can't find revision information for original file $argfile\n"; verbose("Original revision: $origrev"); - my $nextrev = $origrev; - $nextrev =~ s/(\d+)$/(1+$1)/e; - verbose("Next revision: $nextrev"); + my $prevrev = $VCS->next_revision($argfile, $origrev, -1); + verbose("Previous revision: $prevrev"); foreach my $lang (@opt_l) { my $transfile = $argfile; @@ -98,17 +103,19 @@ foreach my $argfile (@ARGV) { next unless $transcheck->revision() || $lang eq 'english'; my $langrev = $transcheck->revision(); + if (defined $langrev and $langrev =~ m/^$origrev$/) { + print " $transfile already claims to be a translation for $argfile rev $origrev\n"; + } + my $origtext = ''; my $transtext = ''; open (TRANS, "< $transfile"); while (<TRANS>) { $origtext .= $_; if (m/^#use wml::debian::translation-check/ && !$opt_n && - ($langrev eq $origrev || $langrev eq $nextrev)) { - # Also check for $nextrev in case this script - # is run several times - s/(translation="?)($origrev|$nextrev)("?)/$1$nextrev$3/; - verbose("Bump version number to $nextrev"); + ($langrev eq $prevrev)) { + s/(translation="?)($prevrev)("?)/$1$origrev$3/; + verbose("Bump version number to $origrev"); } $transtext .= $_; } |