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