1
1
=======================
2
Integrating with Bazaar
2
Integrating with Breezy
3
3
=======================
5
5
This document provides some general observations on integrating with
6
Bazaar and some recipes for typical tasks. It is intended to be useful to
6
Breezy and some recipes for typical tasks. It is intended to be useful to
7
7
someone developing either a plugin or some other piece of software that
8
integrates with bzr. If you want to know about a topic that's not covered
8
integrates with brz. If you want to know about a topic that's not covered
15
15
====================
20
When using bzrlib within the ``bzr`` program (for instance as a bzr
21
plugin), bzrlib's global state is already available for use.
20
When using breezy within the ``brz`` program (for instance as a brz
21
plugin), breezy's global state is already available for use.
26
To use bzrlib outside of ``bzr`` some global state needs to be setup.
27
bzrlib needs ways to handle user input, passwords, a place to emit
26
To use breezy outside of ``brz`` some global state needs to be setup.
27
breezy needs ways to handle user input, passwords, a place to emit
28
28
progress bars, logging setup appropriately for your program. The easiest
29
way to set all this up in the same fashion ``bzr`` does is to call
30
``bzrlib.initialize``.
29
way to set all this up in the same fashion ``brz`` does is to call
30
``breezy.initialize``.
32
This returns a context manager within which bzrlib functions will work
33
correctly. See the pydoc for ``bzrlib.initialize`` for more information.
32
This returns a context manager within which breezy functions will work
33
correctly. See the pydoc for ``breezy.initialize`` for more information.
34
34
(You can get away without entering the context manager, because the setup
35
35
work happens directly from ``initialize``.)
37
In Python 2.4 the ``with`` keyword is not supported and
38
so you need to use the context manager manually::
40
# This sets up your ~/.bzr.log, ui factory and so on and so forth. It is
41
# not safe to use as a doctest.
42
library_state = bzrlib.initialize()
43
library_state.__enter__()
48
library_state.__exit__(None, None, None)
52
39
====================
54
41
To run command-line commands in-process::
56
from bzrlib.commands import get_command
43
from breezy.commands import get_command
58
45
cmd = get_command('version')
61
48
This will send output through the current UIFactory; you can redirect this
62
elsewhere through the parameters to `bzrlib.initialize`.
49
elsewhere through the parameters to `breezy.initialize`.
65
52
Manipulating the Working Tree
66
53
=============================
67
Most objects in Bazaar are in files, named after the class they contain.
54
Most objects in Breezy are in files, named after the class they contain.
68
55
To manipulate the Working Tree we need a valid WorkingTree object, which
69
56
is loaded from the workingtree.py file, eg::
71
from bzrlib import workingtree
72
wt = workingtree.WorkingTree.open('/home/jebw/bzrtest')
58
from breezy import workingtree
59
wt = workingtree.WorkingTree.open('/home/jebw/brztest')
75
62
This gives us a WorkingTree object, which has various methods spread over
117
If you want to add files the same way ``bzr add`` does, you can use
104
If you want to add files the same way ``brz add`` does, you can use
118
105
MutableTree.smart_add. By default, this is recursive. Paths can either be
119
106
absolute or relative to the workingtree::
121
108
wt.smart_add(['dir1/filea.txt', 'fileb.txt',
122
'/home/jebw/bzrtesttree/filec.txt'])
109
'/home/jebw/brztesttree/filec.txt'])
125
112
For more precise control over which files to add, use MutableTree.add::
127
wt.add(['dir1/filea.txt', 'fileb.txt', '/home/jebw/bzrtesttree/filec.txt'])
114
wt.add(['dir1/filea.txt', 'fileb.txt', '/home/jebw/brztesttree/filec.txt'])
186
173
Generating a log is, in itself, simple. Grab a branch (see below) and pass
187
174
it to show_log together with a log formatter, eg::
189
from bzrlib import log
190
from bzrlib import branch
176
from breezy import log
177
from breezy import branch
192
179
b = branch.Branch.open('/path/to/bazaar/branch')
193
180
lf = log.LongLogFormatter(to_file=sys.stdout)
194
181
log.show_log(b, lf)
197
Three log formatters are included with bzrlib: LongLogFormatter,
184
Three log formatters are included with breezy: LongLogFormatter,
198
185
ShortLogFormatter and LineLogFormatter. These provide long, short and
199
186
single-line log output formats. It's also possible to write your own in
200
187
very little code.
250
237
To branch you create a branch object representing the branch you are
251
238
branching from, and supply a path/url to the new branch location.
252
The following code clones the bzr.dev branch (the latest copy of the Bazaar
239
The following code clones the brz trunk branch (the latest copy of the Breezy
253
240
source code) - be warned it has to download 60meg so takes a while to run
254
241
with no feedback::
256
from bzrlib import branch
258
b = branch.Branch.open('http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev')
259
nb = b.bzrdir.sprout('/tmp/newBzrBranch').open_branch()
262
This provides no feedback, since Bazaar automatically uses the 'silent' UI.
243
from breezy import branch
245
b = branch.Branch.open('bzr+ssh://bazaar.launchpad.net/+branch/brz/')
246
nb = b.controldir.sprout('/tmp/newBrzBzranch').open_branch()
249
This provides no feedback, since Breezy automatically uses the 'silent' UI.
265
252
Pushing and pulling branches
293
280
This performs a Lightweight checkout from an existing Branch::
295
from bzrlib import bzrdir
282
from breezy import bzrdir
297
284
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch('http:URL')
298
source.create_checkout('/tmp/newBzrCheckout', None, True, accelerator_tree)
285
source.create_checkout('/tmp/newBrzCheckout', None, True, accelerator_tree)
301
288
To make a heavyweight checkout, change the last line to::
303
source.create_checkout('/tmp/newBzrCheckout', None, False, accelerator_tree
290
source.create_checkout('/tmp/newBrzCheckout', None, False, accelerator_tree
306
293
History Operations