~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-10 00:43:37 UTC
  • mto: This revision was merged to the branch mainline in revision 1926.
  • Revision ID: john@arbash-meinel.com-20060810004337-6aa4d7ea80e85093
Moving everything into a new location so that we can cache more than just revision ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
453
453
        next = best_ancestor(next)
454
454
    path.reverse()
455
455
    return path
456
 
 
457
 
 
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 = {}
463
 
 
464
 
 
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"""
469
 
    try:
470
 
        return _u_to_8[unicode_str]
471
 
    except KeyError:
472
 
        _u_to_8[unicode_str] = utf8_str = unicode_str.encode('utf-8')
473
 
        _8_to_u[utf8_str] = unicode_str
474
 
        return utf8_str
475
 
 
476
 
 
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"""
481
 
    try:
482
 
        return _8_to_u[utf8_str]
483
 
    except KeyError:
484
 
        _8_to_u[utf8_str] = unicode_str = utf8_str.decode('utf-8')
485
 
        _u_to_8[unicode_str] = utf8_str
486
 
        return unicode_str
487
 
 
488
 
 
489
 
def clear_encoding_cache():
490
 
    """Clear the encoding and decoding caches"""
491
 
    _unicode_to_utf8_map = {}
492
 
    _utf8_to_unicode_map = {}
493