Use File::Find rather than find and xargs in git-archimport
PATCH 2/3 Use File::Find rather than find and xargs in git-archimport
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 moderately complex, interrelated set of Arch repos.
---
git-archimport.perl | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-)
5cd391ce78022806bbe12d5fda5ff49843e53207
git-archimport.perl +24 -10
@@ -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,30 @@ 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. + if (-f && !-z && /^.*\.patch$/ && !/{arch}/) { + push @patchlist, $File::Find::name; + } + }; # 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_patches, $tmp . "/changeset/patches"); + foreach my $patchname (@patchlist) { + safe_pipe_capture("patch", "-p1", "--forward", "-i", $patchname); die "Problem applying patches! $!" if $?; }
Signature · 1 line
1.1.6.g0d39d
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jason" == Jason Riedy <[email protected]> writes:
Jason> + if (-f && !-z && /^.*\.patch$/ && !/{arch}/) {
If that works, it's only accidentally. Perhaps you wanted !/\{arch\}/ because curlies are special to regex. Dunno, because I don't know what you're excluding.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
And Randal L. Schwartz writes:
- Jason> + if (-f && !-z && /^.*\.patch$/ && !/{arch}/) {
-
- If that works, it's only accidentally.
Thanks! Not only is the regex wrong, it's applied to the wrong quantity. Should be on $File::Find::dir. Looks like the repos I tested against didn't have any Arch state patches.
I'll fix this, test it on a nastier set of repos, and re- send. It'll be an hour or so, at least.
Jason