3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
1 |
============================= |
2 |
Bazaar Architectural Overview |
|
3 |
============================= |
|
4 |
||
5 |
This document describes the key classes and concepts within Bazaar. It is |
|
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
6 |
intended to be useful to people working on the Bazaar codebase, or to |
5225.2.13
by Martin Pool
More reorganization of the developer documentation |
7 |
people writing plugins. People writing plugins may also like to read the |
8 |
guide to `Integrating with Bazaar <integrating.html>`_ for some specific |
|
9 |
recipes. |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
10 |
|
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
11 |
If you have any questions, or if something seems to be incorrect, unclear |
12 |
or missing, please talk to us in ``irc://irc.freenode.net/#bzr``, or write |
|
5225.2.13
by Martin Pool
More reorganization of the developer documentation |
13 |
to the Bazaar mailing list. |
4634.39.12
by Ian Clatworthy
pdf generation of the Developer Guide |
14 |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
15 |
|
5222.2.9
by Robert Collins
Write up some doc about bzrlib.initialize. |
16 |
Using bzrlib |
17 |
############ |
|
18 |
||
19 |
Within bzr |
|
20 |
========== |
|
21 |
||
22 |
When using bzrlib within the ``bzr`` program (for instance as a bzr |
|
23 |
plugin), bzrlib's global state is already available for use. |
|
24 |
||
25 |
From outside bzr |
|
26 |
================ |
|
27 |
||
28 |
To use bzrlib outside of ``bzr`` some global state needs to be setup. |
|
29 |
bzrlib needs ways to handle user input, passwords, a place to emit |
|
30 |
progress bars, logging setup appropriately for your program. The easiest |
|
31 |
way to set all this up in the same fashion ``bzr`` does is to call |
|
32 |
``bzrlib.initialize``. This returns a context manager within which bzrlib |
|
33 |
functions will work correctly. See the pydoc for ``bzrlib.initialize`` for |
|
34 |
more information. In Python 2.4 the ``with`` keyword is not supported and |
|
35 |
so you need to use the context manager manually:: |
|
36 |
||
37 |
# This sets up your ~/.bzr.log, ui factory and so on and so forth. It is |
|
38 |
# not safe to use as a doctest. |
|
39 |
library_state = bzrlib.initialize() |
|
40 |
library_state.__enter__() |
|
41 |
try: |
|
42 |
pass |
|
43 |
# do stuff here |
|
44 |
finally: |
|
45 |
library_state.__exit__(None, None, None) |
|
46 |
||
47 |
||
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
48 |
Core classes |
49 |
############ |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
50 |
|
51 |
Transport |
|
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
52 |
========= |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
53 |
|
54 |
The ``Transport`` layer handles access to local or remote directories. |
|
4144.4.3
by Eric Siegerman
Copy editing. |
55 |
Each Transport object acts as a logical connection to a particular |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
56 |
directory, and it allows various operations on files within it. You can |
57 |
*clone* a transport to get a new Transport connected to a subdirectory or |
|
58 |
parent directory. |
|
59 |
||
60 |
Transports are not used for access to the working tree. At present |
|
61 |
working trees are always local and they are accessed through the regular |
|
4144.4.3
by Eric Siegerman
Copy editing. |
62 |
Python file I/O mechanisms. |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
63 |
|
64 |
Filenames vs URLs |
|
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
65 |
----------------- |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
66 |
|
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
67 |
Transports work in terms of URLs. Take note that URLs are by definition |
68 |
only ASCII - the decision of how to encode a Unicode string into a URL |
|
69 |
must be taken at a higher level, typically in the Store. (Note that |
|
70 |
Stores also escape filenames which cannot be safely stored on all |
|
71 |
filesystems, but this is a different level.) |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
72 |
|
73 |
The main reason for this is that it's not possible to safely roundtrip a |
|
74 |
URL into Unicode and then back into the same URL. The URL standard |
|
75 |
gives a way to represent non-ASCII bytes in ASCII (as %-escapes), but |
|
76 |
doesn't say how those bytes represent non-ASCII characters. (They're not |
|
77 |
guaranteed to be UTF-8 -- that is common but doesn't happen everywhere.) |
|
78 |
||
4144.4.3
by Eric Siegerman
Copy editing. |
79 |
For example, if the user enters the URL ``http://example/%e0``, there's no |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
80 |
way to tell whether that character represents "latin small letter a with |
4144.4.3
by Eric Siegerman
Copy editing. |
81 |
grave" in iso-8859-1, or "latin small letter r with acute" in iso-8859-2, |
82 |
or malformed UTF-8. So we can't convert the URL to Unicode reliably. |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
83 |
|
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
84 |
Equally problematic is if we're given a URL-like string containing |
85 |
(unescaped) non-ASCII characters (such as the accented a). We can't be |
|
86 |
sure how to convert that to a valid (i.e. ASCII-only) URL, because we |
|
87 |
don't know what encoding the server expects for those characters. |
|
88 |
(Although it is not totally reliable, we might still accept these and |
|
89 |
assume that they should be put into UTF-8.) |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
90 |
|
4144.4.2
by Eric Siegerman
Uppercase acronyms. |
91 |
A similar edge case is that the URL ``http://foo/sweet%2Fsour`` contains |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
92 |
one directory component whose name is "sweet/sour". The escaped slash is |
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
93 |
not a directory separator, but if we try to convert the URL to a regular |
94 |
Unicode path, this information will be lost. |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
95 |
|
4144.4.3
by Eric Siegerman
Copy editing. |
96 |
This implies that Transports must natively deal with URLs. For simplicity |
97 |
they *only* deal with URLs; conversion of other strings to URLs is done |
|
4144.4.4
by Eric Siegerman
Line-wrap changed paragraphs. |
98 |
elsewhere. Information that Transports return, such as from ``list_dir``, |
99 |
is also in the form of URL components. |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
100 |
|
101 |
||
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
102 |
WorkingTree |
103 |
=========== |
|
104 |
||
105 |
A workingtree is a special type of Tree that's associated with a working |
|
106 |
directory on disk, where the user can directly modify the files. |
|
107 |
||
108 |
Responsibilities: |
|
109 |
||
110 |
* Maintaining a WorkingTree on disk at a file path. |
|
111 |
* Maintaining the basis inventory (the inventory of the last commit done) |
|
112 |
* Maintaining the working inventory. |
|
113 |
* Maintaining the pending merges list. |
|
114 |
* Maintaining the stat cache. |
|
115 |
* Maintaining the last revision the working tree was updated to. |
|
116 |
* Knows where its Branch is located. |
|
117 |
||
118 |
Dependencies: |
|
119 |
||
120 |
* a Branch |
|
121 |
* an MutableInventory |
|
122 |
* local access to the working tree |
|
123 |
||
124 |
Branch |
|
125 |
====== |
|
126 |
||
127 |
A Branch is a key user concept - its a single line of history that one or |
|
128 |
more people have been committing to. |
|
129 |
||
130 |
A Branch is responsible for: |
|
131 |
||
132 |
* Holding user preferences that are set in a Branch. |
|
133 |
* Holding the 'tip': the last revision to be committed to this Branch. (And the revno of that revision.) |
|
134 |
* Knowing how to open the Repository that holds its history. |
|
135 |
* Allowing write locks to be taken out to prevent concurrent alterations to the branch. |
|
136 |
||
137 |
Depends on: |
|
138 |
* URL access to its base directory. |
|
139 |
* A Transport to access its files. |
|
140 |
* A Repository to hold its history. |
|
141 |
||
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
142 |
Repository |
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
143 |
========== |
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
144 |
|
145 |
Repositories store committed history: file texts, revisions, inventories, |
|
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
146 |
and graph relationships between them. A repository holds a bag of |
147 |
revision data that can be pointed to by various branches: |
|
148 |
||
149 |
* Maintains storage of various history data at a URL: |
|
150 |
* Revisions (Must have a matching inventory) |
|
151 |
* Digital Signatures |
|
152 |
* Inventories for each Revision. (Must have all the file texts available). |
|
153 |
* File texts |
|
5225.2.15
by Martin Pool
Clarify text about repository write locks in overview doc |
154 |
|
155 |
* Synchronizes concurrent access to the repository by different |
|
156 |
processes. (Most repository implementations use a physical |
|
157 |
mutex only for a short period, and effectively support multiple readers |
|
158 |
and writers.) |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
159 |
|
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
160 |
Stacked Repositories |
5225.2.14
by Martin Pool
Move core class documentation from the wiki into the developer docs |
161 |
-------------------- |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
162 |
|
4144.4.3
by Eric Siegerman
Copy editing. |
163 |
A repository can be configured to refer to a list of "fallback" |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
164 |
repositories. If a particular revision is not present in the original |
165 |
repository, it refers the query to the fallbacks. |
|
166 |
||
167 |
Compression deltas don't span physical repository boundaries. So the |
|
4144.4.3
by Eric Siegerman
Copy editing. |
168 |
first commit to a new, empty repository with fallback repositories will |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
169 |
store a full text of the inventory, and of every new file text. |
170 |
||
171 |
At runtime, repository stacking is actually configured by the branch, not |
|
4853.1.1
by Patrick Regan
Removed trailing whitespace from files in doc directory |
172 |
the repository. So doing ``a_bzrdir.open_repository()`` |
173 |
gets you just the single physical repository, while |
|
174 |
``a_bzrdir.open_branch().repository`` gets one configured with a stacking. |
|
4144.4.3
by Eric Siegerman
Copy editing. |
175 |
Therefore, to permanently change the fallback repository stored on disk, |
4853.1.1
by Patrick Regan
Removed trailing whitespace from files in doc directory |
176 |
you must use ``Branch.set_stacked_on_url``. |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
177 |
|
4144.4.3
by Eric Siegerman
Copy editing. |
178 |
Changing away from an existing stacked-on URL will copy across any |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
179 |
necessary history so that the repository remains usable. |
180 |
||
4144.4.2
by Eric Siegerman
Uppercase acronyms. |
181 |
A repository opened from an HPSS server is never stacked on the server |
3683.1.2
by Martin Pool
Developer documentation of repository stacking |
182 |
side, because this could cause complexity or security problems with the |
183 |
server acting as a proxy for the client. Instead, the branch on the |
|
184 |
server exposes the stacked-on URL and the client can open that. |
|
3683.1.1
by Martin Pool
Improved review process docs and separate out architectural overview |
185 |
|
186 |
||
187 |
.. |
|
188 |
vim: ft=rst tw=74 ai |