/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

Merge test-run support.

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 .sixish import text_type
 
82
from .tree import Tree
83
83
 
84
84
 
85
85
class Testament(object):
94
94
    """
95
95
 
96
96
    long_header = 'bazaar-ng testament version 1\n'
97
 
    short_header = 'bazaar-ng testament short form 1\n'
 
97
    short_header = b'bazaar-ng testament short form 1\n'
98
98
    include_root = False
99
99
 
100
100
    @classmethod
120
120
        self.parent_ids = rev.parent_ids[:]
121
121
        if not isinstance(tree, Tree):
122
122
            raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
123
 
                            "Revision and a Tree.")
 
123
                "Revision and a Tree.")
124
124
        self.tree = tree
125
125
        self.revprops = copy(rev.properties)
126
126
        if contains_whitespace(self.revision_id):
137
137
        r = []
138
138
        a = r.append
139
139
        a(self.long_header)
140
 
        a('revision-id: %s\n' % self.revision_id.decode('utf-8'))
 
140
        a('revision-id: %s\n' % self.revision_id)
141
141
        a('committer: %s\n' % self.committer)
142
142
        a('timestamp: %d\n' % self.timestamp)
143
143
        a('timezone: %d\n' % self.timezone)
146
146
        for parent_id in sorted(self.parent_ids):
147
147
            if contains_whitespace(parent_id):
148
148
                raise ValueError(parent_id)
149
 
            a('  %s\n' % parent_id.decode('utf-8'))
 
149
            a('  %s\n' % parent_id)
150
150
        a('message:\n')
151
151
        for l in self.message.splitlines():
152
152
            a('  %s\n' % l)
157
157
        return [line.encode('utf-8') for line in r]
158
158
 
159
159
    def _get_entries(self):
160
 
        return ((path, ie) for (path, file_class, kind, ie) in
 
160
        return ((path, ie) for (path, versioned, kind, file_id, ie) in
161
161
                self.tree.list_files(include_root=self.include_root))
162
162
 
163
163
    def _escape_path(self, path):
173
173
        if contains_whitespace(ie.file_id):
174
174
            raise ValueError(ie.file_id)
175
175
        content = ''
176
 
        content_spacer = ''
 
176
        content_spacer=''
177
177
        if ie.kind == 'file':
178
178
            # TODO: avoid switching on kind
179
179
            if not ie.text_sha1:
180
180
                raise AssertionError()
181
 
            content = ie.text_sha1.decode('ascii')
 
181
            content = ie.text_sha1
182
182
            content_spacer = ' '
183
183
        elif ie.kind == 'symlink':
184
184
            if not ie.symlink_target:
196
196
 
197
197
    def as_short_text(self):
198
198
        """Return short digest-based testament."""
199
 
        return (self.short_header.encode('ascii') +
 
199
        return (self.short_header +
200
200
                b'revision-id: %s\n'
201
201
                b'sha1: %s\n'
202
202
                % (self.revision_id, self.as_sha1()))
224
224
    long_header = 'bazaar-ng testament version 2.1\n'
225
225
    short_header = 'bazaar-ng testament short form 2.1\n'
226
226
    include_root = False
227
 
 
228
227
    def _entry_to_line(self, path, ie):
229
228
        l = Testament._entry_to_line(self, path, ie)[:-1]
230
 
        l += ' ' + ie.revision.decode('utf-8')
 
229
        l += ' ' + ie.revision.decode('ascii')
231
230
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
232
231
        return l
233
232