/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 bzrlib/testament.py

  • Committer: Martin Pool
  • Date: 2011-05-20 14:46:02 UTC
  • mto: This revision was merged to the branch mainline in revision 5923.
  • Revision ID: mbp@canonical.com-20110520144602-bqli0t6dj01gl0pv
Various pyflakes import fixes.

Some modules were used for subclassing or at module load time, so there is no
point loading them lazily.

Some were not imported when they should be.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
from bzrlib.osutils import (
75
75
    contains_whitespace,
76
76
    contains_linebreaks,
77
 
    sha,
 
77
    sha_strings,
78
78
    )
 
79
from bzrlib.tree import Tree
79
80
 
80
81
 
81
82
class Testament(object):
91
92
 
92
93
    long_header = 'bazaar-ng testament version 1\n'
93
94
    short_header = 'bazaar-ng testament short form 1\n'
 
95
    include_root = False
94
96
 
95
97
    @classmethod
96
98
    def from_revision(cls, repository, revision_id):
97
 
        """Produce a new testament from a historical revision"""
 
99
        """Produce a new testament from a historical revision."""
98
100
        rev = repository.get_revision(revision_id)
99
 
        inventory = repository.get_inventory(revision_id)
100
 
        return cls(rev, inventory)
101
 
 
102
 
    def __init__(self, rev, inventory):
103
 
        """Create a new testament for rev using inventory."""
 
101
        tree = repository.revision_tree(revision_id)
 
102
        return cls(rev, tree)
 
103
 
 
104
    @classmethod
 
105
    def from_revision_tree(cls, tree):
 
106
        """Produce a new testament from a revision tree."""
 
107
        rev = tree._repository.get_revision(tree.get_revision_id())
 
108
        return cls(rev, tree)
 
109
 
 
110
    def __init__(self, rev, tree):
 
111
        """Create a new testament for rev using tree."""
104
112
        self.revision_id = rev.revision_id
105
113
        self.committer = rev.committer
106
114
        self.timezone = rev.timezone or 0
107
115
        self.timestamp = rev.timestamp
108
116
        self.message = rev.message
109
117
        self.parent_ids = rev.parent_ids[:]
110
 
        self.inventory = inventory
 
118
        if not isinstance(tree, Tree):
 
119
            raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
 
120
                "Revision and a Tree.")
 
121
        self.tree = tree
111
122
        self.revprops = copy(rev.properties)
112
123
        if contains_whitespace(self.revision_id):
113
124
            raise ValueError(self.revision_id)
143
154
        return [line.encode('utf-8') for line in r]
144
155
 
145
156
    def _get_entries(self):
146
 
        entries = self.inventory.iter_entries()
147
 
        entries.next()
148
 
        return entries
 
157
        return ((path, ie) for (path, versioned, kind, file_id, ie) in
 
158
                self.tree.list_files(include_root=self.include_root))
149
159
 
150
160
    def _escape_path(self, path):
151
161
        if contains_linebreaks(path):
199
209
        return r
200
210
 
201
211
    def as_sha1(self):
202
 
        s = sha()
203
 
        map(s.update, self.as_text_lines())
204
 
        return s.hexdigest()
 
212
        return sha_strings(self.as_text_lines())
205
213
 
206
214
 
207
215
class StrictTestament(Testament):
209
217
 
210
218
    long_header = 'bazaar-ng testament version 2.1\n'
211
219
    short_header = 'bazaar-ng testament short form 2.1\n'
 
220
    include_root = False
212
221
    def _entry_to_line(self, path, ie):
213
222
        l = Testament._entry_to_line(self, path, ie)[:-1]
214
223
        l += ' ' + ie.revision
224
233
 
225
234
    long_header = 'bazaar testament version 3 strict\n'
226
235
    short_header = 'bazaar testament short form 3 strict\n'
227
 
    def _get_entries(self):
228
 
        return self.inventory.iter_entries()
 
236
    include_root = True
229
237
 
230
238
    def _escape_path(self, path):
231
239
        if contains_linebreaks(path):