453
453
next = best_ancestor(next)
458
# Map revisions from and to utf8 encoding
459
# Whenever we do an encode/decode operation, we save the result, so that
460
# we don't have to do it again.
461
_unicode_to_utf8_map = {}
462
_utf8_to_unicode_map = {}
465
def encode_utf8(unicode_str,
466
_u_to_8=_unicode_to_utf8_map,
467
_8_to_u=_utf8_to_unicode_map):
468
"""Take this unicode revision id, and get a unicode version"""
470
return _u_to_8[unicode_str]
472
_u_to_8[unicode_str] = utf8_str = unicode_str.encode('utf-8')
473
_8_to_u[utf8_str] = unicode_str
477
def decode_utf8(utf8_str,
478
_u_to_8=_unicode_to_utf8_map,
479
_8_to_u=_utf8_to_unicode_map):
480
"""Take a utf8 revision id, and decode it, but cache the result"""
482
return _8_to_u[utf8_str]
484
_8_to_u[utf8_str] = unicode_str = utf8_str.decode('utf-8')
485
_u_to_8[unicode_str] = utf8_str
489
def clear_encoding_cache():
490
"""Clear the encoding and decoding caches"""
491
_unicode_to_utf8_map = {}
492
_utf8_to_unicode_map = {}