/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3250.4.1 by Martin Albisetti
Added integration guide for developers
1
=======================
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
2
Integrating with Breezy
3250.4.1 by Martin Albisetti
Added integration guide for developers
3
=======================
4
5225.2.13 by Martin Pool
More reorganization of the developer documentation
5
This document provides some general observations on integrating with
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
6
Breezy and some recipes for typical tasks.  It is intended to be useful to
5225.2.13 by Martin Pool
More reorganization of the developer documentation
7
someone developing either a plugin or some other piece of software that
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
8
integrates with brz.  If you want to know about a topic that's not covered
5225.2.13 by Martin Pool
More reorganization of the developer documentation
9
here, just ask us.
10
11
5225.2.4 by Martin Pool
ReST format fixes
12
13
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
14
Starting with breezy
5225.2.6 by Martin Pool
mention bzrlib.initialize and get_command
15
====================
16
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
17
Within brz
5641.2.1 by Andrew Bennetts
Fix some formatting nits in doc/developers/overview.txt, and expand the content a little.
18
----------
19
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
20
When using breezy within the ``brz`` program (for instance as a brz
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
21
plugin), breezy's global state is already available for use.
5641.2.1 by Andrew Bennetts
Fix some formatting nits in doc/developers/overview.txt, and expand the content a little.
22
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
23
From outside brz
5641.2.1 by Andrew Bennetts
Fix some formatting nits in doc/developers/overview.txt, and expand the content a little.
24
----------------
25
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
26
To use breezy outside of ``brz`` some global state needs to be setup.
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
27
breezy needs ways to handle user input, passwords, a place to emit
5641.2.1 by Andrew Bennetts
Fix some formatting nits in doc/developers/overview.txt, and expand the content a little.
28
progress bars, logging setup appropriately for your program. The easiest
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
29
way to set all this up in the same fashion ``brz`` does is to call
30
``breezy.initialize``.
5728.4.1 by Martin Pool
bzrlib.initialize now does what you'd expect
31
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
32
This returns a context manager within which breezy functions will work
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
33
correctly. See the pydoc for ``breezy.initialize`` for more information.
5728.4.1 by Martin Pool
bzrlib.initialize now does what you'd expect
34
(You can get away without entering the context manager, because the setup
35
work happens directly from ``initialize``.)
36
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
37
38
Running brz commands
5225.2.6 by Martin Pool
mention bzrlib.initialize and get_command
39
====================
40
41
To run command-line commands in-process::
42
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
43
  from breezy.commands import get_command
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
44
5225.2.6 by Martin Pool
mention bzrlib.initialize and get_command
45
  cmd = get_command('version')
46
  cmd.run([])
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
47
5225.2.6 by Martin Pool
mention bzrlib.initialize and get_command
48
This will send output through the current UIFactory; you can redirect this
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
49
elsewhere through the parameters to `breezy.initialize`.
5225.2.6 by Martin Pool
mention bzrlib.initialize and get_command
50
5225.2.4 by Martin Pool
ReST format fixes
51
3250.4.1 by Martin Albisetti
Added integration guide for developers
52
Manipulating the Working Tree
53
=============================
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
54
Most objects in Breezy are in files, named after the class they contain.
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
55
To manipulate the Working Tree we need a valid WorkingTree object, which
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
56
is loaded from the workingtree.py file, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
57
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
58
  from breezy import workingtree
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
59
  wt = workingtree.WorkingTree.open('/home/jebw/brztest')
3250.4.1 by Martin Albisetti
Added integration guide for developers
60
61
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
62
This gives us a WorkingTree object, which has various methods spread over
5538.1.1 by Zearin
Fixed “its” vs “it's”.
63
itself, and its parent classes MutableTree and Tree - it's worth having a
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
64
look through these three files (workingtree.py, mutabletree.py and tree.py)
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
65
to see which methods are available.
3250.4.1 by Martin Albisetti
Added integration guide for developers
66
3250.4.6 by Martin Albisetti
Added changes sent by Aaron Bently
67
Compare trees
5225.2.4 by Martin Pool
ReST format fixes
68
-------------
69
3250.4.6 by Martin Albisetti
Added changes sent by Aaron Bently
70
There are two methods for comparing trees: ``changes_from`` and
71
``iter_changes``.  ``iter_changes`` is more regular and precise, but it is
72
somewhat harder to work with.  See the API documentation for more details.
73
74
``changes_from`` creates a Delta object showing changes::
3250.4.1 by Martin Albisetti
Added integration guide for developers
75
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
76
  from breezy import delta
3250.4.1 by Martin Albisetti
Added integration guide for developers
77
  changes = wt.changes_from(wt.basis_tree())
78
3250.4.6 by Martin Albisetti
Added changes sent by Aaron Bently
79
This gives us a Delta object, which has several lists of files for each type of
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
80
change, eg changes.added is a list of added files, changes.removed is list
81
of removed files, changes.modified is a list of modified files. The contents
3250.4.6 by Martin Albisetti
Added changes sent by Aaron Bently
82
of the lists aren't just filenames, but include other information as well.
3344.1.2 by Martin Pool
Fix ReST syntax in integration guide
83
To grab just the filename we want the first value, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
84
85
  print("list of newly added files")
86
  for filename in changes.added:
87
    print("%s has been added" % filename[0])
88
89
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
90
The exception to this is changes.renamed, where the list returned for each
91
renamed files contains both the old and new names -- one or both may interest
92
you, depending on what you're doing.
3250.4.1 by Martin Albisetti
Added integration guide for developers
93
94
For example::
95
96
  print("list of renamed files")
97
  for filename in changes.renamed:
98
    print("%s has been renamed to %s" % (filename[0], filename[1]))
99
100
101
Adding Files
5225.2.4 by Martin Pool
ReST format fixes
102
------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
103
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
104
If you want to add files the same way ``brz add`` does, you can use
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
105
MutableTree.smart_add.  By default, this is recursive. Paths can either be
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
106
absolute or relative to the workingtree::
3250.4.1 by Martin Albisetti
Added integration guide for developers
107
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
108
  wt.smart_add(['dir1/filea.txt', 'fileb.txt',
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
109
                '/home/jebw/brztesttree/filec.txt'])
3250.4.1 by Martin Albisetti
Added integration guide for developers
110
111
112
For more precise control over which files to add, use MutableTree.add::
113
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
114
  wt.add(['dir1/filea.txt', 'fileb.txt', '/home/jebw/brztesttree/filec.txt'])
3250.4.1 by Martin Albisetti
Added integration guide for developers
115
116
117
Removing Files
5225.2.4 by Martin Pool
ReST format fixes
118
--------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
119
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
120
You can remove multiple files at once.  The file paths need to be relative
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
121
to the workingtree::
3250.4.1 by Martin Albisetti
Added integration guide for developers
122
123
  wt.remove(['filea.txt', 'fileb.txt', 'dir1'])
124
125
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
126
By default, the files are not deleted, just removed from the inventory.
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
127
To delete them from the filesystem as well::
3250.4.1 by Martin Albisetti
Added integration guide for developers
128
129
  wt.remove(['filea.txt', 'fileb.txt', 'dir1'], keep_files=False)
130
131
132
Renaming a File
5225.2.4 by Martin Pool
ReST format fixes
133
---------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
134
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
135
You can rename one file to a different name using WorkingTree.rename_one.
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
136
You just provide the old and new names, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
137
138
  wt.rename_one('oldfile.txt','newfile.txt')
139
140
141
Moving Files
5225.2.4 by Martin Pool
ReST format fixes
142
------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
143
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
144
You can move multiple files from one directory into another using
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
145
WorkingTree.move::
3250.4.1 by Martin Albisetti
Added integration guide for developers
146
147
  wt.move(['olddir/file.txt'], 'newdir')
148
149
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
150
More complicated renames/moves can be done with transform.TreeTransform,
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
151
which is outside the scope of this document.
3250.4.1 by Martin Albisetti
Added integration guide for developers
152
153
154
Committing Changes
5225.2.4 by Martin Pool
ReST format fixes
155
------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
156
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
157
To commit _all_ the changes to our working tree we can just call the
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
158
WorkingTree's commit method, giving it a commit message, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
159
160
  wt.commit('this is my commit message')
161
162
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
163
To commit only certain files, we need to provide a list of filenames which we
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
164
want committing, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
165
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
166
  wt.commit(message='this is my commit message', specific_files=['fileA.txt',
167
            'dir2/fileB.txt', 'fileD.txt'])
3250.4.1 by Martin Albisetti
Added integration guide for developers
168
169
170
Generating a Log for a File
171
===========================
172
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
173
Generating a log is, in itself, simple.  Grab a branch (see below) and pass
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
174
it to show_log together with a log formatter, eg::
3250.4.1 by Martin Albisetti
Added integration guide for developers
175
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
176
  from breezy import log
177
  from breezy import branch
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
178
3250.4.1 by Martin Albisetti
Added integration guide for developers
179
  b = branch.Branch.open('/path/to/bazaar/branch')
180
  lf = log.LongLogFormatter(to_file=sys.stdout)
181
  log.show_log(b, lf)
182
183
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
184
Three log formatters are included with breezy: LongLogFormatter,
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
185
ShortLogFormatter and LineLogFormatter.  These provide long, short and
186
single-line log output formats. It's also possible to write your own in
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
187
very little code.
3250.4.1 by Martin Albisetti
Added integration guide for developers
188
189
Annotating a File
190
=================
191
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
192
To annotate a file, we want to walk every line of a file, retrieving the
193
revision which last modified/created that line and then retrieving the
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
194
information for that revision.
3250.4.1 by Martin Albisetti
Added integration guide for developers
195
196
First we get an annotation iterator for the file we are interested in::
197
198
  tree, relpath = workingtree.WorkingTree.open_containing('/path/to/file.txt')
199
  fileid = tree.path2id(relpath)
200
  annotation = list(tree.annotate_iter(fileid))
201
202
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
203
To avoid repeatedly retrieving the same revisions we grab all revisions
204
associated with the file at once and build up a map of id to revision
205
information. We also build an map of revision numbers, again indexed
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
206
by the revision id::
3250.4.1 by Martin Albisetti
Added integration guide for developers
207
208
  revision_ids = set(revision_id for revision_id, text in annotation)
209
  revisions = tree.branch.repository.get_revisions(revision_ids)
210
  revision_map = dict(izip(revision_ids, revisions))
211
  revno_map = tree.branch.get_revision_id_to_revno_map()
212
213
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
214
Finally, we use our annotation iterator to walk the lines of the file,
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
215
displaying the information from our revision maps as we go::
3250.4.1 by Martin Albisetti
Added integration guide for developers
216
217
  for revision_id, text in annotation :
218
      rev = revision_map[revision_id]
219
      revno = revno_map[revision_id]
220
      revno_string = '.'.join(str(i) for i in revno)
7490.155.1 by Jelmer Vernooij
Use print with parentheses, for python 3 compatibility.
221
      print("%s, %s: %s" % (revno_string, rev.committer, text))
3250.4.1 by Martin Albisetti
Added integration guide for developers
222
223
224
Working with branches
225
=====================
226
227
To work with a branch you need a branch object, created from your branch::
228
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
229
  from breezy import branch
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
230
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
231
  b = branch.Branch.open('/home/jebw/brztest')
3250.4.1 by Martin Albisetti
Added integration guide for developers
232
233
234
Branching from an existing branch
5225.2.4 by Martin Pool
ReST format fixes
235
---------------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
236
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
237
To branch you create a branch object representing the branch you are
238
branching from, and supply a path/url to the new branch location.
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
239
The following code clones the brz trunk branch (the latest copy of the Breezy
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
240
source code) - be warned it has to download 60meg so takes a while to run
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
241
with no feedback::
3250.4.1 by Martin Albisetti
Added integration guide for developers
242
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
243
  from breezy import branch
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
244
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
245
  b = branch.Branch.open('bzr+ssh://bazaar.launchpad.net/+branch/brz/')
246
  nb = b.controldir.sprout('/tmp/newBrzBzranch').open_branch()
3250.4.1 by Martin Albisetti
Added integration guide for developers
247
248
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
249
This provides no feedback, since Breezy automatically uses the 'silent' UI.
3250.4.1 by Martin Albisetti
Added integration guide for developers
250
251
252
Pushing and pulling branches
5225.2.4 by Martin Pool
ReST format fixes
253
----------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
254
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
255
To push a branch you need to open the source and destination branches, then
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
256
just call push with the other branch as a parameter::
3250.4.1 by Martin Albisetti
Added integration guide for developers
257
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
258
  from breezy import branch
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
259
3250.4.1 by Martin Albisetti
Added integration guide for developers
260
  b1 = branch.Branch.open('file:///home/user/mybranch')
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
261
  b2 = branch.Branch.open('bzr+ssh://bazaar.launchpad.net/+branch/brz/')
3250.4.1 by Martin Albisetti
Added integration guide for developers
262
  b1.push(b2)
263
264
265
Pulling is much the same::
266
267
  b1.pull(b2)
268
269
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
270
If you have a working tree, as well as a branch, you should use
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
271
WorkingTree.pull, not Branch.pull.
3250.4.1 by Martin Albisetti
Added integration guide for developers
272
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
273
This won't handle conflicts automatically though, so any conflicts will be
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
274
left in the working tree for the user to resolve.
3250.4.1 by Martin Albisetti
Added integration guide for developers
275
276
277
Checkout from an existing branch
278
================================
279
280
This performs a Lightweight checkout from an existing Branch::
281
6803.1.1 by Jelmer Vernooij
Bunch of developer docs changes:
282
  from breezy import bzrdir
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
283
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
284
  accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch('http:URL')
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
285
  source.create_checkout('/tmp/newBrzCheckout', None, True, accelerator_tree)
3250.4.1 by Martin Albisetti
Added integration guide for developers
286
287
288
To make a heavyweight checkout, change the last line to::
289
7344.2.1 by Martin
Relocate the bzr log file out of $HOME
290
  source.create_checkout('/tmp/newBrzCheckout', None, False, accelerator_tree
3250.4.1 by Martin Albisetti
Added integration guide for developers
291
4634.39.32 by Ian Clatworthy
proper Contents panel in bzr-developers.chm
292
3250.4.1 by Martin Albisetti
Added integration guide for developers
293
History Operations
294
==================
295
296
Finding the last revision number or id
4634.39.32 by Ian Clatworthy
proper Contents panel in bzr-developers.chm
297
--------------------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
298
299
To get the last revision number and id of a branch use::
300
301
  revision_number, revision_id = branch.last_revision_info()
302
303
304
If all you care about is the revision_id there is also the
305
method::
306
307
  revision_id = branch.last_revision()
308
309
310
Getting the list of revision ids that make up a branch
4634.39.32 by Ian Clatworthy
proper Contents panel in bzr-developers.chm
311
------------------------------------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
312
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
313
IMPORTANT: This should be avoided wherever possible, as it scales with the
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
314
length of history::
3250.4.1 by Martin Albisetti
Added integration guide for developers
315
316
  revisions = branch.revision_history()
317
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
318
now revisions[0] is the revision id of the first commit, and revs[-1] is the
319
revision id of the most recent. Note that if all you want is the last
320
revision then you should use branch.last_revision() as described above, as
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
321
it is vastly more efficient.
3250.4.1 by Martin Albisetti
Added integration guide for developers
322
323
324
Getting a Revision object from a revision id
4634.39.32 by Ian Clatworthy
proper Contents panel in bzr-developers.chm
325
--------------------------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
326
327
The Revision object has attributes like "message" to get the information
328
about the revision::
329
330
  repo = branch.repository
331
  revision = repo.get_revision(rev_id)
332
333
334
Accessing the files from a revision
4634.39.32 by Ian Clatworthy
proper Contents panel in bzr-developers.chm
335
-----------------------------------
3250.4.1 by Martin Albisetti
Added integration guide for developers
336
337
To get the file contents and tree shape for a specific revision you need
338
a RevisionTree. These are supplied by the repository for a specific
339
revision id::
340
341
  revtree = repo.revision_tree(rev_id)
342
3250.4.6 by Martin Albisetti
Added changes sent by Aaron Bently
343
RevisionTrees, like all trees, can be compared as described in "Comparing
344
Trees" above.
3250.4.1 by Martin Albisetti
Added integration guide for developers
345
3250.4.5 by Martin Albisetti
Removed trailing whitespaces
346
The most common way to list files in a tree is ``Tree.iter_entries()``.
347
The simplest way to get file content is ``Tree.get_file()``.  The best way
348
to retrieve file content for large numbers of files `Tree.iter_files_bytes()``
3250.4.4 by Martin Albisetti
Shortened to under 80 characters per line, and removed all wiki-specific information
349