/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-28 16:19:47 UTC
  • mto: This revision was merged to the branch mainline in revision 1979.
  • Revision ID: john@arbash-meinel.com-20060828161947-5986ffb6cf082f59
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
 
122
122
        symbol_versioning.warn('Creating a RevisionSpec directly has'
123
123
                               ' been deprecated in version 0.11. Use'
124
 
                               ' bzrlib.revisionspec.get_revision_spec()'
 
124
                               ' RevisionSpec.from_string()'
125
125
                               ' instead.',
126
126
                               DeprecationWarning, stacklevel=2)
127
 
        return get_revision_spec(spec)
 
127
        return RevisionSpec.from_string(spec)
 
128
 
 
129
    @staticmethod
 
130
    def from_string(spec):
 
131
        """Parse a revision spec string into a RevisionSpec object.
 
132
 
 
133
        :param spec: A string specified by the user
 
134
        :return: A RevisionSpec object that understands how to parse the
 
135
            supplied notation.
 
136
        """
 
137
        if not isinstance(spec, (type(None), basestring)):
 
138
            raise TypeError('error')
 
139
 
 
140
        if spec is None:
 
141
            return RevisionSpec(None, _internal=True)
 
142
 
 
143
        assert isinstance(spec, basestring), \
 
144
            "You should only supply strings not %s" % (type(spec),)
 
145
 
 
146
        for spectype in SPEC_TYPES:
 
147
            if spec.startswith(spectype.prefix):
 
148
                trace.mutter('Returning RevisionSpec %s for %s',
 
149
                             spectype.__name__, spec)
 
150
                return spectype(spec, _internal=True)
 
151
        else:
 
152
            # RevisionSpec_revno is special cased, because it is the only
 
153
            # one that directly handles plain integers
 
154
            global _revno_regex
 
155
            if _revno_regex is None:
 
156
                _revno_regex = re.compile(r'-?\d+(:.*)?$')
 
157
            if _revno_regex.match(spec) is not None:
 
158
                return RevisionSpec_revno(spec, _internal=True)
 
159
 
 
160
            raise errors.NoSuchRevisionSpec(spec)
128
161
 
129
162
    def __init__(self, spec, _internal=False):
130
163
        """Create a RevisionSpec referring to the Null revision.
131
164
 
132
165
        :param spec: The original spec supplied by the user
133
166
        :param _internal: Used to ensure that RevisionSpec is not being
134
 
            called directly. Only from get_revision_spec()
 
167
            called directly. Only from RevisionSpec.from_string()
135
168
        """
136
169
        if not _internal:
137
170
            # XXX: Update this after 0.10 is released
138
171
            symbol_versioning.warn('Creating a RevisionSpec directly has'
139
172
                                   ' been deprecated in version 0.11. Use'
140
 
                                   ' bzrlib.revisionspec.get_revision_spec()'
 
173
                                   ' RevisionSpec.from_string()'
141
174
                                   ' instead.',
142
175
                                   DeprecationWarning, stacklevel=2)
143
176
        self.user_spec = spec
193
226
 
194
227
_revno_regex = None
195
228
 
196
 
def get_revision_spec(spec):
197
 
    """Parse a revision spec into a RevisionSpec object.
198
 
 
199
 
    :param spec: A string specified by the user
200
 
    :return: A RevisionSpec object that understands how to parse the
201
 
        supplied notation.
202
 
    """
203
 
    if not isinstance(spec, (type(None), basestring)):
204
 
        raise TypeError('error')
205
 
 
206
 
    if spec is None:
207
 
        return RevisionSpec(None, _internal=True)
208
 
 
209
 
    assert isinstance(spec, basestring), \
210
 
        "You should only supply strings not %s" % (type(spec),)
211
 
 
212
 
    for spectype in SPEC_TYPES:
213
 
        if spec.startswith(spectype.prefix):
214
 
            trace.mutter('Returning RevisionSpec %s for %s',
215
 
                         spectype.__name__, spec)
216
 
            return spectype(spec, _internal=True)
217
 
    else:
218
 
        # RevisionSpec_revno is special cased, because it is the only
219
 
        # one that directly handles plain integers
220
 
        global _revno_regex
221
 
        if _revno_regex is None:
222
 
            _revno_regex = re.compile(r'-?\d+(:.*)?$')
223
 
        if _revno_regex.match(spec) is not None:
224
 
            return RevisionSpec_revno(spec, _internal=True)
225
 
 
226
 
        raise errors.NoSuchRevisionSpec(spec)
227
 
        
228
 
        
229
229
# private API
230
230
 
231
231
 
327
327
    prefix = 'before:'
328
328
    
329
329
    def _match_on(self, branch, revs):
330
 
        r = get_revision_spec(self.spec)._match_on(branch, revs)
 
330
        r = RevisionSpec.from_string(self.spec)._match_on(branch, revs)
331
331
        if r.revno == 0:
332
332
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
333
333
                                         'cannot go before the null: revision')