Mercurial > hgsubversion
comparison __init__.py @ 304:ce676eff002b
First merge, totally untested.
| author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
|---|---|
| date | Fri, 01 May 2009 10:28:59 +0200 |
| parents | 79440ed81011 ba8e91a7c077 |
| children | b6c6d32c8ef1 33736e2e25f0 |
comparison
equal
deleted
inserted
replaced
| 303:f423a8780832 | 304:ce676eff002b |
|---|---|
| 11 automated tests. See `README' in the hgsubversion directory for | 11 automated tests. See `README' in the hgsubversion directory for |
| 12 details. | 12 details. |
| 13 ''' | 13 ''' |
| 14 | 14 |
| 15 import os | 15 import os |
| 16 import sys | |
| 17 import traceback | |
| 16 | 18 |
| 17 from mercurial import commands | 19 from mercurial import commands |
| 18 from mercurial import hg | 20 from mercurial import extensions |
| 19 from mercurial import util as mutil | 21 from mercurial import util as hgutil |
| 20 | 22 |
| 21 from svn import core | 23 from svn import core |
| 22 | 24 |
| 23 import svncommand | 25 import svncommands |
| 24 import fetch_command | |
| 25 import tag_repo | 26 import tag_repo |
| 26 import util | 27 import util |
| 28 import wrappers | |
| 29 import svnexternals | |
| 27 | 30 |
| 28 def reposetup(ui, repo): | 31 def reposetup(ui, repo): |
| 29 if not util.is_svn_repo(repo): | 32 if not util.is_svn_repo(repo): |
| 30 return | 33 return |
| 31 | 34 |
| 32 repo.__class__ = tag_repo.generate_repo_class(ui, repo) | 35 repo.__class__ = tag_repo.generate_repo_class(ui, repo) |
| 33 | 36 |
| 37 def uisetup(ui): | |
| 38 """Do our UI setup. | |
| 39 | |
| 40 Does the following wrappings: | |
| 41 * parent -> utility_commands.parent | |
| 42 * outgoing -> utility_commands.outgoing | |
| 43 """ | |
| 44 entry = extensions.wrapcommand(commands.table, 'parents', | |
| 45 wrappers.parent) | |
| 46 entry[1].append(('', 'svn', None, "show parent svn revision instead")) | |
| 47 entry = extensions.wrapcommand(commands.table, 'outgoing', | |
| 48 wrappers.outgoing) | |
| 49 entry[1].append(('', 'svn', None, "show revisions outgoing to subversion")) | |
| 50 entry = extensions.wrapcommand(commands.table, 'diff', | |
| 51 wrappers.diff) | |
| 52 entry[1].append(('', 'svn', None, | |
| 53 "show svn-style diffs, default against svn parent")) | |
| 54 entry = extensions.wrapcommand(commands.table, 'push', | |
| 55 wrappers.push) | |
| 56 entry[1].append(('', 'svn', None, "push to subversion")) | |
| 57 entry[1].append(('', 'svn-stupid', None, "use stupid replay during push to svn")) | |
| 58 entry = extensions.wrapcommand(commands.table, 'pull', | |
| 59 wrappers.pull) | |
| 60 entry[1].append(('', 'svn', None, "pull from subversion")) | |
| 61 entry[1].append(('', 'svn-stupid', None, "use stupid replay during pull from svn")) | |
| 62 | |
| 63 entry = extensions.wrapcommand(commands.table, 'clone', | |
| 64 wrappers.clone) | |
| 65 entry[1].extend([#('', 'skipto-rev', '0', 'skip commits before this revision.'), | |
| 66 ('', 'svn-stupid', False, 'be stupid and use diffy replay.'), | |
| 67 ('', 'svn-tag-locations', 'tags', 'Relative path to Subversion tags.'), | |
| 68 ('', 'svn-authors', '', 'username mapping filename'), | |
| 69 ('', 'svn-filemap', '', | |
| 70 'remap file to exclude paths or include only certain paths'), | |
| 71 ]) | |
| 72 | |
| 73 try: | |
| 74 rebase = extensions.find('rebase') | |
| 75 if rebase: | |
| 76 entry = extensions.wrapcommand(rebase.cmdtable, 'rebase', wrappers.rebase) | |
| 77 entry[1].append(('', 'svn', None, 'automatic svn rebase', )) | |
| 78 except: | |
| 79 pass | |
| 80 | |
| 34 | 81 |
| 35 def svn(ui, repo, subcommand, *args, **opts): | 82 def svn(ui, repo, subcommand, *args, **opts): |
| 36 '''see detailed help for list of subcommands''' | 83 '''see detailed help for list of subcommands''' |
| 84 | |
| 85 # guess command if prefix | |
| 86 if subcommand not in svncommands.table: | |
| 87 candidates = [] | |
| 88 for c in svncommands.table: | |
| 89 if c.startswith(subcommand): | |
| 90 candidates.append(c) | |
| 91 if len(candidates) == 1: | |
| 92 subcommand = candidates[0] | |
| 93 | |
| 94 path = os.path.dirname(repo.path) | |
| 37 try: | 95 try: |
| 38 return svncommand.svncmd(ui, repo, subcommand, *args, **opts) | 96 commandfunc = svncommands.table[subcommand] |
| 97 if subcommand not in svncommands.nourl: | |
| 98 opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read() | |
| 99 return commandfunc(ui, args=args, hg_repo_path=path, repo=repo, **opts) | |
| 39 except core.SubversionException, e: | 100 except core.SubversionException, e: |
| 40 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: | 101 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' | 102 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.') | 103 'Please try running svn ls on that url first.') |
| 43 raise | 104 raise |
| 105 except TypeError: | |
| 106 tb = traceback.extract_tb(sys.exc_info()[2]) | |
| 107 if len(tb) == 1: | |
| 108 ui.status('Bad arguments for subcommand %s\n' % subcommand) | |
| 109 else: | |
| 110 raise | |
| 111 except KeyError, e: | |
| 112 tb = traceback.extract_tb(sys.exc_info()[2]) | |
| 113 if len(tb) == 1: | |
| 114 ui.status('Unknown subcommand %s\n' % subcommand) | |
| 115 else: | |
| 116 raise | |
| 44 | 117 |
| 45 | 118 |
| 46 def svn_fetch(ui, svn_url, hg_repo_path=None, **opts): | |
| 47 '''clone Subversion repository to a local Mercurial repository. | |
| 48 | 119 |
| 49 If no destination directory name is specified, it defaults to the | |
| 50 basename of the source plus "-hg". | |
| 51 | |
| 52 You can specify multiple paths for the location of tags using comma | |
| 53 separated values. | |
| 54 ''' | |
| 55 if not hg_repo_path: | |
| 56 hg_repo_path = hg.defaultdest(svn_url) + "-hg" | |
| 57 ui.status("Assuming destination %s\n" % hg_repo_path) | |
| 58 should_update = not os.path.exists(hg_repo_path) | |
| 59 svn_url = util.normalize_url(svn_url) | |
| 60 try: | |
| 61 res = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path, **opts) | |
| 62 except core.SubversionException, e: | |
| 63 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' | |
| 65 'Please try running svn ls on that url first.') | |
| 66 raise | |
| 67 if (res is None or res == 0) and should_update: | |
| 68 repo = hg.repository(ui, hg_repo_path) | |
| 69 commands.update(ui, repo, repo['tip'].node()) | |
| 70 return res | |
| 71 | |
| 72 commands.norepo += " svnclone" | |
| 73 cmdtable = { | 120 cmdtable = { |
| 74 "svn": | 121 "svn": |
| 75 (svn, | 122 (svn, |
| 76 [('u', 'svn-url', '', 'path to the Subversion server.'), | 123 [('u', 'svn-url', '', 'path to the Subversion server.'), |
| 77 ('', 'stupid', False, 'be stupid and use diffy replay.'), | 124 ('', 'stupid', False, 'be stupid and use diffy replay.'), |
| 78 ('A', 'authors', '', 'username mapping filename'), | 125 ('A', 'authors', '', 'username mapping filename'), |
| 79 ('', 'filemap', '', | 126 ('', 'filemap', '', |
| 80 'remap file to exclude paths or include only certain paths'), | 127 'remap file to exclude paths or include only certain paths'), |
| 81 ('', 'force', False, 'force an operation to happen'), | 128 ('', 'force', False, 'force an operation to happen'), |
| 129 ('', 'username', '', 'username for authentication'), | |
| 130 ('', 'password', '', 'password for authentication'), | |
| 82 ], | 131 ], |
| 83 svncommand.generate_help(), | 132 svncommands._helpgen(), |
| 84 ), | 133 ), |
| 85 "svnclone": | |
| 86 (svn_fetch, | |
| 87 [('S', 'skipto-rev', 0, 'skip commits before this revision.'), | |
| 88 ('H', 'head', 0, 'skip revisions after this one.'), | |
| 89 ('', 'stupid', False, 'be stupid and use diffy replay.'), | |
| 90 ('T', 'tag-locations', 'tags', 'Relative path to Subversion tags.'), | |
| 91 ('A', 'authors', '', 'username mapping filename'), | |
| 92 ('', 'filemap', '', | |
| 93 'remap file to exclude paths or include only certain paths'), | |
| 94 ], | |
| 95 'hg svnclone source [dest]'), | |
| 96 } | 134 } |
