Exemplo n.º 1
0
    def transformFallbackLocation(self, branch, url):
        """See `BranchOpenPolicy.transformFallbackLocation`.

        Here we return the URL that would be used anyway and optionally check
        it.
        """
        return urlutils.join(branch.base, url), self.check
Exemplo n.º 2
0
    def transformFallbackLocation(self, branch, url):
        """See `BranchOpenPolicy.transformFallbackLocation`.

        For mirrored branches, we stack on whatever the remote branch claims
        to stack on, but this URL still needs to be checked.
        """
        return urlutils.join(branch.base, url), True
Exemplo n.º 3
0
    def rewriteLine(self, resource_location):
        """Rewrite 'resource_location' to a more concrete location.

        We use the 'translatePath' BranchFileSystemClient method.  There are
        three cases:

         (1) The request is for something within the .bzr directory of a
             branch.

             In this case we rewrite the request to the location from which
             branches are served by ID.

         (2) The request is for something within a branch, but not the .bzr
             directory.

             In this case, we hand the request off to codebrowse.

         (3) The branch is not found.  Two sub-cases: the request is for a
             product control directory or the we don't know how to translate
             the path.

             In both these cases we return 'NULL' which indicates to Apache
             that we don't know how to rewrite the request (and so it should
             go on to generate a 404 response).

        Other errors are allowed to propagate, on the assumption that the
        caller will catch and log them.
        """
        # Codebrowse generates references to its images and stylesheets
        # starting with "/static", so pass them on unthinkingly.
        T = time.time()
        # Tell the webapp adapter that we are in a request, so that DB
        # statement timeouts will be applied.
        set_request_started()
        try:
            cached = None
            if resource_location.startswith('/static/'):
                r = self._codebrowse_url(resource_location)
                cached = 'N/A'
            else:
                branch_id, trailing, cached = self._getBranchIdAndTrailingPath(
                    resource_location)
                if branch_id is None:
                    if resource_location.startswith('/' +
                                                    BRANCH_ID_ALIAS_PREFIX):
                        r = 'NULL'
                    else:
                        r = self._codebrowse_url(resource_location)
                else:
                    if trailing.startswith('/.bzr'):
                        r = urlutils.join(
                            config.codehosting.internal_branch_by_id_root,
                            branch_id_to_path(branch_id), trailing[1:])
                    else:
                        r = self._codebrowse_url(resource_location)
        finally:
            clear_request_started()
        self.logger.info("%r -> %r (%fs, cache: %s)", resource_location, r,
                         time.time() - T, cached)
        return r
Exemplo n.º 4
0
def list_branches(repo):
    trans = repo.bzrdir.root_transport
    dirs_to_check = ['.']
    branches = []
    while len(dirs_to_check) > 0:
        filename = dirs_to_check.pop(0)
        if stat.S_ISDIR(trans.stat(filename).st_mode):
            # is this a branch inside the given repository?
            try:
                br_dir = BzrDir.open(trans.abspath(filename))
                branch = br_dir.open_branch()
            except errors.NotBranchError:
                branch = None

            # if we have a branch, add it to the result set, provided
            # that it uses the same repository.
            if branch is not None:
                # if the branch uses a different repository, then
                # don't include it.
                if (branch.repository.bzrdir.root_transport.base !=
                        trans.base):
                    continue
                # XXX: hack to make sure the branch is using the same
                # repository instance, for locking purposes
                branch.repository = repo
                branches.append(branch)

            # extend the list of dirs to check.
            dirs_to_check.extend([
                urlutils.join(filename, name)
                for name in trans.list_dir(filename) if name != '.bzr'
            ])
    return branches
 def test_multi_stack(self):
     """base + stacked + stacked-on-stacked"""
     base_tree, stacked_tree = self.make_stacked_target()
     self.build_tree(['stacked/f3.txt'])
     stacked_tree.add(['f3.txt'], ['f3.txt-id'])
     stacked_key = ('stacked-rev-id', )
     stacked_tree.commit('add f3', rev_id=stacked_key[0])
     stacked_only_repo = self.get_only_repo(stacked_tree)
     self.assertPresent([self.r2_key], stacked_only_repo.inventories,
                        [self.r1_key, self.r2_key])
     # This ensures we get a Remote URL, rather than a local one.
     stacked2_url = urlutils.join(base_tree.branch.base, '../stacked2')
     stacked2_bzrdir = stacked_tree.bzrdir.sprout(
         stacked2_url, revision_id=self.r1_key[0], stacked=True)
     if isinstance(stacked2_bzrdir, remote.RemoteBzrDir):
         stacked2_branch = stacked2_bzrdir.open_branch()
         stacked2_tree = stacked2_branch.create_checkout('stacked2',
                                                         lightweight=True)
     else:
         stacked2_tree = stacked2_bzrdir.open_workingtree()
     # stacked2 is stacked on stacked, but its content is rev1, so
     # it needs to pull the basis information from a fallback-of-fallback.
     self.build_tree(['stacked2/f3.txt'])
     stacked2_only_repo = self.get_only_repo(stacked2_tree)
     self.assertPresent([], stacked2_only_repo.inventories,
                        [self.r1_key, self.r2_key])
     stacked2_tree.add(['f3.txt'], ['f3.txt-id'])
     stacked2_tree.commit('add f3', rev_id='stacked2-rev-id')
     # We added data to this read-locked repo, so refresh it
     stacked2_only_repo.refresh_data()
     self.assertPresent([self.r1_key], stacked2_only_repo.inventories,
                        [self.r1_key, self.r2_key])
    def _download_in_cache(self, source_url, name, force=False):
        """Download ``name`` from ``source_url`` in ``vm.download_cache``.

        :param source_url: The url where the file to download is located

        :param name: The name of the file to download (also used as the name
            for the downloaded file).

        :param force: Remove the file from the cache if present.

        :return: False if the file is in the download cache, True if a download
            occurred.
        """
        source = urlutils.join(source_url, name)
        download_dir = self.conf.get('vm.download_cache')
        if not os.path.exists(download_dir):
            raise ConfigValueError('vm.download_cache', download_dir)
        target = os.path.join(download_dir, name)
        # FIXME: By default the download dir may be under root control, but if
        # a user chose to use a different one under his own control, it would
        # be nice to not require sudo usage. -- vila 2013-02-06
        if force:
            run_subprocess(['sudo', 'rm', '-f', target])
        if not os.path.exists(target):
            # FIXME: We do ask for a progress bar but it's not displayed
            # (run_subprocess capture both stdout and stderr) ! At least while
            # used interactively, it should. -- vila 2013-02-06
            run_subprocess(
                ['sudo', 'wget', '--progress=dot:mega', '-O', target, source])
            return True
        else:
            return False
    def _download_in_cache(self, source_url, name, force=False):
        """Download ``name`` from ``source_url`` in ``vm.download_cache``.

        :param source_url: The url where the file to download is located

        :param name: The name of the file to download (also used as the name
            for the downloaded file).

        :param force: Remove the file from the cache if present.

        :return: False if the file is in the download cache, True if a download
            occurred.
        """
        source = urlutils.join(source_url, name)
        download_dir = self.conf.get('vm.download_cache')
        if not os.path.exists(download_dir):
            raise ConfigValueError('vm.download_cache', download_dir)
        target = os.path.join(download_dir, name)
        # FIXME: By default the download dir may be under root control, but if
        # a user chose to use a different one under his own control, it would
        # be nice to not require sudo usage. -- vila 2013-02-06
        if force:
            run_subprocess(['sudo', 'rm', '-f', target])
        if not os.path.exists(target):
            # FIXME: We do ask for a progress bar but it's not displayed
            # (run_subprocess capture both stdout and stderr) ! At least while
            # used interactively, it should. -- vila 2013-02-06
            run_subprocess(['sudo', 'wget', '--progress=dot:mega','-O',
                            target, source])
            return True
        else:
            return False
Exemplo n.º 8
0
    def transform_fallback_location(self, branch, url):
        """See `BranchOpenPolicy.transform_fallback_location`.

        Here we return the URL that would be used anyway and optionally check
        it.
        """
        return urlutils.join(branch.base, url), self.check
Exemplo n.º 9
0
 def _relurljoin(base, relative):
     if relative.startswith('//'):
         # urlutils.join not supports relative urls start with '//'
         scheme = base.partition('://')
         return scheme[0] + ':' + relative
     else:
         return join(base, relative)
Exemplo n.º 10
0
def list_branches(repo):
    trans = repo.bzrdir.root_transport
    dirs_to_check = ['.']
    branches = []
    while len(dirs_to_check) > 0:
        filename = dirs_to_check.pop(0)
        if stat.S_ISDIR(trans.stat(filename).st_mode):
            # is this a branch inside the given repository?
            try:
                br_dir = BzrDir.open(trans.abspath(filename))
                branch = br_dir.open_branch()
            except errors.NotBranchError:
                branch = None

            # if we have a branch, add it to the result set, provided
            # that it uses the same repository.
            if branch is not None:
                # if the branch uses a different repository, then
                # don't include it.
                if (branch.repository.bzrdir.root_transport.base !=
                    trans.base):
                    continue
                # XXX: hack to make sure the branch is using the same
                # repository instance, for locking purposes
                branch.repository = repo
                branches.append(branch)

            # extend the list of dirs to check.
            dirs_to_check.extend([urlutils.join(filename, name)
                                  for name in trans.list_dir(filename)
                                  if name != '.bzr'])
    return branches
Exemplo n.º 11
0
def import_git_tree(repo, mapping, path, tree, inv, parent_invs, lookup_object):
    """Import a git tree object into a bzr repository.

    :param repo: A Bzr repository object
    :param path: Path in the tree
    :param tree: A git tree object
    :param inv: Inventory object
    """
    file_id = mapping.generate_file_id(path)
    text_revision = inv.revision_id
    repo.texts.add_lines((file_id, text_revision),
        [(file_id, p[file_id].revision) for p in parent_invs if file_id in p],
        [])
    ie = inv.add_path(path, "directory", file_id)
    ie.revision = text_revision
    for mode, name, hexsha in tree.entries():
        entry_kind = (mode & 0700000) / 0100000
        basename = name.decode("utf-8")
        if path == "":
            child_path = name
        else:
            child_path = urlutils.join(path, name)
        if entry_kind == 0:
            tree = lookup_object(hexsha)
            import_git_tree(repo, mapping, child_path, tree, inv, parent_invs, lookup_object)
        elif entry_kind == 1:
            blob = lookup_object(hexsha)
            fs_mode = mode & 0777
            import_git_blob(repo, mapping, child_path, blob, inv, parent_invs, bool(fs_mode & 0111))
        else:
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
Exemplo n.º 12
0
 def test_multi_stack(self):
     """base + stacked + stacked-on-stacked"""
     base_tree, stacked_tree = self.make_stacked_target()
     self.build_tree(['stacked/f3.txt'])
     stacked_tree.add(['f3.txt'], ['f3.txt-id'])
     stacked_key = ('stacked-rev-id',)
     stacked_tree.commit('add f3', rev_id=stacked_key[0])
     stacked_only_repo = self.get_only_repo(stacked_tree)
     self.assertPresent([self.r2_key], stacked_only_repo.inventories,
                        [self.r1_key, self.r2_key])
     # This ensures we get a Remote URL, rather than a local one.
     stacked2_url = urlutils.join(base_tree.branch.base, '../stacked2')
     stacked2_bzrdir = stacked_tree.bzrdir.sprout(stacked2_url,
                         revision_id=self.r1_key[0],
                         stacked=True)
     if isinstance(stacked2_bzrdir, remote.RemoteBzrDir):
         stacked2_branch = stacked2_bzrdir.open_branch()
         stacked2_tree = stacked2_branch.create_checkout('stacked2',
             lightweight=True)
     else:
         stacked2_tree = stacked2_bzrdir.open_workingtree()
     # stacked2 is stacked on stacked, but its content is rev1, so
     # it needs to pull the basis information from a fallback-of-fallback.
     self.build_tree(['stacked2/f3.txt'])
     stacked2_only_repo = self.get_only_repo(stacked2_tree)
     self.assertPresent([], stacked2_only_repo.inventories,
                        [self.r1_key, self.r2_key])
     stacked2_tree.add(['f3.txt'], ['f3.txt-id'])
     stacked2_tree.commit('add f3', rev_id='stacked2-rev-id')
     # We added data to this read-locked repo, so refresh it
     stacked2_only_repo.refresh_data()
     self.assertPresent([self.r1_key], stacked2_only_repo.inventories,
                        [self.r1_key, self.r2_key])
Exemplo n.º 13
0
    def transform_fallback_location(self, branch, url):
        """See `BranchOpenPolicy.transform_fallback_location`.

        This class is not used for testing our smarter stacking features so we
        just do the simplest thing: return the URL that would be used anyway
        and don't check it.
        """
        return urlutils.join(branch.base, url), False
Exemplo n.º 14
0
 def _remote_path(self, relpath):
     """After connecting, HTTP Transport only deals in relative URLs."""
     # Adjust the relpath based on which URL this smart transport is
     # connected to.
     http_base = urlutils.normalize_url(self.get_smart_medium().base)
     url = urlutils.join(self.base[len('bzr+'):], relpath)
     url = urlutils.normalize_url(url)
     return urlutils.relative_url(http_base, url)
Exemplo n.º 15
0
    def clone(self, offset=None):
        """See Transport.clone()."""
        if offset is None:
            newurl = self.base
        else:
            newurl = urlutils.join(self.base, offset)

        return GitSmartTransport(newurl, self._client)
Exemplo n.º 16
0
 def _remote_path(self, relpath):
     """After connecting, HTTP Transport only deals in relative URLs."""
     # Adjust the relpath based on which URL this smart transport is
     # connected to.
     http_base = urlutils.normalize_url(self.get_smart_medium().base)
     url = urlutils.join(self.base[len('bzr+'):], relpath)
     url = urlutils.normalize_url(url)
     return urlutils.relative_url(http_base, url)
Exemplo n.º 17
0
    def clone(self, offset=None):
        """See Transport.clone()."""
        if offset is None:
            newurl = self.base
        else:
            newurl = urlutils.join(self.base, offset)

        return GitSmartTransport(newurl, self._client)
Exemplo n.º 18
0
 def test_codebrowse_url_for_default(self):
     [ref] = self.factory.makeGitRefs(paths=["refs/heads/name"])
     with person_logged_in(ref.repository.target.owner):
         getUtility(IGitRepositorySet).setDefaultRepository(
             ref.repository.target, ref.repository)
     expected_url = "%s?h=name" % urlutils.join(
         config.codehosting.git_browse_root, ref.repository.shortened_path)
     self.assertEqual(expected_url, ref.getCodebrowseUrl())
Exemplo n.º 19
0
    def transformFallbackLocation(self, branch, url):
        """See `BranchOpenPolicy.transformFallbackLocation`.

        This class is not used for testing our smarter stacking features so we
        just do the simplest thing: return the URL that would be used anyway
        and don't check it.
        """
        return urlutils.join(branch.base, url), False
Exemplo n.º 20
0
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
        """Get the Launchpad web URL for the given branch URL.

        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
            Launchpad branch URL.
        :return: The URL of the branch on Launchpad.
        """
        path = self._guess_branch_path(branch_url, _request_factory)
        return urlutils.join('https://code.%s' % self.domain, path)
Exemplo n.º 21
0
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
        """Get the Launchpad web URL for the given branch URL.

        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
            Launchpad branch URL.
        :return: The URL of the branch on Launchpad.
        """
        path = self._guess_branch_path(branch_url, _request_factory)
        return urlutils.join('https://code.%s' % self.domain, path)
Exemplo n.º 22
0
 def rename(self, rel_from, rel_to):
     """See Transport.rename().
     """
     try:
         if self._decorated.has(rel_to):
             rel_to = urlutils.join(rel_to, urlutils.basename(rel_from))
         self._decorated.rename(rel_from, rel_to)
     except (errors.DirectoryNotEmpty, errors.FileExists), e:
         # absorb the error
         return
Exemplo n.º 23
0
 def rename(self, rel_from, rel_to):
     """See Transport.rename().
     """
     try:
         if self._decorated.has(rel_to):
             rel_to = urlutils.join(rel_to, urlutils.basename(rel_from))
         self._decorated.rename(rel_from, rel_to)
     except (errors.DirectoryNotEmpty, errors.FileExists), e:
         # absorb the error
         return
Exemplo n.º 24
0
 def test_clone_with_relative_offset(self):
     # FatLocalTransport.clone with an offset path returns a new instance
     # of FatLocalTransport with a base URL equal to the offset path
     # relative to the old base.
     transport = self.transport.clone("foo")
     self.assertIsNot(self.transport, transport)
     self.assertEqual(
         urlutils.join(self.transport.base, "foo").rstrip('/'),
         transport.base.rstrip('/'))
     self.assertIsInstance(transport, FatLocalTransport)
Exemplo n.º 25
0
 def test_clone_with_relative_offset(self):
     # FatLocalTransport.clone with an offset path returns a new instance
     # of FatLocalTransport with a base URL equal to the offset path
     # relative to the old base.
     transport = self.transport.clone("foo")
     self.assertIsNot(self.transport, transport)
     self.assertEqual(
         urlutils.join(self.transport.base, "foo").rstrip('/'),
         transport.base.rstrip('/'))
     self.assertIsInstance(transport, FatLocalTransport)
Exemplo n.º 26
0
    def test_get_with_supported_tag(self):
        """If asked for a valid tag, return a tracker instance that can map bug
        IDs to <base_url>/<bug_area> + <bug_id>."""
        bugtracker.tracker_registry.register('some', self.tracker)
        self.addCleanup(lambda: bugtracker.tracker_registry.remove('some'))

        branch = self.make_branch('some_branch')
        config = branch.get_config()
        config.set_user_option('some_twisted_url', self.url)
        tracker = self.tracker.get('twisted', branch)
        self.assertEqual(
            urlutils.join(self.url, 'ticket/') + '1234',
            tracker.get_bug_url('1234'))
Exemplo n.º 27
0
    def test_get_with_supported_tag(self):
        """If asked for a valid tag, return a tracker instance that can map bug
        IDs to <base_url>/<bug_area> + <bug_id>."""
        bugtracker.tracker_registry.register('some', self.tracker)
        self.addCleanup(bugtracker.tracker_registry.remove, 'some')

        branch = self.make_branch('some_branch')
        config = branch.get_config()
        config.set_user_option('some_twisted_url', self.url)
        tracker = self.tracker.get('twisted', branch)
        self.assertEqual(
            urlutils.join(self.url, 'ticket/') + '1234',
            tracker.get_bug_url('1234'))
Exemplo n.º 28
0
    def test_set_get_parent(self):
        """Set, re-get and reset the parent"""
        b = self.make_branch('subdir')
        url = 'http://example.com/bzr/bzr.dev'
        b.set_parent(url)
        self.assertEqual(url, b.get_parent())
        self.assertEqual(url, b._get_parent_location())

        b.set_parent(None)
        self.assertEqual(None, b.get_parent())

        b.set_parent('../other_branch')

        expected_parent = urlutils.join(self.get_url('subdir'),
                                        '../other_branch')
        self.assertEqual(expected_parent, b.get_parent())
        path = urlutils.join(self.get_url('subdir'), '../yanb')
        b.set_parent(path)
        self.assertEqual('../yanb', b._get_parent_location())
        self.assertEqual(path, b.get_parent())


        self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
        b.set_parent(urlutils.escape(u'\xb5'))
        self.assertEqual('%C2%B5', b._get_parent_location())

        self.assertEqual(b.base + '%C2%B5', b.get_parent())

        # Handle the case for older style absolute local paths
        if sys.platform == 'win32':
            # TODO: jam 20060515 Do we want to special case Windows local
            #       paths as well? Nobody has complained about it.
            pass
        else:
            b.lock_write()
            b._set_parent_location('/local/abs/path')
            b.unlock()
            self.assertEqual('file:///local/abs/path', b.get_parent())
Exemplo n.º 29
0
    def getStackedOnURLForDestinationBranch(self, source_branch,
                                            destination_url):
        """Return the stacked on URL for the destination branch.

        Mirrored branches are stacked on the default stacked-on branch of
        their product, except when we're mirroring the default stacked-on
        branch itself.
        """
        if self.stacked_on_url is None:
            return None
        stacked_on_url = urlutils.join(destination_url, self.stacked_on_url)
        if destination_url == stacked_on_url:
            return None
        return self.stacked_on_url
Exemplo n.º 30
0
    def test_set_get_parent(self):
        """Set, re-get and reset the parent"""
        b = self.make_branch('subdir')
        url = 'http://example.com/bzr/bzr.dev'
        b.set_parent(url)
        self.assertEqual(url, b.get_parent())
        self.assertEqual(url, b._get_parent_location())

        b.set_parent(None)
        self.assertEqual(None, b.get_parent())

        b.set_parent('../other_branch')

        expected_parent = urlutils.join(self.get_url('subdir'),
                                        '../other_branch')
        self.assertEqual(expected_parent, b.get_parent())
        path = urlutils.join(self.get_url('subdir'), '../yanb')
        b.set_parent(path)
        self.assertEqual('../yanb', b._get_parent_location())
        self.assertEqual(path, b.get_parent())

        self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
        b.set_parent(urlutils.escape(u'\xb5'))
        self.assertEqual('%C2%B5', b._get_parent_location())

        self.assertEqual(b.base + '%C2%B5', b.get_parent())

        # Handle the case for older style absolute local paths
        if sys.platform == 'win32':
            # TODO: jam 20060515 Do we want to special case Windows local
            #       paths as well? Nobody has complained about it.
            pass
        else:
            b.lock_write()
            b._set_parent_location('/local/abs/path')
            b.unlock()
            self.assertEqual('file:///local/abs/path', b.get_parent())
Exemplo n.º 31
0
    def run(self, from_location, to_location=None, lightweight=False, **kw):
        if lightweight:
            import errno
            import os
            from bzrlib.branch import Branch
            from bzrlib.errors import BzrError
            from bzrlib.urlutils import basename, dirname, join
            from bzrlib.workingtree import WorkingTree

            br_from = Branch.open(from_location)
            repo = br_from.repository
            if not repo.is_shared():
                raise BzrError('branch --lightweight supported '
                               'only for shared repository')
            wt_from = WorkingTree.open(from_location)
            working_path = wt_from.bzrdir.root_transport.base
            from_branch_path = br_from.bzrdir.root_transport.base
            if working_path == from_branch_path:
                raise BzrError('source branch is not lightweight checkout')
            if to_location is None:
                raise BzrError('you should specify name for new branch')
            from_basename = basename(from_branch_path)
            to_basename = basename(to_location)
            if from_basename == to_basename:
                raise BzrError('basename of source and destination is equal')
            to_branch_path = join(dirname(from_branch_path), to_basename)
            # make branch
            print >> self.outf, 'Create branch: %s => %s' % (from_branch_path,
                                                             to_branch_path)
            builtins.cmd_branch.run(self, from_branch_path, to_branch_path,
                                    **kw)
            # make lightweight chekout
            source = Branch.open(to_branch_path)
            revision_id = source.last_revision()
            try:
                os.mkdir(to_location)
            except OSError, e:
                if e.errno == errno.EEXIST:
                    raise errors.BzrCommandError(
                        'Target directory "%s" already'
                        ' exists.' % to_location)
                if e.errno == errno.ENOENT:
                    raise errors.BzrCommandError(
                        'Parent of "%s" does not exist.' % to_location)
                else:
                    raise
            source.create_checkout(to_location, revision_id, lightweight)
 def make_stacked_target(self):
     base_tree = self.make_branch_and_tree('base')
     self.build_tree(['base/f1.txt'])
     base_tree.add(['f1.txt'], ['f1.txt-id'])
     base_tree.commit('initial', rev_id=self.r1_key[0])
     self.build_tree(['base/f2.txt'])
     base_tree.add(['f2.txt'], ['f2.txt-id'])
     base_tree.commit('base adds f2', rev_id=self.r2_key[0])
     stacked_url = urlutils.join(base_tree.branch.base, '../stacked')
     stacked_bzrdir = base_tree.bzrdir.sprout(stacked_url, stacked=True)
     if isinstance(stacked_bzrdir, remote.RemoteBzrDir):
         stacked_branch = stacked_bzrdir.open_branch()
         stacked_tree = stacked_branch.create_checkout('stacked',
                                                       lightweight=True)
     else:
         stacked_tree = stacked_bzrdir.open_workingtree()
     return base_tree, stacked_tree
Exemplo n.º 33
0
 def make_stacked_target(self):
     base_tree = self.make_branch_and_tree('base')
     self.build_tree(['base/f1.txt'])
     base_tree.add(['f1.txt'], ['f1.txt-id'])
     base_tree.commit('initial', rev_id=self.r1_key[0])
     self.build_tree(['base/f2.txt'])
     base_tree.add(['f2.txt'], ['f2.txt-id'])
     base_tree.commit('base adds f2', rev_id=self.r2_key[0])
     stacked_url = urlutils.join(base_tree.branch.base, '../stacked')
     stacked_bzrdir = base_tree.bzrdir.sprout(stacked_url,
         stacked=True)
     if isinstance(stacked_bzrdir, remote.RemoteBzrDir):
         stacked_branch = stacked_bzrdir.open_branch()
         stacked_tree = stacked_branch.create_checkout('stacked',
             lightweight=True)
     else:
         stacked_tree = stacked_bzrdir.open_workingtree()
     return base_tree, stacked_tree
Exemplo n.º 34
0
    def __init__(self, bzrdir, repo, branch):
        self.basedir = bzrdir.transport.base
        self.bzrdir = bzrdir
        self.repository = repo
        self._branch = branch
        self._transport = bzrdir.transport

        self.controldir = urlutils.join(self.repository._git.path, 'bzr')

        try:
            os.makedirs(self.controldir)
            os.makedirs(os.path.join(self.controldir, 'lock'))
        except OSError:
            pass

        self._control_files = lockable_files.LockableFiles(
            transport.get_transport(self.controldir), 'lock', lockdir.LockDir)

        self._format = GitWorkingTreeFormat()

        self.index = Index(
            os.path.join(self.repository._git.controldir(), "index"))
Exemplo n.º 35
0
 def test_local_by_url(self):
     # It's possible (though not encouraged) to retrieve files from
     # self-hosted repositories by URL.
     [ref] = self.factory.makeGitRefs()
     hosting_fixture = self.useFixture(GitHostingFixture(blob=b"foo"))
     https_ref = self.factory.makeGitRefRemote(
         repository_url=ref.repository.git_https_url, path=ref.path)
     anon_ref = self.factory.makeGitRefRemote(repository_url=urlutils.join(
         config.codehosting.git_anon_root, ref.repository.shortened_path),
                                              path=ref.path)
     self.assertEqual(b"foo", https_ref.getBlob("dir/file"))
     self.assertEqual(b"foo", anon_ref.getBlob("dir/file"))
     internal_path = ref.repository.getInternalPath()
     expected_calls = [
         ((internal_path, "dir/file"), {
             "rev": ref.path
         }),
         ((internal_path, "dir/file"), {
             "rev": ref.path
         }),
     ]
     self.assertEqual(expected_calls, hosting_fixture.getBlob.calls)
Exemplo n.º 36
0
    def __init__(self, bzrdir, repo, branch):
        self.basedir = bzrdir.transport.base
        self.bzrdir = bzrdir
        self.repository = repo
        self._branch = branch
        self._transport = bzrdir.transport

        self.controldir = urlutils.join(self.repository._git.path, 'bzr')

        try:
            os.makedirs(self.controldir)
            os.makedirs(os.path.join(self.controldir, 'lock'))
        except OSError:
            pass

        self._control_files = lockable_files.LockableFiles(
            transport.get_transport(self.controldir), 'lock', lockdir.LockDir)

        self._format = GitWorkingTreeFormat()

        self.index = Index(os.path.join(self.repository._git.controldir(), 
            "index"))
Exemplo n.º 37
0
 def _build_inventory(self, tree_id, ie, path):
     assert isinstance(path, str)
     tree = self._repository._git.tree(tree_id)
     for mode, name, hexsha in tree.entries():
         basename = name.decode("utf-8")
         if path == "":
             child_path = name
         else:
             child_path = urlutils.join(path, name)
         file_id = self.mapping.generate_file_id(child_path)
         entry_kind = (mode & 0700000) / 0100000
         if entry_kind == 0:
             child_ie = inventory.InventoryDirectory(
                 file_id, basename, ie.file_id)
         elif entry_kind == 1:
             file_kind = (mode & 070000) / 010000
             b = self._repository._git.get_blob(hexsha)
             if file_kind == 0:
                 child_ie = inventory.InventoryFile(file_id, basename,
                                                    ie.file_id)
                 child_ie.text_sha1 = osutils.sha_string(b.data)
             elif file_kind == 2:
                 child_ie = inventory.InventoryLink(file_id, basename,
                                                    ie.file_id)
                 child_ie.text_sha1 = osutils.sha_string("")
             else:
                 raise AssertionError("Unknown file kind, perms=%o." %
                                      (mode, ))
             child_ie.text_id = b.id
             child_ie.text_size = len(b.data)
         else:
             raise AssertionError("Unknown blob kind, perms=%r." % (mode, ))
         fs_mode = mode & 0777
         child_ie.executable = bool(fs_mode & 0111)
         child_ie.revision = self.revision_id
         self._inventory.add(child_ie)
         if entry_kind == 0:
             self._build_inventory(hexsha, child_ie, child_path)
Exemplo n.º 38
0
    def _handle_lock_contention(self, other_holder):
        """A lock we want to take is held by someone else.

        This function can: tell the user about it; possibly detect that it's
        safe or appropriate to steal the lock, or just raise an exception.

        If this function returns (without raising an exception) the lock will
        be attempted again.

        :param other_holder: A LockHeldInfo for the current holder; note that
            it might be None if the lock can be seen to be held but the info
            can't be read.
        """
        if (other_holder is not None):
            if other_holder.is_lock_holder_known_dead():
                if self.get_config().get('locks.steal_dead'):
                    ui.ui_factory.show_user_warning(
                        'locks_steal_dead',
                        lock_url=urlutils.join(self.transport.base, self.path),
                        other_holder_info=unicode(other_holder))
                    self.force_break(other_holder)
                    self._trace("stole lock from dead holder")
                    return
        raise LockContention(self)
Exemplo n.º 39
0
    def _handle_lock_contention(self, other_holder):
        """A lock we want to take is held by someone else.

        This function can: tell the user about it; possibly detect that it's
        safe or appropriate to steal the lock, or just raise an exception.

        If this function returns (without raising an exception) the lock will
        be attempted again.

        :param other_holder: A LockHeldInfo for the current holder; note that
            it might be None if the lock can be seen to be held but the info
            can't be read.
        """
        if (other_holder is not None):
            if other_holder.is_lock_holder_known_dead():
                if self.get_config().get('locks.steal_dead'):
                    ui.ui_factory.show_user_warning(
                        'locks_steal_dead',
                        lock_url=urlutils.join(self.transport.base, self.path),
                        other_holder_info=unicode(other_holder))
                    self.force_break(other_holder)
                    self._trace("stole lock from dead holder")
                    return
        raise LockContention(self)
Exemplo n.º 40
0
 def _build_inventory(self, tree_id, ie, path):
     assert isinstance(path, str)
     tree = self._repository._git.tree(tree_id)
     for mode, name, hexsha in tree.entries():
         basename = name.decode("utf-8")
         if path == "":
             child_path = name
         else:
             child_path = urlutils.join(path, name)
         file_id = self.mapping.generate_file_id(child_path)
         entry_kind = (mode & 0700000) / 0100000
         if entry_kind == 0:
             child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)
         elif entry_kind == 1:
             file_kind = (mode & 070000) / 010000
             b = self._repository._git.get_blob(hexsha)
             if file_kind == 0:
                 child_ie = inventory.InventoryFile(file_id, basename, ie.file_id)
                 child_ie.text_sha1 = osutils.sha_string(b.data)
             elif file_kind == 2:
                 child_ie = inventory.InventoryLink(file_id, basename, ie.file_id)
                 child_ie.text_sha1 = osutils.sha_string("")
             else:
                 raise AssertionError(
                     "Unknown file kind, perms=%o." % (mode,))
             child_ie.text_id = b.id
             child_ie.text_size = len(b.data)
         else:
             raise AssertionError(
                 "Unknown blob kind, perms=%r." % (mode,))
         fs_mode = mode & 0777
         child_ie.executable = bool(fs_mode & 0111)
         child_ie.revision = self.revision_id
         self._inventory.add(child_ie)
         if entry_kind == 0:
             self._build_inventory(hexsha, child_ie, child_path)
Exemplo n.º 41
0
 def test_extra_path(self):
     self.assertEqual(urlutils.join(self.branch.base, 'arg'),
                      directories.dereference(':this/arg'))
Exemplo n.º 42
0
 def clone(self, relpath=None):
     if relpath is None:
         return self.__class__(self.server, self.base)
     else:
         return self.__class__(self.server,
                               urlutils.join(self.base, relpath))
Exemplo n.º 43
0
 def abspath(self, relpath):
     return urlutils.join(self.base, relpath)
Exemplo n.º 44
0
 def transformFallbackLocation(self, branch, url):
     return urlutils.join(branch.base, url), True
Exemplo n.º 45
0
 def _relpath_to_url(self, relpath):
     full_url = urlutils.join(self.url, relpath)
     if isinstance(full_url, unicode):
         raise errors.InvalidURL(full_url)
     return full_url
Exemplo n.º 46
0
 def clone(self, relpath=None):
     if relpath is None:
         return self.__class__(self.server, self.base)
     else:
         return self.__class__(
             self.server, urlutils.join(self.base, relpath))
Exemplo n.º 47
0
    def rewriteLine(self, resource_location):
        """Rewrite 'resource_location' to a more concrete location.

        We use the 'translatePath' BranchFileSystemClient method.  There are
        three cases:

         (1) The request is for something within the .bzr directory of a
             branch.

             In this case we rewrite the request to the location from which
             branches are served by ID.

         (2) The request is for something within a branch, but not the .bzr
             directory.

             In this case, we hand the request off to codebrowse.

         (3) The branch is not found.  Two sub-cases: the request is for a
             product control directory or the we don't know how to translate
             the path.

             In both these cases we return 'NULL' which indicates to Apache
             that we don't know how to rewrite the request (and so it should
             go on to generate a 404 response).

        Other errors are allowed to propagate, on the assumption that the
        caller will catch and log them.
        """
        # Codebrowse generates references to its images and stylesheets
        # starting with "/static", so pass them on unthinkingly.
        T = time.time()
        # Tell the webapp adapter that we are in a request, so that DB
        # statement timeouts will be applied.
        set_request_started()
        try:
            cached = None
            if resource_location.startswith('/static/'):
                r = self._codebrowse_url(resource_location)
                cached = 'N/A'
            else:
                branch_id, trailing, cached = self._getBranchIdAndTrailingPath(
                    resource_location)
                if branch_id is None:
                    if resource_location.startswith(
                            '/' + BRANCH_ID_ALIAS_PREFIX):
                        r = 'NULL'
                    else:
                        r = self._codebrowse_url(resource_location)
                else:
                    if trailing.startswith('/.bzr'):
                        r = urlutils.join(
                            config.codehosting.internal_branch_by_id_root,
                            branch_id_to_path(branch_id), trailing[1:])
                    else:
                        r = self._codebrowse_url(resource_location)
        finally:
            clear_request_started()
        self.logger.info(
            "%r -> %r (%fs, cache: %s)",
            resource_location, r, time.time() - T, cached)
        return r
Exemplo n.º 48
0
 def _codebrowse_url(self, path):
     return urlutils.join(
         config.codehosting.internal_codebrowse_root,
         path)
Exemplo n.º 49
0
 def abspath(self, relpath):
     return urlutils.join(self.base, relpath)
Exemplo n.º 50
0
 def test(expected, *args):
     joined = urlutils.join(*args)
     self.assertEqual(expected, joined)
Exemplo n.º 51
0
 def _codebrowse_url(self, path):
     return urlutils.join(config.codehosting.internal_codebrowse_root, path)
Exemplo n.º 52
0
 def test_extra_path(self):
     self.assertEqual(urlutils.join(self.branch.base, 'arg'),
                      directories.dereference(':this/arg'))
Exemplo n.º 53
0
 def transform_fallback_location(self, branch, url):
     return urlutils.join(branch.base, url), True
Exemplo n.º 54
0
Arquivo: pull.py Projeto: biji/qbzr
 def _build_generic_push_suggestion(self, master_url):
     master_parent = urlutils.dirname(master_url)
     branch_name = urlutils.basename(self.branch.base)
     return urlutils.join(master_parent, branch_name)
Exemplo n.º 55
0
 def _relpath_to_url(self, relpath):
     full_url = urlutils.join(self.url, relpath)
     if isinstance(full_url, unicode):
         raise errors.InvalidURL(full_url)
     return full_url