Mercurial > hgsubversion
comparison svncommand.py @ 247:1272e87546ed
Move help, update into svncommands.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 08 Apr 2009 18:59:50 +0200 |
parents | 074f27c68818 |
children |
comparison
equal
deleted
inserted
replaced
246:074f27c68818 | 247:1272e87546ed |
---|---|
1 import os | 1 import os |
2 import sys | 2 import sys |
3 import traceback | 3 import traceback |
4 | 4 |
5 from mercurial import hg | 5 from util import svn_subcommands, svn_commands_nourl |
6 from mercurial import node | |
7 | |
8 import util | |
9 from util import register_subcommand, svn_subcommands, generate_help, svn_commands_nourl | |
10 # dirty trick to force demandimport to run my decorator anyway. | 6 # dirty trick to force demandimport to run my decorator anyway. |
11 from svncommands import pull, diff, rebuildmeta | 7 from svncommands import pull, diff, rebuildmeta |
12 from utility_commands import print_wc_url | 8 from utility_commands import print_wc_url |
13 # shut up, pyflakes, we must import those | 9 # shut up, pyflakes, we must import those |
14 __x = [print_wc_url, pull, diff, rebuildmeta] | 10 __x = [print_wc_url, pull, diff, rebuildmeta] |
41 tb = traceback.extract_tb(sys.exc_info()[2]) | 37 tb = traceback.extract_tb(sys.exc_info()[2]) |
42 if len(tb) == 1: | 38 if len(tb) == 1: |
43 ui.status('Unknown subcommand %s\n' % subcommand) | 39 ui.status('Unknown subcommand %s\n' % subcommand) |
44 else: | 40 else: |
45 raise | 41 raise |
46 | |
47 | |
48 def help_command(ui, args=None, **opts): | |
49 """show help for a given subcommands or a help overview | |
50 """ | |
51 if args: | |
52 subcommand = args[0] | |
53 if subcommand not in svn_subcommands: | |
54 candidates = [] | |
55 for c in svn_subcommands: | |
56 if c.startswith(subcommand): | |
57 candidates.append(c) | |
58 if len(candidates) == 1: | |
59 subcommand = candidates[0] | |
60 elif len(candidates) > 1: | |
61 ui.status('Ambiguous command. Could have been:\n%s\n' % | |
62 ' '.join(candidates)) | |
63 return | |
64 doc = svn_subcommands[subcommand].__doc__ | |
65 if doc is None: | |
66 doc = "No documentation available for %s." % subcommand | |
67 ui.status(doc.strip(), '\n') | |
68 return | |
69 ui.status(generate_help()) | |
70 help_command = register_subcommand('help')(help_command) | |
71 | |
72 def update(ui, args, repo, clean=False, **opts): | |
73 """update to a specified Subversion revision number | |
74 """ | |
75 assert len(args) == 1 | |
76 rev = int(args[0]) | |
77 path = os.path.join(repo.path, 'svn', 'rev_map') | |
78 answers = [] | |
79 for k,v in util.parse_revmap(path).iteritems(): | |
80 if k[0] == rev: | |
81 answers.append((v, k[1])) | |
82 if len(answers) == 1: | |
83 if clean: | |
84 return hg.clean(repo, answers[0][0]) | |
85 return hg.update(repo, answers[0][0]) | |
86 elif len(answers) == 0: | |
87 ui.status('Revision %s did not produce an hg revision.\n' % rev) | |
88 return 1 | |
89 else: | |
90 ui.status('Ambiguous revision!\n') | |
91 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in | |
92 answers]+[''])) | |
93 return 1 | |
94 update = register_subcommand('up')(update) |