~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/HACKING.txt

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Bazaar Developer Guide
3
3
======================
4
4
 
5
 
This document describes the Bazaar internals and the development process.  
 
5
This document describes the Bazaar internals and the development process.
6
6
It's meant for people interested in developing Bazaar, and some parts will
7
7
also be useful to people developing Bazaar plugins.
8
8
 
62
62
to involving the community before you spend much time on a change.
63
63
These include:
64
64
 
65
 
* you get to build on the wisdom on others, saving time
 
65
* you get to build on the wisdom of others, saving time
66
66
 
67
 
* if others can direct you to similar code, it minimises the work to be done 
 
67
* if others can direct you to similar code, it minimises the work to be done
68
68
 
69
69
* it assists everyone in coordinating direction, priorities and effort.
70
70
 
87
87
-----------------
88
88
 
89
89
First, get a local copy of the development mainline (See `Why make a local
90
 
copy of bzr.dev?`_.) 
 
90
copy of bzr.dev?`_.)
91
91
::
92
92
 
93
93
 $ bzr init-repo ~/bzr
100
100
 
101
101
This will give you a branch called "123456-my-bugfix" that you can work on
102
102
and commit in. Here, you can study the code, make a fix or a new feature.
103
 
Feel free to commit early and often (after all, it's your branch!). 
 
103
Feel free to commit early and often (after all, it's your branch!).
104
104
 
105
105
Documentation improvements are an easy place to get started giving back to the
106
106
Bazaar project.  The documentation is in the `doc/` subdirectory of the Bazaar
133
133
Making a local mirror of bzr.dev is not strictly necessary, but it means
134
134
 
135
135
- You can use that copy of bzr.dev as your main bzr executable, and keep it
136
 
  up-to-date using ``bzr pull``.  
 
136
  up-to-date using ``bzr pull``.
137
137
- Certain operations are faster, and can be done when offline.  For example:
138
138
 
139
139
  - ``bzr bundle``
140
140
  - ``bzr diff -r ancestor:...``
141
141
  - ``bzr merge``
142
142
 
143
 
- When it's time to create your next branch, it's more convenient.  When you 
 
143
- When it's time to create your next branch, it's more convenient.  When you
144
144
  have further contributions to make, you should do them in their own branch::
145
145
 
146
146
    $ cd ~/bzr
193
193
 
194
194
* create a local copy of the main development branch (bzr.dev) by using
195
195
  this command::
196
 
  
 
196
 
197
197
    bzr branch http://bazaar-vcs.org/bzr/bzr.dev/ bzr.dev
198
 
   
 
198
 
199
199
* keep your copy of bzr.dev pristine (by not developing in it) and keep
200
200
  it up to date (by using bzr pull)
201
201
 
222
222
 
223
223
README
224
224
    This file covers a brief introduction to Bazaar and lists some of its
225
 
    key features. 
 
225
    key features.
226
226
 
227
227
NEWS
228
 
    Summary of changes in each Bazaar release that can affect users or 
 
228
    Summary of changes in each Bazaar release that can affect users or
229
229
    plugin developers.
230
230
 
231
231
setup.py
237
237
    with this but don't be confused by it. The build process puts a copy
238
238
    of the main code base into this build directory, along with some other
239
239
    files. You don't need to go in here for anything discussed in this
240
 
    guide. 
 
240
    guide.
241
241
 
242
242
bzrlib
243
243
    Possibly the most exciting folder of all, bzrlib holds the main code
248
248
    Holds documentation on a whole range of things on Bazaar from the
249
249
    origination of ideas within the project to information on Bazaar
250
250
    features and use cases.  Within this directory there is a subdirectory
251
 
    for each translation into a human language.  All the documentation 
 
251
    for each translation into a human language.  All the documentation
252
252
    is in the ReStructuredText markup language.
253
253
 
254
 
doc/developers 
 
254
doc/developers
255
255
    Documentation specifically targeted at Bazaar and plugin developers.
256
256
    (Including this document.)
257
 
    
258
 
        
259
 
 
260
 
Automatically-generated API reference information is available at 
261
 
<http://starship.python.net/crew/mwh/bzrlibapi/>.  
 
257
 
 
258
 
 
259
 
 
260
Automatically-generated API reference information is available at
 
261
<http://starship.python.net/crew/mwh/bzrlibapi/>.
262
262
 
263
263
See also the `Bazaar Architectural Overview
264
264
<http://doc.bazaar-vcs.org/developers/overview.html>`_.
291
291
 
292
292
* **how** this change achieves this purpose
293
293
 
294
 
* anything else you may have fixed in passing 
 
294
* anything else you may have fixed in passing
295
295
 
296
296
* anything significant that you thought of doing, such as a more
297
297
  extensive fix or a different approach, but didn't or couldn't do now
336
336
welcome that only cleanup the code without changing the external
337
337
behaviour.  The core developers take care to keep the code quality high
338
338
and understandable while recognising that perfect is sometimes the enemy
339
 
of good. 
 
339
of good.
340
340
 
341
341
It is easy for reviews to make people notice other things which should be
342
342
fixed but those things should not hold up the original fix being accepted.
378
378
====================
379
379
 
380
380
From May 2009 on, we prefer people to propose code reviews through
381
 
Launchpad.  
 
381
Launchpad.
382
382
 
383
383
 * <https://launchpad.net/+tour/code-review>
384
384
 
403
403
Then go to the branch's web page, which in this case would be
404
404
<https://code.launchpad.net/~mbp/bzr/doc>.  You can simplify this step by just
405
405
running ::
406
 
 
 
406
 
407
407
  bzr lp-open
408
408
 
409
409
You can then click "Propose for merging into another branch", and enter your
425
425
You can generate a merge request like this::
426
426
 
427
427
  bzr send -o bug-1234.diff
428
 
  
 
428
 
429
429
``bzr send`` can also send mail directly if you prefer; see the help.
430
430
 
431
431
Reviewing changes
457
457
You can generate a merge request like this::
458
458
 
459
459
  bzr send -o bug-1234.patch
460
 
  
 
460
 
461
461
A ``.patch`` extension is recommended instead of .bundle as many mail clients
462
462
will send the latter as a binary file.
463
463
 
512
512
Code layout
513
513
===========
514
514
 
515
 
Please write PEP-8__ compliant code.  
 
515
Please write PEP-8__ compliant code.
516
516
 
517
517
__ http://www.python.org/peps/pep-0008.html
518
518
 
530
530
Each file must have a newline at the end of it.
531
531
 
532
532
Lines should be no more than 79 characters if at all possible.
533
 
Lines that continue a long statement may be indented in either of 
 
533
Lines that continue a long statement may be indented in either of
534
534
two ways:
535
535
 
536
536
within the parenthesis or other character that opens the block, e.g.::
623
623
Functions, methods or members that are relatively private are given
624
624
a leading underscore prefix.  Names without a leading underscore are
625
625
public not just across modules but to programmers using bzrlib as an
626
 
API. 
 
626
API.
627
627
 
628
628
We prefer class names to be concatenated capital words (``TestCase``)
629
629
and variables, methods and functions to be lowercase words joined by
680
680
``only_raises`` decorator (from ``bzrlib.decorators``) for methods that
681
681
are typically called in ``finally`` blocks, such as ``unlock`` methods.
682
682
For example, ``@only_raises(LockNotHeld, LockBroken)``.  All errors that
683
 
are unlikely to be a knock-on failure from an previous failure should be
 
683
are unlikely to be a knock-on failure from a previous failure should be
684
684
allowed.
685
685
 
686
686
 
702
702
Registries
703
703
==========
704
704
 
705
 
Several places in Bazaar use (or will use) a registry, which is a 
706
 
mapping from names to objects or classes.  The registry allows for 
 
705
Several places in Bazaar use (or will use) a registry, which is a
 
706
mapping from names to objects or classes.  The registry allows for
707
707
loading in registered code only when it's needed, and keeping
708
708
associated information such as a help string or description.
709
709
 
713
713
 
714
714
The ``InterObject`` provides for two-way `multiple dispatch`__: matching
715
715
up for example a source and destination repository to find the right way
716
 
to transfer data between them. 
 
716
to transfer data between them.
717
717
 
718
718
.. __: http://en.wikipedia.org/wiki/Multiple_dispatch
719
719
 
720
720
There is a subclass ``InterObject`` classes for each type of object that is
721
721
dispatched this way, e.g. ``InterRepository``.  Calling ``.get()`` on this
722
 
class will return an ``InterObject`` instance providing the best match for 
 
722
class will return an ``InterObject`` instance providing the best match for
723
723
those parameters, and this instance then has methods for operations
724
724
between the objects.
725
725
 
806
806
 
807
807
If you add a new class you should generally add a ``__repr__`` method
808
808
unless there is an adequate method in a parent class.  There should be a
809
 
test for the repr.  
 
809
test for the repr.
810
810
 
811
811
Representations should typically look like Python constructor syntax, but
812
812
they don't need to include every value in the object and they don't need
869
869
way, you need to change its name as well. For instance, if I add an optional keyword
870
870
parameter to branch.commit - that's fine. On the other hand, if I add a
871
871
keyword parameter to branch.commit which is a *required* transaction
872
 
object, I should rename the API - i.e. to 'branch.commit_transaction'. 
 
872
object, I should rename the API - i.e. to 'branch.commit_transaction'.
873
873
 
874
874
  (Actually, that may break code that provides a new implementation of
875
875
  ``commit`` and doesn't expect to receive the parameter.)
1039
1039
 
1040
1040
    0. OK.
1041
1041
    1. Conflicts in merge-like operations, or changes are present in
1042
 
       diff-like operations. 
1043
 
    2. Unrepresentable diff changes (i.e. binary files that we cannot show 
 
1042
       diff-like operations.
 
1043
    2. Unrepresentable diff changes (i.e. binary files that we cannot show
1044
1044
       a diff of).
1045
1045
    3. An error or exception has occurred.
1046
1046
    4. An internal error occurred (one that shows a traceback.)
1077
1077
format string.
1078
1078
 
1079
1079
#. If it is something that a caller can recover from, a custom exception
1080
 
   is reasonable. 
 
1080
   is reasonable.
1081
1081
 
1082
1082
#. If it is a data consistency issue, using a builtin like
1083
 
   ``ValueError``/``TypeError`` is reasonable. 
 
1083
   ``ValueError``/``TypeError`` is reasonable.
1084
1084
 
1085
1085
#. If it is a programmer error (using an api incorrectly)
1086
 
   ``AssertionError`` is reasonable. 
 
1086
   ``AssertionError`` is reasonable.
1087
1087
 
1088
1088
#. Otherwise, use ``BzrError`` or ``InternalBzrError``.
1089
1089
 
1142
1142
Within each release, entries in the news file should have the most
1143
1143
user-visible changes first.  So the order should be approximately:
1144
1144
 
1145
 
 * changes to existing behaviour - the highest priority because the 
 
1145
 * changes to existing behaviour - the highest priority because the
1146
1146
   user's existing knowledge is incorrect
1147
1147
 * new features - should be brought to their attention
1148
1148
 * bug fixes - may be of interest if the bug was affecting them, and
1167
1167
-----------------
1168
1168
 
1169
1169
Functions, methods, classes and modules should have docstrings
1170
 
describing how they are used. 
 
1170
describing how they are used.
1171
1171
 
1172
1172
The first line of the docstring should be a self-contained sentence.
1173
1173
 
1198
1198
    We had the problem that lots of our files were "Copyright Canonical
1199
1199
    Development Ltd" which is not a real company, and some other variations
1200
1200
    on this theme. Also, some files were missing the GPL statements.
1201
 
    
 
1201
 
1202
1202
    I want to be clear about the intent of this patch, since copyright can
1203
1203
    be a little controversial.
1204
 
    
 
1204
 
1205
1205
    1) The big motivation for this is not to shut out the community, but
1206
1206
    just to clean up all of the invalid copyright statements.
1207
 
    
 
1207
 
1208
1208
    2) It has been the general policy for bzr that we want a single
1209
1209
    copyright holder for all of the core code. This is following the model
1210
1210
    set by the FSF, which makes it easier to update the code to a new
1217
1217
    I'm sure Canonical would do the same).
1218
1218
    As such, Canonical has requested copyright assignments from all of the
1219
1219
    major contributers.
1220
 
    
 
1220
 
1221
1221
    3) If someone wants to add code and not attribute it to Canonical, there
1222
1222
    is a specific list of files that are excluded from this check. And the
1223
1223
    test failure indicates where that is, and how to update it.
1224
 
    
 
1224
 
1225
1225
    4) If anyone feels that I changed a copyright statement incorrectly, just
1226
1226
    let me know, and I'll be happy to correct it. Whenever you have large
1227
1227
    mechanical changes like this, it is possible to make some mistakes.
1228
 
    
 
1228
 
1229
1229
    Just to reiterate, this is a community project, and it is meant to stay
1230
1230
    that way. Core bzr code is copyright Canonical for legal reasons, and
1231
1231
    the tests are just there to help us maintain that.
1242
1242
 
1243
1243
.. _pdb: http://docs.python.org/lib/debugger-commands.html
1244
1244
 
1245
 
If the ``BZR_PDB`` environment variable is set 
 
1245
If the ``BZR_PDB`` environment variable is set
1246
1246
then bzr will go into pdb post-mortem mode when an unhandled exception
1247
1247
occurs.
1248
1248
 
1310
1310
    for automated processing.
1311
1311
    For example: ``bzr log`` should not fail if one of the entries has text
1312
1312
    that cannot be displayed.
1313
 
  
 
1313
 
1314
1314
  strict
1315
1315
    Attempting to print an unprintable character will cause a UnicodeError.
1316
1316
    This is for commands that are intended more as scripting support, rather
1320
1320
    printed a filename with a '?', the wrong file could be deleted. (At the
1321
1321
    very least, the correct file would not be deleted). An error is used to
1322
1322
    indicate that the requested action could not be performed.
1323
 
  
 
1323
 
1324
1324
  exact
1325
1325
    Do not attempt to automatically convert Unicode strings. This is used
1326
1326
    for commands that must handle conversion themselves.
1374
1374
 
1375
1375
To create an extension, add rules to setup.py for building it with pyrex,
1376
1376
and with distutils. Now start with an empty .pyx file. At the top add
1377
 
"include 'yourmodule.py'". This will import the contents of foo.py into this 
 
1377
"include 'yourmodule.py'". This will import the contents of foo.py into this
1378
1378
file at build time - remember that only one module will be loaded at
1379
1379
runtime. Now you can subclass classes, or replace functions, and only your
1380
1380
changes need to be present in the .pyx file.
1381
1381
 
1382
1382
Note that pyrex does not support all 2.4 programming idioms, so some
1383
 
syntax changes may be required. I.e. 
 
1383
syntax changes may be required. I.e.
1384
1384
 
1385
 
 - 'from foo import (bar, gam)' needs to change to not use the brackets. 
1386
 
 - 'import foo.bar as bar' needs to be 'import foo.bar; bar = foo.bar' 
 
1385
 - 'from foo import (bar, gam)' needs to change to not use the brackets.
 
1386
 - 'import foo.bar as bar' needs to be 'import foo.bar; bar = foo.bar'
1387
1387
 
1388
1388
If the changes are too dramatic, consider
1389
1389
maintaining the python code twice - once in the .pyx, and once in the .py,
1666
1666
.. note::
1667
1667
  As well as prioritizing bugs and nominating them against a
1668
1668
  target milestone, Launchpad lets core developers offer to mentor others in
1669
 
  fixing them. 
 
1669
  fixing them.
1670
1670
 
1671
1671
 
1672
1672
..