mercurial/subrepo.py
changeset 11112 4a9bee613737
parent 11111 d2da9e6dd13e
child 11117 dd543e8da87e
equal deleted inserted replaced
11111:d2da9e6dd13e 11112:4a9bee613737
   124                 sm[s] = r
   124                 sm[s] = r
   125 
   125 
   126     # record merged .hgsubstate
   126     # record merged .hgsubstate
   127     writestate(repo, sm)
   127     writestate(repo, sm)
   128 
   128 
       
   129 def relpath(sub):
       
   130     if not hasattr(sub, '_repo'):
       
   131         return sub._path
       
   132     parent = sub._repo
       
   133     while hasattr(parent, '_subparent'):
       
   134         parent = parent._subparent
       
   135     return sub._repo.root[len(parent.root)+1:]
       
   136 
   129 def _abssource(repo, push=False):
   137 def _abssource(repo, push=False):
   130     if hasattr(repo, '_subparent'):
   138     if hasattr(repo, '_subparent'):
   131         source = repo._subsource
   139         source = repo._subsource
   132         if source.startswith('/') or '://' in source:
   140         if source.startswith('/') or '://' in source:
   133             return source
   141             return source
   212         if w.p1() != self._repo[r]: # version checked out change
   220         if w.p1() != self._repo[r]: # version checked out change
   213             return True
   221             return True
   214         return w.dirty() # working directory changed
   222         return w.dirty() # working directory changed
   215 
   223 
   216     def commit(self, text, user, date):
   224     def commit(self, text, user, date):
   217         self._repo.ui.debug("committing subrepo %s\n" % self._path)
   225         self._repo.ui.debug("committing subrepo %s\n" % relpath(self))
   218         n = self._repo.commit(text, user, date)
   226         n = self._repo.commit(text, user, date)
   219         if not n:
   227         if not n:
   220             return self._repo['.'].hex() # different version checked out
   228             return self._repo['.'].hex() # different version checked out
   221         return node.hex(n)
   229         return node.hex(n)
   222 
   230 
   223     def remove(self):
   231     def remove(self):
   224         # we can't fully delete the repository as it may contain
   232         # we can't fully delete the repository as it may contain
   225         # local-only history
   233         # local-only history
   226         self._repo.ui.note(_('removing subrepo %s\n') % self._path)
   234         self._repo.ui.note(_('removing subrepo %s\n') % relpath(self))
   227         hg.clean(self._repo, node.nullid, False)
   235         hg.clean(self._repo, node.nullid, False)
   228 
   236 
   229     def _get(self, state):
   237     def _get(self, state):
   230         source, revision, kind = state
   238         source, revision, kind = state
   231         try:
   239         try:
   232             self._repo.lookup(revision)
   240             self._repo.lookup(revision)
   233         except error.RepoError:
   241         except error.RepoError:
   234             self._repo._subsource = source
   242             self._repo._subsource = source
   235             srcurl = _abssource(self._repo)
   243             srcurl = _abssource(self._repo)
   236             self._repo.ui.status(_('pulling subrepo %s from %s\n')
   244             self._repo.ui.status(_('pulling subrepo %s from %s\n')
   237                                  % (self._path, srcurl))
   245                                  % (relpath(self), srcurl))
   238             other = hg.repository(self._repo.ui, srcurl)
   246             other = hg.repository(self._repo.ui, srcurl)
   239             self._repo.pull(other)
   247             self._repo.pull(other)
   240 
   248 
   241     def get(self, state):
   249     def get(self, state):
   242         self._get(state)
   250         self._get(state)
   248         self._get(state)
   256         self._get(state)
   249         cur = self._repo['.']
   257         cur = self._repo['.']
   250         dst = self._repo[state[1]]
   258         dst = self._repo[state[1]]
   251         anc = dst.ancestor(cur)
   259         anc = dst.ancestor(cur)
   252         if anc == cur:
   260         if anc == cur:
   253             self._repo.ui.debug("updating subrepo %s\n" % self._path)
   261             self._repo.ui.debug("updating subrepo %s\n" % relpath(self))
   254             hg.update(self._repo, state[1])
   262             hg.update(self._repo, state[1])
   255         elif anc == dst:
   263         elif anc == dst:
   256             self._repo.ui.debug("skipping subrepo %s\n" % self._path)
   264             self._repo.ui.debug("skipping subrepo %s\n" % relpath(self))
   257         else:
   265         else:
   258             self._repo.ui.debug("merging subrepo %s\n" % self._path)
   266             self._repo.ui.debug("merging subrepo %s\n" % relpath(self))
   259             hg.merge(self._repo, state[1], remind=False)
   267             hg.merge(self._repo, state[1], remind=False)
   260 
   268 
   261     def push(self, force):
   269     def push(self, force):
   262         # push subrepos depth-first for coherent ordering
   270         # push subrepos depth-first for coherent ordering
   263         c = self._repo['']
   271         c = self._repo['']
   266             if not c.sub(s).push(force):
   274             if not c.sub(s).push(force):
   267                 return False
   275                 return False
   268 
   276 
   269         dsturl = _abssource(self._repo, True)
   277         dsturl = _abssource(self._repo, True)
   270         self._repo.ui.status(_('pushing subrepo %s to %s\n') %
   278         self._repo.ui.status(_('pushing subrepo %s to %s\n') %
   271             (self._path, dsturl))
   279             (relpath(self), dsturl))
   272         other = hg.repository(self._repo.ui, dsturl)
   280         other = hg.repository(self._repo.ui, dsturl)
   273         return self._repo.push(other, force)
   281         return self._repo.push(other, force)
   274 
   282 
   275 class svnsubrepo(object):
   283 class svnsubrepo(object):
   276     def __init__(self, ctx, path, state):
   284     def __init__(self, ctx, path, state):