threads / discuss / 33635

Possible meaningless block in perl/Git/SVN/Fetcher.pm: sub find_empty_directories

Subject: Possible meaningless block in perl/Git/SVN/Fetcher.pm: sub find_empty_directories

## tl;dr

One message between Apr 27, 2013 and Apr 27, 2013.

replies: 0people: 1as markdown or json

Ilya Basin· Apr 27, 2013, 19:10 UTC · lore

Hi list, Hi Ray. Ray Chen who coded this part didn't show up in this list since 2011, so I'm asking everyone else. Also, I don't know perl. Excuse me, if the question is stupid.

Here's the function. It's supposed to return a list of directories that became empty during this commit. The returned paths should be SVN paths (like "trunk/*"), but that's another question.

My comments inside.
    sub find_empty_directories {
        my ($self) = @_;
        my @empty_dirs;
        my %dirs = map { dirname($_) => 1 } @deleted_gpath;
    
        foreach my $dir (sort keys %dirs) {
                next if $dir eq ".";
    
IB> ################################################
IB> The variable $dir isn't used here.
IB> I think the value of $skip_added will be the same (0 or 1) in all
IB> iterations, regardless of $dir
                # If there have been any additions to this directory, there is
                # no reason to check if it is empty.
                my $skip_added = 0;
                foreach my $t (qw/dir_prop file_prop/) {
                        foreach my $path (keys %{ $self->{$t} }) {
                                if (exists $self->{$t}->{dirname($path)}) {
                                        $skip_added = 1;
                                        last;
                                }
                        }
                        last if $skip_added;
                }
                next if $skip_added;
IB> ################################################
    
                # Use `git ls-tree` to get the filenames of this directory
                # that existed prior to this particular commit.
                my $ls = command('ls-tree', '-z', '--name-only',
                                 $self->{c}, "$dir/");
                my %files = map { $_ => 1 } split(/\0/, $ls);
    
                # Remove the filenames that were deleted during this commit.
                delete $files{$_} foreach (@deleted_gpath);
    
                # Report the directory if there are no filenames left.
                push @empty_dirs, $dir unless (scalar %files);
        }
        @empty_dirs;
    }

← back to recent threads