~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

and the tutorial patch came back, the very next day

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import bzrlib
42
42
import bzrlib.trace
43
43
from bzrlib.trace import mutter, note, log_error, warning
44
 
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
45
 
from bzrlib.revisionspec import RevisionSpec
 
44
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
 
45
from bzrlib.branch import find_branch
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
 
    each revision.
 
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()
81
83
 
82
84
    >>> _parse_revision_str('234')
83
 
    [<RevisionSpec_int 234>]
 
85
    [234]
84
86
    >>> _parse_revision_str('234..567')
85
 
    [<RevisionSpec_int 234>, <RevisionSpec_int 567>]
 
87
    [234, 567]
86
88
    >>> _parse_revision_str('..')
87
 
    [<RevisionSpec None>, <RevisionSpec None>]
 
89
    [None, None]
88
90
    >>> _parse_revision_str('..234')
89
 
    [<RevisionSpec None>, <RevisionSpec_int 234>]
 
91
    [None, 234]
90
92
    >>> _parse_revision_str('234..')
91
 
    [<RevisionSpec_int 234>, <RevisionSpec None>]
 
93
    [234, None]
92
94
    >>> _parse_revision_str('234..456..789') # Maybe this should be an error
93
 
    [<RevisionSpec_int 234>, <RevisionSpec_int 456>, <RevisionSpec_int 789>]
 
95
    [234, 456, 789]
94
96
    >>> _parse_revision_str('234....789') # Error?
95
 
    [<RevisionSpec_int 234>, <RevisionSpec None>, <RevisionSpec_int 789>]
 
97
    [234, None, 789]
96
98
    >>> _parse_revision_str('revid:test@other.com-234234')
97
 
    [<RevisionSpec_revid revid:test@other.com-234234>]
 
99
    ['revid:test@other.com-234234']
98
100
    >>> _parse_revision_str('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>]
 
101
    ['revid:test@other.com-234234', 'revid:test@other.com-234235']
100
102
    >>> _parse_revision_str('revid:test@other.com-234234..23')
101
 
    [<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_int 23>]
 
103
    ['revid:test@other.com-234234', 23]
102
104
    >>> _parse_revision_str('date:2005-04-12')
103
 
    [<RevisionSpec_date date:2005-04-12>]
 
105
    ['date:2005-04-12']
104
106
    >>> _parse_revision_str('date:2005-04-12 12:24:33')
105
 
    [<RevisionSpec_date date:2005-04-12 12:24:33>]
 
107
    ['date:2005-04-12 12:24:33']
106
108
    >>> _parse_revision_str('date:2005-04-12T12:24:33')
107
 
    [<RevisionSpec_date date:2005-04-12T12:24:33>]
 
109
    ['date:2005-04-12T12:24:33']
108
110
    >>> _parse_revision_str('date:2005-04-12,12:24:33')
109
 
    [<RevisionSpec_date date:2005-04-12,12:24:33>]
 
111
    ['date:2005-04-12,12:24:33']
110
112
    >>> _parse_revision_str('-5..23')
111
 
    [<RevisionSpec_int -5>, <RevisionSpec_int 23>]
 
113
    [-5, 23]
112
114
    >>> _parse_revision_str('-5')
113
 
    [<RevisionSpec_int -5>]
 
115
    [-5]
114
116
    >>> _parse_revision_str('123a')
115
 
    Traceback (most recent call last):
116
 
      ...
117
 
    BzrError: No namespace registered for string: '123a'
 
117
    ['123a']
118
118
    >>> _parse_revision_str('abc')
119
 
    Traceback (most recent call last):
120
 
      ...
121
 
    BzrError: No namespace registered for string: 'abc'
 
119
    ['abc']
122
120
    """
123
121
    import re
124
122
    old_format_re = re.compile('\d*:\d*')
125
123
    m = old_format_re.match(revstr)
126
 
    revs = []
127
124
    if m:
128
125
        warning('Colon separator for revision numbers is deprecated.'
129
126
                ' Use .. instead')
 
127
        revs = []
130
128
        for rev in revstr.split(':'):
131
129
            if rev:
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))
 
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)
141
143
    return revs
142
144
 
143
145
 
153
155
        msg = "No known merge type %s. Supported types are:\n%s" %\
154
156
            (typestring, type_list)
155
157
        raise BzrCommandError(msg)
 
158
    
 
159
 
 
160
def get_merge_type(typestring):
 
161
    """Attempt to find the merge class/factory associated with a string."""
 
162
    from merge import merge_types
 
163
    try:
 
164
        return merge_types[typestring][0]
 
165
    except KeyError:
 
166
        templ = '%s%%7s: %%s' % (' '*12)
 
167
        lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
 
168
        type_list = '\n'.join(lines)
 
169
        msg = "No known merge type %s. Supported types are:\n%s" %\
 
170
            (typestring, type_list)
 
171
        raise BzrCommandError(msg)
156
172
 
157
173
 
158
174
def _builtin_commands():
406
422
    >>> parse_args('commit --message=biter'.split())
407
423
    (['commit'], {'message': u'biter'})
408
424
    >>> parse_args('log -r 500'.split())
409
 
    (['log'], {'revision': [<RevisionSpec_int 500>]})
 
425
    (['log'], {'revision': [500]})
410
426
    >>> parse_args('log -r500..600'.split())
411
 
    (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
427
    (['log'], {'revision': [500, 600]})
412
428
    >>> parse_args('log -vr500..600'.split())
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>]})
 
429
    (['log'], {'verbose': True, 'revision': [500, 600]})
 
430
    >>> parse_args('log -rv500..600'.split()) #the r takes an argument
 
431
    (['log'], {'revision': ['v500', 600]})
416
432
    """
417
433
    args = []
418
434
    opts = {}
638
654
    bzrlib.trace.log_startup(argv)
639
655
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
640
656
 
641
 
    return run_bzr_catch_errors(argv[1:])
642
 
 
643
 
 
644
 
def run_bzr_catch_errors(argv):
645
657
    try:
646
658
        try:
647
 
            try:
648
 
                return run_bzr(argv)
649
 
            finally:
650
 
                # do this here inside the exception wrappers to catch EPIPE
651
 
                sys.stdout.flush()
652
 
        #wrap common errors as CommandErrors.
653
 
        except (NotBranchError,), e:
654
 
            raise BzrCommandError(str(e))
 
659
            return run_bzr(argv[1:])
 
660
        finally:
 
661
            # do this here inside the exception wrappers to catch EPIPE
 
662
            sys.stdout.flush()
655
663
    except BzrCommandError, e:
656
664
        # command line syntax error, etc
657
665
        log_error(str(e))