comparison utility_commands.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 2
3 from mercurial import node
4 from mercurial import util as hgutil 3 from mercurial import util as hgutil
5 from hgext import rebase as hgrebase
6 4
7 import svnwrap 5 import svnwrap
8 import cmdutil 6 import cmdutil
9 import util 7 import util
10 import hg_delta_editor 8 import hg_delta_editor
98 'date': hgutil.datestr(parent.date(), 96 'date': hgutil.datestr(parent.date(),
99 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') 97 '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
100 }) 98 })
101 99
102 100
103 def rebase(ui, repo, extrafn=None, sourcerev=None, **opts):
104 """rebase current unpushed revisions onto the Subversion head
105
106 This moves a line of development from making its own head to the top of
107 Subversion development, linearizing the changes. In order to make sure you
108 rebase on top of the current top of Subversion work, you should probably run
109 'hg svn pull' before running this.
110 """
111 if extrafn is None:
112 def extrafn2(ctx, extra):
113 """defined here so we can add things easily.
114 """
115 extra['branch'] = ctx.branch()
116 extrafn = extrafn2
117 if sourcerev is None:
118 sourcerev = repo.parents()[0].node()
119 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
120 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
121 hge.revmap.iterkeys()))
122 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev)
123 if not o_r:
124 ui.status('Nothing to rebase!\n')
125 return 0
126 if len(repo[sourcerev].children()):
127 ui.status('Refusing to rebase non-head commit like a coward\n')
128 return 0
129 parent_rev = repo[o_r[-1]].parents()[0]
130 target_rev = parent_rev
131 p_n = parent_rev.node()
132 exhausted_choices = False
133 while target_rev.children() and not exhausted_choices:
134 for c in target_rev.children():
135 exhausted_choices = True
136 n = c.node()
137 if (n in svn_commit_hashes and
138 svn_commit_hashes[n][1] == svn_commit_hashes[p_n][1]):
139 target_rev = c
140 exhausted_choices = False
141 break
142 if parent_rev == target_rev:
143 ui.status('Already up to date!\n')
144 return 0
145 return hgrebase.rebase(ui, repo, dest=node.hex(target_rev.node()),
146 base=node.hex(sourcerev),
147 extrafn=extrafn)
148
149
150 def listauthors(ui, args, authors=None, **opts): 101 def listauthors(ui, args, authors=None, **opts):
151 """list all authors in a Subversion repository 102 """list all authors in a Subversion repository
152 """ 103 """
153 if not len(args): 104 if not len(args):
154 ui.status('No repository specified.\n') 105 ui.status('No repository specified.\n')
178 'url': url, 129 'url': url,
179 'genignore': genignore, 130 'genignore': genignore,
180 'info': info, 131 'info': info,
181 'listauthors': listauthors, 132 'listauthors': listauthors,
182 'version': version, 133 'version': version,
183 'rebase': rebase,
184 } 134 }