Optimized cvsexportcommit: calling 'cvs status' once instead of once per touched file.
Runtime is now independent of the number of modified files. The old implementation executed 'cvs status' for each file touched by the patch to be applied. The new code calls 'cvs status' only once with all touched files and parses cvs's output to collect all available status information. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Steffen Prohaska committed
May 10, 2007 at 01:06 UTC
c56f0d9c661dc918a088e60d0ab69dd48019a9be
1 file changed
+30
-15
git-cvsexportcommit.perl
+30
-15
@@ -160,36 +160,51 @@ foreach my $p (@afiles) {
160
}
161
}
162
163
+# ... check dirs,
164
foreach my $d (@dirs) {
165
if (-e $d) {
166
$dirty = 1;
167
warn "$d exists and is not a directory!\n";
168
}
169
}
169
-foreach my $f (@afiles) {
170
- # This should return only one value
171
- if ($f =~ m,(.*)/[^/]*$,) {
172
- my $p = $1;
173
- next if (grep { $_ eq $p } @dirs);
170
+
171
+# ... query status of all files that we have a directory for and parse output of 'cvs status' to %cvsstat.
172
+my @canstatusfiles;
173
+foreach my $f (@files) {
174
+ my $path = dirname $f;
175
+ next if (grep { $_ eq $path } @dirs);
176
+ push @canstatusfiles, $f;
177
+}
178
+
179
+my %cvsstat;
180
+if (@canstatusfiles) {
181
+ my @cvsoutput;
182
+ @cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles);
183
+ my $matchcount = 0;
184
+ foreach my $l (@cvsoutput) {
185
+ chomp $l;
186
+ if ( $l =~ /^File:/ and $l =~ /Status: (.*)$/ ) {
187
+ $cvsstat{$canstatusfiles[$matchcount]} = $1;
188
+ $matchcount++;
189
+ }
190
}
175
- my @status = grep(m/^File/, safe_pipe_capture(@cvs, '-q', 'status' ,$f));
176
- if (@status > 1) { warn 'Strange! cvs status returned more than one line?'};
177
- if (-d dirname $f and $status[0] !~ m/Status: Unknown$/
178
- and $status[0] !~ m/^File: no file /) {
191
+}
192
+
193
+# ... validate new files,
194
+foreach my $f (@afiles) {
195
+ if (defined ($cvsstat{$f}) and $cvsstat{$f} ne "Unknown") {
196
$dirty = 1;
197
warn "File $f is already known in your CVS checkout -- perhaps it has been added by another user. Or this may indicate that it exists on a different branch. If this is the case, use -f to force the merge.\n";
181
- warn "Status was: $status[0]\n";
198
+ warn "Status was: $cvsstat{$f}\n";
199
}
200
}
184
-
201
+# ... validate known files.
202
foreach my $f (@files) {
203
next if grep { $_ eq $f } @afiles;
204
# TODO:we need to handle removed in cvs
188
- my @status = grep(m/^File/, safe_pipe_capture(@cvs, '-q', 'status' ,$f));
189
- if (@status > 1) { warn 'Strange! cvs status returned more than one line?'};
190
- unless ($status[0] =~ m/Status: Up-to-date$/) {
205
+ unless (defined ($cvsstat{$f}) and $cvsstat{$f} eq "Up-to-date") {
206
$dirty = 1;
192
- warn "File $f not up to date in your CVS checkout!\n";
207
+ warn "File $f not up to date but has status '$cvsstat{$f}' in your CVS checkout!\n";
208
}
209
}
210
if ($dirty) {