/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2005-2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
16
6379.6.1 by Jelmer Vernooij
Import absolute_import in a few places.
17
from __future__ import absolute_import
18
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
19
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
20
from .lazy_import import lazy_import
3224.5.31 by Andrew Bennetts
A couple more lazy imports, helps 'bzr log --line -r -1' a little.
21
lazy_import(globals(), """
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
22
import bisect
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
23
import datetime
5671.1.2 by Jelmer Vernooij
Lazy load gzip (we don't use it when doing 2a), remove some unused imports.
24
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy import (
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
26
    branch as _mod_branch,
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
27
    cache_utf8,
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
28
    revision,
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
29
    workingtree,
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.i18n import gettext
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
32
""")
33
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
34
from . import (
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
35
    errors,
5685.1.2 by Jelmer Vernooij
Merge bzr.dev.
36
    lazy_regex,
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
37
    registry,
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
38
    trace,
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
39
    )
6695.3.2 by Martin
Fix test fallout from basestring removal
40
from .sixish import (
41
    text_type,
42
    )
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
43
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
44
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
45
class RevisionInfo(object):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
46
    """The results of applying a revision specification to a branch."""
47
48
    help_txt = """The results of applying a revision specification to a branch.
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
49
50
    An instance has two useful attributes: revno, and rev_id.
51
52
    They can also be accessed as spec[0] and spec[1] respectively,
53
    so that you can write code like:
54
    revno, rev_id = RevisionSpec(branch, spec)
55
    although this is probably going to be deprecated later.
56
57
    This class exists mostly to be the return value of a RevisionSpec,
58
    so that you can access the member you're interested in (number or id)
59
    or treat the result as a tuple.
60
    """
61
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
62
    def __init__(self, branch, revno=None, rev_id=None):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
63
        self.branch = branch
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
64
        self._has_revno = (revno is not None)
65
        self._revno = revno
66
        self.rev_id = rev_id
67
        if self.rev_id is None and self._revno is not None:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
68
            # allow caller to be lazy
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
69
            self.rev_id = branch.get_rev_id(self._revno)
70
71
    @property
72
    def revno(self):
73
        if not self._has_revno and self.rev_id is not None:
74
            try:
75
                self._revno = self.branch.revision_id_to_revno(self.rev_id)
7290.19.7 by Jelmer Vernooij
Catch RevnoOutOfBounds.
76
            except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
77
                self._revno = None
78
            self._has_revno = True
79
        return self._revno
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
80
6619.3.20 by Jelmer Vernooij
Apply 2to3 nonzero fix.
81
    def __bool__(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
82
        if self.rev_id is None:
83
            return False
84
        # TODO: otherwise, it should depend on how I was built -
85
        # if it's in_history(branch), then check revision_history(),
86
        # if it's in_store(branch), do the check below
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
87
        return self.branch.repository.has_revision(self.rev_id)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
88
6619.3.23 by Jelmer Vernooij
Keep __nonzero__ around for Python2.
89
    __nonzero__ = __bool__
90
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
91
    def __len__(self):
92
        return 2
93
94
    def __getitem__(self, index):
7143.15.2 by Jelmer Vernooij
Run autopep8.
95
        if index == 0:
96
            return self.revno
97
        if index == 1:
98
            return self.rev_id
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
99
        raise IndexError(index)
100
101
    def get(self):
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
102
        return self.branch.repository.get_revision(self.rev_id)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
103
104
    def __eq__(self, other):
105
        if type(other) not in (tuple, list, type(self)):
106
            return False
6619.3.18 by Jelmer Vernooij
Run 2to3 idioms fixer.
107
        if isinstance(other, type(self)) and self.branch is not other.branch:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
108
            return False
109
        return tuple(self) == tuple(other)
110
111
    def __repr__(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
112
        return '<breezy.revisionspec.RevisionInfo object %s, %s for %r>' % (
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
113
            self.revno, self.rev_id, self.branch)
114
2220.2.3 by Martin Pool
Add tag: revision namespace.
115
    @staticmethod
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
116
    def from_revision_id(branch, revision_id):
2220.2.3 by Martin Pool
Add tag: revision namespace.
117
        """Construct a RevisionInfo given just the id.
118
119
        Use this if you don't know or care what the revno is.
120
        """
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
121
        return RevisionInfo(branch, revno=None, rev_id=revision_id)
2220.2.3 by Martin Pool
Add tag: revision namespace.
122
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
123
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
124
class RevisionSpec(object):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
125
    """A parsed revision specification."""
126
127
    help_txt = """A parsed revision specification.
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
128
4569.2.3 by Matthew Fuller
Adjust the help test for the RevisionSpec class a bit to describe the
129
    A revision specification is a string, which may be unambiguous about
130
    what it represents by giving a prefix like 'date:' or 'revid:' etc,
131
    or it may have no prefix, in which case it's tried against several
132
    specifier types in sequence to determine what the user meant.
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
133
134
    Revision specs are an UI element, and they have been moved out
135
    of the branch class to leave "back-end" classes unaware of such
136
    details.  Code that gets a revno or rev_id from other code should
137
    not be using revision specs - revnos and revision ids are the
138
    accepted ways to refer to revisions internally.
139
140
    (Equivalent to the old Branch method get_revision_info())
141
    """
142
143
    prefix = None
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
144
    dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
4569.2.21 by Vincent Ladeuil
Fix some typos.
145
    """Exceptions that RevisionSpec_dwim._match_on will catch.
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
146
4569.2.21 by Vincent Ladeuil
Fix some typos.
147
    If the revspec is part of ``dwim_revspecs``, it may be tried with an
148
    invalid revspec and raises some exception. The exceptions mentioned here
149
    will not be reported to the user but simply ignored without stopping the
150
    dwim processing.
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
151
    """
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
152
153
    @staticmethod
154
    def from_string(spec):
155
        """Parse a revision spec string into a RevisionSpec object.
156
157
        :param spec: A string specified by the user
158
        :return: A RevisionSpec object that understands how to parse the
159
            supplied notation.
160
        """
161
        if spec is None:
162
            return RevisionSpec(None, _internal=True)
6695.3.2 by Martin
Fix test fallout from basestring removal
163
        if not isinstance(spec, (str, text_type)):
164
            raise TypeError("revision spec needs to be text")
3966.2.1 by Jelmer Vernooij
Register revision specifiers in a registry.
165
        match = revspec_registry.get_prefix(spec)
166
        if match is not None:
167
            spectype, specsuffix = match
168
            trace.mutter('Returning RevisionSpec %s for %s',
169
                         spectype.__name__, spec)
170
            return spectype(spec, _internal=True)
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
171
        else:
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
172
            # Otherwise treat it as a DWIM, build the RevisionSpec object and
173
            # wait for _match_on to be called.
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
174
            return RevisionSpec_dwim(spec, _internal=True)
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
175
176
    def __init__(self, spec, _internal=False):
177
        """Create a RevisionSpec referring to the Null revision.
178
179
        :param spec: The original spec supplied by the user
180
        :param _internal: Used to ensure that RevisionSpec is not being
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
181
            called directly. Only from RevisionSpec.from_string()
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
182
        """
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
183
        if not _internal:
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
184
            raise AssertionError(
185
                'Creating a RevisionSpec directly is not supported. '
186
                'Use RevisionSpec.from_string() instead.')
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
187
        self.user_spec = spec
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
188
        if self.prefix and spec.startswith(self.prefix):
189
            spec = spec[len(self.prefix):]
190
        self.spec = spec
191
192
    def _match_on(self, branch, revs):
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
193
        trace.mutter('Returning RevisionSpec._match_on: None')
3298.2.11 by Aaron Bentley
Update tests for null:, clea up slightly
194
        return RevisionInfo(branch, None, None)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
195
196
    def _match_on_and_check(self, branch, revs):
197
        info = self._match_on(branch, revs)
198
        if info:
199
            return info
3298.2.11 by Aaron Bentley
Update tests for null:, clea up slightly
200
        elif info == (None, None):
201
            # special case - nothing supplied
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
202
            return info
203
        elif self.prefix:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
204
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
205
        else:
1948.4.2 by John Arbash Meinel
Update _match_on_and_check to raise the right error
206
            raise errors.InvalidRevisionSpec(self.spec, branch)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
207
208
    def in_history(self, branch):
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
209
        return self._match_on_and_check(branch, revs=None)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
210
1432 by Robert Collins
branch: namespace
211
        # FIXME: in_history is somewhat broken,
212
        # it will return non-history revisions in many
213
        # circumstances. The expected facility is that
214
        # in_history only returns revision-history revs,
215
        # in_store returns any rev. RBC 20051010
216
    # aliases for now, when we fix the core logic, then they
217
    # will do what you expect.
218
    in_store = in_history
3298.2.8 by John Arbash Meinel
Get rid of .in_branch(need_revno=False) in favor of simpler .as_revision_id()
219
    in_branch = in_store
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
220
3298.2.4 by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False)
221
    def as_revision_id(self, context_branch):
222
        """Return just the revision_id for this revisions spec.
223
224
        Some revision specs require a context_branch to be able to determine
225
        their value. Not all specs will make use of it.
226
        """
227
        return self._as_revision_id(context_branch)
228
229
    def _as_revision_id(self, context_branch):
230
        """Implementation of as_revision_id()
231
232
        Classes should override this function to provide appropriate
233
        functionality. The default is to just call '.in_history().rev_id'
234
        """
235
        return self.in_history(context_branch).rev_id
236
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
237
    def as_tree(self, context_branch):
238
        """Return the tree object for this revisions spec.
239
240
        Some revision specs require a context_branch to be able to determine
241
        the revision id and access the repository. Not all specs will make
242
        use of it.
243
        """
244
        return self._as_tree(context_branch)
245
246
    def _as_tree(self, context_branch):
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
247
        """Implementation of as_tree().
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
248
249
        Classes should override this function to provide appropriate
250
        functionality. The default is to just call '.as_revision_id()'
251
        and get the revision tree from context_branch's repository.
252
        """
253
        revision_id = self.as_revision_id(context_branch)
254
        return context_branch.repository.revision_tree(revision_id)
255
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
256
    def __repr__(self):
257
        # this is mostly for helping with testing
1948.4.32 by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/
258
        return '<%s %s>' % (self.__class__.__name__,
7143.15.2 by Jelmer Vernooij
Run autopep8.
259
                            self.user_spec)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
260
1881.1.4 by Matthieu Moy
needs_tree -> needs_branch
261
    def needs_branch(self):
262
        """Whether this revision spec needs a branch.
263
1711.2.99 by John Arbash Meinel
minor typo fix
264
        Set this to False the branch argument of _match_on is not used.
265
        """
1881.1.1 by Matthieu Moy
Fixed and tested "bzr diff" outside a working tree.
266
        return True
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
267
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
268
    def get_branch(self):
269
        """When the revision specifier contains a branch location, return it.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
270
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
271
        Otherwise, return None.
272
        """
273
        return None
274
1907.4.9 by Matthieu Moy
missing newline
275
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
276
# private API
277
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
278
class RevisionSpec_dwim(RevisionSpec):
279
    """Provides a DWIMish revision specifier lookup.
280
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
281
    Note that this does not go in the revspec_registry because by definition
282
    there is no prefix to identify it.  It's solely called from
283
    RevisionSpec.from_string() because the DWIMification happen when _match_on
284
    is called so the string describing the revision is kept here until needed.
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
285
    """
286
287
    help_txt = None
288
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
289
    _revno_regex = lazy_regex.lazy_compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
290
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
291
    # The revspecs to try
292
    _possible_revspecs = []
293
4569.2.19 by Vincent Ladeuil
A bit more tweaks.
294
    def _try_spectype(self, rstype, branch):
295
        rs = rstype(self.spec, _internal=True)
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
296
        # Hit in_history to find out if it exists, or we need to try the
297
        # next type.
298
        return rs.in_history(branch)
299
300
    def _match_on(self, branch, revs):
301
        """Run the lookup and see what we can get."""
302
303
        # First, see if it's a revno
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
304
        if self._revno_regex.match(self.spec) is not None:
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
305
            try:
4569.2.19 by Vincent Ladeuil
A bit more tweaks.
306
                return self._try_spectype(RevisionSpec_revno, branch)
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
307
            except RevisionSpec_revno.dwim_catchable_exceptions:
308
                pass
309
310
        # Next see what has been registered
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
311
        for objgetter in self._possible_revspecs:
312
            rs_class = objgetter.get_obj()
313
            try:
314
                return self._try_spectype(rs_class, branch)
315
            except rs_class.dwim_catchable_exceptions:
316
                pass
317
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
318
        # Well, I dunno what it is. Note that we don't try to keep track of the
319
        # first of last exception raised during the DWIM tries as none seems
320
        # really relevant.
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
321
        raise errors.InvalidRevisionSpec(self.spec, branch)
322
5671.5.3 by Jelmer Vernooij
Fix test.. not sure how I missed this.
323
    @classmethod
324
    def append_possible_revspec(cls, revspec):
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
325
        """Append a possible DWIM revspec.
326
327
        :param revspec: Revision spec to try.
328
        """
5671.5.3 by Jelmer Vernooij
Fix test.. not sure how I missed this.
329
        cls._possible_revspecs.append(registry._ObjectGetter(revspec))
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
330
5671.5.3 by Jelmer Vernooij
Fix test.. not sure how I missed this.
331
    @classmethod
332
    def append_possible_lazy_revspec(cls, module_name, member_name):
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
333
        """Append a possible lazily loaded DWIM revspec.
334
335
        :param module_name: Name of the module with the revspec
336
        :param member_name: Name of the revspec within the module
337
        """
5671.5.3 by Jelmer Vernooij
Fix test.. not sure how I missed this.
338
        cls._possible_revspecs.append(
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
339
            registry._LazyObjectGetter(module_name, member_name))
340
4569.2.1 by Matthew Fuller
Implement a DWIM revspec type and use it to allow simpler user
341
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
342
class RevisionSpec_revno(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
343
    """Selects a revision using a number."""
344
345
    help_txt = """Selects a revision using a number.
2023.1.1 by ghigo
add topics help
346
347
    Use an integer to specify a revision in the history of the branch.
4569.2.5 by Matthew Fuller
Update online documentation to match new DWIM behavior.
348
    Optionally a branch can be specified.  A negative number will count
349
    from the end of the branch (-1 is the last revision, -2 the previous
350
    one). If the negative number is larger than the branch's history, the
351
    first revision is returned.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
352
    Examples::
353
3651.2.1 by Daniel Clemente
Clarify that you don't have to write a path if you mean the current branch
354
      revno:1                   -> return the first revision of this branch
2023.1.1 by ghigo
add topics help
355
      revno:3:/path/to/branch   -> return the 3rd revision of
356
                                   the branch '/path/to/branch'
357
      revno:-1                  -> The last revision in a branch.
358
      -2:http://other/branch    -> The second to last revision in the
359
                                   remote branch.
360
      -1000000                  -> Most likely the first revision, unless
361
                                   your history is very long.
362
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
363
    prefix = 'revno:'
364
365
    def _match_on(self, branch, revs):
366
        """Lookup a revision by revision number"""
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
367
        branch, revno, revision_id = self._lookup(branch)
3298.2.6 by John Arbash Meinel
Don't abstract through RevisionInfo for RevisionSpec_revno.as_revision_id()
368
        return RevisionInfo(branch, revno, revision_id)
369
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
370
    def _lookup(self, branch):
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
371
        loc = self.spec.find(':')
372
        if loc == -1:
373
            revno_spec = self.spec
374
            branch_spec = None
375
        else:
376
            revno_spec = self.spec[:loc]
7143.15.2 by Jelmer Vernooij
Run autopep8.
377
            branch_spec = self.spec[loc + 1:]
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
378
379
        if revno_spec == '':
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
380
            if not branch_spec:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
381
                raise errors.InvalidRevisionSpec(self.user_spec,
7143.15.2 by Jelmer Vernooij
Run autopep8.
382
                                                 branch, 'cannot have an empty revno and no branch')
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
383
            revno = None
384
        else:
385
            try:
386
                revno = int(revno_spec)
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
387
                dotted = False
388
            except ValueError:
389
                # dotted decimal. This arguably should not be here
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
390
                # but the from_string method is a little primitive
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
391
                # right now - RBC 20060928
392
                try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
393
                    match_revno = tuple((int(number)
394
                                         for number in revno_spec.split('.')))
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
395
                except ValueError as e:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
396
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
397
398
                dotted = True
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
399
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
400
        if branch_spec:
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
401
            # the user has overriden the branch to look in.
402
            branch = _mod_branch.Branch.open(branch_spec)
1948.4.22 by John Arbash Meinel
Refactor common code from integer revno handlers
403
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
404
        if dotted:
405
            try:
3949.2.6 by Ian Clatworthy
review feedback from jam
406
                revision_id = branch.dotted_revno_to_revision_id(match_revno,
7143.15.2 by Jelmer Vernooij
Run autopep8.
407
                                                                 _cache_reverse=True)
7290.19.7 by Jelmer Vernooij
Catch RevnoOutOfBounds.
408
            except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
3872.2.2 by Marius Kruger
* use NULL_REVISION in stead of None for rev_id
409
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
410
            else:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
411
                # there is no traditional 'revno' for dotted-decimal revnos.
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
412
                # so for API compatibility we return None.
3949.2.6 by Ian Clatworthy
review feedback from jam
413
                return branch, None, revision_id
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
414
        else:
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
415
            last_revno, last_revision_id = branch.last_revision_info()
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
416
            if revno < 0:
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
417
                # if get_rev_id supported negative revnos, there would not be a
418
                # need for this special case.
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
419
                if (-revno) >= last_revno:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
420
                    revno = 1
421
                else:
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
422
                    revno = last_revno + revno + 1
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
423
            try:
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
424
                revision_id = branch.get_rev_id(revno)
7290.19.3 by Jelmer Vernooij
More tests.
425
            except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
426
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
3298.2.6 by John Arbash Meinel
Don't abstract through RevisionInfo for RevisionSpec_revno.as_revision_id()
427
        return branch, revno, revision_id
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
428
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
429
    def _as_revision_id(self, context_branch):
430
        # We would have the revno here, but we don't really care
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
431
        branch, revno, revision_id = self._lookup(context_branch)
3298.2.6 by John Arbash Meinel
Don't abstract through RevisionInfo for RevisionSpec_revno.as_revision_id()
432
        return revision_id
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
433
1881.1.4 by Matthieu Moy
needs_tree -> needs_branch
434
    def needs_branch(self):
1881.1.1 by Matthieu Moy
Fixed and tested "bzr diff" outside a working tree.
435
        return self.spec.find(':') == -1
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
436
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
437
    def get_branch(self):
438
        if self.spec.find(':') == -1:
439
            return None
440
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
441
            return self.spec[self.spec.find(':') + 1:]
442
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
443
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
444
# Old compatibility
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
445
RevisionSpec_int = RevisionSpec_revno
446
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
447
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
448
class RevisionIDSpec(RevisionSpec):
449
450
    def _match_on(self, branch, revs):
451
        revision_id = self.as_revision_id(branch)
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
452
        return RevisionInfo.from_revision_id(branch, revision_id)
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
453
454
455
class RevisionSpec_revid(RevisionIDSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
456
    """Selects a revision using the revision id."""
457
458
    help_txt = """Selects a revision using the revision id.
2023.1.1 by ghigo
add topics help
459
460
    Supply a specific revision id, that can be used to specify any
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
461
    revision id in the ancestry of the branch.
2023.1.1 by ghigo
add topics help
462
    Including merges, and pending merges.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
463
    Examples::
464
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
465
      revid:aaaa@bbbb-123456789 -> Select revision 'aaaa@bbbb-123456789'
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
466
    """
467
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
468
    prefix = 'revid:'
469
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
470
    def _as_revision_id(self, context_branch):
2325.2.5 by Marien Zwart
Call osutils.safe_revision_id instead of duplicating it.
471
        # self.spec comes straight from parsing the command line arguments,
472
        # so we expect it to be a Unicode string. Switch it to the internal
473
        # representation.
6973.6.2 by Jelmer Vernooij
Fix more tests.
474
        if isinstance(self.spec, text_type):
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
475
            return cache_utf8.encode(self.spec)
476
        return self.spec
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
477
478
479
class RevisionSpec_last(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
480
    """Selects the nth revision from the end."""
481
482
    help_txt = """Selects the nth revision from the end.
2023.1.1 by ghigo
add topics help
483
484
    Supply a positive number to get the nth revision from the end.
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
485
    This is the same as supplying negative numbers to the 'revno:' spec.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
486
    Examples::
487
2023.1.1 by ghigo
add topics help
488
      last:1        -> return the last revision
489
      last:3        -> return the revision 2 before the end.
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
490
    """
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
491
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
492
    prefix = 'last:'
493
494
    def _match_on(self, branch, revs):
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
495
        revno, revision_id = self._revno_and_revision_id(branch)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
496
        return RevisionInfo(branch, revno, revision_id)
497
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
498
    def _revno_and_revision_id(self, context_branch):
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
499
        last_revno, last_revision_id = context_branch.last_revision_info()
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
500
1948.4.9 by John Arbash Meinel
Cleanup and test last:
501
        if self.spec == '':
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
502
            if not last_revno:
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
503
                raise errors.NoCommits(context_branch)
504
            return last_revno, last_revision_id
1948.4.9 by John Arbash Meinel
Cleanup and test last:
505
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
506
        try:
507
            offset = int(self.spec)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
508
        except ValueError as e:
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
509
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch, e)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
510
511
        if offset <= 0:
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
512
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
1948.4.9 by John Arbash Meinel
Cleanup and test last:
513
                                             'you must supply a positive value')
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
514
515
        revno = last_revno - offset + 1
1948.4.9 by John Arbash Meinel
Cleanup and test last:
516
        try:
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
517
            revision_id = context_branch.get_rev_id(revno)
7290.19.7 by Jelmer Vernooij
Catch RevnoOutOfBounds.
518
        except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
519
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
520
        return revno, revision_id
521
522
    def _as_revision_id(self, context_branch):
523
        # We compute the revno as part of the process, but we don't really care
524
        # about it.
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
525
        revno, revision_id = self._revno_and_revision_id(context_branch)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
526
        return revision_id
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
527
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
528
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
529
class RevisionSpec_before(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
530
    """Selects the parent of the revision specified."""
531
532
    help_txt = """Selects the parent of the revision specified.
2023.1.1 by ghigo
add topics help
533
3651.2.4 by Daniel Clemente
Reordered to put explanation first and exceptions after
534
    Supply any revision spec to return the parent of that revision.  This is
535
    mostly useful when inspecting revisions that are not in the revision history
536
    of a branch.
537
2023.1.1 by ghigo
add topics help
538
    It is an error to request the parent of the null revision (before:0).
539
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
540
    Examples::
541
2023.1.1 by ghigo
add topics help
542
      before:1913    -> Return the parent of revno 1913 (revno 1912)
543
      before:revid:aaaa@bbbb-1234567890  -> return the parent of revision
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
544
                                            aaaa@bbbb-1234567890
3651.2.5 by Daniel Clemente
Wrote specifical and simpler example for 'before:', and referred to 'bzr diff -c'
545
      bzr diff -r before:1913..1913
546
            -> Find the changes between revision 1913 and its parent (1912).
547
               (What changes did revision 1913 introduce).
548
               This is equivalent to:  bzr diff -c 1913
2023.1.1 by ghigo
add topics help
549
    """
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
550
551
    prefix = 'before:'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
552
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
553
    def _match_on(self, branch, revs):
554
        r = RevisionSpec.from_string(self.spec)._match_on(branch, revs)
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
555
        if r.revno == 0:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
556
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
557
                                             'cannot go before the null: revision')
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
558
        if r.revno is None:
559
            # We need to use the repository history here
560
            rev = branch.repository.get_revision(r.rev_id)
561
            if not rev.parent_ids:
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
562
                revision_id = revision.NULL_REVISION
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
563
            else:
564
                revision_id = rev.parent_ids[0]
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
565
            revno = None
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
566
        else:
567
            revno = r.revno - 1
568
            try:
569
                revision_id = branch.get_rev_id(revno, revs)
7290.19.7 by Jelmer Vernooij
Catch RevnoOutOfBounds.
570
            except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
571
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
572
                                                 branch)
573
        return RevisionInfo(branch, revno, revision_id)
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
574
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
575
    def _as_revision_id(self, context_branch):
7143.15.2 by Jelmer Vernooij
Run autopep8.
576
        base_revision_id = RevisionSpec.from_string(
577
            self.spec)._as_revision_id(context_branch)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
578
        if base_revision_id == revision.NULL_REVISION:
3495.1.1 by John Arbash Meinel
Fix bug #239933, use the right exception for -c0
579
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
580
                                             'cannot go before the null: revision')
3298.2.10 by Aaron Bentley
Refactor partial history code
581
        context_repo = context_branch.repository
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
582
        with context_repo.lock_read():
3298.2.10 by Aaron Bentley
Refactor partial history code
583
            parent_map = context_repo.get_parent_map([base_revision_id])
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
584
        if base_revision_id not in parent_map:
585
            # Ghost, or unknown revision id
586
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
587
                                             'cannot find the matching revision')
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
588
        parents = parent_map[base_revision_id]
589
        if len(parents) < 1:
590
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
591
                                             'No parents for revision.')
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
592
        return parents[0]
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
593
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
594
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
595
class RevisionSpec_tag(RevisionSpec):
2220.2.3 by Martin Pool
Add tag: revision namespace.
596
    """Select a revision identified by tag name"""
597
598
    help_txt = """Selects a revision identified by a tag name.
599
1551.10.34 by Aaron Bentley
Fix tag: help
600
    Tags are stored in the branch and created by the 'tag' command.
2220.2.3 by Martin Pool
Add tag: revision namespace.
601
    """
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
602
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
603
    prefix = 'tag:'
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
604
    dwim_catchable_exceptions = (errors.NoSuchTag, errors.TagsNotSupported)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
605
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
606
    def _match_on(self, branch, revs):
2220.2.3 by Martin Pool
Add tag: revision namespace.
607
        # Can raise tags not supported, NoSuchTag, etc
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
608
        return RevisionInfo.from_revision_id(branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
609
                                             branch.tags.lookup_tag(self.spec))
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
610
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
611
    def _as_revision_id(self, context_branch):
612
        return context_branch.tags.lookup_tag(self.spec)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
613
614
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
615
class _RevListToTimestamps(object):
616
    """This takes a list of revisions, and allows you to bisect by date"""
617
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
618
    __slots__ = ['branch']
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
619
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
620
    def __init__(self, branch):
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
621
        self.branch = branch
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
622
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
623
    def __getitem__(self, index):
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
624
        """Get the date of the index'd item"""
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
625
        r = self.branch.repository.get_revision(self.branch.get_rev_id(index))
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
626
        # TODO: Handle timezone.
627
        return datetime.datetime.fromtimestamp(r.timestamp)
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
628
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
629
    def __len__(self):
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
630
        return self.branch.revno()
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
631
632
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
633
class RevisionSpec_date(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
634
    """Selects a revision on the basis of a datestamp."""
635
636
    help_txt = """Selects a revision on the basis of a datestamp.
2023.1.1 by ghigo
add topics help
637
638
    Supply a datestamp to select the first revision that matches the date.
639
    Date can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
640
    Matches the first entry after a given date (either at midnight or
641
    at a specified time).
642
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
643
    One way to display all the changes since yesterday would be::
2666.1.5 by Ian Clatworthy
Incorporate feedback from Alex B. & James W.
644
6622.1.30 by Jelmer Vernooij
Some more test fixes.
645
        brz log -r date:yesterday..
2023.1.1 by ghigo
add topics help
646
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
647
    Examples::
648
2023.1.1 by ghigo
add topics help
649
      date:yesterday            -> select the first revision since yesterday
650
      date:2006-08-14,17:10:14  -> select the first revision after
651
                                   August 14th, 2006 at 5:10pm.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
652
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
653
    prefix = 'date:'
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
654
    _date_regex = lazy_regex.lazy_compile(
7143.15.2 by Jelmer Vernooij
Run autopep8.
655
        r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
656
        r'(,|T)?\s*'
657
        r'(?P<time>(?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d))?)?'
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
658
        )
659
660
    def _match_on(self, branch, revs):
2023.1.1 by ghigo
add topics help
661
        """Spec for date revisions:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
662
          date:value
663
          value can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
664
          matches the first entry after a given date (either at midnight or
665
          at a specified time).
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
666
        """
2070.4.3 by John Arbash Meinel
code and doc cleanup
667
        #  XXX: This doesn't actually work
668
        #  So the proper way of saying 'give me all entries for today' is:
669
        #      -r date:yesterday..date:today
7143.15.2 by Jelmer Vernooij
Run autopep8.
670
        today = datetime.datetime.fromordinal(
671
            datetime.date.today().toordinal())
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
672
        if self.spec.lower() == 'yesterday':
673
            dt = today - datetime.timedelta(days=1)
674
        elif self.spec.lower() == 'today':
675
            dt = today
676
        elif self.spec.lower() == 'tomorrow':
677
            dt = today + datetime.timedelta(days=1)
678
        else:
5685.1.1 by Jelmer Vernooij
More lazy imports, lazy regexes in bzrlib.revisionspec.
679
            m = self._date_regex.match(self.spec)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
680
            if not m or (not m.group('date') and not m.group('time')):
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
681
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
682
                                                 branch, 'invalid date')
683
684
            try:
685
                if m.group('date'):
686
                    year = int(m.group('year'))
687
                    month = int(m.group('month'))
688
                    day = int(m.group('day'))
689
                else:
690
                    year = today.year
691
                    month = today.month
692
                    day = today.day
693
694
                if m.group('time'):
695
                    hour = int(m.group('hour'))
696
                    minute = int(m.group('minute'))
697
                    if m.group('second'):
698
                        second = int(m.group('second'))
699
                    else:
700
                        second = 0
701
                else:
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
702
                    hour, minute, second = 0, 0, 0
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
703
            except ValueError:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
704
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
705
                                                 branch, 'invalid date')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
706
707
            dt = datetime.datetime(year=year, month=month, day=day,
7143.15.2 by Jelmer Vernooij
Run autopep8.
708
                                   hour=hour, minute=minute, second=second)
6754.8.4 by Jelmer Vernooij
Use new context stuff.
709
        with branch.lock_read():
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
710
            rev = bisect.bisect(_RevListToTimestamps(branch), dt, 1)
711
        if rev == branch.revno():
3298.2.11 by Aaron Bentley
Update tests for null:, clea up slightly
712
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
713
        return RevisionInfo(branch, rev)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
714
715
716
class RevisionSpec_ancestor(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
717
    """Selects a common ancestor with a second branch."""
718
719
    help_txt = """Selects a common ancestor with a second branch.
2023.1.1 by ghigo
add topics help
720
721
    Supply the path to a branch to select the common ancestor.
722
723
    The common ancestor is the last revision that existed in both
724
    branches. Usually this is the branch point, but it could also be
725
    a revision that was merged.
726
727
    This is frequently used with 'diff' to return all of the changes
728
    that your branch introduces, while excluding the changes that you
729
    have not merged from the remote branch.
730
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
731
    Examples::
732
2023.1.1 by ghigo
add topics help
733
      ancestor:/path/to/branch
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
734
      $ bzr diff -r ancestor:../../mainline/branch
2023.1.1 by ghigo
add topics help
735
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
736
    prefix = 'ancestor:'
737
738
    def _match_on(self, branch, revs):
1551.10.33 by Aaron Bentley
Updates from review
739
        trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
740
        return self._find_revision_info(branch, self.spec)
741
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
742
    def _as_revision_id(self, context_branch):
743
        return self._find_revision_id(context_branch, self.spec)
744
1551.10.33 by Aaron Bentley
Updates from review
745
    @staticmethod
746
    def _find_revision_info(branch, other_location):
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
747
        revision_id = RevisionSpec_ancestor._find_revision_id(branch,
748
                                                              other_location)
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
749
        return RevisionInfo(branch, None, revision_id)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
750
751
    @staticmethod
752
    def _find_revision_id(branch, other_location):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
753
        from .branch import Branch
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
754
6754.8.4 by Jelmer Vernooij
Use new context stuff.
755
        with branch.lock_read():
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
756
            revision_a = revision.ensure_null(branch.last_revision())
757
            if revision_a == revision.NULL_REVISION:
758
                raise errors.NoCommits(branch)
3984.1.2 by Daniel Watkins
Added fix.
759
            if other_location == '':
760
                other_location = branch.get_parent()
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
761
            other_branch = Branch.open(other_location)
6754.8.4 by Jelmer Vernooij
Use new context stuff.
762
            with other_branch.lock_read():
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
763
                revision_b = revision.ensure_null(other_branch.last_revision())
764
                if revision_b == revision.NULL_REVISION:
765
                    raise errors.NoCommits(other_branch)
766
                graph = branch.repository.get_graph(other_branch.repository)
3010.1.12 by Robert Collins
Lock branches while doing revision specification lookups.
767
                rev_id = graph.find_unique_lca(revision_a, revision_b)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
768
            if rev_id == revision.NULL_REVISION:
769
                raise errors.NoCommonAncestor(revision_a, revision_b)
770
            return rev_id
1432 by Robert Collins
branch: namespace
771
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
772
1432 by Robert Collins
branch: namespace
773
class RevisionSpec_branch(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
774
    """Selects the last revision of a specified branch."""
775
776
    help_txt = """Selects the last revision of a specified branch.
2023.1.1 by ghigo
add topics help
777
778
    Supply the path to a branch to select its last revision.
779
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
780
    Examples::
781
2023.1.1 by ghigo
add topics help
782
      branch:/path/to/branch
1432 by Robert Collins
branch: namespace
783
    """
784
    prefix = 'branch:'
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
785
    dwim_catchable_exceptions = (errors.NotBranchError,)
1432 by Robert Collins
branch: namespace
786
787
    def _match_on(self, branch, revs):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
788
        from .branch import Branch
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
789
        other_branch = Branch.open(self.spec)
1432 by Robert Collins
branch: namespace
790
        revision_b = other_branch.last_revision()
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
791
        if revision_b in (None, revision.NULL_REVISION):
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
792
            raise errors.NoCommits(other_branch)
5318.1.1 by Martin von Gagern
Extract branch location from branch: revision specs.
793
        if branch is None:
794
            branch = other_branch
795
        else:
796
            try:
797
                # pull in the remote revisions so we can diff
798
                branch.fetch(other_branch, revision_b)
799
            except errors.ReadOnlyError:
800
                branch = other_branch
6336.1.1 by Jelmer Vernooij
Deprecate ``RevisionSpec.wants_revision_history`` and remove any uses of it.
801
        return RevisionInfo(branch, None, revision_b)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
802
803
    def _as_revision_id(self, context_branch):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
804
        from .branch import Branch
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
805
        other_branch = Branch.open(self.spec)
806
        last_revision = other_branch.last_revision()
807
        last_revision = revision.ensure_null(last_revision)
1551.19.33 by Aaron Bentley
Use as_revision_id for diff
808
        context_branch.fetch(other_branch, last_revision)
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
809
        if last_revision == revision.NULL_REVISION:
810
            raise errors.NoCommits(other_branch)
811
        return last_revision
812
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
813
    def _as_tree(self, context_branch):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
814
        from .branch import Branch
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
815
        other_branch = Branch.open(self.spec)
816
        last_revision = other_branch.last_revision()
817
        last_revision = revision.ensure_null(last_revision)
818
        if last_revision == revision.NULL_REVISION:
819
            raise errors.NoCommits(other_branch)
820
        return other_branch.repository.revision_tree(last_revision)
821
5318.1.1 by Martin von Gagern
Extract branch location from branch: revision specs.
822
    def needs_branch(self):
823
        return False
824
825
    def get_branch(self):
826
        return self.spec
827
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
828
1551.10.33 by Aaron Bentley
Updates from review
829
class RevisionSpec_submit(RevisionSpec_ancestor):
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
830
    """Selects a common ancestor with a submit branch."""
831
832
    help_txt = """Selects a common ancestor with the submit branch.
833
834
    Diffing against this shows all the changes that were made in this branch,
835
    and is a good predictor of what merge will do.  The submit branch is
3565.2.1 by Christophe Troestler
(trivial) Corrected typos.
836
    used by the bundle and merge directive commands.  If no submit branch
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
837
    is specified, the parent branch is used instead.
838
839
    The common ancestor is the last revision that existed in both
840
    branches. Usually this is the branch point, but it could also be
841
    a revision that was merged.
842
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
843
    Examples::
844
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
845
      $ bzr diff -r submit:
846
    """
1551.10.33 by Aaron Bentley
Updates from review
847
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
848
    prefix = 'submit:'
849
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
850
    def _get_submit_location(self, branch):
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
851
        submit_location = branch.get_submit_branch()
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
852
        location_type = 'submit branch'
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
853
        if submit_location is None:
854
            submit_location = branch.get_parent()
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
855
            location_type = 'parent branch'
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
856
        if submit_location is None:
857
            raise errors.NoSubmitBranch(branch)
6147.1.1 by Jonathan Riddell
use .format() instead of % for string formatting where there are multiple formats in one string to allow for translations
858
        trace.note(gettext('Using {0} {1}').format(location_type,
7143.15.2 by Jelmer Vernooij
Run autopep8.
859
                                                   submit_location))
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
860
        return submit_location
861
862
    def _match_on(self, branch, revs):
863
        trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
864
        return self._find_revision_info(branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
865
                                        self._get_submit_location(branch))
3298.2.5 by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups.
866
867
    def _as_revision_id(self, context_branch):
868
        return self._find_revision_id(context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
869
                                      self._get_submit_location(context_branch))
1551.10.33 by Aaron Bentley
Updates from review
870
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
871
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
872
class RevisionSpec_annotate(RevisionIDSpec):
873
874
    prefix = 'annotate:'
875
876
    help_txt = """Select the revision that last modified the specified line.
877
878
    Select the revision that last modified the specified line.  Line is
879
    specified as path:number.  Path is a relative path to the file.  Numbers
880
    start at 1, and are relative to the current version, not the last-
881
    committed version of the file.
882
    """
883
884
    def _raise_invalid(self, numstring, context_branch):
885
        raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
886
                                         'No such line: %s' % numstring)
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
887
888
    def _as_revision_id(self, context_branch):
889
        path, numstring = self.spec.rsplit(':', 1)
890
        try:
891
            index = int(numstring) - 1
892
        except ValueError:
893
            self._raise_invalid(numstring, context_branch)
894
        tree, file_path = workingtree.WorkingTree.open_containing(path)
6754.8.4 by Jelmer Vernooij
Use new context stuff.
895
        with tree.lock_read():
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
896
            if not tree.has_filename(file_path):
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
897
                raise errors.InvalidRevisionSpec(self.user_spec,
7143.15.2 by Jelmer Vernooij
Run autopep8.
898
                                                 context_branch, "File '%s' is not versioned." %
899
                                                 file_path)
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
900
            revision_ids = [r for (r, l) in tree.annotate_iter(file_path)]
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
901
        try:
902
            revision_id = revision_ids[index]
903
        except IndexError:
904
            self._raise_invalid(numstring, context_branch)
905
        if revision_id == revision.CURRENT_REVISION:
906
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
907
                                             'Line %s has not been committed.' % numstring)
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
908
        return revision_id
909
910
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
911
class RevisionSpec_mainline(RevisionIDSpec):
912
913
    help_txt = """Select mainline revision that merged the specified revision.
914
915
    Select the revision that merged the specified revision into mainline.
916
    """
917
918
    prefix = 'mainline:'
919
920
    def _as_revision_id(self, context_branch):
921
        revspec = RevisionSpec.from_string(self.spec)
922
        if revspec.get_branch() is None:
923
            spec_branch = context_branch
924
        else:
925
            spec_branch = _mod_branch.Branch.open(revspec.get_branch())
926
        revision_id = revspec.as_revision_id(spec_branch)
927
        graph = context_branch.repository.get_graph()
928
        result = graph.find_lefthand_merger(revision_id,
929
                                            context_branch.last_revision())
930
        if result is None:
931
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
932
        return result
933
934
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
935
# The order in which we want to DWIM a revision spec without any prefix.
936
# revno is always tried first and isn't listed here, this is used by
937
# RevisionSpec_dwim._match_on
5671.5.1 by Jelmer Vernooij
Allow lazily registering possible DWIM revspecs.
938
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_tag)
939
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_revid)
940
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date)
941
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch)
4569.2.18 by Vincent Ladeuil
Small refactoring to unblock the submission.
942
3966.2.1 by Jelmer Vernooij
Register revision specifiers in a registry.
943
revspec_registry = registry.Registry()
7143.15.2 by Jelmer Vernooij
Run autopep8.
944
945
3966.2.1 by Jelmer Vernooij
Register revision specifiers in a registry.
946
def _register_revspec(revspec):
947
    revspec_registry.register(revspec.prefix, revspec)
948
7143.15.2 by Jelmer Vernooij
Run autopep8.
949
3966.2.1 by Jelmer Vernooij
Register revision specifiers in a registry.
950
_register_revspec(RevisionSpec_revno)
951
_register_revspec(RevisionSpec_revid)
952
_register_revspec(RevisionSpec_last)
953
_register_revspec(RevisionSpec_before)
954
_register_revspec(RevisionSpec_tag)
955
_register_revspec(RevisionSpec_date)
956
_register_revspec(RevisionSpec_ancestor)
957
_register_revspec(RevisionSpec_branch)
958
_register_revspec(RevisionSpec_submit)
5365.6.6 by Aaron Bentley
Implement 'annotate' revision-id.
959
_register_revspec(RevisionSpec_annotate)
5365.6.4 by Aaron Bentley
Implement mainline revision spec.
960
_register_revspec(RevisionSpec_mainline)