comparison svncommands.py @ 253:c3d5c4ae9c7c

Work with simple command table instead of decorators.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 10 Apr 2009 23:09:59 +0200
parents 1272e87546ed
children 246aaefb1cc0
comparison
equal deleted inserted replaced
252:4d3bcd2f26ed 253:c3d5c4ae9c7c
13 import svnwrap 13 import svnwrap
14 import stupid as stupidmod 14 import stupid as stupidmod
15 import cmdutil 15 import cmdutil
16 import util 16 import util
17 import utility_commands 17 import utility_commands
18
19 from util import generate_help, svn_subcommands, register_subcommand
20 18
21 19
22 def pull(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None, 20 def pull(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
23 tag_locations='tags', authors=None, filemap=None, **opts): 21 tag_locations='tags', authors=None, filemap=None, **opts):
24 """pull new revisions from Subversion 22 """pull new revisions from Subversion
95 tries += 1 93 tries += 1
96 ui.status('Got a 502, retrying (%s)\n' % tries) 94 ui.status('Got a 502, retrying (%s)\n' % tries)
97 else: 95 else:
98 raise hgutil.Abort(*e.args) 96 raise hgutil.Abort(*e.args)
99 util.swap_out_encoding(old_encoding) 97 util.swap_out_encoding(old_encoding)
100
101 pull = util.register_subcommand('pull')(pull)
102 98
103 99
104 def push(ui, repo, hg_repo_path, svn_url, stupid=False, **opts): 100 def push(ui, repo, hg_repo_path, svn_url, stupid=False, **opts):
105 """push revisions starting at a specified head back to Subversion. 101 """push revisions starting at a specified head back to Subversion.
106 """ 102 """
164 for needs_transplant in heads: 160 for needs_transplant in heads:
165 def extrafn(ctx, extra): 161 def extrafn(ctx, extra):
166 if ctx.node() == oldest: 162 if ctx.node() == oldest:
167 return 163 return
168 extra['branch'] = ctx.branch() 164 extra['branch'] = ctx.branch()
169 utility_commands.rebase_commits(ui, repo, 165 utility_commands.rebase(ui, repo, extrafn=extrafn,
170 extrafn=extrafn, 166 sourcerev=needs_transplant, **opts)
171 sourcerev=needs_transplant,
172 **opts)
173 repo = hg.repository(ui, hge.path) 167 repo = hg.repository(ui, hge.path)
174 for child in repo[replacement.node()].children(): 168 for child in repo[replacement.node()].children():
175 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) 169 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
176 if rebasesrc in outgoing: 170 if rebasesrc in outgoing:
177 while rebasesrc in outgoing: 171 while rebasesrc in outgoing:
184 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) 178 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
185 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui) 179 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui)
186 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) 180 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys()))
187 util.swap_out_encoding(old_encoding) 181 util.swap_out_encoding(old_encoding)
188 return 0 182 return 0
189 push = util.register_subcommand('push')(push)
190 # for git expats
191 dcommit = util.register_subcommand('dcommit')(push)
192 183
193 184
194 def diff(ui, repo, hg_repo_path, **opts): 185 def diff(ui, repo, hg_repo_path, **opts):
195 """show a diff of the most recent revision against its parent from svn 186 """show a diff of the most recent revision against its parent from svn
196 """ 187 """
211 'ignore_blank_lines': False, 202 'ignore_blank_lines': False,
212 'unified': True, 203 'unified': True,
213 'text': False, 204 'text': False,
214 })) 205 }))
215 ui.write(cmdutil.filterdiff(''.join(it), base_rev)) 206 ui.write(cmdutil.filterdiff(''.join(it), base_rev))
216 diff = util.register_subcommand('diff')(diff)
217 207
218 208
219 def rebuildmeta(ui, repo, hg_repo_path, args, **opts): 209 def rebuildmeta(ui, repo, hg_repo_path, args, **opts):
220 """rebuild hgsubversion metadata using values stored in revisions 210 """rebuild hgsubversion metadata using values stored in revisions
221 """ 211 """
327 tagsinfo[tag] = source, rev 317 tagsinfo[tag] = source, rev
328 318
329 tagsinfofile = open(os.path.join(svnmetadir, 'tag_info'), 'w') 319 tagsinfofile = open(os.path.join(svnmetadir, 'tag_info'), 'w')
330 pickle.dump(tagsinfo, tagsinfofile) 320 pickle.dump(tagsinfo, tagsinfofile)
331 tagsinfofile.close() 321 tagsinfofile.close()
332 rebuildmeta = util.register_subcommand('rebuildmeta')(rebuildmeta)
333 rebuildmeta = util.command_needs_no_url(rebuildmeta)
334 322
335 323
336 def help(ui, args=None, **opts): 324 def help(ui, args=None, **opts):
337 """show help for a given subcommands or a help overview 325 """show help for a given subcommands or a help overview
338 """ 326 """
339 if args: 327 if args:
340 subcommand = args[0] 328 subcommand = args[0]
341 if subcommand not in svn_subcommands: 329 if subcommand not in table:
342 candidates = [] 330 candidates = []
343 for c in svn_subcommands: 331 for c in table:
344 if c.startswith(subcommand): 332 if c.startswith(subcommand):
345 candidates.append(c) 333 candidates.append(c)
346 if len(candidates) == 1: 334 if len(candidates) == 1:
347 subcommand = candidates[0] 335 subcommand = candidates[0]
348 elif len(candidates) > 1: 336 elif len(candidates) > 1:
349 ui.status('Ambiguous command. Could have been:\n%s\n' % 337 ui.status('Ambiguous command. Could have been:\n%s\n' %
350 ' '.join(candidates)) 338 ' '.join(candidates))
351 return 339 return
352 doc = svn_subcommands[subcommand].__doc__ 340 doc = table[subcommand].__doc__
353 if doc is None: 341 if doc is None:
354 doc = "No documentation available for %s." % subcommand 342 doc = "No documentation available for %s." % subcommand
355 ui.status(doc.strip(), '\n') 343 ui.status(doc.strip(), '\n')
356 return 344 return
357 ui.status(generate_help()) 345 ui.status(_helpgen())
358 help = register_subcommand('help')(help)
359 346
360 347
361 def update(ui, args, repo, clean=False, **opts): 348 def update(ui, args, repo, clean=False, **opts):
362 """update to a specified Subversion revision number 349 """update to a specified Subversion revision number
363 """ 350 """
378 else: 365 else:
379 ui.status('Ambiguous revision!\n') 366 ui.status('Ambiguous revision!\n')
380 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in 367 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in
381 answers]+[''])) 368 answers]+['']))
382 return 1 369 return 1
383 update = register_subcommand('up')(update) 370
371
372 nourl = ['rebuildmeta'] + utility_commands.nourl
373 table = {
374 'pull': pull,
375 'push': push,
376 'dcommit': push,
377 'update': update,
378 'help': help,
379 'rebuildmeta': rebuildmeta,
380 'diff': diff,
381 }
382
383 table.update(utility_commands.table)
384
385
386 def _helpgen():
387 ret = ['hg svn ...', '',
388 'subcommands for Subversion integration', '',
389 'list of subcommands:', '']
390 for name, func in sorted(table.items()):
391 short_description = (func.__doc__ or '').splitlines()[0]
392 ret.append(" %-10s %s" % (name, short_description))
393 return '\n'.join(ret) + '\n'