Show More
@@ -10,7 +10,7 b' from cvs import convert_cvs' | |||||
10 | from darcs import darcs_source |
|
10 | from darcs import darcs_source | |
11 | from git import convert_git |
|
11 | from git import convert_git | |
12 | from hg import mercurial_source, mercurial_sink |
|
12 | from hg import mercurial_source, mercurial_sink | |
13 |
from subversion import |
|
13 | from subversion import svn_source, debugsvnlog | |
14 | import filemap |
|
14 | import filemap | |
15 |
|
15 | |||
16 | import os, shutil |
|
16 | import os, shutil | |
@@ -19,27 +19,32 b' from mercurial.i18n import _' | |||||
19 |
|
19 | |||
20 | commands.norepo += " convert debugsvnlog" |
|
20 | commands.norepo += " convert debugsvnlog" | |
21 |
|
21 | |||
22 | sink_converters = [mercurial_sink] |
|
22 | source_converters = [ | |
23 | source_converters = [convert_cvs, convert_git, convert_svn, |
|
23 | ('cvs', convert_cvs), | |
24 | mercurial_source, darcs_source] |
|
24 | ('git', convert_git), | |
25 | def convertsource(ui, path, **opts): |
|
25 | ('svn', svn_source), | |
26 | for c in source_converters: |
|
26 | ('hg', mercurial_source), | |
|
27 | ('darcs', darcs_source), | |||
|
28 | ] | |||
|
29 | ||||
|
30 | sink_converters = [ | |||
|
31 | ('hg', mercurial_sink), | |||
|
32 | ] | |||
|
33 | ||||
|
34 | def convertsource(ui, path, type, rev): | |||
|
35 | for name, source in source_converters: | |||
27 | try: |
|
36 | try: | |
28 | return c.getcommit and c(ui, path, **opts) |
|
37 | if not type or name == type: | |
29 | except AttributeError: |
|
38 | return source(ui, path, rev) | |
30 | pass |
|
|||
31 | except NoRepo, inst: |
|
39 | except NoRepo, inst: | |
32 | ui.note(_("convert: %s\n") % inst) |
|
40 | ui.note(_("convert: %s\n") % inst) | |
33 | raise util.Abort('%s: unknown repository type' % path) |
|
41 | raise util.Abort('%s: unknown repository type' % path) | |
34 |
|
42 | |||
35 | def convertsink(ui, path): |
|
43 | def convertsink(ui, path, type): | |
36 | if not os.path.isdir(path): |
|
44 | for name, sink in sink_converters: | |
37 | raise util.Abort("%s: not a directory" % path) |
|
|||
38 | for c in sink_converters: |
|
|||
39 | try: |
|
45 | try: | |
40 | return c.putcommit and c(ui, path) |
|
46 | if not type or name == type: | |
41 | except AttributeError: |
|
47 | return sink(ui, path) | |
42 | pass |
|
|||
43 | except NoRepo, inst: |
|
48 | except NoRepo, inst: | |
44 | ui.note(_("convert: %s\n") % inst) |
|
49 | ui.note(_("convert: %s\n") % inst) | |
45 | raise util.Abort('%s: unknown repository type' % path) |
|
50 | raise util.Abort('%s: unknown repository type' % path) | |
@@ -350,37 +355,14 b' def convert(ui, src, dest=None, revmapfi' | |||||
350 | dest = hg.defaultdest(src) + "-hg" |
|
355 | dest = hg.defaultdest(src) + "-hg" | |
351 | ui.status("assuming destination %s\n" % dest) |
|
356 | ui.status("assuming destination %s\n" % dest) | |
352 |
|
357 | |||
353 | # Try to be smart and initalize things when required |
|
358 | destc = convertsink(ui, dest, opts.get('dest_type')) | |
354 | created = False |
|
|||
355 | if os.path.isdir(dest): |
|
|||
356 | if len(os.listdir(dest)) > 0: |
|
|||
357 | try: |
|
|||
358 | hg.repository(ui, dest) |
|
|||
359 | ui.status("destination %s is a Mercurial repository\n" % dest) |
|
|||
360 | except hg.RepoError: |
|
|||
361 | raise util.Abort( |
|
|||
362 | "destination directory %s is not empty.\n" |
|
|||
363 | "Please specify an empty directory to be initialized\n" |
|
|||
364 | "or an already initialized mercurial repository" |
|
|||
365 | % dest) |
|
|||
366 | else: |
|
|||
367 | ui.status("initializing destination %s repository\n" % dest) |
|
|||
368 | hg.repository(ui, dest, create=True) |
|
|||
369 | created = True |
|
|||
370 | elif os.path.exists(dest): |
|
|||
371 | raise util.Abort("destination %s exists and is not a directory" % dest) |
|
|||
372 | else: |
|
|||
373 | ui.status("initializing destination %s repository\n" % dest) |
|
|||
374 | hg.repository(ui, dest, create=True) |
|
|||
375 | created = True |
|
|||
376 |
|
||||
377 | destc = convertsink(ui, dest) |
|
|||
378 |
|
359 | |||
379 | try: |
|
360 | try: | |
380 |
srcc = convertsource(ui, src, |
|
361 | srcc = convertsource(ui, src, opts.get('source_type'), | |
|
362 | opts.get('rev')) | |||
381 | except Exception: |
|
363 | except Exception: | |
382 |
|
|
364 | for path in destc.created: | |
383 |
shutil.rmtree( |
|
365 | shutil.rmtree(path, True) | |
384 | raise |
|
366 | raise | |
385 |
|
367 | |||
386 | fmap = opts.get('filemap') |
|
368 | fmap = opts.get('filemap') | |
@@ -402,8 +384,10 b' cmdtable = {' | |||||
402 | "convert": |
|
384 | "convert": | |
403 | (convert, |
|
385 | (convert, | |
404 | [('A', 'authors', '', 'username mapping filename'), |
|
386 | [('A', 'authors', '', 'username mapping filename'), | |
|
387 | ('d', 'dest-type', '', 'destination repository type'), | |||
405 | ('', 'filemap', '', 'remap file names using contents of file'), |
|
388 | ('', 'filemap', '', 'remap file names using contents of file'), | |
406 | ('r', 'rev', '', 'import up to target revision REV'), |
|
389 | ('r', 'rev', '', 'import up to target revision REV'), | |
|
390 | ('s', 'source-type', '', 'source repository type'), | |||
407 | ('', 'datesort', None, 'try to sort changesets by date')], |
|
391 | ('', 'datesort', None, 'try to sort changesets by date')], | |
408 | 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'), |
|
392 | 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'), | |
409 | "debugsvnlog": |
|
393 | "debugsvnlog": |
@@ -20,13 +20,15 b' class NoRepo(Exception): pass' | |||||
20 | SKIPREV = 'SKIP' |
|
20 | SKIPREV = 'SKIP' | |
21 |
|
21 | |||
22 | class commit(object): |
|
22 | class commit(object): | |
23 |
def __init__(self, author, date, desc, parents, branch=None, rev=None |
|
23 | def __init__(self, author, date, desc, parents, branch=None, rev=None, | |
|
24 | extra={}): | |||
24 | self.author = author |
|
25 | self.author = author | |
25 | self.date = date |
|
26 | self.date = date | |
26 | self.desc = desc |
|
27 | self.desc = desc | |
27 | self.parents = parents |
|
28 | self.parents = parents | |
28 | self.branch = branch |
|
29 | self.branch = branch | |
29 | self.rev = rev |
|
30 | self.rev = rev | |
|
31 | self.extra = extra | |||
30 |
|
32 | |||
31 | class converter_source(object): |
|
33 | class converter_source(object): | |
32 | """Conversion source interface""" |
|
34 | """Conversion source interface""" | |
@@ -114,8 +116,13 b' class converter_sink(object):' | |||||
114 |
|
116 | |||
115 | def __init__(self, ui, path): |
|
117 | def __init__(self, ui, path): | |
116 | """Initialize conversion sink (or raise NoRepo("message") |
|
118 | """Initialize conversion sink (or raise NoRepo("message") | |
117 |
exception if path is not a valid repository) |
|
119 | exception if path is not a valid repository) | |
118 | raise NotImplementedError() |
|
120 | ||
|
121 | created is a list of paths to remove if a fatal error occurs | |||
|
122 | later""" | |||
|
123 | self.ui = ui | |||
|
124 | self.path = path | |||
|
125 | self.created = [] | |||
119 |
|
126 | |||
120 | def getheads(self): |
|
127 | def getheads(self): | |
121 | """Return a list of this repository's heads""" |
|
128 | """Return a list of this repository's heads""" |
@@ -16,16 +16,27 b' from common import NoRepo, commit, conve' | |||||
16 |
|
16 | |||
17 | class mercurial_sink(converter_sink): |
|
17 | class mercurial_sink(converter_sink): | |
18 | def __init__(self, ui, path): |
|
18 | def __init__(self, ui, path): | |
19 | self.path = path |
|
19 | converter_sink.__init__(self, ui, path) | |
20 | self.ui = ui |
|
|||
21 | self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True) |
|
20 | self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True) | |
22 | self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False) |
|
21 | self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False) | |
23 | self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default') |
|
22 | self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default') | |
24 | self.lastbranch = None |
|
23 | self.lastbranch = None | |
|
24 | if os.path.isdir(path) and len(os.listdir(path)) > 0: | |||
25 | try: |
|
25 | try: | |
26 | self.repo = hg.repository(self.ui, path) |
|
26 | self.repo = hg.repository(self.ui, path) | |
27 | except: |
|
27 | ui.status(_('destination %s is a Mercurial repository\n') % | |
28 | raise NoRepo("could not open hg repo %s as sink" % path) |
|
28 | path) | |
|
29 | except hg.RepoError, err: | |||
|
30 | ui.print_exc() | |||
|
31 | raise NoRepo(err.args[0]) | |||
|
32 | else: | |||
|
33 | try: | |||
|
34 | ui.status(_('initializing destination %s repository\n') % path) | |||
|
35 | self.repo = hg.repository(self.ui, path, create=True) | |||
|
36 | self.created.append(path) | |||
|
37 | except hg.RepoError, err: | |||
|
38 | ui.print_exc() | |||
|
39 | raise NoRepo("could not create hg repo %s as sink" % path) | |||
29 | self.lock = None |
|
40 | self.lock = None | |
30 | self.wlock = None |
|
41 | self.wlock = None | |
31 | self.filemapmode = False |
|
42 | self.filemapmode = False | |
@@ -108,7 +119,7 b' class mercurial_sink(converter_sink):' | |||||
108 | p2 = parents.pop(0) |
|
119 | p2 = parents.pop(0) | |
109 |
|
120 | |||
110 | text = commit.desc |
|
121 | text = commit.desc | |
111 |
extra = |
|
122 | extra = commit.extra.copy() | |
112 | if self.branchnames and commit.branch: |
|
123 | if self.branchnames and commit.branch: | |
113 | extra['branch'] = commit.branch |
|
124 | extra['branch'] = commit.branch | |
114 | if commit.rev: |
|
125 | if commit.rev: | |
@@ -174,7 +185,11 b' class mercurial_source(converter_source)' | |||||
174 | converter_source.__init__(self, ui, path, rev) |
|
185 | converter_source.__init__(self, ui, path, rev) | |
175 | try: |
|
186 | try: | |
176 | self.repo = hg.repository(self.ui, path) |
|
187 | self.repo = hg.repository(self.ui, path) | |
177 | except: |
|
188 | # try to provoke an exception if this isn't really a hg | |
|
189 | # repo, but some other bogus compatible-looking url | |||
|
190 | self.repo.heads() | |||
|
191 | except hg.RepoError: | |||
|
192 | ui.print_exc() | |||
178 | raise NoRepo("could not open hg repo %s as source" % path) |
|
193 | raise NoRepo("could not open hg repo %s as source" % path) | |
179 | self.lastrev = None |
|
194 | self.lastrev = None | |
180 | self.lastctx = None |
|
195 | self.lastctx = None | |
@@ -226,7 +241,7 b' class mercurial_source(converter_source)' | |||||
226 | parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] |
|
241 | parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] | |
227 | return commit(author=ctx.user(), date=util.datestr(ctx.date()), |
|
242 | return commit(author=ctx.user(), date=util.datestr(ctx.date()), | |
228 | desc=ctx.description(), parents=parents, |
|
243 | desc=ctx.description(), parents=parents, | |
229 | branch=ctx.branch()) |
|
244 | branch=ctx.branch(), extra=ctx.extra()) | |
230 |
|
245 | |||
231 | def gettags(self): |
|
246 | def gettags(self): | |
232 | tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
|
247 | tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
@@ -93,9 +93,9 b' def debugsvnlog(ui, **opts):' | |||||
93 | get_log_child(sys.stdout, *args) |
|
93 | get_log_child(sys.stdout, *args) | |
94 |
|
94 | |||
95 | # SVN conversion code stolen from bzr-svn and tailor |
|
95 | # SVN conversion code stolen from bzr-svn and tailor | |
96 |
class |
|
96 | class svn_source(converter_source): | |
97 | def __init__(self, ui, url, rev=None): |
|
97 | def __init__(self, ui, url, rev=None): | |
98 |
super( |
|
98 | super(svn_source, self).__init__(ui, url, rev=rev) | |
99 |
|
99 | |||
100 | try: |
|
100 | try: | |
101 | SubversionException |
|
101 | SubversionException | |
@@ -128,6 +128,7 b' class convert_svn(converter_source):' | |||||
128 | self.paths = {} |
|
128 | self.paths = {} | |
129 | self.uuid = svn.ra.get_uuid(self.ra).decode(self.encoding) |
|
129 | self.uuid = svn.ra.get_uuid(self.ra).decode(self.encoding) | |
130 | except SubversionException, e: |
|
130 | except SubversionException, e: | |
|
131 | ui.print_exc() | |||
131 | raise NoRepo("couldn't open SVN repo %s" % self.url) |
|
132 | raise NoRepo("couldn't open SVN repo %s" % self.url) | |
132 |
|
133 | |||
133 | if rev: |
|
134 | if rev: |
@@ -82,6 +82,7 b' class changectx(object):' | |||||
82 | def files(self): return self._changeset[3] |
|
82 | def files(self): return self._changeset[3] | |
83 | def description(self): return self._changeset[4] |
|
83 | def description(self): return self._changeset[4] | |
84 | def branch(self): return self._changeset[5].get("branch") |
|
84 | def branch(self): return self._changeset[5].get("branch") | |
|
85 | def extra(self): return self._changeset[5] | |||
85 | def tags(self): return self._repo.nodetags(self._node) |
|
86 | def tags(self): return self._repo.nodetags(self._node) | |
86 |
|
87 | |||
87 | def parents(self): |
|
88 | def parents(self): |
@@ -3,6 +3,8 b'' | |||||
3 | echo "[extensions]" >> $HGRCPATH |
|
3 | echo "[extensions]" >> $HGRCPATH | |
4 | echo "convert=" >> $HGRCPATH |
|
4 | echo "convert=" >> $HGRCPATH | |
5 |
|
5 | |||
|
6 | hg help convert | |||
|
7 | ||||
6 | hg init a |
|
8 | hg init a | |
7 | cd a |
|
9 | cd a | |
8 | echo a > a |
|
10 | echo a > a | |
@@ -19,3 +21,17 b" hg ci -d'4 0' -me" | |||||
19 | cd .. |
|
21 | cd .. | |
20 | hg convert a 2>&1 | grep -v 'subversion python bindings could not be loaded' |
|
22 | hg convert a 2>&1 | grep -v 'subversion python bindings could not be loaded' | |
21 | hg --cwd a-hg pull ../a |
|
23 | hg --cwd a-hg pull ../a | |
|
24 | ||||
|
25 | touch bogusfile | |||
|
26 | echo % should fail | |||
|
27 | hg convert a bogusfile | |||
|
28 | ||||
|
29 | mkdir bogusdir | |||
|
30 | chmod 000 bogusdir | |||
|
31 | ||||
|
32 | echo % should fail | |||
|
33 | hg convert a bogusdir | |||
|
34 | ||||
|
35 | echo % should succeed | |||
|
36 | chmod 700 bogusdir | |||
|
37 | hg convert a bogusdir |
@@ -7,6 +7,7 b' echo "convert=" >> $HGRCPATH' | |||||
7 | echo 'hgext.graphlog =' >> $HGRCPATH |
|
7 | echo 'hgext.graphlog =' >> $HGRCPATH | |
8 |
|
8 | |||
9 | DARCS_EMAIL='test@example.org'; export DARCS_EMAIL |
|
9 | DARCS_EMAIL='test@example.org'; export DARCS_EMAIL | |
|
10 | HOME=do_not_use_HOME_darcs; export HOME | |||
10 |
|
11 | |||
11 | echo % initialize darcs repo |
|
12 | echo % initialize darcs repo | |
12 | mkdir darcs-repo |
|
13 | mkdir darcs-repo |
@@ -1,3 +1,67 b'' | |||||
|
1 | hg convert [OPTION]... SOURCE [DEST [MAPFILE]] | |||
|
2 | ||||
|
3 | Convert a foreign SCM repository to a Mercurial one. | |||
|
4 | ||||
|
5 | Accepted source formats: | |||
|
6 | - CVS | |||
|
7 | - Darcs | |||
|
8 | - git | |||
|
9 | - Subversion | |||
|
10 | ||||
|
11 | Accepted destination formats: | |||
|
12 | - Mercurial | |||
|
13 | ||||
|
14 | If no revision is given, all revisions will be converted. Otherwise, | |||
|
15 | convert will only import up to the named revision (given in a format | |||
|
16 | understood by the source). | |||
|
17 | ||||
|
18 | If no destination directory name is specified, it defaults to the | |||
|
19 | basename of the source with '-hg' appended. If the destination | |||
|
20 | repository doesn't exist, it will be created. | |||
|
21 | ||||
|
22 | If <revmapfile> isn't given, it will be put in a default location | |||
|
23 | (<dest>/.hg/shamap by default). The <revmapfile> is a simple text | |||
|
24 | file that maps each source commit ID to the destination ID for | |||
|
25 | that revision, like so: | |||
|
26 | <source ID> <destination ID> | |||
|
27 | ||||
|
28 | If the file doesn't exist, it's automatically created. It's updated | |||
|
29 | on each commit copied, so convert-repo can be interrupted and can | |||
|
30 | be run repeatedly to copy new commits. | |||
|
31 | ||||
|
32 | The [username mapping] file is a simple text file that maps each source | |||
|
33 | commit author to a destination commit author. It is handy for source SCMs | |||
|
34 | that use unix logins to identify authors (eg: CVS). One line per author | |||
|
35 | mapping and the line format is: | |||
|
36 | srcauthor=whatever string you want | |||
|
37 | ||||
|
38 | The filemap is a file that allows filtering and remapping of files | |||
|
39 | and directories. Comment lines start with '#'. Each line can | |||
|
40 | contain one of the following directives: | |||
|
41 | ||||
|
42 | include path/to/file | |||
|
43 | ||||
|
44 | exclude path/to/file | |||
|
45 | ||||
|
46 | rename from/file to/file | |||
|
47 | ||||
|
48 | The 'include' directive causes a file, or all files under a | |||
|
49 | directory, to be included in the destination repository. The | |||
|
50 | 'exclude' directive causes files or directories to be omitted. | |||
|
51 | The 'rename' directive renames a file or directory. To rename | |||
|
52 | from a subdirectory into the root of the repository, use '.' as | |||
|
53 | the path to rename to. | |||
|
54 | ||||
|
55 | options: | |||
|
56 | ||||
|
57 | -A --authors username mapping filename | |||
|
58 | -d --dest-type destination repository type | |||
|
59 | --filemap remap file names using contents of file | |||
|
60 | -r --rev import up to target revision REV | |||
|
61 | -s --source-type source repository type | |||
|
62 | --datesort try to sort changesets by date | |||
|
63 | ||||
|
64 | use "hg -v help convert" to show global options | |||
1 | adding a |
|
65 | adding a | |
2 | assuming destination a-hg |
|
66 | assuming destination a-hg | |
3 | initializing destination a-hg repository |
|
67 | initializing destination a-hg repository | |
@@ -12,3 +76,18 b' 0 e' | |||||
12 | pulling from ../a |
|
76 | pulling from ../a | |
13 | searching for changes |
|
77 | searching for changes | |
14 | no changes found |
|
78 | no changes found | |
|
79 | % should fail | |||
|
80 | initializing destination bogusfile repository | |||
|
81 | abort: cannot create new bundle repository | |||
|
82 | % should fail | |||
|
83 | abort: Permission denied: bogusdir | |||
|
84 | % should succeed | |||
|
85 | initializing destination bogusdir repository | |||
|
86 | scanning source... | |||
|
87 | sorting... | |||
|
88 | converting... | |||
|
89 | 4 a | |||
|
90 | 3 b | |||
|
91 | 2 c | |||
|
92 | 1 d | |||
|
93 | 0 e |
General Comments 0
You need to be logged in to leave comments.
Login now