git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Riedy <ejr@EECS.Berkeley.EDU>
To: git@vger.kernel.org
Subject: [PATCH 2/3] Use File::Find rather than find and xargs in git-archimport
Date: Fri, 10 Feb 2006 18:52:03 -0800	[thread overview]
Message-ID: <549.1139626323@lotus.CS.Berkeley.EDU> (raw)

git-archimport uses find and xargs directly to find and apply patches.
Replace these by File::Find and save one call to find.  Tested on
Solaris 8 with a quite complex, interrelated set of Arch repos.

Hopefully handles {arch} subdirectories correctly.  Thanks to Randal
Schwartz for pointing out the problem.

Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>

---

 git-archimport.perl |   39 +++++++++++++++++++++++++++++----------
 1 files changed, 29 insertions(+), 10 deletions(-)

8e7119df3d59da189baa741d44b04e7c8da2c421
diff --git a/git-archimport.perl b/git-archimport.perl
index 841738d..ffdf742 100755
--- a/git-archimport.perl
+++ b/git-archimport.perl
@@ -60,6 +60,7 @@ use Getopt::Std;
 use File::Temp qw(tempdir);
 use File::Path qw(mkpath rmtree);
 use File::Basename qw(basename dirname);
+use File::Find;
 use Data::Dumper qw/ Dumper /;
 use IPC::Open2;
 
@@ -664,17 +665,35 @@ sub apply_cset {
     # get the changeset
     safe_pipe_capture($TLA,'get-changeset',$ps->{id},"$tmp/changeset");
     die "Cannot get changeset: $!" if $?;
-    
+
+    my @patchlist;
+    my $wanted_patches = sub {
+        # We want all those non-empty *.patch files that do not modify
+        # arch state.  The preprocess argument strips out {arch}.
+	if (-f && !-z && /^.*\.patch$/) {
+	    push @patchlist, $File::Find::name;
+	}
+	if ($File::Find::dir =~ /\{arch\}/) {
+	    print STDERR "AUGH!  tested " . $File::Find::name . "\n";
+	}
+    }; # perl note: This needs to be an anonymous sub to share
+       # @patchlist correctly.
+
     # apply patches
-    if (`find $tmp/changeset/patches -type f -name '*.patch'`) {
-        # this can be sped up considerably by doing
-        #    (find | xargs cat) | patch
-        # but that cna get mucked up by patches
-        # with missing trailing newlines or the standard 
-        # 'missing newline' flag in the patch - possibly
-        # produced with an old/buggy diff.
-        # slow and safe, we invoke patch once per patchfile
-        `find $tmp/changeset/patches -type f -name '*.patch' -print0 | grep -zv '{arch}' | xargs -iFILE -0 --no-run-if-empty patch -p1 --forward -iFILE`;
+
+    # this can be sped up considerably by applying all the patches in
+    # one pass, as with
+    #    (find | xargs cat) | patch
+    # but that can get mucked up by patches with missing trailing
+    # newlines or the standard 'missing newline' flag in the patch -
+    # possibly produced with an old/buggy diff.
+    # slow and safe, we invoke patch once per patchfile
+
+    File::Find ({wanted => $wanted_patches,
+		 preprocess => sub { grep(!/^\{arch\}$/, @_); }},
+		$tmp . "/changeset/patches");
+    foreach my $patchname (@patchlist) {
+	safe_pipe_capture("patch", "-p1", "--forward", "-i", $patchname);
         die "Problem applying patches! $!" if $?;
     }
 
-- 
1.1.6.g0d39d

             reply	other threads:[~2006-02-11  2:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-11  2:52 Jason Riedy [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-02-10 23:35 [PATCH 2/3] Use File::Find rather than find and xargs in git-archimport Jason Riedy
2006-02-10 23:47 ` Randal L. Schwartz
2006-02-11  0:17   ` Jason Riedy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=549.1139626323@lotus.CS.Berkeley.EDU \
    --to=ejr@eecs.berkeley.edu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).