mercurial/subrepo.py
changeset 24302 6e092ea2eff1
parent 24256 e964edc3274e
child 24409 30b8db6d0c04
equal deleted inserted replaced
24301:18b5b2c9d921 24302:6e092ea2eff1
   125             kind, src = src.split(']', 1)
   125             kind, src = src.split(']', 1)
   126             kind = kind[1:]
   126             kind = kind[1:]
   127             src = src.lstrip() # strip any extra whitespace after ']'
   127             src = src.lstrip() # strip any extra whitespace after ']'
   128 
   128 
   129         if not util.url(src).isabs():
   129         if not util.url(src).isabs():
   130             parent = _abssource(ctx._repo, abort=False)
   130             parent = _abssource(ctx.repo(), abort=False)
   131             if parent:
   131             if parent:
   132                 parent = util.url(parent)
   132                 parent = util.url(parent)
   133                 parent.path = posixpath.join(parent.path or '', src)
   133                 parent.path = posixpath.join(parent.path or '', src)
   134                 parent.path = posixpath.normpath(parent.path)
   134                 parent.path = posixpath.normpath(parent.path)
   135                 joined = str(parent)
   135                 joined = str(parent)
   330     # scripts that don't use our demand-loading
   330     # scripts that don't use our demand-loading
   331     global hg
   331     global hg
   332     import hg as h
   332     import hg as h
   333     hg = h
   333     hg = h
   334 
   334 
   335     pathutil.pathauditor(ctx._repo.root)(path)
   335     pathutil.pathauditor(ctx.repo().root)(path)
   336     state = ctx.substate[path]
   336     state = ctx.substate[path]
   337     if state[2] not in types:
   337     if state[2] not in types:
   338         raise util.Abort(_('unknown subrepo type %s') % state[2])
   338         raise util.Abort(_('unknown subrepo type %s') % state[2])
   339     return types[state[2]](ctx, path, state[:2])
   339     return types[state[2]](ctx, path, state[:2])
   340 
   340 
   514     def shortid(self, revid):
   514     def shortid(self, revid):
   515         return revid
   515         return revid
   516 
   516 
   517 class hgsubrepo(abstractsubrepo):
   517 class hgsubrepo(abstractsubrepo):
   518     def __init__(self, ctx, path, state):
   518     def __init__(self, ctx, path, state):
   519         super(hgsubrepo, self).__init__(ctx._repo.ui)
   519         super(hgsubrepo, self).__init__(ctx.repo().ui)
   520         self._path = path
   520         self._path = path
   521         self._state = state
   521         self._state = state
   522         r = ctx._repo
   522         r = ctx.repo()
   523         root = r.wjoin(path)
   523         root = r.wjoin(path)
   524         create = not r.wvfs.exists('%s/.hg' % path)
   524         create = not r.wvfs.exists('%s/.hg' % path)
   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')]:
   896     def shortid(self, revid):
   896     def shortid(self, revid):
   897         return revid[:12]
   897         return revid[:12]
   898 
   898 
   899 class svnsubrepo(abstractsubrepo):
   899 class svnsubrepo(abstractsubrepo):
   900     def __init__(self, ctx, path, state):
   900     def __init__(self, ctx, path, state):
   901         super(svnsubrepo, self).__init__(ctx._repo.ui)
   901         super(svnsubrepo, self).__init__(ctx.repo().ui)
   902         self._path = path
   902         self._path = path
   903         self._state = state
   903         self._state = state
   904         self._ctx = ctx
   904         self._ctx = ctx
   905         self._exe = util.findexe('svn')
   905         self._exe = util.findexe('svn')
   906         if not self._exe:
   906         if not self._exe:
   920             # --non-interactive.
   920             # --non-interactive.
   921             if commands[0] in ('update', 'checkout', 'commit'):
   921             if commands[0] in ('update', 'checkout', 'commit'):
   922                 cmd.append('--non-interactive')
   922                 cmd.append('--non-interactive')
   923         cmd.extend(commands)
   923         cmd.extend(commands)
   924         if filename is not None:
   924         if filename is not None:
   925             path = os.path.join(self._ctx._repo.origroot, self._path, filename)
   925             path = os.path.join(self._ctx.repo().origroot, self._path, filename)
   926             cmd.append(path)
   926             cmd.append(path)
   927         env = dict(os.environ)
   927         env = dict(os.environ)
   928         # Avoid localized output, preserve current locale for everything else.
   928         # Avoid localized output, preserve current locale for everything else.
   929         lc_all = env.get('LC_ALL')
   929         lc_all = env.get('LC_ALL')
   930         if lc_all:
   930         if lc_all:
  1062             if (s.st_mode & stat.S_IWRITE) != 0:
  1062             if (s.st_mode & stat.S_IWRITE) != 0:
  1063                 raise
  1063                 raise
  1064             os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
  1064             os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
  1065             os.remove(path)
  1065             os.remove(path)
  1066 
  1066 
  1067         path = self._ctx._repo.wjoin(self._path)
  1067         path = self._ctx.repo().wjoin(self._path)
  1068         shutil.rmtree(path, onerror=onerror)
  1068         shutil.rmtree(path, onerror=onerror)
  1069         try:
  1069         try:
  1070             os.removedirs(os.path.dirname(path))
  1070             os.removedirs(os.path.dirname(path))
  1071         except OSError:
  1071         except OSError:
  1072             pass
  1072             pass
  1080             args.append('--force')
  1080             args.append('--force')
  1081         # The revision must be specified at the end of the URL to properly
  1081         # The revision must be specified at the end of the URL to properly
  1082         # update to a directory which has since been deleted and recreated.
  1082         # update to a directory which has since been deleted and recreated.
  1083         args.append('%s@%s' % (state[0], state[1]))
  1083         args.append('%s@%s' % (state[0], state[1]))
  1084         status, err = self._svncommand(args, failok=True)
  1084         status, err = self._svncommand(args, failok=True)
  1085         _sanitize(self.ui, self._ctx._repo.wjoin(self._path), '.svn')
  1085         _sanitize(self.ui, self._ctx.repo().wjoin(self._path), '.svn')
  1086         if not re.search('Checked out revision [0-9]+.', status):
  1086         if not re.search('Checked out revision [0-9]+.', status):
  1087             if ('is already a working copy for a different URL' in err
  1087             if ('is already a working copy for a different URL' in err
  1088                 and (self._wcchanged()[:2] == (False, False))):
  1088                 and (self._wcchanged()[:2] == (False, False))):
  1089                 # obstructed but clean working copy, so just blow it away.
  1089                 # obstructed but clean working copy, so just blow it away.
  1090                 self.remove()
  1090                 self.remove()
  1126         return self._svncommand(['cat'], name)[0]
  1126         return self._svncommand(['cat'], name)[0]
  1127 
  1127 
  1128 
  1128 
  1129 class gitsubrepo(abstractsubrepo):
  1129 class gitsubrepo(abstractsubrepo):
  1130     def __init__(self, ctx, path, state):
  1130     def __init__(self, ctx, path, state):
  1131         super(gitsubrepo, self).__init__(ctx._repo.ui)
  1131         super(gitsubrepo, self).__init__(ctx.repo().ui)
  1132         self._state = state
  1132         self._state = state
  1133         self._ctx = ctx
  1133         self._ctx = ctx
  1134         self._path = path
  1134         self._path = path
  1135         self._relpath = os.path.join(reporelpath(ctx._repo), path)
  1135         self._relpath = os.path.join(reporelpath(ctx.repo()), path)
  1136         self._abspath = ctx._repo.wjoin(path)
  1136         self._abspath = ctx.repo().wjoin(path)
  1137         self._subparent = ctx._repo
  1137         self._subparent = ctx.repo()
  1138         self._ensuregit()
  1138         self._ensuregit()
  1139 
  1139 
  1140     def _ensuregit(self):
  1140     def _ensuregit(self):
  1141         try:
  1141         try:
  1142             self._gitexecutable = 'git'
  1142             self._gitexecutable = 'git'