comparison __init__.py @ 256:7932d098cb5f

Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
author Augie Fackler <durin42@gmail.com>
date Fri, 10 Apr 2009 18:47:18 -0500
parents c3d5c4ae9c7c
children ffccf0080e54
comparison
equal deleted inserted replaced
255:246aaefb1cc0 256:7932d098cb5f
15 import os 15 import os
16 import sys 16 import sys
17 import traceback 17 import traceback
18 18
19 from mercurial import commands 19 from mercurial import commands
20 from mercurial import extensions
20 from mercurial import hg 21 from mercurial import hg
21 from mercurial import util as hgutil 22 from mercurial import util as hgutil
22 23
23 from svn import core 24 from svn import core
24 25
29 def reposetup(ui, repo): 30 def reposetup(ui, repo):
30 if not util.is_svn_repo(repo): 31 if not util.is_svn_repo(repo):
31 return 32 return
32 33
33 repo.__class__ = tag_repo.generate_repo_class(ui, repo) 34 repo.__class__ = tag_repo.generate_repo_class(ui, repo)
35
36 def uisetup(ui):
37 """Do our UI setup.
38
39 Does the following wrappings:
40 * parent -> utility_commands.parent
41 * outgoing -> utility_commands.outgoing
42 """
43 entry = extensions.wrapcommand(commands.table, 'parents',
44 utility_commands.parent)
45 entry[1].append(('', 'svn', None, "show parent svn revision instead"))
46 entry = extensions.wrapcommand(commands.table, 'outgoing',
47 utility_commands.outgoing)
48 entry[1].append(('', 'svn', None, "show revisions outgoing to subversion"))
49 entry = extensions.wrapcommand(commands.table, 'diff',
50 svncommands.diff)
51 entry[1].append(('', 'svn', None,
52 "show svn-style diffs, default against svn parent"))
53 entry = extensions.wrapcommand(commands.table, 'push',
54 svncommands.push)
55 entry[1].append(('', 'svn', None, "push to subversion"))
56 entry[1].append(('', 'svn-stupid', None, "use stupid replay during push to svn"))
57 entry = extensions.wrapcommand(commands.table, 'pull',
58 svncommands.pull)
59 entry[1].append(('', 'svn', None, "pull from subversion"))
60 entry[1].append(('', 'svn-stupid', None, "use stupid replay during pull from svn"))
61
62 entry = extensions.wrapcommand(commands.table, 'clone',
63 svncommands.clone)
64 entry[1].extend([#('', 'skipto-rev', '0', 'skip commits before this revision.'),
65 ('', 'svn-stupid', False, 'be stupid and use diffy replay.'),
66 ('', 'svn-tag-locations', 'tags', 'Relative path to Subversion tags.'),
67 ('', 'svn-authors', '', 'username mapping filename'),
68 ('', 'svn-filemap', '',
69 'remap file to exclude paths or include only certain paths'),
70 ])
71 # (svn_fetch,
72 # ,
73 # 'hg svnclone source [dest]'),
34 74
35 75
36 def svn(ui, repo, subcommand, *args, **opts): 76 def svn(ui, repo, subcommand, *args, **opts):
37 '''see detailed help for list of subcommands''' 77 '''see detailed help for list of subcommands'''
38 78
68 ui.status('Unknown subcommand %s\n' % subcommand) 108 ui.status('Unknown subcommand %s\n' % subcommand)
69 else: 109 else:
70 raise 110 raise
71 111
72 112
73 def svn_fetch(ui, svn_url, hg_repo_path=None, **opts):
74 '''clone Subversion repository to a local Mercurial repository.
75 113
76 If no destination directory name is specified, it defaults to the
77 basename of the source plus "-hg".
78
79 You can specify multiple paths for the location of tags using comma
80 separated values.
81 '''
82 if not hg_repo_path:
83 hg_repo_path = hg.defaultdest(svn_url) + "-hg"
84 ui.status("Assuming destination %s\n" % hg_repo_path)
85 should_update = not os.path.exists(hg_repo_path)
86 svn_url = util.normalize_url(svn_url)
87 try:
88 res = svncommands.pull(ui, svn_url, hg_repo_path, **opts)
89 except core.SubversionException, e:
90 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED:
91 raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n'
92 'Please try running svn ls on that url first.')
93 raise
94 if (res is None or res == 0) and should_update:
95 repo = hg.repository(ui, hg_repo_path)
96 commands.update(ui, repo, repo['tip'].node())
97 return res
98
99 commands.norepo += " svnclone"
100 cmdtable = { 114 cmdtable = {
101 "svn": 115 "svn":
102 (svn, 116 (svn,
103 [('u', 'svn-url', '', 'path to the Subversion server.'), 117 [('u', 'svn-url', '', 'path to the Subversion server.'),
104 ('', 'stupid', False, 'be stupid and use diffy replay.'), 118 ('', 'stupid', False, 'be stupid and use diffy replay.'),
109 ('', 'username', '', 'username for authentication'), 123 ('', 'username', '', 'username for authentication'),
110 ('', 'password', '', 'password for authentication'), 124 ('', 'password', '', 'password for authentication'),
111 ], 125 ],
112 svncommands._helpgen(), 126 svncommands._helpgen(),
113 ), 127 ),
114 "svnclone":
115 (svn_fetch,
116 [('S', 'skipto-rev', '0', 'skip commits before this revision.'),
117 ('', 'stupid', False, 'be stupid and use diffy replay.'),
118 ('T', 'tag-locations', 'tags', 'Relative path to Subversion tags.'),
119 ('A', 'authors', '', 'username mapping filename'),
120 ('', 'filemap', '',
121 'remap file to exclude paths or include only certain paths'),
122 ('', 'username', '', 'username for authentication'),
123 ('', 'password', '', 'password for authentication'),
124 ],
125 'hg svnclone source [dest]'),
126 } 128 }