From 7d525ec923196de87f4fc5cdea3466376450fef8 Mon Sep 17 00:00:00 2001 From: Takumi IINO Date: Tue, 17 Jun 2014 15:42:37 +0900 Subject: [PATCH] git_handler: use mercurial's password manager mercurial has useful own password manager. --- hggit/git_handler.py | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/hggit/git_handler.py b/hggit/git_handler.py index 00db0f243c..2d2624dc52 100644 --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -23,6 +23,7 @@ from mercurial.i18n import _ from mercurial.node import hex, bin, nullid from mercurial import context, util as hgutil from mercurial import error +from mercurial import url import _ssh import hg2git @@ -1418,7 +1419,7 @@ class GitHandler(object): if not httpclient: raise RepoError('git via HTTP requires dulwich 0.8.1 or later') else: - auth_handler = urllib2.HTTPBasicAuthHandler(AuthManager(self.ui)) + auth_handler = urllib2.HTTPBasicAuthHandler(url.passwordmgr(self.ui)) opener = urllib2.build_opener(auth_handler) try: return client.HttpGitClient(uri, opener=opener, thin_packs=False), uri @@ -1432,31 +1433,3 @@ class GitHandler(object): # if its not git or git+ssh, try a local url.. return client.SubprocessGitClient(thin_packs=False), uri - -class AuthManager(object): - def __init__(self, ui): - self.ui = ui - - def add_password(self, realm, uri, user, passwd): - raise NotImplementedError( - 'AuthManager currently gets passwords from hg repo config') - - def find_user_password(self, realm, authuri): - - # find a stanza in the auth section which matches this uri - for item in self.ui.configitems('auth'): - if len(item) < 2: - continue - if item[0].endswith('.prefix') and authuri.startswith(item[1]): - prefix = item[0][:-len('.prefix')] - break - else: - # no matching stanza found! - return (None,None) - - self.ui.note(_('using "%s" auth credentials\n') % (prefix,)) - username = self.ui.config('auth', '%s.username' % prefix) - password = self.ui.config('auth', '%s.password' % prefix) - - return (username,password) -