Add --username and --password options to all commands

This commit is contained in:
Daniel Tang 2009-04-06 02:52:14 -04:00
parent 8140653efb
commit 578aaf5fe9
6 changed files with 28 additions and 8 deletions

View File

@ -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]'),
}

View File

@ -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,

View File

@ -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'

View File

@ -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):

View File

@ -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

View File

@ -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)