X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=i18n-diff-auditor;h=6868ca7d2c8df16f3b6fee1169a3b7c04903e06c;hp=363103fccf01e7a4f7bfc47894330d6c56fe2066;hb=91ddd61e738d009851936647142dc94975d17882;hpb=6090adb68f0ab2b79adba51212bfe7b2dff0e6df diff --git a/i18n-diff-auditor b/i18n-diff-auditor index 363103fc..6868ca7d 100755 --- a/i18n-diff-auditor +++ b/i18n-diff-auditor @@ -4,6 +4,37 @@ # Copyright (C)2018 Ian Jackson # GPLv3+, NO WARRANTY, see below. # +# +# Usage: +# something like this +# git-log -n1 -p | ./i18n-diff-auditor -D 2>&1 |less -j10 +/'^!.*' +# +# -D is for debug. Currently only one level. +# +# Output is the relevant diff hunks, with each line prepended with +# space for ok lines and ! for questionable ones, and with relevant +# diff lines prepended with lines starting !! (and lines starting # +# for debug output), so ovrall: +# +# !! reasoning for subsequent questionable diff line(s) +# !+ diff line found to be questionable +# !- diff line found to be questionable +# @@@ etc. diff furniture +# + diff line checked and ok +# - diff line checked and ok +# # debug output (normally precedes relevant output) +# +# Changes are generally marked as ok if they correspond to a known +# intended code change pattern. (That includes changing error calls +# to different error calls.) If they don't correspond to any known +# pattern, they are "questionable" and the first thing that doesn't +# match the most common pattern is reported. +# +# Might be useful for projects other than dgit, provided it uses +# the same gettext aliases (__ f_ i_) and similar error calls +# (die, confess, fail). +# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -189,6 +220,7 @@ sub semiparse ($) { push @o, { T => 'specvar', E => $&, P => $& }; } elsif (!length) { last; + } elsif (s{^\#.*\n}{}) { } else { m{^.{0,10}}; die "cannot tokenise \`$&'"; @@ -220,8 +252,8 @@ our @analysed_x; our @analysed_y; sub analyse_chunk_core () { + $before //= ''; die "plain deletion\n" unless defined $after; - die "plain insertion\n" unless defined $before; my @xs = semiparse $before; my @ys = semiparse $after; @analysed_x = @analysed_y = (); @@ -236,6 +268,7 @@ sub analyse_chunk_core () { my $next_x = sub { $next_something->(\@xs, \@analysed_x, \$x, 'before'); }; my $next_y = sub { $next_something->(\@ys, \@analysed_y, \$y, 'after' ); }; our @y_expect_suffix = (); + ANALYSE: for (;;) { while (my $e = shift @y_expect_suffix) { $next_y->(); @@ -249,6 +282,24 @@ sub analyse_chunk_core () { next if $x->{E} eq 'sprintf' and $y->{E} eq 'f_'; next if $x->{E} eq 'die' and $y->{E} eq 'confess'; next if $x->{E} eq 'die' and $y->{E} eq 'fail'; + foreach my $with_fh (qw(0 1)) { + next unless $x->{E} eq 'printf'; + next unless $y->{E} eq 'print'; + next unless @xs >= $with_fh; + next unless @ys > $with_fh; + if ($with_fh) { + next unless $xs[0]{E} eq $ys[0]{E}; + next unless + $xs[0]{E} =~ m{^[A-Z]+$} or + $xs[0]{T} eq 'ident' && $xs[0]{E} =~ m{^\$}; + } + next unless $ys[$with_fh]{E} eq 'f_'; + # yay! + $next_x->() if $with_fh; + $next_y->() if $with_fh; + $next_y->(); # f_ + next ANALYSE; + } if ($y->{E} eq '+' and @ys >= 3 and $ys[0]{E} eq '('