[PATCH] suffix option in auth section to be used rather than prefix
Filip Gruszczyński
gruszczy at gmail.com
Thu Jul 14 12:09:40 UTC 2011
If you take a look at old Google Code mercurial addresses, you will
see that they look like this:
https://<project_name>.googlecode.com/hg/
I am pushing to several projects and they all use a common password,
which is generated by Google, so I wanted to store this password.
Unfortunately I need to set it for every project I commit to, because
there is no common prefix for them. I would like to set it once in
~/.hgrc and forget about this password forever. So I added suffix
option to auth section. My ~/.hgrc looks like this now:
[auth]
google.suffix = googlecode.com/hg/
google.username = gruszczy
google.password = ...
Which serves now all projects from Google Code :-)
# HG changeset patch
# User Filip Gruszczyński <gruszczy at gmail.com>
# Date 1310644828 -7200
# Node ID cc3c5603250c5292956cc3d98d872f7b3eb079e6
# Parent ddc4567a3d0b1d9e405e4c7974b8324e1aaf6036
providing suffix in .hgrc auth section and using it to determine which
auth entry should be used to authenticate to given host
diff -r ddc4567a3d0b -r cc3c5603250c mercurial/httpconnection.py
--- a/mercurial/httpconnection.py Wed Jul 13 19:30:27 2011 -0500
+++ b/mercurial/httpconnection.py Thu Jul 14 14:00:28 2011 +0200
@@ -77,16 +77,24 @@
bestauth = None
for group, auth in config.iteritems():
prefix = auth.get('prefix')
- if not prefix:
+ suffix = auth.get('suffix')
+ if prefix:
+ pattern = prefix
+ method = hostpath.startswith
+ elif suffix:
+ pattern = suffix
+ method = hostpath.split('?')[0].endswith
+ else:
+ print('no suffix or prefix')
continue
- p = prefix.split('://', 1)
+ p = pattern.split('://', 1)
if len(p) > 1:
- schemes, prefix = [p[0]], p[1]
+ schemes, pattern = [p[0]], p[1]
else:
schemes = (auth.get('schemes') or 'https').split()
- if (prefix == '*' or hostpath.startswith(prefix)) and \
- len(prefix) > bestlen and scheme in schemes:
- bestlen = len(prefix)
+ if (pattern == '*' or method(pattern)) and \
+ len(pattern) > bestlen and scheme in schemes:
+ bestlen = len(pattern)
bestauth = group, auth
return bestauth
--
Filip Gruszczyński
More information about the Mercurial-devel
mailing list