##// END OF EJS Templates
merge: with merge.preferancestor=*, run an auction with bids from ancestors...
Mads Kiilerich -
r21128:f4014f64 default
parent child Browse files
Show More
@@ -723,12 +723,69 b' def calculateupdates(repo, wctx, mctx, a'
723 acceptremote, followcopies):
723 acceptremote, followcopies):
724 "Calculate the actions needed to merge mctx into wctx using ancestors"
724 "Calculate the actions needed to merge mctx into wctx using ancestors"
725
725
726 ancestor = ancestors[0]
726 if len(ancestors) == 1: # default
727 actions = manifestmerge(repo, wctx, mctx, ancestors[0],
728 branchmerge, force,
729 partial, acceptremote, followcopies)
727
730
728 actions = manifestmerge(repo, wctx, mctx,
731 else: # only when merge.preferancestor=* - experimentalish code
729 ancestor,
732 # Call for bids
733 fbids = {} # mapping filename to list af action bids
734 for ancestor in ancestors:
735 repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor)
736 actions = manifestmerge(repo, wctx, mctx, ancestor,
730 branchmerge, force,
737 branchmerge, force,
731 partial, acceptremote, followcopies)
738 partial, acceptremote, followcopies)
739 for a in sorted(actions):
740 repo.ui.debug(' %s: %s\n' % (a[0], a[1]))
741 f = a[0]
742 if f in fbids:
743 fbids[f].append(a)
744 else:
745 fbids[f] = [a]
746
747 # Pick the best bid for each file
748 repo.ui.note(_('\nauction for merging merge bids\n'))
749 actions = []
750 for f, bidsl in sorted(fbids.items()):
751 # Consensus?
752 a0 = bidsl[0]
753 if util.all(a == a0 for a in bidsl[1:]): # len(bidsl) is > 1
754 repo.ui.note(" %s: consensus for %s\n" % (f, a0[1]))
755 actions.append(a0)
756 continue
757 # Group bids by kind of action
758 bids = {}
759 for a in bidsl:
760 m = a[1]
761 if m in bids:
762 bids[m].append(a)
763 else:
764 bids[m] = [a]
765 # If keep is an option, just do it.
766 if "k" in bids:
767 repo.ui.note(" %s: picking 'keep' action\n" % f)
768 actions.append(bids["k"][0])
769 continue
770 # If all gets agree [how could they not?], just do it.
771 if "g" in bids:
772 ga0 = bids["g"][0]
773 if util.all(a == ga0 for a in bids["g"][1:]):
774 repo.ui.note(" %s: picking 'get' action\n" % f)
775 actions.append(ga0)
776 continue
777 # TODO: Consider other simple actions such as mode changes
778 # Handle inefficient democrazy.
779 repo.ui.note(_(' %s: multiple merge bids:\n') % (f, m))
780 for a in bidsl:
781 repo.ui.note(' %s: %s\n' % (f, a[1]))
782 # Pick random action. TODO: Instead, prompt user when resolving
783 a0 = bidsl[0]
784 repo.ui.warn(_(' %s: ambiguous merge - picked %s action)\n') %
785 (f, a0[1]))
786 actions.append(a0)
787 continue
788 repo.ui.note(_('end of auction\n\n'))
732
789
733 # Filter out prompts.
790 # Filter out prompts.
734 newactions, prompts = [], []
791 newactions, prompts = [], []
@@ -926,6 +983,10 b' def update(repo, node, branchmerge, forc'
926
983
927 p2 = repo[node]
984 p2 = repo[node]
928 if pas[0] is None:
985 if pas[0] is None:
986 if repo.ui.config("merge", "preferancestor") == '*':
987 cahs = repo.changelog.commonancestorsheads(p1.node(), p2.node())
988 pas = [repo[anc] for anc in (sorted(cahs) or [nullid])]
989 else:
929 pas = [p1.ancestor(p2)]
990 pas = [p1.ancestor(p2)]
930
991
931 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
992 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
@@ -123,4 +123,145 b' Criss cross merging'
123 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
123 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
124 [1]
124 [1]
125
125
126 Redo merge with merge.preferancestor="*" to enable bid merge
127
128 $ rm f*
129 $ hg up -qC .
130 $ hg merge -v --debug --tool internal:dump 5 --config merge.preferancestor="*"
131
132 calculating bids for ancestor 0f6b37dbe527
133 searching for copies back to rev 3
134 resolving manifests
135 branchmerge: True, force: False, partial: False
136 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
137 f1: g
138 f2: m
139
140 calculating bids for ancestor 40663881a6dd
141 searching for copies back to rev 3
142 resolving manifests
143 branchmerge: True, force: False, partial: False
144 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
145 f1: m
146 f2: k
147
148 auction for merging merge bids
149 f1: picking 'get' action
150 f2: picking 'keep' action
151 end of auction
152
153 f1: remote is newer -> g
154 f2: keep -> k
155 getting f1
156 updating: f1 1/1 files (100.00%)
157 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
158 (branch merge, don't forget to commit)
159
160 $ head *
161 ==> f1 <==
162 5 second change
163
164 ==> f2 <==
165 6 second change
166
167
168 The other way around:
169
170 $ hg up -C -r5
171 note: using 0f6b37dbe527 as ancestor of 3b08d01b0ab5 and adfe50279922
172 alternatively, use --config merge.preferancestor=40663881a6dd
173 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
174 $ hg merge -v --debug --config merge.preferancestor="*"
175
176 calculating bids for ancestor 0f6b37dbe527
177 searching for copies back to rev 3
178 resolving manifests
179 branchmerge: True, force: False, partial: False
180 ancestor: 0f6b37dbe527, local: adfe50279922+, remote: 3b08d01b0ab5
181 f1: k
182 f2: m
183
184 calculating bids for ancestor 40663881a6dd
185 searching for copies back to rev 3
186 resolving manifests
187 branchmerge: True, force: False, partial: False
188 ancestor: 40663881a6dd, local: adfe50279922+, remote: 3b08d01b0ab5
189 f1: m
190 f2: g
191
192 auction for merging merge bids
193 f1: picking 'keep' action
194 f2: picking 'get' action
195 end of auction
196
197 f1: keep -> k
198 f2: remote is newer -> g
199 getting f2
200 updating: f2 1/1 files (100.00%)
201 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
202 (branch merge, don't forget to commit)
203
204 $ head *
205 ==> f1 <==
206 5 second change
207
208 ==> f2 <==
209 6 second change
210
211 Verify how the output looks and and how verbose it is:
212
213 $ hg up -qC
214 $ hg merge --config merge.preferancestor="*"
215 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
216 (branch merge, don't forget to commit)
217
218 $ hg up -qC
219 $ hg merge -v --config merge.preferancestor="*"
220
221 calculating bids for ancestor 0f6b37dbe527
222 resolving manifests
223
224 calculating bids for ancestor 40663881a6dd
225 resolving manifests
226
227 auction for merging merge bids
228 f1: picking 'get' action
229 f2: picking 'keep' action
230 end of auction
231
232 getting f1
233 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
234 (branch merge, don't forget to commit)
235
236 $ hg up -qC
237 $ hg merge -v --debug --config merge.preferancestor="*"
238
239 calculating bids for ancestor 0f6b37dbe527
240 searching for copies back to rev 3
241 resolving manifests
242 branchmerge: True, force: False, partial: False
243 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
244 f1: g
245 f2: m
246
247 calculating bids for ancestor 40663881a6dd
248 searching for copies back to rev 3
249 resolving manifests
250 branchmerge: True, force: False, partial: False
251 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
252 f1: m
253 f2: k
254
255 auction for merging merge bids
256 f1: picking 'get' action
257 f2: picking 'keep' action
258 end of auction
259
260 f1: remote is newer -> g
261 f2: keep -> k
262 getting f1
263 updating: f1 1/1 files (100.00%)
264 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
265 (branch merge, don't forget to commit)
266
126 $ cd ..
267 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now