comparison mercurial/discovery.py @ 22178:70383c6961b4 stable

discovery: prevent crash on unknown remote heads with old repo (issue4337) When a remote is not capable of the `branchmap` wireproto command, we denote incoming heads with None. This leads to a crash in the code in charge of displaying the list of unknown remote heads. We now properly detect this case and display a shorter message in this case. The reason for this `set([None])` value is now documented.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 14 Aug 2014 16:26:41 -0700
parents 32601b0b74c0
children 6ddc86eedc3b
comparison
equal deleted inserted replaced
22177:a56038e6a3c9 22178:70383c6961b4
215 # - another element of outgoing.missing 215 # - another element of outgoing.missing
216 # - nullrev 216 # - nullrev
217 # This explains why the new head are very simple to compute. 217 # This explains why the new head are very simple to compute.
218 r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing) 218 r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing)
219 newheads = list(c.node() for c in r) 219 newheads = list(c.node() for c in r)
220 # set some unsynced head to issue the "unsynced changes" warning
220 unsynced = inc and set([None]) or set() 221 unsynced = inc and set([None]) or set()
221 return {None: (oldheads, newheads, unsynced)} 222 return {None: (oldheads, newheads, unsynced)}
222 223
223 def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False, 224 def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False,
224 newbookmarks=[]): 225 newbookmarks=[]):
311 newhs.add(nh) 312 newhs.add(nh)
312 else: 313 else:
313 newhs = candidate_newhs 314 newhs = candidate_newhs
314 unsynced = sorted(h for h in unsyncedheads if h not in discardedheads) 315 unsynced = sorted(h for h in unsyncedheads if h not in discardedheads)
315 if unsynced: 316 if unsynced:
316 if len(unsynced) <= 4 or repo.ui.verbose: 317 if None in unsynced:
318 # old remote, no heads data
319 heads = None
320 elif len(unsynced) <= 4 or repo.ui.verbose:
317 heads = ' '.join(short(h) for h in unsynced) 321 heads = ' '.join(short(h) for h in unsynced)
318 else: 322 else:
319 heads = (' '.join(short(h) for h in unsynced[:4]) + 323 heads = (' '.join(short(h) for h in unsynced[:4]) +
320 ' ' + _("and %s others") % (len(unsynced) - 4)) 324 ' ' + _("and %s others") % (len(unsynced) - 4))
321 if branch is None: 325 if heads is None:
326 repo.ui.status(_("remote has heads that are "
327 "not known locally\n"))
328 elif branch is None:
322 repo.ui.status(_("remote has heads that are " 329 repo.ui.status(_("remote has heads that are "
323 "not known locally: %s\n") % heads) 330 "not known locally: %s\n") % heads)
324 else: 331 else:
325 repo.ui.status(_("remote has heads on branch '%s' that are " 332 repo.ui.status(_("remote has heads on branch '%s' that are "
326 "not known locally: %s\n") % (branch, heads)) 333 "not known locally: %s\n") % (branch, heads))