/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to doc/developers/integration.txt

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Integrating with Bazaar
3
3
=======================
4
4
 
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
9
 
here, just ask us.
10
 
 
11
 
 
12
 
 
13
 
 
14
 
Starting with bzrlib
15
 
====================
16
 
 
17
 
Within bzr
18
 
----------
19
 
 
20
 
When using bzrlib within the ``bzr`` program (for instance as a bzr
21
 
plugin), bzrlib's global state is already available for use.
22
 
 
23
 
From outside bzr
24
 
----------------
25
 
 
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::
34
 
 
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__()
39
 
  try:
40
 
      pass
41
 
      # do stuff here
42
 
  finally:
43
 
      library_state.__exit__(None, None, None)
44
 
 
45
 
 
46
 
Running bzr commands
47
 
====================
48
 
 
49
 
To run command-line commands in-process::
50
 
 
51
 
  from bzrlib.commands import get_command
52
 
  
53
 
  cmd = get_command('version')
54
 
  cmd.run([])
55
 
  
56
 
This will send output through the current UIFactory; you can redirect this
57
 
elsewhere through the parameters to `bzrlib.initialize`.
58
 
 
 
5
This page should hopefully become a quick guide to integrating other
 
6
(Python-based) software with Bazaar.
59
7
 
60
8
Manipulating the Working Tree
61
9
=============================
68
16
 
69
17
 
70
18
This gives us a WorkingTree object, which has various methods spread over
71
 
itself, and its parent classes MutableTree and Tree - it's worth having a
 
19
itself, and its parent classes MutableTree and Tree - its worth having a
72
20
look through these three files (workingtree.py, mutabletree.py and tree.py)
73
21
to see which methods are available.
74
22
 
75
23
Compare trees
76
 
-------------
77
 
 
 
24
===============
78
25
There are two methods for comparing trees: ``changes_from`` and
79
26
``iter_changes``.  ``iter_changes`` is more regular and precise, but it is
80
27
somewhat harder to work with.  See the API documentation for more details.
107
54
 
108
55
 
109
56
Adding Files
110
 
------------
 
57
============
111
58
 
112
59
If you want to add files the same way ``bzr add`` does, you can use
113
60
MutableTree.smart_add.  By default, this is recursive. Paths can either be
123
70
 
124
71
 
125
72
Removing Files
126
 
--------------
 
73
==============
127
74
 
128
75
You can remove multiple files at once.  The file paths need to be relative
129
76
to the workingtree::
138
85
 
139
86
 
140
87
Renaming a File
141
 
---------------
 
88
===============
142
89
 
143
90
You can rename one file to a different name using WorkingTree.rename_one.
144
91
You just provide the old and new names, eg::
147
94
 
148
95
 
149
96
Moving Files
150
 
------------
 
97
============
151
98
 
152
99
You can move multiple files from one directory into another using
153
100
WorkingTree.move::
160
107
 
161
108
 
162
109
Committing Changes
163
 
------------------
 
110
==================
164
111
 
165
112
To commit _all_ the changes to our working tree we can just call the
166
113
WorkingTree's commit method, giving it a commit message, eg::
240
187
 
241
188
 
242
189
Branching from an existing branch
243
 
---------------------------------
 
190
=================================
244
191
 
245
192
To branch you create a branch object representing the branch you are
246
193
branching from, and supply a path/url to the new branch location.
258
205
 
259
206
 
260
207
Pushing and pulling branches
261
 
----------------------------
 
208
============================
262
209
 
263
210
To push a branch you need to open the source and destination branches, then
264
211
just call push with the other branch as a parameter::