{"thread":{"id":"33635","subject":"Possible meaningless block in perl/Git/SVN/Fetcher.pm: sub find_empty_directories","startedAt":"2013-04-27T19:10:05Z","lastAt":"2013-04-27T19:10:05Z","messageCount":1,"participants":["Ilya Basin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"215716","messageId":"1225928524.20130427231005@gmail.com","threadId":"33635","inReplyTo":null,"subject":"Possible meaningless block in perl/Git/SVN/Fetcher.pm: sub find_empty_directories","fromName":"Ilya Basin","fromEmail":"basinilya@gmail.com","sentAt":"2013-04-27T19:10:05Z","receivedAt":"2013-04-27T19:10:05Z","isPatch":false,"sender":{"key":"basinilya@gmail.com","avatar":null},"body":"Hi list, Hi Ray.\nRay Chen who coded this part didn't show up in this list since 2011,\nso I'm asking everyone else.\nAlso, I don't know perl. Excuse me, if the question is stupid.\n\nHere's the function. It's supposed to return a list of directories\nthat became empty during this commit. The returned paths should be SVN\npaths (like \"trunk/*\"), but that's another question.\n\nMy comments inside.\n\n    sub find_empty_directories {\n        my ($self) = @_;\n        my @empty_dirs;\n        my %dirs = map { dirname($_) => 1 } @deleted_gpath;\n    \n        foreach my $dir (sort keys %dirs) {\n                next if $dir eq \".\";\n    \n\nIB> ################################################\nIB> The variable $dir isn't used here.\nIB> I think the value of $skip_added will be the same (0 or 1) in all\nIB> iterations, regardless of $dir\n                # If there have been any additions to this directory, there is\n                # no reason to check if it is empty.\n                my $skip_added = 0;\n                foreach my $t (qw/dir_prop file_prop/) {\n                        foreach my $path (keys %{ $self->{$t} }) {\n                                if (exists $self->{$t}->{dirname($path)}) {\n                                        $skip_added = 1;\n                                        last;\n                                }\n                        }\n                        last if $skip_added;\n                }\n                next if $skip_added;\nIB> ################################################\n    \n                # Use `git ls-tree` to get the filenames of this directory\n                # that existed prior to this particular commit.\n                my $ls = command('ls-tree', '-z', '--name-only',\n                                 $self->{c}, \"$dir/\");\n                my %files = map { $_ => 1 } split(/\\0/, $ls);\n    \n                # Remove the filenames that were deleted during this commit.\n                delete $files{$_} foreach (@deleted_gpath);\n    \n                # Report the directory if there are no filenames left.\n                push @empty_dirs, $dir unless (scalar %files);\n        }\n        @empty_dirs;\n    }\n"}]}