comparison hgext/obsolete.py @ 337:ebfd1b96a013 stable

obsolete: convert try to guess what invalid node id are invalid input are probably short version of node
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 04 Jul 2012 18:00:43 +0200
parents 7db8107eef30
children b922d144f93d
comparison
equal deleted inserted replaced
336:7db8107eef30 337:ebfd1b96a013
567 567
568 @command('debugconvertobsolete', [], '') 568 @command('debugconvertobsolete', [], '')
569 def cmddebugconvertobsolete(ui, repo): 569 def cmddebugconvertobsolete(ui, repo):
570 """import markers from an .hg/obsolete-relations file""" 570 """import markers from an .hg/obsolete-relations file"""
571 cnt = 0 571 cnt = 0
572 error = 0 572 err = 0
573 l = repo.lock() 573 l = repo.lock()
574 some = False 574 some = False
575 try: 575 try:
576 repo._importoldobsolete = True 576 repo._importoldobsolete = True
577 store = repo.obsstore 577 store = repo.obsstore
599 ### second (json) format 599 ### second (json) format
600 data = repo.sopener.tryread('obsoletemarkers') 600 data = repo.sopener.tryread('obsoletemarkers')
601 if data: 601 if data:
602 some = True 602 some = True
603 for oldmark in json.loads(data): 603 for oldmark in json.loads(data):
604 del oldmark['id'] # dropped for now 604 del oldmark['id'] # dropped for now
605 del oldmark['reason'] # unused until then 605 del oldmark['reason'] # unused until then
606 oldobject = oldmark['object'] 606 oldobject = str(oldmark.pop('object'))
607 oldsubjects = oldmark['subjects'] 607 oldsubjects = [str(s) for s in oldmark.pop('subjects')]
608 oldmark['subjects'] = [bin(n) for n in oldmark['subjects']] 608 if len(oldobject) != 40:
609 oldmark['object'] = bin(oldmark['object']) 609 try:
610 oldobject = repo[oldobject].node()
611 except error.RepoLookupError:
612 pass
613 if any(len(s) != 40 for s in oldsubjects):
614 try:
615 oldsubjects = [repo[s].node() for s in oldsubjects]
616 except error.RepoLookupError:
617 pass
618
610 oldmark['date'] = '%i %i' % tuple(oldmark['date']) 619 oldmark['date'] = '%i %i' % tuple(oldmark['date'])
611 assert oldmark['object'], repr(oldmark['object'])
612 try: 620 try:
613 store.create(oldmark.pop('object'), 621 store.create(bin(oldobject), [bin(n) for n in oldsubjects],
614 oldmark.pop('subjects'),
615 0, oldmark) 622 0, oldmark)
616 except ValueError: 623 except ValueError:
617 repo.ui.write_err("invalid marker %s -> %s\n" 624 repo.ui.write_err("invalid marker %s -> %s\n"
618 % (oldobject, oldsubjects)) 625 % (oldobject, oldsubjects))
619 error += 1 626 err += 1
620 cnt += 1 627 cnt += 1
621 util.unlink(repo.sjoin('obsoletemarkers')) 628 util.unlink(repo.sjoin('obsoletemarkers'))
622 finally: 629 finally:
623 del repo._importoldobsolete 630 del repo._importoldobsolete
624 l.release() 631 l.release()
625 if not some: 632 if not some:
626 ui.warn('nothing to do\n') 633 ui.warn('nothing to do\n')
627 ui.status('%i obsolete marker converted\n' % cnt) 634 ui.status('%i obsolete marker converted\n' % cnt)
628 if error: 635 if err:
629 ui.write_err('%i conversion failed. check you graph!\n' % error) 636 ui.write_err('%i conversion failed. check you graph!\n' % err)
630 637
631 @command('debugsuccessors', [], '') 638 @command('debugsuccessors', [], '')
632 def cmddebugsuccessors(ui, repo): 639 def cmddebugsuccessors(ui, repo):
633 """dump obsolete changesets and their successors 640 """dump obsolete changesets and their successors
634 641