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