From 578aaf5fe93e250abeac6db3fc082da066ed62d7 Mon Sep 17 00:00:00 2001 From: Daniel Tang Date: Mon, 6 Apr 2009 02:52:14 -0400 Subject: [PATCH] Add --username and --password options to all commands --- __init__.py | 4 ++++ fetch_command.py | 4 +++- push_cmd.py | 13 +++++++++---- rebuildmeta.py | 4 +++- svnwrap/svn_swig_wrapper.py | 7 ++++++- utility_commands.py | 4 +++- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index 16bdb5d762..4fee39fd0c 100644 --- a/__init__.py +++ b/__init__.py @@ -79,6 +79,8 @@ cmdtable = { ('', 'filemap', '', 'remap file to exclude paths or include only certain paths'), ('', 'force', False, 'force an operation to happen'), + ('', 'username', '', 'username for authentication'), + ('', 'password', '', 'password for authentication'), ], svncommand.generate_help(), ), @@ -90,6 +92,8 @@ cmdtable = { ('A', 'authors', '', 'username mapping filename'), ('', 'filemap', '', 'remap file to exclude paths or include only certain paths'), + ('', 'username', '', 'username for authentication'), + ('', 'password', '', 'password for authentication'), ], 'hg svnclone source [dest]'), } diff --git a/fetch_command.py b/fetch_command.py index 365caf59c0..463b17d880 100644 --- a/fetch_command.py +++ b/fetch_command.py @@ -41,7 +41,9 @@ def fetch_revisions(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None, ' of SWIG.\n') have_replay = False initializing_repo = False - svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser()) + user = opts.get('username', merc_util.getuser()) + passwd = opts.get('password', '') + svn = svnwrap.SubversionRepo(svn_url, user, passwd) author_host = "@%s" % svn.uuid tag_locations = tag_locations.split(',') hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path, diff --git a/push_cmd.py b/push_cmd.py index 38fc28ce40..57296a7d7e 100644 --- a/push_cmd.py +++ b/push_cmd.py @@ -29,6 +29,8 @@ def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url, ui_=ui) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) + user = opts.get('username', merc_util.getuser()) + passwd = opts.get('password', '') # Strategy: # 1. Find all outgoing commits from this head if len(repo.parents()) != 1: @@ -59,14 +61,16 @@ def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url, # 2. Commit oldest revision that needs to be pushed base_revision = svn_commit_hashes[base_n][0] try: - commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision) + commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision, + user, passwd) except NoFilesException: ui.warn("Could not push revision %s because it had no changes in svn.\n" % old_ctx) return 1 # 3. Fetch revisions from svn r = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path, - stupid=stupid) + stupid=stupid, username=user, + password=passwd) assert not r or r == 0 # 4. Find the new head of the target branch repo = hg.repository(ui, hge.path) @@ -182,11 +186,12 @@ def _externals(ctx): ext.read(ctx['.hgsvnexternals'].data()) return ext -def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision): +def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision, + username, password): """Build and send a commit from Mercurial to Subversion. """ file_data = {} - svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser()) + svn = svnwrap.SubversionRepo(svn_url, username, password) parent = rev_ctx.parents()[0] parent_branch = rev_ctx.parents()[0].branch() branch_path = 'trunk' diff --git a/rebuildmeta.py b/rebuildmeta.py index 6cfbf65e02..c25cff6461 100644 --- a/rebuildmeta.py +++ b/rebuildmeta.py @@ -14,7 +14,9 @@ def rebuildmeta(ui, repo, hg_repo_path, args, **opts): raise mutil.Abort('You must pass the svn URI used to create this repo.') uuid = None url = args[0].rstrip('/') - svn = svnwrap.SubversionRepo(url=url) + user = opts.get('username', mutil.getuser()) + passwd = opts.get('password', '') + svn = svnwrap.SubversionRepo(url, user, passwd) subdir = svn.subdir svnmetadir = os.path.join(repo.path, 'svn') if not os.path.exists(svnmetadir): diff --git a/svnwrap/svn_swig_wrapper.py b/svnwrap/svn_swig_wrapper.py index ff4595b0e4..0fe9148559 100644 --- a/svnwrap/svn_swig_wrapper.py +++ b/svnwrap/svn_swig_wrapper.py @@ -118,9 +118,10 @@ class SubversionRepo(object): This uses the SWIG Python bindings, and will only work on svn >= 1.4. It takes a required param, the URL. """ - def __init__(self, url='', username=''): + def __init__(self, url='', username='', password=''): self.svn_url = url self.username = username + self.password = password self.auth_baton_pool = core.Pool() self.auth_baton = _create_auth_baton(self.auth_baton_pool) @@ -143,6 +144,10 @@ class SubversionRepo(object): core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) + if self.password: + core.svn_auth_set_parameter(self.auth_baton, + core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, + self.password) self.client_context = client.create_context() self.client_context.auth_baton = self.auth_baton diff --git a/utility_commands.py b/utility_commands.py index e1d003c5c9..44ff6dfe8d 100644 --- a/utility_commands.py +++ b/utility_commands.py @@ -50,7 +50,9 @@ def generate_ignore(ui, repo, hg_repo_path, force=False, **opts): url = hge.url if url[-1] == '/': url = url[:-1] - svn = svnwrap.SubversionRepo(url) + user = opts.get('username', mutil.getuser()) + passwd = opts.get('passwd', '') + svn = svnwrap.SubversionRepo(url, user, passwd) dirs = [''] + [d[0] for d in svn.list_files(branchpath, r) if d[1] == 'd'] for dir in dirs: props = svn.list_props('%s/%s/' % (branchpath,dir), r)