Mercurial > hgsubversion
changeset 463:c82d5a9acecf
Unify svn credentials handling as config entries
It has 2 benefits:
- It generalizes the use of hgsubversion.username/password initiated in
push/pull.
- Command line options are no longer need to create SubversionRepo, so we can
move this out of command handling code.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sat, 18 Jul 2009 20:44:33 -0500 |
parents | e43e4d506e4d |
children | 0f7095f53ca3 |
files | hgsubversion/__init__.py hgsubversion/svncommands.py hgsubversion/util.py hgsubversion/utility_commands.py hgsubversion/wrappers.py |
diffstat | 5 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -106,6 +106,11 @@ def svn(ui, repo, subcommand, *args, **o if len(candidates) == 1: subcommand = candidates[0] + # override subversion credentials + for key in ('username', 'password'): + if key in opts: + ui.setconfig('hgsubversion', key, opts[key]) + path = os.path.dirname(repo.path) try: commandfunc = svncommands.table[subcommand]
--- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -34,7 +34,7 @@ def verify(ui, repo, *args, **opts): ui.write('verifying %s against r%i\n' % (ctx, srev)) url = util.normalize_url(url.rstrip('/')) - user, passwd = util.getuserpass(opts) + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(url, user, passwd) btypes = {'default': 'trunk'} @@ -75,7 +75,7 @@ def rebuildmeta(ui, repo, hg_repo_path, url = repo.ui.expandpath(dest or 'default-push', dest or 'default') uuid = None url = util.normalize_url(url.rstrip('/')) - user, passwd = util.getuserpass(opts) + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(url, user, passwd) subdir = svn.subdir svnmetadir = os.path.join(repo.path, 'svn')
--- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -60,12 +60,13 @@ def islocalrepo(url): return False -def getuserpass(opts): +def getuserpass(ui): # DO NOT default the user to hg's getuser(). If you provide # *any* default username to Subversion, it won't use any remembered # username for the desired realm, breaking OS X Keychain support, # GNOME keyring support, and all similar tools. - return opts.get('username', None), opts.get('password', '') + return (ui.config('hgsubversion', 'username'), + ui.config('hgsubversion', 'password')) def version(ui):
--- a/hgsubversion/utility_commands.py +++ b/hgsubversion/utility_commands.py @@ -13,7 +13,7 @@ def genignore(ui, repo, force=False, **o if not force and os.path.exists(ignpath): raise hgutil.Abort('not overwriting existing .hgignore, try --force?') url = util.normalize_url(repo.ui.config('paths', 'default')) - user, passwd = util.getuserpass(opts) + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(url, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid) hashes = meta.revmap.hashes() @@ -36,7 +36,7 @@ def info(ui, repo, hg_repo_path, **opts) """show Subversion details similar to `svn info' """ url = util.normalize_url(repo.ui.config('paths', 'default')) - user, passwd = util.getuserpass(opts) + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(url, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid) hashes = meta.revmap.hashes()
--- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -53,7 +53,7 @@ def incoming(orig, ui, repo, source='def if 'subversion' not in other.capabilities: return orig(ui, repo, source, **opts) - user, passwd = util.getuserpass(opts) + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(other.svnurl, user, passwd) meta = svnmeta.SVNMeta(repo) @@ -119,8 +119,7 @@ def push(repo, dest, force, revs): # split of #rev; TODO: implement --rev/#rev support svnurl, revs, checkout = hg.parseurl(svnurl, revs) # TODO: do credentials specified in the URL still work? - user = repo.ui.config('hgsubversion', 'username') - passwd = repo.ui.config('hgsubversion', 'password') + user, passwd = util.getuserpass(ui) svn = svnwrap.SubversionRepo(svnurl, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid) @@ -231,8 +230,7 @@ def pull(repo, source, heads=[], force=F repo.ui.note('fetching stupidly...\n') # TODO: do credentials specified in the URL still work? - user = repo.ui.config('hgsubversion', 'username') - passwd = repo.ui.config('hgsubversion', 'password') + user, passwd = util.getuserpass(repo.ui) svn = svnwrap.SubversionRepo(svn_url, user, passwd) meta = svnmeta.SVNMeta(repo, svn.uuid, svn.subdir)