annotate hgsubversion/wrappers.py @ 367:ce64d57172a3

Generate separate data structure containing revision's tags/branches changes.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 29 May 2009 17:33:52 +0200
parents 25ebdc16b05b
children afe93f14a361
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 import os
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2
264
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
3 from hgext import rebase as hgrebase
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
4
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 from mercurial import cmdutil as hgcmdutil
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 from mercurial import commands
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 from mercurial import patch
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 from mercurial import hg
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 from mercurial import util as hgutil
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 from mercurial import node
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
11 from mercurial import i18n
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 from svn import core
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14 from svn import delta
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 import cmdutil
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 import hg_delta_editor
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 import stupid as stupidmod
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 import svnwrap
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 import util
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21
366
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
22 pullfuns = {
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
23 True: cmdutil.replay_convert_rev,
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
24 False: stupidmod.convert_rev,
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
25 }
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
26
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 def parent(orig, ui, repo, *args, **opts):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 """show Mercurial & Subversion parents of the working dir or revision
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 """
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 if not opts.get('svn', False):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 return orig(ui, repo, *args, **opts)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 hge.revmap.iterkeys()))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 ha = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 if ha.node() == node.nullid:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 raise hgutil.Abort('No parent svn revision!')
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 displayer = hgcmdutil.show_changeset(ui, repo, opts, buffered=False)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 displayer.show(ha)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 return 0
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
43 def outgoing(repo, dest=None, heads=None, force=False):
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 """show changesets not found in the Subversion repository
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 """
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
46 assert dest.capable('subversion')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47
284
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 283
diff changeset
48 # split off #rev; TODO implement --revision/#rev support
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
49 svnurl, revs, checkout = hg.parseurl(dest.svnurl, heads)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 hge.revmap.iterkeys()))
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
53 return util.outgoing_revisions(repo.ui, repo, hge, svn_commit_hashes,
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
54 repo.parents()[0].node())
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 def diff(orig, ui, repo, *args, **opts):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 """show a diff of the most recent revision against its parent from svn
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 """
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 if not opts.get('svn', False) or opts.get('change', None):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 return orig(ui, repo, *args, **opts)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 svn_commit_hashes = {}
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 hge.revmap.iterkeys()))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 if not opts.get('rev', None):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 parent = repo.parents()[0]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 parent.node())
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 if o_r:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 parent = repo[o_r[-1]].parents()[0]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 opts['rev'] = ['%s:.' % node.hex(parent.node()), ]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 node1, node2 = hgcmdutil.revpair(repo, opts['rev'])
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 baserev, _junk = svn_commit_hashes.get(node1, (-1, 'junk', ))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 newrev, _junk = svn_commit_hashes.get(node2, (-1, 'junk', ))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 it = patch.diff(repo, node1, node2,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 opts=patch.diffopts(ui, opts={'git': True,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 'show_function': False,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 'ignore_all_space': False,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 'ignore_space_change': False,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 'ignore_blank_lines': False,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 'unified': True,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 'text': False,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 }))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 ui.write(cmdutil.filterdiff(''.join(it), baserev, newrev))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
87 def push(repo, dest, force, revs):
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 """push revisions starting at a specified head back to Subversion.
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 """
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
90 assert not revs, 'designated revisions for push remains unimplemented.'
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
91 ui = repo.ui
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
92 svnurl = util.normalize_url(repo.ui.expandpath(dest.svnurl))
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 old_encoding = util.swap_out_encoding()
284
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 283
diff changeset
94 # split of #rev; TODO: implement --rev/#rev support
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
95 svnurl, revs, checkout = hg.parseurl(svnurl, revs)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
96 # TODO: do credentials specified in the URL still work?
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
97 user = repo.ui.config('hgsubversion', 'username')
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
98 passwd = repo.ui.config('hgsubversion', 'password')
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
99 svn = svnwrap.SubversionRepo(svnurl, user, passwd)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
100 hge = hg_delta_editor.HgChangeReceiver(repo=repo, uuid=svn.uuid)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
101
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 # Strategy:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 # 1. Find all outgoing commits from this head
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 if len(repo.parents()) != 1:
271
5278817fe8a1 Add newlines to ui.status calls where needed
Daniel Tang <dytang@cs.purdue.edu>
parents: 269
diff changeset
105 ui.status('Cowardly refusing to push branch merge\n')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 return 1
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 workingrev = repo.parents()[0]
267
f000b2392fc2 Push status messages, remove svn flag from opts before passing on
Luke Opperman <luke@loppear.com>
parents: 266
diff changeset
108 ui.status('searching for changes\n')
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
109 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
110 hge.revmap.iterkeys()))
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 outgoing = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingrev.node())
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 if not (outgoing and len(outgoing)):
267
f000b2392fc2 Push status messages, remove svn flag from opts before passing on
Luke Opperman <luke@loppear.com>
parents: 266
diff changeset
113 ui.status('no changes found\n')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114 return 0
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 while outgoing:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 oldest = outgoing.pop(-1)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 old_ctx = repo[oldest]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 if len(old_ctx.parents()) != 1:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 ui.status('Found a branch merge, this needs discussion and '
271
5278817fe8a1 Add newlines to ui.status calls where needed
Daniel Tang <dytang@cs.purdue.edu>
parents: 269
diff changeset
120 'implementation.\n')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 return 1
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 base_n = old_ctx.parents()[0].node()
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 old_children = repo[base_n].children()
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 svnbranch = repo[base_n].branch()
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 oldtip = base_n
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 and c.node() in svn_commit_hashes]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 while samebranchchildren:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 oldtip = samebranchchildren[0].node()
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 and c.node() in svn_commit_hashes]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 # 2. Commit oldest revision that needs to be pushed
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133 base_revision = svn_commit_hashes[base_n][0]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 try:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 cmdutil.commit_from_rev(ui, repo, old_ctx, hge, svnurl,
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136 base_revision, user, passwd)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 except cmdutil.NoFilesException:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 ui.warn("Could not push revision %s because it had no changes in svn.\n" %
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 old_ctx)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 return 1
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 # 3. Fetch revisions from svn
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
142 # TODO: this probably should pass in the source explicitly - rev too?
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
143 r = repo.pull(dest, force=force)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 assert not r or r == 0
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 # 4. Find the new head of the target branch
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 oldtipctx = repo[oldtip]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 replacement = [c for c in oldtipctx.children() if c not in old_children
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 and c.branch() == oldtipctx.branch()]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 assert len(replacement) == 1, 'Replacement node came back as: %r' % replacement
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 replacement = replacement[0]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 # 5. Rebase all children of the currently-pushing rev to the new branch
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152 heads = repo.heads(old_ctx.node())
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 for needs_transplant in heads:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 def extrafn(ctx, extra):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 if ctx.node() == oldest:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 return
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 extra['branch'] = ctx.branch()
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
158 # TODO: can we avoid calling our own rebase wrapper here?
264
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
159 rebase(hgrebase.rebase, ui, repo, svn=True, svnextrafn=extrafn,
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
160 svnsourcerev=needs_transplant)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 repo = hg.repository(ui, hge.path)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 for child in repo[replacement.node()].children():
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 if rebasesrc in outgoing:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165 while rebasesrc in outgoing:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 rebsrcindex = outgoing.index(rebasesrc)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167 outgoing = (outgoing[0:rebsrcindex] +
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 [child.node(), ] + outgoing[rebsrcindex+1:])
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 children = [c for c in child.children() if c.branch() == child.branch()]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 if children:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171 child = children[0]
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
173 # TODO: stop constantly creating the HgChangeReceiver instances.
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
174 hge = hg_delta_editor.HgChangeReceiver(hge.repo, ui_=ui, uuid=svn.uuid)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
175 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys()))
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 util.swap_out_encoding(old_encoding)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 return 0
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
180 def pull(repo, source, heads=[], force=False):
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
181 """pull new revisions from Subversion"""
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
182 assert source.capable('subversion')
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
183 svn_url = source.svnurl
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
184
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
185 # Split off #rev
344
4dfab1b8b7be Mention what failed when given a non-numeric revision to clone/pull.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 342
diff changeset
186 svn_url, heads, checkout = hg.parseurl(svn_url, heads)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 old_encoding = util.swap_out_encoding()
341
cfbd0e563af9 wrappers: remove unused clone() function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
188
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 # TODO implement skipto support
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 skipto_rev = 0
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
191 try:
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
192 stopat_rev = int(checkout or 0)
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
193 except ValueError:
344
4dfab1b8b7be Mention what failed when given a non-numeric revision to clone/pull.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 342
diff changeset
194 raise hgutil.Abort('unrecognised Subversion revision %s: '
4dfab1b8b7be Mention what failed when given a non-numeric revision to clone/pull.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 342
diff changeset
195 'only numbers work.' % checkout)
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
196
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
197 have_replay = not repo.ui.configbool('hgsubversion', 'stupid')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 if have_replay and not callable(
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199 delta.svn_txdelta_apply(None, None, None)[0]): #pragma: no cover
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
200 repo.ui.status('You are using old Subversion SWIG bindings. Replay '
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
201 'will not work until you upgrade to 1.5.0 or newer. '
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
202 'Falling back to a slower method that may be buggier. '
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
203 'Please upgrade, or contribute a patch to use the '
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
204 'ctypes bindings instead of SWIG.\n')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205 have_replay = False
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
206 elif not have_replay:
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
207 repo.ui.note('fetching stupidly...\n')
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
208
341
cfbd0e563af9 wrappers: remove unused clone() function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
209 # TODO: do credentials specified in the URL still work?
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
210 user = repo.ui.config('hgsubversion', 'username')
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
211 passwd = repo.ui.config('hgsubversion', 'password')
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
212 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
213 hg_editor = hg_delta_editor.HgChangeReceiver(repo=repo, subdir=svn.subdir,
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
214 uuid=svn.uuid)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
215
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
216 start = max(hg_editor.last_known_revision(), skipto_rev)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
217 initializing_repo = (hg_editor.last_known_revision() <= 0)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 329
diff changeset
218 ui = repo.ui
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
219
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
220 if initializing_repo and start > 0:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
221 raise hgutil.Abort('Revision skipping at repository initialization '
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
222 'remains unimplemented.')
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
223
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
224 revisions = 0
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
225 try:
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
226 # start converting revisions
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
227 for r in svn.revisions(start=start, stop=stopat_rev):
356
62f90781eb10 push: don't refuse to push if it looks like we haven't pulled all changes.
Augie Fackler <durin42@gmail.com>
parents: 347
diff changeset
228 if (r.author is None and
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
229 r.message == 'This is an empty revision for padding.'):
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
230 continue
367
ce64d57172a3 Generate separate data structure containing revision's tags/branches changes.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 366
diff changeset
231 tbdelta = hg_editor.update_branch_tag_map_for_rev(r)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
232 # got a 502? Try more than once!
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
233 tries = 0
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
234 converted = False
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
235 while not converted:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
236 try:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
237 util.describe_revision(ui, r)
367
ce64d57172a3 Generate separate data structure containing revision's tags/branches changes.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 366
diff changeset
238 pullfuns[have_replay](ui, hg_editor, svn, r, tbdelta)
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
239 converted = True
366
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
240 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
241 ui.status('%s\n' % e.message)
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
242 stupidmod.print_your_svn_is_old_message(ui)
25ebdc16b05b Simplify pulling revs a bit, unify stupid/replay interfaces.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 356
diff changeset
243 have_replay = False
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
244 except core.SubversionException, e: #pragma: no cover
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
245 if (e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
246 and '502' in str(e)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
247 and tries < 3):
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
248 tries += 1
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
249 ui.status('Got a 502, retrying (%s)\n' % tries)
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
250 else:
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
251 raise hgutil.Abort(*e.args)
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
252 revisions += 1
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
253 except KeyboardInterrupt:
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 341
diff changeset
254 pass
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
255 finally:
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
256 util.swap_out_encoding(old_encoding)
264
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
257
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
258 if revisions == 0:
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
259 ui.status(i18n._("no changes found\n"))
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 346
diff changeset
260 return 0
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents: 278
diff changeset
261 else:
341
cfbd0e563af9 wrappers: remove unused clone() function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
262 ui.status("pulled %d revisions\n" % revisions)
264
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
263
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
264 def rebase(orig, ui, repo, **opts):
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
265 """rebase current unpushed revisions onto the Subversion head
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
266
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
267 This moves a line of development from making its own head to the top of
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
268 Subversion development, linearizing the changes. In order to make sure you
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
269 rebase on top of the current top of Subversion work, you should probably run
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
270 'hg svn pull' before running this.
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
271
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
272 Also looks for svnextrafn and svnsourcerev in **opts.
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
273 """
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
274 if not opts.get('svn', False):
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
275 return orig(ui, repo, **opts)
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
276 def extrafn2(ctx, extra):
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
277 """defined here so we can add things easily.
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
278 """
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
279 extra['branch'] = ctx.branch()
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
280 extrafn = opts.get('svnextrafn', extrafn2)
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
281 sourcerev = opts.get('svnsourcerev', repo.parents()[0].node())
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
282 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
283 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
284 hge.revmap.iterkeys()))
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
285 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev)
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
286 if not o_r:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
287 ui.status('Nothing to rebase!\n')
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
288 return 0
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
289 if len(repo[sourcerev].children()):
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
290 ui.status('Refusing to rebase non-head commit like a coward\n')
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
291 return 0
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
292 parent_rev = repo[o_r[-1]].parents()[0]
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
293 target_rev = parent_rev
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
294 p_n = parent_rev.node()
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
295 exhausted_choices = False
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
296 while target_rev.children() and not exhausted_choices:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
297 for c in target_rev.children():
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
298 exhausted_choices = True
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
299 n = c.node()
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
300 if (n in svn_commit_hashes and
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
301 svn_commit_hashes[n][1] == svn_commit_hashes[p_n][1]):
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
302 target_rev = c
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
303 exhausted_choices = False
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
304 break
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
305 if parent_rev == target_rev:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
306 ui.status('Already up to date!\n')
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
307 return 0
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
308 return orig(ui, repo, dest=node.hex(target_rev.node()),
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
309 base=node.hex(sourcerev),
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 263
diff changeset
310 extrafn=extrafn)