interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / technical / connectivity-check.adoc

259 lines · 9908 bytes Raw Blame History
1Connectivity checking
2=====================
3
4After receiving new objects via fetch, push (receive-pack), clone,
5or bundle, Git verifies that the new reference tips do not leave
6the repository in a state where reachable objects are missing.
7This verification is called the connectivity check.
8
9Connectivity invariant
10----------------------
11
12A repository is connected when every object reachable from its
13references is available locally (with exceptions noted below).
14The reverse does not hold: objects that exist in the object
15database but are not reachable from any reference may be
16incomplete or lack a connected closure.
17
18The connectivity check maintains this invariant when references
19are updated. It trusts that all objects reachable from existing
20reference tips are already fully connected and verifies that the
21new reference tips do not introduce references to unavailable
22objects. Verification is permitted to stop when it reaches
23objects already reachable from existing references, since their
24closure is already connected. These trusted references include
25local references and references from alternate object stores.
26
27Without this check, a truncated or corrupted transfer could leave
28a repository in a state where later history walks encounter
29missing objects.
30
31Exceptions
32~~~~~~~~~~
33
34Gitlink entries (submodule references) are excluded from
35connectivity checking. Their target objects belong to a separate
36repository.
37
38In partial clones, objects promised by a promisor remote are
39accepted as connected without requiring local existence. The
40check excludes promisor objects from traversal so that it does
41not trigger on-demand fetches for them.
42
43Full connectivity check
44-----------------------
45
46The full connectivity check runs a `rev-list` subprocess, feeding
47the new reference tips via stdin. A normal invocation is roughly:
48
49 git rev-list --objects --stdin --not --all --quiet
50 --alternate-refs [--exclude-promisor-objects]
51
52In a partial clone, objects received from a promisor remote do
53not need to be checked: anything they reference is promised by
54that remote and can be fetched on demand. So if every new tip is
55found in a promisor packfile, `rev-list` is not run at all.
56Otherwise it runs with `--exclude-promisor-objects`, so that the
57traversal stops at promisor objects instead of fetching them.
58
59Consider the following graph after a fetch, where all reference
60tips point directly to commits. For simplicity, only local
61references appear on the already-connected side; alternate refs
62play the same role. N3 is a merge commit:
63
64 /-------------L2
65 /
66 C1---B1---C2---B2-----L1
67 \ \
68 N1 N3---T2
69 \ /
70 N2-----------T1
71
72 L1, L2: local refs
73 T1, T2: incoming tips (new refs)
74 N1, N2, N3: incoming commits (N3 is a merge)
75 B1, B2: boundary commits (already connected)
76 C1, C2: already connected (but not boundary)
77
78The incoming set is the commits reachable from the incoming
79tips but not from the already-connected side. Boundary commits
80are the already-connected commits at the edge of that set. Here
81B1 is an ancestor of B2, which happens when incoming branches
82fork at different depths in the existing history.
83
84The `--not --all` arguments establish the trust boundary: the
85incoming set is the commits reachable from the new tips but not
86from any existing reference.
87
88The traversal then walks the trees of the boundary commits and
89marks those objects uninteresting. Trees of incoming commits
90are then walked, stopping at objects already marked as
91uninteresting. The cost of marking boundary trees uninteresting
92dominates when the boundary commits have large trees, even when
93the incoming changes are small.
94
95Deepening fetches
96~~~~~~~~~~~~~~~~~
97
98For deepening fetches (where the shallow boundary moves), the
99full check omits `--not --all`. There is no existing-reference
100boundary at which the walk can stop. Instead, traversal follows
101the effective shallow boundary supplied for the deepened
102repository. The new content may be below the old shallow
103boundary even when the tips themselves have not changed.
104
105Non-commit tips
106~~~~~~~~~~~~~~~
107
108When a new reference points to a non-commit object, such as a
109tag, tree, or blob, that object is not part of the commit walk.
110These non-commit tips are verified during the tree and blob
111traversal that follows the commit walk within the same rev-list
112invocation.
113
114Incremental connectivity check
115------------------------------
116
117The incremental mode, selected by
118`transfer.connectivityCheck=incremental`, avoids traversing the
119full tree walk of the boundary commits. Instead, it verifies
120each incoming commit's tree against the already-trusted trees of
121its parent commits.
122
123The same `--not --all` boundary as the full check identifies the
124incoming commits. The incremental mode reuses this boundary but
125replaces what happens afterwards: rather than walking boundary
126trees to mark objects uninteresting, it compares each incoming
127commit's tree against its parents' trees, processing commits in
128topological order (ancestors first). This all happens inside
129the same `rev-list` invocation, and the promisor fast path above
130still runs first.
131
132Trust model
133~~~~~~~~~~~
134
135A tree is trusted when its transitive object closure is known to
136be connected.
137
138Every parent of an incoming commit is either on the
139already-connected side of the `--not --all` boundary (a boundary
140parent whose tree is trusted by definition) or is an earlier
141incoming commit that was already verified due to the topological
142processing order. In both cases the parent's tree is trusted, so
143all parent trees can be unconditionally used as comparison bases.
144
145Once an incoming commit's tree has been verified, it is trusted
146and can serve as a comparison base for later descendants. This
147gives an inductive correctness argument: the base case is the
148trust boundary established by `--not --all`, and the inductive
149step is that verifying a commit extends the trusted set.
150
151Tree states
152~~~~~~~~~~~
153
154The verifier tracks tree OIDs in three states:
155
156untrusted::
157 The tree has not yet been established as connected. This
158 is the implicit state of an OID not present in the state
159 map.
160
161trusted::
162 The tree is known to have a connected transitive closure,
163 but its direct entries have not yet been published into the
164 verifier's trusted object sets.
165
166expanded::
167 The tree is trusted and its direct non-gitlink entries
168 have also been published into the trusted object sets.
169
170State transitions are monotonic: a tree may move from untrusted
171to trusted to expanded, but never backwards. An untrusted tree
172that is successfully verified goes directly to expanded.
173
174Blobs require only trusted/untrusted state: a blob becomes
175trusted when it is found in a trusted tree or when its existence
176and type have been verified directly.
177
178The trusted/expanded distinction is an optimization. An expanded
179parent does not need to be reread merely to publish entries that
180are already trusted, though it may still be read when same-path
181subtree bases are needed for recursive comparison.
182
183Algorithm
184~~~~~~~~~
185
186At a high level:
187
188 verify(commits):
189 sort topologically (ancestors first)
190 for each commit:
191 mark parent root trees as trusted
192 verify_tree(commit.tree, parent root trees)
193
194 verify_tree(tree, base_trees):
195 if tree already trusted: return
196 read tree, collect entries not already trusted
197 for each available base tree:
198 publish its entries as trusted
199 record same-path subtrees as bases
200 for each collected entry:
201 if now trusted: skip
202 if blob: verify blob connectivity and type
203 if tree: verify_tree(entry, its recorded bases)
204 mark tree as expanded
205
206The important ordering within `verify_tree` is that entries from
207the new tree are collected before the base trees are scanned, but
208are processed only afterwards. Trust learned from any base can
209therefore eliminate work before recursive verification begins.
210
211Same-path parent subtrees are passed down as comparison bases
212during recursive descent. If no comparison base is available,
213the new subtree is verified from scratch.
214
215Example
216~~~~~~~
217
218Consider a commit that changes one file under `lib/` and moves an
219unchanged subtree from `src/` to `dev/`:
220
221 Parent tree New tree
222 +-- src/ (aaa) +-- dev/ (aaa)
223 +-- lib/ (bbb) +-- lib/ (ccc)
224 +-- foo.c (ddd) +-- foo.c (ddd)
225 +-- bar.c (eee) +-- bar.c (fff)
226
227Scanning the parent makes `aaa` trusted even though it moved from
228`src/` to `dev/`, so that subtree is skipped. The changed `ccc`
229subtree is compared against its same-path parent `bbb`; scanning
230`bbb` makes `ddd` and `eee` trusted, leaving only the new `fff`
231blob to be checked.
232
233This illustrates two properties:
234
235* Trust is OID-based rather than path-based. An unchanged subtree
236 is recognized after a move.
237
238* Same-path parent subtrees provide recursive comparison bases.
239 These bases improve pruning efficiency but are not required for
240 correctness; a new subtree can always be verified from scratch.
241
242Multiple parents
243~~~~~~~~~~~~~~~~
244
245For a merge commit, root trees from all parents are comparison
246bases. When several parents contain a same-path subtree, each
247matching subtree is collected as a recursive comparison base.
248
249Entries published from any trusted parent become globally trusted,
250so a matching tree or blob entry present in any parent can be
251skipped while verifying the merge tree.
252
253Missing comparison bases
254~~~~~~~~~~~~~~~~~~~~~~~~
255
256A promised base tree may not be locally available for comparison.
257In that case the verifier skips that base and verifies the new
258subtree without it. The missing comparison can reduce pruning but
259does not affect correctness.