chiark / gitweb /
5bb0db2b79feffdd0be6452064c36c631b65385a
[topbloke-formulae.git] / merge.tex
1 \section{Merge}
2
3 Merge commits $L$ and $R$ using merge base $M$:
4 \gathbegin
5  C \hasparents \{ L, R \}
6 \gathnext
7  \patchof{C} = \patchof{L}
8 \gathnext
9  \commitmergeof{C}{L}{M}{R}
10 \end{gather}
11 We will occasionally use $X,Y$ s.t. $\{X,Y\} = \{L,R\}$.
12
13 This can also be used for dependency re-insertion, by setting $L \in
14 \pn$, $R \in \pry$, $M = \baseof{R}$, provided that the Conditions are
15 satisfied; in particular, provided that $L \ge \baseof{R}$.
16
17 \subsection{Conditions}
18 \[ \eqn{ Ingredients }{
19  M \le L \land M \le R
20 }\]
21 \[ \eqn{ Tip Merge }{
22  L \in \py \implies
23    \begin{cases}
24       R \in \py : & \baseof{R} \ge \baseof{L}
25               \land [\baseof{L} = M \lor \baseof{L} = \baseof{M}] \\
26       R \in \pn : & M = \baseof{L} \\
27       \text{otherwise} : & \false
28    \end{cases}
29 }\]
30 \[ \eqn{ Base Merge }{
31  L \in \pn \implies
32   \big[
33    R \in \pn
34      \lor
35    R \in \foreign
36      \lor
37    R \in \pqy
38   \big]
39 }\]
40 \[ \eqn{ Merge Acyclic }{
41     L \in \pn
42    \implies
43     R \nothaspatch \p
44 }\]
45 \[ \eqn{ Removal Merge Ends }{
46     X \not\haspatch \p \land
47     M \haspatch \p \land
48     Y \haspatch \p
49   \implies
50     \pendsof{Y}{\py} = \pendsof{M}{\py}
51 }\]
52 \[ \eqn{ Addition Merge Ends }{
53     X \not\haspatch \p \land
54     M \nothaspatch \p \land
55     Y \haspatch \p
56    \implies \left[
57     \bigforall_{E \in \pendsof{X}{\py}} E \le Y
58    \right]
59 }\]
60 \[ \eqn{ Suitable Tips }{
61     \bigforall_{\p \neq \patchof{L}, \; C \haspatch \p}
62     \bigexists_T
63       \pendsof{J}{\py} = \{ T \}
64      \land
65       \forall_{E \in \pendsof{K}{\py}} T \ge E
66     , \text{where} \{J,K\} = \{L,R\}
67 }\]
68 \[ \eqn{ Foreign Merges }{
69     \isforeign{L} \implies \isforeign{R}
70 }\]
71
72 \subsection{Non-Topbloke merges}
73
74 We require both $\isforeign{L}$ and $\isforeign{R}$
75 (Foreign Merges, above).
76 I.e. not only is it forbidden to merge into a Topbloke-controlled
77 branch without Topbloke's assistance, it is also forbidden to
78 merge any Topbloke-controlled branch into any plain git branch.
79
80 Given those conditions, Tip Merge and Merge Acyclic do not apply.
81 By Foreign Contents of $L$, $\isforeign{M}$ as well.
82 So by Foreign Contents for any $A \in \{L,M,R\}$,
83 $\forall_{\p, D \in \py} D \not\le A$
84 so $\pendsof{A}{\py} = \{ \}$ and the RHS of both Merge Ends
85 conditions are satisifed.
86
87 So a plain git merge of non-Topbloke branches meets the conditions and
88 is therefore consistent with our model.
89
90 \subsection{No Replay}
91
92 By definition of \commitmergename,
93 $D \isin C \implies D \isin L \lor D \isin R \lor D = C$.
94 So, by Ingredients,
95 Ingredients Prevent Replay applies.  $\qed$
96
97 \subsection{Unique Base}
98
99 Need to consider only $C \in \py$, ie $L \in \py$,
100 and calculate $\pendsof{C}{\pn}$.  So we will consider some
101 putative ancestor $A \in \pn$ and see whether $A \le C$.
102
103 By Exact Ancestors for C, $A \le C \equiv A \le L \lor A \le R \lor A = C$.
104 But $C \in \py$ and $A \in \pn$ so $A \neq C$.
105 Thus $A \le C \equiv A \le L \lor A \le R$.
106
107 By Unique Base of L and Transitive Ancestors,
108 $A \le L \equiv A \le \baseof{L}$.
109
110 \subsubsection{For $R \in \py$:}
111
112 By Unique Base of $R$ and Transitive Ancestors,
113 $A \le R \equiv A \le \baseof{R}$.
114
115 But by Tip Merge condition on $\baseof{R}$,
116 $A \le \baseof{L} \implies A \le \baseof{R}$, so
117 $A \le \baseof{R} \lor A \le \baseof{L} \equiv A \le \baseof{R}$.
118 Thus $A \le C \equiv A \le \baseof{R}$.
119 That is, $\baseof{C} = \baseof{R}$.
120
121 \subsubsection{For $R \in \pn$:}
122
123 By Tip Merge condition and since $M \le R$,
124 $A \le \baseof{L} \implies A \le R$, so
125 $A \le R \lor A \le \baseof{L} \equiv A \le R$.
126 Thus $A \le C \equiv A \le R$.
127 That is, $\baseof{C} = R$.
128
129 $\qed$
130
131 \subsection{Coherence and Patch Inclusion}
132
133 $$
134 \begin{cases}
135   L \nothaspatch \p \land R \nothaspatch \p : & C \nothaspatch \p  \\
136   L \haspatch    \p \land R \haspatch    \p : & C \haspatch    \p  \\
137   \text{otherwise} \land M \haspatch    \p  : & C \nothaspatch \p  \\
138   \text{otherwise} \land M \nothaspatch \p  : & C \haspatch    \p
139 \end{cases}
140 $$
141 \proofstarts
142 ~ Consider $D \in \py$.
143
144 \subsubsection{For $L \nothaspatch \p, R \nothaspatch \p$:}
145 $D \not\isin L \land D \not\isin R$.  $C \not\in \py$ (otherwise $L
146 \in \py$ ie $L \haspatch \p$ by Tip Own Contents for $L$).
147 So $D \neq C$.
148 Applying \commitmergename gives $D \not\isin C$ i.e. $C \nothaspatch \p$.
149 OK.
150
151 \subsubsection{For $L \haspatch \p, R \haspatch \p$:}
152 $D \isin L \equiv D \le L$ and $D \isin R \equiv D \le R$.
153 (Likewise $D \isin X \equiv D \le X$ and $D \isin Y \equiv D \le Y$.)
154
155 Consider $D = C$: $D \isin C$, $D \le C$, OK for $C \zhaspatch \p$.
156
157 For $D \neq C$: $D \le C \equiv D \le L \lor D \le R
158  \equiv D \isin L \lor D \isin R$.
159 (Likewise $D \le C \equiv D \le X \lor D \le Y$.)
160
161 Consider $D \neq C, D \isin X \land D \isin Y$:
162 By \commitmergename, $D \isin C$.  Also $D \le X$
163 so $D \le C$.  OK for $C \zhaspatch \p$.
164
165 Consider $D \neq C, D \not\isin X \land D \not\isin Y$:
166 By \commitmergename, $D \not\isin C$.
167 And $D \not\le X \land D \not\le Y$ so $D \not\le C$.
168 OK for $C \zhaspatch \p$.
169
170 Remaining case, wlog, is $D \not\isin X \land D \isin Y$.
171 $D \not\le X$ so $D \not\le M$ so $D \not\isin M$.
172 Thus by \commitmergename, $D \isin C$.  And $D \le Y$ so $D \le C$.
173 OK for $C \zhaspatch \p$.
174
175 So, in all cases, $C \zhaspatch \p$.
176 And by $L \haspatch \p$, $\exists_{F \in \py} F \le L$
177 and this $F \le C$ so indeed $C \haspatch \p$.
178
179 \subsubsection{For (wlog) $X \not\haspatch \p, Y \haspatch \p$:}
180
181 One of the Merge Ends conditions applies.
182 Recall that we are considering $D \in \py$.
183 $D \isin Y \equiv D \le Y$.  $D \not\isin X$.
184 We will show for each of
185 various cases that
186 if $M \haspatch \p$, $D \not\isin C$,
187 whereas if $M \nothaspatch \p$, $D \isin C \equiv D \le C$.
188 And by $Y \haspatch \p$, $\exists_{F \in \py} F \le Y$ and this
189 $F \le C$ so this suffices.
190
191 Consider $D = C$:  Thus $C \in \py, L \in \py$.
192 By Tip Own Contents, $L \haspatch \p$ so $L \neq X$,
193 therefore we must have $L=Y$, $R=X$.
194 Conversely $R \not\in \py$
195 so by Tip Merge $M = \baseof{L}$.  Thus $M \in \pn$ so
196 by Base Acyclic $M \nothaspatch \p$.  By \commitmergename, $D \isin C$,
197 and $D \le C$.  OK.
198
199 Consider $D \neq C, M \nothaspatch \p, D \isin Y$:
200 $D \le Y$ so $D \le C$.
201 $D \not\isin M$ so by \commitmergename, $D \isin C$.  OK.
202
203 Consider $D \neq C, M \nothaspatch \p, D \not\isin Y$:
204 $D \not\le Y$.  If $D \le X$ then
205 $D \in \pancsof{X}{\py}$, so by Addition Merge Ends and
206 Transitive Ancestors $D \le Y$ --- a contradiction, so $D \not\le X$.
207 Thus $D \not\le C$.  By \commitmergename, $D \not\isin C$.  OK.
208
209 Consider $D \neq C, M \haspatch \p, D \isin Y$:
210 $D \le Y$ so $D \in \pancsof{Y}{\py}$ so by Removal Merge Ends
211 and Transitive Ancestors $D \in \pancsof{M}{\py}$ so $D \le M$.
212 Thus $D \isin M$.  By \commitmergename, $D \not\isin C$.  OK.
213
214 Consider $D \neq C, M \haspatch \p, D \not\isin Y$:
215 By \commitmergename, $D \not\isin C$.  OK.
216
217 $\qed$
218
219 \subsection{Base Acyclic}
220
221 This applies when $C \in \pn$.
222 $C \in \pn$ when $L \in \pn$ so by Merge Acyclic, $R \nothaspatch \p$.
223
224 Consider some $D \in \py$.
225
226 By Base Acyclic of $L$, $D \not\isin L$.  By the above, $D \not\isin
227 R$.  And $D \neq C$.  So $D \not\isin C$.
228
229 $\qed$
230
231 \subsection{Tip Contents}
232
233 We need worry only about $C \in \py$.
234 And $\patchof{C} = \patchof{L}$
235 so $L \in \py$ so $L \haspatch \p$.  We will use the Unique Base
236 of $C$, and its Coherence and Patch Inclusion, as just proved.
237
238 Firstly we show $C \haspatch \p$: If $R \in \py$, then $R \haspatch
239 \p$ and by Coherence/Inclusion $C \haspatch \p$ .  If $R \not\in \py$
240 then by Tip Merge $M = \baseof{L}$ so by Base Acyclic and definition
241 of $\nothaspatch$, $M \nothaspatch \p$.  So by Coherence/Inclusion $C
242 \haspatch \p$ (whether $R \haspatch \p$ or $\nothaspatch$).
243
244 We will consider an arbitrary commit $D$
245 and prove the Exclusive Tip Contents form.
246
247 \subsubsection{For $D \in \py$:}
248 $C \haspatch \p$ so by definition of $\haspatch$, $D \isin C \equiv D
249 \le C$.  OK.
250
251 \subsubsection{For $D \not\in \py, R \not\in \py$:}
252
253 $D \neq C$.  By Tip Contents of $L$,
254 $D \isin L \equiv D \isin \baseof{L}$, so by Tip Merge condition,
255 $D \isin L \equiv D \isin M$.  So by \commitmergename, $D \isin
256 C \equiv D \isin R$.  And $R = \baseof{C}$ by Unique Base of $C$.
257 Thus $D \isin C \equiv D \isin \baseof{C}$.  OK.
258
259 \subsubsection{For $D \not\in \py, R \in \py$:}
260
261 $D \neq C$.
262
263 By Tip Contents
264 $D \isin L \equiv D \isin \baseof{L}$ and
265 $D \isin R \equiv D \isin \baseof{R}$.
266
267 Apply Tip Merge condition.
268 If $\baseof{L} = M$, trivially $D \isin M \equiv D \isin \baseof{L}.$
269 Whereas if $\baseof{L} = \baseof{M}$, by definition of $\base$,
270 $\patchof{M} = \patchof{L} = \py$, so by Tip Contents of $M$,
271 $D \isin M \equiv D \isin \baseof{M} \equiv D \isin \baseof{L}$.
272
273 So $D \isin M \equiv D \isin L$ so by \commitmergename,
274 $D \isin C \equiv D \isin R$.  But from Unique Base,
275 $\baseof{C} = \baseof{R}$.
276 Therefore $D \isin C \equiv D \isin \baseof{C}$.  OK.
277
278 $\qed$
279
280 \subsection{Unique Tips}
281
282 For $L \in \py$, trivially $\pendsof{C}{\py} = C$ so $T = C$ is
283 suitable.
284
285 For $L \not\in \py$, $\pancsof{C}{\py} = \pancsof{L}{\py} \cup
286 \pancsof{R}{\py}$.  So $T$ from Suitable Tips is a suitable $T$ for
287 Unique Tips.
288
289 $\qed$
290
291 \subsection{Foreign Inclusion}
292
293 Consider some $D \in \foreign$.
294 By Foreign Inclusion of $L, M, R$:
295 $D \isin L \equiv D \le L$;
296 $D \isin M \equiv D \le M$;
297 $D \isin R \equiv D \le R$.
298
299 \subsubsection{For $D = C$:}
300
301 $D \isin C$ and $D \le C$.  OK.
302
303 \subsubsection{For $D \neq C, D \isin M$:}
304
305 Thus $D \le M$ so $D \le L$ and $D \le R$ so $D \isin L$ and $D \isin
306 R$.  So by \commitmergename, $D \isin C$.  And $D \le C$.  OK.
307
308 \subsubsection{For $D \neq C, D \not\isin M, D \isin X$:}
309
310 By \commitmergename, $D \isin C$.
311 And $D \isin X$ means $D \le X$ so $D \le C$.
312 OK.
313
314 \subsubsection{For $D \neq C, D \not\isin M, D \not\isin L, D \not\isin R$:}
315
316 By \commitmergename, $D \not\isin C$.
317 And $D \not\le L, D \not\le R$ so $D \not\le C$.
318 OK
319
320 $\qed$
321
322 \subsection{Foreign Contents}
323
324 Only relevant if $\isforeign{L}$, in which case
325 $\isforeign{C}$ and by Foreign Merges $\isforeign{R}$,
326 so Totally Foreign Contents applies.  $\qed$
327
328 \subsection{Bases' Children}
329
330 If $L \in \py, R \in \py$: not applicable for either $D=L$ or $D=R$.
331
332 If $L \in \py, R \in \pn$: not applicable for $L$, OK for $R$.
333
334 Other possibilities for $L \in \py$ are excluded by Tip Merge.
335
336 If $L \in \pn, R \in \pn$: satisfied for both $L$ and $R$.
337
338 If $L \in \pn, R \in \foreign$: satisfied for $L$, not applicable for
339 $R$.
340
341 If $L \in \pn, R \in \pqy$: satisfied for $L$, not applicable for
342 $R$.
343
344 Other possibilities for $L \in \pn$ are excluded by Base Merge.
345
346 If $L \in \foreign$: not applicable for $L$; nor for $R$, by Foreign Merges.
347