diff --git a/mercurial_keyring.py b/mercurial_keyring.py --- a/mercurial_keyring.py +++ b/mercurial_keyring.py @@ -317,7 +317,8 @@ class HTTPPasswordHandler(object): """ ui = pwmgr.ui - base_url, url_user, url_passwd = self.unpack_url(authuri) + parsed_url, url_user, url_passwd = self.unpack_url(authuri) + base_url = str(parsed_url) ui.debug(_('keyring: base url: %s, url user: %s, url pwd: %s\n') % (base_url, url_user or '', url_passwd and '******' or '')) @@ -335,7 +336,7 @@ class HTTPPasswordHandler(object): # Consult configuration to normalize url to prefix, and find username # (and maybe password) auth_user, auth_pwd, keyring_url = self.get_url_config( - ui, base_url, url_user) + ui, parsed_url, url_user) if auth_user and url_user and (url_user != auth_user): raise util.Abort(_('keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, url_user, auth_user))) if auth_user and auth_pwd: @@ -415,7 +416,7 @@ class HTTPPasswordHandler(object): _debug(ui, _("Manually entered password")) return user, pwd - def get_url_config(self, ui, base_url, user): + def get_url_config(self, ui, parsed_url, user): """ Checks configuration to decide whether/which username, prefix, and password are configured for given url. Consults [auth] section. @@ -424,9 +425,17 @@ class HTTPPasswordHandler(object): found. username and password can be None (if unset), if prefix is not found, url itself is returned. """ + base_url = str(parsed_url) + from mercurial.httpconnection import readauthforuri _debug(ui, _("Checking for hgrc info about url %s, user %s") % (base_url, user)) res = readauthforuri(ui, base_url, user) + # If it user-less version not work, let's try with added username to handle + # both config conventions + if (not res) and user: + parsed_url.user = user + res = readauthforuri(ui, str(parsed_url), user) + parsed_url.user = None if res: group, auth_token = res else: @@ -503,6 +512,8 @@ class HTTPPasswordHandler(object): (so prefix matching works properly) Returns url, user, password + where url is mercurial.util.url object already stripped of all those + params. """ # mercurial.util.url, rather handy url parser parsed_url = util.url(authuri) @@ -516,7 +527,7 @@ class HTTPPasswordHandler(object): parsed_url.user = None parsed_url.passwd = None - return str(parsed_url), user, passwd + return parsed_url, user, passwd ############################################################