# HG changeset patch # User Patrick Mezard # Date 1247967873 18000 # Node ID c82d5a9acecf60f67a5ca4c897da0501bf0023ab # Parent e43e4d506e4d65a435146e0eeccbfb7053fe3d12 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. diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- 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] diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- 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') diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- 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): diff --git a/hgsubversion/utility_commands.py b/hgsubversion/utility_commands.py --- 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() diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- 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)