diff --git a/README.txt b/README.txt --- a/README.txt +++ b/README.txt @@ -27,9 +27,8 @@ invalid, or because it was changed on th prompts the user again. Passwords are identified by the combination of username and remote -repository url (for HTTP) or username and smtp server address (for -SMTP), so they can be reused between repositories if they access -the same remote repository. +address, so they can be reused between repositories if they access the +same remote repository (or the same SMTP server). Installation ============ @@ -114,6 +113,11 @@ Simpler form with url-embedded name can [paths] bitbucket = https://User@bitbucket.org/User/project_name/ +If prefix is specified, it is used to identify the password (so all +repositories with the same prefix and the same username will share the +same password). Otherwise full repository URL is used for this +purpose. + Note: if both username and password are given in ``.hg/hgrc``, extension will use them without using the password database. If username is not given, extension will prompt for credentials every @@ -147,11 +151,12 @@ Usage Configure the repository as above, then just ``hg pull``, ``hg push``, etc. You should be asked for the password only once (per every -username+remote_repository_url combination). +username and remote repository prefix or url combination). + Similarly, for email, configure as above and just ``hg email``. -Again, you will be asked for the password once (per every -username+email_server_name+email_server_port). +Again, you will be asked for the password once (per every username and +email server address combination). Implementation details ====================== diff --git a/mercurial_keyring.py b/mercurial_keyring.py --- a/mercurial_keyring.py +++ b/mercurial_keyring.py @@ -22,6 +22,7 @@ import keyring from urlparse import urlparse import urllib2 import smtplib, socket +import os KEYRING_SERVICE = "Mercurial" @@ -110,8 +111,9 @@ class HTTPPasswordHandler(object): self.last_reply = dict(realm=realm,authuri=authuri,user=user) return user, pwd - # Loading username and maybe password and prefix URL from [auth] in .hg/hgrc - nuser, pwd, prefix_url = self.load_hgrc_auth(ui, base_url) + # Loading .hg/hgrc [auth] section contents. If prefix is given, + # it will be used as a key to lookup password in the keyring. + auth_user, pwd, prefix_url = self.load_hgrc_auth(ui, base_url) if prefix_url: keyring_url = prefix_url else: @@ -129,10 +131,10 @@ class HTTPPasswordHandler(object): self.last_reply = dict(realm=realm,authuri=authuri,user=user) return user, pwd - if nuser: + if auth_user: if user: - raise util.Abort(_('mercurial_keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, user, nuser))) - user = nuser + raise util.Abort(_('mercurial_keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, user, auth_user))) + user = auth_user if pwd: self.pwd_cache[cache_key] = user, pwd self._debug_reply(ui, _("Auth data set in .hg/hgrc"), @@ -186,8 +188,10 @@ class HTTPPasswordHandler(object): def load_hgrc_auth(self, ui, base_url): """ - Loading username and possibly password from [auth] in local - repo .hgrc + Loading [auth] section contents from local .hgrc + + Returns (username, password, prefix) tuple (every + element can be None) """ # Theoretically 3 lines below should do: @@ -204,7 +208,6 @@ class HTTPPasswordHandler(object): repo_root = ui.config("bundle", "mainreporoot") from mercurial.ui import ui as _ui - import os local_ui = _ui(ui) if repo_root: local_ui.readconfig(os.path.join(repo_root, ".hg", "hgrc")) @@ -217,7 +220,7 @@ class HTTPPasswordHandler(object): shortest_url = self.shortest_url(base_url, prefix) return username, password, shortest_url - return None, None + return None, None, None def shortest_url(self, base_url, prefix): if not prefix or prefix == '*':