# [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal

7 messages from 2015-08-12 to 2015-12-14. Participants: Johannes Sixt, Jeff King, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/40071

## Johannes Sixt, 2015-08-12 17:43

Subject: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <55CB85A5.5040802@kdbg.org>
URL: https://gitlist.dev/e/55CB85A5.5040802%40kdbg.org
In-Reply-To: <b9cf9e2168c3b2476bb5bb134a1528be@www.dscho.org>

```
27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
introduced a new function for_each_loose_file_in_objdir() with a helper
for_each_file_in_obj_subdir(). The latter calls callbacks for each file
found during a directory traversal and finally also a callback for the
directory itself.

git-prune uses the function to clean up the object directory. In
particular, in the directory callback it calls rmdir(). On Windows XP,
this rmdir call fails, because the directory is still open while the
callback is called. Close the directory before calling the callback.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 My Windows 8.1 machine does not require this fix for some unkonwn
 reason. But we still cater for Windows XP users, where this change
 is a real improvement.

 sha1_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 4d1b26f..5cecc68 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3473,12 +3473,12 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
 				break;
 		}
 	}
+	closedir(dir);
+
 	strbuf_setlen(path, baselen);
-
 	if (!r && subdir_cb)
 		r = subdir_cb(subdir_nr, path->buf, data);
 
-	closedir(dir);
 	return r;
 }
 
-- 
2.3.2.245.gb5bf9d3

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```

## Jeff King, 2015-08-12 17:56

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <20150812175629.GA24964@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20150812175629.GA24964%40sigill.intra.peff.net
In-Reply-To: <55CB85A5.5040802@kdbg.org>

```
On Wed, Aug 12, 2015 at 07:43:01PM +0200, Johannes Sixt wrote:

> 27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
> introduced a new function for_each_loose_file_in_objdir() with a helper
> for_each_file_in_obj_subdir(). The latter calls callbacks for each file
> found during a directory traversal and finally also a callback for the
> directory itself.
> 
> git-prune uses the function to clean up the object directory. In
> particular, in the directory callback it calls rmdir(). On Windows XP,
> this rmdir call fails, because the directory is still open while the
> callback is called. Close the directory before calling the callback.

Makes sense, and the patch looks good to me. Sorry for breaking things
on Windows.

Acked-by: Jeff King <peff@peff.net>

-Peff

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```

## Johannes Schindelin, 2015-08-13 07:32

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <557753b4c14eb3f90270007782bc3a73@www.dscho.org>
URL: https://gitlist.dev/e/557753b4c14eb3f90270007782bc3a73%40www.dscho.org
In-Reply-To: <55CB85A5.5040802@kdbg.org>

```
Hi,

On 2015-08-12 19:43, Johannes Sixt wrote:
> 27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
> introduced a new function for_each_loose_file_in_objdir() with a helper
> for_each_file_in_obj_subdir(). The latter calls callbacks for each file
> found during a directory traversal and finally also a callback for the
> directory itself.
> 
> git-prune uses the function to clean up the object directory. In
> particular, in the directory callback it calls rmdir(). On Windows XP,
> this rmdir call fails, because the directory is still open while the
> callback is called. Close the directory before calling the callback.
> 
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
>  My Windows 8.1 machine does not require this fix for some unkonwn
>  reason. But we still cater for Windows XP users, where this change
>  is a real improvement.

I believe that we have a concrete bug report for that:

    https://github.com/git-for-windows/git/issues/231

Ciao,
Johannes

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```

## Junio C Hamano, 2015-12-11 19:37

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <xmqqvb84epyl.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqvb84epyl.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20150812175629.GA24964@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Wed, Aug 12, 2015 at 07:43:01PM +0200, Johannes Sixt wrote:
>
>> 27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
>> introduced a new function for_each_loose_file_in_objdir() with a helper
>> for_each_file_in_obj_subdir(). The latter calls callbacks for each file
>> found during a directory traversal and finally also a callback for the
>> directory itself.
>> 
>> git-prune uses the function to clean up the object directory. In
>> particular, in the directory callback it calls rmdir(). On Windows XP,
>> this rmdir call fails, because the directory is still open while the
>> callback is called. Close the directory before calling the callback.
>
> Makes sense, and the patch looks good to me. Sorry for breaking things
> on Windows.
>
> Acked-by: Jeff King <peff@peff.net>

Sorry for reviving this old thread, but I noticed that we do not
have this patch in our tree yet.  I'll queue to 'pu' for now lest I
forget.  If I missed a good argument or concensus against the change
please let me know, otherwise I'll fast track the change to 2.7 final

```

## Jeff King, 2015-12-11 19:41

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <20151211194103.GA5834@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151211194103.GA5834%40sigill.intra.peff.net
In-Reply-To: <xmqqvb84epyl.fsf@gitster.mtv.corp.google.com>

```
On Fri, Dec 11, 2015 at 11:37:54AM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > On Wed, Aug 12, 2015 at 07:43:01PM +0200, Johannes Sixt wrote:
> >
> >> 27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
> >> introduced a new function for_each_loose_file_in_objdir() with a helper
> >> for_each_file_in_obj_subdir(). The latter calls callbacks for each file
> >> found during a directory traversal and finally also a callback for the
> >> directory itself.
> >> 
> >> git-prune uses the function to clean up the object directory. In
> >> particular, in the directory callback it calls rmdir(). On Windows XP,
> >> this rmdir call fails, because the directory is still open while the
> >> callback is called. Close the directory before calling the callback.
> >
> > Makes sense, and the patch looks good to me. Sorry for breaking things
> > on Windows.
> >
> > Acked-by: Jeff King <peff@peff.net>
> 
> Sorry for reviving this old thread, but I noticed that we do not
> have this patch in our tree yet.  I'll queue to 'pu' for now lest I
> forget.  If I missed a good argument or concensus against the change
> please let me know, otherwise I'll fast track the change to 2.7 final

Ah, thanks for doing that. I noticed it when picking through "git branch
--no-merged pu" of your workspace a few weeks ago, but forgot to follow
up. I certainly have no objections.

-Peff

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```

## Johannes Schindelin, 2015-12-13 13:26

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <alpine.DEB.2.20.1512131425300.21630@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1512131425300.21630%40virtualbox
In-Reply-To: <20151211194103.GA5834@sigill.intra.peff.net>

```
Hi Junio & Peff,

On Fri, 11 Dec 2015, Jeff King wrote:

> On Fri, Dec 11, 2015 at 11:37:54AM -0800, Junio C Hamano wrote:
> 
> > Jeff King <peff@peff.net> writes:
> > 
> > > On Wed, Aug 12, 2015 at 07:43:01PM +0200, Johannes Sixt wrote:
> > >
> > >> 27e1e22d (prune: factor out loose-object directory traversal, 2014-10-16)
> > >> introduced a new function for_each_loose_file_in_objdir() with a helper
> > >> for_each_file_in_obj_subdir(). The latter calls callbacks for each file
> > >> found during a directory traversal and finally also a callback for the
> > >> directory itself.
> > >> 
> > >> git-prune uses the function to clean up the object directory. In
> > >> particular, in the directory callback it calls rmdir(). On Windows XP,
> > >> this rmdir call fails, because the directory is still open while the
> > >> callback is called. Close the directory before calling the callback.
> > >
> > > Makes sense, and the patch looks good to me. Sorry for breaking things
> > > on Windows.
> > >
> > > Acked-by: Jeff King <peff@peff.net>
> > 
> > Sorry for reviving this old thread, but I noticed that we do not
> > have this patch in our tree yet.  I'll queue to 'pu' for now lest I
> > forget.  If I missed a good argument or concensus against the change
> > please let me know, otherwise I'll fast track the change to 2.7 final
> 
> Ah, thanks for doing that. I noticed it when picking through "git branch
> --no-merged pu" of your workspace a few weeks ago, but forgot to follow
> up. I certainly have no objections.

Git for Windows carries this patch since Git for Windows v2.5.0. So: no
objection from my side, either.

Ciao,
Dscho

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```

## Junio C Hamano, 2015-12-14 19:02

Subject: Re: [PATCH jk/prune-mtime] prune: close directory earlier during loose-object directory traversal
Message-ID: <xmqqvb80kg5a.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqvb80kg5a.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <alpine.DEB.2.20.1512131425300.21630@virtualbox>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> > Sorry for reviving this old thread, but I noticed that we do not
>> > have this patch in our tree yet.  I'll queue to 'pu' for now lest I
>> > forget.  If I missed a good argument or concensus against the change
>> > please let me know, otherwise I'll fast track the change to 2.7 final
>> 
>> Ah, thanks for doing that. I noticed it when picking through "git branch
>> --no-merged pu" of your workspace a few weeks ago, but forgot to follow
>> up. I certainly have no objections.
>
> Git for Windows carries this patch since Git for Windows v2.5.0. So: no
> objection from my side, either.

Thanks!

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

```
