~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/annotate.py

  • Committer: Ian Clatworthy
  • Date: 2007-07-09 05:23:16 UTC
  • mfrom: (2593.1.5 bzr.annotate_fixes)
  • mto: This revision was merged to the branch mainline in revision 2594.
  • Revision ID: ian.clatworthy@internode.on.net-20070709052316-v812p7fielxa3th7
(Adeodato Simó) Merge annotate changes to make it behave in a non-ASCII world

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from bzrlib import (
32
32
    errors,
 
33
    osutils,
33
34
    patiencediff,
34
35
    tsort,
35
36
    )
79
80
            anno = "%-*s %-7s " % (max_revno_len, revno_str, author[:7])
80
81
 
81
82
        if anno.lstrip() == "" and full: anno = prevanno
82
 
        print >>to_file, '%s| %s' % (anno, text)
 
83
        try:
 
84
            to_file.write(anno)
 
85
        except UnicodeEncodeError:
 
86
            # cmd_annotate should be passing in an 'exact' object, which means
 
87
            # we have a direct handle to sys.stdout or equivalent. It may not
 
88
            # be able to handle the exact Unicode characters, but 'annotate' is
 
89
            # a user function (non-scripting), so shouldn't die because of
 
90
            # unrepresentable annotation characters. So encode using 'replace',
 
91
            # and write them again.
 
92
            encoding = getattr(to_file, 'encoding', None) or \
 
93
                    osutils.get_terminal_encoding()
 
94
            to_file.write(anno.encode(encoding, 'replace'))
 
95
        print >>to_file, '| %s' % (text,)
83
96
        prevanno=anno
84
97
 
85
98