comparison mercurial/bookmarks.py @ 24473:3f6bf9f29e7b

bookmarks: prevent divergent bookmark from being updated unexpectedly Before this patch, "@99" suffixed bookmark may be updated unexpectedly by the bookmark value on the remote side at "hg pull", if all of "@1" to "@99" suffixed bookmarks exist in the local repository, because variable "n" still refers "@99" suffixed bookmark after the loop to examine "@num" suffixes, even though it already exists in the local repository. This patch prevents divergent bookmark from being updated unexpectedly, and shows warning message in such situation. This patch uses original python script "seq.py" instead of "seq" command to create sequence numbers in the test, because "seq" command may not be available: it isn't defined in recent POSIX specification (POSIX.1-2001 2013 Edition or XPG7)
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 17 Mar 2015 18:20:24 +0900
parents 6ddc86eedc3b
children 194e1e3ebc29
comparison
equal deleted inserted replaced
24472:d6dbe4d1c9bc 24473:3f6bf9f29e7b
361 differ((b, scid, dcid)) 361 differ((b, scid, dcid))
362 362
363 return results 363 return results
364 364
365 def _diverge(ui, b, path, localmarks): 365 def _diverge(ui, b, path, localmarks):
366 '''Return appropriate diverged bookmark for specified ``path``
367
368 This returns None, if it is failed to assign any divergent
369 bookmark name.
370 '''
366 if b == '@': 371 if b == '@':
367 b = '' 372 b = ''
368 # find a unique @ suffix 373 # find a unique @ suffix
369 for x in range(1, 100): 374 for x in range(1, 100):
370 n = '%s@%d' % (b, x) 375 n = '%s@%d' % (b, x)
371 if n not in localmarks: 376 if n not in localmarks:
372 break 377 break
378 else:
379 n = None
373 # try to use an @pathalias suffix 380 # try to use an @pathalias suffix
374 # if an @pathalias already exists, we overwrite (update) it 381 # if an @pathalias already exists, we overwrite (update) it
375 if path.startswith("file:"): 382 if path.startswith("file:"):
376 path = util.url(path).path 383 path = util.url(path).path
377 for p, u in ui.configitems("paths"): 384 for p, u in ui.configitems("paths"):
409 explicit.discard(b) 416 explicit.discard(b)
410 changed.append((b, bin(scid), status, 417 changed.append((b, bin(scid), status,
411 _("importing bookmark %s\n") % (b))) 418 _("importing bookmark %s\n") % (b)))
412 else: 419 else:
413 db = _diverge(ui, b, path, localmarks) 420 db = _diverge(ui, b, path, localmarks)
414 changed.append((db, bin(scid), warn, 421 if db:
415 _("divergent bookmark %s stored as %s\n") 422 changed.append((db, bin(scid), warn,
416 % (b, db))) 423 _("divergent bookmark %s stored as %s\n") %
424 (b, db)))
425 else:
426 warn(_("warning: failed to assign numbered name "
427 "to divergent bookmark %s\n") % (b))
417 for b, scid, dcid in adddst + advdst: 428 for b, scid, dcid in adddst + advdst:
418 if b in explicit: 429 if b in explicit:
419 explicit.discard(b) 430 explicit.discard(b)
420 changed.append((b, bin(scid), status, 431 changed.append((b, bin(scid), status,
421 _("importing bookmark %s\n") % (b))) 432 _("importing bookmark %s\n") % (b)))