annotate hgext/convert/__init__.py @ 5513:f0c58fd4b798

convert: add support for Subversion as a sink
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 07 Nov 2007 18:26:59 -0800
parents 11d7908a3ea8
children 6ffca2bf23da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
1 # convert.py Foreign SCM converter
3917
645e1dd4b8ae convert-repo: update usage information
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3911
diff changeset
2 #
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4591
diff changeset
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
4 #
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
5 # This software may be used and distributed according to the terms
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
7
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
8 from common import NoRepo, SKIPREV, converter_source, converter_sink, mapfile
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
9 from cvs import convert_cvs
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents: 5356
diff changeset
10 from darcs import darcs_source
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
11 from git import convert_git
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5012
diff changeset
12 from hg import mercurial_source, mercurial_sink
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5510
diff changeset
13 from subversion import debugsvnlog, svn_source, svn_sink
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
14 import filemap
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
15
5376
d60a067227a5 convert: move filemapper class to a separate file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5375
diff changeset
16 import os, shutil
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
17 from mercurial import hg, ui, util, commands
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
18 from mercurial.i18n import _
3821
158fce02dc40 Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents: 2657
diff changeset
19
5138
9cda2315c7a9 convert: Use debugsvnlog instead of git-like debug-svn-log.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5134
diff changeset
20 commands.norepo += " convert debugsvnlog"
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
21
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
22 source_converters = [
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
23 ('cvs', convert_cvs),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
24 ('git', convert_git),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
25 ('svn', svn_source),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
26 ('hg', mercurial_source),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
27 ('darcs', darcs_source),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
28 ]
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
29
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
30 sink_converters = [
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
31 ('hg', mercurial_sink),
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5510
diff changeset
32 ('svn', svn_sink),
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
33 ]
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
34
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
35 def convertsource(ui, path, type, rev):
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
36 for name, source in source_converters:
4763
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4761
diff changeset
37 try:
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
38 if not type or name == type:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
39 return source(ui, path, rev)
5415
1d53a75ea0fc convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5414
diff changeset
40 except NoRepo, inst:
1d53a75ea0fc convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5414
diff changeset
41 ui.note(_("convert: %s\n") % inst)
4763
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4761
diff changeset
42 raise util.Abort('%s: unknown repository type' % path)
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4761
diff changeset
43
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
44 def convertsink(ui, path, type):
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
45 for name, sink in sink_converters:
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
46 try:
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
47 if not type or name == type:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
48 return sink(ui, path)
5415
1d53a75ea0fc convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5414
diff changeset
49 except NoRepo, inst:
1d53a75ea0fc convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5414
diff changeset
50 ui.note(_("convert: %s\n") % inst)
4763
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4761
diff changeset
51 raise util.Abort('%s: unknown repository type' % path)
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
52
5281
a176f9c8b26e convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5256
diff changeset
53 class converter(object):
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
54 def __init__(self, ui, source, dest, revmapfile, opts):
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
55
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
56 self.source = source
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
57 self.dest = dest
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
58 self.ui = ui
3957
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
59 self.opts = opts
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
60 self.commitcache = {}
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
61 self.authors = {}
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
62 self.authorfile = None
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
63
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
64 self.map = mapfile(ui, revmapfile)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
65
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
66 # Read first the dst author map if any
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
67 authorfile = self.dest.authorfile()
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
68 if authorfile and os.path.exists(authorfile):
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
69 self.readauthormap(authorfile)
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
70 # Extend/Override with new author map if necessary
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
71 if opts.get('authors'):
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
72 self.readauthormap(opts.get('authors'))
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
73 self.authorfile = self.dest.authorfile()
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
74
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
75 def walktree(self, heads):
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
76 '''Return a mapping that identifies the uncommitted parents of every
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
77 uncommitted changeset.'''
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
78 visit = heads
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
79 known = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
80 parents = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
81 while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
82 n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
83 if n in known or n in self.map: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
84 known[n] = 1
5203
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
85 commit = self.cachecommit(n)
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
86 parents[n] = []
5203
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
87 for p in commit.parents:
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
88 parents[n].append(p)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
89 visit.append(p)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
90
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
91 return parents
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
92
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
93 def toposort(self, parents):
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
94 '''Return an ordering such that every uncommitted changeset is
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
95 preceeded by all its uncommitted ancestors.'''
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
96 visit = parents.keys()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
97 seen = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
98 children = {}
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
99
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
100 while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
101 n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
102 if n in seen: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
103 seen[n] = 1
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
104 # Ensure that nodes without parents are present in the 'children'
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
105 # mapping.
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
106 children.setdefault(n, [])
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
107 for p in parents[n]:
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
108 if not p in self.map:
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
109 visit.append(p)
4719
1069205a8894 fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents: 4635
diff changeset
110 children.setdefault(p, []).append(n)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
111
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
112 s = []
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
113 removed = {}
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
114 visit = children.keys()
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
115 while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
116 n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
117 if n in removed: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
118 dep = 0
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
119 if n in parents:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
120 for p in parents[n]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
121 if p in self.map: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
122 if p not in removed:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
123 # we're still dependent
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
124 visit.append(n)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
125 dep = 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
126 break
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
127
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
128 if not dep:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
129 # all n's parents are in the list
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
130 removed[n] = 1
3957
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
131 if n not in self.map:
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
132 s.append(n)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
133 if n in children:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
134 for c in children[n]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
135 visit.insert(0, c)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
136
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
137 if self.opts.get('datesort'):
3957
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
138 depth = {}
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
139 for n in s:
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
140 depth[n] = 0
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
141 pl = [p for p in self.commitcache[n].parents
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
142 if p not in self.map]
3957
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
143 if pl:
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
144 depth[n] = max([depth[p] for p in pl]) + 1
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
145
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
146 s = [(depth[n], self.commitcache[n].date, n) for n in s]
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
147 s.sort()
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
148 s = [e[2] for e in s]
2b87d3c5ab8e convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents: 3956
diff changeset
149
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
150 return s
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
151
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
152 def writeauthormap(self):
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
153 authorfile = self.authorfile
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
154 if authorfile:
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
155 self.ui.status('Writing author map file %s\n' % authorfile)
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
156 ofile = open(authorfile, 'w+')
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
157 for author in self.authors:
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
158 ofile.write("%s=%s\n" % (author, self.authors[author]))
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
159 ofile.close()
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
160
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
161 def readauthormap(self, authorfile):
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
162 afile = open(authorfile, 'r')
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
163 for line in afile:
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
164 try:
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
165 srcauthor = line.split('=')[0].strip()
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
166 dstauthor = line.split('=')[1].strip()
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
167 if srcauthor in self.authors and dstauthor != self.authors[srcauthor]:
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
168 self.ui.status(
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
169 'Overriding mapping for author %s, was %s, will be %s\n'
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
170 % (srcauthor, self.authors[srcauthor], dstauthor))
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
171 else:
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
172 self.ui.debug('Mapping author %s to %s\n'
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
173 % (srcauthor, dstauthor))
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
174 self.authors[srcauthor] = dstauthor
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
175 except IndexError:
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
176 self.ui.warn(
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
177 'Ignoring bad line in author file map %s: %s\n'
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
178 % (authorfile, line))
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
179 afile.close()
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
180
5203
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
181 def cachecommit(self, rev):
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
182 commit = self.source.getcommit(rev)
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
183 commit.author = self.authors.get(commit.author, commit.author)
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
184 self.commitcache[rev] = commit
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
185 return commit
653790c2fa52 convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents: 5195
diff changeset
186
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
187 def copy(self, rev):
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
188 commit = self.commitcache[rev]
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
189 do_copies = hasattr(self.dest, 'copyfile')
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
190 filenames = []
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4924
diff changeset
191
5374
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
192 changes = self.source.getchanges(rev)
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
193 if isinstance(changes, basestring):
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
194 if changes == SKIPREV:
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
195 dest = SKIPREV
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
196 else:
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
197 dest = self.map[changes]
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
198 self.map[rev] = dest
5374
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
199 return
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
200 files, copies = changes
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
201 parents = [self.map[r] for r in commit.parents]
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
202 if commit.parents:
5204
6f636d13f6b8 convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents: 5203
diff changeset
203 prev = commit.parents[0]
6f636d13f6b8 convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents: 5203
diff changeset
204 if prev not in self.commitcache:
6f636d13f6b8 convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents: 5203
diff changeset
205 self.cachecommit(prev)
6f636d13f6b8 convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents: 5203
diff changeset
206 pbranch = self.commitcache[prev].branch
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
207 else:
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
208 pbranch = None
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
209 self.dest.setbranch(commit.branch, pbranch, parents)
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5018
diff changeset
210 for f, v in files:
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
211 filenames.append(f)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
212 try:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
213 data = self.source.getfile(f, v)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
214 except IOError, inst:
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
215 self.dest.delfile(f)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
216 else:
3956
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
217 e = self.source.getmode(f, v)
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
218 self.dest.putfile(f, e, data)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents: 4763
diff changeset
219 if do_copies:
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5018
diff changeset
220 if f in copies:
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
221 copyf = copies[f]
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
222 # Merely marks that a copy happened.
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
223 self.dest.copyfile(copyf, f)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents: 4763
diff changeset
224
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
225 newnode = self.dest.putcommit(filenames, parents, commit)
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
226 self.map[rev] = newnode
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
227
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
228 def convert(self):
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
229 try:
5356
f0931c0240b4 convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents: 5281
diff changeset
230 self.source.before()
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
231 self.dest.before()
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
232 self.source.setrevmap(self.map)
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
233 self.ui.status("scanning source...\n")
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
234 heads = self.source.getheads()
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
235 parents = self.walktree(heads)
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
236 self.ui.status("sorting...\n")
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
237 t = self.toposort(parents)
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
238 num = len(t)
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
239 c = None
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
240
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
241 self.ui.status("converting...\n")
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
242 for c in t:
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
243 num -= 1
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
244 desc = self.commitcache[c].desc
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
245 if "\n" in desc:
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
246 desc = desc.splitlines()[0]
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
247 self.ui.status("%d %s\n" % (num, desc))
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
248 self.copy(c)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
249
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
250 tags = self.source.gettags()
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
251 ctags = {}
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
252 for k in tags:
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
253 v = tags[k]
5374
e710874247d1 convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
254 if self.map.get(v, SKIPREV) != SKIPREV:
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
255 ctags[k] = self.map[v]
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
256
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
257 if c and ctags:
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
258 nrev = self.dest.puttags(ctags)
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
259 # write another hash correspondence to override the previous
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
260 # one so we don't end up with extra tag heads
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
261 if nrev:
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
262 self.map[c] = nrev
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
263
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
264 self.writeauthormap()
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
265 finally:
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
266 self.cleanup()
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
267
4588
9855939d0c82 convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
268 def cleanup(self):
5356
f0931c0240b4 convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents: 5281
diff changeset
269 try:
f0931c0240b4 convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents: 5281
diff changeset
270 self.dest.after()
f0931c0240b4 convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents: 5281
diff changeset
271 finally:
f0931c0240b4 convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents: 5281
diff changeset
272 self.source.after()
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5488
diff changeset
273 self.map.close()
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
274
5281
a176f9c8b26e convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5256
diff changeset
275 def convert(ui, src, dest=None, revmapfile=None, **opts):
4958
71fed370b7a7 Backout ad09ce1d393c and replace ''' with """ to make some highlighting happy.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4957
diff changeset
276 """Convert a foreign SCM repository to a Mercurial one.
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
277
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
278 Accepted source formats:
5484
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
279 - Mercurial
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
280 - CVS
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents: 5356
diff changeset
281 - Darcs
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents: 5356
diff changeset
282 - git
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents: 5356
diff changeset
283 - Subversion
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
284
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
285 Accepted destination formats:
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
286 - Mercurial
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5510
diff changeset
287 - Subversion (history on branches is not preserved)
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
288
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4719
diff changeset
289 If no revision is given, all revisions will be converted. Otherwise,
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4719
diff changeset
290 convert will only import up to the named revision (given in a format
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4719
diff changeset
291 understood by the source).
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4719
diff changeset
292
4883
72ac66e88c43 convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4719
diff changeset
293 If no destination directory name is specified, it defaults to the
4958
71fed370b7a7 Backout ad09ce1d393c and replace ''' with """ to make some highlighting happy.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4957
diff changeset
294 basename of the source with '-hg' appended. If the destination
71fed370b7a7 Backout ad09ce1d393c and replace ''' with """ to make some highlighting happy.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4957
diff changeset
295 repository doesn't exist, it will be created.
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
296
5484
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
297 If <MAPFILE> isn't given, it will be put in a default location
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
298 (<dest>/.hg/shamap by default). The <MAPFILE> is a simple text
4883
72ac66e88c43 convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4719
diff changeset
299 file that maps each source commit ID to the destination ID for
72ac66e88c43 convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4719
diff changeset
300 that revision, like so:
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
301 <source ID> <destination ID>
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
302
4958
71fed370b7a7 Backout ad09ce1d393c and replace ''' with """ to make some highlighting happy.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4957
diff changeset
303 If the file doesn't exist, it's automatically created. It's updated
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
304 on each commit copied, so convert-repo can be interrupted and can
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
305 be run repeatedly to copy new commits.
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
306
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
307 The [username mapping] file is a simple text file that maps each source
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
308 commit author to a destination commit author. It is handy for source SCMs
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
309 that use unix logins to identify authors (eg: CVS). One line per author
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
310 mapping and the line format is:
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
311 srcauthor=whatever string you want
5256
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
312
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
313 The filemap is a file that allows filtering and remapping of files
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
314 and directories. Comment lines start with '#'. Each line can
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
315 contain one of the following directives:
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
316
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
317 include path/to/file
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
318
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
319 exclude path/to/file
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
320
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
321 rename from/file to/file
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
322
0b0caffcf175 convert: document filemap.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5204
diff changeset
323 The 'include' directive causes a file, or all files under a
5484
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
324 directory, to be included in the destination repository, and the
5488
247af577fe29 fix typo in convert help text, update test
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5484
diff changeset
325 exclusion of all other files and dirs not explicitely included.
5484
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
326 The 'exclude' directive causes files or directories to be omitted.
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
327 The 'rename' directive renames a file or directory. To rename from a
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
328 subdirectory into the root of the repository, use '.' as the path to
07bdb5e5d08c Update convert help text
"Rafael Villar Burke <pachi@rvburke.com>"
parents: 5441
diff changeset
329 rename to.
4958
71fed370b7a7 Backout ad09ce1d393c and replace ''' with """ to make some highlighting happy.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4957
diff changeset
330 """
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
331
4895
fa6c9381d053 convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4883
diff changeset
332 util._encoding = 'UTF-8'
fa6c9381d053 convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4883
diff changeset
333
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
334 if not dest:
4883
72ac66e88c43 convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4719
diff changeset
335 dest = hg.defaultdest(src) + "-hg"
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
336 ui.status("assuming destination %s\n" % dest)
4521
d634b61e9cec Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents: 4520
diff changeset
337
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
338 destc = convertsink(ui, dest, opts.get('dest_type'))
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
339
4761
7c8cd400e86a convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
340 try:
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
341 srcc = convertsource(ui, src, opts.get('source_type'),
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
342 opts.get('rev'))
4761
7c8cd400e86a convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
343 except Exception:
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
344 for path in destc.created:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
345 shutil.rmtree(path, True)
4761
7c8cd400e86a convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
346 raise
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
347
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
348 fmap = opts.get('filemap')
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
349 if fmap:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
350 srcc = filemap.filemap_source(ui, srcc, fmap)
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
351 destc.setfilemapmode(True)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
352
5011
89fbb0a5e8e3 convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents: 4958
diff changeset
353 if not revmapfile:
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
354 try:
5011
89fbb0a5e8e3 convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents: 4958
diff changeset
355 revmapfile = destc.revmapfile()
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
356 except:
5011
89fbb0a5e8e3 convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents: 4958
diff changeset
357 revmapfile = os.path.join(destc, "map")
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
358
5375
dae323e453aa convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5374
diff changeset
359 c = converter(ui, srcc, destc, revmapfile, opts)
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
360 c.convert()
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
361
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5121
diff changeset
362
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
363 cmdtable = {
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
364 "convert":
5281
a176f9c8b26e convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5256
diff changeset
365 (convert,
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
366 [('A', 'authors', '', 'username mapping filename'),
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
367 ('d', 'dest-type', '', 'destination repository type'),
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
368 ('', 'filemap', '', 'remap file names using contents of file'),
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4719
diff changeset
369 ('r', 'rev', '', 'import up to target revision REV'),
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5438
diff changeset
370 ('s', 'source-type', '', 'source repository type'),
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4588
diff changeset
371 ('', 'datesort', None, 'try to sort changesets by date')],
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
372 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'),
5138
9cda2315c7a9 convert: Use debugsvnlog instead of git-like debug-svn-log.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5134
diff changeset
373 "debugsvnlog":
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5121
diff changeset
374 (debugsvnlog,
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5121
diff changeset
375 [],
5138
9cda2315c7a9 convert: Use debugsvnlog instead of git-like debug-svn-log.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5134
diff changeset
376 'hg debugsvnlog'),
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
377 }
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5121
diff changeset
378