2
2
Integrating with Bazaar
3
3
=======================
5
This page should hopefully become a quick guide to integrating other
6
(Python-based) software with Bazaar.
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
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
20
When using bzrlib within the ``bzr`` program (for instance as a bzr
21
plugin), bzrlib'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
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``. This returns a context manager within which bzrlib
31
functions will work correctly. See the pydoc for ``bzrlib.initialize`` for
32
more information. In Python 2.4 the ``with`` keyword is not supported and
33
so you need to use the context manager manually::
35
# This sets up your ~/.bzr.log, ui factory and so on and so forth. It is
36
# not safe to use as a doctest.
37
library_state = bzrlib.initialize()
38
library_state.__enter__()
43
library_state.__exit__(None, None, None)
49
To run command-line commands in-process::
51
from bzrlib.commands import get_command
53
cmd = get_command('version')
56
This will send output through the current UIFactory; you can redirect this
57
elsewhere through the parameters to `bzrlib.initialize`.
8
60
Manipulating the Working Tree
9
61
=============================
18
70
This gives us a WorkingTree object, which has various methods spread over
19
itself, and its parent classes MutableTree and Tree - its worth having a
71
itself, and its parent classes MutableTree and Tree - it's worth having a
20
72
look through these three files (workingtree.py, mutabletree.py and tree.py)
21
73
to see which methods are available.
25
78
There are two methods for comparing trees: ``changes_from`` and
26
79
``iter_changes``. ``iter_changes`` is more regular and precise, but it is
27
80
somewhat harder to work with. See the API documentation for more details.
189
242
Branching from an existing branch
190
=================================
243
---------------------------------
192
245
To branch you create a branch object representing the branch you are
193
246
branching from, and supply a path/url to the new branch location.
207
260
Pushing and pulling branches
208
============================
261
----------------------------
210
263
To push a branch you need to open the source and destination branches, then
211
264
just call push with the other branch as a parameter::