27
27
revision_sha1 = None
28
def __init__(self, revision_id, revision_sha1=None):
28
def __init__(self, revision_id, revision_sha1):
29
29
if revision_id == None \
30
30
or isinstance(revision_id, basestring):
31
31
self.revision_id = revision_id
49
49
into the file it describes.
51
51
After bzr 0.0.5 revisions are allowed to have multiple parents.
52
To support old clients this is written out in a slightly redundant
53
form: the first parent as the predecessor. This will eventually
54
57
List of parent revisions, each is a RevisionReference.
65
68
self.__dict__.update(args)
71
def _get_precursor(self):
72
from warnings import warn
73
warn("Revision.precursor is deprecated", stacklevel=2)
75
return self.parents[0].revision_id
80
def _get_precursor_sha1(self):
81
from warnings import warn
82
warn("Revision.precursor_sha1 is deprecated", stacklevel=2)
84
return self.parents[0].revision_sha1
90
raise Exception("can't assign to precursor anymore")
93
precursor = property(_get_precursor, _fail, _fail)
94
precursor_sha1 = property(_get_precursor_sha1, _fail, _fail)
69
98
def __repr__(self):
70
99
return "<Revision id %s>" % self.revision_id
121
# first parent stored as precursor for compatability with 0.0.5 and
124
assert pr.revision_id
125
root.set('precursor', pr.revision_id)
127
root.set('precursor_sha1', pr.revision_sha1)
92
130
pelts = SubElement(root, 'parents')
93
131
pelts.tail = pelts.text = '\n'
94
132
for rr in self.parents:
131
169
pelts = elt.find('parents')
172
# revisions written prior to 0.0.5 have a single precursor
173
# give as an attribute
174
rev_ref = RevisionReference(precursor, precursor_sha1)
175
rev.parents.append(rev_ref)
135
178
assert p.tag == 'revision_ref', \
136
179
"bad parent node tag %r" % p.tag
138
181
p.get('revision_sha1'))
139
182
rev.parents.append(rev_ref)
143
prec_parent = rev.parents[0].revision_id
144
assert prec_parent == precursor
146
# revisions written prior to 0.0.5 have a single precursor
147
# give as an attribute
148
rev_ref = RevisionReference(precursor, precursor_sha1)
149
rev.parents.append(rev_ref)
151
184
v = elt.get('timezone')
152
185
rev.timezone = v and int(v)
154
187
rev.message = elt.findtext('message') # text of <message>
159
REVISION_ID_RE = None
161
def validate_revision_id(rid):
162
"""Check rid is syntactically valid for a revision id."""
163
global REVISION_ID_RE
164
if not REVISION_ID_RE:
166
REVISION_ID_RE = re.compile('[\w.-]+@[\w.-]+--?\d+--?[0-9a-f]+\Z')
168
if not REVISION_ID_RE.match(rid):
169
raise ValueError("malformed revision-id %r" % rid)
171
def is_ancestor(revision_id, candidate_id, revision_source):
172
"""Return true if candidate_id is an ancestor of revision_id.
173
A false negative will be returned if any intermediate descendent of
174
candidate_id is not present in any of the revision_sources.
176
revisions_source is an object supporting a get_revision operation that
177
behaves like Branch's.
180
from bzrlib.branch import NoSuchRevision
181
ancestors = (revision_id,)
182
while len(ancestors) > 0:
184
for ancestor in ancestors:
185
if ancestor == candidate_id:
188
revision = revision_source.get_revision(ancestor)
189
except NoSuchRevision, e:
190
if e.revision == revision_id:
194
new_ancestors.extend([p.revision_id for p in revision.parents])
195
ancestors = new_ancestors
198
class MultipleRevisionSources(object):
199
def __init__(self, *args):
200
object.__init__(self)
201
assert len(args) != 0
202
self._revision_sources = args
204
def get_revision(self, revision_id):
205
from bzrlib.branch import NoSuchRevision
206
for source in self._revision_sources:
208
return source.get_revision(revision_id)
209
except NoSuchRevision, e: