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