def do(self, path): """Initialize a bzrdir at path. The default format of the server is used. :return: SmartServerResponse(('ok', )) """ target_transport = self.transport_from_client_path(path) BzrDirFormat.get_default_format().initialize_on_transport(target_transport) return SuccessfulSmartServerResponse(('ok', ))
def do(self, path): """Initialize a bzrdir at path. The default format of the server is used. :return: SmartServerResponse(('ok', )) """ target_transport = self.transport_from_client_path(path) BzrDirFormat.get_default_format().initialize_on_transport( target_transport) return SuccessfulSmartServerResponse(('ok', ))
def _qbzr_run(self): # Remove svn checkout support try: from bzrlib.plugins.svn.format import SvnWorkingTreeDirFormat except ImportError: pass else: from bzrlib.bzrdir import BzrDirFormat, format_registry BzrDirFormat.unregister_control_format(SvnWorkingTreeDirFormat) format_registry.remove('subversion-wc') # Start QBzr window = QBzrMainWindow() window.setDirectory(osutils.realpath(CUR_DIR)) window.show() self._application.exec_()
def convert(self): try: branch = self.bzrdir.open_branch() if branch.bzrdir.root_transport.base != \ self.bzrdir.root_transport.base: self.pb.note("This is a checkout. The branch (%s) needs to be " "upgraded separately.", branch.bzrdir.root_transport.base) del branch except (errors.NotBranchError, errors.IncompatibleRepositories): # might not be a format we can open without upgrading; see e.g. # https://bugs.launchpad.net/bzr/+bug/253891 pass if not self.bzrdir.needs_format_conversion(self.format): raise errors.UpToDateFormat(self.bzrdir._format) if not self.bzrdir.can_convert_format(): raise errors.BzrError("cannot upgrade from bzrdir format %s" % self.bzrdir._format) if self.format is None: target_format = BzrDirFormat.get_default_format() else: target_format = self.format self.bzrdir.check_conversion_target(target_format) self.pb.note('starting upgrade of %s', self.transport.base) self._backup_control_dir() while self.bzrdir.needs_format_conversion(self.format): converter = self.bzrdir._format.get_converter(self.format) self.bzrdir = converter.convert(self.bzrdir, self.pb) self.pb.note("finished")
def convert(self): try: branch = self.bzrdir.open_branch() if branch.bzrdir.root_transport.base != \ self.bzrdir.root_transport.base: self.pb.note( "This is a checkout. The branch (%s) needs to be " "upgraded separately.", branch.bzrdir.root_transport.base) del branch except (errors.NotBranchError, errors.IncompatibleRepositories): # might not be a format we can open without upgrading; see e.g. # https://bugs.launchpad.net/bzr/+bug/253891 pass if not self.bzrdir.needs_format_conversion(self.format): raise errors.UpToDateFormat(self.bzrdir._format) if not self.bzrdir.can_convert_format(): raise errors.BzrError("cannot upgrade from bzrdir format %s" % self.bzrdir._format) if self.format is None: target_format = BzrDirFormat.get_default_format() else: target_format = self.format self.bzrdir.check_conversion_target(target_format) self.pb.note('starting upgrade of %s', self.transport.base) self._backup_control_dir() while self.bzrdir.needs_format_conversion(self.format): converter = self.bzrdir._format.get_converter(self.format) self.bzrdir = converter.convert(self.bzrdir, self.pb) self.pb.note("finished")
def needs_format_conversion(self, format=None): """See ControlDir.needs_format_conversion().""" # if the format is not the same as the system default, # an upgrade is needed. if format is None: symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0)) % 'needs_format_conversion(format=None)') format = BzrDirFormat.get_default_format() return not isinstance(self._format, format.__class__)
def needs_format_conversion(self, format=None): """See ControlDir.needs_format_conversion().""" # if the format is not the same as the system default, # an upgrade is needed. if format is None: symbol_versioning.warn( symbol_versioning.deprecated_in( (1, 13, 0)) % 'needs_format_conversion(format=None)') format = BzrDirFormat.get_default_format() return not isinstance(self._format, format.__class__)
def load_tests(basic_tests, module, loader): result = loader.suiteClass() # add the tests for this module result.addTests(basic_tests) test_bzrdir_implementations = [ 'bzrlib.tests.bzrdir_implementations.test_bzrdir', ] formats = BzrDirFormat.known_formats() adapter = BzrDirTestProviderAdapter( default_transport, None, # None here will cause a readonly decorator to be created # by the TestCaseWithTransport.get_readonly_transport method. None, formats) # add the tests for the sub modules adapt_modules(test_bzrdir_implementations, adapter, loader, result) # This will always add the tests for smart server transport, regardless of # the --transport option the user specified to 'bzr selftest'. from bzrlib.smart.server import ( ReadonlySmartTCPServer_for_testing, ReadonlySmartTCPServer_for_testing_v2_only, SmartTCPServer_for_testing, SmartTCPServer_for_testing_v2_only, ) from bzrlib.remote import RemoteBzrDirFormat # test the remote server behaviour using a MemoryTransport smart_server_suite = loader.suiteClass() adapt_to_smart_server = BzrDirTestProviderAdapter( MemoryServer, SmartTCPServer_for_testing, ReadonlySmartTCPServer_for_testing, [(RemoteBzrDirFormat())], name_suffix='-default') adapt_modules(test_bzrdir_implementations, adapt_to_smart_server, loader, smart_server_suite) adapt_to_smart_server = BzrDirTestProviderAdapter( MemoryServer, SmartTCPServer_for_testing_v2_only, ReadonlySmartTCPServer_for_testing_v2_only, [(RemoteBzrDirFormat())], name_suffix='-v2') adapt_modules(test_bzrdir_implementations, adapt_to_smart_server, loader, smart_server_suite) result.addTests(smart_server_suite) return result
class ToBzrImportWorker(ImportWorker): """Oversees the actual work of a code import to Bazaar.""" # Where the Bazaar working tree will be stored. BZR_BRANCH_PATH = 'bzr_branch' # Should `getBazaarBranch` create a working tree? needs_bzr_tree = True required_format = BzrDirFormat.get_default_format() def __init__(self, source_details, import_data_transport, bazaar_branch_store, logger, opener_policy): """Construct a `ToBzrImportWorker`. :param source_details: A `CodeImportSourceDetails` object. :param bazaar_branch_store: A `BazaarBranchStore`. The import worker uses this to fetch and store the Bazaar branches that are created and updated during the import process. :param logger: A `Logger` to pass to cscvs. :param opener_policy: Policy object that decides what branches can be imported """ super(ToBzrImportWorker, self).__init__(source_details, logger, opener_policy) self.bazaar_branch_store = bazaar_branch_store self.import_data_store = ImportDataStore(import_data_transport, self.source_details) def getBazaarBranch(self): """Return the Bazaar `Branch` that we are importing into.""" if os.path.isdir(self.BZR_BRANCH_PATH): shutil.rmtree(self.BZR_BRANCH_PATH) return self.bazaar_branch_store.pull( self.source_details.target_id, self.BZR_BRANCH_PATH, self.required_format, self.needs_bzr_tree, stacked_on_url=self.source_details.stacked_on_url) def pushBazaarBranch(self, bazaar_branch, remote_branch=None): """Push the updated Bazaar branch to the server. :return: True if revisions were transferred. """ return self.bazaar_branch_store.push( self.source_details.target_id, bazaar_branch, self.required_format, stacked_on_url=self.source_details.stacked_on_url)
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 do(self, path): from bzrlib.bzrdir import BzrDirFormat try: t = self.transport_from_client_path(path) except errors.PathNotChild: # The client is trying to ask about a path that they have no access # to. # Ideally we'd return a FailedSmartServerResponse here rather than # a "successful" negative, but we want to be compatibile with # clients that don't anticipate errors from this method. answer = 'no' else: default_format = BzrDirFormat.get_default_format() real_bzrdir = default_format.open(t, _found=True) try: real_bzrdir._format.probe_transport(t) except (errors.NotBranchError, errors.UnknownFormatError): answer = 'no' else: answer = 'yes' return SuccessfulSmartServerResponse((answer, ))
def do(self, path): from bzrlib.bzrdir import BzrDirFormat try: t = self.transport_from_client_path(path) except errors.PathNotChild: # The client is trying to ask about a path that they have no access # to. # Ideally we'd return a FailedSmartServerResponse here rather than # a "successful" negative, but we want to be compatibile with # clients that don't anticipate errors from this method. answer = 'no' else: default_format = BzrDirFormat.get_default_format() real_bzrdir = default_format.open(t, _found=True) try: real_bzrdir._format.probe_transport(t) except (errors.NotBranchError, errors.UnknownFormatError): answer = 'no' else: answer = 'yes' return SuccessfulSmartServerResponse((answer,))
def _makeControlTransport(self, default_stack_on, trailing_path=None): """Make a transport that points to a control directory. A control directory is a .bzr directory containing a 'control.conf' file. This is used to specify configuration for branches created underneath the directory that contains the control directory. :param default_stack_on: The default stacked-on branch URL for branches that respect this control directory. If empty, then we'll return an empty memory transport. :return: A read-only `MemoryTransport` containing a working BzrDir, configured to use the given default stacked-on location. """ memory_server = MemoryServer() memory_server.start_server() transport = get_transport(memory_server.get_url()) if default_stack_on == "": return transport format = BzrDirFormat.get_default_format() bzrdir = format.initialize_on_transport(transport) bzrdir.get_config().set_default_stack_on(urlutils.unescape(default_stack_on)) return get_readonly_transport(transport)
def _makeControlTransport(self, default_stack_on, trailing_path=None): """Make a transport that points to a control directory. A control directory is a .bzr directory containing a 'control.conf' file. This is used to specify configuration for branches created underneath the directory that contains the control directory. :param default_stack_on: The default stacked-on branch URL for branches that respect this control directory. If empty, then we'll return an empty memory transport. :return: A read-only `MemoryTransport` containing a working BzrDir, configured to use the given default stacked-on location. """ memory_server = MemoryServer() memory_server.start_server() transport = get_transport(memory_server.get_url()) if default_stack_on == '': return transport format = BzrDirFormat.get_default_format() bzrdir = format.initialize_on_transport(transport) bzrdir.get_config().set_default_stack_on( urlutils.unescape(default_stack_on)) return get_readonly_transport(transport)
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_default_format_is_same_as_bzrdir_default(self): # XXX: it might be nice if there was only one place the default was # set, but at the moment that's not true -- mbp 20070814 -- # https://bugs.launchpad.net/bzr/+bug/132376 self.assertEqual(BranchFormat.get_default_format(), BzrDirFormat.get_default_format().get_branch_format())
class ImportWorker: """Oversees the actual work of a code import.""" # Where the Bazaar working tree will be stored. BZR_BRANCH_PATH = 'bzr_branch' # Should `getBazaarBranch` create a working tree? needs_bzr_tree = True required_format = BzrDirFormat.get_default_format() def __init__(self, source_details, import_data_transport, bazaar_branch_store, logger, opener_policy): """Construct an `ImportWorker`. :param source_details: A `CodeImportSourceDetails` object. :param bazaar_branch_store: A `BazaarBranchStore`. The import worker uses this to fetch and store the Bazaar branches that are created and updated during the import process. :param logger: A `Logger` to pass to cscvs. :param opener_policy: Policy object that decides what branches can be imported """ self.source_details = source_details self.bazaar_branch_store = bazaar_branch_store self.import_data_store = ImportDataStore( import_data_transport, self.source_details) self._logger = logger self._opener_policy = opener_policy def getBazaarBranch(self): """Return the Bazaar `Branch` that we are importing into.""" if os.path.isdir(self.BZR_BRANCH_PATH): shutil.rmtree(self.BZR_BRANCH_PATH) return self.bazaar_branch_store.pull( self.source_details.branch_id, self.BZR_BRANCH_PATH, self.required_format, self.needs_bzr_tree, stacked_on_url=self.source_details.stacked_on_url) def pushBazaarBranch(self, bazaar_branch): """Push the updated Bazaar branch to the server. :return: True if revisions were transferred. """ return self.bazaar_branch_store.push( self.source_details.branch_id, bazaar_branch, self.required_format, stacked_on_url=self.source_details.stacked_on_url) def getWorkingDirectory(self): """The directory we should change to and store all scratch files in. """ base = config.codeimportworker.working_directory_root dirname = 'worker-for-branch-%s' % self.source_details.branch_id return os.path.join(base, dirname) def run(self): """Run the code import job. This is the primary public interface to the `ImportWorker`. This method: 1. Retrieves an up-to-date foreign tree to import. 2. Gets the Bazaar branch to import into. 3. Imports the foreign tree into the Bazaar branch. If we've already imported this before, we synchronize the imported Bazaar branch with the latest changes to the foreign tree. 4. Publishes the newly-updated Bazaar branch, making it available to Launchpad users. 5. Archives the foreign tree, so that we can update it quickly next time. """ working_directory = self.getWorkingDirectory() if os.path.exists(working_directory): shutil.rmtree(working_directory) os.makedirs(working_directory) saved_pwd = os.getcwd() os.chdir(working_directory) try: return self._doImport() finally: shutil.rmtree(working_directory) os.chdir(saved_pwd) def _doImport(self): """Perform the import. :return: A CodeImportWorkerExitCode """ raise NotImplementedError()