Mercurial > hgsubversion
comparison __init__.py @ 248:a9134fa28d15
Move svncommand code into __init__.py.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 08 Apr 2009 19:12:23 +0200 |
parents | 1272e87546ed |
children | 23b02f892d9b |
comparison
equal
deleted
inserted
replaced
247:1272e87546ed | 248:a9134fa28d15 |
---|---|
14 | 14 |
15 import os | 15 import os |
16 | 16 |
17 from mercurial import commands | 17 from mercurial import commands |
18 from mercurial import hg | 18 from mercurial import hg |
19 from mercurial import util as mutil | 19 from mercurial import util as hgutil |
20 | 20 |
21 from svn import core | 21 from svn import core |
22 | 22 |
23 import svncommand | 23 import svncommand |
24 import svncommands | 24 import svncommands |
25 import tag_repo | 25 import tag_repo |
26 import util | 26 import util |
27 | |
28 from util import svn_subcommands, svn_commands_nourl | |
27 | 29 |
28 def reposetup(ui, repo): | 30 def reposetup(ui, repo): |
29 if not util.is_svn_repo(repo): | 31 if not util.is_svn_repo(repo): |
30 return | 32 return |
31 | 33 |
32 repo.__class__ = tag_repo.generate_repo_class(ui, repo) | 34 repo.__class__ = tag_repo.generate_repo_class(ui, repo) |
33 | 35 |
34 | 36 |
35 def svn(ui, repo, subcommand, *args, **opts): | 37 def svn(ui, repo, subcommand, *args, **opts): |
36 '''see detailed help for list of subcommands''' | 38 '''see detailed help for list of subcommands''' |
39 | |
40 # guess command if prefix | |
41 if subcommand not in svn_subcommands: | |
42 candidates = [] | |
43 for c in svn_subcommands: | |
44 if c.startswith(subcommand): | |
45 candidates.append(c) | |
46 if len(candidates) == 1: | |
47 subcommand = candidates[0] | |
48 | |
49 path = os.path.dirname(repo.path) | |
37 try: | 50 try: |
38 return svncommand.svncmd(ui, repo, subcommand, *args, **opts) | 51 commandfunc = svn_subcommands[subcommand] |
52 if commandfunc not in svn_commands_nourl: | |
53 opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read() | |
54 return commandfunc(ui, args=args, hg_repo_path=path, repo=repo, **opts) | |
39 except core.SubversionException, e: | 55 except core.SubversionException, e: |
40 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: | 56 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: |
41 raise mutil.Abort('It appears svn does not trust the ssl cert for this site.\n' | 57 raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n' |
42 'Please try running svn ls on that url first.') | 58 'Please try running svn ls on that url first.') |
43 raise | 59 raise |
60 except TypeError: | |
61 tb = traceback.extract_tb(sys.exc_info()[2]) | |
62 if len(tb) == 1: | |
63 ui.status('Bad arguments for subcommand %s\n' % subcommand) | |
64 else: | |
65 raise | |
66 except KeyError, e: | |
67 tb = traceback.extract_tb(sys.exc_info()[2]) | |
68 if len(tb) == 1: | |
69 ui.status('Unknown subcommand %s\n' % subcommand) | |
70 else: | |
71 raise | |
44 | 72 |
45 | 73 |
46 def svn_fetch(ui, svn_url, hg_repo_path=None, **opts): | 74 def svn_fetch(ui, svn_url, hg_repo_path=None, **opts): |
47 '''clone Subversion repository to a local Mercurial repository. | 75 '''clone Subversion repository to a local Mercurial repository. |
48 | 76 |
59 svn_url = util.normalize_url(svn_url) | 87 svn_url = util.normalize_url(svn_url) |
60 try: | 88 try: |
61 res = svncommands.pull(ui, svn_url, hg_repo_path, **opts) | 89 res = svncommands.pull(ui, svn_url, hg_repo_path, **opts) |
62 except core.SubversionException, e: | 90 except core.SubversionException, e: |
63 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: | 91 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: |
64 raise mutil.Abort('It appears svn does not trust the ssl cert for this site.\n' | 92 raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n' |
65 'Please try running svn ls on that url first.') | 93 'Please try running svn ls on that url first.') |
66 raise | 94 raise |
67 if (res is None or res == 0) and should_update: | 95 if (res is None or res == 0) and should_update: |
68 repo = hg.repository(ui, hg_repo_path) | 96 repo = hg.repository(ui, hg_repo_path) |
69 commands.update(ui, repo, repo['tip'].node()) | 97 commands.update(ui, repo, repo['tip'].node()) |