annotate __init__.py @ 326:33736e2e25f0

alternate approach for supporting svn schemes for repository paths We now intercept the operations in the local repo class, and handle the relevant operation ourselves. This frees us from wrapping all relevant commands and replicating their functionality. The implementation is incomplete; only one test has been modified to use the standard Mercurial API with the changed URLs. Once changed, those tests will likely reveal bugs or missing features in the new wrappers. Also, new wrappers will be needed for handling conversion flags such as -A/--authormap.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 07 May 2009 20:50:53 +0200
parents ce676eff002b
children 48ec2d62dc29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
1 '''integration with Subversion repositories
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
2
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
3 This extension allows Mercurial to act as a Subversion client, for
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
4 fast incremental, bidirectional updates.
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
5
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
6 It is *not* ready yet for production use. You should only be using
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
7 this if you're ready to hack on it, and go diving into the internals
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
8 of Mercurial and/or Subversion.
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
9
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
10 Before using hgsubversion, it is *strongly* encouraged to run the
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
11 automated tests. See `README' in the hgsubversion directory for
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
12 details.
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
13 '''
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
14
52
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
15 import os
251
23b02f892d9b Fix up imports in __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 248
diff changeset
16 import sys
23b02f892d9b Fix up imports in __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 248
diff changeset
17 import traceback
52
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
18
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 from mercurial import commands
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
20 from mercurial import extensions
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
21 from mercurial import hg
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
22 from mercurial import util as hgutil
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
23
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
24 from svn import core
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 234
diff changeset
26 import svncommands
124
291925677a9f tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents: 115
diff changeset
27 import tag_repo
291925677a9f tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents: 115
diff changeset
28 import util
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents: 256
diff changeset
29 import wrappers
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 273
diff changeset
30 import svnexternals
124
291925677a9f tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents: 115
diff changeset
31
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
32 def uisetup(ui):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
33 """Do our UI setup.
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
34
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
35 Does the following wrappings:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
36 * parent -> utility_commands.parent
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
37 * outgoing -> utility_commands.outgoing
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
38 """
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
39 entry = extensions.wrapcommand(commands.table, 'parents',
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents: 256
diff changeset
40 wrappers.parent)
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
41 entry[1].append(('', 'svn', None, "show parent svn revision instead"))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
42 entry = extensions.wrapcommand(commands.table, 'outgoing',
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents: 256
diff changeset
43 wrappers.outgoing)
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
44 entry[1].append(('', 'svn', None, "show revisions outgoing to subversion"))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
45 entry = extensions.wrapcommand(commands.table, 'diff',
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents: 256
diff changeset
46 wrappers.diff)
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
47 entry[1].append(('', 'svn', None,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
48 "show svn-style diffs, default against svn parent"))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
49 entry = extensions.wrapcommand(commands.table, 'push',
257
ffccf0080e54 Move wrappers for hg commands to their own module.
Augie Fackler <durin42@gmail.com>
parents: 256
diff changeset
50 wrappers.push)
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
51 entry[1].append(('', 'svn', None, "push to subversion"))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
52 entry[1].append(('', 'svn-stupid', None, "use stupid replay during push to svn"))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 253
diff changeset
53
264
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
54 try:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
55 rebase = extensions.find('rebase')
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
56 if rebase:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
57 entry = extensions.wrapcommand(rebase.cmdtable, 'rebase', wrappers.rebase)
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
58 entry[1].append(('', 'svn', None, 'automatic svn rebase', ))
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
59 except:
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
60 pass
112d57bb736e rebase: moved to wrappers, now a wrapper around rebase triggered with --svn.
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
61
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 52
diff changeset
62
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 def svn(ui, repo, subcommand, *args, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
64 '''see detailed help for list of subcommands'''
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
65
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
66 # guess command if prefix
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 251
diff changeset
67 if subcommand not in svncommands.table:
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
68 candidates = []
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 251
diff changeset
69 for c in svncommands.table:
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
70 if c.startswith(subcommand):
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
71 candidates.append(c)
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
72 if len(candidates) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
73 subcommand = candidates[0]
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
74
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
75 path = os.path.dirname(repo.path)
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
76 try:
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 251
diff changeset
77 commandfunc = svncommands.table[subcommand]
273
e0f9fa0acc03 Fix the nourl check to use the command name, instead of the function
Daniel Tang <dytang@cs.purdue.edu>
parents: 264
diff changeset
78 if subcommand not in svncommands.nourl:
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
79 opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read()
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
80 return commandfunc(ui, args=args, hg_repo_path=path, repo=repo, **opts)
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
81 except core.SubversionException, e:
224
2165461d2dd8 Exception clean-ups; use symbolic names & avoid Python 2.6 deprecations.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 209
diff changeset
82 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED:
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
83 raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n'
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
84 'Please try running svn ls on that url first.')
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
85 raise
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
86 except TypeError:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
87 tb = traceback.extract_tb(sys.exc_info()[2])
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
88 if len(tb) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
89 ui.status('Bad arguments for subcommand %s\n' % subcommand)
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
90 else:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
91 raise
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
92 except KeyError, e:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
93 tb = traceback.extract_tb(sys.exc_info()[2])
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
94 if len(tb) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
95 ui.status('Unknown subcommand %s\n' % subcommand)
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
96 else:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
97 raise
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
98
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
99 def reposetup(ui, repo):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
100 if repo.local():
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
101 tag_repo.generate_repo_class(ui, repo)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
103 for scheme in ('svn', 'svn+ssh', 'svn+http', 'svn+file'):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 304
diff changeset
104 hg.schemes[scheme] = tag_repo
142
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
105
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 cmdtable = {
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 "svn":
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
108 (svn,
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
109 [('u', 'svn-url', '', 'path to the Subversion server.'),
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
110 ('', 'stupid', False, 'be stupid and use diffy replay.'),
167
3cd6a7354207 fetch: Add support for an authormap which can rename authors, intended for
Graham Booker <gbooker@cod3r.com>
parents: 143
diff changeset
111 ('A', 'authors', '', 'username mapping filename'),
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
112 ('', 'filemap', '',
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
113 'remap file to exclude paths or include only certain paths'),
199
91db8fc049b0 Add a genignore utility command that generates an hgignore file by scraping svn:ignore properties.
Augie Fackler <durin42@gmail.com>
parents: 185
diff changeset
114 ('', 'force', False, 'force an operation to happen'),
234
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 224
diff changeset
115 ('', 'username', '', 'username for authentication'),
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 224
diff changeset
116 ('', 'password', '', 'password for authentication'),
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 ],
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 251
diff changeset
118 svncommands._helpgen(),
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 52
diff changeset
119 ),
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120 }