def get_parented_branch(self): wt_a = self.make_branch_and_tree('a') self.build_tree(['a/one']) wt_a.add(['one']) rev1 = wt_a.commit('commit one') branch_b = wt_a.branch.controldir.sprout( 'b', revision_id=rev1).open_branch() self.assertEqual( urlutils.split_segment_parameters(wt_a.branch.user_url)[0], urlutils.split_segment_parameters(branch_b.get_parent())[0]) return branch_b
def open(self, transport, _create=False, _found=None): """Open this directory. :param _create: create the hg dir on the fly. private to HgControlDirFormat. """ # we dont grok readonly - hg isn't integrated with transport. try: url = transport.external_url() except errors.InProcessTransport: raise errors.NotBranchError(transport.base) url = urlutils.split_segment_parameters(url)[0] try: path = transport.local_abspath('.').encode('utf-8') except errors.NotLocalUrl: path = url.rstrip("/") supports_read_lock = False else: supports_read_lock = True lazy_load_mercurial() import mercurial.hg from breezy.plugins.hg.ui import ui repository = mercurial.hg.repository(ui(), path, create=_create) lock = HgLock(transport, repository, supports_read_lock) return HgDir(repository, transport, lock, self)
def probe_transport(self, transport): try: external_url = transport.external_url() except errors.InProcessTransport: raise errors.NotBranchError(path=transport.base) scheme = external_url.split(":")[0] if scheme not in self._supported_schemes: raise errors.NotBranchError(path=transport.base) from breezy import urlutils external_url = urlutils.split_segment_parameters(external_url)[0] # Explicitly check for .hg directories here, so we avoid # loading foreign branches through Mercurial. if (external_url.startswith("http:") or external_url.startswith("https:")): if not has_hg_http_smart_server(transport, external_url): raise errors.NotBranchError(path=transport.base) else: if not has_hg_dumb_repository(transport): raise errors.NotBranchError(path=transport.base) lazy_load_mercurial() from mercurial import error as hg_errors import urllib2 from breezy.plugins.hg.dir import HgControlDirFormat format = HgControlDirFormat() try: format.open(transport) except hg_errors.RepoError, e: raise errors.NotBranchError(path=transport.base)
def open_packaging_branch(location, possible_transports=None, vcs_type=None): """Open a packaging branch from a location string. location can either be a package name or a full URL """ if "/" not in location and ":" not in location: pkg_source = apt_get_source_package(location) try: (vcs_type, vcs_url) = source_package_vcs(pkg_source) except KeyError: raise NoVcsInformation(location) (url, branch_name, subpath) = split_vcs_url(vcs_url) else: url, params = urlutils.split_segment_parameters(location) try: branch_name = urlutils.unquote(params["branch"]) except KeyError: branch_name = None subpath = "" probers = select_probers(vcs_type) branch = open_branch(url, possible_transports=possible_transports, probers=probers, name=branch_name) return branch, subpath or ""
def push_branch( source_branch: Branch, url: str, vcs_type: str, overwrite=False, stop_revision=None, tag_selector=None, possible_transports: Optional[List[Transport]] = None, ) -> None: url, params = urlutils.split_segment_parameters(url) branch_name = params.get("branch") if branch_name is not None: branch_name = urlutils.unquote(branch_name) if vcs_type is None: vcs_type = source_branch.controldir.cloning_metadir() try: target = ControlDir.open(url, possible_transports=possible_transports) except NotBranchError: target = ControlDir.create(url, format=vcs_type, possible_transports=possible_transports) target.push_branch(source_branch, revision_id=stop_revision, overwrite=overwrite, name=branch_name, tag_selector=tag_selector)
def full_branch_url(branch): """Get the full URL for a branch. Ideally this should just return Branch.user_url, but that currently exclude the branch name in some situations. """ if branch.name is None: return branch.user_url url, params = urlutils.split_segment_parameters(branch.user_url) if branch.name != "": params["branch"] = urlutils.quote(branch.name, "") return urlutils.join_segment_parameters(url, params)
def bzr_to_svn_url(url): """Convert a Bazaar URL to a URL understood by Subversion. This will possibly remove the svn+ prefix. """ url = urlutils.split_segment_parameters(url.strip("/"))[0] if url.startswith("readonly+"): url = url[len("readonly+"):] readonly = True else: readonly = False if (url.startswith("svn+http://") or url.startswith("svn+https://")): url = url[len("svn+"):] # Skip svn+ url = svn_uri_canonicalize(url) # The SVN libraries don't like trailing slashes... url = url.rstrip('/') return url, readonly
def open_branch( url: str, possible_transports: Optional[List[Transport]] = None, probers: Optional[List[Prober]] = None, name: str = None, ) -> Branch: """Open a branch by URL.""" url, params = urlutils.split_segment_parameters(url) if name is None: try: name = urlutils.unquote(params["branch"]) except KeyError: name = None try: transport = get_transport(url, possible_transports=possible_transports) dir = ControlDir.open_from_transport(transport, probers) return dir.open_branch(name=name) except Exception as e: converted = _convert_exception(url, e) if converted is not None: raise converted raise e
def test_sprout_branch_parent(self): source = self.make_branch('source') target = source.controldir.sprout(self.get_url('target')).open_branch() self.assertEqual( urlutils.split_segment_parameters(source.user_url)[0], urlutils.split_segment_parameters(target.get_parent())[0])