2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import logging
|
2009-11-20 22:03:40 +01:00
|
|
|
import os
|
2014-01-27 15:07:10 +01:00
|
|
|
|
2014-06-06 20:21:51 +02:00
|
|
|
from pip._vendor.six.moves import configparser
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.download import path_to_url
|
2018-09-24 23:53:39 +02:00
|
|
|
from pip._internal.utils.misc import display_path, make_vcs_requirement_url
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils.temp_dir import TempDirectory
|
|
|
|
from pip._internal.vcs import VersionControl, vcs
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
class Mercurial(VersionControl):
|
|
|
|
name = 'hg'
|
|
|
|
dirname = '.hg'
|
|
|
|
repo_name = 'clone'
|
|
|
|
schemes = ('hg', 'hg+http', 'hg+https', 'hg+ssh', 'hg+static-http')
|
|
|
|
|
2017-10-02 00:21:11 +02:00
|
|
|
def get_base_rev_args(self, rev):
|
|
|
|
return [rev]
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
def export(self, location):
|
|
|
|
"""Export the Hg repository at the url to the destination location"""
|
2017-06-01 14:54:29 +02:00
|
|
|
with TempDirectory(kind="export") as temp_dir:
|
|
|
|
self.unpack(temp_dir.path)
|
|
|
|
|
2015-03-10 12:28:09 +01:00
|
|
|
self.run_command(
|
2017-06-01 14:54:29 +02:00
|
|
|
['archive', location], show_stdout=False, cwd=temp_dir.path
|
|
|
|
)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2018-07-08 05:47:16 +02:00
|
|
|
def fetch_new(self, dest, url, rev_options):
|
|
|
|
rev_display = rev_options.to_display()
|
|
|
|
logger.info(
|
|
|
|
'Cloning hg %s%s to %s',
|
|
|
|
url,
|
|
|
|
rev_display,
|
|
|
|
display_path(dest),
|
|
|
|
)
|
|
|
|
self.run_command(['clone', '--noupdate', '-q', url, dest])
|
|
|
|
cmd_args = ['update', '-q'] + rev_options.to_args()
|
|
|
|
self.run_command(cmd_args, cwd=dest)
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
def switch(self, dest, url, rev_options):
|
|
|
|
repo_config = os.path.join(dest, self.dirname, 'hgrc')
|
2014-06-06 20:21:51 +02:00
|
|
|
config = configparser.SafeConfigParser()
|
2009-11-20 22:03:40 +01:00
|
|
|
try:
|
|
|
|
config.read(repo_config)
|
|
|
|
config.set('paths', 'default', url)
|
2014-10-02 23:45:37 +02:00
|
|
|
with open(repo_config, 'w') as config_file:
|
|
|
|
config.write(config_file)
|
2014-06-06 20:21:51 +02:00
|
|
|
except (OSError, configparser.NoSectionError) as exc:
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.warning(
|
|
|
|
'Could not switch Mercurial repository to %s: %s', url, exc,
|
|
|
|
)
|
2009-11-20 22:03:40 +01:00
|
|
|
else:
|
2017-10-02 00:21:11 +02:00
|
|
|
cmd_args = ['update', '-q'] + rev_options.to_args()
|
|
|
|
self.run_command(cmd_args, cwd=dest)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2018-07-17 18:36:48 +02:00
|
|
|
def update(self, dest, url, rev_options):
|
2015-03-10 12:28:09 +01:00
|
|
|
self.run_command(['pull', '-q'], cwd=dest)
|
2017-10-02 00:21:11 +02:00
|
|
|
cmd_args = ['update', '-q'] + rev_options.to_args()
|
|
|
|
self.run_command(cmd_args, cwd=dest)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2019-01-07 01:31:06 +01:00
|
|
|
@classmethod
|
|
|
|
def get_remote_url(cls, location):
|
|
|
|
url = cls.run_command(
|
2015-03-10 12:28:09 +01:00
|
|
|
['showconfig', 'paths.default'],
|
2009-11-20 22:03:40 +01:00
|
|
|
show_stdout=False, cwd=location).strip()
|
2019-01-07 01:31:06 +01:00
|
|
|
if cls._is_local_repository(url):
|
2013-11-19 07:12:41 +01:00
|
|
|
url = path_to_url(url)
|
2009-11-20 22:03:40 +01:00
|
|
|
return url.strip()
|
|
|
|
|
2019-01-07 01:35:56 +01:00
|
|
|
@classmethod
|
|
|
|
def get_revision(cls, location):
|
|
|
|
current_revision = cls.run_command(
|
2015-03-10 12:28:09 +01:00
|
|
|
['parents', '--template={rev}'],
|
2009-11-20 22:03:40 +01:00
|
|
|
show_stdout=False, cwd=location).strip()
|
|
|
|
return current_revision
|
|
|
|
|
2019-01-07 01:35:56 +01:00
|
|
|
@classmethod
|
|
|
|
def get_revision_hash(cls, location):
|
|
|
|
current_rev_hash = cls.run_command(
|
2015-03-10 12:28:09 +01:00
|
|
|
['parents', '--template={node}'],
|
2009-11-20 22:03:40 +01:00
|
|
|
show_stdout=False, cwd=location).strip()
|
|
|
|
return current_rev_hash
|
|
|
|
|
2018-11-08 13:19:09 +01:00
|
|
|
def get_src_requirement(self, location, project_name):
|
2018-11-10 07:55:59 +01:00
|
|
|
repo = self.get_remote_url(location)
|
2009-11-20 22:03:40 +01:00
|
|
|
if not repo.lower().startswith('hg:'):
|
|
|
|
repo = 'hg+' + repo
|
|
|
|
current_rev_hash = self.get_revision_hash(location)
|
2018-11-08 13:19:09 +01:00
|
|
|
return make_vcs_requirement_url(repo, current_rev_hash, project_name)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2017-10-03 10:21:55 +02:00
|
|
|
def is_commit_id_equal(self, dest, name):
|
2015-08-31 22:52:01 +02:00
|
|
|
"""Always assume the versions don't match"""
|
|
|
|
return False
|
|
|
|
|
2017-06-13 18:19:46 +02:00
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
vcs.register(Mercurial)
|