/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_dirstate_helpers_py.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 01:35:53 UTC
  • mto: (6670.4.8 move-bzr)
  • mto: This revision was merged to the branch mainline in revision 6681.
  • Revision ID: jelmer@jelmer.uk-20170610013553-560y7mn3su4pp763
Fix remaining tests.

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
19
22
import os
 
23
import struct
20
24
 
21
25
# We cannot import the dirstate module, because it loads this module
22
26
# All we really need is the IN_MEMORY_MODIFIED constant
23
 
from bzrlib import errors
24
 
from bzrlib.dirstate import DirState
 
27
from breezy import errors
 
28
from .dirstate import DirState
 
29
from .sixish import (
 
30
    range,
 
31
    )
 
32
 
 
33
 
 
34
def pack_stat(st, _b64=binascii.b2a_base64, _pack=struct.Struct('>6L').pack):
 
35
    """Convert stat values into a packed representation
 
36
 
 
37
    Not all of the fields from the stat included are strictly needed, and by
 
38
    just encoding the mtime and mode a slight speed increase could be gained.
 
39
    However, using the pyrex version instead is a bigger win.
 
40
    """
 
41
    # base64 encoding always adds a final newline, so strip it off
 
42
    return _b64(_pack(st.st_size & 0xFFFFFFFF, int(st.st_mtime) & 0xFFFFFFFF,
 
43
        int(st.st_ctime) & 0xFFFFFFFF, st.st_dev & 0xFFFFFFFF,
 
44
        st.st_ino & 0xFFFFFFFF, st.st_mode))[:-1]
 
45
 
 
46
 
 
47
def _unpack_stat(packed_stat):
 
48
    """Turn a packed_stat back into the stat fields.
 
49
 
 
50
    This is meant as a debugging tool, should not be used in real code.
 
51
    """
 
52
    (st_size, st_mtime, st_ctime, st_dev, st_ino,
 
53
     st_mode) = struct.unpack('>6L', binascii.a2b_base64(packed_stat))
 
54
    return dict(st_size=st_size, st_mtime=st_mtime, st_ctime=st_ctime,
 
55
                st_dev=st_dev, st_ino=st_ino, st_mode=st_mode)
25
56
 
26
57
 
27
58
def _bisect_path_left(paths, path):
234
265
        # them. Grab an straight iterator over the fields. (We use an
235
266
        # iterator because we don't want to do a lot of additions, nor
236
267
        # do we want to do a lot of slicing)
237
 
        next = iter(fields).next
 
268
        _iter = iter(fields)
 
269
        # Get a local reference to the compatible next method
 
270
        next = getattr(_iter, '__next__', None)
 
271
        if next is None:
 
272
            next = _iter.next
238
273
        # Move the iterator to the current position
239
 
        for x in xrange(cur):
 
274
        for x in range(cur):
240
275
            next()
241
276
        # The two blocks here are deliberate: the root block and the
242
277
        # contents-of-root block.
244
279
        current_block = state._dirblocks[0][1]
245
280
        current_dirname = ''
246
281
        append_entry = current_block.append
247
 
        for count in xrange(state._num_entries):
 
282
        for count in range(state._num_entries):
248
283
            dirname = next()
249
284
            name = next()
250
285
            file_id = next()
281
316
    else:
282
317
        fields_to_entry = state._get_fields_to_entry()
283
318
        entries = [fields_to_entry(fields[pos:pos+entry_size])
284
 
                   for pos in xrange(cur, field_count, entry_size)]
 
319
                   for pos in range(cur, field_count, entry_size)]
285
320
        state._entries_to_current_state(entries)
286
321
    # To convert from format 2  => format 3
287
322
    # state._dirblocks = sorted(state._dirblocks,