~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

Late bind to PatienceSequenceMatcher to allow plugin to override.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
# TODO: For things like --diff-prefix, we want a way to customize the display
 
18
# of the option argument.
17
19
 
18
20
import re
19
21
 
20
22
import bzrlib.commands
21
23
from bzrlib.trace import warning, mutter
22
24
from bzrlib.revisionspec import RevisionSpec
 
25
from bzrlib.errors import BzrCommandError
23
26
 
24
27
 
25
28
def _parse_revision_str(revstr):
70
73
    BzrError: No namespace registered for string: 'abc'
71
74
    >>> _parse_revision_str('branch:../branch2')
72
75
    [<RevisionSpec_branch branch:../branch2>]
 
76
    >>> _parse_revision_str('branch:../../branch2')
 
77
    [<RevisionSpec_branch branch:../../branch2>]
 
78
    >>> _parse_revision_str('branch:../../branch2..23')
 
79
    [<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_int 23>]
73
80
    """
74
81
    # TODO: Maybe move this into revisionspec.py
75
82
    old_format_re = re.compile('\d*:\d*')
84
91
            else:
85
92
                revs.append(RevisionSpec(None))
86
93
    else:
87
 
        next_prefix = None
88
 
        for x in revstr.split('..'):
89
 
            if not x:
90
 
                revs.append(RevisionSpec(None))
91
 
            elif x[-1] == ':':
92
 
                # looks like a namespace:.. has happened
93
 
                next_prefix = x + '..'
94
 
            else:
95
 
                if next_prefix is not None:
96
 
                    x = next_prefix + x
97
 
                revs.append(RevisionSpec(x))
98
 
                next_prefix = None
99
 
        if next_prefix is not None:
100
 
            revs.append(RevisionSpec(next_prefix))
 
94
        sep = re.compile("\\.\\.(?!/)")
 
95
        for x in sep.split(revstr):
 
96
            revs.append(RevisionSpec(x or None))
101
97
    return revs
102
98
 
103
99
 
154
150
 
155
151
        Short options are globally registered.
156
152
        """
157
 
        return Option.SHORT_OPTIONS.get(self.name)
 
153
        for short, option in Option.SHORT_OPTIONS.iteritems():
 
154
            if option is self:
 
155
                return short
158
156
 
159
157
 
160
158
def _global_option(name, **kwargs):
162
160
    Option.OPTIONS[name] = Option(name, **kwargs)
163
161
 
164
162
_global_option('all')
165
 
_global_option('clobber')
 
163
_global_option('overwrite', help='Ignore differences between branches and '
 
164
               'overwrite unconditionally')
166
165
_global_option('basis', type=str)
 
166
_global_option('bound')
167
167
_global_option('diff-options', type=str)
168
168
_global_option('help',
169
169
               help='show help message')
173
173
_global_option('forward')
174
174
_global_option('message', type=unicode)
175
175
_global_option('no-recurse')
 
176
_global_option('prefix', type=str, 
 
177
               help='Set prefixes to added to old and new filenames, as '
 
178
                    'two values separated by a colon.')
176
179
_global_option('profile',
177
180
               help='show performance profiling information')
178
181
_global_option('revision', type=_parse_revision_str)
179
 
_global_option('short')
180
182
_global_option('show-ids', 
181
183
               help='show internal object ids')
182
184
_global_option('timezone', 
183
185
               type=str,
184
186
               help='display timezone as local, original, or utc')
 
187
_global_option('unbound')
185
188
_global_option('verbose',
186
189
               help='display more information')
187
190
_global_option('version')
188
191
_global_option('email')
189
192
_global_option('update')
190
 
_global_option('long')
 
193
_global_option('log-format', type=str, help="Use this log format")
 
194
_global_option('long', help='Use detailed log format. Same as --log-format long')
 
195
_global_option('short', help='Use moderately short log format. Same as --log-format short')
 
196
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
191
197
_global_option('root', type=str)
192
198
_global_option('no-backup')
193
 
_global_option('merge-type', type=_parse_merge_type)
 
199
_global_option('merge-type', type=_parse_merge_type, 
 
200
               help='Select a particular merge algorithm')
194
201
_global_option('pattern', type=str)
195
202
_global_option('quiet')
196
 
_global_option('remember')
 
203
_global_option('remember', help='Remember the specified location as a'
 
204
               ' default.')
 
205
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
 
206
_global_option('kind', type=str)
 
207
_global_option('dry-run',
 
208
               help="show what would be done, but don't actually do anything")
197
209
 
198
210
 
199
211
def _global_short(short_name, long_name):
208
220
Option.SHORT_OPTIONS['v'] = Option.OPTIONS['verbose']
209
221
Option.SHORT_OPTIONS['l'] = Option.OPTIONS['long']
210
222
Option.SHORT_OPTIONS['q'] = Option.OPTIONS['quiet']
 
223
Option.SHORT_OPTIONS['p'] = Option.OPTIONS['prefix']