comparison mercurial/destutil.py @ 28138:5ad2017454ee

destutil: remove current head from list of candidates early While 'hg merge' will refuse to pick a default destination if the working copy is not on a head, this will be a common and valid case for rebase. In this case, we will need to exclude from the candidate destination all descendants from the rebased set. We make a step forward in that direction by removing parents of the working copy from the candidate destinations instead of manually filtering the working copy parent at the end of the process. This will make the extra step of filtering descendant much simpler in a future changeset.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 08 Feb 2016 18:12:06 +0100
parents b54c0246295b
children 5476a7a039c0
comparison
equal deleted inserted replaced
28137:b54c0246295b 28138:5ad2017454ee
210 """find merge destination based on branch heads""" 210 """find merge destination based on branch heads"""
211 node = None 211 node = None
212 parent = repo.dirstate.p1() 212 parent = repo.dirstate.p1()
213 branch = repo.dirstate.branch() 213 branch = repo.dirstate.branch()
214 bheads = repo.branchheads(branch) 214 bheads = repo.branchheads(branch)
215 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
216 215
217 if parent not in bheads: 216 if parent not in bheads:
218 # Case A: working copy if not on a head. 217 # Case A: working copy if not on a head.
219 # 218 #
220 # This is probably a user mistake We bailout pointing at 'hg update' 219 # This is probably a user mistake We bailout pointing at 'hg update'
221 if len(repo.heads()) <= 1: 220 if len(repo.heads()) <= 1:
222 msg, hint = msgdestmerge['nootherheadsbehind'][action] 221 msg, hint = msgdestmerge['nootherheadsbehind'][action]
223 else: 222 else:
224 msg, hint = msgdestmerge['notatheads'][action] 223 msg, hint = msgdestmerge['notatheads'][action]
225 raise error.Abort(msg, hint=hint) 224 raise error.Abort(msg, hint=hint)
226 elif len(nbhs) > 2: 225 # remove current head from the set
227 # Case B: There is more than 2 anonymous heads 226 bheads = [bh for bh in bheads if bh != parent]
227 # filters out bookmarked heads
228 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
229 if len(nbhs) > 1:
230 # Case B: There is more than 1 other anonymous heads
228 # 231 #
229 # This means that there will be more than 1 candidate. This is 232 # This means that there will be more than 1 candidate. This is
230 # ambiguous. We abort asking the user to pick as explicit destination 233 # ambiguous. We abort asking the user to pick as explicit destination
231 # instead. 234 # instead.
232 msg, hint = msgdestmerge['toomanyheads'][action] 235 msg, hint = msgdestmerge['toomanyheads'][action]
233 msg %= (branch, len(bheads)) 236 msg %= (branch, len(bheads) + 1)
234 raise error.Abort(msg, hint=hint) 237 raise error.Abort(msg, hint=hint)
235 elif len(nbhs) <= 1: 238 elif not nbhs:
236 # Case B: There is no other anonymous head that the one we are one 239 # Case B: There is no other anonymous heads
237 # 240 #
238 # This means that there is no natural candidate to merge with. 241 # This means that there is no natural candidate to merge with.
239 # We abort, with various messages for various cases. 242 # We abort, with various messages for various cases.
240 if len(bheads) > 1: 243 if bheads:
241 msg, hint = msgdestmerge['bookmarkedheads'][action] 244 msg, hint = msgdestmerge['bookmarkedheads'][action]
242 elif len(repo.heads()) > 1: 245 elif len(repo.heads()) > 1:
243 msg, hint = msgdestmerge['nootherbranchheads'][action] 246 msg, hint = msgdestmerge['nootherbranchheads'][action]
244 msg %= branch 247 msg %= branch
245 else: 248 else:
246 msg, hint = msgdestmerge['nootherheads'][action] 249 msg, hint = msgdestmerge['nootherheads'][action]
247 raise error.Abort(msg, hint=hint) 250 raise error.Abort(msg, hint=hint)
248 elif parent == nbhs[0]:
249 node = nbhs[-1]
250 else: 251 else:
251 node = nbhs[0] 252 node = nbhs[0]
252 assert node is not None 253 assert node is not None
253 return node 254 return node
254 255