~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-10-05 21:15:13 UTC
  • mfrom: (5448.3.5 374700-Add-gnu-lsh-support)
  • Revision ID: pqm@pqm.ubuntu.com-20101005211513-whouyj5t7oo92gmq
(gz) Add support for GNU lsh as a secure shell client (Matthew Gordon)

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
 
 
64
62
# XXX: At the moment, clients trust that the graph described in a weave
65
63
# is accurate, but that's not covered by the testament.  Perhaps the best
66
64
# fix is when verifying a revision to make sure that every file mentioned
76
74
from bzrlib.osutils import (
77
75
    contains_whitespace,
78
76
    contains_linebreaks,
79
 
    sha_strings,
 
77
    sha,
80
78
    )
81
 
from bzrlib.tree import Tree
82
79
 
83
80
 
84
81
class Testament(object):
94
91
 
95
92
    long_header = 'bazaar-ng testament version 1\n'
96
93
    short_header = 'bazaar-ng testament short form 1\n'
97
 
    include_root = False
98
94
 
99
95
    @classmethod
100
96
    def from_revision(cls, repository, revision_id):
101
 
        """Produce a new testament from a historical revision."""
 
97
        """Produce a new testament from a historical revision"""
102
98
        rev = repository.get_revision(revision_id)
103
 
        tree = repository.revision_tree(revision_id)
104
 
        return cls(rev, tree)
105
 
 
106
 
    @classmethod
107
 
    def from_revision_tree(cls, tree):
108
 
        """Produce a new testament from a revision tree."""
109
 
        rev = tree._repository.get_revision(tree.get_revision_id())
110
 
        return cls(rev, tree)
111
 
 
112
 
    def __init__(self, rev, tree):
113
 
        """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."""
114
104
        self.revision_id = rev.revision_id
115
105
        self.committer = rev.committer
116
106
        self.timezone = rev.timezone or 0
117
107
        self.timestamp = rev.timestamp
118
108
        self.message = rev.message
119
109
        self.parent_ids = rev.parent_ids[:]
120
 
        if not isinstance(tree, Tree):
121
 
            raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
122
 
                "Revision and a Tree.")
123
 
        self.tree = tree
 
110
        self.inventory = inventory
124
111
        self.revprops = copy(rev.properties)
125
112
        if contains_whitespace(self.revision_id):
126
113
            raise ValueError(self.revision_id)
156
143
        return [line.encode('utf-8') for line in r]
157
144
 
158
145
    def _get_entries(self):
159
 
        return ((path, ie) for (path, versioned, kind, file_id, ie) in
160
 
                self.tree.list_files(include_root=self.include_root))
 
146
        entries = self.inventory.iter_entries()
 
147
        entries.next()
 
148
        return entries
161
149
 
162
150
    def _escape_path(self, path):
163
151
        if contains_linebreaks(path):
211
199
        return r
212
200
 
213
201
    def as_sha1(self):
214
 
        return sha_strings(self.as_text_lines())
 
202
        s = sha()
 
203
        map(s.update, self.as_text_lines())
 
204
        return s.hexdigest()
215
205
 
216
206
 
217
207
class StrictTestament(Testament):
219
209
 
220
210
    long_header = 'bazaar-ng testament version 2.1\n'
221
211
    short_header = 'bazaar-ng testament short form 2.1\n'
222
 
    include_root = False
223
212
    def _entry_to_line(self, path, ie):
224
213
        l = Testament._entry_to_line(self, path, ie)[:-1]
225
214
        l += ' ' + ie.revision
235
224
 
236
225
    long_header = 'bazaar testament version 3 strict\n'
237
226
    short_header = 'bazaar testament short form 3 strict\n'
238
 
    include_root = True
 
227
    def _get_entries(self):
 
228
        return self.inventory.iter_entries()
239
229
 
240
230
    def _escape_path(self, path):
241
231
        if contains_linebreaks(path):