~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-10-16 10:03:21 UTC
  • mfrom: (1988.4.6 dotted-revno-input.)
  • Revision ID: pqm@pqm.ubuntu.com-20061016100321-c4951c9fc020dbd0
(Robert Collins) Output dotted decimal revision numbers during log, and accept them as revision specifiers.

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
 
255
260
        else:
256
261
            try:
257
262
                revno = int(revno_spec)
258
 
            except ValueError, e:
259
 
                raise errors.InvalidRevisionSpec(self.user_spec,
260
 
                                                 branch, e)
 
263
                dotted = False
 
264
            except ValueError:
 
265
                # dotted decimal. This arguably should not be here
 
266
                # but the from_string method is a little primitive 
 
267
                # right now - RBC 20060928
 
268
                try:
 
269
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
 
270
                except ValueError, e:
 
271
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
 
272
 
 
273
                dotted = True
261
274
 
262
275
        if branch_spec:
 
276
            # the user has override the branch to look in.
 
277
            # we need to refresh the revision_history map and
 
278
            # the branch object.
263
279
            from bzrlib.branch import Branch
264
280
            branch = Branch.open(branch_spec)
265
281
            # Need to use a new revision history
266
282
            # because we are using a specific branch
267
283
            revs = branch.revision_history()
268
284
 
269
 
        if revno < 0:
270
 
            if (-revno) >= len(revs):
271
 
                revno = 1
 
285
        if dotted:
 
286
            branch.lock_read()
 
287
            try:
 
288
                last_rev = branch.last_revision()
 
289
                merge_sorted_revisions = tsort.merge_sort(
 
290
                    branch.repository.get_revision_graph(last_rev),
 
291
                    last_rev,
 
292
                    generate_revno=True)
 
293
                def match(item):
 
294
                    return item[3] == match_revno
 
295
                revisions = filter(match, merge_sorted_revisions)
 
296
            finally:
 
297
                branch.unlock()
 
298
            if len(revisions) != 1:
 
299
                return RevisionInfo(branch, None, None)
272
300
            else:
273
 
                revno = len(revs) + revno + 1
274
 
        try:
275
 
            revision_id = branch.get_rev_id(revno, revs)
276
 
        except errors.NoSuchRevision:
277
 
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
 
301
                # there is no traditional 'revno' for dotted-decimal revnos.
 
302
                # so for  API compatability we return None.
 
303
                return RevisionInfo(branch, None, revisions[0][1])
 
304
        else:
 
305
            if revno < 0:
 
306
                if (-revno) >= len(revs):
 
307
                    revno = 1
 
308
                else:
 
309
                    revno = len(revs) + revno + 1
 
310
            try:
 
311
                revision_id = branch.get_rev_id(revno, revs)
 
312
            except errors.NoSuchRevision:
 
313
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
278
314
        return RevisionInfo(branch, revno, revision_id)
279
315
        
280
316
    def needs_branch(self):