Mercurial > hgsubversion
comparison svncommands.py @ 241:4950b18cf949
Move fetch_command.fetch_revisions() to svncommands.pull().
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 08 Apr 2009 17:49:30 +0200 |
parents | |
children | 06130689a2c8 |
comparison
equal
deleted
inserted
replaced
240:1aa1d2d406d9 | 241:4950b18cf949 |
---|---|
1 import os | |
2 | |
3 from mercurial import util as hgutil | |
4 from svn import core | |
5 from svn import delta | |
6 | |
7 import hg_delta_editor | |
8 import svnwrap | |
9 import stupid as stupidmod | |
10 import cmdutil | |
11 import util | |
12 | |
13 | |
14 def pull(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None, | |
15 tag_locations='tags', authors=None, filemap=None, **opts): | |
16 """pull new revisions from Subversion | |
17 """ | |
18 svn_url = util.normalize_url(svn_url) | |
19 old_encoding = util.swap_out_encoding() | |
20 skipto_rev=int(skipto_rev) | |
21 have_replay = not stupid | |
22 if have_replay and not callable( | |
23 delta.svn_txdelta_apply(None, None, None)[0]): #pragma: no cover | |
24 ui.status('You are using old Subversion SWIG bindings. Replay will not' | |
25 ' work until you upgrade to 1.5.0 or newer. Falling back to' | |
26 ' a slower method that may be buggier. Please upgrade, or' | |
27 ' contribute a patch to use the ctypes bindings instead' | |
28 ' of SWIG.\n') | |
29 have_replay = False | |
30 initializing_repo = False | |
31 user = opts.get('username', hgutil.getuser()) | |
32 passwd = opts.get('password', '') | |
33 svn = svnwrap.SubversionRepo(svn_url, user, passwd) | |
34 author_host = "@%s" % svn.uuid | |
35 tag_locations = tag_locations.split(',') | |
36 hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path, | |
37 ui_=ui, | |
38 subdir=svn.subdir, | |
39 author_host=author_host, | |
40 tag_locations=tag_locations, | |
41 authors=authors, | |
42 filemap=filemap) | |
43 if os.path.exists(hg_editor.uuid_file): | |
44 uuid = open(hg_editor.uuid_file).read() | |
45 assert uuid == svn.uuid | |
46 start = hg_editor.last_known_revision() | |
47 else: | |
48 open(hg_editor.uuid_file, 'w').write(svn.uuid) | |
49 open(hg_editor.svn_url_file, 'w').write(svn_url) | |
50 initializing_repo = True | |
51 start = skipto_rev | |
52 | |
53 if initializing_repo and start > 0: | |
54 raise hgutil.Abort('Revision skipping at repository initialization ' | |
55 'remains unimplemented.') | |
56 | |
57 # start converting revisions | |
58 for r in svn.revisions(start=start): | |
59 valid = True | |
60 hg_editor.update_branch_tag_map_for_rev(r) | |
61 for p in r.paths: | |
62 if hg_editor._is_path_valid(p): | |
63 valid = True | |
64 break | |
65 if valid: | |
66 # got a 502? Try more than once! | |
67 tries = 0 | |
68 converted = False | |
69 while not converted: | |
70 try: | |
71 util.describe_revision(ui, r) | |
72 if have_replay: | |
73 try: | |
74 cmdutil.replay_convert_rev(hg_editor, svn, r) | |
75 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover | |
76 ui.status('%s\n' % e.message) | |
77 stupidmod.print_your_svn_is_old_message(ui) | |
78 have_replay = False | |
79 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r) | |
80 else: | |
81 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r) | |
82 converted = True | |
83 except core.SubversionException, e: #pragma: no cover | |
84 if (e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED | |
85 and '502' in str(e) | |
86 and tries < 3): | |
87 tries += 1 | |
88 ui.status('Got a 502, retrying (%s)\n' % tries) | |
89 else: | |
90 raise hgutil.Abort(*e.args) | |
91 util.swap_out_encoding(old_encoding) | |
92 | |
93 pull = util.register_subcommand('pull')(pull) |