1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2004, 2005 by Canonical Ltd
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
17
# TODO: For things like --diff-prefix, we want a way to customize the display
18
# of the option argument.
22
20
import bzrlib.commands
23
21
from bzrlib.trace import warning, mutter
24
22
from bzrlib.revisionspec import RevisionSpec
25
from bzrlib.errors import BzrCommandError
28
25
def _parse_revision_str(revstr):
73
70
BzrError: No namespace registered for string: 'abc'
74
71
>>> _parse_revision_str('branch:../branch2')
75
72
[<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>]
81
74
# TODO: Maybe move this into revisionspec.py
82
75
old_format_re = re.compile('\d*:\d*')
92
85
revs.append(RevisionSpec(None))
94
sep = re.compile("\\.\\.(?!/)")
95
for x in sep.split(revstr):
96
revs.append(RevisionSpec(x or None))
88
for x in revstr.split('..'):
90
revs.append(RevisionSpec(None))
92
# looks like a namespace:.. has happened
93
next_prefix = x + '..'
95
if next_prefix is not None:
97
revs.append(RevisionSpec(x))
99
if next_prefix is not None:
100
revs.append(RevisionSpec(next_prefix))
100
104
def _parse_merge_type(typestring):
101
return get_merge_type(typestring)
105
return bzrlib.commands.get_merge_type(typestring)
103
def get_merge_type(typestring):
104
"""Attempt to find the merge class/factory associated with a string."""
105
from merge import merge_types
107
return merge_types[typestring][0]
109
templ = '%s%%7s: %%s' % (' '*12)
110
lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
111
type_list = '\n'.join(lines)
112
msg = "No known merge type %s. Supported types are:\n%s" %\
113
(typestring, type_list)
114
raise BzrCommandError(msg)
116
108
class Option(object):
117
109
"""Description of a command line option"""
151
143
Short options are globally registered.
153
for short, option in Option.SHORT_OPTIONS.iteritems():
145
return Option.SHORT_OPTIONS.get(self.name)
158
148
def _global_option(name, **kwargs):
160
150
Option.OPTIONS[name] = Option(name, **kwargs)
162
152
_global_option('all')
163
_global_option('overwrite', help='Ignore differences between branches and '
164
'overwrite unconditionally')
165
153
_global_option('basis', type=str)
166
_global_option('bound')
167
154
_global_option('diff-options', type=str)
168
_global_option('diff-prefix', type=str,
169
help='Set prefixes to added to old and new filenames, as two values separated by a colon')
170
155
_global_option('help',
171
156
help='show help message')
172
157
_global_option('file', type=unicode)
178
163
_global_option('profile',
179
164
help='show performance profiling information')
180
165
_global_option('revision', type=_parse_revision_str)
166
_global_option('short')
181
167
_global_option('show-ids',
182
168
help='show internal object ids')
183
169
_global_option('timezone',
185
171
help='display timezone as local, original, or utc')
186
_global_option('unbound')
187
172
_global_option('verbose',
188
173
help='display more information')
189
174
_global_option('version')
190
175
_global_option('email')
191
176
_global_option('update')
192
_global_option('log-format', type=str, help="Use this log format")
193
_global_option('long', help='Use detailed log format. Same as --log-format long')
194
_global_option('short', help='Use moderately short log format. Same as --log-format short')
195
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
177
_global_option('long')
196
178
_global_option('root', type=str)
197
179
_global_option('no-backup')
198
180
_global_option('merge-type', type=_parse_merge_type)
199
181
_global_option('pattern', type=str)
200
182
_global_option('quiet')
201
_global_option('remember', help='Remember the specified location as a'
203
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
204
_global_option('kind', type=str)
205
_global_option('dry-run',
206
help="show what would be done, but don't actually do anything")
183
_global_option('remember')
209
186
def _global_short(short_name, long_name):