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