annotate svncommands.py @ 243:2027f851d60c

Small cleanups: remove unneeded imports, useless superclass.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Apr 2009 17:54:30 +0200
parents 06130689a2c8
children 28d0ee605308
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
1 import os
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
2
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
3 from mercurial import hg
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
4 from mercurial import node
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
5 from mercurial import util as hgutil
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
6
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
7 from svn import core
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
8 from svn import delta
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
9
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
10 import hg_delta_editor
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
11 import svnwrap
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
12 import stupid as stupidmod
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
13 import cmdutil
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
14 import util
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
15 import utility_commands
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
16
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
17
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
18 def pull(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
19 tag_locations='tags', authors=None, filemap=None, **opts):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
20 """pull new revisions from Subversion
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
21 """
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
22 svn_url = util.normalize_url(svn_url)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
23 old_encoding = util.swap_out_encoding()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
24 skipto_rev=int(skipto_rev)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
25 have_replay = not stupid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
26 if have_replay and not callable(
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
27 delta.svn_txdelta_apply(None, None, None)[0]): #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
28 ui.status('You are using old Subversion SWIG bindings. Replay will not'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
29 ' work until you upgrade to 1.5.0 or newer. Falling back to'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
30 ' a slower method that may be buggier. Please upgrade, or'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
31 ' contribute a patch to use the ctypes bindings instead'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
32 ' of SWIG.\n')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
33 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
34 initializing_repo = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
35 user = opts.get('username', hgutil.getuser())
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
36 passwd = opts.get('password', '')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
37 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
38 author_host = "@%s" % svn.uuid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
39 tag_locations = tag_locations.split(',')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
40 hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
41 ui_=ui,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
42 subdir=svn.subdir,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
43 author_host=author_host,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
44 tag_locations=tag_locations,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
45 authors=authors,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
46 filemap=filemap)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
47 if os.path.exists(hg_editor.uuid_file):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
48 uuid = open(hg_editor.uuid_file).read()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
49 assert uuid == svn.uuid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
50 start = hg_editor.last_known_revision()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
51 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
52 open(hg_editor.uuid_file, 'w').write(svn.uuid)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
53 open(hg_editor.svn_url_file, 'w').write(svn_url)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
54 initializing_repo = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
55 start = skipto_rev
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
56
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
57 if initializing_repo and start > 0:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
58 raise hgutil.Abort('Revision skipping at repository initialization '
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
59 'remains unimplemented.')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
60
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
61 # start converting revisions
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
62 for r in svn.revisions(start=start):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
63 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
64 hg_editor.update_branch_tag_map_for_rev(r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
65 for p in r.paths:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
66 if hg_editor._is_path_valid(p):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
67 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
68 break
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
69 if valid:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
70 # got a 502? Try more than once!
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
71 tries = 0
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
72 converted = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
73 while not converted:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
74 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
75 util.describe_revision(ui, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
76 if have_replay:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
77 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
78 cmdutil.replay_convert_rev(hg_editor, svn, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
79 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
80 ui.status('%s\n' % e.message)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
81 stupidmod.print_your_svn_is_old_message(ui)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
82 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
83 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
84 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
85 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
86 converted = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
87 except core.SubversionException, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
88 if (e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
89 and '502' in str(e)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
90 and tries < 3):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
91 tries += 1
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
92 ui.status('Got a 502, retrying (%s)\n' % tries)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
93 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
94 raise hgutil.Abort(*e.args)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
95 util.swap_out_encoding(old_encoding)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
96
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
97 pull = util.register_subcommand('pull')(pull)
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
98
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
99
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
100 def push(ui, repo, hg_repo_path, svn_url, stupid=False, **opts):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
101 """push revisions starting at a specified head back to Subversion.
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
102 """
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
103 old_encoding = util.swap_out_encoding()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
104 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
105 ui_=ui)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
106 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
107 hge.revmap.iterkeys()))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
108 user = opts.get('username', hgutil.getuser())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
109 passwd = opts.get('password', '')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
110
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
111 # Strategy:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
112 # 1. Find all outgoing commits from this head
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
113 if len(repo.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
114 ui.status('Cowardly refusing to push branch merge')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
115 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
116 workingrev = repo.parents()[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
117 outgoing = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingrev.node())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
118 if not (outgoing and len(outgoing)):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
119 ui.status('No revisions to push.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
120 return 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
121 while outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
122 oldest = outgoing.pop(-1)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
123 old_ctx = repo[oldest]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
124 if len(old_ctx.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
125 ui.status('Found a branch merge, this needs discussion and '
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
126 'implementation.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
127 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
128 base_n = old_ctx.parents()[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
129 old_children = repo[base_n].children()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
130 svnbranch = repo[base_n].branch()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
131 oldtip = base_n
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
132 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
133 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
134 while samebranchchildren:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
135 oldtip = samebranchchildren[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
136 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
137 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
138 # 2. Commit oldest revision that needs to be pushed
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
139 base_revision = svn_commit_hashes[base_n][0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
140 try:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
141 cmdutil.commit_from_rev(ui, repo, old_ctx, hge, svn_url,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
142 base_revision, user, passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
143 except cmdutil.NoFilesException:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
144 ui.warn("Could not push revision %s because it had no changes in svn.\n" %
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
145 old_ctx)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
146 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
147 # 3. Fetch revisions from svn
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
148 r = pull(ui, svn_url, hg_repo_path, stupid=stupid,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
149 username=user, password=passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
150 assert not r or r == 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
151 # 4. Find the new head of the target branch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
152 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
153 oldtipctx = repo[oldtip]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
154 replacement = [c for c in oldtipctx.children() if c not in old_children
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
155 and c.branch() == oldtipctx.branch()]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
156 assert len(replacement) == 1, 'Replacement node came back as: %r' % replacement
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
157 replacement = replacement[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
158 # 5. Rebase all children of the currently-pushing rev to the new branch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
159 heads = repo.heads(old_ctx.node())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
160 for needs_transplant in heads:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
161 def extrafn(ctx, extra):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
162 if ctx.node() == oldest:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
163 return
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
164 extra['branch'] = ctx.branch()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
165 utility_commands.rebase_commits(ui, repo,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
166 extrafn=extrafn,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
167 sourcerev=needs_transplant,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
168 **opts)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
169 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
170 for child in repo[replacement.node()].children():
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
171 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
172 if rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
173 while rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
174 rebsrcindex = outgoing.index(rebasesrc)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
175 outgoing = (outgoing[0:rebsrcindex] +
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
176 [child.node(), ] + outgoing[rebsrcindex+1:])
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
177 children = [c for c in child.children() if c.branch() == child.branch()]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
178 if children:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
179 child = children[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
180 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
181 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
182 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys()))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
183 util.swap_out_encoding(old_encoding)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
184 return 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
185 push = util.register_subcommand('push')(push)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
186 # for git expats
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
187 dcommit = util.register_subcommand('dcommit')(push)