Merge lp:~spiv/bzr/fetch-dev-docs into lp:bzr

Proposed by Andrew Bennetts
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 5612
Proposed branch: lp:~spiv/bzr/fetch-dev-docs
Merge into: lp:bzr
Prerequisite: lp:~spiv/bzr/fetch-spec-everything-not-in-other
Diff against target: 102 lines (+87/-0)
2 files modified
doc/developers/fetch.txt (+86/-0)
doc/developers/index.txt (+1/-0)
To merge this branch: bzr merge lp:~spiv/bzr/fetch-dev-docs
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+46053@code.launchpad.net

Commit message

Add a developer doc on the topic of fetch.

Description of the change

This is the start of a developer doc explaining how fetch works, as suggested in a review comment on <https://code.launchpad.net/~spiv/bzr/fetch-spec-everything-not-in-other/+merge/42811>. More could be said, but hopefully even this short text is already valuable.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

nice, thanks!

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'doc/developers/fetch.txt'
2--- doc/developers/fetch.txt 1970-01-01 00:00:00 +0000
3+++ doc/developers/fetch.txt 2011-01-13 00:47:19 +0000
4@@ -0,0 +1,86 @@
5+=============
6+Fetching data
7+=============
8+
9+Overview of a fetch
10+===================
11+
12+Inside bzr, a typical fetch happens like this:
13+
14+* a user runs a command like ``bzr branch`` or ``bzr pull``
15+
16+* ``Repository.fetch`` is called (by a higher-level method such as
17+ ``ControlDir.sprout``, ``Branch.fetch``, etc).
18+
19+* An ``InterRepository`` object is created. The exact implementation of
20+ ``InterRepository`` chosen depends on the format/capabilities of the
21+ source and target repos.
22+
23+* The source and target repositories are compared to determine which data
24+ needs to be transferred.
25+
26+* The repository data is copied. Often this is done by creating a
27+ ``StreamSource`` and ``StreamSink`` from the source and target
28+ repositories and feeding the stream from the source into the sink, but
29+ some ``InterRepository`` implementations do differently.
30+
31+
32+How objects to be transferred are determined
33+============================================
34+
35+See ``InterRepository._walk_to_common_revisions``. The basic idea is to
36+do a breadth-first search in the source repository's revision graph
37+(starting from the head or heads the caller asked for), and look in the
38+target repository to see if those revisions are already present.
39+Eventually this will find the common ancestors in both graphs, and thus
40+the set of revisions to be copied has been identified.
41+
42+All inventories for the copied revisions need to be present (and all
43+parent inventories at the stacking boundary too, to support stacking).
44+
45+All texts versions introduced by those inventories need to be transferred
46+(but see also stacking constraints).
47+
48+Fetch specs
49+===========
50+
51+The most ``fetch`` methods accept a ``fetch_spec`` parameter. This is how
52+the caller controls what is fetched: e.g. all revisions for a given head
53+(that aren't already present in the target), the full ancestry for one or
54+more heads, or even the full contents of the source repository.
55+
56+The ``fetch_spec`` parameter is an object that implements the interface
57+defined by ``AbstractSearchResult`` in ``bzrlib.graph``. It describes
58+which keys should be fetched. Current implementations are
59+``SearchResult``, ``PendingAncestryResult``, ``EmptySearchResult``, and
60+``EverythingResult``. Some have options controlling if missing revisions
61+cause errors or not, etc.
62+
63+There are also some “search” objects, which can be used to conveniently
64+construct a search result for common cases: ``EverythingNotInOther`` and
65+``NotInOtherForRevs``. They provide an ``execute`` method that performs
66+the search and returns a search result.
67+
68+Also, ``Graph._make_breadth_first_searcher`` returns an object with a
69+``get_result`` method that returns a search result.
70+
71+
72+Streams
73+=======
74+
75+A **stream** is an iterable of (substream type, substream) pairs.
76+The **substream type** is a ``str`` that will be one of ``texts``,
77+``inventories``, ``inventory-deltas``, ``chk_bytes``, ``revisions`` or
78+``signatures``. A **substream** is a record stream. The format of those
79+records depends on the repository format being streamed, except for
80+``inventory-deltas`` records which are format-independent.
81+
82+A stream source can be constructed with ``repo._get_source(to_format)``,
83+and it provides a ``get_stream(search)`` method (among others). A stream
84+sink can be constructed with ``repo._get_sink()``, and provides an
85+``insert_stream(stream, src_format, resume_tokens)`` method (among
86+others).
87+
88+
89+..
90+ vim: ft=rst tw=74 ai
91
92=== modified file 'doc/developers/index.txt'
93--- doc/developers/index.txt 2010-10-13 04:13:48 +0000
94+++ doc/developers/index.txt 2011-01-13 00:47:19 +0000
95@@ -38,6 +38,7 @@
96
97 transports
98 ui
99+ fetch
100
101 Releasing and Packaging
102 =======================