/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Martin Pool
  • Date: 2005-06-28 11:14:41 UTC
  • Revision ID: mbp@sourcefrog.net-20050628111441-db4512efe25b418a
- Remove dead code from remotebranch

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    """
26
26
    revision_id = None
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.
50
50
 
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
    be dropped.
52
55
 
53
56
    parents
54
57
        List of parent revisions, each is a RevisionReference.
65
68
        self.__dict__.update(args)
66
69
        self.parents = []
67
70
 
 
71
    def _get_precursor(self):
 
72
        from warnings import warn
 
73
        warn("Revision.precursor is deprecated", stacklevel=2)
 
74
        if self.parents:
 
75
            return self.parents[0].revision_id
 
76
        else:
 
77
            return None
 
78
 
 
79
 
 
80
    def _get_precursor_sha1(self):
 
81
        from warnings import warn
 
82
        warn("Revision.precursor_sha1 is deprecated", stacklevel=2)
 
83
        if self.parents:
 
84
            return self.parents[0].revision_sha1
 
85
        else:
 
86
            return None    
 
87
 
 
88
 
 
89
    def _fail(self):
 
90
        raise Exception("can't assign to precursor anymore")
 
91
 
 
92
 
 
93
    precursor = property(_get_precursor, _fail, _fail)
 
94
    precursor_sha1 = property(_get_precursor_sha1, _fail, _fail)
 
95
 
 
96
 
68
97
 
69
98
    def __repr__(self):
70
99
        return "<Revision id %s>" % self.revision_id
89
118
        msg.tail = '\n'
90
119
 
91
120
        if self.parents:
 
121
            # first parent stored as precursor for compatability with 0.0.5 and
 
122
            # earlier
 
123
            pr = self.parents[0]
 
124
            assert pr.revision_id
 
125
            root.set('precursor', pr.revision_id)
 
126
            if pr.revision_sha1:
 
127
                root.set('precursor_sha1', pr.revision_sha1)
 
128
                
 
129
        if self.parents:
92
130
            pelts = SubElement(root, 'parents')
93
131
            pelts.tail = pelts.text = '\n'
94
132
            for rr in self.parents:
130
168
 
131
169
    pelts = elt.find('parents')
132
170
 
133
 
    if pelts:
 
171
    if precursor:
 
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)
 
176
    elif pelts:
134
177
        for p in pelts:
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)
140
183
 
141
 
        if precursor:
142
 
            # must be consistent
143
 
            prec_parent = rev.parents[0].revision_id
144
 
            assert prec_parent == precursor
145
 
    elif 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)
150
 
 
151
184
    v = elt.get('timezone')
152
185
    rev.timezone = v and int(v)
153
186
 
154
187
    rev.message = elt.findtext('message') # text of <message>
155
188
    return rev
156
 
 
157
 
 
158
 
 
159
 
REVISION_ID_RE = None
160
 
 
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:
165
 
        import re
166
 
        REVISION_ID_RE = re.compile('[\w.-]+@[\w.-]+--?\d+--?[0-9a-f]+\Z')
167
 
 
168
 
    if not REVISION_ID_RE.match(rid):
169
 
        raise ValueError("malformed revision-id %r" % rid)
170
 
 
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.
175
 
    
176
 
    revisions_source is an object supporting a get_revision operation that
177
 
    behaves like Branch's.
178
 
    """
179
 
 
180
 
    from bzrlib.branch import NoSuchRevision
181
 
    ancestors = (revision_id,)
182
 
    while len(ancestors) > 0:
183
 
        new_ancestors = []
184
 
        for ancestor in ancestors:
185
 
            if ancestor == candidate_id:
186
 
                return True
187
 
            try:
188
 
                revision = revision_source.get_revision(ancestor)
189
 
            except NoSuchRevision, e:
190
 
                if e.revision == revision_id:
191
 
                    raise e
192
 
                else:
193
 
                    continue
194
 
            new_ancestors.extend([p.revision_id for p in revision.parents])
195
 
        ancestors = new_ancestors
196
 
 
197
 
 
198
 
class MultipleRevisionSources(object):
199
 
    def __init__(self, *args):
200
 
        object.__init__(self)
201
 
        assert len(args) != 0
202
 
        self._revision_sources = args
203
 
 
204
 
    def get_revision(self, revision_id):
205
 
        from bzrlib.branch import NoSuchRevision
206
 
        for source in self._revision_sources:
207
 
            try:
208
 
                return source.get_revision(revision_id)
209
 
            except NoSuchRevision, e:
210
 
                pass
211
 
        raise e