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