~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2006-06-15 20:49:03 UTC
  • mto: (1780.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1781.
  • Revision ID: robertc@robertcollins.net-20060615204903-994181bbe8cd4ec1
Add path_prefix_key and compare_paths_prefix_order utility functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
846
846
        for dir in reversed(dirblock):
847
847
            if dir[2] == _directory:
848
848
                pending.append(dir)
 
849
 
 
850
 
 
851
def path_prefix_key(path):
 
852
    """Generate a prefix-order path key for path.
 
853
 
 
854
    This can be used to sort paths in the same way that walkdirs does.
 
855
    """
 
856
    return (path.count('/'), path)
 
857
 
 
858
 
 
859
def compare_paths_prefix_order(path_a, path_b):
 
860
    """Compare path_a and path_b to generate the same order walkdirs uses."""
 
861
    key_a = path_prefix_key(path_a)
 
862
    key_b = path_prefix_key(path_b)
 
863
    return cmp(key_a, key_b)