Changeset View
Changeset View
Standalone View
Standalone View
mercurial/subrepo.py
Show All 38 Lines | from . import ( | ||||
subrepoutil, | subrepoutil, | ||||
util, | util, | ||||
vfs as vfsmod, | vfs as vfsmod, | ||||
) | ) | ||||
from .utils import ( | from .utils import ( | ||||
dateutil, | dateutil, | ||||
hashutil, | hashutil, | ||||
procutil, | procutil, | ||||
urlutil, | |||||
) | ) | ||||
hg = None | hg = None | ||||
reporelpath = subrepoutil.reporelpath | reporelpath = subrepoutil.reporelpath | ||||
subrelpath = subrepoutil.subrelpath | subrelpath = subrepoutil.subrelpath | ||||
_abssource = subrepoutil._abssource | _abssource = subrepoutil._abssource | ||||
propertycache = util.propertycache | propertycache = util.propertycache | ||||
def _expandedabspath(path): | def _expandedabspath(path): | ||||
""" | """ | ||||
get a path or url and if it is a path expand it and return an absolute path | get a path or url and if it is a path expand it and return an absolute path | ||||
""" | """ | ||||
expandedpath = util.urllocalpath(util.expandpath(path)) | expandedpath = urlutil.urllocalpath(util.expandpath(path)) | ||||
u = util.url(expandedpath) | u = urlutil.url(expandedpath) | ||||
if not u.scheme: | if not u.scheme: | ||||
path = util.normpath(os.path.abspath(u.path)) | path = util.normpath(os.path.abspath(u.path)) | ||||
return path | return path | ||||
def _getstorehashcachename(remotepath): | def _getstorehashcachename(remotepath): | ||||
'''get a unique filename for the store hash cache of a remote repository''' | '''get a unique filename for the store hash cache of a remote repository''' | ||||
return hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12] | return hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12] | ||||
▲ Show 20 Lines • Show All 670 Lines • ▼ Show 20 Line(s) | def _get(self, state): | ||||
b'pool': pool, | b'pool': pool, | ||||
b'mode': self.ui.config(b'share', b'poolnaming'), | b'mode': self.ui.config(b'share', b'poolnaming'), | ||||
} | } | ||||
else: | else: | ||||
shareopts = {} | shareopts = {} | ||||
self.ui.status( | self.ui.status( | ||||
_(b'cloning subrepo %s from %s\n') | _(b'cloning subrepo %s from %s\n') | ||||
% (subrelpath(self), util.hidepassword(srcurl)) | % (subrelpath(self), urlutil.hidepassword(srcurl)) | ||||
) | ) | ||||
peer = getpeer() | peer = getpeer() | ||||
try: | try: | ||||
other, cloned = hg.clone( | other, cloned = hg.clone( | ||||
self._repo._subparent.baseui, | self._repo._subparent.baseui, | ||||
{}, | {}, | ||||
peer, | peer, | ||||
self._repo.root, | self._repo.root, | ||||
update=False, | update=False, | ||||
shareopts=shareopts, | shareopts=shareopts, | ||||
) | ) | ||||
finally: | finally: | ||||
peer.close() | peer.close() | ||||
self._repo = cloned.local() | self._repo = cloned.local() | ||||
self._initrepo(parentrepo, source, create=True) | self._initrepo(parentrepo, source, create=True) | ||||
self._cachestorehash(srcurl) | self._cachestorehash(srcurl) | ||||
else: | else: | ||||
self.ui.status( | self.ui.status( | ||||
_(b'pulling subrepo %s from %s\n') | _(b'pulling subrepo %s from %s\n') | ||||
% (subrelpath(self), util.hidepassword(srcurl)) | % (subrelpath(self), urlutil.hidepassword(srcurl)) | ||||
) | ) | ||||
cleansub = self.storeclean(srcurl) | cleansub = self.storeclean(srcurl) | ||||
peer = getpeer() | peer = getpeer() | ||||
try: | try: | ||||
exchange.pull(self._repo, peer) | exchange.pull(self._repo, peer) | ||||
finally: | finally: | ||||
peer.close() | peer.close() | ||||
if cleansub: | if cleansub: | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | def push(self, opts): | ||||
if c.sub(s).push(opts) == 0: | if c.sub(s).push(opts) == 0: | ||||
return False | return False | ||||
dsturl = _abssource(self._repo, True) | dsturl = _abssource(self._repo, True) | ||||
if not force: | if not force: | ||||
if self.storeclean(dsturl): | if self.storeclean(dsturl): | ||||
self.ui.status( | self.ui.status( | ||||
_(b'no changes made to subrepo %s since last push to %s\n') | _(b'no changes made to subrepo %s since last push to %s\n') | ||||
% (subrelpath(self), util.hidepassword(dsturl)) | % (subrelpath(self), urlutil.hidepassword(dsturl)) | ||||
) | ) | ||||
return None | return None | ||||
self.ui.status( | self.ui.status( | ||||
_(b'pushing subrepo %s to %s\n') | _(b'pushing subrepo %s to %s\n') | ||||
% (subrelpath(self), util.hidepassword(dsturl)) | % (subrelpath(self), urlutil.hidepassword(dsturl)) | ||||
) | ) | ||||
other = hg.peer(self._repo, {b'ssh': ssh}, dsturl) | other = hg.peer(self._repo, {b'ssh': ssh}, dsturl) | ||||
try: | try: | ||||
res = exchange.push(self._repo, other, force, newbranch=newbranch) | res = exchange.push(self._repo, other, force, newbranch=newbranch) | ||||
finally: | finally: | ||||
other.close() | other.close() | ||||
# the repo is now clean | # the repo is now clean | ||||
▲ Show 20 Lines • Show All 413 Lines • ▼ Show 20 Line(s) | def get(self, state, overwrite=False): | ||||
args = [b'checkout'] | args = [b'checkout'] | ||||
if self._svnversion >= (1, 5): | if self._svnversion >= (1, 5): | ||||
args.append(b'--force') | args.append(b'--force') | ||||
# The revision must be specified at the end of the URL to properly | # The revision must be specified at the end of the URL to properly | ||||
# update to a directory which has since been deleted and recreated. | # update to a directory which has since been deleted and recreated. | ||||
args.append(b'%s@%s' % (state[0], state[1])) | args.append(b'%s@%s' % (state[0], state[1])) | ||||
# SEC: check that the ssh url is safe | # SEC: check that the ssh url is safe | ||||
util.checksafessh(state[0]) | urlutil.checksafessh(state[0]) | ||||
status, err = self._svncommand(args, failok=True) | status, err = self._svncommand(args, failok=True) | ||||
_sanitize(self.ui, self.wvfs, b'.svn') | _sanitize(self.ui, self.wvfs, b'.svn') | ||||
if not re.search(b'Checked out revision [0-9]+.', status): | if not re.search(b'Checked out revision [0-9]+.', status): | ||||
if b'is already a working copy for a different URL' in err and ( | if b'is already a working copy for a different URL' in err and ( | ||||
self._wcchanged()[:2] == (False, False) | self._wcchanged()[:2] == (False, False) | ||||
): | ): | ||||
# obstructed but clean working copy, so just blow it away. | # obstructed but clean working copy, so just blow it away. | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Line(s) | def _abssource(self, source): | ||||
if colon != -1 and b'/' not in source[:colon]: | if colon != -1 and b'/' not in source[:colon]: | ||||
return source | return source | ||||
self._subsource = source | self._subsource = source | ||||
return _abssource(self) | return _abssource(self) | ||||
def _fetch(self, source, revision): | def _fetch(self, source, revision): | ||||
if self._gitmissing(): | if self._gitmissing(): | ||||
# SEC: check for safe ssh url | # SEC: check for safe ssh url | ||||
util.checksafessh(source) | urlutil.checksafessh(source) | ||||
source = self._abssource(source) | source = self._abssource(source) | ||||
self.ui.status( | self.ui.status( | ||||
_(b'cloning subrepo %s from %s\n') % (self._relpath, source) | _(b'cloning subrepo %s from %s\n') % (self._relpath, source) | ||||
) | ) | ||||
self._gitnodir([b'clone', source, self._abspath]) | self._gitnodir([b'clone', source, self._abspath]) | ||||
if self._githavelocally(revision): | if self._githavelocally(revision): | ||||
return | return | ||||
▲ Show 20 Lines • Show All 481 Lines • Show Last 20 Lines |