b.b.BranchBuilder(object) : class documentation

Part of bzrlib.branchbuilder View In Hierarchy

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 bzrlib.transport.memory import MemoryTransport
>>> builder = BranchBuilder(MemoryTransport("memory:///"))
>>> builder.start_series()
>>> builder.build_snapshot('rev-id', None, [
...     ('add', ('', 'root-id', 'directory', '')),
...     ('add', ('filename', 'f-id', 'file', 'content\n'))])
'rev-id'
>>> builder.build_snapshot('rev2-id', ['rev-id'],
...     [('modify', ('f-id', 'new-content\n'))])
'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.
Method __init__ Construct a BranchBuilder on transport.
Method build_commit Build a commit on the branch.
Method start_series We will be creating a series of commits.
Method finish_series Call this after start_series to unlock the various objects.
Method build_snapshot Build a commit, shaped in a specific way.
Method get_branch Return the branch created by the builder.
Method _do_commit Undocumented
Method _move_branch_pointer Point self._branch to a different revision id.
Method _flush_pending Flush the pending actions in 'pending', i.e. apply them to 'tree'.
def __init__(self, transport=None, format=None, branch=None):
Construct a BranchBuilder on transport.
ParameterstransportThe transport the branch should be created on. If the path of the transport does not exist but its parent does it will be created.
formatEither a BzrDirFormat, or the name of a format in the controldir format registry for the branch to be built.
branchAn already constructed branch to use. This param is mutually exclusive with the transport and format params.
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.

Parameterscommit_kwargsArguments to pass through to commit, such as timestamp.
def _do_commit(self, tree, message=None, message_callback=None, **kwargs):
Undocumented
def _move_branch_pointer(self, new_revision_id, allow_leftmost_as_ghost=False):
Point self._branch to a different revision id.
def start_series(self):
We will be creating a series of commits.

This allows us to hold open the locks while we are processing.

Make sure to call 'finish_series' when you are done.

def finish_series(self):
Call this after start_series to unlock the various objects.
def build_snapshot(self, revision_id, parent_ids, actions, message=None, timestamp=None, allow_leftmost_as_ghost=False, committer=None, timezone=None, message_callback=None):
Build a commit, shaped in a specific way.

Most of the actions are self-explanatory. 'flush' is special action to break a series of actions into discrete steps so that complex changes (such as unversioning a file-id and re-adding it with a different kind) can be expressed in a way that will clearly work.

Parametersrevision_idThe handle for the new commit, can be None
parent_idsA list of parent_ids to use for the commit. It can be None, which indicates to use the last commit.
actionsA list of actions to perform. Supported actions are: ('add', ('path', 'file-id', 'kind', 'content' or None)) ('modify', ('file-id', 'new-content')) ('unversion', 'file-id') ('rename', ('orig-path', 'new-path')) ('flush', None)
messageAn optional commit message, if not supplied, a default commit message will be written.
message_callbackA message callback to use for the commit, as per mutabletree.commit.
timestampIf non-None, set the timestamp of the commit to this value.
timezoneAn optional timezone for timestamp.
committerAn optional username to use for commit
allow_leftmost_as_ghostTrue if the leftmost parent should be permitted to be a ghost.
ReturnsThe revision_id of the new commit
def _flush_pending(self, tree, pending):
Flush the pending actions in 'pending', i.e. apply them to 'tree'.
def get_branch(self):
Return the branch created by the builder.
API Documentation for Bazaar, generated by pydoctor at 2019-09-23 00:31:07.