Merge lp:~jelmer/brz/ghost-revisions into lp:brz

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/brz/ghost-revisions
Merge into: lp:brz
Diff against target: 174 lines (+79/-1)
7 files modified
breezy/branch.py (+4/-1)
breezy/bzr/remote.py (+9/-0)
breezy/bzr/smart/branch.py (+4/-0)
breezy/git/remote.py (+5/-0)
breezy/tests/per_branch/test_dotted_revno_to_revision_id.py (+19/-0)
breezy/tests/test_remote.py (+25/-0)
breezy/tests/test_smart.py (+13/-0)
To merge this branch: bzr merge lp:~jelmer/brz/ghost-revisions
Reviewer Review Type Date Requested Status
Breezy developers Pending
Review via email: mp+364296@code.launchpad.net

This proposal has been superseded by a proposal from 2019-05-29.

Description of the change

Raise consistent GhostRevisionsHaveNoRevno from dotted_revno_to_revision_id.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/branch.py'
2--- breezy/branch.py 2019-02-15 04:22:43 +0000
3+++ breezy/branch.py 2019-03-13 23:26:23 +0000
4@@ -364,7 +364,10 @@
5 provide a more efficient implementation.
6 """
7 if len(revno) == 1:
8- return self.get_rev_id(revno[0])
9+ try:
10+ return self.get_rev_id(revno[0])
11+ except errors.RevisionNotPresent as e:
12+ raise errors.GhostRevisionsHaveNoRevno(revno[0], e.revision_id)
13 revision_id_to_revno = self.get_revision_id_to_revno_map()
14 revision_ids = [revision_id for revision_id, this_revno
15 in viewitems(revision_id_to_revno)
16
17=== modified file 'breezy/bzr/remote.py'
18--- breezy/bzr/remote.py 2019-02-15 14:00:31 +0000
19+++ breezy/bzr/remote.py 2019-03-13 23:26:23 +0000
20@@ -18,6 +18,7 @@
21
22 import bz2
23 import os
24+import re
25 import sys
26 import zlib
27
28@@ -4032,6 +4033,14 @@
29 except errors.UnknownSmartMethod:
30 self._ensure_real()
31 return self._real_branch.revision_id_to_dotted_revno(revision_id)
32+ except errors.UnknownErrorFromSmartServer as e:
33+ # Deal with older versions of bzr/brz that didn't explicitly
34+ # wrap GhostRevisionsHaveNoRevno.
35+ if e.error_tuple[1] == b'GhostRevisionsHaveNoRevno':
36+ (revid, ghost_revid) = re.findall(b"{([^}]+)}", e.error_tuple[2])
37+ raise errors.GhostRevisionsHaveNoRevno(
38+ revid, ghost_revid)
39+ raise
40 if response[0] == b'ok':
41 return tuple([int(x) for x in response[1:]])
42 else:
43
44=== modified file 'breezy/bzr/smart/branch.py'
45--- breezy/bzr/smart/branch.py 2018-11-11 04:08:32 +0000
46+++ breezy/bzr/smart/branch.py 2019-03-13 23:26:23 +0000
47@@ -236,6 +236,10 @@
48 dotted_revno = branch.revision_id_to_dotted_revno(revid)
49 except errors.NoSuchRevision:
50 return FailedSmartServerResponse((b'NoSuchRevision', revid))
51+ except errors.GhostRevisionsHaveNoRevno as e:
52+ return FailedSmartServerResponse(
53+ (b'GhostRevisionsHaveNoRevno', e.revision_id,
54+ e.ghost_revision_id))
55 return SuccessfulSmartServerResponse(
56 (b'ok', ) + tuple([b'%d' % x for x in dotted_revno]))
57
58
59=== modified file 'breezy/git/remote.py'
60--- breezy/git/remote.py 2019-02-15 14:45:15 +0000
61+++ breezy/git/remote.py 2019-03-13 23:26:23 +0000
62@@ -89,6 +89,7 @@
63 )
64 from .repository import (
65 GitRepository,
66+ GitRepositoryFormat,
67 )
68 from .refs import (
69 branch_name_to_ref,
70@@ -753,6 +754,10 @@
71 def get_branch_format(self):
72 return RemoteGitBranchFormat()
73
74+ @property
75+ def repository_format(self):
76+ return GitRepositoryFormat()
77+
78 def is_initializable(self):
79 return False
80
81
82=== modified file 'breezy/tests/per_branch/test_dotted_revno_to_revision_id.py'
83--- breezy/tests/per_branch/test_dotted_revno_to_revision_id.py 2018-11-11 04:08:32 +0000
84+++ breezy/tests/per_branch/test_dotted_revno_to_revision_id.py 2019-03-13 23:26:23 +0000
85@@ -17,6 +17,8 @@
86 """Tests for Branch.dotted_revno_to_revision_id()"""
87
88 from breezy import errors
89+from breezy.bzr.fullhistory import FullHistoryBzrBranch
90+from breezy.tests import TestNotApplicable
91
92 from breezy.tests.per_branch import TestCaseWithBranch
93
94@@ -52,3 +54,20 @@
95 self.assertEqual(
96 (1,),
97 the_branch._partial_revision_id_to_revno_cache.get(revmap['1']))
98+
99+ def test_ghost_revision(self):
100+ if not self.bzrdir_format.repository_format.supports_ghosts:
101+ raise TestNotApplicable("repository format does not support ghosts")
102+ builder = self.make_branch_builder('foo')
103+ builder.start_series()
104+ try:
105+ revid1 = builder.build_snapshot(
106+ [b'ghost'], [('add', ('', b'ROOT_ID', 'directory', ''))],
107+ allow_leftmost_as_ghost=True, revision_id=b'tip')
108+ finally:
109+ builder.finish_series()
110+ b = builder.get_branch()
111+ if isinstance(b, FullHistoryBzrBranch):
112+ raise TestNotApplicable("branch format stores full history")
113+ b.set_last_revision_info(4, revid1)
114+ self.assertRaises(errors.GhostRevisionsHaveNoRevno, b.dotted_revno_to_revision_id, (2,))
115
116=== modified file 'breezy/tests/test_remote.py'
117--- breezy/tests/test_remote.py 2019-02-15 14:00:31 +0000
118+++ breezy/tests/test_remote.py 2019-03-13 23:26:23 +0000
119@@ -2214,6 +2214,31 @@
120 branch.revision_id_to_dotted_revno, b'unknown')
121 self.assertFinished(client)
122
123+ def test_ghost_revid(self):
124+ transport = MemoryTransport()
125+ client = FakeClient(transport.base)
126+ client.add_expected_call(
127+ b'Branch.get_stacked_on_url', (b'quack/',),
128+ b'error', (b'NotStacked',),)
129+ # Some older versions of bzr/brz didn't explicitly return
130+ # GhostRevisionsHaveNoRevno
131+ client.add_expected_call(
132+ b'Branch.revision_id_to_revno', (b'quack/', b'revid'),
133+ b'error', (b'error', b'GhostRevisionsHaveNoRevno',
134+ b'The reivison {revid} was not found because there was '
135+ b'a ghost at {ghost-revid}'))
136+ client.add_expected_call(
137+ b'Branch.revision_id_to_revno', (b'quack/', b'revid'),
138+ b'error', (b'GhostRevisionsHaveNoRevno', b'revid', b'ghost-revid',))
139+ transport.mkdir('quack')
140+ transport = transport.clone('quack')
141+ branch = self.make_remote_branch(transport, client)
142+ self.assertRaises(errors.GhostRevisionsHaveNoRevno,
143+ branch.revision_id_to_dotted_revno, b'revid')
144+ self.assertRaises(errors.GhostRevisionsHaveNoRevno,
145+ branch.revision_id_to_dotted_revno, b'revid')
146+ self.assertFinished(client)
147+
148 def test_dotted_no_smart_verb(self):
149 self.setup_smart_server_with_call_log()
150 branch = self.make_branch('.')
151
152=== modified file 'breezy/tests/test_smart.py'
153--- breezy/tests/test_smart.py 2018-11-29 23:42:41 +0000
154+++ breezy/tests/test_smart.py 2019-03-13 23:26:23 +0000
155@@ -905,6 +905,19 @@
156 self.assertEqual(smart_req.SmartServerResponse((b'ok', b'0')),
157 request.execute(b'', b'null:'))
158
159+ def test_ghost_revision(self):
160+ backing = self.get_transport()
161+ request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
162+ backing)
163+ branch = self.make_branch('.')
164+ def revision_id_to_dotted_revno(revid):
165+ raise errors.GhostRevisionsHaveNoRevno(revid, b'ghost-revid')
166+ self.overrideAttr(branch, 'revision_id_to_dotted_revno', revision_id_to_dotted_revno)
167+ self.assertEqual(
168+ smart_req.FailedSmartServerResponse(
169+ (b'GhostRevisionsHaveNoRevno', b'revid', b'ghost-revid')),
170+ request.do_with_branch(branch, b'revid'))
171+
172 def test_simple(self):
173 backing = self.get_transport()
174 request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(

Subscribers

People subscribed via source and target branches