{"thread":{"id":"3297","subject":"[PATCH 2/3] Use File::Find rather than find and xargs in git-archimport","startedAt":"2006-02-11T02:52:03Z","lastAt":"2006-02-11T02:52:03Z","messageCount":1,"participants":["Jason Riedy"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"15896","messageId":"549.1139626323@lotus.CS.Berkeley.EDU","threadId":"3297","inReplyTo":null,"subject":"[PATCH 2/3] Use File::Find rather than find and xargs in git-archimport","fromName":"Jason Riedy","fromEmail":"ejr@eecs.berkeley.edu","sentAt":"2006-02-11T02:52:03Z","receivedAt":"2006-02-11T02:52:03Z","isPatch":true,"sender":{"key":"ejr@eecs.berkeley.edu","avatar":"https://gravatar.com/avatar/547fa56f887cab01599edab4e9f813c949c1269e02714f20e0496c56185d9837?d=mp&s=160"},"body":"git-archimport uses find and xargs directly to find and apply patches.\nReplace these by File::Find and save one call to find.  Tested on\nSolaris 8 with a quite complex, interrelated set of Arch repos.\n\nHopefully handles {arch} subdirectories correctly.  Thanks to Randal\nSchwartz for pointing out the problem.\n\nSigned-off-by: Jason Riedy <ejr@cs.berkeley.edu>\n\n---\n\n git-archimport.perl |   39 +++++++++++++++++++++++++++++----------\n 1 files changed, 29 insertions(+), 10 deletions(-)\n\n8e7119df3d59da189baa741d44b04e7c8da2c421\ndiff --git a/git-archimport.perl b/git-archimport.perl\nindex 841738d..ffdf742 100755\n--- a/git-archimport.perl\n+++ b/git-archimport.perl\n@@ -60,6 +60,7 @@ use Getopt::Std;\n use File::Temp qw(tempdir);\n use File::Path qw(mkpath rmtree);\n use File::Basename qw(basename dirname);\n+use File::Find;\n use Data::Dumper qw/ Dumper /;\n use IPC::Open2;\n \n@@ -664,17 +665,35 @@ sub apply_cset {\n     # get the changeset\n     safe_pipe_capture($TLA,'get-changeset',$ps->{id},\"$tmp/changeset\");\n     die \"Cannot get changeset: $!\" if $?;\n-    \n+\n+    my @patchlist;\n+    my $wanted_patches = sub {\n+        # We want all those non-empty *.patch files that do not modify\n+        # arch state.  The preprocess argument strips out {arch}.\n+\tif (-f && !-z && /^.*\\.patch$/) {\n+\t    push @patchlist, $File::Find::name;\n+\t}\n+\tif ($File::Find::dir =~ /\\{arch\\}/) {\n+\t    print STDERR \"AUGH!  tested \" . $File::Find::name . \"\\n\";\n+\t}\n+    }; # perl note: This needs to be an anonymous sub to share\n+       # @patchlist correctly.\n+\n     # apply patches\n-    if (`find $tmp/changeset/patches -type f -name '*.patch'`) {\n-        # this can be sped up considerably by doing\n-        #    (find | xargs cat) | patch\n-        # but that cna get mucked up by patches\n-        # with missing trailing newlines or the standard \n-        # 'missing newline' flag in the patch - possibly\n-        # produced with an old/buggy diff.\n-        # slow and safe, we invoke patch once per patchfile\n-        `find $tmp/changeset/patches -type f -name '*.patch' -print0 | grep -zv '{arch}' | xargs -iFILE -0 --no-run-if-empty patch -p1 --forward -iFILE`;\n+\n+    # this can be sped up considerably by applying all the patches in\n+    # one pass, as with\n+    #    (find | xargs cat) | patch\n+    # but that can get mucked up by patches with missing trailing\n+    # newlines or the standard 'missing newline' flag in the patch -\n+    # possibly produced with an old/buggy diff.\n+    # slow and safe, we invoke patch once per patchfile\n+\n+    File::Find ({wanted => $wanted_patches,\n+\t\t preprocess => sub { grep(!/^\\{arch\\}$/, @_); }},\n+\t\t$tmp . \"/changeset/patches\");\n+    foreach my $patchname (@patchlist) {\n+\tsafe_pipe_capture(\"patch\", \"-p1\", \"--forward\", \"-i\", $patchname);\n         die \"Problem applying patches! $!\" if $?;\n     }\n \n-- \n1.1.6.g0d39d\n"}]}