1 When we are trying to do a merge of some kind, in general,
2 we want to merge some source commits $S_0 \ldots S_n$.
3 We'll write $S_0 = L$. We require that $L$ is the current git ref
10 \desclabelstyle{\nextlinelabel}
12 \item[ $\depsreqof{K}$ ]
13 The set of direct dependencies (in the form $\py$)
14 requested in the commit $K$ ($K \in \pn$) for the patch $\p$.
16 \item[ $\pc \hasdirdep \p$ ]
17 The Topbloke commit set $\pc$ has as a direct contributors the
18 commit set $\p$. This is an acyclic relation.
20 \item[ $\p \hasdep \pq$ ]
21 The commit set $\p$ has as direct or indirect contributor the commit
23 Acyclic; the completion of $\hasdirdep$ into a
26 \item[ $\set E_{\pc}$ ]
27 $ \bigcup_i \pendsof{S_i}{\pc} $.
28 All the ends of $\pc$ in the sources.
30 \item[ $ \tipzc, \tipcc, \tipuc, \tipfc $ ]
31 The git ref for the Topbloke commit set $\pc$: respectively,
32 the original, current, updated, and final values.
36 \section{Planning phase}
38 The planning phase computes:
40 \item{ The relation $\hasdirdep$ and hence the ordering $\hasdep$. }
41 \item{ For each commit set $\pc$, the order in which to merge
42 $E_{\pc,j} \in \set E_{\pc}$. }
43 \item{ For each $E_{\pc,j}$ an intended merge base $M_{\pc,j}$. }
46 We use a recursive planning algorith, recursing over Topbloke commit
47 sets (ie, sets $\py$ or $\pn$). We'll call the commit set we're
48 processing at each step $\pc$.
49 At each recursive step
50 we make a plan to merge all $\set E_{\pc} = \{ E_{\pc,j \ldots} \}$
51 and all the direct contributors of $\pc$ (as determined below)
52 into $\tipzc$, to make $\tipfc$.
54 We start with $\pc = \pl$ where $\pl = \patchof{L}$.
57 \subsection{Direct contributors for $\pc = \pcn$}
59 The direct contributors of $\pcn$ are the commit sets corresponding to
60 the tip branches for the direct dependencies of the patch $\pc$. We
61 need to calculate what the direct dependencies are going to be.
63 Choose an (arbitrary, but ideally somehow optimal in
64 a way not discussed here) ordering of $\set E_{\pc}$, $E_{\pc,j}$
66 For brevity we will write $E_j$ for $E_{\pc,j}$.
67 Remove from that set (and ordering) any $E_j$ which
68 are $\le$ and $\neq$ some other $E_k$.
70 Initially let $\set D_0 = \depsreqof{\tipzc}$.
71 For each $E_j$ starting with $j=1$ choose a corresponding intended
72 merge base $M_j$ such that $M_j \le E_j \land M_j \le T_{\pc,j-1}$.
73 Calculate $\set D_j$ as the 3-way merge of the sets $\set D_{j-1}$ and
74 $\depsreqof{E_j}$ using as a base $\depsreqof{M_j}$. This will
75 generate $D_m$ as the putative direct contributors of $\pcn$.
77 However, the invocation may give instructions that certain direct
78 dependencies are definitely to be included, or excluded. As a result
79 the set of actual direct contributors is some arbitrary set of patches
80 (strictly, some arbitrary set of Topbloke tip commit sets).
82 \subsection{Direct contributors for $\pc = \pcy$}
84 The sole direct contributor of $\pcy$ is $\pcn$.
86 \subsection{Recursive step}
88 For each direct contributor $\p$, we add the edge $\pc \hasdirdep \p$
89 and augment the ordering $\hasdep$ accordingly.
91 If this would make a cycle in $\hasdep$, we abort . The operation must
92 then be retried by the user, if desired, but with different or
93 additional instructions for modifying the direct contributors of some
94 $\pqn$ involved in the cycle.
96 For each such $\p$, after updating $\hasdep$, we recursively make a plan
101 \section{Execution phase}
103 We process commit sets from the bottom up according to the relation
104 $\hasdep$. For each commit set $\pc$ we construct $\tipfc$ from
105 $\tipzc$, as planned. By construction, $\hasdep$ has $\patchof{L}$
106 as its maximum, so this operation will finish by updating
107 $\tipca{\patchof{L}}$ with $\tipfa{\patchof{L}}$.
109 After we are done with each commit set $\pc$, the
110 new tip $\tipfc$ has the following properties:
111 \[ \eqn{Tip Sources}{
112 \bigforall_{E_i \in \set E_{\pc}} \tipfc \ge E_i
114 \[ \eqn{Tip Dependencies}{
115 \bigforall_{\pc \hasdep \p} \tipfc \ge \tipfa \p
117 \[ \eqn{Perfect Contents}{
118 \tipfc \haspatch \p \equiv \pc \hasdep \py
121 For brevity we will sometimes write $\tipu$ for $\tipuc$, etc. We will start
122 out with $\tipc = \tipz$, and at each step of the way construct some
123 $\tipu$ from $\tipc$. The final $\tipu$ becomes $\tipf$.
125 \subsection{Preparation}
127 Firstly, we will check each $E_i$ for being $\ge \tipc$. If
128 it is, are we fast forward to $E_i$
129 --- formally, $\tipu = \text{max}(\tipc, E_i)$ ---
130 and drop $E_i$ from the planned ordering.
132 Then we will merge the direct contributors and the sources' ends.
134 This generates more commits $\tipuc \in \pc$, but none in any other
135 commit set. We maintain XXX FIXME IS THIS THE BEST THING?
137 \bigforall_{\p \isdep \pc}
138 \pancsof{\tipcc}{\p} \subset \left[
140 \bigcup_{E \in \set E_{\pc}} \pancsof{E}{\p}
144 \subsection{Merge Contributors for $\pcy$}
146 Merge $\pcn$ into $\tipc$. That is, merge with
147 $L = \tipc, R = \tipfa{\pcn}, M = \baseof{\tipc}$.
148 to construct $\tipu$.
150 Merge conditions: Ingredients satisfied by construction.
151 Tip Merge satisfied by construction. Merge Acyclic follows
152 from Perfect Contents and $\hasdep$ being acyclic.
154 Removal Merge Ends: For $\p = \pc$, $M \nothaspatch \p$.
155 For $p \neq \pc$, by Tip Contents,
156 $M \haspatch \p \equiv L \haspatch \p$, so we need only
157 worry about $X = R, Y = L$; ie $L \haspatch \p$,
158 $M = \baseof{L} \haspatch \p$.
159 By Tip Contents for $L$, $D \le L \equiv D \le M$. $\qed$
163 Addition Merge Ends: If $\py \isdep \pcn$, we have already
164 done the execution phase for $\pcn$ and $\py$. By
165 Perfect Contents for $\pcn$, $\tipfa \pcn \haspatch \p$ i.e.
166 $R \haspatch \p$. So we only need to worry about $Y = R = \tipfa \pcn$.
167 By Tip Dependencies $\tipfa \pcn \ge \tipfa \py$.
168 And by Tip Sources $\tipfa \py \ge $
171 computed $\tipfa \py$, and by Perfect Contents for $\py$
174 with $M=M_j, L=T_{\pc,j-1}, R=E_j$,
175 and calculate what the resulting desired direct dependencies file
176 (ie, the set of patches $\set D_j$)
177 would be. Eventually we
179 So, formally, we select somehow an order of sources $S_i$. For each
182 Make use of the following recursive algorithm, Plan
187 recursively make a plan to merge all $E = \pends$