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