hgext/convert/transport.py
changeset 4938 4db03fa58bd5
parent 4764 6a16ef0d1c7c
child 4957 cdd33a048289
equal deleted inserted replaced
4925:2642726b61b6 4938:4db03fa58bd5
    22 import os
    22 import os
    23 from tempfile import mktemp
    23 from tempfile import mktemp
    24 
    24 
    25 from svn.core import SubversionException, Pool
    25 from svn.core import SubversionException, Pool
    26 import svn.ra
    26 import svn.ra
       
    27 import svn.client
    27 import svn.core
    28 import svn.core
    28 
    29 
    29 # Some older versions of the Python bindings need to be 
    30 # Some older versions of the Python bindings need to be 
    30 # explicitly initialized. But what we want to do probably
    31 # explicitly initialized. But what we want to do probably
    31 # won't work worth a darn against those libraries anyway!
    32 # won't work worth a darn against those libraries anyway!
    46         svn.client.get_ssl_client_cert_pw_file_provider(pool),
    47         svn.client.get_ssl_client_cert_pw_file_provider(pool),
    47         svn.client.get_ssl_server_trust_file_provider(pool),
    48         svn.client.get_ssl_server_trust_file_provider(pool),
    48         ]
    49         ]
    49     return svn.core.svn_auth_open(providers, pool)
    50     return svn.core.svn_auth_open(providers, pool)
    50 
    51 
    51 
       
    52 #    # The SVN libraries don't like trailing slashes...
       
    53 #    return url.rstrip('/')
       
    54 
       
    55 
       
    56 class SvnRaCallbacks(svn.ra.callbacks2_t):
       
    57     """Remote access callbacks implementation for bzr-svn."""
       
    58     def __init__(self, pool):
       
    59         svn.ra.callbacks2_t.__init__(self)
       
    60         self.auth_baton = _create_auth_baton(pool)
       
    61         self.pool = pool
       
    62     
       
    63     def open_tmp_file(self, pool):
       
    64         return mktemp(prefix='tailor-svn')
       
    65 
       
    66 class NotBranchError(SubversionException):
    52 class NotBranchError(SubversionException):
    67     pass
    53     pass
    68 
    54 
    69 class SvnRaTransport(object):
    55 class SvnRaTransport(object):
    70     """
    56     """
    71     Open an ra connection to a Subversion repository.
    57     Open an ra connection to a Subversion repository.
    72     """
    58     """
    73     def __init__(self, url="", ra=None):
    59     def __init__(self, url="", ra=None):
    74         self.pool = Pool()
    60         self.pool = Pool()
    75         self.svn_url = url
    61         self.svn_url = url
       
    62         self.username = ''
       
    63         self.password = ''
    76 
    64 
    77         # Only Subversion 1.4 has reparent()
    65         # Only Subversion 1.4 has reparent()
    78         if ra is None or not hasattr(svn.ra, 'reparent'):
    66         if ra is None or not hasattr(svn.ra, 'reparent'):
    79             self.callbacks = SvnRaCallbacks(self.pool)
    67             self.client = svn.client.create_context(self.pool)
       
    68             ab = _create_auth_baton(self.pool)
       
    69             if False:
       
    70                 svn.core.svn_auth_set_parameter(
       
    71                     ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username)
       
    72                 svn.core.svn_auth_set_parameter(
       
    73                     ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password)
       
    74             self.client.auth_baton = ab
       
    75             self.client.config = svn_config
    80             try:
    76             try:
    81                 ver = svn.ra.version()
    77                 self.ra = svn.client.open_ra_session(
    82                 try: # Older SVN bindings
    78                     self.svn_url.encode('utf8'), 
    83                     self.ra = svn.ra.open2(self.svn_url.encode('utf8'), self.callbacks, None, svn_config, None)
    79                     self.client, self.pool)
    84                 except TypeError, e:
       
    85                     self.ra = svn.ra.open2(self.svn_url.encode('utf8'), self.callbacks, svn_config, None)
       
    86             except SubversionException, (_, num):
    80             except SubversionException, (_, num):
    87                 if num == svn.core.SVN_ERR_RA_ILLEGAL_URL:
    81                 if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL,
    88                     raise NotBranchError(url)
    82                            svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED,
    89                 if num == svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED:
    83                            svn.core.SVN_ERR_BAD_URL):
    90                     raise NotBranchError(url)
       
    91                 if num == svn.core.SVN_ERR_BAD_URL:
       
    92                     raise NotBranchError(url)
    84                     raise NotBranchError(url)
    93                 raise
    85                 raise
    94 
       
    95         else:
    86         else:
    96             self.ra = ra
    87             self.ra = ra
    97             svn.ra.reparent(self.ra, self.svn_url.encode('utf8'))
    88             svn.ra.reparent(self.ra, self.svn_url.encode('utf8'))
    98 
    89 
    99     class Reporter:
    90     class Reporter: