~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
# revisions can be serialized.
71
71
 
72
72
from copy import copy
 
73
from cStringIO import StringIO
 
74
import string
73
75
from sha import sha
74
76
 
75
77
from bzrlib.osutils import contains_whitespace, contains_linebreaks
76
78
 
77
 
 
78
79
class Testament(object):
79
80
    """Reduced summary of a revision.
80
81
 
144
145
 
145
146
    def _escape_path(self, path):
146
147
        assert not contains_linebreaks(path)
147
 
        return unicode(path.replace('\\', '/').replace(' ', '\ '))
 
148
        return unicode(path.replace('\\', '/').replace(' ', '\ ')).encode('utf-8')
148
149
 
149
150
    def _entry_to_line(self, path, ie):
150
151
        """Turn an inventory entry into a testament line"""
 
152
        l = '  ' + str(ie.kind)
 
153
        l += ' ' + self._escape_path(path)
151
154
        assert not contains_whitespace(ie.file_id)
152
 
 
153
 
        content = ''
154
 
        content_spacer=''
 
155
        l += ' ' + unicode(ie.file_id).encode('utf-8')
155
156
        if ie.kind == 'file':
156
157
            # TODO: avoid switching on kind
157
158
            assert ie.text_sha1
158
 
            content = ie.text_sha1
159
 
            content_spacer = ' '
 
159
            l += ' ' + ie.text_sha1
160
160
        elif ie.kind == 'symlink':
161
161
            assert ie.symlink_target
162
 
            content = self._escape_path(ie.symlink_target)
163
 
            content_spacer = ' '
164
 
 
165
 
        l = u'  %s %s %s%s%s\n' % (ie.kind, self._escape_path(path),
166
 
                                   unicode(ie.file_id),
167
 
                                   content_spacer, content)
168
 
        return l
 
162
            l += ' ' + self._escape_path(ie.symlink_target)
 
163
        l += '\n'
 
164
        return l.decode('utf-8')
169
165
 
170
166
    def as_text(self):
171
167
        return ''.join(self.as_text_lines())
187
183
            assert not contains_whitespace(name)
188
184
            r.append('  %s:\n' % name)
189
185
            for line in value.splitlines():
190
 
                r.append(u'    %s\n' % line)
 
186
                if not isinstance(line, str):
 
187
                    line = line.encode('utf-8')
 
188
                r.append('    %s\n' % line)
191
189
        return r
192
190
 
193
191
    def as_sha1(self):
203
201
    short_header = 'bazaar-ng testament short form 2.1\n'
204
202
    def _entry_to_line(self, path, ie):
205
203
        l = Testament._entry_to_line(self, path, ie)[:-1]
206
 
        l += ' ' + ie.revision
 
204
        l += ' ' + ie.revision.decode('utf-8')
207
205
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
208
206
        return l