/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-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
* the testament uses unix line-endings (\n)
60
60
"""
61
61
 
 
62
from __future__ import absolute_import
 
63
 
62
64
# XXX: At the moment, clients trust that the graph described in a weave
63
65
# is accurate, but that's not covered by the testament.  Perhaps the best
64
66
# fix is when verifying a revision to make sure that every file mentioned
71
73
 
72
74
from copy import copy
73
75
 
74
 
from ..osutils import (
 
76
from .osutils import (
75
77
    contains_whitespace,
76
78
    contains_linebreaks,
77
79
    sha_strings,
78
80
    )
79
 
from ..tree import Tree
 
81
from .tree import Tree
80
82
 
81
83
 
82
84
class Testament(object):
117
119
        self.parent_ids = rev.parent_ids[:]
118
120
        if not isinstance(tree, Tree):
119
121
            raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
120
 
                            "Revision and a Tree.")
 
122
                "Revision and a Tree.")
121
123
        self.tree = tree
122
124
        self.revprops = copy(rev.properties)
123
125
        if contains_whitespace(self.revision_id):
134
136
        r = []
135
137
        a = r.append
136
138
        a(self.long_header)
137
 
        a('revision-id: %s\n' % self.revision_id.decode('utf-8'))
 
139
        a('revision-id: %s\n' % self.revision_id)
138
140
        a('committer: %s\n' % self.committer)
139
141
        a('timestamp: %d\n' % self.timestamp)
140
142
        a('timezone: %d\n' % self.timezone)
143
145
        for parent_id in sorted(self.parent_ids):
144
146
            if contains_whitespace(parent_id):
145
147
                raise ValueError(parent_id)
146
 
            a('  %s\n' % parent_id.decode('utf-8'))
 
148
            a('  %s\n' % parent_id)
147
149
        a('message:\n')
148
150
        for l in self.message.splitlines():
149
151
            a('  %s\n' % l)
154
156
        return [line.encode('utf-8') for line in r]
155
157
 
156
158
    def _get_entries(self):
157
 
        return ((path, ie) for (path, file_class, kind, ie) in
 
159
        return ((path, ie) for (path, versioned, kind, file_id, ie) in
158
160
                self.tree.list_files(include_root=self.include_root))
159
161
 
160
162
    def _escape_path(self, path):
161
163
        if contains_linebreaks(path):
162
164
            raise ValueError(path)
163
 
        if not isinstance(path, str):
164
 
            # TODO(jelmer): Clean this up for pad.lv/1696545
165
 
            path = path.decode('ascii')
166
 
        return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
 
165
        return unicode(path.replace('\\', '/').replace(' ', '\\ '))
167
166
 
168
167
    def _entry_to_line(self, path, ie):
169
168
        """Turn an inventory entry into a testament line"""
170
169
        if contains_whitespace(ie.file_id):
171
170
            raise ValueError(ie.file_id)
172
171
        content = ''
173
 
        content_spacer = ''
 
172
        content_spacer=''
174
173
        if ie.kind == 'file':
175
174
            # TODO: avoid switching on kind
176
175
            if not ie.text_sha1:
177
176
                raise AssertionError()
178
 
            content = ie.text_sha1.decode('ascii')
 
177
            content = ie.text_sha1
179
178
            content_spacer = ' '
180
179
        elif ie.kind == 'symlink':
181
180
            if not ie.symlink_target:
189
188
        return l
190
189
 
191
190
    def as_text(self):
192
 
        return b''.join(self.as_text_lines())
 
191
        return ''.join(self.as_text_lines())
193
192
 
194
193
    def as_short_text(self):
195
194
        """Return short digest-based testament."""
196
 
        return (self.short_header.encode('ascii') +
197
 
                b'revision-id: %s\n'
198
 
                b'sha1: %s\n'
 
195
        return (self.short_header +
 
196
                'revision-id: %s\n'
 
197
                'sha1: %s\n'
199
198
                % (self.revision_id, self.as_sha1()))
200
199
 
201
200
    def _revprops_to_lines(self):
221
220
    long_header = 'bazaar-ng testament version 2.1\n'
222
221
    short_header = 'bazaar-ng testament short form 2.1\n'
223
222
    include_root = False
224
 
 
225
223
    def _entry_to_line(self, path, ie):
226
224
        l = Testament._entry_to_line(self, path, ie)[:-1]
227
 
        l += ' ' + ie.revision.decode('utf-8')
 
225
        l += ' ' + ie.revision
228
226
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
229
227
        return l
230
228
 
242
240
    def _escape_path(self, path):
243
241
        if contains_linebreaks(path):
244
242
            raise ValueError(path)
245
 
        if not isinstance(path, str):
246
 
            # TODO(jelmer): Clean this up for pad.lv/1696545
247
 
            path = path.decode('ascii')
248
 
        if path == u'':
249
 
            path = u'.'
250
 
        return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
 
243
        if path == '':
 
244
            path = '.'
 
245
        return unicode(path.replace('\\', '/').replace(' ', '\\ '))