21
21
NULL_REVISION="null:"
23
class RevisionReference(object):
25
Reference to a stored revision.
27
Includes the revision_id and revision_sha1.
30
def __eq__(self, other):
32
return self.revision_id == other.revision_id and \
33
self.revision_sha1 == other.revision_sha1
34
except AttributeError:
37
def __init__(self, revision_id, revision_sha1=None):
38
self.revision_id = None
39
self.revision_sha1 = None
40
if revision_id == None \
41
or isinstance(revision_id, basestring):
42
self.revision_id = revision_id
44
raise ValueError('bad revision_id %r' % revision_id)
46
if revision_sha1 != None:
47
if isinstance(revision_sha1, basestring) \
48
and len(revision_sha1) == 40:
49
self.revision_sha1 = revision_sha1
51
raise ValueError('bad revision_sha1 %r' % revision_sha1)
55
23
class Revision(object):
56
24
"""Single revision on a branch.
62
30
After bzr 0.0.5 revisions are allowed to have multiple parents.
65
List of parent revisions, each is a RevisionReference.
33
List of parent revision_ids
68
def __init__(self, inventory_id=None, inventory_sha1=None,
69
revision_id=None, timestamp=None,
70
message=None, timezone=None,
71
committer=None, parents=None):
72
self.inventory_id = inventory_id
73
self.inventory_sha1 = inventory_sha1
74
self.revision_id = revision_id
75
self.timestamp = timestamp
76
self.message = message
77
self.timezone = timezone
78
self.committer = committer
79
if parents is not None:
80
self.parents = parents
84
def __eq__(self, other):
86
return self.inventory_id == other.inventory_id and \
87
self.inventory_sha1 == other.inventory_sha1 and \
88
self.revision_id == other.revision_id and \
89
self.timestamp == other.timestamp and \
90
self.message == other.message and \
91
self.timezone == other.timezone and \
92
self.committer == other.committer and \
93
self.parents == other.parents
94
except AttributeError:
36
def __init__(self, **args):
37
self.__dict__.update(args)
39
self.parent_sha1s = []
97
41
def __repr__(self):
98
42
return "<Revision id %s>" % self.revision_id
100
44
def __eq__(self, other):
101
45
if not isinstance(other, Revision):
103
return (self.inventory_id == other.inventory_id
104
and self.inventory_sha1 == other.inventory_sha1
47
# FIXME: rbc 20050930 parent_ids are not being compared
49
self.inventory_sha1 == other.inventory_sha1
105
50
and self.revision_id == other.revision_id
106
51
and self.timestamp == other.timestamp
107
52
and self.message == other.message
124
69
if not REVISION_ID_RE.match(rid):
125
70
raise ValueError("malformed revision-id %r" % rid)
127
def is_ancestor(revision_id, candidate_id, revision_source):
73
def is_ancestor(revision_id, candidate_id, branch):
128
74
"""Return true if candidate_id is an ancestor of revision_id.
129
76
A false negative will be returned if any intermediate descendent of
130
77
candidate_id is not present in any of the revision_sources.
132
79
revisions_source is an object supporting a get_revision operation that
133
80
behaves like Branch's.
135
if candidate_id is None:
137
for ancestor_id, distance in iter_ancestors(revision_id, revision_source):
138
if ancestor_id == candidate_id:
82
return candidate_id in branch.get_ancestry(revision_id)
142
85
def iter_ancestors(revision_id, revision_source, only_present=False):
143
86
ancestors = (revision_id,)
241
184
rev = revision_source.get_revision(line)
242
parents = [p.revision_id for p in rev.parents]
185
parents = list(rev.parent_ids)
243
186
if len(parents) == 0:
244
187
parents = [NULL_REVISION]
245
188
except bzrlib.errors.NoSuchRevision: