1 Basic update algorithm:
3 1. recurse to all of our direct dependencies and
4 update their bases and tips
8 i. Compute our base's set of desired included deps:
9 The set of desired included deps for a base
10 is the union of the desired included deps for each
11 branch named in the base's branch's direct deps, plus
12 the name of every direct external dep.
13 The set of desired included deps for a branch
14 is the set of desired included deps for the branch's
15 base plus the branch name itself.
17 ii. For each source in the best order, do the following merge:
18 (Our base has sources:
19 - the branch for each direct dep
21 - the topgit base, if this is a topgit import)
23 Find the (latest) common ancestor.
25 Check for unwanted dependency removals.
26 An unwanted dependency removal is
27 A branch in the desired included deps
28 Which exists in the common ancestor's actual included deps
29 but which is missing in the source's actual included deps
30 (NB that this definition excludes dependency removals
31 which have already occurred on our base; these will be
33 For each unwanted dependency removal (ie for each such
34 branch), search as follows:
35 * An "unwanted removal commit" is a non-merge commit in the
36 history of the source, which removes the dep from the
38 * But the search stops at any point where we would have to
39 traverse a commit where .topbloke/deps is empty (which
40 stops us looking into the hitory of non-topbloke-controlled
41 branches). This can be done with git-rev-list
43 * It also stops at any point where we meet a commit which
44 does have the dep in the actual included deps. We have
46 * The the relevant unwanted removal commit for that dep is
47 the most recent unwanted removal commit, as defined.
48 Select the unwantedly removed dep whose relevant unwanted
49 removal commit is the earliest. Merge from the ancestor of
50 that relevant unwanted removal commit. Merge from the relevant
51 unwanted removal commit using -s ours.
53 Now continue to the next unwanted dependency removal.
55 (The purpose of this, and the result, is that the unwanted
56 dependency removal has gone away. Doing things in this order
57 tries to keep the unwanted dependency removal's reversions as
58 close as possible to their originating points. The
59 recursion, which processes dependencies before their clients,
60 tries to keep the reversion churn localised: client patches
61 of a patch affected by an unwanted removal will benefit from
62 that client's resolution of the situation.)
64 If there are no (more) unwanted dependency removals, merge
68 Check whether our list of dependencies has changed. If so
69 we need to restart the whole base update.
72 Check for missing or unwanted dependency inclusions. Compare
73 our base's desired included deps with our base's actual
74 included deps. In exceptional conditions, they will not
75 be identical. This can happen, for example, because a
76 dependency removal was incorporated into our base branch but
77 the removed branch was introduced as an explicit dependency.
78 This will also happen if we remove a dependency ourselves.
80 Do the unwanted inclusions first, and then the missing ones.
81 (This is because that the missing ones cannot depend on the
82 unwanted ones, as otherwise the unwanted ones would be in the
83 desired inclusions. So removing the unwanted ones first
84 reduces the chances of conflicts.)
87 * Do the comparison between desired and actual included
88 * Pick a missing inclusion, or failing that an unwanted one
89 (call this the "relevant" branch)
90 * Depth first search all of the dependencies of the
91 relevant branch; if any of these is also a missing
92 (resp. unwanted) inclusion, start again processing it
94 * Attempt to apply the appropriate diff to add (resp. remove)
95 the contents of the relevant patch (adjusted appropriately
96 for metadata, XXX??? particularly the actual inclusion list)
97 XXX if we want to add a dep we need to update the dep first
98 * Go round again looking for another discrepancy.
100 3. Update our branch.
101 Our branch has sources:
103 - the remote for our branch
104 - the topgit branch, if this is a topgit import
105 For each source in the best order, do the merge.
107 Double-check the actual dependency inclusions. In
108 particular, if we just upgraded to actual dependency tracking
109 we may need to explicitly add our branch name to the actual
110 dependency inclusion list.
112 The "best order" for merges is in order of recency of common
113 ancestor, most recent first, and if that does not distinguish,
114 merging from local branches first.
116 "Recency" refers to the order from git-rev-list --date-order.
121 - removed patch must be removed from the deps of its
122 ex-children, and replaced with the deps of the removed
125 - removed patch wants not to be in list of patches "tb-list"
127 branches in refs/topbloke-tips ? yes
128 deleted patches do something to the base ? no
130 deleting empty patch: dependencies fine
131 deleting nonempty patch: if any dependencies found, their
135 - remove from views of active patches
136 - prevent new commits
137 - remove from dependencies of active patches
138 only makes sense if no active patches depend on it.
141 - just unmark the patch as deleted
145 When merging from a foreign dependency, check that it
146 does not have .topbloke metadata; LATER if it
147 does, could produce a new commit which has .topbloke removed
151 needs to be globally unique
152 so put email address in it
153 tg operations search for applicable patches
154 safe charset for patch names
156 not permitted (git-check-ref-format(1))
162 When pulling, which remotes get to update which patches ?
163 Complicated question!
165 For now, have "blessed" remotes, which we always pull and update from.
166 All these count as sources above.
168 Update operation restrictions available, which restrict use of various
169 sources above ? What about implications for correctness of merge
173 Concept of a "stack" ?
174 Unnecessary - instead, deal with leaf patches
175 Operations like "go up the stack", goes towards leaf. Hopefully unique.
176 "Down" the stack, uses a "conventional" linearisation
177 Stack reordering op ? auto adjust deps
180 When merging, we need to DTRT with our metadata.
181 Do this by running write-tree/read-tree etc. ourselves ?
182 For a source we're merging from, we make a version where the
183 metadata we shouldn't be merging is removed ?
185 Have discovered that specifying a custom merge driver for a file does
186 not have any effect if the three-way-merge looks trivial based
187 on looking at the file contents - at least, if you use git-merge.
189 Only thing which knows how to do all the gitattributes stuff and
190 conflict markers and what have you is git-merge. (git-merge-tree does
191 too but the output format is unsuitable.) "git-merge-index
192 ... git-merge-one-file" does not honour the merge drivers and is,
193 contrary to what the git docs seem to suggest but don't actually
194 state, not actualy used by git-merge.
196 OK so here is a plan:
197 Use git-merge --no-commit
198 Perhaps on a HEAD, and/or against a tree, which have been massaged
199 to make the metadata suitable as input.
200 Filtering out the "merge was successful but we aren't committing"
201 message. Use a single pipe for stdout/stderr to get interleaving
202 right; the message from git-merge is not i18n'd.
204 Check for merge success in the index and compare to exit status
205 from git-merge (which is 1 if the merge failed).
207 Print appropriate big fat warnings if we have merge conflicts in our
209 Commit, adjusting the parents of the new commit to the original
210 parents if we made the merge with special massaged parents.
211 We may still need to have custom merge drivers for metadata.
214 Strategies for each metadata file merge:
216 in base/tip same patch & branch dep -> base base -> tip
218 msg T textual merge rm from src not in src
219 deps B list merge rm from src rm from src
220 deleted T std existence merge rm from src not in src
221 patch- BT must be same rm from src must be same
222 topgit- B std exist/text merge rm from src rm from src
223 [^+]*- ?? textual merge rm from src rm from src
224 +included BT list merge rm from non-tb src list merge
225 +*- ?? textual merge rm from non-tb src textual merge
226 *[^-] ?? die, aborting all ops, if found in any tb src or branch
232 Unwanted removal search subgraphs:
237 rm impossible to undo removal, arrgh, terminates search
242 inc.. rm.. merge of a removal, search down the rm path
245 inc ??? call it an inclusion, terminate the search
248 inc merge of an inclusion, terminates search
252 inc ??? call it an inclusion, terminate search
257 rm inc inc rm irrelevant
258 rm inc inc inc.. rm rm..
262 OUR BASE SOURCE OUR IT TIP
268 / | ______________'/ \ |
270 / inc REMOVAL rm \ | elsewhere
279 / | | `------------ | ----<-------- | -.| |
281 | |`- | ------------- | ----<--------.| | |
284 | RE-INCLUDE inc rm REMOVAL |' |
288 |`-------------- | ----------. / | |
291 |`.____________ | / | |
293 | | /`--------<----------- | ---. |
296 \ RE-INCLUDE inc / | /
300 \ inc FIRST ADD DEP |/
302 \ | `------------<-------------.|
311 Merge 1* and 2*, diff against some relevant base branch commit
312 or something, and apply to proposed. ???
316 source tip is included in our base
319 * pick common ancestor
320 * compute whether merge from common anc would unwantedly remove
321 * if so we arrange that the common anc is a "rm" but our branch