570 common, anyinc, heads = orig(repo, remote, *args, **kwargs) |
570 common, anyinc, heads = orig(repo, remote, *args, **kwargs) |
571 if getattr(remote, '_reducehead', None) is not None: |
571 if getattr(remote, '_reducehead', None) is not None: |
572 heads = remote._reducehead(heads) |
572 heads = remote._reducehead(heads) |
573 return common, anyinc, heads |
573 return common, anyinc, heads |
574 |
574 |
|
575 # states boundary IO |
|
576 ##################### |
|
577 |
|
578 def _readheadsfile(repo, filename): |
|
579 """read head from the given file |
|
580 |
|
581 XXX move me elsewhere""" |
|
582 heads = [nullid] |
|
583 try: |
|
584 f = repo.opener(filename) |
|
585 try: |
|
586 heads = sorted([node.bin(n) for n in f.read().split() if n]) |
|
587 finally: |
|
588 f.close() |
|
589 except IOError: |
|
590 pass |
|
591 return heads |
|
592 |
|
593 def _readstatesheads(repo, undo=False): |
|
594 """read all state heads |
|
595 |
|
596 XXX move me elsewhere""" |
|
597 statesheads = {} |
|
598 for state in STATES: |
|
599 if state.trackheads: |
|
600 filemask = 'states/%s-heads' |
|
601 filename = filemask % state.name |
|
602 statesheads[state] = _readheadsfile(repo, filename) |
|
603 return statesheads |
|
604 |
|
605 def _writeheadsfile(repo, filename, heads): |
|
606 """write given <heads> in the file with at <filename> |
|
607 |
|
608 XXX move me elsewhere""" |
|
609 f = repo.opener(filename, 'w', atomictemp=True) |
|
610 try: |
|
611 for h in heads: |
|
612 f.write(hex(h) + '\n') |
|
613 f.rename() |
|
614 finally: |
|
615 f.close() |
|
616 |
|
617 def _writestateshead(repo): |
|
618 """write all heads |
|
619 |
|
620 XXX move me elsewhere""" |
|
621 # XXX transaction! |
|
622 for state in STATES: |
|
623 if state.trackheads: |
|
624 filename = 'states/%s-heads' % state.name |
|
625 _writeheadsfile(repo, filename, repo._statesheads[state]) |
|
626 |
575 # WireProtocols |
627 # WireProtocols |
576 #################### |
628 #################### |
577 def wireheads(repo, proto): |
629 def wireheads(repo, proto): |
578 """Altered head command that doesn't include _NOSHARE |
630 """Altered head command that doesn't include _NOSHARE |
579 |
631 |
652 return self.heads() |
706 return self.heads() |
653 |
707 |
654 @util.propertycache |
708 @util.propertycache |
655 def _statesheads(self): |
709 def _statesheads(self): |
656 """{ state-object -> set(defining head)} mapping""" |
710 """{ state-object -> set(defining head)} mapping""" |
657 return self._readstatesheads() |
711 return _readstatesheads(self) |
658 |
|
659 |
|
660 def _readheadsfile(self, filename): |
|
661 """read head from the given file |
|
662 |
|
663 XXX move me elsewhere""" |
|
664 heads = [nullid] |
|
665 try: |
|
666 f = self.opener(filename) |
|
667 try: |
|
668 heads = sorted([node.bin(n) for n in f.read().split() if n]) |
|
669 finally: |
|
670 f.close() |
|
671 except IOError: |
|
672 pass |
|
673 return heads |
|
674 |
|
675 def _readstatesheads(self, undo=False): |
|
676 """read all state heads |
|
677 |
|
678 XXX move me elsewhere""" |
|
679 statesheads = {} |
|
680 for state in STATES: |
|
681 if state.trackheads: |
|
682 filemask = 'states/%s-heads' |
|
683 filename = filemask % state.name |
|
684 statesheads[state] = self._readheadsfile(filename) |
|
685 return statesheads |
|
686 |
|
687 def _writeheadsfile(self, filename, heads): |
|
688 """write given <heads> in the file with at <filename> |
|
689 |
|
690 XXX move me elsewhere""" |
|
691 f = self.opener(filename, 'w', atomictemp=True) |
|
692 try: |
|
693 for h in heads: |
|
694 f.write(hex(h) + '\n') |
|
695 f.rename() |
|
696 finally: |
|
697 f.close() |
|
698 |
|
699 def _writestateshead(self): |
|
700 """write all heads |
|
701 |
|
702 XXX move me elsewhere""" |
|
703 # XXX transaction! |
|
704 for state in STATES: |
|
705 if state.trackheads: |
|
706 filename = 'states/%s-heads' % state.name |
|
707 self._writeheadsfile(filename, self._statesheads[state]) |
|
708 |
712 |
709 def setstate(self, state, nodes): |
713 def setstate(self, state, nodes): |
710 """change state of targets changeset and it's ancestors. |
714 """change state of targets changeset and it's ancestors. |
711 |
715 |
712 Simplify the list of head.""" |
716 Simplify the list of head.""" |
718 heads.sort() |
722 heads.sort() |
719 if olds != heads: |
723 if olds != heads: |
720 heads[:] = noderange(repo, ["heads(::%s())" % state.headssymbol]) |
724 heads[:] = noderange(repo, ["heads(::%s())" % state.headssymbol]) |
721 heads.sort() |
725 heads.sort() |
722 if olds != heads: |
726 if olds != heads: |
723 self._writestateshead() |
727 _writestateshead(self) |
724 if state.next is not None and state.next.trackheads: |
728 if state.next is not None and state.next.trackheads: |
725 self.setstate(state.next, nodes) # cascading |
729 self.setstate(state.next, nodes) # cascading |
726 |
730 |
727 def _reducehead(self, candidates): |
731 def _reducehead(self, candidates): |
728 """recompute a set of heads so it doesn't include _NOSHARE changeset |
732 """recompute a set of heads so it doesn't include _NOSHARE changeset |