~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
 
99
99
    def __init__(self, rev, inventory):
100
100
        """Create a new testament for rev using inventory."""
101
 
        self.revision_id = rev.revision_id
 
101
        self.revision_id = str(rev.revision_id)
102
102
        self.committer = rev.committer
103
103
        self.timezone = rev.timezone or 0
104
104
        self.timestamp = rev.timestamp
106
106
        self.parent_ids = rev.parent_ids[:]
107
107
        self.inventory = inventory
108
108
        self.revprops = copy(rev.properties)
109
 
        if contains_whitespace(self.revision_id):
110
 
            raise ValueError(self.revision_id)
111
 
        if contains_linebreaks(self.committer):
112
 
            raise ValueError(self.committer)
 
109
        assert not contains_whitespace(self.revision_id)
 
110
        assert not contains_linebreaks(self.committer)
113
111
 
114
112
    def as_text_lines(self):
115
113
        """Yield text form as a sequence of lines.
127
125
        # inventory length contains the root, which is not shown here
128
126
        a('parents:\n')
129
127
        for parent_id in sorted(self.parent_ids):
130
 
            if contains_whitespace(parent_id):
131
 
                raise ValueError(parent_id)
 
128
            assert not contains_whitespace(parent_id)
132
129
            a('  %s\n' % parent_id)
133
130
        a('message:\n')
134
131
        for l in self.message.splitlines():
137
134
        for path, ie in self._get_entries():
138
135
            a(self._entry_to_line(path, ie))
139
136
        r.extend(self._revprops_to_lines())
 
137
        if __debug__:
 
138
            for l in r:
 
139
                assert isinstance(l, basestring), \
 
140
                    '%r of type %s is not a plain string' % (l, type(l))
140
141
        return [line.encode('utf-8') for line in r]
141
142
 
142
143
    def _get_entries(self):
145
146
        return entries
146
147
 
147
148
    def _escape_path(self, path):
148
 
        if contains_linebreaks(path):
149
 
            raise ValueError(path)
 
149
        assert not contains_linebreaks(path)
150
150
        return unicode(path.replace('\\', '/').replace(' ', '\ '))
151
151
 
152
152
    def _entry_to_line(self, path, ie):
153
153
        """Turn an inventory entry into a testament line"""
154
 
        if contains_whitespace(ie.file_id):
155
 
            raise ValueError(ie.file_id)
 
154
        assert not contains_whitespace(ie.file_id)
 
155
 
156
156
        content = ''
157
157
        content_spacer=''
158
158
        if ie.kind == 'file':
159
159
            # TODO: avoid switching on kind
160
 
            if not ie.text_sha1:
161
 
                raise AssertionError()
 
160
            assert ie.text_sha1
162
161
            content = ie.text_sha1
163
162
            content_spacer = ' '
164
163
        elif ie.kind == 'symlink':
165
 
            if not ie.symlink_target:
166
 
                raise AssertionError()
 
164
            assert ie.symlink_target
167
165
            content = self._escape_path(ie.symlink_target)
168
166
            content_spacer = ' '
169
167
 
170
168
        l = u'  %s %s %s%s%s\n' % (ie.kind, self._escape_path(path),
171
 
                                   ie.file_id.decode('utf8'),
 
169
                                   unicode(ie.file_id),
172
170
                                   content_spacer, content)
173
171
        return l
174
172
 
188
186
            return []
189
187
        r = ['properties:\n']
190
188
        for name, value in sorted(self.revprops.items()):
191
 
            if contains_whitespace(name):
192
 
                raise ValueError(name)
 
189
            assert isinstance(name, str)
 
190
            assert not contains_whitespace(name)
193
191
            r.append('  %s:\n' % name)
194
192
            for line in value.splitlines():
195
193
                r.append(u'    %s\n' % line)
225
223
        return self.inventory.iter_entries()
226
224
 
227
225
    def _escape_path(self, path):
228
 
        if contains_linebreaks(path):
229
 
            raise ValueError(path)
 
226
        assert not contains_linebreaks(path)
230
227
        if path == '':
231
228
            path = '.'
232
229
        return unicode(path.replace('\\', '/').replace(' ', '\ '))