~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branchbuilder.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-11-11 03:35:23 UTC
  • mfrom: (3825.3.2 branchbuilder)
  • Revision ID: pqm@pqm.ubuntu.com-20081111033523-xbz2o8weoyl4d0l7
(mbp) fix up branchbuilder doctests

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Utility for create branches with particular contents."""
18
18
 
19
 
from bzrlib import bzrdir, errors, memorytree
 
19
from bzrlib import (
 
20
    bzrdir, 
 
21
    commit,
 
22
    errors,
 
23
    memorytree,
 
24
    )
20
25
 
21
26
 
22
27
class BranchBuilder(object):
23
 
    """A BranchBuilder aids creating Branches with particular shapes.
 
28
    r"""A BranchBuilder aids creating Branches with particular shapes.
24
29
    
25
30
    The expected way to use BranchBuilder is to construct a
26
31
    BranchBuilder on the transport you want your branch on, and then call
30
35
    real data.
31
36
 
32
37
    For instance:
33
 
      builder = BranchBuilder(self.get_transport().clone('relpath'))
34
 
      builder.start_series()
35
 
      builder.build_snapshot('rev-id', [],
36
 
        [('add', ('filename', 'f-id', 'file', 'content\n'))])
37
 
      builder.build_snapshot('rev2-id', ['rev-id'],
38
 
        [('modify', ('f-id', 'new-content\n'))])
39
 
      builder.finish_series()
40
 
      branch = builder.get_branch()
 
38
 
 
39
    >>> from bzrlib.transport.memory import MemoryTransport
 
40
    >>> builder = BranchBuilder(MemoryTransport("memory:///"))
 
41
    >>> builder.start_series()
 
42
    >>> builder.build_snapshot('rev-id', None, [
 
43
    ...     ('add', ('', 'root-id', 'directory', '')),
 
44
    ...     ('add', ('filename', 'f-id', 'file', 'content\n'))])
 
45
    'rev-id'
 
46
    >>> builder.build_snapshot('rev2-id', ['rev-id'],
 
47
    ...     [('modify', ('f-id', 'new-content\n'))])
 
48
    'rev2-id'
 
49
    >>> builder.finish_series()
 
50
    >>> branch = builder.get_branch()
41
51
 
42
52
    :ivar _tree: This is a private member which is not meant to be modified by
43
53
        users of this class. While a 'series' is in progress, it should hold a
71
81
        tree.lock_write()
72
82
        try:
73
83
            tree.add('')
74
 
            return tree.commit('commit %d' % (self._branch.revno() + 1))
 
84
            return self._do_commit(tree)
75
85
        finally:
76
86
            tree.unlock()
77
87
 
 
88
    def _do_commit(self, tree, message=None, **kwargs):
 
89
        reporter = commit.NullCommitReporter()
 
90
        if message is None:
 
91
            message = u'commit %d' % (self._branch.revno() + 1,)
 
92
        return tree.commit(message,
 
93
            reporter=reporter,
 
94
            **kwargs)
 
95
 
78
96
    def _move_branch_pointer(self, new_revision_id):
79
97
        """Point self._branch to a different revision id."""
80
98
        self._branch.lock_write()
192
210
            tree.add(to_add_files, to_add_file_ids, to_add_kinds)
193
211
            for file_id, content in new_contents.iteritems():
194
212
                tree.put_file_bytes_non_atomic(file_id, content)
195
 
 
196
 
            if message is None:
197
 
                message = u'commit %d' % (self._branch.revno() + 1,)
198
 
            return tree.commit(message, rev_id=revision_id)
 
213
            return self._do_commit(tree, message=message, rev_id=revision_id) 
199
214
        finally:
200
215
            tree.unlock()
201
216