Re: [PATCH] [GSOC] prune_worktrees(): reimplement with dir_iterator

2017-04-01 Thread Junio C Hamano
Robert Stanca  writes:

> On Sat, Apr 1, 2017 at 5:29 AM, Junio C Hamano  wrote:
>>
>> Using dir_iterator() to make it recursive is not just overkill but
>> is a positively wrong change, isn't it?
>
> Thanks for the review, and yes the commit message is misleading (my
> bad there). I understood that remove_temp_files has no recursion
> component to it and it removes all ".tmp-id-pack-" files from
> /objects/pack , but shouldn't dir-iterator work even if there's no
> recursion level?

The point is what should happen when somebody (perhaps a newer
version of Git, or a third-party add-on that works with Git) adds a
subdirectory in .git/objects/pack/ or .git/worktrees/.  The answer
is that files and directories in such a subdirectory must not be
touched, because prune_worktrees() or remove_temporary_files() do
not know what these files and directories are.

The dir-iterator API does not allow you to say "only scan the
directory without recursing into the subdirectories" so your code
ends up recursing into them, without knowing what the files and
directories inside are (or are not).  As Peff mentioned in his
review on the other one, if we add a knob to dir-iterator API to
allow you to tell it not to recurse, then it would make it possible
to do a faithful conversion from the original, but without such a
change, you are changing the behaviour.


Re: [PATCH] [GSOC] prune_worktrees(): reimplement with dir_iterator

2017-04-01 Thread Robert Stanca
On Sat, Apr 1, 2017 at 5:29 AM, Junio C Hamano  wrote:
>
> Robert Stanca  writes:
>
> > Replaces recursive traversing of opendir with dir_iterator
>
> The original code for this one, and also the other one, is not
> recursive traversing.  This one enumerates all the _direct_
> subdirectories of ".git/worktrees", and feeds them to
> prune_worktree() without recursing.  The other one scans all the
> files _directly_ underneath ".git/objects/pack" to find the ones
> that begin with the packtmp prefix, and unlinks them without
> recursing.  Neither of them touches anything in subdirectory of
> ".git/worktrees/" nor ".git/objects/pack/".
>
> Using dir_iterator() to make it recursive is not just overkill but
> is a positively wrong change, isn't it?


Thanks for the review, and yes the commit message is misleading (my
bad there). I understood that remove_temp_files has no recursion
component to it and it removes all ".tmp-id-pack-" files from
/objects/pack , but shouldn't dir-iterator work even if there's no
recursion level?
My understanding of dir-iterator is that it is used for directory
iteration (recursive or not) and where are no subdirectories it's
basically recursive with level = 0 .


Re: [PATCH] [GSOC] prune_worktrees(): reimplement with dir_iterator

2017-03-31 Thread Junio C Hamano
Robert Stanca  writes:

> Replaces recursive traversing of opendir with dir_iterator

The original code for this one, and also the other one, is not
recursive traversing.  This one enumerates all the _direct_
subdirectories of ".git/worktrees", and feeds them to
prune_worktree() without recursing.  The other one scans all the
files _directly_ underneath ".git/objects/pack" to find the ones
that begin with the packtmp prefix, and unlinks them without
recursing.  Neither of them touches anything in subdirectory of
".git/worktrees/" nor ".git/objects/pack/".

Using dir_iterator() to make it recursive is not just overkill but
is a positively wrong change, isn't it?