[Merge] workingtree.walkdirs to support walking an empty directory

Marius Kruger amanic at gmail.com
Sat Oct 27 22:52:49 BST 2007


hi,
> workingtree.walkdirs did not like it if we specify
> a prefix which represents an empty directory.
this patch tries to fix it again
  The previous attempt got a bit stale and thus vetoed.
  I didn't have time until now, so here goes.


Martin Pool wrote (in his review of the original patch):
> -                if current_disk[0][1][top_strip_len:] == '':
> +                if (current_disk[0][1][top_strip_len:] == '' and
> +                    len(current_disk[1]) > 0):
>
> Sorry I don't understand how this works - can you explain?
It wasn't very complicated Martin. It is assumed further down in
the if-block that the directory contains something
(current_disk[1][bzrdir_loc][0]).
Thus we have to check if its empty so that empty directories can be
safely ignored.

This is the only real change I want to get merged and I refactored it a
little more to
make it more understandable (I hope):

-                if current_disk[0][1][top_strip_len:] == '':
-                    # osutils.walkdirs can be made nicer -
+                if (cur_disk_dir_path_from_top[top_strip_len:] == '' and
+                    len(cur_disk_dir_content) > 0):
+                    # osutils.walkdirs can be made nicer -
                     # yield the path-from-prefix rather than the pathjoined
                     # value.
-                    bzrdir_loc = bisect_left(current_disk[1], ('.bzr',
'.bzr'))
-                    if current_disk[1][bzrdir_loc][0] == '.bzr':
+                    bzrdir_loc = bisect_left(cur_disk_dir_content,
+                        ('.bzr', '.bzr'))
+                    if cur_disk_dir_content[bzrdir_loc][0] == '.bzr':
                         # we dont yield the contents of, or, .bzr itself.
-                        del current_disk[1][bzrdir_loc]
+                        del cur_disk_dir_content[bzrdir_loc]


I also attended to your other concerns,
hopefully it can be merged (after the new bzr release).
regards
marius

-------------- next part --------------
A non-text attachment was scrubbed...
Name: workingtree.walk_empty_dir2.patch
Type: text/x-diff
Size: 19826 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20071027/9d21d876/attachment-0001.bin 


More information about the bazaar mailing list