/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/testament.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
from copy import copy
75
75
 
76
 
from ..osutils import (
 
76
from .osutils import (
77
77
    contains_whitespace,
78
78
    contains_linebreaks,
79
79
    sha_strings,
80
80
    )
81
 
from ..sixish import text_type
82
 
from ..tree import Tree
 
81
from .tree import Tree
83
82
 
84
83
 
85
84
class Testament(object):
120
119
        self.parent_ids = rev.parent_ids[:]
121
120
        if not isinstance(tree, Tree):
122
121
            raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
123
 
                            "Revision and a Tree.")
 
122
                "Revision and a Tree.")
124
123
        self.tree = tree
125
124
        self.revprops = copy(rev.properties)
126
125
        if contains_whitespace(self.revision_id):
137
136
        r = []
138
137
        a = r.append
139
138
        a(self.long_header)
140
 
        a('revision-id: %s\n' % self.revision_id.decode('utf-8'))
 
139
        a('revision-id: %s\n' % self.revision_id)
141
140
        a('committer: %s\n' % self.committer)
142
141
        a('timestamp: %d\n' % self.timestamp)
143
142
        a('timezone: %d\n' % self.timezone)
146
145
        for parent_id in sorted(self.parent_ids):
147
146
            if contains_whitespace(parent_id):
148
147
                raise ValueError(parent_id)
149
 
            a('  %s\n' % parent_id.decode('utf-8'))
 
148
            a('  %s\n' % parent_id)
150
149
        a('message:\n')
151
150
        for l in self.message.splitlines():
152
151
            a('  %s\n' % l)
157
156
        return [line.encode('utf-8') for line in r]
158
157
 
159
158
    def _get_entries(self):
160
 
        return ((path, ie) for (path, file_class, kind, ie) in
 
159
        return ((path, ie) for (path, versioned, kind, file_id, ie) in
161
160
                self.tree.list_files(include_root=self.include_root))
162
161
 
163
162
    def _escape_path(self, path):
164
163
        if contains_linebreaks(path):
165
164
            raise ValueError(path)
166
 
        if not isinstance(path, text_type):
167
 
            # TODO(jelmer): Clean this up for pad.lv/1696545
168
 
            path = path.decode('ascii')
169
 
        return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
 
165
        return unicode(path.replace('\\', '/').replace(' ', '\\ '))
170
166
 
171
167
    def _entry_to_line(self, path, ie):
172
168
        """Turn an inventory entry into a testament line"""
173
169
        if contains_whitespace(ie.file_id):
174
170
            raise ValueError(ie.file_id)
175
171
        content = ''
176
 
        content_spacer = ''
 
172
        content_spacer=''
177
173
        if ie.kind == 'file':
178
174
            # TODO: avoid switching on kind
179
175
            if not ie.text_sha1:
180
176
                raise AssertionError()
181
 
            content = ie.text_sha1.decode('ascii')
 
177
            content = ie.text_sha1
182
178
            content_spacer = ' '
183
179
        elif ie.kind == 'symlink':
184
180
            if not ie.symlink_target:
192
188
        return l
193
189
 
194
190
    def as_text(self):
195
 
        return b''.join(self.as_text_lines())
 
191
        return ''.join(self.as_text_lines())
196
192
 
197
193
    def as_short_text(self):
198
194
        """Return short digest-based testament."""
199
 
        return (self.short_header.encode('ascii') +
200
 
                b'revision-id: %s\n'
201
 
                b'sha1: %s\n'
 
195
        return (self.short_header +
 
196
                'revision-id: %s\n'
 
197
                'sha1: %s\n'
202
198
                % (self.revision_id, self.as_sha1()))
203
199
 
204
200
    def _revprops_to_lines(self):
224
220
    long_header = 'bazaar-ng testament version 2.1\n'
225
221
    short_header = 'bazaar-ng testament short form 2.1\n'
226
222
    include_root = False
227
 
 
228
223
    def _entry_to_line(self, path, ie):
229
224
        l = Testament._entry_to_line(self, path, ie)[:-1]
230
 
        l += ' ' + ie.revision.decode('utf-8')
 
225
        l += ' ' + ie.revision
231
226
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
232
227
        return l
233
228
 
245
240
    def _escape_path(self, path):
246
241
        if contains_linebreaks(path):
247
242
            raise ValueError(path)
248
 
        if not isinstance(path, text_type):
249
 
            # TODO(jelmer): Clean this up for pad.lv/1696545
250
 
            path = path.decode('ascii')
251
 
        if path == u'':
252
 
            path = u'.'
253
 
        return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
 
243
        if path == '':
 
244
            path = '.'
 
245
        return unicode(path.replace('\\', '/').replace(' ', '\\ '))