~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_py.py

(gz) Tidy up dirstate pack_stat code and expose pyrex implementation (Martin
 Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Python implementations of Dirstate Helper functions."""
18
18
 
 
19
import binascii
19
20
import os
 
21
import struct
20
22
 
21
23
# We cannot import the dirstate module, because it loads this module
22
24
# All we really need is the IN_MEMORY_MODIFIED constant
24
26
from bzrlib.dirstate import DirState
25
27
 
26
28
 
 
29
def pack_stat(st, _b64=binascii.b2a_base64, _pack=struct.Struct('>6L').pack):
 
30
    """Convert stat values into a packed representation
 
31
 
 
32
    Not all of the fields from the stat included are strictly needed, and by
 
33
    just encoding the mtime and mode a slight speed increase could be gained.
 
34
    However, using the pyrex version instead is a bigger win.
 
35
    """
 
36
    # base64 encoding always adds a final newline, so strip it off
 
37
    return _b64(_pack(st.st_size, int(st.st_mtime), int(st.st_ctime),
 
38
        st.st_dev, st.st_ino & 0xFFFFFFFF, st.st_mode))[:-1]
 
39
 
 
40
 
 
41
def _unpack_stat(packed_stat):
 
42
    """Turn a packed_stat back into the stat fields.
 
43
 
 
44
    This is meant as a debugging tool, should not be used in real code.
 
45
    """
 
46
    (st_size, st_mtime, st_ctime, st_dev, st_ino,
 
47
     st_mode) = struct.unpack('>6L', binascii.a2b_base64(packed_stat))
 
48
    return dict(st_size=st_size, st_mtime=st_mtime, st_ctime=st_ctime,
 
49
                st_dev=st_dev, st_ino=st_ino, st_mode=st_mode)
 
50
 
 
51
 
27
52
def _bisect_path_left(paths, path):
28
53
    """Return the index where to insert path into paths.
29
54