/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/revisionspec.py

  • Committer: ghigo
  • Date: 2006-10-22 16:43:28 UTC
  • mfrom: (2091 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2126.
  • Revision ID: ghigo@venice-20061022164328-da86f3a7676b06bd
Update to bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    revision,
25
25
    symbol_versioning,
26
26
    trace,
 
27
    tsort,
27
28
    )
28
29
 
29
30
 
152
153
        else:
153
154
            # RevisionSpec_revno is special cased, because it is the only
154
155
            # one that directly handles plain integers
 
156
            # TODO: This should not be special cased rather it should be
 
157
            # a method invocation on spectype.canparse()
155
158
            global _revno_regex
156
159
            if _revno_regex is None:
157
 
                _revno_regex = re.compile(r'-?\d+(:.*)?$')
 
160
                _revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
158
161
            if _revno_regex.match(spec) is not None:
159
162
                return RevisionSpec_revno(spec, _internal=True)
160
163
 
199
202
        if branch:
200
203
            revs = branch.revision_history()
201
204
        else:
 
205
            # this should never trigger.
 
206
            # TODO: make it a deprecated code path. RBC 20060928
202
207
            revs = None
203
208
        return self._match_on_and_check(branch, revs)
204
209
 
272
277
        else:
273
278
            try:
274
279
                revno = int(revno_spec)
275
 
            except ValueError, e:
276
 
                raise errors.InvalidRevisionSpec(self.user_spec,
277
 
                                                 branch, e)
 
280
                dotted = False
 
281
            except ValueError:
 
282
                # dotted decimal. This arguably should not be here
 
283
                # but the from_string method is a little primitive 
 
284
                # right now - RBC 20060928
 
285
                try:
 
286
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
 
287
                except ValueError, e:
 
288
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
 
289
 
 
290
                dotted = True
278
291
 
279
292
        if branch_spec:
 
293
            # the user has override the branch to look in.
 
294
            # we need to refresh the revision_history map and
 
295
            # the branch object.
280
296
            from bzrlib.branch import Branch
281
297
            branch = Branch.open(branch_spec)
282
298
            # Need to use a new revision history
283
299
            # because we are using a specific branch
284
300
            revs = branch.revision_history()
285
301
 
286
 
        if revno < 0:
287
 
            if (-revno) >= len(revs):
288
 
                revno = 1
 
302
        if dotted:
 
303
            branch.lock_read()
 
304
            try:
 
305
                last_rev = branch.last_revision()
 
306
                merge_sorted_revisions = tsort.merge_sort(
 
307
                    branch.repository.get_revision_graph(last_rev),
 
308
                    last_rev,
 
309
                    generate_revno=True)
 
310
                def match(item):
 
311
                    return item[3] == match_revno
 
312
                revisions = filter(match, merge_sorted_revisions)
 
313
            finally:
 
314
                branch.unlock()
 
315
            if len(revisions) != 1:
 
316
                return RevisionInfo(branch, None, None)
289
317
            else:
290
 
                revno = len(revs) + revno + 1
291
 
        try:
292
 
            revision_id = branch.get_rev_id(revno, revs)
293
 
        except errors.NoSuchRevision:
294
 
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
 
318
                # there is no traditional 'revno' for dotted-decimal revnos.
 
319
                # so for  API compatability we return None.
 
320
                return RevisionInfo(branch, None, revisions[0][1])
 
321
        else:
 
322
            if revno < 0:
 
323
                if (-revno) >= len(revs):
 
324
                    revno = 1
 
325
                else:
 
326
                    revno = len(revs) + revno + 1
 
327
            try:
 
328
                revision_id = branch.get_rev_id(revno, revs)
 
329
            except errors.NoSuchRevision:
 
330
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
295
331
        return RevisionInfo(branch, revno, revision_id)
296
332
        
297
333
    def needs_branch(self):