525 self._repo = hg.repository(r.baseui, root, create=create) |
525 self._repo = hg.repository(r.baseui, root, create=create) |
526 self.ui = self._repo.ui |
526 self.ui = self._repo.ui |
527 for s, k in [('ui', 'commitsubrepos')]: |
527 for s, k in [('ui', 'commitsubrepos')]: |
528 v = r.ui.config(s, k) |
528 v = r.ui.config(s, k) |
529 if v: |
529 if v: |
530 self._repo.ui.setconfig(s, k, v, 'subrepo') |
530 self.ui.setconfig(s, k, v, 'subrepo') |
531 self._repo.ui.setconfig('ui', '_usedassubrepo', 'True', 'subrepo') |
531 self.ui.setconfig('ui', '_usedassubrepo', 'True', 'subrepo') |
532 self._initrepo(r, state[0], create) |
532 self._initrepo(r, state[0], create) |
533 |
533 |
534 def storeclean(self, path): |
534 def storeclean(self, path): |
535 lock = self._repo.lock() |
535 lock = self._repo.lock() |
536 try: |
536 try: |
604 lines = ['[paths]\n'] |
604 lines = ['[paths]\n'] |
605 |
605 |
606 def addpathconfig(key, value): |
606 def addpathconfig(key, value): |
607 if value: |
607 if value: |
608 lines.append('%s = %s\n' % (key, value)) |
608 lines.append('%s = %s\n' % (key, value)) |
609 self._repo.ui.setconfig('paths', key, value, 'subrepo') |
609 self.ui.setconfig('paths', key, value, 'subrepo') |
610 |
610 |
611 defpath = _abssource(self._repo, abort=False) |
611 defpath = _abssource(self._repo, abort=False) |
612 defpushpath = _abssource(self._repo, True, abort=False) |
612 defpushpath = _abssource(self._repo, True, abort=False) |
613 addpathconfig('default', defpath) |
613 addpathconfig('default', defpath) |
614 if defpath != defpushpath: |
614 if defpath != defpushpath: |
647 rev1 = self._state[1] |
647 rev1 = self._state[1] |
648 ctx1 = self._repo[rev1] |
648 ctx1 = self._repo[rev1] |
649 ctx2 = self._repo[rev2] |
649 ctx2 = self._repo[rev2] |
650 return self._repo.status(ctx1, ctx2, **opts) |
650 return self._repo.status(ctx1, ctx2, **opts) |
651 except error.RepoLookupError, inst: |
651 except error.RepoLookupError, inst: |
652 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
652 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
653 % (inst, subrelpath(self))) |
653 % (inst, subrelpath(self))) |
654 return scmutil.status([], [], [], [], [], [], []) |
654 return scmutil.status([], [], [], [], [], [], []) |
655 |
655 |
656 @annotatesubrepoerror |
656 @annotatesubrepoerror |
657 def diff(self, ui, diffopts, node2, match, prefix, **opts): |
657 def diff(self, ui, diffopts, node2, match, prefix, **opts): |
658 try: |
658 try: |
664 cmdutil.diffordiffstat(ui, self._repo, diffopts, |
664 cmdutil.diffordiffstat(ui, self._repo, diffopts, |
665 node1, node2, match, |
665 node1, node2, match, |
666 prefix=posixpath.join(prefix, self._path), |
666 prefix=posixpath.join(prefix, self._path), |
667 listsubrepos=True, **opts) |
667 listsubrepos=True, **opts) |
668 except error.RepoLookupError, inst: |
668 except error.RepoLookupError, inst: |
669 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
669 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
670 % (inst, subrelpath(self))) |
670 % (inst, subrelpath(self))) |
671 |
671 |
672 @annotatesubrepoerror |
672 @annotatesubrepoerror |
673 def archive(self, ui, archiver, prefix, match=None): |
673 def archive(self, ui, archiver, prefix, match=None): |
674 self._get(self._state + ('hg',)) |
674 self._get(self._state + ('hg',)) |
675 total = abstractsubrepo.archive(self, ui, archiver, prefix, match) |
675 total = abstractsubrepo.archive(self, ui, archiver, prefix, match) |
703 def commit(self, text, user, date): |
703 def commit(self, text, user, date): |
704 # don't bother committing in the subrepo if it's only been |
704 # don't bother committing in the subrepo if it's only been |
705 # updated |
705 # updated |
706 if not self.dirty(True): |
706 if not self.dirty(True): |
707 return self._repo['.'].hex() |
707 return self._repo['.'].hex() |
708 self._repo.ui.debug("committing subrepo %s\n" % subrelpath(self)) |
708 self.ui.debug("committing subrepo %s\n" % subrelpath(self)) |
709 n = self._repo.commit(text, user, date) |
709 n = self._repo.commit(text, user, date) |
710 if not n: |
710 if not n: |
711 return self._repo['.'].hex() # different version checked out |
711 return self._repo['.'].hex() # different version checked out |
712 return node.hex(n) |
712 return node.hex(n) |
713 |
713 |
717 |
717 |
718 @annotatesubrepoerror |
718 @annotatesubrepoerror |
719 def remove(self): |
719 def remove(self): |
720 # we can't fully delete the repository as it may contain |
720 # we can't fully delete the repository as it may contain |
721 # local-only history |
721 # local-only history |
722 self._repo.ui.note(_('removing subrepo %s\n') % subrelpath(self)) |
722 self.ui.note(_('removing subrepo %s\n') % subrelpath(self)) |
723 hg.clean(self._repo, node.nullid, False) |
723 hg.clean(self._repo, node.nullid, False) |
724 |
724 |
725 def _get(self, state): |
725 def _get(self, state): |
726 source, revision, kind = state |
726 source, revision, kind = state |
727 if revision in self._repo.unfiltered(): |
727 if revision in self._repo.unfiltered(): |
728 return True |
728 return True |
729 self._repo._subsource = source |
729 self._repo._subsource = source |
730 srcurl = _abssource(self._repo) |
730 srcurl = _abssource(self._repo) |
731 other = hg.peer(self._repo, {}, srcurl) |
731 other = hg.peer(self._repo, {}, srcurl) |
732 if len(self._repo) == 0: |
732 if len(self._repo) == 0: |
733 self._repo.ui.status(_('cloning subrepo %s from %s\n') |
733 self.ui.status(_('cloning subrepo %s from %s\n') |
734 % (subrelpath(self), srcurl)) |
734 % (subrelpath(self), srcurl)) |
735 parentrepo = self._repo._subparent |
735 parentrepo = self._repo._subparent |
736 shutil.rmtree(self._repo.path) |
736 shutil.rmtree(self._repo.path) |
737 other, cloned = hg.clone(self._repo._subparent.baseui, {}, |
737 other, cloned = hg.clone(self._repo._subparent.baseui, {}, |
738 other, self._repo.root, |
738 other, self._repo.root, |
739 update=False) |
739 update=False) |
740 self._repo = cloned.local() |
740 self._repo = cloned.local() |
741 self._initrepo(parentrepo, source, create=True) |
741 self._initrepo(parentrepo, source, create=True) |
742 self._cachestorehash(srcurl) |
742 self._cachestorehash(srcurl) |
743 else: |
743 else: |
744 self._repo.ui.status(_('pulling subrepo %s from %s\n') |
744 self.ui.status(_('pulling subrepo %s from %s\n') |
745 % (subrelpath(self), srcurl)) |
745 % (subrelpath(self), srcurl)) |
746 cleansub = self.storeclean(srcurl) |
746 cleansub = self.storeclean(srcurl) |
747 exchange.pull(self._repo, other) |
747 exchange.pull(self._repo, other) |
748 if cleansub: |
748 if cleansub: |
749 # keep the repo clean after pull |
749 # keep the repo clean after pull |
750 self._cachestorehash(srcurl) |
750 self._cachestorehash(srcurl) |
773 dst = self._repo[state[1]] |
773 dst = self._repo[state[1]] |
774 anc = dst.ancestor(cur) |
774 anc = dst.ancestor(cur) |
775 |
775 |
776 def mergefunc(): |
776 def mergefunc(): |
777 if anc == cur and dst.branch() == cur.branch(): |
777 if anc == cur and dst.branch() == cur.branch(): |
778 self._repo.ui.debug("updating subrepo %s\n" % subrelpath(self)) |
778 self.ui.debug("updating subrepo %s\n" % subrelpath(self)) |
779 hg.update(self._repo, state[1]) |
779 hg.update(self._repo, state[1]) |
780 elif anc == dst: |
780 elif anc == dst: |
781 self._repo.ui.debug("skipping subrepo %s\n" % subrelpath(self)) |
781 self.ui.debug("skipping subrepo %s\n" % subrelpath(self)) |
782 else: |
782 else: |
783 self._repo.ui.debug("merging subrepo %s\n" % subrelpath(self)) |
783 self.ui.debug("merging subrepo %s\n" % subrelpath(self)) |
784 hg.merge(self._repo, state[1], remind=False) |
784 hg.merge(self._repo, state[1], remind=False) |
785 |
785 |
786 wctx = self._repo[None] |
786 wctx = self._repo[None] |
787 if self.dirty(): |
787 if self.dirty(): |
788 if anc != dst: |
788 if anc != dst: |
789 if _updateprompt(self._repo.ui, self, wctx.dirty(), cur, dst): |
789 if _updateprompt(self.ui, self, wctx.dirty(), cur, dst): |
790 mergefunc() |
790 mergefunc() |
791 else: |
791 else: |
792 mergefunc() |
792 mergefunc() |
793 else: |
793 else: |
794 mergefunc() |
794 mergefunc() |
807 return False |
807 return False |
808 |
808 |
809 dsturl = _abssource(self._repo, True) |
809 dsturl = _abssource(self._repo, True) |
810 if not force: |
810 if not force: |
811 if self.storeclean(dsturl): |
811 if self.storeclean(dsturl): |
812 self._repo.ui.status( |
812 self.ui.status( |
813 _('no changes made to subrepo %s since last push to %s\n') |
813 _('no changes made to subrepo %s since last push to %s\n') |
814 % (subrelpath(self), dsturl)) |
814 % (subrelpath(self), dsturl)) |
815 return None |
815 return None |
816 self._repo.ui.status(_('pushing subrepo %s to %s\n') % |
816 self.ui.status(_('pushing subrepo %s to %s\n') % |
817 (subrelpath(self), dsturl)) |
817 (subrelpath(self), dsturl)) |
818 other = hg.peer(self._repo, {'ssh': ssh}, dsturl) |
818 other = hg.peer(self._repo, {'ssh': ssh}, dsturl) |
819 res = exchange.push(self._repo, other, force, newbranch=newbranch) |
819 res = exchange.push(self._repo, other, force, newbranch=newbranch) |
820 |
820 |
821 # the repo is now clean |
821 # the repo is now clean |