chiark / gitweb /
eff0adfd8ca423dd3668b48c386189f352d086cc
[topbloke-formulae.git] / strategy.tex
1 When we are trying to do an update of some kind, in general,
2 for each patch $\pc$
3 we want to merge some source commits $S \in \set S_{\pc}$.
4 We require $\patchof{S} = \pc$,
5 and $\tipcc \in \set S_{\pc}$.
6
7 \stdsection{Notation}
8
9 \begin{basedescript}{
10 \desclabelwidth{5em}
11 \desclabelstyle{\nextlinelabel}
12 }
13 \item[ $\depsreqof{K}$ ]
14 The set of direct dependencies (in the form $\py$)
15 requested in the commit $K$ ($K \in \pn$) for the patch $\p$.
16
17 \item[ $\pc \hasdirdep \p$ ]
18 The Topbloke commit set $\pc$ has as a direct contributor the
19 commit set $\p$.  This is an acyclic relation.
20
21 \item[ $\p \hasdep \pq$ ]
22 The commit set $\p$ has as direct or indirect contributor the commit
23 set $\pq$.
24 Acyclic; the completion of $\hasdirdep$ into a
25 partial order.
26
27 %\item[ $\set E_{\pc}$ ]
28 %$ \bigcup_i \pendsof{S_{\pc,i}}{\pc} $.
29 %All the ends of $\pc$ in the sources.
30
31 \item[ $ \tipzc, \tipcc, \tipuc, \tipfc $ ]
32 The git ref for the Topbloke commit set $\pc$: respectively,
33 the original, current, updated, and final values.
34
35 \end{basedescript}
36
37 \section{Planning phase}
38
39 The results of the planning phase consist of: 
40 \begin{itemize*}
41 \item{ The relation $\hasdirdep$ and hence the partial order $\hasdep$. }
42 \item{ For each commit set $\pc$, a confirmed set of sources $\set S_{\pc}$. }
43 \item{ For each commit set $\pc$, the order in which to merge the sources
44         $E_{\pc,j} \in \set E_{\pc}$. }
45 \item{ For each $E_{\pc,j}$ an intended merge base $M_{\pc,j}$. }
46 \end{itemize*}
47
48 We use a recursive planning algorith, recursing over Topbloke commit
49 sets (ie, sets $\py$ or $\pn$).  We'll call the commit set we're
50 processing at each step $\pc$.
51 At each recursive step 
52 we make a plan to merge all $\set E_{\pc} = \{ E_{\pc,j \ldots} \}$
53 and all the direct contributors of $\pc$ (as determined below)
54 into $\tipzc$, to make $\tipfc$.
55
56 We start with $\pc = \pl$ where $\pl = \patchof{L}$.
57
58
59 \subsection{Direct contributors for $\pc = \pcn$}
60
61 The direct contributors of $\pcn$ are the commit sets corresponding to
62 the tip branches for the direct dependencies of the patch $\pc$.  We
63 need to calculate what the direct dependencies are going to be.
64
65 Choose an (arbitrary, but ideally somehow optimal in
66 a way not discussed here) ordering of $\set E_{\pc}$, $E_{\pc,j}$
67 ($j = 1 \ldots m$).
68 For brevity we will write $E_j$ for $E_{\pc,j}$.
69 Remove from that set (and ordering) any $E_j$ which
70 are $\le$ and $\neq$ some other $E_k$.
71
72 Initially let $\set D_0 = \depsreqof{\tipzc}$.
73 For each $E_j$ starting with $j=1$ choose a corresponding intended
74 merge base $M_j$ such that $M_j \le E_j \land M_j \le T_{\pc,j-1}$.
75 Calculate $\set D_j$ as the 3-way merge of the sets $\set D_{j-1}$ and
76 $\depsreqof{E_j}$ using as a base $\depsreqof{M_j}$.  This will
77 generate $D_m$ as the putative direct contributors of $\pcn$.
78
79 However, the invocation may give instructions that certain direct
80 dependencies are definitely to be included, or excluded.  As a result
81 the set of actual direct contributors is some arbitrary set of patches
82 (strictly, some arbitrary set of Topbloke tip commit sets).
83
84 \subsection{Direct contributors for $\pc = \pcy$}
85
86 The sole direct contributor of $\pcy$ is $\pcn$.
87
88 \subsection{Recursive step}
89
90 For each direct contributor $\p$, we add the edge $\pc \hasdirdep \p$
91 and augment the ordering $\hasdep$ accordingly.
92
93 If this would make a cycle in $\hasdep$, we abort . The operation must
94 then be retried by the user, if desired, but with different or
95 additional instructions for modifying the direct contributors of some
96 $\pqn$ involved in the cycle.
97
98 For each such $\p$, after updating $\hasdep$, we recursively make a plan
99 for $\pc' = \p$.
100
101
102
103 \section{Execution phase}
104
105 We process commit sets from the bottom up according to the relation
106 $\hasdep$.  For each commit set $\pc$ we construct $\tipfc$ from
107 $\tipzc$, as planned.  By construction, $\hasdep$ has $\patchof{L}$
108 as its maximum, so this operation will finish by updating
109 $\tipca{\patchof{L}}$ with $\tipfa{\patchof{L}}$.
110
111 After we are done with each commit set $\pc$, the
112 new tip $\tipfc$ has the following properties:
113 \[ \eqn{Tip Sources}{
114   \bigforall_{E_i \in \set E_{\pc}} \tipfc \ge E_i
115 }\]
116 \[ \eqn{Tip Dependencies}{
117   \bigforall_{\pc \hasdep \p} \tipfc \ge \tipfa \p
118 }\]
119 \[ \eqn{Perfect Contents}{
120   \tipfc \haspatch \p \equiv \pc \hasdep \py
121 }\]
122
123 For brevity we will sometimes write $\tipu$ for $\tipuc$, etc.  We will start
124 out with $\tipc = \tipz$, and at each step of the way construct some
125 $\tipu$ from $\tipc$.  The final $\tipu$ becomes $\tipf$.
126
127 \subsection{Preparation}
128
129 Firstly, we will check each $E_i$ for being $\ge \tipc$.  If
130 it is, are we fast forward to $E_i$
131 --- formally, $\tipu = \text{max}(\tipc, E_i)$ ---
132 and drop $E_i$ from the planned ordering.
133
134 Then we will merge the direct contributors and the sources' ends.
135 This generates more commits $\tipuc \in \pc$, but none in any other
136 commit set.  We maintain
137 $$
138  \bigforall_{\p \isdep \pc}
139  \pancsof{\tipcc}{\p} \subset
140    \pancsof{\tipfa \p}{\p}
141 $$
142 \proof{
143  For $\tipcc = \tipzc$, $T$ ...WRONG WE NEED $\tipfa \p$ TO BE IN $\set E$ SOMEHOW
144 }
145
146 \subsection{Merge Contributors for $\pcy$}
147
148 Merge $\pcn$ into $\tipc$.  That is, merge with
149 $L = \tipc, R = \tipfa{\pcn}, M = \baseof{\tipc}$.
150 to construct $\tipu$.
151
152 Merge conditions:
153
154 Ingredients satisfied by construction.
155 Tip Merge satisfied by construction.  Merge Acyclic follows
156 from Perfect Contents and $\hasdep$ being acyclic.
157
158 Removal Merge Ends: For $\p = \pc$, $M \nothaspatch \p$; OK.
159 For $\p \neq \pc$, by Tip Contents,
160 $M \haspatch \p \equiv L \haspatch \p$, so we need only
161 worry about $X = R, Y = L$; ie $L \haspatch \p$,
162 $M = \baseof{L} \haspatch \p$.
163 By Tip Contents for $L$, $D \le L \equiv D \le M$.  OK.~~$\qed$
164
165 WIP UP TO HERE
166
167 Addition Merge Ends: If $\py \isdep \pcn$, we have already
168 done the execution phase for $\pcn$ and $\py$.  By
169 Perfect Contents for $\pcn$, $\tipfa \pcn \haspatch \p$ i.e.
170 $R \haspatch \p$.  So we only need to worry about $Y = R = \tipfa \pcn$.
171 By Tip Dependencies $\tipfa \pcn \ge \tipfa \py$.
172 And by Tip Sources $\tipfa \py \ge $
173
174 want to prove $E \le \tipfc$ where $E \in \pendsof{\tipcc}{\py}$
175
176 $\pancsof{\tipcc}{\py} = $
177
178
179 computed $\tipfa \py$, and by Perfect Contents for $\py$
180
181
182 with $M=M_j, L=T_{\pc,j-1}, R=E_j$,
183 and calculate what the resulting desired direct dependencies file
184 (ie, the set of patches $\set D_j$)
185 would be.  Eventually we 
186
187 So, formally, we select somehow an order of sources $S_i$.  For each 
188
189
190 Make use of the following recursive algorithm, Plan 
191
192
193
194
195  recursively make a plan to merge all $E = \pends$
196
197 Specifically, in