def test_shared_no_tree_disk_layout(self): control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control, shared=True) repo.set_make_working_trees(False) # we want: # format 'Bazaar-NG Repository format 7' # lock '' # inventory.weave == empty_weave # empty revision-store directory # empty weaves directory # a 'shared-storage' marker file. t = control.get_repository_transport(None) self.assertEqualDiff('Bazaar-NG Repository format 7', t.get('format').read()) ## self.assertEqualDiff('', t.get('lock').read()) self.assertEqualDiff('', t.get('shared-storage').read()) self.assertEqualDiff('', t.get('no-working-trees').read()) repo.set_make_working_trees(True) self.assertFalse(t.has('no-working-trees')) self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode)) self.assertTrue(S_ISDIR(t.stat('weaves').st_mode)) self.assertEqualDiff('# bzr weave file v5\n' 'w\n' 'W\n', t.get('inventory.weave').read())
def makeBranch(self, path, branch_format, repository_format): """Make a Bazaar branch at 'path' with the given formats.""" bzrdir_format = BzrDirMetaFormat1() bzrdir_format.set_branch_format(branch_format) bzrdir = self.make_bzrdir(path, format=bzrdir_format) repository_format.initialize(bzrdir) return bzrdir.create_branch()
def test_notification_on_branch_from_nonrepository(self): fmt = BzrDirMetaFormat1() t = self.get_transport() t.mkdir('a') dir = fmt.initialize_on_transport(t.clone('a')) self.assertRaises(errors.NoRepositoryPresent, dir.open_repository) e = self.assertRaises(errors.NotBranchError, dir.open_branch) self.assertNotContainsRe(str(e), "location is a repository")
def testSourceFormatChange(self): # If a branch that has already been mirrored changes format, then we # when we re-mirror the branch, the mirror will acquire the new # format. # Create and mirror a branch in weave format. self._createSourceBranch(RepositoryFormat7(), BzrDirMetaFormat1()) self.worker.mirror() # Change the branch to knit format and mirror again. self.get_transport().delete_tree(self._source_branch_path) self._createSourceBranch(RepositoryFormatKnit1(), BzrDirMetaFormat1()) self.worker.mirror() # The mirrored branch should now be in knit format. self.assertMirrored( Branch.open(self.worker.source), Branch.open(self.worker.dest))
def test_loomBranch(self): # When we mirror a loom branch for the first time, the mirrored loom # branch matches the original. branch = self._createSourceBranch(RepositoryFormatKnitPack5(), BzrDirMetaFormat1()) self.loomify(branch) self.worker.mirror() mirrored_branch = Branch.open(self.worker.dest) self.assertMirrored(branch, mirrored_branch)
def test_creation(self): format = BzrDirMetaFormat1() format.set_branch_format(_mod_branch.BzrBranchFormat6()) branch = self.make_branch('a', format=format) self.assertIsInstance(branch, self.get_class()) branch = self.make_branch('b', format=self.get_format_name()) self.assertIsInstance(branch, self.get_class()) branch = _mod_branch.Branch.open('a') self.assertIsInstance(branch, self.get_class())
def test_get_set_default_format(self): # set the format and then set it back again old_format = BranchFormat.get_default_format() BranchFormat.set_default_format(SampleBranchFormat()) try: # the default branch format is used by the meta dir format # which is not the default bzrdir format at this point dir = BzrDirMetaFormat1().initialize('memory:///') result = dir.create_branch() self.assertEqual(result, 'A branch') finally: BranchFormat.set_default_format(old_format) self.assertEqual(old_format, BranchFormat.get_default_format())
def test_creates_lockdir(self): """Make sure it appears to be controlled by a LockDir existence""" control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control, shared=True) t = control.get_repository_transport(None) # TODO: Should check there is a 'lock' toplevel directory, # regardless of contents self.assertFalse(t.has('lock/held/info')) repo.lock_write() try: self.assertTrue(t.has('lock/held/info')) finally: # unlock so we don't get a warning about failing to do so repo.unlock()
def test_safe_master_lock(self): os.mkdir('master') master = BzrDirMetaFormat1().initialize('master') master.create_repository() master_branch = master.create_branch() master.create_workingtree() bound = master.sprout('bound') wt = bound.open_workingtree() wt.branch.set_bound_location(os.path.realpath('master')) master_branch.lock_write() try: self.assertRaises(LockContention, wt.commit, 'silly') finally: master_branch.unlock()
def test_init_at_repository_root(self): # bzr init at the root of a repository should create a branch # and working tree even when creation of working trees is disabled. t = self.get_transport() t.mkdir('repo') format = BzrDirMetaFormat1() newdir = format.initialize(t.abspath('repo')) repo = newdir.create_repository(shared=True) repo.set_make_working_trees(False) out, err = self.run_bzr('init repo') self.assertEqual('', out) self.assertEqual('', err) newdir.open_branch() newdir.open_workingtree()
def test_uses_lockdir(self): """repo format 7 actually locks on lockdir""" base_url = self.get_url() control = BzrDirMetaFormat1().initialize(base_url) repo = RepositoryFormat7().initialize(control, shared=True) t = control.get_repository_transport(None) repo.lock_write() repo.unlock() del repo # make sure the same lock is created by opening it repo = Repository.open(base_url) repo.lock_write() self.assertTrue(t.has('lock/held/info')) repo.unlock() self.assertFalse(t.has('lock/held/info'))
def test_branch_format_5_uses_lockdir(self): url = self.get_url() bzrdir = BzrDirMetaFormat1().initialize(url) bzrdir.create_repository() branch = bzrdir.create_branch() t = self.get_transport() self.log("branch instance is %r" % branch) self.assert_(isinstance(branch, BzrBranch5)) self.assertIsDirectory('.', t) self.assertIsDirectory('.bzr/branch', t) self.assertIsDirectory('.bzr/branch/lock', t) branch.lock_write() try: self.assertIsDirectory('.bzr/branch/lock/held', t) finally: branch.unlock()
def test_disk_layout(self): control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control) # in case of side effects of locking. repo.lock_write() repo.unlock() # we want: # format 'Bazaar-NG Repository format 7' # lock '' # inventory.weave == empty_weave # empty revision-store directory # empty weaves directory t = control.get_repository_transport(None) self.assertEqualDiff('Bazaar-NG Repository format 7', t.get('format').read()) self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode)) self.assertTrue(S_ISDIR(t.stat('weaves').st_mode)) self.assertEqualDiff('# bzr weave file v5\n' 'w\n' 'W\n', t.get('inventory.weave').read()) # Creating a file with id Foo:Bar results in a non-escaped file name on # disk. control.create_branch() tree = control.create_workingtree() tree.add(['foo'], ['Foo:Bar'], ['file']) tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n') try: tree.commit('first post', rev_id='first') except IllegalPath: if sys.platform != 'win32': raise self.knownFailure('Foo:Bar cannot be used as a file-id on windows' ' in repo format 7') return self.assertEqualDiff( '# bzr weave file v5\n' 'i\n' '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n' 'n first\n' '\n' 'w\n' '{ 0\n' '. content\n' '}\n' 'W\n', t.get('weaves/74/Foo%3ABar.weave').read())
def test_uncommit_bound(self): os.mkdir('a') a = BzrDirMetaFormat1().initialize('a') a.create_repository() a.create_branch() t_a = a.create_workingtree() t_a.commit('commit 1') t_a.commit('commit 2') t_a.commit('commit 3') b = t_a.branch.create_checkout('b').branch uncommit.uncommit(b) self.assertEqual(b.last_revision_info()[0], 2) self.assertEqual(t_a.branch.last_revision_info()[0], 2) # update A's tree to not have the uncommitted revision referenced. t_a.update() t_a.commit('commit 3b') self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b) b.pull(t_a.branch) uncommit.uncommit(b)
def test_init_at_repository_root(self): # bzr init at the root of a repository should create a branch # and working tree even when creation of working trees is disabled. t = self.get_transport() t.mkdir('repo') format = BzrDirMetaFormat1() newdir = format.initialize(t.abspath('repo')) repo = newdir.create_repository(shared=True) repo.set_make_working_trees(False) out, err = self.run_bzr('init repo') self.assertEqual( """Created a repository tree (format: %s) Using shared repository: %s """ % (self._default_label, urlutils.local_path_from_url( repo.bzrdir.root_transport.external_url())), out) cwd = osutils.getcwd() self.assertEndsWith(out, cwd + '/repo/\n') self.assertEqual('', err) newdir.open_branch() newdir.open_workingtree()
def test_push_only_pushes_history(self): # Knit branches should only push the history for the current revision. format = BzrDirMetaFormat1() format.repository_format = RepositoryFormatKnit1() shared_repo = self.make_repository('repo', format=format, shared=True) shared_repo.set_make_working_trees(True) def make_shared_tree(path): shared_repo.bzrdir.root_transport.mkdir(path) shared_repo.bzrdir.create_branch_convenience('repo/' + path) return WorkingTree.open('repo/' + path) tree_a = make_shared_tree('a') self.build_tree(['repo/a/file']) tree_a.add('file') tree_a.commit('commit a-1', rev_id='a-1') f = open('repo/a/file', 'ab') f.write('more stuff\n') f.close() tree_a.commit('commit a-2', rev_id='a-2') tree_b = make_shared_tree('b') self.build_tree(['repo/b/file']) tree_b.add('file') tree_b.commit('commit b-1', rev_id='b-1') self.assertTrue(shared_repo.has_revision('a-1')) self.assertTrue(shared_repo.has_revision('a-2')) self.assertTrue(shared_repo.has_revision('b-1')) # Now that we have a repository with shared files, make sure # that things aren't copied out by a 'push' os.chdir('repo/b') self.run_bzr('push ../../push-b') pushed_tree = WorkingTree.open('../../push-b') pushed_repo = pushed_tree.branch.repository self.assertFalse(pushed_repo.has_revision('a-1')) self.assertFalse(pushed_repo.has_revision('a-2')) self.assertTrue(pushed_repo.has_revision('b-1'))
def initialize_on_transport_ex(self, transport, use_existing_dir=False, create_prefix=False, force_new_repo=False, stacked_on=None, stack_on_pwd=None, repo_format_name=None, make_working_trees=None, shared_repo=False): """See ControlDir.initialize_on_transport_ex.""" require_stacking = (stacked_on is not None) # Format 5 cannot stack, but we've been asked to - actually init # a Meta1Dir if require_stacking: format = BzrDirMetaFormat1() return format.initialize_on_transport_ex( transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo, stacked_on=stacked_on, stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name, make_working_trees=make_working_trees, shared_repo=shared_repo) return BzrDirFormat.initialize_on_transport_ex( self, transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo, stacked_on=stacked_on, stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name, make_working_trees=make_working_trees, shared_repo=shared_repo)
def test_attribute__fetch_uses_deltas(self): """Weaves do not reuse deltas.""" control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control) self.assertEqual(False, repo._format._fetch_uses_deltas)
def test_attribute__fetch_order(self): """Weaves need topological data insertion.""" control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control) self.assertEqual('topological', repo._format._fetch_order)
def test_supports_external_lookups(self): control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control) self.assertFalse(repo._format.supports_external_lookups)
def convert(self, to_convert, pb): """See Converter.convert().""" from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7 from bzrlib.branchfmt.fullhistory import BzrBranchFormat5 self.bzrdir = to_convert self.pb = ui.ui_factory.nested_progress_bar() self.count = 0 self.total = 20 # the steps we know about self.garbage_inventories = [] self.dir_mode = self.bzrdir._get_dir_mode() self.file_mode = self.bzrdir._get_file_mode() ui.ui_factory.note( gettext('starting upgrade from format 6 to metadir')) self.bzrdir.transport.put_bytes('branch-format', "Converting to format 6", mode=self.file_mode) # its faster to move specific files around than to open and use the apis... # first off, nuke ancestry.weave, it was never used. try: self.step(gettext('Removing ancestry.weave')) self.bzrdir.transport.delete('ancestry.weave') except errors.NoSuchFile: pass # find out whats there self.step(gettext('Finding branch files')) last_revision = self.bzrdir.open_branch().last_revision() bzrcontents = self.bzrdir.transport.list_dir('.') for name in bzrcontents: if name.startswith('basis-inventory.'): self.garbage_inventories.append(name) # create new directories for repository, working tree and branch repository_names = [('inventory.weave', True), ('revision-store', True), ('weaves', True)] self.step(gettext('Upgrading repository') + ' ') self.bzrdir.transport.mkdir('repository', mode=self.dir_mode) self.make_lock('repository') # we hard code the formats here because we are converting into # the meta format. The meta format upgrader can take this to a # future format within each component. self.put_format('repository', RepositoryFormat7()) for entry in repository_names: self.move_entry('repository', entry) self.step(gettext('Upgrading branch') + ' ') self.bzrdir.transport.mkdir('branch', mode=self.dir_mode) self.make_lock('branch') self.put_format('branch', BzrBranchFormat5()) branch_files = [('revision-history', True), ('branch-name', True), ('parent', False)] for entry in branch_files: self.move_entry('branch', entry) checkout_files = [('pending-merges', True), ('inventory', True), ('stat-cache', False)] # If a mandatory checkout file is not present, the branch does not have # a functional checkout. Do not create a checkout in the converted # branch. for name, mandatory in checkout_files: if mandatory and name not in bzrcontents: has_checkout = False break else: has_checkout = True if not has_checkout: ui.ui_factory.note(gettext('No working tree.')) # If some checkout files are there, we may as well get rid of them. for name, mandatory in checkout_files: if name in bzrcontents: self.bzrdir.transport.delete(name) else: from bzrlib.workingtree_3 import WorkingTreeFormat3 self.step(gettext('Upgrading working tree')) self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode) self.make_lock('checkout') self.put_format('checkout', WorkingTreeFormat3()) self.bzrdir.transport.delete_multi(self.garbage_inventories, self.pb) for entry in checkout_files: self.move_entry('checkout', entry) if last_revision is not None: self.bzrdir.transport.put_bytes('checkout/last-revision', last_revision) self.bzrdir.transport.put_bytes( 'branch-format', BzrDirMetaFormat1().get_format_string(), mode=self.file_mode) self.pb.finished() return ControlDir.open(self.bzrdir.user_url)
def test_attribute__fetch_reconcile(self): """Weave repositories need a reconcile after fetch.""" control = BzrDirMetaFormat1().initialize(self.get_url()) repo = RepositoryFormat7().initialize(control) self.assertEqual(True, repo._format._fetch_reconcile)
def testMirrorMetaweaveAsMetaweave(self): # Create a source branch in metaweave format, and check that the # mirror is in metaweave format. self._testMirrorWithFormats(RepositoryFormat7(), BzrDirMetaFormat1())
def testMirrorKnitAsKnit(self): # Create a source branch in knit format, and check that the mirror is # in knit format. self._testMirrorWithFormats( RepositoryFormatKnit1(), BzrDirMetaFormat1())