chiark / gitweb /
a718aecc8b7040f46ee459715344548da5086ec5
[topbloke-formulae.git] / strategy.tex
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
4 for $\patchof{L}$.
5
6 \stdsection{Notation}
7
8 \begin{basedescript}{
9 \desclabelwidth{5em}
10 \desclabelstyle{\nextlinelabel}
11 }
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$.
15
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.
19
20 \item[ $\p \hasdep \pq$ ]
21 The commit set $\p$ has as direct or indirect contributor the commit
22 set $\pq$.
23 Acyclic; the completion of $\hasdirdep$ into a
24 partial order.
25
26 \item[ $\set E_{\pc}$ ]
27 $ \bigcup_i \pendsof{S_i}{\pc} $.
28 All the ends of $\pc$ in the sources.
29
30 \item[ $ \grefzc, \grefcc, \grefuc, \greffc $ ]
31 The git ref for the Topbloke commit set $\pc$: respectively,
32 the original, current, updated, and final values.
33
34 \end{basedescript}
35
36 \section{Planning phase}
37
38 The planning phase computes: 
39 \begin{itemize*}
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}$. }
44 \end{itemize*}
45
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 $\grefzc$, to make $\greffc$.
53
54 We start with $\pc = \pl$ where $\pl = \patchof{L}$.
55
56
57 \subsection{Direct contributors for $\pc = \pcn$}
58
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.
62
63 Choose an (arbitrary, but ideally somehow optimal in
64 a way not discussed here) ordering of $\set E_{\pc}$, $E_{\pc,j}$
65 ($j = 1 \ldots m$).
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$.
69
70 Initially let $\set D_0 = \depsreqof{\grefzc}$.
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$.
76
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).
81
82 \subsection{Direct contributors for $\pc = \pcy$}
83
84 The sole direct contributor of $\pcy$ is $\pcn$.
85
86 \subsection{Recursive step}
87
88 For each direct contributor $\p$, we add the edge $\pc \hasdirdep \p$
89 and augment the ordering $\hasdep$ accordingly.
90
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.
95
96 For each such $\p$, after updating $\hasdep$, we recursively make a plan
97 for $\pc' = \p$.
98
99 \section{Execution phase}
100
101
102
103
104 with $M=M_j, L=T_{\pc,j-1}, R=E_j$,
105 and calculate what the resulting desired direct dependencies file
106 (ie, the set of patches $\set D_j$)
107 would be.  Eventually we 
108
109 So, formally, we select somehow an order of sources $S_i$.  For each 
110
111
112 Make use of the following recursive algorithm, Plan 
113
114
115
116
117  recursively make a plan to merge all $E = \pends$
118
119 Specifically, in