70
70
import_static_tuple_c, StaticTuple_New, \
71
71
StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact, \
72
72
StaticTuple_GET_SIZE, StaticTuple_GET_ITEM
75
76
# TODO: Find some way to import this from _dirstate_helpers
496
cdef _format_record_py24(gc_chk_sha1_record *record):
497
"""Python2.4 PyString_FromFormat doesn't have %u.
499
It only has %d and %ld. We would really like to even have %llu, which
500
is only in python2.7. So we go back into casting to regular objects.
502
return "%s %s %s %s" % (record.block_offset, record.block_length,
503
record.record_start, record.record_end)
506
cdef _format_record(gc_chk_sha1_record *record):
507
# This is inefficient to go from a logical state back to a
508
# string, but it makes things work a bit better internally for now.
509
if record.block_offset >= 0xFFFFFFFF:
510
# %llu is what we really want, but unfortunately it was only added
511
# in python 2.7... :(
512
block_offset_str = str(record.block_offset)
513
value = PyString_FromFormat('%s %lu %lu %lu',
514
PyString_AS_STRING(block_offset_str),
516
record.record_start, record.record_end)
518
value = PyString_FromFormat('%lu %lu %lu %lu',
519
<unsigned long>record.block_offset,
521
record.record_start, record.record_end)
524
ctypedef object (*formatproc)(gc_chk_sha1_record *)
525
cdef formatproc _record_formatter
526
_record_formatter = _format_record
527
if sys.version_info[:2] == (2, 4):
528
_record_formatter = _format_record_py24
495
531
cdef class GCCHKSHA1LeafNode:
496
532
"""Track all the entries for a given leaf node."""
554
590
cdef StaticTuple value_and_refs
555
591
cdef StaticTuple empty
556
592
value_and_refs = StaticTuple_New(2)
557
# This is really inefficient to go from a logical state back to a
558
# string, but it makes things work a bit better internally for now.
559
if record.block_offset >= 0xFFFFFFFF:
560
# %llu is what we really want, but unfortunately it was only added
561
# in python 2.7... :(
562
block_offset_str = str(record.block_offset)
563
value = PyString_FromFormat('%s %lu %lu %lu',
564
PyString_AS_STRING(block_offset_str),
566
record.record_start, record.record_end)
568
value = PyString_FromFormat('%lu %lu %lu %lu',
569
<unsigned long>record.block_offset,
571
record.record_start, record.record_end)
593
value = _record_formatter(record)
573
595
StaticTuple_SET_ITEM(value_and_refs, 0, value)
574
596
# Always empty refs