]> git.lyx.org Git - lyx.git/blobdiff - po/diff_po.pl
Don't allow newline characters in document settings.
[lyx.git] / po / diff_po.pl
index 7b89e6cebb4e48cf2c8c6635d92ee603a5ddc1b6..857b96aae2652b6a63d670cd66e1cc19f1407619 100755 (executable)
@@ -8,6 +8,7 @@
 # svn diff -r38367 --diff-cmd ./diff_po.pl cs.po
 # git difftool --extcmd=./diff_po.pl sk.po
 # ./diff_po.pl -r HEAD~100 cs.po       #fetch git revision and compare
+# ./diff_po.pl -r39229 cs.po           #fetch svn revision and compare
 #
 # This file is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public
 # License along with this software; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
-# author: Kornel Benko, kornel@lyx.org
+# Copyright (c) 1010-2011 Kornel Benko, kornel@lyx.org
 #
-# TODO: Search for good correlations of deleted and inserted string
-# using Text::Levenshtein or Algorithm::Diff
+# TODO:
+# 1.) Check for ".git" or ".svn" to decide about revisioning
+# 2.) Search for good correlations of deleted <==> inserted string
+#     using Text::Levenshtein or Algorithm::Diff
 
 use strict;
 use Term::ANSIColor qw(:constants);
+use File::Temp;
 
 my ($status, $foundline, $msgid, $msgstr, $fuzzy);
 
@@ -40,7 +44,6 @@ my %Fuzzy = ();                 # inside new po-file
 my $result = 0;                 # exit value
 my $printlines = 0;
 my @names = ();
-my $tmpfile = "/tmp/blax";
 
 # Check first, if called as standalone program for git
 if ($ARGV[0] =~ /^-r(.*)/) {
@@ -51,19 +54,36 @@ if ($ARGV[0] =~ /^-r(.*)/) {
   }
   for my $argf (@ARGV) {
     my $baseargf;
-    ($baseargf = $argf) =~ s/^.*\///;
-    my @args = ();
-    push(@args, "-L", $argf . "    (" . $rev . ")");
-    push(@args, "-L", $argf . "    (local copy)");
-    open(FI, "git show $rev:po/$baseargf|");
-    open(FO, '>', $tmpfile);
-    while(my $l = <FI>) {
-      print FO $l;
+    my $filedir;
+    if ($argf =~ /^(.*)\/([^\/]+)$/) {
+      $baseargf = $2;
+      $filedir = $1;
+    }
+    else {
+      $baseargf = $argf;
+      $filedir = ".";
+    }
+    if (-d "$filedir/../.git") {
+      my @args = ();
+      my $tmpfile = File::Temp->new();
+      push(@args, "-L", $argf . "    (" . $rev . ")");
+      push(@args, "-L", $argf . "    (local copy)");
+      open(FI, "git show $rev:po/$baseargf|");
+      $tmpfile->unlink_on_destroy( 1 );
+      while(my $l = <FI>) {
+       print $tmpfile $l;
+      }
+      close(FI);
+      push(@args, $tmpfile->filename, $argf);
+      print "===================================================================\n";
+      &diff_po(@args);
+    }
+    elsif (-d "$filedir/.svn") {
+      # call it again indirectly
+      my @cmd = ("svn", "diff", "-r$rev", "--diff-cmd", $0, $argf);
+      print "cmd = " . join(' ', @cmd) . "\n";
+      system(@cmd);
     }
-    close(FI);
-    close(FO);
-    push(@args, $tmpfile, $argf);
-    &diff_po(@args);
   }
 }
 else {
@@ -81,7 +101,6 @@ sub diff_po($$)
   %Untranslated = ();
   %Fuzzy = ();
   @names = ();
-  print "========================================================\n";
   while(defined($args[0])) {
     last if ($args[0] !~ /^\-/);
     my $param = shift(@args);
@@ -127,26 +146,48 @@ sub diff_po($$)
     }
   }
 
-  @MsgKeys = &getLineSortedKeys(\%Messages);
-  for my $k (@MsgKeys) {
-    $result |= 8;
-    print "deleted message\n";
-    print "< line = " . $Messages{$k}->{line} . "\n" if ($printlines);
-    print RED "< fuzzy = " . $Messages{$k}->{fuzzy} . "\n", RESET;
-    print RED "< msgid = \"$k\"\n", RESET;
-    print RED "< msgstr = \"" . $Messages{$k}->{msgstr} . "\"\n", RESET;
+  if (1) {
+    @MsgKeys = sort keys %Messages, keys %newMessages;
+    for my $k (@MsgKeys) {
+      if (defined($Messages{$k})) {
+       $result |= 8;
+       print "deleted message\n";
+       print "< line = " . $Messages{$k}->{line} . "\n" if ($printlines);
+       print RED "< fuzzy = " . $Messages{$k}->{fuzzy} . "\n", RESET;
+       print RED "< msgid = \"$k\"\n", RESET;
+       print RED "< msgstr = \"" . $Messages{$k}->{msgstr} . "\"\n", RESET;
+      }
+      if (defined($newMessages{$k})) {
+       $result |= 16;
+       print "new message\n";
+       print "> line = " . $newMessages{$k}->{line} . "\n" if ($printlines);
+       print GREEN "> fuzzy = " . $newMessages{$k}->{fuzzy} . "\n", RESET;
+       print GREEN "> msgid = \"$k\"\n", RESET;
+       print GREEN "> msgstr = \"" . $newMessages{$k}->{msgstr} . "\"\n", RESET;
+      }
+    }
   }
+  else {
+    @MsgKeys = &getLineSortedKeys(\%Messages);
+    for my $k (@MsgKeys) {
+      $result |= 8;
+      print "deleted message\n";
+      print "< line = " . $Messages{$k}->{line} . "\n" if ($printlines);
+      print RED "< fuzzy = " . $Messages{$k}->{fuzzy} . "\n", RESET;
+      print RED "< msgid = \"$k\"\n", RESET;
+      print RED "< msgstr = \"" . $Messages{$k}->{msgstr} . "\"\n", RESET;
+    }
 
-  @MsgKeys = &getLineSortedKeys(\%newMessages);
-  for my $k (@MsgKeys) {
-    $result |= 16;
-    print "new message\n";
-    print "> line = " . $newMessages{$k}->{line} . "\n" if ($printlines);
-    print GREEN "> fuzzy = " . $newMessages{$k}->{fuzzy} . "\n", RESET;
-    print GREEN "> msgid = \"$k\"\n", RESET;
-    print GREEN "> msgstr = \"" . $newMessages{$k}->{msgstr} . "\"\n", RESET;
+    @MsgKeys = &getLineSortedKeys(\%newMessages);
+    for my $k (@MsgKeys) {
+      $result |= 16;
+      print "new message\n";
+      print "> line = " . $newMessages{$k}->{line} . "\n" if ($printlines);
+      print GREEN "> fuzzy = " . $newMessages{$k}->{fuzzy} . "\n", RESET;
+      print GREEN "> msgid = \"$k\"\n", RESET;
+      print GREEN "> msgstr = \"" . $newMessages{$k}->{msgstr} . "\"\n", RESET;
+    }
   }
-
   &printExtraMessages("fuzzy", \%Fuzzy);
   &printExtraMessages("untranslated", \%Untranslated);
 }