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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
    }


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]