1
# Copyright (C) 2004, 2005 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
import bzrlib.commands
21
from bzrlib.trace import warning, mutter
22
from bzrlib.revisionspec import RevisionSpec
25
def _parse_revision_str(revstr):
26
"""This handles a revision string -> revno.
28
This always returns a list. The list will have one element for
29
each revision specifier supplied.
31
>>> _parse_revision_str('234')
32
[<RevisionSpec_int 234>]
33
>>> _parse_revision_str('234..567')
34
[<RevisionSpec_int 234>, <RevisionSpec_int 567>]
35
>>> _parse_revision_str('..')
36
[<RevisionSpec None>, <RevisionSpec None>]
37
>>> _parse_revision_str('..234')
38
[<RevisionSpec None>, <RevisionSpec_int 234>]
39
>>> _parse_revision_str('234..')
40
[<RevisionSpec_int 234>, <RevisionSpec None>]
41
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
42
[<RevisionSpec_int 234>, <RevisionSpec_int 456>, <RevisionSpec_int 789>]
43
>>> _parse_revision_str('234....789') #Error ?
44
[<RevisionSpec_int 234>, <RevisionSpec None>, <RevisionSpec_int 789>]
45
>>> _parse_revision_str('revid:test@other.com-234234')
46
[<RevisionSpec_revid revid:test@other.com-234234>]
47
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
48
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
49
>>> _parse_revision_str('revid:test@other.com-234234..23')
50
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_int 23>]
51
>>> _parse_revision_str('date:2005-04-12')
52
[<RevisionSpec_date date:2005-04-12>]
53
>>> _parse_revision_str('date:2005-04-12 12:24:33')
54
[<RevisionSpec_date date:2005-04-12 12:24:33>]
55
>>> _parse_revision_str('date:2005-04-12T12:24:33')
56
[<RevisionSpec_date date:2005-04-12T12:24:33>]
57
>>> _parse_revision_str('date:2005-04-12,12:24:33')
58
[<RevisionSpec_date date:2005-04-12,12:24:33>]
59
>>> _parse_revision_str('-5..23')
60
[<RevisionSpec_int -5>, <RevisionSpec_int 23>]
61
>>> _parse_revision_str('-5')
62
[<RevisionSpec_int -5>]
63
>>> _parse_revision_str('123a')
64
Traceback (most recent call last):
66
BzrError: No namespace registered for string: '123a'
67
>>> _parse_revision_str('abc')
68
Traceback (most recent call last):
70
BzrError: No namespace registered for string: 'abc'
71
>>> _parse_revision_str('branch:../branch2')
72
[<RevisionSpec_branch branch:../branch2>]
74
# TODO: Maybe move this into revisionspec.py
75
old_format_re = re.compile('\d*:\d*')
76
m = old_format_re.match(revstr)
79
warning('Colon separator for revision numbers is deprecated.'
81
for rev in revstr.split(':'):
83
revs.append(RevisionSpec(int(rev)))
85
revs.append(RevisionSpec(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))
104
def _parse_merge_type(typestring):
105
return bzrlib.commands.get_merge_type(typestring)
108
class Option(object):
112
def __init__(self, name, help='help string', type=None):
113
# need to add some description of the parameters here
118
def _global_option(name, **kwargs):
119
"""Register o as a global option."""
120
Option.OPTIONS[name] = Option(name, **kwargs)
122
_global_option('all', type=None)
123
_global_option('basis', type=str)
124
_global_option('diff-options', type=str)
125
_global_option('help', type=None)
126
_global_option('file', type=unicode)
127
_global_option('force', type=None)
128
_global_option('format', type=unicode)
129
_global_option('forward', type=None)
130
_global_option('message', type=unicode)
131
_global_option('no-recurse', type=None)
132
_global_option('profile', type=None)
133
_global_option('revision', type=_parse_revision_str)
134
_global_option('short', type=None)
135
_global_option('show-ids', type=None)
136
_global_option('timezone', type=str)
137
_global_option('verbose', type=None)
138
_global_option('version', type=None)
139
_global_option('email', type=None)
140
_global_option('unchanged', type=None)
141
_global_option('update', type=None)
142
_global_option('long', type=None)
143
_global_option('root', type=str)
144
_global_option('no-backup', type=None)
145
_global_option('merge-type', type=_parse_merge_type)
146
_global_option('pattern', type=str)
147
_global_option('quiet', type=None)
148
_global_option('remember', type=None)
150
Option.SHORT_OPTIONS['F'] = Option.OPTIONS['file']
151
Option.SHORT_OPTIONS['h'] = Option.OPTIONS['help']
152
Option.SHORT_OPTIONS['m'] = Option.OPTIONS['message']
153
Option.SHORT_OPTIONS['r'] = Option.OPTIONS['revision']
154
Option.SHORT_OPTIONS['v'] = Option.OPTIONS['verbose']
155
Option.SHORT_OPTIONS['l'] = Option.OPTIONS['long']
156
Option.SHORT_OPTIONS['q'] = Option.OPTIONS['quiet']