예제 #1
0
def parse_text_revisions_property(text):
    ret = {}
    for line in text.splitlines():
        (entry, revid) = line.split("\t", 1)
        ret[urlutils.unquote(entry).decode(
            "utf-8")] = osutils.safe_revision_id(revid)
    return ret
예제 #2
0
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 ""
예제 #3
0
def url_join_unescaped_path(url, path):
    (scheme, netloc, basepath, query, fragment) = urlparse.urlsplit(url)
    path = urlutils.join(urlutils.unquote(basepath), path)
    if scheme in ("http", "https"):
        # Without this, URLs with + in them break
        path = urlutils.quote(path, safe="/+%")
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
예제 #4
0
def unescape_svn_path(x):
    """Unescape a path for use by Subversion.

    :param x: Escaped path
    :return: Unescaped path
    """
    return urlutils.unquote(x.decode('utf-8'))
예제 #5
0
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)
예제 #6
0
def _url_unescape_uri(url):
    (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
    if scheme in ("http", "https"):
        # Without this, URLs with + in them break
        path = urlutils.quote(urlutils.unquote(path), safe="/+%")
    while "//" in path:
        path = path.replace("//", "/")
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
예제 #7
0
def parse_text_parents_property(text):
    ret = {}
    for line in text.splitlines():
        parts = line.split("\t")
        entry = parts[0]
        ret[urlutils.unquote(entry).decode("utf-8")] = filter(
            lambda x: x != "", [
                osutils.safe_revision_id(parent_revid)
                for parent_revid in parts[1:]
            ])
    return ret
예제 #8
0
def parse_fileid_property(text):
    """Pares a fileid file or revision property.

    :param text: Property value
    :return: Map of path -> fileid
    """
    ret = {}
    for line in text.splitlines():
        (path, key) = line.split("\t", 1)
        ret[urlutils.unquote(path).decode("utf-8")] = str(key)
    return ret
예제 #9
0
 def __init__(self, dirname, parity, branch):
     self.dirname = urlutils.unquote(dirname)
     self.parity = parity
     self.branch = branch
     if branch is not None:
         # If a branch is empty, bzr raises an exception when trying this
         try:
             self.last_revision = branch.repository.get_revision(branch.last_revision())
             self.last_change_time = datetime.datetime.utcfromtimestamp(self.last_revision.timestamp)
         except errors.NoSuchRevision:
             self.last_revision = None
             self.last_change_time = None
예제 #10
0
 def find_ids(entry):
     assert entry.url.startswith(self._repository.svn_transport.svn_url)
     relpath = urlutils.unquote(
         entry.url[len(self._repository.svn_transport.svn_url):].strip(
             "/"))
     if isinstance(relpath, bytes):
         relpath = relpath.decode('utf-8')
     assert isinstance(relpath, str)
     if entry.schedule in (wc.SCHEDULE_NORMAL, wc.SCHEDULE_DELETE,
                           wc.SCHEDULE_REPLACE):
         return self.lookup_id(self.workingtree.unprefix(relpath))
     return (None, None)
예제 #11
0
    def get_values(self, path, kwargs, headers):
        revid = urlutils.unquote_to_bytes(self.args[0])
        compare_revid = urlutils.unquote_to_bytes(self.args[1])
        filename = urlutils.unquote(self.args[2])

        try:
            context_lines = int(kwargs['context'])
        except (KeyError, ValueError):
            context_lines = None

        chunks = diff_chunks_for_file(self._history._branch.repository,
                                      filename,
                                      compare_revid,
                                      revid,
                                      context_lines=context_lines)

        return {
            'chunks': chunks,
        }
예제 #12
0
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
예제 #13
0
    def __init__(self, _transport, _format=None):
        """See ControlDir.__init__()."""
        from .transport import bzr_to_svn_url, get_svn_ra_transport
        svn_transport = get_svn_ra_transport(_transport)
        if _format is None:
            _format = SvnRemoteFormat()
        self._format = _format
        self._config = None
        self.svn_transport = svn_transport
        self.transport = None
        self.root_transport = _transport

        self.svn_url, readonly = bzr_to_svn_url(self.root_transport.base)
        self.svn_root_url = svn_transport.get_svn_repos_root()
        self.root_url = svn_transport.get_repos_root()

        if not self.svn_url.lower().startswith(self.svn_root_url.lower()):
            raise AssertionError("SVN URL %r does not start with root %r" %
                                 (self.svn_url, self.svn_root_url))

        self._branch_path = urlutils.unquote(
            self.svn_url[len(self.svn_root_url):])