0
  B   	ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þYiÙnQðÈ0„¤óË„-2ïÊ_ŠI|¥�+Wé3ž¯ÀÉ 4}    	# Copyright (C) 2007, 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Utility for create branches with particular contents."""

from . import (
    controldir,
    commit,
    errors,
    revision,
    )


class BranchBuilder:
    r"""A BranchBuilder aids creating Branches with particular shapes.

    The expected way to use BranchBuilder is to construct a
    BranchBuilder on the transport you want your branch on, and then call
    appropriate build_ methods on it to get the shape of history you want.

    This is meant as a helper for the test suite, not as a general class for
    real data.

    For instance:

    >>> from breezy.transport.memory import MemoryTransport
    >>> builder = BranchBuilder(MemoryTransport("memory:///"))
    >>> builder.start_series()
    >>> builder.build_snapshot(None, [
    ...     ('add', ('', b'root-id', 'directory', '')),
    ...     ('add', ('filename', b'f-id', 'file', b'content\n'))],
    ...     revision_id=b'rev-id')
    b'rev-id'
    >>> builder.build_snapshot([b'rev-id'],
    ...     [('modify', ('filename', b'new-content\n'))],
    ...     revision_id=b'rev2-id')
    b'rev2-id'
    >>> builder.finish_series()
    >>> branch = builder.get_branch()

    :ivar _tree: This is a private member which is not meant to be modified by
        users of this class. While a 'series' is in progress, it should hold a
        MemoryTree with the contents of the last commit (ready to be modified
        by the next build_snapshot command) with a held write lock. Outside of
        a series in progress, it should be None.
    """

    def __init__(self, transport=None, format=None, branch=None):
        """Construct a BranchBuilder on transport.

        :param transport: The transport the branch should be created on.
            If the path of the transport does not exist but its parent does
            it will be created.
        :param format: Either a BzrDirFormat, or the name of a format in the
            controldir format registry for the branch to be built.
        :param branch: An already constructed branch to use.  This param is
            mutually exclusive with the transport and format params.
        """
        if branch is not None:
            if format is not None:
                raise AssertionError(
                    "branch and format kwargs are mutually exclusive")
            if transport is not None:
                raise AssertionError(
                    "branch and transport kwargs are mutually exclusive")
            self._branch = branch
        else:
            if not transport.has('.'):
                transport.mkdir('.')
            if format is None:
                format = 'default'
            if isinstance(format, str):
                format = controldir.format_registry.make_controldir(format)
            self._branch = controldir.ControlDir.create_branch_convenience(
                transport.base, format=format, force_new_tree=False)
        self._tree = None

    def build_commit(self, parent_ids=None, allow_leftmost_as_ghost=False,
                     **commit_kwargs):
        """Build a commit on the branch.

        This makes a commit with no real file content for when you only want
        to look at the revision graph structure.

        :param commit_kwargs: Arguments to pass through