summaryrefslogtreecommitdiff
path: root/git-svn.perl
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-19 13:49:00 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-19 14:07:24 -0800
commita5b80d92632a2d76325d4b6e6161022171a9fee4 (patch)
treee225a55790c2d58084f5e2d8a8b7121af95525d7 /git-svn.perl
parent94058a90cf3e10122037cd80ea48d3d52be5efd9 (diff)
downloadgit-a5b80d92632a2d76325d4b6e6161022171a9fee4.tar.gz
git svn: make empty directory creation gc-aware
The "git svn gc" command creates and appends to unhandled.log.gz files which should be parsed before the uncompressed unhandled.log files. Reported-by: Robert Zeh Signed-off-by: Eric Wong <normalperson@yhbt.net>
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-xgit-svn.perl45
1 files changed, 34 insertions, 11 deletions
diff --git a/git-svn.perl b/git-svn.perl
index a4b052c71e..d362de7364 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2740,21 +2740,44 @@ sub do_fetch {
sub mkemptydirs {
my ($self, $r) = @_;
+
+ sub scan {
+ my ($r, $empty_dirs, $line) = @_;
+ if (defined $r && $line =~ /^r(\d+)$/) {
+ return 0 if $1 > $r;
+ } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
+ $empty_dirs->{$1} = 1;
+ } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
+ my @d = grep {m[^\Q$1\E(/|$)]} (keys %$empty_dirs);
+ delete @$empty_dirs{@d};
+ }
+ 1; # continue
+ };
+
my %empty_dirs = ();
+ my $gz_file = "$self->{dir}/unhandled.log.gz";
+ if (-f $gz_file) {
+ if (!$can_compress) {
+ warn "Compress::Zlib could not be found; ",
+ "empty directories in $gz_file will not be read\n";
+ } else {
+ my $gz = Compress::Zlib::gzopen($gz_file, "rb") or
+ die "Unable to open $gz_file: $!\n";
+ my $line;
+ while ($gz->gzreadline($line) > 0) {
+ scan($r, \%empty_dirs, $line) or last;
+ }
+ $gz->gzclose;
+ }
+ }
- open my $fh, '<', "$self->{dir}/unhandled.log" or return;
- binmode $fh or croak "binmode: $!";
- while (<$fh>) {
- if (defined $r && /^r(\d+)$/) {
- last if $1 > $r;
- } elsif (/^ \+empty_dir: (.+)$/) {
- $empty_dirs{$1} = 1;
- } elsif (/^ \-empty_dir: (.+)$/) {
- my @d = grep {m[^\Q$1\E(/|$)]} (keys %empty_dirs);
- delete @empty_dirs{@d};
+ if (open my $fh, '<', "$self->{dir}/unhandled.log") {
+ binmode $fh or croak "binmode: $!";
+ while (<$fh>) {
+ scan($r, \%empty_dirs, $_) or last;
}
+ close $fh;
}
- close $fh;
my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
foreach my $d (sort keys %empty_dirs) {