comparison push_cmd.py @ 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 4c3bad24f950
children 4950b18cf949
comparison
equal deleted inserted replaced
233:80a700398995 234:33e885f5f86a
27 old_encoding = util.swap_out_encoding() 27 old_encoding = util.swap_out_encoding()
28 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 28 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
29 ui_=ui) 29 ui_=ui)
30 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 30 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
31 hge.revmap.iterkeys())) 31 hge.revmap.iterkeys()))
32 user = opts.get('username', merc_util.getuser())
33 passwd = opts.get('password', '')
32 # Strategy: 34 # Strategy:
33 # 1. Find all outgoing commits from this head 35 # 1. Find all outgoing commits from this head
34 if len(repo.parents()) != 1: 36 if len(repo.parents()) != 1:
35 ui.status('Cowardly refusing to push branch merge') 37 ui.status('Cowardly refusing to push branch merge')
36 return 1 38 return 1
57 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch 59 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
58 and c.node() in svn_commit_hashes] 60 and c.node() in svn_commit_hashes]
59 # 2. Commit oldest revision that needs to be pushed 61 # 2. Commit oldest revision that needs to be pushed
60 base_revision = svn_commit_hashes[base_n][0] 62 base_revision = svn_commit_hashes[base_n][0]
61 try: 63 try:
62 commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision) 64 commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision,
65 user, passwd)
63 except NoFilesException: 66 except NoFilesException:
64 ui.warn("Could not push revision %s because it had no changes in svn.\n" % 67 ui.warn("Could not push revision %s because it had no changes in svn.\n" %
65 old_ctx) 68 old_ctx)
66 return 1 69 return 1
67 # 3. Fetch revisions from svn 70 # 3. Fetch revisions from svn
68 r = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path, 71 r = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path,
69 stupid=stupid) 72 stupid=stupid, username=user,
73 password=passwd)
70 assert not r or r == 0 74 assert not r or r == 0
71 # 4. Find the new head of the target branch 75 # 4. Find the new head of the target branch
72 repo = hg.repository(ui, hge.path) 76 repo = hg.repository(ui, hge.path)
73 oldtipctx = repo[oldtip] 77 oldtipctx = repo[oldtip]
74 replacement = [c for c in oldtipctx.children() if c not in old_children 78 replacement = [c for c in oldtipctx.children() if c not in old_children
180 ext = svnexternals.externalsfile() 184 ext = svnexternals.externalsfile()
181 if '.hgsvnexternals' in ctx: 185 if '.hgsvnexternals' in ctx:
182 ext.read(ctx['.hgsvnexternals'].data()) 186 ext.read(ctx['.hgsvnexternals'].data())
183 return ext 187 return ext
184 188
185 def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision): 189 def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision,
190 username, password):
186 """Build and send a commit from Mercurial to Subversion. 191 """Build and send a commit from Mercurial to Subversion.
187 """ 192 """
188 file_data = {} 193 file_data = {}
189 svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser()) 194 svn = svnwrap.SubversionRepo(svn_url, username, password)
190 parent = rev_ctx.parents()[0] 195 parent = rev_ctx.parents()[0]
191 parent_branch = rev_ctx.parents()[0].branch() 196 parent_branch = rev_ctx.parents()[0].branch()
192 branch_path = 'trunk' 197 branch_path = 'trunk'
193 198
194 if parent_branch and parent_branch != 'default': 199 if parent_branch and parent_branch != 'default':