~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Aaron Bentley
  • Date: 2005-09-29 21:07:17 UTC
  • mfrom: (1393.1.6)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20050929210717-cd73981590f17017
Merged the weave changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
NULL_REVISION="null:"
22
22
 
23
 
class RevisionReference(object):
24
 
    """
25
 
    Reference to a stored revision.
26
 
 
27
 
    Includes the revision_id and revision_sha1.
28
 
    """
29
 
    revision_id = None
30
 
    revision_sha1 = None
31
 
    def __init__(self, revision_id, revision_sha1=None):
32
 
        if revision_id == None \
33
 
           or isinstance(revision_id, basestring):
34
 
            self.revision_id = revision_id
35
 
        else:
36
 
            raise ValueError('bad revision_id %r' % revision_id)
37
 
 
38
 
        if revision_sha1 != None:
39
 
            if isinstance(revision_sha1, basestring) \
40
 
               and len(revision_sha1) == 40:
41
 
                self.revision_sha1 = revision_sha1
42
 
            else:
43
 
                raise ValueError('bad revision_sha1 %r' % revision_sha1)
44
 
                
45
 
 
46
 
 
47
23
class Revision(object):
48
24
    """Single revision on a branch.
49
25
 
53
29
 
54
30
    After bzr 0.0.5 revisions are allowed to have multiple parents.
55
31
 
56
 
    parents
57
 
        List of parent revisions, each is a RevisionReference.
 
32
    parent_ids
 
33
        List of parent revision_ids
58
34
    """
59
35
    inventory_id = None
60
36
    inventory_sha1 = None
66
42
    
67
43
    def __init__(self, **args):
68
44
        self.__dict__.update(args)
69
 
        self.parents = []
 
45
        self.parent_ids = []
 
46
        self.parent_sha1s = []
70
47
 
71
48
 
72
49
    def __repr__(self):
100
77
    if not REVISION_ID_RE.match(rid):
101
78
        raise ValueError("malformed revision-id %r" % rid)
102
79
 
103
 
def is_ancestor(revision_id, candidate_id, revision_source):
 
80
 
 
81
def is_ancestor(revision_id, candidate_id, branch):
104
82
    """Return true if candidate_id is an ancestor of revision_id.
 
83
 
105
84
    A false negative will be returned if any intermediate descendent of
106
85
    candidate_id is not present in any of the revision_sources.
107
86
    
108
87
    revisions_source is an object supporting a get_revision operation that
109
88
    behaves like Branch's.
110
89
    """
111
 
    if candidate_id is None:
112
 
        return True
113
 
    for ancestor_id, distance in iter_ancestors(revision_id, revision_source):
114
 
        if ancestor_id == candidate_id:
115
 
            return True
116
 
    return False
 
90
    return candidate_id in branch.get_ancestry(revision_id)
 
91
 
117
92
 
118
93
def iter_ancestors(revision_id, revision_source, only_present=False):
119
94
    ancestors = (revision_id,)
132
107
                    continue
133
108
            if only_present:
134
109
                yield ancestor, distance
135
 
            new_ancestors.extend([p.revision_id for p in revision.parents])
 
110
            new_ancestors.extend(revision.parent_ids)
136
111
        ancestors = new_ancestors
137
112
        distance += 1
138
113
 
215
190
            else:
216
191
                try:
217
192
                    rev = revision_source.get_revision(line)
218
 
                    parents = [p.revision_id for p in rev.parents]
 
193
                    parents = list(rev.parent_ids)
219
194
                    if len(parents) == 0:
220
195
                        parents = [NULL_REVISION]
221
196
                except bzrlib.errors.NoSuchRevision: