~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_py.py

  • Committer: Samuel Bronson
  • Date: 2012-08-30 20:36:18 UTC
  • mto: (6015.57.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: naesten@gmail.com-20120830203618-y2dzw91nqpvpgxvx
Update INSTALL for switch to Python 2.6 and up.

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