~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-16 14:57:59 UTC
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050916145758-ad06c9ae86840f17
Merged up-to-date against mainline, still broken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
import bzrlib.trace
43
43
from bzrlib.trace import mutter, note, log_error, warning
44
44
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
45
 
from bzrlib.branch import find_branch
 
45
from bzrlib.revisionspec import RevisionSpec
46
46
from bzrlib import BZRDIR
47
47
 
48
48
plugin_cmds = {}
76
76
def _parse_revision_str(revstr):
77
77
    """This handles a revision string -> revno.
78
78
 
79
 
    This always returns a list.  The list will have one element for 
80
 
 
81
 
    It supports integers directly, but everything else it
82
 
    defers for passing to Branch.get_revision_info()
 
79
    This always returns a list.  The list will have one element for
 
80
    each revision.
83
81
 
84
82
    >>> _parse_revision_str('234')
85
 
    [234]
 
83
    [<RevisionSpec_int 234>]
86
84
    >>> _parse_revision_str('234..567')
87
 
    [234, 567]
 
85
    [<RevisionSpec_int 234>, <RevisionSpec_int 567>]
88
86
    >>> _parse_revision_str('..')
89
 
    [None, None]
 
87
    [<RevisionSpec None>, <RevisionSpec None>]
90
88
    >>> _parse_revision_str('..234')
91
 
    [None, 234]
 
89
    [<RevisionSpec None>, <RevisionSpec_int 234>]
92
90
    >>> _parse_revision_str('234..')
93
 
    [234, None]
 
91
    [<RevisionSpec_int 234>, <RevisionSpec None>]
94
92
    >>> _parse_revision_str('234..456..789') # Maybe this should be an error
95
 
    [234, 456, 789]
 
93
    [<RevisionSpec_int 234>, <RevisionSpec_int 456>, <RevisionSpec_int 789>]
96
94
    >>> _parse_revision_str('234....789') # Error?
97
 
    [234, None, 789]
 
95
    [<RevisionSpec_int 234>, <RevisionSpec None>, <RevisionSpec_int 789>]
98
96
    >>> _parse_revision_str('revid:test@other.com-234234')
99
 
    ['revid:test@other.com-234234']
 
97
    [<RevisionSpec_revid revid:test@other.com-234234>]
100
98
    >>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
101
 
    ['revid:test@other.com-234234', 'revid:test@other.com-234235']
 
99
    [<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
102
100
    >>> _parse_revision_str('revid:test@other.com-234234..23')
103
 
    ['revid:test@other.com-234234', 23]
 
101
    [<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_int 23>]
104
102
    >>> _parse_revision_str('date:2005-04-12')
105
 
    ['date:2005-04-12']
 
103
    [<RevisionSpec_date date:2005-04-12>]
106
104
    >>> _parse_revision_str('date:2005-04-12 12:24:33')
107
 
    ['date:2005-04-12 12:24:33']
 
105
    [<RevisionSpec_date date:2005-04-12 12:24:33>]
108
106
    >>> _parse_revision_str('date:2005-04-12T12:24:33')
109
 
    ['date:2005-04-12T12:24:33']
 
107
    [<RevisionSpec_date date:2005-04-12T12:24:33>]
110
108
    >>> _parse_revision_str('date:2005-04-12,12:24:33')
111
 
    ['date:2005-04-12,12:24:33']
 
109
    [<RevisionSpec_date date:2005-04-12,12:24:33>]
112
110
    >>> _parse_revision_str('-5..23')
113
 
    [-5, 23]
 
111
    [<RevisionSpec_int -5>, <RevisionSpec_int 23>]
114
112
    >>> _parse_revision_str('-5')
115
 
    [-5]
 
113
    [<RevisionSpec_int -5>]
116
114
    >>> _parse_revision_str('123a')
117
 
    ['123a']
 
115
    Traceback (most recent call last):
 
116
      ...
 
117
    BzrError: No namespace registered for string: '123a'
118
118
    >>> _parse_revision_str('abc')
119
 
    ['abc']
 
119
    Traceback (most recent call last):
 
120
      ...
 
121
    BzrError: No namespace registered for string: 'abc'
120
122
    """
121
123
    import re
122
124
    old_format_re = re.compile('\d*:\d*')
123
125
    m = old_format_re.match(revstr)
 
126
    revs = []
124
127
    if m:
125
128
        warning('Colon separator for revision numbers is deprecated.'
126
129
                ' Use .. instead')
127
 
        revs = []
128
130
        for rev in revstr.split(':'):
129
131
            if rev:
130
 
                revs.append(int(rev))
131
 
            else:
132
 
                revs.append(None)
133
 
        return revs
134
 
    revs = []
135
 
    for x in revstr.split('..'):
136
 
        if not x:
137
 
            revs.append(None)
138
 
        else:
139
 
            try:
140
 
                revs.append(int(x))
141
 
            except ValueError:
142
 
                revs.append(x)
 
132
                revs.append(RevisionSpec(int(rev)))
 
133
            else:
 
134
                revs.append(RevisionSpec(None))
 
135
    else:
 
136
        for x in revstr.split('..'):
 
137
            if not x:
 
138
                revs.append(RevisionSpec(None))
 
139
            else:
 
140
                revs.append(RevisionSpec(x))
143
141
    return revs
144
142
 
145
143
 
408
406
    >>> parse_args('commit --message=biter'.split())
409
407
    (['commit'], {'message': u'biter'})
410
408
    >>> parse_args('log -r 500'.split())
411
 
    (['log'], {'revision': [500]})
 
409
    (['log'], {'revision': [<RevisionSpec_int 500>]})
412
410
    >>> parse_args('log -r500..600'.split())
413
 
    (['log'], {'revision': [500, 600]})
 
411
    (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
414
412
    >>> parse_args('log -vr500..600'.split())
415
 
    (['log'], {'verbose': True, 'revision': [500, 600]})
416
 
    >>> parse_args('log -rv500..600'.split()) #the r takes an argument
417
 
    (['log'], {'revision': ['v500', 600]})
 
413
    (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
414
    >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
 
415
    (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})
418
416
    """
419
417
    args = []
420
418
    opts = {}