b._dirstate_helpers_py : module documentation

Part of bzrlib

Python implementations of Dirstate Helper functions.
Function pack_stat Convert stat values into a packed representation
Function bisect_dirblock Return the index where to insert dirname into the dirblocks.
Function cmp_by_dirs Compare two paths directory by directory.
Function _unpack_stat Turn a packed_stat back into the stat fields.
Function _bisect_path_left Return the index where to insert path into paths.
Function _bisect_path_right Return the index where to insert path into paths.
Function _cmp_path_by_dirblock Compare two paths based on what directory they are in.
Function _read_dirblocks Read in the dirblocks for the given DirState object.
def pack_stat(st, _b64=binascii.b2a_base64, _pack=struct.Struct('>6L').pack):
Convert stat values into a packed representation

Not all of the fields from the stat included are strictly needed, and by just encoding the mtime and mode a slight speed increase could be gained. However, using the pyrex version instead is a bigger win.

def _unpack_stat(packed_stat):
Turn a packed_stat back into the stat fields.

This is meant as a debugging tool, should not be used in real code.

def _bisect_path_left(paths, path):

Return the index where to insert path into paths.

This uses the dirblock sorting. So all children in a directory come before the children of children. For example:

a/
  b/
    c
  d/
    e
  b-c
  d-e
a-a
a=c

Will be sorted as:

a
a-a
a=c
a/b
a/b-c
a/d
a/d-e
a/b/c
a/d/e
ParameterspathsA list of paths to search through
pathA single path to insert
ReturnsAn offset where 'path' can be inserted.
See Alsobisect.bisect_left
def _bisect_path_right(paths, path):
Return the index where to insert path into paths.

This uses a path-wise comparison so we get::
    a
    a-b
    a=b
    a/b
Rather than::
    a
    a-b
    a/b
    a=b
:param paths: A list of paths to search through
:param path: A single path to insert
:return: An offset where 'path' can be inserted.
:seealso: bisect.bisect_right
def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
Return the index where to insert dirname into the dirblocks.

The return value idx is such that all directories blocks in dirblock[:idx] have names < dirname, and all blocks in dirblock[idx:] have names >= dirname.

Optional args lo (default 0) and hi (default len(dirblocks)) bound the slice of a to be searched.

def cmp_by_dirs(path1, path2):
Compare two paths directory by directory.

This is equivalent to doing:

cmp(path1.split('/'), path2.split('/'))

The idea is that you should compare path components separately. This differs from plain cmp(path1, path2) for paths like 'a-b' and a/b. "a-b" comes after "a" but would come before "a/b" lexically.

Parameterspath1first path
path2second path
Returnsnegative number if path1 comes first, 0 if paths are equal, and positive number if path2 sorts first
def _cmp_path_by_dirblock(path1, path2):
Compare two paths based on what directory they are in.

This generates a sort order, such that all children of a directory are sorted together, and grandchildren are in the same order as the children appear. But all grandchildren come after all children.

Parameterspath1first path
path2the second path
Returnsnegative number if path1 comes first, 0 if paths are equal and a positive number if path2 sorts first
def _read_dirblocks(state):
Read in the dirblocks for the given DirState object.

This is tightly bound to the DirState internal representation. It should be thought of as a member function, which is only separated out so that we can re-write it in pyrex.

ParametersstateA DirState object.
ReturnsNone
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.