~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

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