/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: Jelmer Vernooij
  • Date: 2018-04-02 00:52:27 UTC
  • mfrom: (6939 work)
  • mto: This revision was merged to the branch mainline in revision 7274.
  • Revision ID: jelmer@jelmer.uk-20180402005227-pecflp1mvdjrjqd6
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
=======================
2
 
Integrating with Bazaar
 
2
Integrating with Breezy
3
3
=======================
4
4
 
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
8
integrates with bzr.  If you want to know about a topic that's not covered
9
9
here, just ask us.
11
11
 
12
12
 
13
13
 
14
 
Starting with bzrlib
 
14
Starting with breezy
15
15
====================
16
16
 
17
17
Within bzr
18
18
----------
19
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.
 
20
When using breezy within the ``bzr`` program (for instance as a bzr
 
21
plugin), breezy's global state is already available for use.
22
22
 
23
23
From outside bzr
24
24
----------------
25
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
 
26
To use breezy outside of ``bzr`` 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
29
way to set all this up in the same fashion ``bzr`` does is to call
30
 
``bzrlib.initialize``. 
 
30
``breezy.initialize``. 
31
31
 
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``.)
36
36
 
39
39
 
40
40
  # This sets up your ~/.bzr.log, ui factory and so on and so forth. It is
41
41
  # not safe to use as a doctest.
42
 
  library_state = bzrlib.initialize()
 
42
  library_state = breezy.initialize()
43
43
  library_state.__enter__()
44
44
  try:
45
45
      pass
53
53
 
54
54
To run command-line commands in-process::
55
55
 
56
 
  from bzrlib.commands import get_command
 
56
  from breezy.commands import get_command
57
57
  
58
58
  cmd = get_command('version')
59
59
  cmd.run([])
60
60
  
61
61
This will send output through the current UIFactory; you can redirect this
62
 
elsewhere through the parameters to `bzrlib.initialize`.
 
62
elsewhere through the parameters to `breezy.initialize`.
63
63
 
64
64
 
65
65
Manipulating the Working Tree
66
66
=============================
67
 
Most objects in Bazaar are in files, named after the class they contain.
 
67
Most objects in Breezy are in files, named after the class they contain.
68
68
To manipulate the Working Tree we need a valid WorkingTree object, which
69
69
is loaded from the workingtree.py file, eg::
70
70
 
71
 
  from bzrlib import workingtree
 
71
  from breezy import workingtree
72
72
  wt = workingtree.WorkingTree.open('/home/jebw/bzrtest')
73
73
 
74
74
 
86
86
 
87
87
``changes_from`` creates a Delta object showing changes::
88
88
 
89
 
  from bzrlib import delta
 
89
  from breezy import delta
90
90
  changes = wt.changes_from(wt.basis_tree())
91
91
 
92
92
This gives us a Delta object, which has several lists of files for each type of
186
186
Generating a log is, in itself, simple.  Grab a branch (see below) and pass
187
187
it to show_log together with a log formatter, eg::
188
188
 
189
 
  from bzrlib import log
190
 
  from bzrlib import branch
 
189
  from breezy import log
 
190
  from breezy import branch
191
191
 
192
192
  b = branch.Branch.open('/path/to/bazaar/branch')
193
193
  lf = log.LongLogFormatter(to_file=sys.stdout)
194
194
  log.show_log(b, lf)
195
195
 
196
196
 
197
 
Three log formatters are included with bzrlib: LongLogFormatter,
 
197
Three log formatters are included with breezy: LongLogFormatter,
198
198
ShortLogFormatter and LineLogFormatter.  These provide long, short and
199
199
single-line log output formats. It's also possible to write your own in
200
200
very little code.
239
239
 
240
240
To work with a branch you need a branch object, created from your branch::
241
241
 
242
 
  from bzrlib import branch
 
242
  from breezy import branch
243
243
 
244
244
  b = branch.Branch.open('/home/jebw/bzrtest')
245
245
 
249
249
 
250
250
To branch you create a branch object representing the branch you are
251
251
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
 
252
The following code clones the bzr.dev branch (the latest copy of the Breezy
253
253
source code) - be warned it has to download 60meg so takes a while to run
254
254
with no feedback::
255
255
 
256
 
  from bzrlib import branch
 
256
  from breezy import branch
257
257
 
258
258
  b = branch.Branch.open('http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev')
259
259
  nb = b.controldir.sprout('/tmp/newBzrBranch').open_branch()
260
260
 
261
261
 
262
 
This provides no feedback, since Bazaar automatically uses the 'silent' UI.
 
262
This provides no feedback, since Breezy automatically uses the 'silent' UI.
263
263
 
264
264
 
265
265
Pushing and pulling branches
268
268
To push a branch you need to open the source and destination branches, then
269
269
just call push with the other branch as a parameter::
270
270
 
271
 
  from bzrlib import branch
 
271
  from breezy import branch
272
272
 
273
273
  b1 = branch.Branch.open('file:///home/user/mybranch')
274
274
  b2 = branch.Branch.open('http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev')
292
292
 
293
293
This performs a Lightweight checkout from an existing Branch::
294
294
 
295
 
  from bzrlib import bzrdir
 
295
  from breezy import bzrdir
296
296
 
297
297
  accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch('http:URL')
298
298
  source.create_checkout('/tmp/newBzrCheckout', None, True, accelerator_tree)