~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 17:48:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6613.
  • Revision ID: v.ladeuil+lp@free.fr-20160121174807-g4ybpaij9ln5wj6a
Make all transport put_bytes() raises TypeError when given unicode strings rather than bytes.

There was a mix of AssertionError or UnicodeEncodeError.

Also deleted test_put_file_unicode() which was bogus, files contain bytes not unicode strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    object PyTuple_GetItem_void_object "PyTuple_GET_ITEM" (void* tpl, int index)
98
98
    object PyTuple_GET_ITEM(object tpl, Py_ssize_t index)
99
99
 
 
100
    unsigned long PyInt_AsUnsignedLongMask(object number) except? -1
100
101
 
101
102
    char *PyString_AsString(object p)
102
103
    char *PyString_AsString_obj "PyString_AsString" (PyObject *string)
811
812
_encode = binascii.b2a_base64
812
813
 
813
814
 
814
 
from struct import pack
815
815
cdef _pack_stat(stat_value):
816
816
    """return a string representing the stat value's key fields.
817
817
 
821
821
    cdef char result[6*4] # 6 long ints
822
822
    cdef int *aliased
823
823
    aliased = <int *>result
824
 
    aliased[0] = htonl(stat_value.st_size)
825
 
    aliased[1] = htonl(int(stat_value.st_mtime))
826
 
    aliased[2] = htonl(int(stat_value.st_ctime))
827
 
    aliased[3] = htonl(stat_value.st_dev)
828
 
    aliased[4] = htonl(stat_value.st_ino & 0xFFFFFFFF)
829
 
    aliased[5] = htonl(stat_value.st_mode)
 
824
    aliased[0] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_size))
 
825
    # mtime and ctime will often be floats but get converted to PyInt within
 
826
    aliased[1] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mtime))
 
827
    aliased[2] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ctime))
 
828
    aliased[3] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_dev))
 
829
    aliased[4] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ino))
 
830
    aliased[5] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mode))
830
831
    packed = PyString_FromStringAndSize(result, 6*4)
831
832
    return _encode(packed)[:-1]
832
833
 
833
834
 
 
835
def pack_stat(stat_value):
 
836
    """Convert stat value into a packed representation quickly with pyrex"""
 
837
    return _pack_stat(stat_value)
 
838
 
 
839
 
834
840
def update_entry(self, entry, abspath, stat_value):
835
841
    """Update the entry based on what is actually on disk.
836
842
 
1793
1799
                advance_entry = -1
1794
1800
                advance_path = -1
1795
1801
                result = None
 
1802
                changed = None
1796
1803
                path_handled = 0
1797
1804
                if current_entry is None:
1798
1805
                    # unversioned -  the check for path_handled when the path