~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

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
 
131
132
        for l in self.message.splitlines():
132
133
            a('  %s\n' % l)
133
134
        a('inventory:\n')
134
 
        for path, ie in self._get_entries():
 
135
        entries = self.inventory.iter_entries()
 
136
        entries.next()
 
137
        for path, ie in entries:
135
138
            a(self._entry_to_line(path, ie))
136
139
        r.extend(self._revprops_to_lines())
137
140
        if __debug__:
140
143
                    '%r of type %s is not a plain string' % (l, type(l))
141
144
        return [line.encode('utf-8') for line in r]
142
145
 
143
 
    def _get_entries(self):
144
 
        entries = self.inventory.iter_entries()
145
 
        entries.next()
146
 
        return entries
147
 
 
148
146
    def _escape_path(self, path):
149
147
        assert not contains_linebreaks(path)
150
 
        return unicode(path.replace('\\', '/').replace(' ', '\ '))
 
148
        return unicode(path.replace('\\', '/').replace(' ', '\ ')).encode('utf-8')
151
149
 
152
150
    def _entry_to_line(self, path, ie):
153
151
        """Turn an inventory entry into a testament line"""
 
152
        l = '  ' + str(ie.kind)
 
153
        l += ' ' + self._escape_path(path)
154
154
        assert not contains_whitespace(ie.file_id)
155
 
 
156
 
        content = ''
157
 
        content_spacer=''
 
155
        l += ' ' + unicode(ie.file_id).encode('utf-8')
158
156
        if ie.kind == 'file':
159
157
            # TODO: avoid switching on kind
160
158
            assert ie.text_sha1
161
 
            content = ie.text_sha1
162
 
            content_spacer = ' '
 
159
            l += ' ' + ie.text_sha1
163
160
        elif ie.kind == 'symlink':
164
161
            assert ie.symlink_target
165
 
            content = self._escape_path(ie.symlink_target)
166
 
            content_spacer = ' '
167
 
 
168
 
        l = u'  %s %s %s%s%s\n' % (ie.kind, self._escape_path(path),
169
 
                                   unicode(ie.file_id),
170
 
                                   content_spacer, content)
171
 
        return l
 
162
            l += ' ' + self._escape_path(ie.symlink_target)
 
163
        l += '\n'
 
164
        return l.decode('utf-8')
172
165
 
173
166
    def as_text(self):
174
167
        return ''.join(self.as_text_lines())
190
183
            assert not contains_whitespace(name)
191
184
            r.append('  %s:\n' % name)
192
185
            for line in value.splitlines():
193
 
                r.append(u'    %s\n' % line)
 
186
                if not isinstance(line, str):
 
187
                    line = line.encode('utf-8')
 
188
                r.append('    %s\n' % line)
194
189
        return r
195
190
 
196
191
    def as_sha1(self):
200
195
 
201
196
 
202
197
class StrictTestament(Testament):
203
 
    """This testament format is for use as a checksum in bundle format 0.8"""
 
198
    """This testament format is for use as a checksum in changesets"""
204
199
 
205
200
    long_header = 'bazaar-ng testament version 2.1\n'
206
201
    short_header = 'bazaar-ng testament short form 2.1\n'
207
202
    def _entry_to_line(self, path, ie):
208
203
        l = Testament._entry_to_line(self, path, ie)[:-1]
209
 
        l += ' ' + ie.revision
 
204
        l += ' ' + ie.revision.decode('utf-8')
210
205
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
211
206
        return l
212
 
 
213
 
 
214
 
class StrictTestament3(StrictTestament):
215
 
    """This testament format is for use as a checksum in bundle format 0.9+
216
 
    
217
 
    It differs from StrictTestament by including data about the tree root.
218
 
    """
219
 
 
220
 
    long_header = 'bazaar testament version 3 strict\n'
221
 
    short_header = 'bazaar testament short form 3 strict\n'
222
 
    def _get_entries(self):
223
 
        return self.inventory.iter_entries()
224
 
 
225
 
    def _escape_path(self, path):
226
 
        assert not contains_linebreaks(path)
227
 
        if path == '':
228
 
            path = '.'
229
 
        return unicode(path.replace('\\', '/').replace(' ', '\ '))