changeset 234:33e885f5f86a

Add --username and --password options to all commands
author Daniel Tang <dytang@cs.purdue.edu>
date Mon, 06 Apr 2009 02:52:14 -0400
parents 80a700398995
children 2969a20e0eef
files __init__.py fetch_command.py push_cmd.py rebuildmeta.py svnwrap/svn_swig_wrapper.py utility_commands.py
diffstat 6 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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]'),
 }
--- a/fetch_command.py
+++ b/fetch_command.py
@@ -41,7 +41,9 @@ def fetch_revisions(ui, svn_url, hg_repo
                   ' 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,
--- a/push_cmd.py
+++ b/push_cmd.py
@@ -29,6 +29,8 @@ def push_revisions_to_subversion(ui, rep
                                            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, rep
         # 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'
--- a/rebuildmeta.py
+++ b/rebuildmeta.py
@@ -14,7 +14,9 @@ def rebuildmeta(ui, repo, hg_repo_path, 
         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):
--- 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
--- a/utility_commands.py
+++ b/utility_commands.py
@@ -50,7 +50,9 @@ def generate_ignore(ui, repo, hg_repo_pa
     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)