Mercurial > hgsubversion
comparison wrappers.py @ 264:112d57bb736e
rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Mon, 13 Apr 2009 21:51:12 -0500 |
| parents | d978192f0d63 |
| children | 9f0738587f94 |
comparison
equal
deleted
inserted
replaced
| 263:d978192f0d63 | 264:112d57bb736e |
|---|---|
| 1 import os | 1 import os |
| 2 | |
| 3 from hgext import rebase as hgrebase | |
| 2 | 4 |
| 3 from mercurial import cmdutil as hgcmdutil | 5 from mercurial import cmdutil as hgcmdutil |
| 4 from mercurial import commands | 6 from mercurial import commands |
| 5 from mercurial import patch | 7 from mercurial import patch |
| 6 from mercurial import hg | 8 from mercurial import hg |
| 13 import cmdutil | 15 import cmdutil |
| 14 import hg_delta_editor | 16 import hg_delta_editor |
| 15 import stupid as stupidmod | 17 import stupid as stupidmod |
| 16 import svnwrap | 18 import svnwrap |
| 17 import util | 19 import util |
| 18 import utility_commands | |
| 19 | 20 |
| 20 def parent(orig, ui, repo, *args, **opts): | 21 def parent(orig, ui, repo, *args, **opts): |
| 21 """show Mercurial & Subversion parents of the working dir or revision | 22 """show Mercurial & Subversion parents of the working dir or revision |
| 22 """ | 23 """ |
| 23 if not opts.get('svn', False): | 24 if not opts.get('svn', False): |
| 49 ui.status('no changes found\n') | 50 ui.status('no changes found\n') |
| 50 return 0 | 51 return 0 |
| 51 displayer = hgcmdutil.show_changeset(ui, repo, opts, buffered=False) | 52 displayer = hgcmdutil.show_changeset(ui, repo, opts, buffered=False) |
| 52 for node in reversed(o_r): | 53 for node in reversed(o_r): |
| 53 displayer.show(repo[node]) | 54 displayer.show(repo[node]) |
| 54 | |
| 55 | |
| 56 | 55 |
| 57 | 56 |
| 58 def diff(orig, ui, repo, *args, **opts): | 57 def diff(orig, ui, repo, *args, **opts): |
| 59 """show a diff of the most recent revision against its parent from svn | 58 """show a diff of the most recent revision against its parent from svn |
| 60 """ | 59 """ |
| 84 'text': False, | 83 'text': False, |
| 85 })) | 84 })) |
| 86 ui.write(cmdutil.filterdiff(''.join(it), baserev, newrev)) | 85 ui.write(cmdutil.filterdiff(''.join(it), baserev, newrev)) |
| 87 | 86 |
| 88 | 87 |
| 89 | |
| 90 | |
| 91 def push(orig, ui, repo, dest=None, *args, **opts): | 88 def push(orig, ui, repo, dest=None, *args, **opts): |
| 92 """push revisions starting at a specified head back to Subversion. | 89 """push revisions starting at a specified head back to Subversion. |
| 93 """ | 90 """ |
| 94 svnurl = repo.ui.expandpath(dest or 'default-push', dest or 'default') | 91 svnurl = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
| 95 if not cmdutil.issvnurl(svnurl): | 92 if not cmdutil.issvnurl(svnurl): |
| 113 outgoing = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingrev.node()) | 110 outgoing = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingrev.node()) |
| 114 if not (outgoing and len(outgoing)): | 111 if not (outgoing and len(outgoing)): |
| 115 ui.status('No revisions to push.') | 112 ui.status('No revisions to push.') |
| 116 return 0 | 113 return 0 |
| 117 while outgoing: | 114 while outgoing: |
| 115 print [node.hex(x) for x in outgoing] | |
| 118 oldest = outgoing.pop(-1) | 116 oldest = outgoing.pop(-1) |
| 119 old_ctx = repo[oldest] | 117 old_ctx = repo[oldest] |
| 120 if len(old_ctx.parents()) != 1: | 118 if len(old_ctx.parents()) != 1: |
| 121 ui.status('Found a branch merge, this needs discussion and ' | 119 ui.status('Found a branch merge, this needs discussion and ' |
| 122 'implementation.') | 120 'implementation.') |
| 157 for needs_transplant in heads: | 155 for needs_transplant in heads: |
| 158 def extrafn(ctx, extra): | 156 def extrafn(ctx, extra): |
| 159 if ctx.node() == oldest: | 157 if ctx.node() == oldest: |
| 160 return | 158 return |
| 161 extra['branch'] = ctx.branch() | 159 extra['branch'] = ctx.branch() |
| 162 utility_commands.rebase(ui, repo, extrafn=extrafn, | 160 rebase(hgrebase.rebase, ui, repo, svn=True, svnextrafn=extrafn, |
| 163 sourcerev=needs_transplant, **opts) | 161 svnsourcerev=needs_transplant, **opts) |
| 164 repo = hg.repository(ui, hge.path) | 162 repo = hg.repository(ui, hge.path) |
| 165 for child in repo[replacement.node()].children(): | 163 for child in repo[replacement.node()].children(): |
| 166 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) | 164 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) |
| 165 print node.hex(rebasesrc) | |
| 167 if rebasesrc in outgoing: | 166 if rebasesrc in outgoing: |
| 167 print 'swap outgoin' | |
| 168 while rebasesrc in outgoing: | 168 while rebasesrc in outgoing: |
| 169 rebsrcindex = outgoing.index(rebasesrc) | 169 rebsrcindex = outgoing.index(rebasesrc) |
| 170 outgoing = (outgoing[0:rebsrcindex] + | 170 outgoing = (outgoing[0:rebsrcindex] + |
| 171 [child.node(), ] + outgoing[rebsrcindex+1:]) | 171 [child.node(), ] + outgoing[rebsrcindex+1:]) |
| 172 children = [c for c in child.children() if c.branch() == child.branch()] | 172 children = [c for c in child.children() if c.branch() == child.branch()] |
| 175 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) | 175 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) |
| 176 hge = hg_delta_editor.HgChangeReceiver(hge.path, ui_=ui) | 176 hge = hg_delta_editor.HgChangeReceiver(hge.path, ui_=ui) |
| 177 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) | 177 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) |
| 178 util.swap_out_encoding(old_encoding) | 178 util.swap_out_encoding(old_encoding) |
| 179 return 0 | 179 return 0 |
| 180 | |
| 181 | 180 |
| 182 | 181 |
| 183 def clone(orig, ui, source, dest=None, *args, **opts): | 182 def clone(orig, ui, source, dest=None, *args, **opts): |
| 184 '''clone Subversion repository to a local Mercurial repository. | 183 '''clone Subversion repository to a local Mercurial repository. |
| 185 | 184 |
| 320 tries += 1 | 319 tries += 1 |
| 321 ui.status('Got a 502, retrying (%s)\n' % tries) | 320 ui.status('Got a 502, retrying (%s)\n' % tries) |
| 322 else: | 321 else: |
| 323 raise hgutil.Abort(*e.args) | 322 raise hgutil.Abort(*e.args) |
| 324 util.swap_out_encoding(old_encoding) | 323 util.swap_out_encoding(old_encoding) |
| 324 | |
| 325 | |
| 326 def rebase(orig, ui, repo, **opts): | |
| 327 """rebase current unpushed revisions onto the Subversion head | |
| 328 | |
| 329 This moves a line of development from making its own head to the top of | |
| 330 Subversion development, linearizing the changes. In order to make sure you | |
| 331 rebase on top of the current top of Subversion work, you should probably run | |
| 332 'hg svn pull' before running this. | |
| 333 | |
| 334 Also looks for svnextrafn and svnsourcerev in **opts. | |
| 335 """ | |
| 336 if not opts.get('svn', False): | |
| 337 return orig(ui, repo, **opts) | |
| 338 def extrafn2(ctx, extra): | |
| 339 """defined here so we can add things easily. | |
| 340 """ | |
| 341 extra['branch'] = ctx.branch() | |
| 342 extrafn = opts.get('svnextrafn', extrafn2) | |
| 343 sourcerev = opts.get('svnsourcerev', repo.parents()[0].node()) | |
| 344 hge = hg_delta_editor.HgChangeReceiver(repo=repo) | |
| 345 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), | |
| 346 hge.revmap.iterkeys())) | |
| 347 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev) | |
| 348 if not o_r: | |
| 349 ui.status('Nothing to rebase!\n') | |
| 350 return 0 | |
| 351 if len(repo[sourcerev].children()): | |
| 352 ui.status('Refusing to rebase non-head commit like a coward\n') | |
| 353 return 0 | |
| 354 parent_rev = repo[o_r[-1]].parents()[0] | |
| 355 target_rev = parent_rev | |
| 356 p_n = parent_rev.node() | |
| 357 exhausted_choices = False | |
| 358 while target_rev.children() and not exhausted_choices: | |
| 359 for c in target_rev.children(): | |
| 360 exhausted_choices = True | |
| 361 n = c.node() | |
| 362 if (n in svn_commit_hashes and | |
| 363 svn_commit_hashes[n][1] == svn_commit_hashes[p_n][1]): | |
| 364 target_rev = c | |
| 365 exhausted_choices = False | |
| 366 break | |
| 367 if parent_rev == target_rev: | |
| 368 ui.status('Already up to date!\n') | |
| 369 return 0 | |
| 370 return orig(ui, repo, dest=node.hex(target_rev.node()), | |
| 371 base=node.hex(sourcerev), | |
| 372 extrafn=extrafn) |
