##// END OF EJS Templates
Slightly polishing the prefix patch:...
Marcin Kasperski -
r46:e0c8034c default
parent child Browse files
Show More
@@ -27,9 +27,8 b' invalid, or because it was changed on th'
27 27 prompts the user again.
28 28
29 29 Passwords are identified by the combination of username and remote
30 repository url (for HTTP) or username and smtp server address (for
31 SMTP), so they can be reused between repositories if they access
32 the same remote repository.
30 address, so they can be reused between repositories if they access the
31 same remote repository (or the same SMTP server).
33 32
34 33 Installation
35 34 ============
@@ -114,6 +113,11 b' Simpler form with url-embedded name can '
114 113 [paths]
115 114 bitbucket = https://User@bitbucket.org/User/project_name/
116 115
116 If prefix is specified, it is used to identify the password (so all
117 repositories with the same prefix and the same username will share the
118 same password). Otherwise full repository URL is used for this
119 purpose.
120
117 121 Note: if both username and password are given in ``.hg/hgrc``,
118 122 extension will use them without using the password database. If
119 123 username is not given, extension will prompt for credentials every
@@ -147,11 +151,12 b' Usage'
147 151
148 152 Configure the repository as above, then just ``hg pull``, ``hg push``,
149 153 etc. You should be asked for the password only once (per every
150 username+remote_repository_url combination).
154 username and remote repository prefix or url combination).
155
151 156
152 157 Similarly, for email, configure as above and just ``hg email``.
153 Again, you will be asked for the password once (per every
154 username+email_server_name+email_server_port).
158 Again, you will be asked for the password once (per every username and
159 email server address combination).
155 160
156 161 Implementation details
157 162 ======================
@@ -22,6 +22,7 b' import keyring'
22 22 from urlparse import urlparse
23 23 import urllib2
24 24 import smtplib, socket
25 import os
25 26
26 27 KEYRING_SERVICE = "Mercurial"
27 28
@@ -110,8 +111,9 b' class HTTPPasswordHandler(object):'
110 111 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
111 112 return user, pwd
112 113
113 # Loading username and maybe password and prefix URL from [auth] in .hg/hgrc
114 nuser, pwd, prefix_url = self.load_hgrc_auth(ui, base_url)
114 # Loading .hg/hgrc [auth] section contents. If prefix is given,
115 # it will be used as a key to lookup password in the keyring.
116 auth_user, pwd, prefix_url = self.load_hgrc_auth(ui, base_url)
115 117 if prefix_url:
116 118 keyring_url = prefix_url
117 119 else:
@@ -129,10 +131,10 b' class HTTPPasswordHandler(object):'
129 131 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
130 132 return user, pwd
131 133
132 if nuser:
134 if auth_user:
133 135 if user:
134 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)))
135 user = nuser
136 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)))
137 user = auth_user
136 138 if pwd:
137 139 self.pwd_cache[cache_key] = user, pwd
138 140 self._debug_reply(ui, _("Auth data set in .hg/hgrc"),
@@ -186,8 +188,10 b' class HTTPPasswordHandler(object):'
186 188
187 189 def load_hgrc_auth(self, ui, base_url):
188 190 """
189 Loading username and possibly password from [auth] in local
190 repo .hgrc
191 Loading [auth] section contents from local .hgrc
192
193 Returns (username, password, prefix) tuple (every
194 element can be None)
191 195 """
192 196 # Theoretically 3 lines below should do:
193 197
@@ -204,7 +208,6 b' class HTTPPasswordHandler(object):'
204 208 repo_root = ui.config("bundle", "mainreporoot")
205 209
206 210 from mercurial.ui import ui as _ui
207 import os
208 211 local_ui = _ui(ui)
209 212 if repo_root:
210 213 local_ui.readconfig(os.path.join(repo_root, ".hg", "hgrc"))
@@ -217,7 +220,7 b' class HTTPPasswordHandler(object):'
217 220 shortest_url = self.shortest_url(base_url, prefix)
218 221 return username, password, shortest_url
219 222
220 return None, None
223 return None, None, None
221 224
222 225 def shortest_url(self, base_url, prefix):
223 226 if not prefix or prefix == '*':
General Comments 0
You need to be logged in to leave comments. Login now