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