annotate __init__.py @ 249:a065bf61caa1

encoding: fix encoding swap to work with demandimport enabled (#67)
author Daniel Tang <dytang@cs.purdue.edu>
date Fri, 10 Apr 2009 15:43:47 -0500
parents a9134fa28d15
children 23b02f892d9b
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
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
16
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 from mercurial import commands
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 from mercurial import hg
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
19 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
20
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
21 from svn import core
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 import svncommand
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 234
diff changeset
24 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
25 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
26 import util
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
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
28 from util import svn_subcommands, svn_commands_nourl
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
29
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
30 def reposetup(ui, 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
31 if not util.is_svn_repo(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
32 return
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
33
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
34 repo.__class__ = 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
35
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 52
diff changeset
36
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 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
38 '''see detailed help for list of subcommands'''
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
39
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
40 # guess command if prefix
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
41 if subcommand not in svn_subcommands:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
42 candidates = []
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
43 for c in svn_subcommands:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
44 if c.startswith(subcommand):
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
45 candidates.append(c)
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
46 if len(candidates) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
47 subcommand = candidates[0]
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
48
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
49 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
50 try:
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
51 commandfunc = svn_subcommands[subcommand]
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
52 if commandfunc not in svn_commands_nourl:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
53 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
54 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
55 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
56 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
57 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
58 '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
59 raise
248
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
60 except TypeError:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
61 tb = traceback.extract_tb(sys.exc_info()[2])
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
62 if len(tb) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
63 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
64 else:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
65 raise
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
66 except KeyError, e:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
67 tb = traceback.extract_tb(sys.exc_info()[2])
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
68 if len(tb) == 1:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
69 ui.status('Unknown subcommand %s\n' % subcommand)
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
70 else:
a9134fa28d15 Move svncommand code into __init__.py.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
71 raise
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
72
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 def svn_fetch(ui, svn_url, hg_repo_path=None, **opts):
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
75 '''clone Subversion repository to a local Mercurial repository.
142
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
76
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
77 If no destination directory name is specified, it defaults to the
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
78 basename of the source plus "-hg".
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
79
143
edd9f4e5154a Phrasing nits.
Augie Fackler <durin42@gmail.com>
parents: 142
diff changeset
80 You can specify multiple paths for the location of tags using comma
edd9f4e5154a Phrasing nits.
Augie Fackler <durin42@gmail.com>
parents: 142
diff changeset
81 separated values.
142
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
82 '''
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 if not hg_repo_path:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 hg_repo_path = hg.defaultdest(svn_url) + "-hg"
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 ui.status("Assuming destination %s\n" % hg_repo_path)
52
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
86 should_update = not os.path.exists(hg_repo_path)
140
9ffde8662967 util: Add a command to normalize svn urls and use it in a couple of places. Test that it works and prevents failed assertions.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
87 svn_url = util.normalize_url(svn_url)
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
88 try:
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 234
diff changeset
89 res = svncommands.pull(ui, svn_url, hg_repo_path, **opts)
209
d06572495c5e Better error message when we encounter an unknown SSL cert.
Augie Fackler <durin42@gmail.com>
parents: 199
diff changeset
90 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
91 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
92 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
93 '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
94 raise
52
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
95 if (res is None or res == 0) and should_update:
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
96 repo = hg.repository(ui, hg_repo_path)
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
97 commands.update(ui, repo, repo['tip'].node())
fb1d911bb0be svnclone now updates to the tip revision if it is the initial clone.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
98 return res
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 commands.norepo += " svnclone"
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 cmdtable = {
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 "svn":
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 (svn,
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
104 [('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
105 ('', '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
106 ('A', 'authors', '', 'username mapping filename'),
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
107 ('', 'filemap', '',
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
108 '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
109 ('', '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
110 ('', 'username', '', 'username for authentication'),
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 224
diff changeset
111 ('', 'password', '', 'password for authentication'),
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 ],
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
113 svncommands.generate_help(),
115
ed42f6e5705a Clean up help text, document subcommands.
Luke Opperman <luke@loppear.com>
parents: 52
diff changeset
114 ),
142
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
115 "svnclone":
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
116 (svn_fetch,
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
117 [('S', 'skipto-rev', '0', 'skip commits before this revision.'),
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
118 ('', '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
119 ('T', 'tag-locations', 'tags', 'Relative path to Subversion tags.'),
3cd6a7354207 fetch: Add support for an authormap which can rename authors, intended for
Graham Booker <gbooker@cod3r.com>
parents: 143
diff changeset
120 ('A', 'authors', '', 'username mapping filename'),
185
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
121 ('', 'filemap', '',
57355b0e7bd1 Creating patch for documention messages.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 179
diff changeset
122 'remap file to exclude paths or include only certain paths'),
234
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 224
diff changeset
123 ('', 'username', '', 'username for authentication'),
33e885f5f86a Add --username and --password options to all commands
Daniel Tang <dytang@cs.purdue.edu>
parents: 224
diff changeset
124 ('', 'password', '', 'password for authentication'),
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 ],
142
42958d9de864 documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 140
diff changeset
126 'hg svnclone source [dest]'),
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 }