39
39
from ..bzr import groupcompress_repo
41
# This is the dummy foreign revision control system, used
41
# This is the dummy foreign revision control system, used
42
42
# mainly here in the testsuite to test the foreign VCS infrastructure.
43
# It is basically standard Bazaar with some minor modifications to
43
# It is basically standard Bazaar with some minor modifications to
46
46
# It has the following differences to "regular" Bazaar:
47
47
# - The control directory is named ".dummy", not ".bzr".
48
48
# - The revision ids are tuples, not strings.
85
85
self.abbreviation = "dummy"
87
87
def show_foreign_revid(self, foreign_revid):
88
return { "dummy ding": "%s/%s\\%s" % foreign_revid }
88
return {"dummy ding": "%s/%s\\%s" % foreign_revid}
90
90
def serialize_foreign_revid(self, foreign_revid):
91
91
return "%s|%s|%s" % foreign_revid
104
104
self._ignore_fallbacks = False
105
105
self.controldir = a_controldir
106
106
foreign.ForeignBranch.__init__(self,
107
DummyForeignVcsMapping(DummyForeignVcs()))
107
DummyForeignVcsMapping(DummyForeignVcs()))
108
108
bzrbranch.BzrBranch6.__init__(self, _format, _control_files, a_controldir,
111
111
def _get_checkout_format(self, lightweight=False):
112
112
"""Return the most suitable metadir for a checkout of this branch.
143
143
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
144
foreign.ForeignRepository):
144
foreign.ForeignRepository):
145
145
"""Dummy foreign vcs repository."""
161
161
def branch_history(graph, revid):
162
162
ret = list(graph.iter_lefthand_ancestry(revid,
163
(revision.NULL_REVISION,)))
163
(revision.NULL_REVISION,)))
183
183
graph = self.source.repository.get_graph()
184
184
# This just handles simple cases, but that's good enough for tests
185
185
my_history = branch_history(self.target.repository.get_graph(),
187
187
if stop_revision is None:
188
188
stop_revision = self.source.last_revision()
189
189
their_history = branch_history(graph, stop_revision)
194
194
for revid in todo:
195
195
rev = self.source.repository.get_revision(revid)
196
196
tree = self.source.repository.revision_tree(revid)
197
def get_file_with_stat(path, file_id=None):
198
return (tree.get_file(path, file_id), None)
197
def get_file_with_stat(path):
198
return (tree.get_file(path), None)
199
199
tree.get_file_with_stat = get_file_with_stat
200
200
new_revid = self.target.mapping.revision_id_foreign_to_bzr(
201
201
(b'%d' % rev.timestamp, str(rev.timezone).encode('ascii'),
202
202
str(self.target.revno()).encode('ascii')))
203
parent_revno, parent_revid= self.target.last_revision_info()
203
parent_revno, parent_revid = self.target.last_revision_info()
204
204
if parent_revid == revision.NULL_REVISION:
205
205
parent_revids = []
207
207
parent_revids = [parent_revid]
208
208
builder = self.target.get_commit_builder(parent_revids,
209
self.target.get_config_stack(), rev.timestamp,
210
rev.timezone, rev.committer, rev.properties,
209
self.target.get_config_stack(), rev.timestamp,
210
rev.timezone, rev.committer, rev.properties,
213
213
parent_tree = self.target.repository.revision_tree(
222
222
revidmap[revid] = builder.commit(rev.message)
223
self.target.set_last_revision_info(parent_revno+1,
223
self.target.set_last_revision_info(parent_revno + 1,
225
225
trace.mutter('lossily pushed revision %s -> %s',
226
revid, revidmap[revid])
226
revid, revidmap[revid])
228
228
self.source.unlock()
229
229
result.new_revno, result.new_revid = self.target.last_revision_info()
242
242
return DummyForeignVcsDirFormat()
244
244
def open(self, a_controldir, name=None, _found=False, ignore_fallbacks=False,
245
found_repository=None):
245
found_repository=None):
247
247
name = a_controldir._get_selected_branch()
254
254
if found_repository is None:
255
255
found_repository = a_controldir.find_repository()
256
256
return DummyForeignVcsBranch(_format=self,
257
_control_files=control_files,
258
a_controldir=a_controldir,
259
_repository=found_repository,
257
_control_files=control_files,
258
a_controldir=a_controldir,
259
_repository=found_repository,
261
261
except errors.NoSuchFile:
262
262
raise errors.NotBranchError(path=transport.base)
289
289
# Since we don't have a .bzr directory, inherit the
290
290
# mode from the root directory
291
291
temp_control = lockable_files.LockableFiles(transport,
292
'', lockable_files.TransportLock)
292
'', lockable_files.TransportLock)
293
293
temp_control._transport.mkdir('.dummy',
294
294
# FIXME: RBC 20060121 don't peek under
298
298
bzrdir_transport = transport.clone('.dummy')
299
299
# NB: no need to escape relative paths that are url safe.
300
300
control_files = lockable_files.LockableFiles(bzrdir_transport,
301
self._lock_file_name, self._lock_class)
301
self._lock_file_name, self._lock_class)
302
302
control_files.create_lock()
303
303
return self.open(transport, _found=True)
314
314
self.root_transport = _transport
315
315
self._mode_check_done = False
316
316
self._control_files = lockable_files.LockableFiles(self.transport,
317
"lock", lockable_files.TransportLock)
317
"lock", lockable_files.TransportLock)
319
319
def create_workingtree(self):
320
320
# dirstate requires a ".bzr" entry to exist
396
396
def test_parse_revision_id(self):
397
397
reg = foreign.ForeignVcsRegistry()
398
398
vcs = DummyForeignVcs()
399
reg.register(b"dummy", vcs, "Dummy VCS")
399
reg.register("dummy", vcs, "Dummy VCS")
400
400
self.assertEqual((
401
401
(b"some", b"foreign", b"revid"), DummyForeignVcsMapping(vcs)),
402
402
reg.parse_revision_id(b"dummy-v1:some-foreign-revid"))