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