]> err.no Git - moreutils/commitdiff
combine: Avoid reading files twice, to support data coming from pipes. Closes: #66796...
authorJoey Hess <joey@kitenet.net>
Mon, 9 Apr 2012 20:18:21 +0000 (16:18 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 9 Apr 2012 20:18:21 +0000 (16:18 -0400)
combine
debian/changelog

diff --git a/combine b/combine
index a695935b24a5f2789c71a8affc4486859a41f737..13fc2e442df918a6f3e9e7d80c0daf975b7eba0b 100755 (executable)
--- a/combine
+++ b/combine
@@ -104,9 +104,32 @@ sub compare_or {
 
 sub compare_xor {
        my ($file1, $file2) = @_;
-       
-       compare_not($file1, $file2);
-       compare_not($file2, $file1);
+
+       my ($lines2, $seen2) = ([], {});
+       filemap $file2,
+               sub {
+                       push @$lines2, $_;
+                       $seen2->{$_} = 1;
+               };
+
+       filemap $file1,
+               sub {
+                       # Print all lines in file1 that are not in file2,
+                       # and mark lines that are in both files by setting
+                       # their value in %seen2 to 0.
+                       if (exists $seen2->{$_}) {
+                               $seen2->{$_} = 0;
+                       }
+                       else {
+                               print "$_\n";
+                       }
+               };
+
+       foreach (@$lines2) {
+               # Print all lines that are in file2 but not in file1.
+               # The value of these lines in seen2 is set to 1.
+               print "$_\n" if $seen2->{$_};
+       }
 }
 
 sub compare_not {
index 13822c148288c7c10bc3253e5abfe115f8ee95d9..cd406ff9a1af769ef07c3554d0afdd9f52bfeb76 100644 (file)
@@ -1,6 +1,8 @@
 moreutils (0.46) UNRELEASED; urgency=low
 
   * Typo. Closes: #649158
+  * combine: Avoid reading files twice, to support data coming from
+    pipes. Closes: #667960 Thanks, Carsten Hey
 
  -- Joey Hess <joeyh@debian.org>  Fri, 18 Nov 2011 13:37:10 -0400