Changeset - b8c69e4deacd
[Not reviewed]
default
0 6 0
Thomas De Schampheleire - 11 years ago 2015-01-24 22:07:35
thomas.de_schampheleire@alcatel-lucent.com
remotes: add support to clone from Mercurial repositories over ssh

This commit adds support to clone a remote Mercurial repository over ssh.

Interactive password authentication is not implemented, nor is support for
pbulic key authentication with passphrases; the repository should be
accessible using bare ssh key authentication.
For this reason, the ssh options -oBatchMode=yes and -oIdentitiesOnly=yes
are added to the ui.ssh setting of Mercurial.
6 files changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/utils.py
Show inline comments
 
@@ -378,12 +378,17 @@ def make_ui(read_from='file', path=None,
 
                # force set push_ssl requirement to False, kallithea
 
                # handles that
 
                baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key),
 
                                 False)
 
        if clear_session:
 
            meta.Session.remove()
 

	
 
        # prevent interactive questions for ssh password / passphrase
 
        ssh = baseui.config('ui', 'ssh', default='ssh')
 
        baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh)
 

	
 
    return baseui
 

	
 

	
 
def set_app_settings(config):
 
    """
 
    Updates pylons config with new settings from database
kallithea/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -28,13 +28,13 @@ from kallithea.lib.vcs.utils import (
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 
from kallithea.lib.vcs.utils.ordered_dict import OrderedDict
 
from kallithea.lib.vcs.utils.paths import abspath
 
from kallithea.lib.vcs.utils.hgcompat import (
 
    ui, nullid, match, patch, diffopts, clone, get_contact, pull,
 
    localrepository, RepoLookupError, Abort, RepoError, hex, scmutil, hg_url,
 
    httpbasicauthhandler, httpdigestauthhandler, peer, httppeer
 
    httpbasicauthhandler, httpdigestauthhandler, peer, httppeer, sshpeer
 
)
 

	
 
from .changeset import MercurialChangeset
 
from .inmemory import MercurialInMemoryChangeset
 
from .workdir import MercurialWorkdir
 

	
 
@@ -279,12 +279,18 @@ class MercurialRepository(BaseRepository
 
        when the return code is non 200
 
        """
 
        # check first if it's not an local url
 
        if os.path.isdir(url) or url.startswith('file:'):
 
            return True
 

	
 
        if url.startswith('ssh:'):
 
            # in case of invalid uri or authentication issues, sshpeer will
 
            # throw an exception.
 
            sshpeer(repoui or ui.ui(), url).lookup('tip')
 
            return True
 

	
 
        url_prefix = None
 
        if '+' in url[:url.find('://')]:
 
            url_prefix, url = url.split('+', 1)
 

	
 
        handlers = []
 
        url_obj = hg_url(url)
kallithea/lib/vcs/utils/hgcompat.py
Show inline comments
 
@@ -22,12 +22,13 @@ from mercurial.match import match
 
from mercurial.mdiff import diffopts
 
from mercurial.node import hex
 
from mercurial.encoding import tolocal
 
from mercurial.discovery import findcommonoutgoing
 
from mercurial.hg import peer
 
from mercurial.httppeer import httppeer
 
from mercurial.sshpeer import sshpeer
 
from mercurial.util import url as hg_url
 
from mercurial.scmutil import revrange
 
from mercurial.node import nullrev
 

	
 
# those authnadlers are patched for python 2.6.5 bug an
 
# infinit looping when given invalid resources
kallithea/model/validators.py
Show inline comments
 
@@ -441,13 +441,13 @@ def SlugifyName():
 
def ValidCloneUri():
 
    from kallithea.lib.utils import make_ui
 

	
 
    def url_handler(repo_type, url, ui):
 
        if repo_type == 'hg':
 
            from kallithea.lib.vcs.backends.hg.repository import MercurialRepository
 
            if url.startswith('http'):
 
            if url.startswith('http') or url.startswith('ssh'):
 
                # initially check if it's at least the proper URL
 
                # or does it pass basic auth
 
                MercurialRepository._check_url(url, ui)
 
            elif url.startswith('svn+http'):
 
                from hgsubversion.svnrepo import svnremoterepo
 
                svnremoterepo(ui, url).svn.uuid
 
@@ -470,13 +470,13 @@ def ValidCloneUri():
 
                raise Exception('clone from URI %s not allowed' % (url))
 

	
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'clone_uri': _(u'invalid clone url'),
 
            'invalid_clone_uri': _(u'Invalid clone url, provide a '
 
                                    'valid clone http(s)/svn+http(s) url')
 
                                    'valid clone http(s)/svn+http(s)/ssh url')
 
        }
 

	
 
        def validate_python(self, value, state):
 
            repo_type = value.get('repo_type')
 
            url = value.get('clone_uri')
 

	
kallithea/templates/admin/repos/repo_add_base.html
Show inline comments
 
@@ -21,13 +21,13 @@ ${h.form(url('repos'))}
 
        <div id="remote_clone" class="field" style="display: none">
 
            <div class="label">
 
                <label for="clone_uri">${_('Clone from')}:</label>
 
            </div>
 
            <div class="input">
 
                ${h.text('clone_uri',class_="small")}
 
                <span class="help-block">${_('Optional http[s] url from which repository should be cloned.')}</span>
 
                <span class="help-block">${_('Optional url from which repository should be cloned.')}</span>
 
            </div>
 
        </div>
 
        <div class="field">
 
            <div class="label label-textarea">
 
                <label for="repo_description">${_('Description')}:</label>
 
            </div>
kallithea/templates/admin/repos/repo_edit_settings.html
Show inline comments
 
@@ -31,13 +31,13 @@ ${h.form(url('repo', repo_name=c.repo_in
 
                    </div>
 
                   %else:
 
                    ## not set yet, display form to set it
 
                    ${h.text('clone_uri',class_="medium")}
 
                    ${h.hidden('clone_uri_change', 'NEW')}
 
                   %endif
 
                 <span id="alter_clone_uri_help_block" class="help-block">${_('http[s] url used for doing remote pulls.')}</span>
 
                 <span id="alter_clone_uri_help_block" class="help-block">${_('Url used for doing remote pulls.')}</span>
 
               </div>
 
            </div>
 
            <div class="field">
 
                <div class="label">
 
                    <label for="repo_group">${_('Repository group')}:</label>
 
                </div>
0 comments (0 inline, 0 general)