[PATCH 2 of 3] url: remember http password database in ui object

liscju piotr.listkiewicz at gmail.com
Tue Jun 14 05:13:30 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1465465296 -7200
#      Thu Jun 09 11:41:36 2016 +0200
# Node ID 62fac77f1cd9e4270b2db7a7a987bc12783b41a8
# Parent  5ac51055840cf0031d8407f722784ce26f152079
url: remember http password database in ui object

This makes http password database stored in ui object.
It allows reusing authentication information when we
use this database for creating password manager for
the new connection.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -29,6 +29,8 @@ from . import (
     util,
 )
 
+urlreq = util.urlreq
+
 samplehgrcs = {
     'user':
 """# example user config (see "hg help config" for more info)
@@ -124,6 +126,8 @@ class ui(object):
             self.callhooks = src.callhooks
             self.insecureconnections = src.insecureconnections
             self.fixconfig()
+
+            self.httppasswordmgrdb = src.httppasswordmgrdb
         else:
             self.fout = sys.stdout
             self.ferr = sys.stderr
@@ -135,6 +139,8 @@ class ui(object):
             for f in scmutil.rcpath():
                 self.readconfig(f, trust=True)
 
+            self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
+
     def copy(self):
         return self.__class__(self)
 
diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -365,7 +365,7 @@ if has_https:
             urlreq.httpshandler.__init__(self)
             self.ui = ui
             self.pwmgr = passwordmgr(self.ui,
-                                     urlreq.httppasswordmgrwithdefaultrealm())
+                                     self.ui.httppasswordmgrdb)
 
         def _start_transaction(self, h, req):
             _generic_start_transaction(self, h, req)
@@ -482,7 +482,7 @@ def opener(ui, authinfo=None):
         handlers = [
             httpconnectionmod.http2handler(
                 ui,
-                passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()))
+                passwordmgr(ui, ui.httppasswordmgrdb))
         ]
     else:
         handlers = [httphandler()]
@@ -491,7 +491,7 @@ def opener(ui, authinfo=None):
 
     handlers.append(proxyhandler(ui))
 
-    passmgr = passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm())
+    passmgr = passwordmgr(ui, ui.httppasswordmgrdb)
     if authinfo is not None:
         passmgr.add_password(*authinfo)
         user, passwd = authinfo[2:4]


More information about the Mercurial-devel mailing list