git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Basin <basinilya@gmail.com>
To: git@vger.kernel.org
Cc: Ray Chen <rchen@cs.umd.edu>
Subject: Possible meaningless block in perl/Git/SVN/Fetcher.pm: sub find_empty_directories
Date: Sat, 27 Apr 2013 23:10:05 +0400	[thread overview]
Message-ID: <1225928524.20130427231005@gmail.com> (raw)

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

                 reply	other threads:[~2013-04-27 19:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1225928524.20130427231005@gmail.com \
    --to=basinilya@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=rchen@cs.umd.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).