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