Merge lp:~jelmer/brz/revspec-errors into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7501
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/revspec-errors
Merge into: lp:brz
Diff against target: 388 lines (+69/-64)
4 files modified
breezy/errors.py (+0/-14)
breezy/git/revspec.py (+1/-1)
breezy/revisionspec.py (+55/-36)
breezy/tests/test_revisionspec.py (+13/-13)
To merge this branch: bzr merge lp:~jelmer/brz/revspec-errors
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+381196@code.launchpad.net

Commit message

Move InvalidRevisionSpec to breezy.revisionspec.

Description of the change

Move InvalidRevisionSpec to breezy.revisionspec.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/errors.py'
2--- breezy/errors.py 2020-02-18 01:57:45 +0000
3+++ breezy/errors.py 2020-03-25 21:52:17 +0000
4@@ -956,20 +956,6 @@
5 self.revision_id = revision_id
6
7
8-class InvalidRevisionSpec(BzrError):
9-
10- _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
11- " %(branch_url)s%(extra)s")
12-
13- def __init__(self, spec, branch, extra=None):
14- BzrError.__init__(self, branch=branch, spec=spec)
15- self.branch_url = getattr(branch, 'user_url', str(branch))
16- if extra:
17- self.extra = '\n' + str(extra)
18- else:
19- self.extra = ''
20-
21-
22 class AppendRevisionsOnlyViolation(BzrError):
23
24 _fmt = ('Operation denied because it would change the main history,'
25
26=== modified file 'breezy/git/revspec.py'
27--- breezy/git/revspec.py 2020-02-18 01:57:45 +0000
28+++ breezy/git/revspec.py 2020-03-25 21:52:17 +0000
29@@ -21,12 +21,12 @@
30
31 from ..errors import (
32 InvalidRevisionId,
33- InvalidRevisionSpec,
34 )
35 from ..revision import (
36 NULL_REVISION,
37 )
38 from ..revisionspec import (
39+ InvalidRevisionSpec,
40 RevisionInfo,
41 RevisionSpec,
42 )
43
44=== modified file 'breezy/revisionspec.py'
45--- breezy/revisionspec.py 2020-02-18 01:57:45 +0000
46+++ breezy/revisionspec.py 2020-03-25 21:52:17 +0000
47@@ -37,6 +37,20 @@
48 )
49
50
51+class InvalidRevisionSpec(errors.BzrError):
52+
53+ _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
54+ " %(branch_url)s%(extra)s")
55+
56+ def __init__(self, spec, branch, extra=None):
57+ errors.BzrError.__init__(self, branch=branch, spec=spec)
58+ self.branch_url = getattr(branch, 'user_url', str(branch))
59+ if extra:
60+ self.extra = '\n' + str(extra)
61+ else:
62+ self.extra = ''
63+
64+
65 class RevisionInfo(object):
66 """The results of applying a revision specification to a branch."""
67
68@@ -136,7 +150,7 @@
69 """
70
71 prefix = None
72- dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
73+ dwim_catchable_exceptions = (InvalidRevisionSpec,)
74 """Exceptions that RevisionSpec_dwim._match_on will catch.
75
76 If the revspec is part of ``dwim_revspecs``, it may be tried with an
77@@ -196,9 +210,9 @@
78 # special case - nothing supplied
79 return info
80 elif self.prefix:
81- raise errors.InvalidRevisionSpec(self.user_spec, branch)
82+ raise InvalidRevisionSpec(self.user_spec, branch)
83 else:
84- raise errors.InvalidRevisionSpec(self.spec, branch)
85+ raise InvalidRevisionSpec(self.spec, branch)
86
87 def in_history(self, branch):
88 return self._match_on_and_check(branch, revs=None)
89@@ -313,7 +327,7 @@
90 # Well, I dunno what it is. Note that we don't try to keep track of the
91 # first of last exception raised during the DWIM tries as none seems
92 # really relevant.
93- raise errors.InvalidRevisionSpec(self.spec, branch)
94+ raise InvalidRevisionSpec(self.spec, branch)
95
96 @classmethod
97 def append_possible_revspec(cls, revspec):
98@@ -373,8 +387,9 @@
99
100 if revno_spec == '':
101 if not branch_spec:
102- raise errors.InvalidRevisionSpec(self.user_spec,
103- branch, 'cannot have an empty revno and no branch')
104+ raise InvalidRevisionSpec(
105+ self.user_spec, branch,
106+ 'cannot have an empty revno and no branch')
107 revno = None
108 else:
109 try:
110@@ -388,7 +403,7 @@
111 match_revno = tuple((int(number)
112 for number in revno_spec.split('.')))
113 except ValueError as e:
114- raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
115+ raise InvalidRevisionSpec(self.user_spec, branch, e)
116
117 dotted = True
118
119@@ -401,7 +416,7 @@
120 revision_id = branch.dotted_revno_to_revision_id(match_revno,
121 _cache_reverse=True)
122 except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
123- raise errors.InvalidRevisionSpec(self.user_spec, branch)
124+ raise InvalidRevisionSpec(self.user_spec, branch)
125 else:
126 # there is no traditional 'revno' for dotted-decimal revnos.
127 # so for API compatibility we return None.
128@@ -418,7 +433,7 @@
129 try:
130 revision_id = branch.get_rev_id(revno)
131 except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
132- raise errors.InvalidRevisionSpec(self.user_spec, branch)
133+ raise InvalidRevisionSpec(self.user_spec, branch)
134 return branch, revno, revision_id
135
136 def _as_revision_id(self, context_branch):
137@@ -501,17 +516,18 @@
138 try:
139 offset = int(self.spec)
140 except ValueError as e:
141- raise errors.InvalidRevisionSpec(self.user_spec, context_branch, e)
142+ raise InvalidRevisionSpec(self.user_spec, context_branch, e)
143
144 if offset <= 0:
145- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
146- 'you must supply a positive value')
147+ raise InvalidRevisionSpec(
148+ self.user_spec, context_branch,
149+ 'you must supply a positive value')
150
151 revno = last_revno - offset + 1
152 try:
153 revision_id = context_branch.get_rev_id(revno)
154 except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
155- raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
156+ raise InvalidRevisionSpec(self.user_spec, context_branch)
157 return revno, revision_id
158
159 def _as_revision_id(self, context_branch):
160@@ -548,8 +564,9 @@
161 def _match_on(self, branch, revs):
162 r = RevisionSpec.from_string(self.spec)._match_on(branch, revs)
163 if r.revno == 0:
164- raise errors.InvalidRevisionSpec(self.user_spec, branch,
165- 'cannot go before the null: revision')
166+ raise InvalidRevisionSpec(
167+ self.user_spec, branch,
168+ 'cannot go before the null: revision')
169 if r.revno is None:
170 # We need to use the repository history here
171 rev = branch.repository.get_revision(r.rev_id)
172@@ -563,27 +580,27 @@
173 try:
174 revision_id = branch.get_rev_id(revno, revs)
175 except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
176- raise errors.InvalidRevisionSpec(self.user_spec,
177- branch)
178+ raise InvalidRevisionSpec(self.user_spec, branch)
179 return RevisionInfo(branch, revno, revision_id)
180
181 def _as_revision_id(self, context_branch):
182 base_revision_id = RevisionSpec.from_string(
183 self.spec)._as_revision_id(context_branch)
184 if base_revision_id == revision.NULL_REVISION:
185- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
186- 'cannot go before the null: revision')
187+ raise InvalidRevisionSpec(
188+ self.user_spec, context_branch,
189+ 'cannot go before the null: revision')
190 context_repo = context_branch.repository
191 with context_repo.lock_read():
192 parent_map = context_repo.get_parent_map([base_revision_id])
193 if base_revision_id not in parent_map:
194 # Ghost, or unknown revision id
195- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
196- 'cannot find the matching revision')
197+ raise InvalidRevisionSpec(
198+ self.user_spec, context_branch, 'cannot find the matching revision')
199 parents = parent_map[base_revision_id]
200 if len(parents) < 1:
201- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
202- 'No parents for revision.')
203+ raise errors.InvalidRevisionSpec(
204+ self.user_spec, context_branch, 'No parents for revision.')
205 return parents[0]
206
207
208@@ -673,8 +690,8 @@
209 else:
210 m = self._date_regex.match(self.spec)
211 if not m or (not m.group('date') and not m.group('time')):
212- raise errors.InvalidRevisionSpec(self.user_spec,
213- branch, 'invalid date')
214+ raise InvalidRevisionSpec(
215+ self.user_spec, branch, 'invalid date')
216
217 try:
218 if m.group('date'):
219@@ -696,15 +713,15 @@
220 else:
221 hour, minute, second = 0, 0, 0
222 except ValueError:
223- raise errors.InvalidRevisionSpec(self.user_spec,
224- branch, 'invalid date')
225+ raise InvalidRevisionSpec(
226+ self.user_spec, branch, 'invalid date')
227
228 dt = datetime.datetime(year=year, month=month, day=day,
229 hour=hour, minute=minute, second=second)
230 with branch.lock_read():
231 rev = bisect.bisect(_RevListToTimestamps(branch), dt, 1)
232 if rev == branch.revno():
233- raise errors.InvalidRevisionSpec(self.user_spec, branch)
234+ raise InvalidRevisionSpec(self.user_spec, branch)
235 return RevisionInfo(branch, rev)
236
237
238@@ -877,8 +894,9 @@
239 """
240
241 def _raise_invalid(self, numstring, context_branch):
242- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
243- 'No such line: %s' % numstring)
244+ raise InvalidRevisionSpec(
245+ self.user_spec, context_branch,
246+ 'No such line: %s' % numstring)
247
248 def _as_revision_id(self, context_branch):
249 path, numstring = self.spec.rsplit(':', 1)
250@@ -889,17 +907,18 @@
251 tree, file_path = workingtree.WorkingTree.open_containing(path)
252 with tree.lock_read():
253 if not tree.has_filename(file_path):
254- raise errors.InvalidRevisionSpec(self.user_spec,
255- context_branch, "File '%s' is not versioned." %
256- file_path)
257+ raise InvalidRevisionSpec(
258+ self.user_spec, context_branch,
259+ "File '%s' is not versioned." % file_path)
260 revision_ids = [r for (r, l) in tree.annotate_iter(file_path)]
261 try:
262 revision_id = revision_ids[index]
263 except IndexError:
264 self._raise_invalid(numstring, context_branch)
265 if revision_id == revision.CURRENT_REVISION:
266- raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
267- 'Line %s has not been committed.' % numstring)
268+ raise InvalidRevisionSpec(
269+ self.user_spec, context_branch,
270+ 'Line %s has not been committed.' % numstring)
271 return revision_id
272
273
274@@ -923,7 +942,7 @@
275 result = graph.find_lefthand_merger(revision_id,
276 context_branch.last_revision())
277 if result is None:
278- raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
279+ raise InvalidRevisionSpec(self.user_spec, context_branch)
280 return result
281
282
283
284=== modified file 'breezy/tests/test_revisionspec.py'
285--- breezy/tests/test_revisionspec.py 2018-11-12 01:41:38 +0000
286+++ breezy/tests/test_revisionspec.py 2020-03-25 21:52:17 +0000
287@@ -23,6 +23,7 @@
288 )
289 from breezy.tests import TestCaseWithTransport
290 from breezy.revisionspec import (
291+ InvalidRevisionSpec,
292 RevisionInfo,
293 RevisionSpec,
294 RevisionSpec_dwim,
295@@ -75,7 +76,7 @@
296 invalid_as_revision_id=True):
297 try:
298 self.get_in_history(revision_spec)
299- except errors.InvalidRevisionSpec as e:
300+ except InvalidRevisionSpec as e:
301 self.assertEqual(revision_spec, e.spec)
302 self.assertEqual(extra, e.extra)
303 else:
304@@ -85,7 +86,7 @@
305 try:
306 spec = RevisionSpec.from_string(revision_spec)
307 spec.as_revision_id(self.tree.branch)
308- except errors.InvalidRevisionSpec as e:
309+ except InvalidRevisionSpec as e:
310 self.assertEqual(revision_spec, e.spec)
311 self.assertEqual(extra, e.extra)
312 else:
313@@ -141,7 +142,7 @@
314 if self.spec == "bork":
315 return RevisionInfo.from_revision_id(branch, b"r1")
316 else:
317- raise errors.InvalidRevisionSpec(self.spec, branch)
318+ raise InvalidRevisionSpec(self.spec, branch)
319
320
321 class TestRevisionSpec_dwim(TestRevisionSpec):
322@@ -159,8 +160,7 @@
323 self.tree.branch.tags.set_tag('footag', b'r1')
324 self.assertAsRevisionId(b'r1', 'footag')
325 self.tree.branch.tags.delete_tag('footag')
326- self.assertRaises(errors.InvalidRevisionSpec,
327- self.get_in_history, 'footag')
328+ self.assertRaises(InvalidRevisionSpec, self.get_in_history, 'footag')
329
330 def test_dwim_spec_tag_that_looks_like_revno(self):
331 # Test that we slip past revno with things that look like revnos,
332@@ -678,8 +678,8 @@
333 self.assertAsRevisionId(b'r2', 'mainline:1.1.1')
334 self.assertAsRevisionId(b'r2', 'mainline:revid:alt_r2')
335 spec = RevisionSpec.from_string('mainline:revid:alt_r22')
336- e = self.assertRaises(errors.InvalidRevisionSpec,
337- spec.as_revision_id, self.tree.branch)
338+ e = self.assertRaises(
339+ InvalidRevisionSpec, spec.as_revision_id, self.tree.branch)
340 self.assertContainsRe(str(e),
341 "Requested revision: 'mainline:revid:alt_r22' does not exist in"
342 " branch: ")
343@@ -708,15 +708,15 @@
344
345 def test_as_revision_id_uncommitted(self):
346 spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
347- e = self.assertRaises(errors.InvalidRevisionSpec,
348- spec.as_revision_id, self.tree.branch)
349+ e = self.assertRaises(
350+ InvalidRevisionSpec, spec.as_revision_id, self.tree.branch)
351 self.assertContainsRe(str(e),
352 r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
353 " exist in branch: .*\nLine 3 has not been committed.")
354
355 def test_non_existent_line(self):
356 spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
357- e = self.assertRaises(errors.InvalidRevisionSpec,
358+ e = self.assertRaises(InvalidRevisionSpec,
359 spec.as_revision_id, self.tree.branch)
360 self.assertContainsRe(str(e),
361 r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
362@@ -724,7 +724,7 @@
363
364 def test_invalid_line(self):
365 spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
366- e = self.assertRaises(errors.InvalidRevisionSpec,
367+ e = self.assertRaises(InvalidRevisionSpec,
368 spec.as_revision_id, self.tree.branch)
369 self.assertContainsRe(str(e),
370 r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
371@@ -732,7 +732,7 @@
372
373 def test_no_such_file(self):
374 spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
375- e = self.assertRaises(errors.InvalidRevisionSpec,
376+ e = self.assertRaises(InvalidRevisionSpec,
377 spec.as_revision_id, self.tree.branch)
378 self.assertContainsRe(str(e),
379 r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
380@@ -740,7 +740,7 @@
381
382 def test_no_such_file_with_colon(self):
383 spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
384- e = self.assertRaises(errors.InvalidRevisionSpec,
385+ e = self.assertRaises(InvalidRevisionSpec,
386 spec.as_revision_id, self.tree.branch)
387 self.assertContainsRe(str(e),
388 r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"

Subscribers

People subscribed via source and target branches