예제 #1
0
    def _normalize_stacked_on_url(self, branch):
        """Normalize and return the stacked-on location of `branch`.

        In the common case, `branch` will either be unstacked or stacked on a
        relative path, in which case this is very easy: just return the
        location.

        If `branch` is stacked on the absolute URL of another Launchpad
        branch, we normalize this to a relative path (mutating the branch) and
        return the relative path.

        If `branch` is stacked on some other absolute URL we don't recognise,
        we just return that and rely on the `branchChanged` XML-RPC method
        recording a complaint in the appropriate place.
        """
        stacked_on_url = get_stacked_on_url(branch)
        if stacked_on_url is None:
            return None
        if "://" not in stacked_on_url:
            # Assume it's a relative path.
            return stacked_on_url
        uri = URI(stacked_on_url)
        if uri.scheme not in ["http", "bzr+ssh", "sftp"]:
            return stacked_on_url
        launchpad_domain = config.vhost.mainsite.hostname
        if not uri.underDomain(launchpad_domain):
            return stacked_on_url
        # We use TransportConfig directly because the branch
        # is still locked at this point!  We're effectively
        # 'borrowing' the lock that is being released.
        branch_config = TransportConfig(branch._transport, "branch.conf")
        branch_config.set_option(uri.path, "stacked_on_location")
        return uri.path
예제 #2
0
    def _normalize_stacked_on_url(self, branch):
        """Normalize and return the stacked-on location of `branch`.

        In the common case, `branch` will either be unstacked or stacked on a
        relative path, in which case this is very easy: just return the
        location.

        If `branch` is stacked on the absolute URL of another Launchpad
        branch, we normalize this to a relative path (mutating the branch) and
        return the relative path.

        If `branch` is stacked on some other absolute URL we don't recognise,
        we just return that and rely on the `branchChanged` XML-RPC method
        recording a complaint in the appropriate place.
        """
        stacked_on_url = get_stacked_on_url(branch)
        if stacked_on_url is None:
            return None
        if '://' not in stacked_on_url:
            # Assume it's a relative path.
            return stacked_on_url
        uri = URI(stacked_on_url)
        if uri.scheme not in ['http', 'bzr+ssh', 'sftp']:
            return stacked_on_url
        launchpad_domain = config.vhost.mainsite.hostname
        if not uri.underDomain(launchpad_domain):
            return stacked_on_url
        # We use TransportConfig directly because the branch
        # is still locked at this point!  We're effectively
        # 'borrowing' the lock that is being released.
        branch_config = TransportConfig(branch._transport, 'branch.conf')
        branch_config.set_option(uri.path, 'stacked_on_location')
        return uri.path
    def commit(self, commit_message, txn=None):
        """Commit to branch.

        :param commit_message: Message for branch's commit log.
        :param txn: Transaction to commit.  Can be helpful in avoiding
            long idle times in database transactions.  May be committed
            more than once.
        """
        assert self.is_open, "Committing closed DirectBranchCommit."
        assert self.is_locked, "Not locked at commit time."

        try:
            self._checkForRace()

            if txn:
                txn.commit()

            rev_id = self.revision_tree.get_revision_id()
            if rev_id == NULL_REVISION:
                if list(self.transform_preview.iter_changes()) == []:
                    return
            committer_id = self.getBzrCommitterID()
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL=committer_id):
                new_rev_id = self.transform_preview.commit(
                    self.bzrbranch, commit_message, self.merge_parents, committer=committer_id
                )
            IMasterObject(self.db_branch).branchChanged(
                get_stacked_on_url(self.bzrbranch),
                new_rev_id,
                self.db_branch.control_format,
                self.db_branch.branch_format,
                self.db_branch.repository_format,
            )

            if txn:
                txn.commit()

        finally:
            self.unlock()
            self.is_open = False
        return new_rev_id
    def commit(self, commit_message, txn=None):
        """Commit to branch.

        :param commit_message: Message for branch's commit log.
        :param txn: Transaction to commit.  Can be helpful in avoiding
            long idle times in database transactions.  May be committed
            more than once.
        """
        assert self.is_open, "Committing closed DirectBranchCommit."
        assert self.is_locked, "Not locked at commit time."

        try:
            self._checkForRace()

            if txn:
                txn.commit()

            rev_id = self.revision_tree.get_revision_id()
            if rev_id == NULL_REVISION:
                if list(self.transform_preview.iter_changes()) == []:
                    return
            committer_id = self.getBzrCommitterID()
            # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
            # required to generate the revision-id.
            with override_environ(BZR_EMAIL=committer_id):
                new_rev_id = self.transform_preview.commit(
                    self.bzrbranch, commit_message, self.merge_parents,
                    committer=committer_id)
            IMasterObject(self.db_branch).branchChanged(
                get_stacked_on_url(self.bzrbranch), new_rev_id,
                self.db_branch.control_format, self.db_branch.branch_format,
                self.db_branch.repository_format)

            if txn:
                txn.commit()

        finally:
            self.unlock()
            self.is_open = False
        return new_rev_id