1 \section{Ranking phase}
3 We run the following algorithm:
5 \item Set $\allpatches = \{ \}$.
8 \item Clear out the graph $\hasdirdep$ so it has no edges.
9 \item Execute $\alg{Rank-Recurse}(\pc_0)$
10 \item Until $\allpatches$ remains unchanged.
14 $\alg{Rank-Recurse}(\pc)$ is:
17 \item If we have already done $\alg{Rank-Recurse}(\pc)$ in this
18 ranking iteration, do nothing. Otherwise:
20 \item Add $\pc$ to $\allpatches$ if it is not there already.
21 If it was added, recalculate $\allsrcs$ accordingly.
25 \set S \iassign h(\pcn)
27 \{ \baseof{E} \; | \; E \in \pendsof{\allsrcs}{\pcy} \}
30 and $W \iassign w(h(\pcn))$
32 \item While $\exists_{S \in \set S} S \ge W$,
33 update $W \assign S$ and $\set S \assign \set S \, \backslash \{ S \}$
35 (This will often remove $W$ from $\set S$. Afterwards, $\set S$
36 is a collection of heads to be merged into $W$.)
38 \item Choose an ordering of $\set S$, $S_i$ for $i=1 \ldots n$.
40 \item For each $S_i$ in turn, choose a corresponding $M_i$
42 M_i \le S_i \land \left[
43 M_i \le W \lor \bigexists_{j<i} M_i \le S_j
47 \item Set $\Gamma \iassign \depsreqof{W}$.
49 If there are multiple candidates we prefer $M_i \in \pcn$
52 \item For each $i \ldots 1..n$, update our putative direct
55 \Gamma \assign \setmergeof{
59 M_i \in \pcn : & \depsreqof{M_i} \\
60 M_i \not\in \pcn : & \{ \}
67 TODO define $\setmerge$
69 \item Finalise our putative direct dependencies
71 \Gamma \assign g(\pc, \Gamma)
74 \item For each direct dependency $\pd \in \Gamma$,
77 \item Add an edge $\pc \hasdirdep \pd$ to the digraph (adding nodes
79 If this results in a cycle, abort entirely (as the function $g$ is
80 inappropriate; a different $g$ could work).
81 \item Run $\alg{Rank-Recurse}(\pd)$.
86 \subsection{Results of the ranking phase}
88 By the end of the ranking phase, we have recorded the following
93 $ \allpatches, \hasdirdep $ and hence the completion of $\hasdirdep$
94 into the partial order $\hasdep$.
97 For each $\pc \in \allpatches$,
98 the base branch starting point commit $W^{\pcn} = W$.
102 the direct dependencies $\Gamma^{\pc} = \Gamma$.
106 the ordered set of base branch sources $\set S^{\pcn} = \set S,
108 and corresponding merge bases $M^{\pcn}_i = M_i$.
112 \subsection{Proof of termination}
114 $\alg{Rank-Recurse}(\pc)$ recurses but only downwards through the
115 finite graph $\hasdirdep$, so it must terminate.
117 The whole ranking algorithm iterates but each iteration involves
118 adding one or more patches to $\allpatches$. Since there are
119 finitely many patches and we never remove anything from $\allpatches$
120 this must complete eventually.