annotate svncommands.py @ 244:28d0ee605308

Move diff to svncommands.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Apr 2009 18:21:47 +0200
parents 06130689a2c8
children 074f27c68818
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
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
5 from mercurial import patch
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
6 from mercurial import util as hgutil
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
7
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
8 from svn import core
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
9 from svn import delta
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
10
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
11 import hg_delta_editor
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
12 import svnwrap
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
13 import stupid as stupidmod
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
14 import cmdutil
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
15 import util
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
16 import utility_commands
241
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
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
19 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
20 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
21 """pull new revisions from Subversion
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
22 """
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
23 svn_url = util.normalize_url(svn_url)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
24 old_encoding = util.swap_out_encoding()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
25 skipto_rev=int(skipto_rev)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
26 have_replay = not stupid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
27 if have_replay and not callable(
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
28 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
29 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
30 ' 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
31 ' 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
32 ' 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
33 ' of SWIG.\n')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
34 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
35 initializing_repo = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
36 user = opts.get('username', hgutil.getuser())
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
37 passwd = opts.get('password', '')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
38 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
39 author_host = "@%s" % svn.uuid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
40 tag_locations = tag_locations.split(',')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
41 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
42 ui_=ui,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
43 subdir=svn.subdir,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
44 author_host=author_host,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
45 tag_locations=tag_locations,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
46 authors=authors,
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
47 filemap=filemap)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
48 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
49 uuid = open(hg_editor.uuid_file).read()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
50 assert uuid == svn.uuid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
51 start = hg_editor.last_known_revision()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
52 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
53 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
54 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
55 initializing_repo = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
56 start = skipto_rev
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
57
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
58 if initializing_repo and start > 0:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
59 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
60 'remains unimplemented.')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
61
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
62 # start converting revisions
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
63 for r in svn.revisions(start=start):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
64 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
65 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
66 for p in r.paths:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
67 if hg_editor._is_path_valid(p):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
68 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
69 break
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
70 if valid:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
71 # got a 502? Try more than once!
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
72 tries = 0
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
73 converted = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
74 while not converted:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
75 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
76 util.describe_revision(ui, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
77 if have_replay:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
78 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
79 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
80 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
81 ui.status('%s\n' % e.message)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
82 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
83 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
84 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
85 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
86 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
87 converted = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
88 except core.SubversionException, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
89 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
90 and '502' in str(e)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
91 and tries < 3):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
92 tries += 1
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
93 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
94 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
95 raise hgutil.Abort(*e.args)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
96 util.swap_out_encoding(old_encoding)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
97
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
98 pull = util.register_subcommand('pull')(pull)
242
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
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
101 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
102 """push revisions starting at a specified head back to Subversion.
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
103 """
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
104 old_encoding = util.swap_out_encoding()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
105 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
106 ui_=ui)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
107 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
108 hge.revmap.iterkeys()))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
109 user = opts.get('username', hgutil.getuser())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
110 passwd = opts.get('password', '')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
111
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
112 # Strategy:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
113 # 1. Find all outgoing commits from this head
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
114 if len(repo.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
115 ui.status('Cowardly refusing to push branch merge')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
116 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
117 workingrev = repo.parents()[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
118 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
119 if not (outgoing and len(outgoing)):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
120 ui.status('No revisions to push.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
121 return 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
122 while outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
123 oldest = outgoing.pop(-1)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
124 old_ctx = repo[oldest]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
125 if len(old_ctx.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
126 ui.status('Found a branch merge, this needs discussion and '
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
127 'implementation.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
128 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
129 base_n = old_ctx.parents()[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
130 old_children = repo[base_n].children()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
131 svnbranch = repo[base_n].branch()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
132 oldtip = base_n
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
133 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
134 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
135 while samebranchchildren:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
136 oldtip = samebranchchildren[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
137 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
138 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
139 # 2. Commit oldest revision that needs to be pushed
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
140 base_revision = svn_commit_hashes[base_n][0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
141 try:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
142 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
143 base_revision, user, passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
144 except cmdutil.NoFilesException:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
145 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
146 old_ctx)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
147 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
148 # 3. Fetch revisions from svn
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
149 r = pull(ui, svn_url, hg_repo_path, stupid=stupid,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
150 username=user, password=passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
151 assert not r or r == 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
152 # 4. Find the new head of the target branch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
153 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
154 oldtipctx = repo[oldtip]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
155 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
156 and c.branch() == oldtipctx.branch()]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
157 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
158 replacement = replacement[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
159 # 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
160 heads = repo.heads(old_ctx.node())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
161 for needs_transplant in heads:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
162 def extrafn(ctx, extra):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
163 if ctx.node() == oldest:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
164 return
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
165 extra['branch'] = ctx.branch()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
166 utility_commands.rebase_commits(ui, repo,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
167 extrafn=extrafn,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
168 sourcerev=needs_transplant,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
169 **opts)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
170 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
171 for child in repo[replacement.node()].children():
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
172 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
173 if rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
174 while rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
175 rebsrcindex = outgoing.index(rebasesrc)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
176 outgoing = (outgoing[0:rebsrcindex] +
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
177 [child.node(), ] + outgoing[rebsrcindex+1:])
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
178 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
179 if children:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
180 child = children[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
181 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
182 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
183 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
184 util.swap_out_encoding(old_encoding)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
185 return 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
186 push = util.register_subcommand('push')(push)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
187 # for git expats
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
188 dcommit = util.register_subcommand('dcommit')(push)
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
189
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
190
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
191 def diff(ui, repo, hg_repo_path, **opts):
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
192 """show a diff of the most recent revision against its parent from svn
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
193 """
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
194 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
195 ui_=ui)
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
196 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
197 hge.revmap.iterkeys()))
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
198 parent = repo.parents()[0]
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
199 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, parent.node())
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
200 if o_r:
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
201 parent = repo[o_r[-1]].parents()[0]
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
202 base_rev, _junk = svn_commit_hashes[parent.node()]
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
203 it = patch.diff(repo, parent.node(), None,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
204 opts=patch.diffopts(ui, opts={'git': True,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
205 'show_function': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
206 'ignore_all_space': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
207 'ignore_space_change': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
208 'ignore_blank_lines': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
209 'unified': True,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
210 'text': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
211 }))
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
212 ui.write(cmdutil.filterdiff(''.join(it), base_rev))
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
213 diff = util.register_subcommand('diff')(diff)