mercurial/subrepo.py
changeset 13771 ce6227306c9a
parent 13753 78a0a815fd41
child 13857 ba1f98f877ec
equal deleted inserted replaced
13770:4e8f2310f310 13771:ce6227306c9a
     3 # Copyright 2009-2010 Matt Mackall <mpm@selenic.com>
     3 # Copyright 2009-2010 Matt Mackall <mpm@selenic.com>
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath
     8 import errno, os, re, xml.dom.minidom, shutil, posixpath
     9 import stat, subprocess, tarfile
     9 import stat, subprocess, tarfile
    10 from i18n import _
    10 from i18n import _
    11 import config, util, node, error, cmdutil, bookmarks
    11 import config, util, node, error, cmdutil, url, bookmarks
    12 hg = None
    12 hg = None
    13 
    13 
    14 nullstate = ('', '', 'empty')
    14 nullstate = ('', '', 'empty')
    15 
    15 
    16 def state(ctx, ui):
    16 def state(ctx, ui):
   191 
   191 
   192 def _abssource(repo, push=False, abort=True):
   192 def _abssource(repo, push=False, abort=True):
   193     """return pull/push path of repo - either based on parent repo .hgsub info
   193     """return pull/push path of repo - either based on parent repo .hgsub info
   194     or on the top repo config. Abort or return None if no source found."""
   194     or on the top repo config. Abort or return None if no source found."""
   195     if hasattr(repo, '_subparent'):
   195     if hasattr(repo, '_subparent'):
   196         source = repo._subsource
   196         source = url.url(repo._subsource)
   197         if source.startswith('/') or '://' in source:
   197         source.path = posixpath.normpath(source.path)
   198             return source
   198         if posixpath.isabs(source.path) or source.scheme:
       
   199             return str(source)
   199         parent = _abssource(repo._subparent, push, abort=False)
   200         parent = _abssource(repo._subparent, push, abort=False)
   200         if parent:
   201         if parent:
   201             if '://' in parent:
   202             parent = url.url(parent)
   202                 if parent[-1] == '/':
   203             parent.path = posixpath.join(parent.path, source.path)
   203                     parent = parent[:-1]
   204             parent.path = posixpath.normpath(parent.path)
   204                 r = urlparse.urlparse(parent + '/' + source)
   205             return str(parent)
   205                 r = urlparse.urlunparse((r[0], r[1],
       
   206                                          posixpath.normpath(r[2]),
       
   207                                          r[3], r[4], r[5]))
       
   208                 return r
       
   209             else: # plain file system path
       
   210                 return posixpath.normpath(os.path.join(parent, repo._subsource))
       
   211     else: # recursion reached top repo
   206     else: # recursion reached top repo
   212         if hasattr(repo, '_subtoppath'):
   207         if hasattr(repo, '_subtoppath'):
   213             return repo._subtoppath
   208             return repo._subtoppath
   214         if push and repo.ui.config('paths', 'default-push'):
   209         if push and repo.ui.config('paths', 'default-push'):
   215             return repo.ui.config('paths', 'default-push')
   210             return repo.ui.config('paths', 'default-push')