84
83
- produced from a revision
86
85
- loaded from a stream
87
86
- compared to a revision
91
def from_revision(cls, repository, revision_id):
90
def from_revision(cls, branch, revision_id):
92
91
"""Produce a new testament from a historical revision"""
93
rev = repository.get_revision(revision_id)
94
inventory = repository.get_inventory(revision_id)
95
return cls(rev, inventory)
97
def __init__(self, rev, inventory):
98
"""Create a new testament for rev using inventory."""
99
self.revision_id = str(rev.revision_id)
100
self.committer = rev.committer
101
self.timezone = rev.timezone or 0
102
self.timestamp = rev.timestamp
103
self.message = rev.message
104
self.parent_ids = rev.parent_ids[:]
105
self.inventory = inventory
106
self.revprops = copy(rev.properties)
107
assert not contains_whitespace(self.revision_id)
108
assert not contains_linebreaks(self.committer)
93
rev = branch.get_revision(revision_id)
94
t.revision_id = str(revision_id)
95
t.committer = rev.committer
96
t.timezone = rev.timezone or 0
97
t.timestamp = rev.timestamp
98
t.message = rev.message
99
t.parent_ids = rev.parent_ids[:]
100
t.inventory = branch.get_inventory(revision_id)
101
assert not contains_whitespace(t.revision_id)
102
assert not contains_linebreaks(t.committer)
110
105
def as_text_lines(self):
111
106
"""Yield text form as a sequence of lines.
131
127
a('inventory:\n')
132
128
for path, ie in self.inventory.iter_entries():
133
129
a(self._entry_to_line(path, ie))
134
r.extend(self._revprops_to_lines())
137
assert isinstance(l, basestring), \
132
assert isinstance(l, str), \
138
133
'%r of type %s is not a plain string' % (l, type(l))
139
return [line.encode('utf-8') for line in r]
141
136
def _escape_path(self, path):
142
137
assert not contains_linebreaks(path)
171
166
% (self.revision_id, s.hexdigest()))
173
def _revprops_to_lines(self):
174
"""Pack up revision properties."""
175
if not self.revprops:
177
r = ['properties:\n']
178
for name, value in sorted(self.revprops.items()):
179
assert isinstance(name, str)
180
assert not contains_whitespace(name)
181
r.append(' %s:\n' % name)
182
for line in value.splitlines():
183
if not isinstance(line, str):
184
line = line.encode('utf-8')
185
r.append(' %s\n' % line)