comparison hgext/obsolete.py @ 361:ac7969043677

obsolete: adapt to core: marker are written in transaction now
author Pierre-Yves.David@ens-lyon.org
date Fri, 13 Jul 2012 13:07:42 +0200
parents 6390ab3aea93
children 1d6cc8c22cd9
comparison
equal deleted inserted replaced
360:6390ab3aea93 361:ac7969043677
542 cnt = 0 542 cnt = 0
543 err = 0 543 err = 0
544 l = repo.lock() 544 l = repo.lock()
545 some = False 545 some = False
546 try: 546 try:
547 repo._importoldobsolete = True 547 unlink = []
548 store = repo.obsstore 548 tr = repo.transaction('convert-obsolete')
549 ### very first format
550 try: 549 try:
551 f = repo.opener('obsolete-relations') 550 repo._importoldobsolete = True
551 store = repo.obsstore
552 ### very first format
552 try: 553 try:
554 f = repo.opener('obsolete-relations')
555 try:
556 some = True
557 for line in f:
558 subhex, objhex = line.split()
559 suc = bin(subhex)
560 prec = bin(objhex)
561 sucs = (suc==nullid) and [] or [suc]
562 meta = {
563 'date': '%i %i' % util.makedate(),
564 'user': ui.username(),
565 }
566 try:
567 store.create(tr, prec, sucs, 0, meta)
568 cnt += 1
569 except ValueError:
570 repo.ui.write_err("invalid old marker line: %s"
571 % (line))
572 err += 1
573 finally:
574 f.close()
575 unlink.append(repo.join('obsolete-relations'))
576 except IOError:
577 pass
578 ### second (json) format
579 data = repo.sopener.tryread('obsoletemarkers')
580 if data:
553 some = True 581 some = True
554 for line in f: 582 for oldmark in json.loads(data):
555 subhex, objhex = line.split() 583 del oldmark['id'] # dropped for now
556 suc = bin(subhex) 584 del oldmark['reason'] # unused until then
557 prec = bin(objhex) 585 oldobject = str(oldmark.pop('object'))
558 sucs = (suc==nullid) and [] or [suc] 586 oldsubjects = [str(s) for s in oldmark.pop('subjects', [])]
559 meta = { 587 LOOKUP_ERRORS = (error.RepoLookupError, error.LookupError)
560 'date': '%i %i' % util.makedate(), 588 if len(oldobject) != 40:
561 'user': ui.username(), 589 try:
562 } 590 oldobject = repo[oldobject].node()
591 except LOOKUP_ERRORS:
592 pass
593 if any(len(s) != 40 for s in oldsubjects):
594 try:
595 oldsubjects = [repo[s].node() for s in oldsubjects]
596 except LOOKUP_ERRORS:
597 pass
598
599 oldmark['date'] = '%i %i' % tuple(oldmark['date'])
600 meta = dict((k.encode('utf-8'), v.encode('utf-8'))
601 for k, v in oldmark.iteritems())
563 try: 602 try:
564 store.create(prec, sucs, 0, meta) 603 succs = [bin(n) for n in oldsubjects]
604 succs = [n for n in succs if n != nullid]
605 store.create(tr, bin(oldobject), succs,
606 0, meta)
565 cnt += 1 607 cnt += 1
566 except ValueError: 608 except ValueError:
567 repo.ui.write_err("invalid old marker line: %s" 609 repo.ui.write_err("invalid marker %s -> %s\n"
568 % (line)) 610 % (oldobject, oldsubjects))
569 err += 1 611 err += 1
570 finally: 612 unlink.append(repo.sjoin('obsoletemarkers'))
571 f.close() 613 tr.close()
572 util.unlink(repo.join('obsolete-relations')) 614 for path in unlink:
573 except IOError: 615 util.unlink(path)
574 pass 616 finally:
575 ### second (json) format 617 tr.release()
576 data = repo.sopener.tryread('obsoletemarkers')
577 if data:
578 some = True
579 for oldmark in json.loads(data):
580 del oldmark['id'] # dropped for now
581 del oldmark['reason'] # unused until then
582 oldobject = str(oldmark.pop('object'))
583 oldsubjects = [str(s) for s in oldmark.pop('subjects', [])]
584 LOOKUP_ERRORS = (error.RepoLookupError, error.LookupError)
585 if len(oldobject) != 40:
586 try:
587 oldobject = repo[oldobject].node()
588 except LOOKUP_ERRORS:
589 pass
590 if any(len(s) != 40 for s in oldsubjects):
591 try:
592 oldsubjects = [repo[s].node() for s in oldsubjects]
593 except LOOKUP_ERRORS:
594 pass
595
596 oldmark['date'] = '%i %i' % tuple(oldmark['date'])
597 meta = dict((k.encode('utf-8'), v.encode('utf-8'))
598 for k, v in oldmark.iteritems())
599 try:
600 succs = [bin(n) for n in oldsubjects]
601 succs = [n for n in succs if n != nullid]
602 store.create(bin(oldobject), succs,
603 0, meta)
604 cnt += 1
605 except ValueError:
606 repo.ui.write_err("invalid marker %s -> %s\n"
607 % (oldobject, oldsubjects))
608 err += 1
609 util.unlink(repo.sjoin('obsoletemarkers'))
610 finally: 618 finally:
611 del repo._importoldobsolete 619 del repo._importoldobsolete
612 l.release() 620 l.release()
613 if not some: 621 if not some:
614 ui.warn('nothing to do\n') 622 ui.warn('nothing to do\n')
684 oldnode = old.node() 692 oldnode = old.node()
685 new = orig(ui, repo, commitfunc, old, *args, **kwargs) 693 new = orig(ui, repo, commitfunc, old, *args, **kwargs)
686 if new != oldnode: 694 if new != oldnode:
687 lock = repo.lock() 695 lock = repo.lock()
688 try: 696 try:
689 meta = { 697 tr = repo.transaction('post-amend-obst')
690 'date': '%i %i' % util.makedate(), 698 try:
691 'user': ui.username(), 699 meta = {
692 } 700 'date': '%i %i' % util.makedate(),
693 repo.obsstore.create(oldnode, [new], 0, meta) 701 'user': ui.username(),
694 repo._clearobsoletecache() 702 }
695 repo._turn_extinct_secret() 703 repo.obsstore.create(tr, oldnode, [new], 0, meta)
704 tr.close()
705 repo._clearobsoletecache()
706 repo._turn_extinct_secret()
707 finally:
708 tr.release()
696 finally: 709 finally:
697 lock.release() 710 lock.release()
698 return new 711 return new
699 712
700 def uisetup(ui): 713 def uisetup(ui):
895 self.ui.warn( 908 self.ui.warn(
896 _("%(sub)s try to obsolete immutable changeset %(obj)s\n") 909 _("%(sub)s try to obsolete immutable changeset %(obj)s\n")
897 % {'sub': short(sub), 'obj': short(obj)}) 910 % {'sub': short(sub), 'obj': short(obj)})
898 lock = self.lock() 911 lock = self.lock()
899 try: 912 try:
900 meta = { 913 tr = self.transaction('add-obsolete')
901 'date': '%i %i' % util.makedate(), 914 try:
902 'user': ui.username(), 915 meta = {
903 } 916 'date': '%i %i' % util.makedate(),
904 subs = (sub == nullid) and [] or [sub] 917 'user': ui.username(),
905 mid = self.obsstore.create(obj, subs, 0, meta) 918 }
906 self._clearobsoletecache() 919 subs = (sub == nullid) and [] or [sub]
907 self._turn_extinct_secret() 920 mid = self.obsstore.create(tr, obj, subs, 0, meta)
908 return mid 921 tr.close()
922 self._clearobsoletecache()
923 self._turn_extinct_secret()
924 return mid
925 finally:
926 tr.release()
909 finally: 927 finally:
910 lock.release() 928 lock.release()
911 929
912 def addcollapsedobsolete(self, oldnodes, newnode): 930 def addcollapsedobsolete(self, oldnodes, newnode):
913 """Mark oldnodes as collapsed into newnode.""" 931 """Mark oldnodes as collapsed into newnode."""