Merge lp:~jr/bzr-explorer/795034-refresh-branch-view-automatically into lp:bzr-explorer

Proposed by Jonathan Riddell
Status: Merged
Merge reported by: Jonathan Riddell
Merged at revision: not available
Proposed branch: lp:~jr/bzr-explorer/795034-refresh-branch-view-automatically
Merge into: lp:bzr-explorer
Diff against target: 0 lines
To merge this branch: bzr merge lp:~jr/bzr-explorer/795034-refresh-branch-view-automatically
Reviewer Review Type Date Requested Status
Andrew Bennetts (community) Approve
Bazaar Explorer Developers Pending
Review via email: mp+64039@code.launchpad.net

Description of the change

Watch for changes in branches and refresh when they happen

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

I think _find_file_watcher_paths could be written more simply as:

import os

    def _find_file_watcher_paths(self, root):
        result = [root]
        for dirpath, dirnames, filenames in os.walk(root):
            result.extend(os.path.join(dirpath, d) for d in dirnames)
        return result

At a minimum I'd suggest avoiding “fileList = fileList + …” in favour of fileList.extend(…) (or equivalently “fileList += …”), as I think the way you have written it CPython is likely to have to allocate a new list rather than growing the existing list in place, making it an O(n²) loop. Newer CPythons *might* optimise in this case, but I'm not sure they do.

It might be worth trying this on a large tree (maybe gcc or emacs?) just to verify there's no nasty performance surprises. But aside from that this seems fine to me, although I'm not a Qt or bzr-explorer expert.

Revision history for this message
Andrew Bennetts (spiv) :
review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/16/2011 7:39 AM, Andrew Bennetts wrote:
> I think _find_file_watcher_paths could be written more simply as:
>
> import os
>
> def _find_file_watcher_paths(self, root):
> result = [root]
> for dirpath, dirnames, filenames in os.walk(root):
> result.extend(os.path.join(dirpath, d) for d in dirnames)
> return result
>
> At a minimum I'd suggest avoiding “fileList = fileList + …” in favour of fileList.extend(…) (or equivalently “fileList += …”), as I think the way you have written it CPython is likely to have to allocate a new list rather than growing the existing list in place, making it an O(n²) loop. Newer CPythons *might* optimise in this case, but I'm not sure they do.
>
> It might be worth trying this on a large tree (maybe gcc or emacs?) just to verify there's no nasty performance surprises. But aside from that this seems fine to me, although I'm not a Qt or bzr-explorer expert.

I'll note that bzrlib has "bzrlib.osutils._walkdirs_utf8" et al because
"os.walk()" is not particularly efficient. ISTR it stats every object 2
times at least. (It does something like

 if os.path.isdir():
  ...
 elif os.path.isfile():
  ...

Which means that the common case of everything is a file, everything
gets os.lstat() 2 times to determine that. Should obviously be fast
because you just stat'd it, but it is still a syscall.

The most straightforward api is "osutils.walkdirs()" but _walkdirs_utf8
is more efficient for filesystems like Linux where we think about them
in terms of Unicode, but the actual paths on disk are in 8-bit (utf-8).

Because you only care about directories, you could actually just do:

result = [root]
for (dir_info, dir_entries) in osutils._walkdirs_utf8(root):
  utf8_relpath, system_path = dir_info
  result.append(system_path)
return result

Check and make sure, but we should descend into every directory, which
means that you can just use the "dir_info" portion.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk35s+IACgkQJdeBCYSNAAOuMgCffOJ9zTy0kBdQfGPVSp3NW+dr
+loAniV8HjoY2pRFnVsdh1vtToQ0jNtA
=/Fp5
-----END PGP SIGNATURE-----

518. By Jonathan Riddell

simplify _find_file_watcher_paths()

Preview Diff

Empty

Subscribers

People subscribed via source and target branches