~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Robert Collins
  • Date: 2005-09-30 02:54:51 UTC
  • mfrom: (1395)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050930025451-47b9e412202be44b
symlink and weaves, whaddya know

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
 
 
30
 
    def __eq__(self, other):
31
 
        try:
32
 
            return self.revision_id == other.revision_id and \
33
 
                   self.revision_sha1 == other.revision_sha1
34
 
        except AttributeError:
35
 
            return False
36
 
 
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
43
 
        else:
44
 
            raise ValueError('bad revision_id %r' % revision_id)
45
 
 
46
 
        if revision_sha1 != None:
47
 
            if isinstance(revision_sha1, basestring) \
48
 
               and len(revision_sha1) == 40:
49
 
                self.revision_sha1 = revision_sha1
50
 
            else:
51
 
                raise ValueError('bad revision_sha1 %r' % revision_sha1)
52
 
                
53
 
 
54
 
 
55
23
class Revision(object):
56
24
    """Single revision on a branch.
57
25
 
61
29
 
62
30
    After bzr 0.0.5 revisions are allowed to have multiple parents.
63
31
 
64
 
    parents
65
 
        List of parent revisions, each is a RevisionReference.
 
32
    parent_ids
 
33
        List of parent revision_ids
66
34
    """
67
35
    
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
81
 
        else:
82
 
            self.parents = []
83
 
 
84
 
    def __eq__(self, other):
85
 
        try:
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:
95
 
            return False
 
36
    def __init__(self, **args):
 
37
        self.__dict__.update(args)
 
38
        self.parent_ids = []
 
39
        self.parent_sha1s = []
96
40
 
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):
102
46
            return False
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
 
48
        return (
 
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)
126
71
 
127
 
def is_ancestor(revision_id, candidate_id, revision_source):
 
72
 
 
73
def is_ancestor(revision_id, candidate_id, branch):
128
74
    """Return true if candidate_id is an ancestor of revision_id.
 
75
 
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.
131
78
    
132
79
    revisions_source is an object supporting a get_revision operation that
133
80
    behaves like Branch's.
134
81
    """
135
 
    if candidate_id is None:
136
 
        return True
137
 
    for ancestor_id, distance in iter_ancestors(revision_id, revision_source):
138
 
        if ancestor_id == candidate_id:
139
 
            return True
140
 
    return False
 
82
    return candidate_id in branch.get_ancestry(revision_id)
 
83
 
141
84
 
142
85
def iter_ancestors(revision_id, revision_source, only_present=False):
143
86
    ancestors = (revision_id,)
156
99
                    continue
157
100
            if only_present:
158
101
                yield ancestor, distance
159
 
            new_ancestors.extend([p.revision_id for p in revision.parents])
 
102
            new_ancestors.extend(revision.parent_ids)
160
103
        ancestors = new_ancestors
161
104
        distance += 1
162
105
 
239
182
            else:
240
183
                try:
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: