changeset 967:0b6a6a7c26f3

svnwrap: Improved handling of username_prompt_provider
author Mitsuhiro Koga <shiena.jp@gmail.com>
date Tue, 23 Oct 2012 20:12:10 +0900
parents 7561aef55a4b
children c500bc862215
files hgsubversion/svnrepo.py hgsubversion/svnwrap/subvertpy_wrapper.py hgsubversion/svnwrap/svn_swig_wrapper.py
diffstat 3 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnrepo.py
+++ b/hgsubversion/svnrepo.py
@@ -207,6 +207,11 @@ class SubversionPrompt(object):
             self.ui.write('Authentication realm: %s\n' % (realm,))
             self.ui.flush()
 
+    def username(self, realm, may_save, pool=None):
+        self.maybe_print_realm(realm)
+        username = self.ui.prompt('Username: ', default='')
+        return (username, bool(may_save))
+
     def simple(self, realm, default_username, may_save, pool=None):
         self.maybe_print_realm(realm)
         if default_username:
--- a/hgsubversion/svnwrap/subvertpy_wrapper.py
+++ b/hgsubversion/svnwrap/subvertpy_wrapper.py
@@ -206,13 +206,13 @@ class SubversionRepo(object):
         """
         def getclientstring():
             return 'hgsubversion'
-        # TODO: handle certificate authentication, Mercurial style
-        def getuser(realm, may_save):
-            return self.username or '', False
 
         def simple(realm, username, may_save):
             return _prompt.simple(realm, username, may_save)
 
+        def username(realm, may_save):
+            return _prompt.username(realm, may_save)
+
         def ssl_server_trust(realm, failures, cert_info, may_save):
             creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save)
             if creds is None:
@@ -230,11 +230,11 @@ class SubversionRepo(object):
             ra.get_ssl_client_cert_file_provider(),
             ra.get_ssl_client_cert_pw_file_provider(),
             ra.get_ssl_server_trust_file_provider(),
-            ra.get_username_prompt_provider(getuser, 0),
         ]
         if _prompt:
             providers += [
                 ra.get_simple_prompt_provider(simple, 2),
+                ra.get_username_prompt_provider(username, 2),
                 ra.get_ssl_server_trust_prompt_provider(ssl_server_trust),
             ]
 
--- a/hgsubversion/svnwrap/svn_swig_wrapper.py
+++ b/hgsubversion/svnwrap/svn_swig_wrapper.py
@@ -103,6 +103,12 @@ def _simple(realm, default_username, ms,
     (creds.username, creds.password, creds.may_save) = ret
     return creds
 
+def _username(realm, ms, pool):
+    ret = _prompt.username(realm, ms, pool)
+    creds = core.svn_auth_cred_username_t()
+    (creds.username, creds.may_save) = ret
+    return creds
+
 def _ssl_server_trust(realm, failures, cert_info, may_save, pool):
     cert = [
             cert_info.hostname,
@@ -166,6 +172,7 @@ def _create_auth_baton(pool, password_st
     if _prompt:
         providers += [
             client.get_simple_prompt_provider(_simple, 2),
+            client.get_username_prompt_provider(_username, 2),
             client.get_ssl_server_trust_prompt_provider(_ssl_server_trust),
             ]