##// END OF EJS Templates
convert: introduce hg.revs to replace hg.startrev and --rev with a revset...
Mads Kiilerich -
r19891:e271970b default
parent child Browse files
Show More
@@ -1,383 +1,382 b''
1 # convert.py Foreign SCM converter
1 # convert.py Foreign SCM converter
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 '''import revisions from foreign VCS repositories into Mercurial'''
8 '''import revisions from foreign VCS repositories into Mercurial'''
9
9
10 import convcmd
10 import convcmd
11 import cvsps
11 import cvsps
12 import subversion
12 import subversion
13 from mercurial import commands, templatekw
13 from mercurial import commands, templatekw
14 from mercurial.i18n import _
14 from mercurial.i18n import _
15
15
16 testedwith = 'internal'
16 testedwith = 'internal'
17
17
18 # Commands definition was moved elsewhere to ease demandload job.
18 # Commands definition was moved elsewhere to ease demandload job.
19
19
20 def convert(ui, src, dest=None, revmapfile=None, **opts):
20 def convert(ui, src, dest=None, revmapfile=None, **opts):
21 """convert a foreign SCM repository to a Mercurial one.
21 """convert a foreign SCM repository to a Mercurial one.
22
22
23 Accepted source formats [identifiers]:
23 Accepted source formats [identifiers]:
24
24
25 - Mercurial [hg]
25 - Mercurial [hg]
26 - CVS [cvs]
26 - CVS [cvs]
27 - Darcs [darcs]
27 - Darcs [darcs]
28 - git [git]
28 - git [git]
29 - Subversion [svn]
29 - Subversion [svn]
30 - Monotone [mtn]
30 - Monotone [mtn]
31 - GNU Arch [gnuarch]
31 - GNU Arch [gnuarch]
32 - Bazaar [bzr]
32 - Bazaar [bzr]
33 - Perforce [p4]
33 - Perforce [p4]
34
34
35 Accepted destination formats [identifiers]:
35 Accepted destination formats [identifiers]:
36
36
37 - Mercurial [hg]
37 - Mercurial [hg]
38 - Subversion [svn] (history on branches is not preserved)
38 - Subversion [svn] (history on branches is not preserved)
39
39
40 If no revision is given, all revisions will be converted.
40 If no revision is given, all revisions will be converted.
41 Otherwise, convert will only import up to the named revision
41 Otherwise, convert will only import up to the named revision
42 (given in a format understood by the source).
42 (given in a format understood by the source).
43
43
44 If no destination directory name is specified, it defaults to the
44 If no destination directory name is specified, it defaults to the
45 basename of the source with ``-hg`` appended. If the destination
45 basename of the source with ``-hg`` appended. If the destination
46 repository doesn't exist, it will be created.
46 repository doesn't exist, it will be created.
47
47
48 By default, all sources except Mercurial will use --branchsort.
48 By default, all sources except Mercurial will use --branchsort.
49 Mercurial uses --sourcesort to preserve original revision numbers
49 Mercurial uses --sourcesort to preserve original revision numbers
50 order. Sort modes have the following effects:
50 order. Sort modes have the following effects:
51
51
52 --branchsort convert from parent to child revision when possible,
52 --branchsort convert from parent to child revision when possible,
53 which means branches are usually converted one after
53 which means branches are usually converted one after
54 the other. It generates more compact repositories.
54 the other. It generates more compact repositories.
55
55
56 --datesort sort revisions by date. Converted repositories have
56 --datesort sort revisions by date. Converted repositories have
57 good-looking changelogs but are often an order of
57 good-looking changelogs but are often an order of
58 magnitude larger than the same ones generated by
58 magnitude larger than the same ones generated by
59 --branchsort.
59 --branchsort.
60
60
61 --sourcesort try to preserve source revisions order, only
61 --sourcesort try to preserve source revisions order, only
62 supported by Mercurial sources.
62 supported by Mercurial sources.
63
63
64 --closesort try to move closed revisions as close as possible
64 --closesort try to move closed revisions as close as possible
65 to parent branches, only supported by Mercurial
65 to parent branches, only supported by Mercurial
66 sources.
66 sources.
67
67
68 If ``REVMAP`` isn't given, it will be put in a default location
68 If ``REVMAP`` isn't given, it will be put in a default location
69 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
69 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
70 text file that maps each source commit ID to the destination ID
70 text file that maps each source commit ID to the destination ID
71 for that revision, like so::
71 for that revision, like so::
72
72
73 <source ID> <destination ID>
73 <source ID> <destination ID>
74
74
75 If the file doesn't exist, it's automatically created. It's
75 If the file doesn't exist, it's automatically created. It's
76 updated on each commit copied, so :hg:`convert` can be interrupted
76 updated on each commit copied, so :hg:`convert` can be interrupted
77 and can be run repeatedly to copy new commits.
77 and can be run repeatedly to copy new commits.
78
78
79 The authormap is a simple text file that maps each source commit
79 The authormap is a simple text file that maps each source commit
80 author to a destination commit author. It is handy for source SCMs
80 author to a destination commit author. It is handy for source SCMs
81 that use unix logins to identify authors (e.g.: CVS). One line per
81 that use unix logins to identify authors (e.g.: CVS). One line per
82 author mapping and the line format is::
82 author mapping and the line format is::
83
83
84 source author = destination author
84 source author = destination author
85
85
86 Empty lines and lines starting with a ``#`` are ignored.
86 Empty lines and lines starting with a ``#`` are ignored.
87
87
88 The filemap is a file that allows filtering and remapping of files
88 The filemap is a file that allows filtering and remapping of files
89 and directories. Each line can contain one of the following
89 and directories. Each line can contain one of the following
90 directives::
90 directives::
91
91
92 include path/to/file-or-dir
92 include path/to/file-or-dir
93
93
94 exclude path/to/file-or-dir
94 exclude path/to/file-or-dir
95
95
96 rename path/to/source path/to/destination
96 rename path/to/source path/to/destination
97
97
98 Comment lines start with ``#``. A specified path matches if it
98 Comment lines start with ``#``. A specified path matches if it
99 equals the full relative name of a file or one of its parent
99 equals the full relative name of a file or one of its parent
100 directories. The ``include`` or ``exclude`` directive with the
100 directories. The ``include`` or ``exclude`` directive with the
101 longest matching path applies, so line order does not matter.
101 longest matching path applies, so line order does not matter.
102
102
103 The ``include`` directive causes a file, or all files under a
103 The ``include`` directive causes a file, or all files under a
104 directory, to be included in the destination repository, and the
104 directory, to be included in the destination repository, and the
105 exclusion of all other files and directories not explicitly
105 exclusion of all other files and directories not explicitly
106 included. The ``exclude`` directive causes files or directories to
106 included. The ``exclude`` directive causes files or directories to
107 be omitted. The ``rename`` directive renames a file or directory if
107 be omitted. The ``rename`` directive renames a file or directory if
108 it is converted. To rename from a subdirectory into the root of
108 it is converted. To rename from a subdirectory into the root of
109 the repository, use ``.`` as the path to rename to.
109 the repository, use ``.`` as the path to rename to.
110
110
111 The splicemap is a file that allows insertion of synthetic
111 The splicemap is a file that allows insertion of synthetic
112 history, letting you specify the parents of a revision. This is
112 history, letting you specify the parents of a revision. This is
113 useful if you want to e.g. give a Subversion merge two parents, or
113 useful if you want to e.g. give a Subversion merge two parents, or
114 graft two disconnected series of history together. Each entry
114 graft two disconnected series of history together. Each entry
115 contains a key, followed by a space, followed by one or two
115 contains a key, followed by a space, followed by one or two
116 comma-separated values::
116 comma-separated values::
117
117
118 key parent1, parent2
118 key parent1, parent2
119
119
120 The key is the revision ID in the source
120 The key is the revision ID in the source
121 revision control system whose parents should be modified (same
121 revision control system whose parents should be modified (same
122 format as a key in .hg/shamap). The values are the revision IDs
122 format as a key in .hg/shamap). The values are the revision IDs
123 (in either the source or destination revision control system) that
123 (in either the source or destination revision control system) that
124 should be used as the new parents for that node. For example, if
124 should be used as the new parents for that node. For example, if
125 you have merged "release-1.0" into "trunk", then you should
125 you have merged "release-1.0" into "trunk", then you should
126 specify the revision on "trunk" as the first parent and the one on
126 specify the revision on "trunk" as the first parent and the one on
127 the "release-1.0" branch as the second.
127 the "release-1.0" branch as the second.
128
128
129 The branchmap is a file that allows you to rename a branch when it is
129 The branchmap is a file that allows you to rename a branch when it is
130 being brought in from whatever external repository. When used in
130 being brought in from whatever external repository. When used in
131 conjunction with a splicemap, it allows for a powerful combination
131 conjunction with a splicemap, it allows for a powerful combination
132 to help fix even the most badly mismanaged repositories and turn them
132 to help fix even the most badly mismanaged repositories and turn them
133 into nicely structured Mercurial repositories. The branchmap contains
133 into nicely structured Mercurial repositories. The branchmap contains
134 lines of the form::
134 lines of the form::
135
135
136 original_branch_name new_branch_name
136 original_branch_name new_branch_name
137
137
138 where "original_branch_name" is the name of the branch in the
138 where "original_branch_name" is the name of the branch in the
139 source repository, and "new_branch_name" is the name of the branch
139 source repository, and "new_branch_name" is the name of the branch
140 is the destination repository. No whitespace is allowed in the
140 is the destination repository. No whitespace is allowed in the
141 branch names. This can be used to (for instance) move code in one
141 branch names. This can be used to (for instance) move code in one
142 repository from "default" to a named branch.
142 repository from "default" to a named branch.
143
143
144 Mercurial Source
144 Mercurial Source
145 ################
145 ################
146
146
147 The Mercurial source recognizes the following configuration
147 The Mercurial source recognizes the following configuration
148 options, which you can set on the command line with ``--config``:
148 options, which you can set on the command line with ``--config``:
149
149
150 :convert.hg.ignoreerrors: ignore integrity errors when reading.
150 :convert.hg.ignoreerrors: ignore integrity errors when reading.
151 Use it to fix Mercurial repositories with missing revlogs, by
151 Use it to fix Mercurial repositories with missing revlogs, by
152 converting from and to Mercurial. Default is False.
152 converting from and to Mercurial. Default is False.
153
153
154 :convert.hg.saverev: store original revision ID in changeset
154 :convert.hg.saverev: store original revision ID in changeset
155 (forces target IDs to change). It takes a boolean argument and
155 (forces target IDs to change). It takes a boolean argument and
156 defaults to False.
156 defaults to False.
157
157
158 :convert.hg.startrev: convert start revision and its descendants.
158 :convert.hg.revs: revset specifying the source revisions to convert.
159 It takes a hg revision identifier and defaults to 0.
160
159
161 CVS Source
160 CVS Source
162 ##########
161 ##########
163
162
164 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
163 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
165 to indicate the starting point of what will be converted. Direct
164 to indicate the starting point of what will be converted. Direct
166 access to the repository files is not needed, unless of course the
165 access to the repository files is not needed, unless of course the
167 repository is ``:local:``. The conversion uses the top level
166 repository is ``:local:``. The conversion uses the top level
168 directory in the sandbox to find the CVS repository, and then uses
167 directory in the sandbox to find the CVS repository, and then uses
169 CVS rlog commands to find files to convert. This means that unless
168 CVS rlog commands to find files to convert. This means that unless
170 a filemap is given, all files under the starting directory will be
169 a filemap is given, all files under the starting directory will be
171 converted, and that any directory reorganization in the CVS
170 converted, and that any directory reorganization in the CVS
172 sandbox is ignored.
171 sandbox is ignored.
173
172
174 The following options can be used with ``--config``:
173 The following options can be used with ``--config``:
175
174
176 :convert.cvsps.cache: Set to False to disable remote log caching,
175 :convert.cvsps.cache: Set to False to disable remote log caching,
177 for testing and debugging purposes. Default is True.
176 for testing and debugging purposes. Default is True.
178
177
179 :convert.cvsps.fuzz: Specify the maximum time (in seconds) that is
178 :convert.cvsps.fuzz: Specify the maximum time (in seconds) that is
180 allowed between commits with identical user and log message in
179 allowed between commits with identical user and log message in
181 a single changeset. When very large files were checked in as
180 a single changeset. When very large files were checked in as
182 part of a changeset then the default may not be long enough.
181 part of a changeset then the default may not be long enough.
183 The default is 60.
182 The default is 60.
184
183
185 :convert.cvsps.mergeto: Specify a regular expression to which
184 :convert.cvsps.mergeto: Specify a regular expression to which
186 commit log messages are matched. If a match occurs, then the
185 commit log messages are matched. If a match occurs, then the
187 conversion process will insert a dummy revision merging the
186 conversion process will insert a dummy revision merging the
188 branch on which this log message occurs to the branch
187 branch on which this log message occurs to the branch
189 indicated in the regex. Default is ``{{mergetobranch
188 indicated in the regex. Default is ``{{mergetobranch
190 ([-\\w]+)}}``
189 ([-\\w]+)}}``
191
190
192 :convert.cvsps.mergefrom: Specify a regular expression to which
191 :convert.cvsps.mergefrom: Specify a regular expression to which
193 commit log messages are matched. If a match occurs, then the
192 commit log messages are matched. If a match occurs, then the
194 conversion process will add the most recent revision on the
193 conversion process will add the most recent revision on the
195 branch indicated in the regex as the second parent of the
194 branch indicated in the regex as the second parent of the
196 changeset. Default is ``{{mergefrombranch ([-\\w]+)}}``
195 changeset. Default is ``{{mergefrombranch ([-\\w]+)}}``
197
196
198 :convert.localtimezone: use local time (as determined by the TZ
197 :convert.localtimezone: use local time (as determined by the TZ
199 environment variable) for changeset date/times. The default
198 environment variable) for changeset date/times. The default
200 is False (use UTC).
199 is False (use UTC).
201
200
202 :hooks.cvslog: Specify a Python function to be called at the end of
201 :hooks.cvslog: Specify a Python function to be called at the end of
203 gathering the CVS log. The function is passed a list with the
202 gathering the CVS log. The function is passed a list with the
204 log entries, and can modify the entries in-place, or add or
203 log entries, and can modify the entries in-place, or add or
205 delete them.
204 delete them.
206
205
207 :hooks.cvschangesets: Specify a Python function to be called after
206 :hooks.cvschangesets: Specify a Python function to be called after
208 the changesets are calculated from the CVS log. The
207 the changesets are calculated from the CVS log. The
209 function is passed a list with the changeset entries, and can
208 function is passed a list with the changeset entries, and can
210 modify the changesets in-place, or add or delete them.
209 modify the changesets in-place, or add or delete them.
211
210
212 An additional "debugcvsps" Mercurial command allows the builtin
211 An additional "debugcvsps" Mercurial command allows the builtin
213 changeset merging code to be run without doing a conversion. Its
212 changeset merging code to be run without doing a conversion. Its
214 parameters and output are similar to that of cvsps 2.1. Please see
213 parameters and output are similar to that of cvsps 2.1. Please see
215 the command help for more details.
214 the command help for more details.
216
215
217 Subversion Source
216 Subversion Source
218 #################
217 #################
219
218
220 Subversion source detects classical trunk/branches/tags layouts.
219 Subversion source detects classical trunk/branches/tags layouts.
221 By default, the supplied ``svn://repo/path/`` source URL is
220 By default, the supplied ``svn://repo/path/`` source URL is
222 converted as a single branch. If ``svn://repo/path/trunk`` exists
221 converted as a single branch. If ``svn://repo/path/trunk`` exists
223 it replaces the default branch. If ``svn://repo/path/branches``
222 it replaces the default branch. If ``svn://repo/path/branches``
224 exists, its subdirectories are listed as possible branches. If
223 exists, its subdirectories are listed as possible branches. If
225 ``svn://repo/path/tags`` exists, it is looked for tags referencing
224 ``svn://repo/path/tags`` exists, it is looked for tags referencing
226 converted branches. Default ``trunk``, ``branches`` and ``tags``
225 converted branches. Default ``trunk``, ``branches`` and ``tags``
227 values can be overridden with following options. Set them to paths
226 values can be overridden with following options. Set them to paths
228 relative to the source URL, or leave them blank to disable auto
227 relative to the source URL, or leave them blank to disable auto
229 detection.
228 detection.
230
229
231 The following options can be set with ``--config``:
230 The following options can be set with ``--config``:
232
231
233 :convert.svn.branches: specify the directory containing branches.
232 :convert.svn.branches: specify the directory containing branches.
234 The default is ``branches``.
233 The default is ``branches``.
235
234
236 :convert.svn.tags: specify the directory containing tags. The
235 :convert.svn.tags: specify the directory containing tags. The
237 default is ``tags``.
236 default is ``tags``.
238
237
239 :convert.svn.trunk: specify the name of the trunk branch. The
238 :convert.svn.trunk: specify the name of the trunk branch. The
240 default is ``trunk``.
239 default is ``trunk``.
241
240
242 :convert.localtimezone: use local time (as determined by the TZ
241 :convert.localtimezone: use local time (as determined by the TZ
243 environment variable) for changeset date/times. The default
242 environment variable) for changeset date/times. The default
244 is False (use UTC).
243 is False (use UTC).
245
244
246 Source history can be retrieved starting at a specific revision,
245 Source history can be retrieved starting at a specific revision,
247 instead of being integrally converted. Only single branch
246 instead of being integrally converted. Only single branch
248 conversions are supported.
247 conversions are supported.
249
248
250 :convert.svn.startrev: specify start Subversion revision number.
249 :convert.svn.startrev: specify start Subversion revision number.
251 The default is 0.
250 The default is 0.
252
251
253 Perforce Source
252 Perforce Source
254 ###############
253 ###############
255
254
256 The Perforce (P4) importer can be given a p4 depot path or a
255 The Perforce (P4) importer can be given a p4 depot path or a
257 client specification as source. It will convert all files in the
256 client specification as source. It will convert all files in the
258 source to a flat Mercurial repository, ignoring labels, branches
257 source to a flat Mercurial repository, ignoring labels, branches
259 and integrations. Note that when a depot path is given you then
258 and integrations. Note that when a depot path is given you then
260 usually should specify a target directory, because otherwise the
259 usually should specify a target directory, because otherwise the
261 target may be named ``...-hg``.
260 target may be named ``...-hg``.
262
261
263 It is possible to limit the amount of source history to be
262 It is possible to limit the amount of source history to be
264 converted by specifying an initial Perforce revision:
263 converted by specifying an initial Perforce revision:
265
264
266 :convert.p4.startrev: specify initial Perforce revision (a
265 :convert.p4.startrev: specify initial Perforce revision (a
267 Perforce changelist number).
266 Perforce changelist number).
268
267
269 Mercurial Destination
268 Mercurial Destination
270 #####################
269 #####################
271
270
272 The following options are supported:
271 The following options are supported:
273
272
274 :convert.hg.clonebranches: dispatch source branches in separate
273 :convert.hg.clonebranches: dispatch source branches in separate
275 clones. The default is False.
274 clones. The default is False.
276
275
277 :convert.hg.tagsbranch: branch name for tag revisions, defaults to
276 :convert.hg.tagsbranch: branch name for tag revisions, defaults to
278 ``default``.
277 ``default``.
279
278
280 :convert.hg.usebranchnames: preserve branch names. The default is
279 :convert.hg.usebranchnames: preserve branch names. The default is
281 True.
280 True.
282 """
281 """
283 return convcmd.convert(ui, src, dest, revmapfile, **opts)
282 return convcmd.convert(ui, src, dest, revmapfile, **opts)
284
283
285 def debugsvnlog(ui, **opts):
284 def debugsvnlog(ui, **opts):
286 return subversion.debugsvnlog(ui, **opts)
285 return subversion.debugsvnlog(ui, **opts)
287
286
288 def debugcvsps(ui, *args, **opts):
287 def debugcvsps(ui, *args, **opts):
289 '''create changeset information from CVS
288 '''create changeset information from CVS
290
289
291 This command is intended as a debugging tool for the CVS to
290 This command is intended as a debugging tool for the CVS to
292 Mercurial converter, and can be used as a direct replacement for
291 Mercurial converter, and can be used as a direct replacement for
293 cvsps.
292 cvsps.
294
293
295 Hg debugcvsps reads the CVS rlog for current directory (or any
294 Hg debugcvsps reads the CVS rlog for current directory (or any
296 named directory) in the CVS repository, and converts the log to a
295 named directory) in the CVS repository, and converts the log to a
297 series of changesets based on matching commit log entries and
296 series of changesets based on matching commit log entries and
298 dates.'''
297 dates.'''
299 return cvsps.debugcvsps(ui, *args, **opts)
298 return cvsps.debugcvsps(ui, *args, **opts)
300
299
301 commands.norepo += " convert debugsvnlog debugcvsps"
300 commands.norepo += " convert debugsvnlog debugcvsps"
302
301
303 cmdtable = {
302 cmdtable = {
304 "convert":
303 "convert":
305 (convert,
304 (convert,
306 [('', 'authors', '',
305 [('', 'authors', '',
307 _('username mapping filename (DEPRECATED, use --authormap instead)'),
306 _('username mapping filename (DEPRECATED, use --authormap instead)'),
308 _('FILE')),
307 _('FILE')),
309 ('s', 'source-type', '',
308 ('s', 'source-type', '',
310 _('source repository type'), _('TYPE')),
309 _('source repository type'), _('TYPE')),
311 ('d', 'dest-type', '',
310 ('d', 'dest-type', '',
312 _('destination repository type'), _('TYPE')),
311 _('destination repository type'), _('TYPE')),
313 ('r', 'rev', '',
312 ('r', 'rev', '',
314 _('import up to source revision REV'), _('REV')),
313 _('import up to source revision REV'), _('REV')),
315 ('A', 'authormap', '',
314 ('A', 'authormap', '',
316 _('remap usernames using this file'), _('FILE')),
315 _('remap usernames using this file'), _('FILE')),
317 ('', 'filemap', '',
316 ('', 'filemap', '',
318 _('remap file names using contents of file'), _('FILE')),
317 _('remap file names using contents of file'), _('FILE')),
319 ('', 'splicemap', '',
318 ('', 'splicemap', '',
320 _('splice synthesized history into place'), _('FILE')),
319 _('splice synthesized history into place'), _('FILE')),
321 ('', 'branchmap', '',
320 ('', 'branchmap', '',
322 _('change branch names while converting'), _('FILE')),
321 _('change branch names while converting'), _('FILE')),
323 ('', 'branchsort', None, _('try to sort changesets by branches')),
322 ('', 'branchsort', None, _('try to sort changesets by branches')),
324 ('', 'datesort', None, _('try to sort changesets by date')),
323 ('', 'datesort', None, _('try to sort changesets by date')),
325 ('', 'sourcesort', None, _('preserve source changesets order')),
324 ('', 'sourcesort', None, _('preserve source changesets order')),
326 ('', 'closesort', None, _('try to reorder closed revisions'))],
325 ('', 'closesort', None, _('try to reorder closed revisions'))],
327 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
326 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
328 "debugsvnlog":
327 "debugsvnlog":
329 (debugsvnlog,
328 (debugsvnlog,
330 [],
329 [],
331 'hg debugsvnlog'),
330 'hg debugsvnlog'),
332 "debugcvsps":
331 "debugcvsps":
333 (debugcvsps,
332 (debugcvsps,
334 [
333 [
335 # Main options shared with cvsps-2.1
334 # Main options shared with cvsps-2.1
336 ('b', 'branches', [], _('only return changes on specified branches')),
335 ('b', 'branches', [], _('only return changes on specified branches')),
337 ('p', 'prefix', '', _('prefix to remove from file names')),
336 ('p', 'prefix', '', _('prefix to remove from file names')),
338 ('r', 'revisions', [],
337 ('r', 'revisions', [],
339 _('only return changes after or between specified tags')),
338 _('only return changes after or between specified tags')),
340 ('u', 'update-cache', None, _("update cvs log cache")),
339 ('u', 'update-cache', None, _("update cvs log cache")),
341 ('x', 'new-cache', None, _("create new cvs log cache")),
340 ('x', 'new-cache', None, _("create new cvs log cache")),
342 ('z', 'fuzz', 60, _('set commit time fuzz in seconds')),
341 ('z', 'fuzz', 60, _('set commit time fuzz in seconds')),
343 ('', 'root', '', _('specify cvsroot')),
342 ('', 'root', '', _('specify cvsroot')),
344 # Options specific to builtin cvsps
343 # Options specific to builtin cvsps
345 ('', 'parents', '', _('show parent changesets')),
344 ('', 'parents', '', _('show parent changesets')),
346 ('', 'ancestors', '',
345 ('', 'ancestors', '',
347 _('show current changeset in ancestor branches')),
346 _('show current changeset in ancestor branches')),
348 # Options that are ignored for compatibility with cvsps-2.1
347 # Options that are ignored for compatibility with cvsps-2.1
349 ('A', 'cvs-direct', None, _('ignored for compatibility')),
348 ('A', 'cvs-direct', None, _('ignored for compatibility')),
350 ],
349 ],
351 _('hg debugcvsps [OPTION]... [PATH]...')),
350 _('hg debugcvsps [OPTION]... [PATH]...')),
352 }
351 }
353
352
354 def kwconverted(ctx, name):
353 def kwconverted(ctx, name):
355 rev = ctx.extra().get('convert_revision', '')
354 rev = ctx.extra().get('convert_revision', '')
356 if rev.startswith('svn:'):
355 if rev.startswith('svn:'):
357 if name == 'svnrev':
356 if name == 'svnrev':
358 return str(subversion.revsplit(rev)[2])
357 return str(subversion.revsplit(rev)[2])
359 elif name == 'svnpath':
358 elif name == 'svnpath':
360 return subversion.revsplit(rev)[1]
359 return subversion.revsplit(rev)[1]
361 elif name == 'svnuuid':
360 elif name == 'svnuuid':
362 return subversion.revsplit(rev)[0]
361 return subversion.revsplit(rev)[0]
363 return rev
362 return rev
364
363
365 def kwsvnrev(repo, ctx, **args):
364 def kwsvnrev(repo, ctx, **args):
366 """:svnrev: String. Converted subversion revision number."""
365 """:svnrev: String. Converted subversion revision number."""
367 return kwconverted(ctx, 'svnrev')
366 return kwconverted(ctx, 'svnrev')
368
367
369 def kwsvnpath(repo, ctx, **args):
368 def kwsvnpath(repo, ctx, **args):
370 """:svnpath: String. Converted subversion revision project path."""
369 """:svnpath: String. Converted subversion revision project path."""
371 return kwconverted(ctx, 'svnpath')
370 return kwconverted(ctx, 'svnpath')
372
371
373 def kwsvnuuid(repo, ctx, **args):
372 def kwsvnuuid(repo, ctx, **args):
374 """:svnuuid: String. Converted subversion revision repository identifier."""
373 """:svnuuid: String. Converted subversion revision repository identifier."""
375 return kwconverted(ctx, 'svnuuid')
374 return kwconverted(ctx, 'svnuuid')
376
375
377 def extsetup(ui):
376 def extsetup(ui):
378 templatekw.keywords['svnrev'] = kwsvnrev
377 templatekw.keywords['svnrev'] = kwsvnrev
379 templatekw.keywords['svnpath'] = kwsvnpath
378 templatekw.keywords['svnpath'] = kwsvnpath
380 templatekw.keywords['svnuuid'] = kwsvnuuid
379 templatekw.keywords['svnuuid'] = kwsvnuuid
381
380
382 # tell hggettext to extract docstrings from these functions:
381 # tell hggettext to extract docstrings from these functions:
383 i18nfunctions = [kwsvnrev, kwsvnpath, kwsvnuuid]
382 i18nfunctions = [kwsvnrev, kwsvnpath, kwsvnuuid]
@@ -1,403 +1,417 b''
1 # hg.py - hg backend for convert extension
1 # hg.py - hg backend for convert extension
2 #
2 #
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 # Notes for hg->hg conversion:
8 # Notes for hg->hg conversion:
9 #
9 #
10 # * Old versions of Mercurial didn't trim the whitespace from the ends
10 # * Old versions of Mercurial didn't trim the whitespace from the ends
11 # of commit messages, but new versions do. Changesets created by
11 # of commit messages, but new versions do. Changesets created by
12 # those older versions, then converted, may thus have different
12 # those older versions, then converted, may thus have different
13 # hashes for changesets that are otherwise identical.
13 # hashes for changesets that are otherwise identical.
14 #
14 #
15 # * Using "--config convert.hg.saverev=true" will make the source
15 # * Using "--config convert.hg.saverev=true" will make the source
16 # identifier to be stored in the converted revision. This will cause
16 # identifier to be stored in the converted revision. This will cause
17 # the converted revision to have a different identity than the
17 # the converted revision to have a different identity than the
18 # source.
18 # source.
19
19
20
20
21 import os, time, cStringIO
21 import os, time, cStringIO
22 from mercurial.i18n import _
22 from mercurial.i18n import _
23 from mercurial.node import bin, hex, nullid
23 from mercurial.node import bin, hex, nullid
24 from mercurial import hg, util, context, bookmarks, error
24 from mercurial import hg, util, context, bookmarks, error, scmutil
25
25
26 from common import NoRepo, commit, converter_source, converter_sink
26 from common import NoRepo, commit, converter_source, converter_sink
27
27
28 class mercurial_sink(converter_sink):
28 class mercurial_sink(converter_sink):
29 def __init__(self, ui, path):
29 def __init__(self, ui, path):
30 converter_sink.__init__(self, ui, path)
30 converter_sink.__init__(self, ui, path)
31 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
31 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
32 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
32 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
33 self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
33 self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
34 self.lastbranch = None
34 self.lastbranch = None
35 if os.path.isdir(path) and len(os.listdir(path)) > 0:
35 if os.path.isdir(path) and len(os.listdir(path)) > 0:
36 try:
36 try:
37 self.repo = hg.repository(self.ui, path)
37 self.repo = hg.repository(self.ui, path)
38 if not self.repo.local():
38 if not self.repo.local():
39 raise NoRepo(_('%s is not a local Mercurial repository')
39 raise NoRepo(_('%s is not a local Mercurial repository')
40 % path)
40 % path)
41 except error.RepoError, err:
41 except error.RepoError, err:
42 ui.traceback()
42 ui.traceback()
43 raise NoRepo(err.args[0])
43 raise NoRepo(err.args[0])
44 else:
44 else:
45 try:
45 try:
46 ui.status(_('initializing destination %s repository\n') % path)
46 ui.status(_('initializing destination %s repository\n') % path)
47 self.repo = hg.repository(self.ui, path, create=True)
47 self.repo = hg.repository(self.ui, path, create=True)
48 if not self.repo.local():
48 if not self.repo.local():
49 raise NoRepo(_('%s is not a local Mercurial repository')
49 raise NoRepo(_('%s is not a local Mercurial repository')
50 % path)
50 % path)
51 self.created.append(path)
51 self.created.append(path)
52 except error.RepoError:
52 except error.RepoError:
53 ui.traceback()
53 ui.traceback()
54 raise NoRepo(_("could not create hg repository %s as sink")
54 raise NoRepo(_("could not create hg repository %s as sink")
55 % path)
55 % path)
56 self.lock = None
56 self.lock = None
57 self.wlock = None
57 self.wlock = None
58 self.filemapmode = False
58 self.filemapmode = False
59
59
60 def before(self):
60 def before(self):
61 self.ui.debug('run hg sink pre-conversion action\n')
61 self.ui.debug('run hg sink pre-conversion action\n')
62 self.wlock = self.repo.wlock()
62 self.wlock = self.repo.wlock()
63 self.lock = self.repo.lock()
63 self.lock = self.repo.lock()
64
64
65 def after(self):
65 def after(self):
66 self.ui.debug('run hg sink post-conversion action\n')
66 self.ui.debug('run hg sink post-conversion action\n')
67 if self.lock:
67 if self.lock:
68 self.lock.release()
68 self.lock.release()
69 if self.wlock:
69 if self.wlock:
70 self.wlock.release()
70 self.wlock.release()
71
71
72 def revmapfile(self):
72 def revmapfile(self):
73 return self.repo.join("shamap")
73 return self.repo.join("shamap")
74
74
75 def authorfile(self):
75 def authorfile(self):
76 return self.repo.join("authormap")
76 return self.repo.join("authormap")
77
77
78 def getheads(self):
78 def getheads(self):
79 h = self.repo.changelog.heads()
79 h = self.repo.changelog.heads()
80 return [hex(x) for x in h]
80 return [hex(x) for x in h]
81
81
82 def setbranch(self, branch, pbranches):
82 def setbranch(self, branch, pbranches):
83 if not self.clonebranches:
83 if not self.clonebranches:
84 return
84 return
85
85
86 setbranch = (branch != self.lastbranch)
86 setbranch = (branch != self.lastbranch)
87 self.lastbranch = branch
87 self.lastbranch = branch
88 if not branch:
88 if not branch:
89 branch = 'default'
89 branch = 'default'
90 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
90 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
91 pbranch = pbranches and pbranches[0][1] or 'default'
91 pbranch = pbranches and pbranches[0][1] or 'default'
92
92
93 branchpath = os.path.join(self.path, branch)
93 branchpath = os.path.join(self.path, branch)
94 if setbranch:
94 if setbranch:
95 self.after()
95 self.after()
96 try:
96 try:
97 self.repo = hg.repository(self.ui, branchpath)
97 self.repo = hg.repository(self.ui, branchpath)
98 except Exception:
98 except Exception:
99 self.repo = hg.repository(self.ui, branchpath, create=True)
99 self.repo = hg.repository(self.ui, branchpath, create=True)
100 self.before()
100 self.before()
101
101
102 # pbranches may bring revisions from other branches (merge parents)
102 # pbranches may bring revisions from other branches (merge parents)
103 # Make sure we have them, or pull them.
103 # Make sure we have them, or pull them.
104 missings = {}
104 missings = {}
105 for b in pbranches:
105 for b in pbranches:
106 try:
106 try:
107 self.repo.lookup(b[0])
107 self.repo.lookup(b[0])
108 except Exception:
108 except Exception:
109 missings.setdefault(b[1], []).append(b[0])
109 missings.setdefault(b[1], []).append(b[0])
110
110
111 if missings:
111 if missings:
112 self.after()
112 self.after()
113 for pbranch, heads in sorted(missings.iteritems()):
113 for pbranch, heads in sorted(missings.iteritems()):
114 pbranchpath = os.path.join(self.path, pbranch)
114 pbranchpath = os.path.join(self.path, pbranch)
115 prepo = hg.peer(self.ui, {}, pbranchpath)
115 prepo = hg.peer(self.ui, {}, pbranchpath)
116 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
116 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
117 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
117 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
118 self.before()
118 self.before()
119
119
120 def _rewritetags(self, source, revmap, data):
120 def _rewritetags(self, source, revmap, data):
121 fp = cStringIO.StringIO()
121 fp = cStringIO.StringIO()
122 for line in data.splitlines():
122 for line in data.splitlines():
123 s = line.split(' ', 1)
123 s = line.split(' ', 1)
124 if len(s) != 2:
124 if len(s) != 2:
125 continue
125 continue
126 revid = revmap.get(source.lookuprev(s[0]))
126 revid = revmap.get(source.lookuprev(s[0]))
127 if not revid:
127 if not revid:
128 continue
128 continue
129 fp.write('%s %s\n' % (revid, s[1]))
129 fp.write('%s %s\n' % (revid, s[1]))
130 return fp.getvalue()
130 return fp.getvalue()
131
131
132 def putcommit(self, files, copies, parents, commit, source, revmap):
132 def putcommit(self, files, copies, parents, commit, source, revmap):
133
133
134 files = dict(files)
134 files = dict(files)
135 def getfilectx(repo, memctx, f):
135 def getfilectx(repo, memctx, f):
136 v = files[f]
136 v = files[f]
137 data, mode = source.getfile(f, v)
137 data, mode = source.getfile(f, v)
138 if f == '.hgtags':
138 if f == '.hgtags':
139 data = self._rewritetags(source, revmap, data)
139 data = self._rewritetags(source, revmap, data)
140 return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
140 return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
141 copies.get(f))
141 copies.get(f))
142
142
143 pl = []
143 pl = []
144 for p in parents:
144 for p in parents:
145 if p not in pl:
145 if p not in pl:
146 pl.append(p)
146 pl.append(p)
147 parents = pl
147 parents = pl
148 nparents = len(parents)
148 nparents = len(parents)
149 if self.filemapmode and nparents == 1:
149 if self.filemapmode and nparents == 1:
150 m1node = self.repo.changelog.read(bin(parents[0]))[0]
150 m1node = self.repo.changelog.read(bin(parents[0]))[0]
151 parent = parents[0]
151 parent = parents[0]
152
152
153 if len(parents) < 2:
153 if len(parents) < 2:
154 parents.append(nullid)
154 parents.append(nullid)
155 if len(parents) < 2:
155 if len(parents) < 2:
156 parents.append(nullid)
156 parents.append(nullid)
157 p2 = parents.pop(0)
157 p2 = parents.pop(0)
158
158
159 text = commit.desc
159 text = commit.desc
160 extra = commit.extra.copy()
160 extra = commit.extra.copy()
161 if self.branchnames and commit.branch:
161 if self.branchnames and commit.branch:
162 extra['branch'] = commit.branch
162 extra['branch'] = commit.branch
163 if commit.rev:
163 if commit.rev:
164 extra['convert_revision'] = commit.rev
164 extra['convert_revision'] = commit.rev
165
165
166 while parents:
166 while parents:
167 p1 = p2
167 p1 = p2
168 p2 = parents.pop(0)
168 p2 = parents.pop(0)
169 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(),
169 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(),
170 getfilectx, commit.author, commit.date, extra)
170 getfilectx, commit.author, commit.date, extra)
171 self.repo.commitctx(ctx)
171 self.repo.commitctx(ctx)
172 text = "(octopus merge fixup)\n"
172 text = "(octopus merge fixup)\n"
173 p2 = hex(self.repo.changelog.tip())
173 p2 = hex(self.repo.changelog.tip())
174
174
175 if self.filemapmode and nparents == 1:
175 if self.filemapmode and nparents == 1:
176 man = self.repo.manifest
176 man = self.repo.manifest
177 mnode = self.repo.changelog.read(bin(p2))[0]
177 mnode = self.repo.changelog.read(bin(p2))[0]
178 closed = 'close' in commit.extra
178 closed = 'close' in commit.extra
179 if not closed and not man.cmp(m1node, man.revision(mnode)):
179 if not closed and not man.cmp(m1node, man.revision(mnode)):
180 self.ui.status(_("filtering out empty revision\n"))
180 self.ui.status(_("filtering out empty revision\n"))
181 self.repo.rollback(force=True)
181 self.repo.rollback(force=True)
182 return parent
182 return parent
183 return p2
183 return p2
184
184
185 def puttags(self, tags):
185 def puttags(self, tags):
186 try:
186 try:
187 parentctx = self.repo[self.tagsbranch]
187 parentctx = self.repo[self.tagsbranch]
188 tagparent = parentctx.node()
188 tagparent = parentctx.node()
189 except error.RepoError:
189 except error.RepoError:
190 parentctx = None
190 parentctx = None
191 tagparent = nullid
191 tagparent = nullid
192
192
193 try:
193 try:
194 oldlines = sorted(parentctx['.hgtags'].data().splitlines(True))
194 oldlines = sorted(parentctx['.hgtags'].data().splitlines(True))
195 except Exception:
195 except Exception:
196 oldlines = []
196 oldlines = []
197
197
198 newlines = sorted([("%s %s\n" % (tags[tag], tag)) for tag in tags])
198 newlines = sorted([("%s %s\n" % (tags[tag], tag)) for tag in tags])
199 if newlines == oldlines:
199 if newlines == oldlines:
200 return None, None
200 return None, None
201 data = "".join(newlines)
201 data = "".join(newlines)
202 def getfilectx(repo, memctx, f):
202 def getfilectx(repo, memctx, f):
203 return context.memfilectx(f, data, False, False, None)
203 return context.memfilectx(f, data, False, False, None)
204
204
205 self.ui.status(_("updating tags\n"))
205 self.ui.status(_("updating tags\n"))
206 date = "%s 0" % int(time.mktime(time.gmtime()))
206 date = "%s 0" % int(time.mktime(time.gmtime()))
207 extra = {'branch': self.tagsbranch}
207 extra = {'branch': self.tagsbranch}
208 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
208 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
209 [".hgtags"], getfilectx, "convert-repo", date,
209 [".hgtags"], getfilectx, "convert-repo", date,
210 extra)
210 extra)
211 self.repo.commitctx(ctx)
211 self.repo.commitctx(ctx)
212 return hex(self.repo.changelog.tip()), hex(tagparent)
212 return hex(self.repo.changelog.tip()), hex(tagparent)
213
213
214 def setfilemapmode(self, active):
214 def setfilemapmode(self, active):
215 self.filemapmode = active
215 self.filemapmode = active
216
216
217 def putbookmarks(self, updatedbookmark):
217 def putbookmarks(self, updatedbookmark):
218 if not len(updatedbookmark):
218 if not len(updatedbookmark):
219 return
219 return
220
220
221 self.ui.status(_("updating bookmarks\n"))
221 self.ui.status(_("updating bookmarks\n"))
222 destmarks = self.repo._bookmarks
222 destmarks = self.repo._bookmarks
223 for bookmark in updatedbookmark:
223 for bookmark in updatedbookmark:
224 destmarks[bookmark] = bin(updatedbookmark[bookmark])
224 destmarks[bookmark] = bin(updatedbookmark[bookmark])
225 destmarks.write()
225 destmarks.write()
226
226
227 def hascommit(self, rev):
227 def hascommit(self, rev):
228 if rev not in self.repo and self.clonebranches:
228 if rev not in self.repo and self.clonebranches:
229 raise util.Abort(_('revision %s not found in destination '
229 raise util.Abort(_('revision %s not found in destination '
230 'repository (lookups with clonebranches=true '
230 'repository (lookups with clonebranches=true '
231 'are not implemented)') % rev)
231 'are not implemented)') % rev)
232 return rev in self.repo
232 return rev in self.repo
233
233
234 class mercurial_source(converter_source):
234 class mercurial_source(converter_source):
235 def __init__(self, ui, path, rev=None):
235 def __init__(self, ui, path, rev=None):
236 converter_source.__init__(self, ui, path, rev)
236 converter_source.__init__(self, ui, path, rev)
237 self.ignoreerrors = ui.configbool('convert', 'hg.ignoreerrors', False)
237 self.ignoreerrors = ui.configbool('convert', 'hg.ignoreerrors', False)
238 self.ignored = set()
238 self.ignored = set()
239 self.saverev = ui.configbool('convert', 'hg.saverev', False)
239 self.saverev = ui.configbool('convert', 'hg.saverev', False)
240 try:
240 try:
241 self.repo = hg.repository(self.ui, path)
241 self.repo = hg.repository(self.ui, path)
242 # try to provoke an exception if this isn't really a hg
242 # try to provoke an exception if this isn't really a hg
243 # repo, but some other bogus compatible-looking url
243 # repo, but some other bogus compatible-looking url
244 if not self.repo.local():
244 if not self.repo.local():
245 raise error.RepoError
245 raise error.RepoError
246 except error.RepoError:
246 except error.RepoError:
247 ui.traceback()
247 ui.traceback()
248 raise NoRepo(_("%s is not a local Mercurial repository") % path)
248 raise NoRepo(_("%s is not a local Mercurial repository") % path)
249 self.lastrev = None
249 self.lastrev = None
250 self.lastctx = None
250 self.lastctx = None
251 self._changescache = None
251 self._changescache = None
252 self.convertfp = None
252 self.convertfp = None
253 # Restrict converted revisions to startrev descendants
253 # Restrict converted revisions to startrev descendants
254 startnode = ui.config('convert', 'hg.startrev')
254 startnode = ui.config('convert', 'hg.startrev')
255 if startnode is not None:
255 hgrevs = ui.config('convert', 'hg.revs')
256 try:
256 if hgrevs is None:
257 startnode = self.repo.lookup(startnode)
257 if startnode is not None:
258 except error.RepoError:
258 try:
259 raise util.Abort(_('%s is not a valid start revision')
259 startnode = self.repo.lookup(startnode)
260 % startnode)
260 except error.RepoError:
261 startrev = self.repo.changelog.rev(startnode)
261 raise util.Abort(_('%s is not a valid start revision')
262 children = {startnode: 1}
262 % startnode)
263 for r in self.repo.changelog.descendants([startrev]):
263 startrev = self.repo.changelog.rev(startnode)
264 children[self.repo.changelog.node(r)] = 1
264 children = {startnode: 1}
265 self.keep = children.__contains__
265 for r in self.repo.changelog.descendants([startrev]):
266 children[self.repo.changelog.node(r)] = 1
267 self.keep = children.__contains__
268 else:
269 self.keep = util.always
270 if rev:
271 self._heads = [self.repo[rev].node()]
272 else:
273 self._heads = self.repo.heads()
266 else:
274 else:
267 self.keep = util.always
275 if rev or startnode is not None:
268 if rev:
276 raise util.Abort(_('hg.revs cannot be combined with '
269 self._heads = [self.repo[rev].node()]
277 'hg.startrev or --rev'))
270 else:
278 nodes = set()
271 self._heads = self.repo.heads()
279 parents = set()
280 for r in scmutil.revrange(self.repo, [hgrevs]):
281 ctx = self.repo[r]
282 nodes.add(ctx.node())
283 parents.update(p.node() for p in ctx.parents())
284 self.keep = nodes.__contains__
285 self._heads = nodes - parents
272
286
273 def changectx(self, rev):
287 def changectx(self, rev):
274 if self.lastrev != rev:
288 if self.lastrev != rev:
275 self.lastctx = self.repo[rev]
289 self.lastctx = self.repo[rev]
276 self.lastrev = rev
290 self.lastrev = rev
277 return self.lastctx
291 return self.lastctx
278
292
279 def parents(self, ctx):
293 def parents(self, ctx):
280 return [p for p in ctx.parents() if p and self.keep(p.node())]
294 return [p for p in ctx.parents() if p and self.keep(p.node())]
281
295
282 def getheads(self):
296 def getheads(self):
283 return [hex(h) for h in self._heads if self.keep(h)]
297 return [hex(h) for h in self._heads if self.keep(h)]
284
298
285 def getfile(self, name, rev):
299 def getfile(self, name, rev):
286 try:
300 try:
287 fctx = self.changectx(rev)[name]
301 fctx = self.changectx(rev)[name]
288 return fctx.data(), fctx.flags()
302 return fctx.data(), fctx.flags()
289 except error.LookupError, err:
303 except error.LookupError, err:
290 raise IOError(err)
304 raise IOError(err)
291
305
292 def getchanges(self, rev):
306 def getchanges(self, rev):
293 ctx = self.changectx(rev)
307 ctx = self.changectx(rev)
294 parents = self.parents(ctx)
308 parents = self.parents(ctx)
295 if not parents:
309 if not parents:
296 files = sorted(ctx.manifest())
310 files = sorted(ctx.manifest())
297 # getcopies() is not needed for roots, but it is a simple way to
311 # getcopies() is not needed for roots, but it is a simple way to
298 # detect missing revlogs and abort on errors or populate
312 # detect missing revlogs and abort on errors or populate
299 # self.ignored
313 # self.ignored
300 self.getcopies(ctx, parents, files)
314 self.getcopies(ctx, parents, files)
301 return [(f, rev) for f in files if f not in self.ignored], {}
315 return [(f, rev) for f in files if f not in self.ignored], {}
302 if self._changescache and self._changescache[0] == rev:
316 if self._changescache and self._changescache[0] == rev:
303 m, a, r = self._changescache[1]
317 m, a, r = self._changescache[1]
304 else:
318 else:
305 m, a, r = self.repo.status(parents[0].node(), ctx.node())[:3]
319 m, a, r = self.repo.status(parents[0].node(), ctx.node())[:3]
306 # getcopies() detects missing revlogs early, run it before
320 # getcopies() detects missing revlogs early, run it before
307 # filtering the changes.
321 # filtering the changes.
308 copies = self.getcopies(ctx, parents, m + a)
322 copies = self.getcopies(ctx, parents, m + a)
309 changes = [(name, rev) for name in m + a + r
323 changes = [(name, rev) for name in m + a + r
310 if name not in self.ignored]
324 if name not in self.ignored]
311 return sorted(changes), copies
325 return sorted(changes), copies
312
326
313 def getcopies(self, ctx, parents, files):
327 def getcopies(self, ctx, parents, files):
314 copies = {}
328 copies = {}
315 for name in files:
329 for name in files:
316 if name in self.ignored:
330 if name in self.ignored:
317 continue
331 continue
318 try:
332 try:
319 copysource, _copynode = ctx.filectx(name).renamed()
333 copysource, _copynode = ctx.filectx(name).renamed()
320 if copysource in self.ignored:
334 if copysource in self.ignored:
321 continue
335 continue
322 # Ignore copy sources not in parent revisions
336 # Ignore copy sources not in parent revisions
323 found = False
337 found = False
324 for p in parents:
338 for p in parents:
325 if copysource in p:
339 if copysource in p:
326 found = True
340 found = True
327 break
341 break
328 if not found:
342 if not found:
329 continue
343 continue
330 copies[name] = copysource
344 copies[name] = copysource
331 except TypeError:
345 except TypeError:
332 pass
346 pass
333 except error.LookupError, e:
347 except error.LookupError, e:
334 if not self.ignoreerrors:
348 if not self.ignoreerrors:
335 raise
349 raise
336 self.ignored.add(name)
350 self.ignored.add(name)
337 self.ui.warn(_('ignoring: %s\n') % e)
351 self.ui.warn(_('ignoring: %s\n') % e)
338 return copies
352 return copies
339
353
340 def getcommit(self, rev):
354 def getcommit(self, rev):
341 ctx = self.changectx(rev)
355 ctx = self.changectx(rev)
342 parents = [p.hex() for p in self.parents(ctx)]
356 parents = [p.hex() for p in self.parents(ctx)]
343 if self.saverev:
357 if self.saverev:
344 crev = rev
358 crev = rev
345 else:
359 else:
346 crev = None
360 crev = None
347 return commit(author=ctx.user(),
361 return commit(author=ctx.user(),
348 date=util.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'),
362 date=util.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'),
349 desc=ctx.description(), rev=crev, parents=parents,
363 desc=ctx.description(), rev=crev, parents=parents,
350 branch=ctx.branch(), extra=ctx.extra(),
364 branch=ctx.branch(), extra=ctx.extra(),
351 sortkey=ctx.rev())
365 sortkey=ctx.rev())
352
366
353 def gettags(self):
367 def gettags(self):
354 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
368 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
355 return dict([(name, hex(node)) for name, node in tags
369 return dict([(name, hex(node)) for name, node in tags
356 if self.keep(node)])
370 if self.keep(node)])
357
371
358 def getchangedfiles(self, rev, i):
372 def getchangedfiles(self, rev, i):
359 ctx = self.changectx(rev)
373 ctx = self.changectx(rev)
360 parents = self.parents(ctx)
374 parents = self.parents(ctx)
361 if not parents and i is None:
375 if not parents and i is None:
362 i = 0
376 i = 0
363 changes = [], ctx.manifest().keys(), []
377 changes = [], ctx.manifest().keys(), []
364 else:
378 else:
365 i = i or 0
379 i = i or 0
366 changes = self.repo.status(parents[i].node(), ctx.node())[:3]
380 changes = self.repo.status(parents[i].node(), ctx.node())[:3]
367 changes = [[f for f in l if f not in self.ignored] for l in changes]
381 changes = [[f for f in l if f not in self.ignored] for l in changes]
368
382
369 if i == 0:
383 if i == 0:
370 self._changescache = (rev, changes)
384 self._changescache = (rev, changes)
371
385
372 return changes[0] + changes[1] + changes[2]
386 return changes[0] + changes[1] + changes[2]
373
387
374 def converted(self, rev, destrev):
388 def converted(self, rev, destrev):
375 if self.convertfp is None:
389 if self.convertfp is None:
376 self.convertfp = open(self.repo.join('shamap'), 'a')
390 self.convertfp = open(self.repo.join('shamap'), 'a')
377 self.convertfp.write('%s %s\n' % (destrev, rev))
391 self.convertfp.write('%s %s\n' % (destrev, rev))
378 self.convertfp.flush()
392 self.convertfp.flush()
379
393
380 def before(self):
394 def before(self):
381 self.ui.debug('run hg source pre-conversion action\n')
395 self.ui.debug('run hg source pre-conversion action\n')
382
396
383 def after(self):
397 def after(self):
384 self.ui.debug('run hg source post-conversion action\n')
398 self.ui.debug('run hg source post-conversion action\n')
385
399
386 def hasnativeorder(self):
400 def hasnativeorder(self):
387 return True
401 return True
388
402
389 def hasnativeclose(self):
403 def hasnativeclose(self):
390 return True
404 return True
391
405
392 def lookuprev(self, rev):
406 def lookuprev(self, rev):
393 try:
407 try:
394 return hex(self.repo.lookup(rev))
408 return hex(self.repo.lookup(rev))
395 except error.RepoError:
409 except error.RepoError:
396 return None
410 return None
397
411
398 def getbookmarks(self):
412 def getbookmarks(self):
399 return bookmarks.listbookmarks(self.repo)
413 return bookmarks.listbookmarks(self.repo)
400
414
401 def checkrevformat(self, revstr):
415 def checkrevformat(self, revstr):
402 """ Mercurial, revision string is a 40 byte hex """
416 """ Mercurial, revision string is a 40 byte hex """
403 self.checkhexformat(revstr)
417 self.checkhexformat(revstr)
@@ -1,185 +1,205 b''
1
1
2 $ cat >> $HGRCPATH <<EOF
2 $ cat >> $HGRCPATH <<EOF
3 > [extensions]
3 > [extensions]
4 > graphlog =
4 > graphlog =
5 > convert =
5 > convert =
6 > [convert]
6 > [convert]
7 > hg.saverev = yes
7 > hg.saverev = yes
8 > EOF
8 > EOF
9
9
10 $ glog()
10 $ glog()
11 > {
11 > {
12 > hg -R "$1" glog --template '{rev} "{desc}" files: {files}\n'
12 > hg -R "$1" glog --template '{rev} "{desc}" files: {files}\n'
13 > }
13 > }
14
14
15 $ hg init source
15 $ hg init source
16 $ cd source
16 $ cd source
17
17
18 $ echo a > a
18 $ echo a > a
19 $ echo b > b
19 $ echo b > b
20 $ echo f > f
20 $ echo f > f
21 $ hg ci -d '0 0' -qAm '0: add a b f'
21 $ hg ci -d '0 0' -qAm '0: add a b f'
22 $ echo c > c
22 $ echo c > c
23 $ hg move f d
23 $ hg move f d
24 $ hg ci -d '1 0' -qAm '1: add c, move f to d'
24 $ hg ci -d '1 0' -qAm '1: add c, move f to d'
25 $ hg copy a e
25 $ hg copy a e
26 $ echo b >> b
26 $ echo b >> b
27 $ hg ci -d '2 0' -qAm '2: copy e from a, change b'
27 $ hg ci -d '2 0' -qAm '2: copy e from a, change b'
28 $ hg up -C 0
28 $ hg up -C 0
29 2 files updated, 0 files merged, 3 files removed, 0 files unresolved
29 2 files updated, 0 files merged, 3 files removed, 0 files unresolved
30 $ echo a >> a
30 $ echo a >> a
31 $ hg ci -d '3 0' -qAm '3: change a'
31 $ hg ci -d '3 0' -qAm '3: change a'
32 $ hg merge
32 $ hg merge
33 merging a and e to e
33 merging a and e to e
34 3 files updated, 1 files merged, 1 files removed, 0 files unresolved
34 3 files updated, 1 files merged, 1 files removed, 0 files unresolved
35 (branch merge, don't forget to commit)
35 (branch merge, don't forget to commit)
36 $ hg ci -d '4 0' -qAm '4: merge 2 and 3'
36 $ hg ci -d '4 0' -qAm '4: merge 2 and 3'
37 $ echo a >> a
37 $ echo a >> a
38 $ hg ci -d '5 0' -qAm '5: change a'
38 $ hg ci -d '5 0' -qAm '5: change a'
39 $ cd ..
39 $ cd ..
40
40
41 Convert from null revision
41 Convert from null revision
42
42
43 $ hg convert --config convert.hg.startrev=null source full
43 $ hg convert --config convert.hg.startrev=null source full
44 initializing destination full repository
44 initializing destination full repository
45 scanning source...
45 scanning source...
46 sorting...
46 sorting...
47 converting...
47 converting...
48 5 0: add a b f
48 5 0: add a b f
49 4 1: add c, move f to d
49 4 1: add c, move f to d
50 3 2: copy e from a, change b
50 3 2: copy e from a, change b
51 2 3: change a
51 2 3: change a
52 1 4: merge 2 and 3
52 1 4: merge 2 and 3
53 0 5: change a
53 0 5: change a
54
54
55 $ glog full
55 $ glog full
56 o 5 "5: change a" files: a
56 o 5 "5: change a" files: a
57 |
57 |
58 o 4 "4: merge 2 and 3" files: e f
58 o 4 "4: merge 2 and 3" files: e f
59 |\
59 |\
60 | o 3 "3: change a" files: a
60 | o 3 "3: change a" files: a
61 | |
61 | |
62 o | 2 "2: copy e from a, change b" files: b e
62 o | 2 "2: copy e from a, change b" files: b e
63 | |
63 | |
64 o | 1 "1: add c, move f to d" files: c d f
64 o | 1 "1: add c, move f to d" files: c d f
65 |/
65 |/
66 o 0 "0: add a b f" files: a b f
66 o 0 "0: add a b f" files: a b f
67
67
68 $ rm -Rf full
68 $ rm -Rf full
69
69
70 Convert from zero revision
70 Convert from zero revision
71
71
72 $ hg convert --config convert.hg.startrev=0 source full
72 $ hg convert --config convert.hg.startrev=0 source full
73 initializing destination full repository
73 initializing destination full repository
74 scanning source...
74 scanning source...
75 sorting...
75 sorting...
76 converting...
76 converting...
77 5 0: add a b f
77 5 0: add a b f
78 4 1: add c, move f to d
78 4 1: add c, move f to d
79 3 2: copy e from a, change b
79 3 2: copy e from a, change b
80 2 3: change a
80 2 3: change a
81 1 4: merge 2 and 3
81 1 4: merge 2 and 3
82 0 5: change a
82 0 5: change a
83
83
84 $ glog full
84 $ glog full
85 o 5 "5: change a" files: a
85 o 5 "5: change a" files: a
86 |
86 |
87 o 4 "4: merge 2 and 3" files: e f
87 o 4 "4: merge 2 and 3" files: e f
88 |\
88 |\
89 | o 3 "3: change a" files: a
89 | o 3 "3: change a" files: a
90 | |
90 | |
91 o | 2 "2: copy e from a, change b" files: b e
91 o | 2 "2: copy e from a, change b" files: b e
92 | |
92 | |
93 o | 1 "1: add c, move f to d" files: c d f
93 o | 1 "1: add c, move f to d" files: c d f
94 |/
94 |/
95 o 0 "0: add a b f" files: a b f
95 o 0 "0: add a b f" files: a b f
96
96
97 Convert from merge parent
97 Convert from merge parent
98
98
99 $ hg convert --config convert.hg.startrev=1 source conv1
99 $ hg convert --config convert.hg.startrev=1 source conv1
100 initializing destination conv1 repository
100 initializing destination conv1 repository
101 scanning source...
101 scanning source...
102 sorting...
102 sorting...
103 converting...
103 converting...
104 3 1: add c, move f to d
104 3 1: add c, move f to d
105 2 2: copy e from a, change b
105 2 2: copy e from a, change b
106 1 4: merge 2 and 3
106 1 4: merge 2 and 3
107 0 5: change a
107 0 5: change a
108
108
109 $ glog conv1
109 $ glog conv1
110 o 3 "5: change a" files: a
110 o 3 "5: change a" files: a
111 |
111 |
112 o 2 "4: merge 2 and 3" files: a e
112 o 2 "4: merge 2 and 3" files: a e
113 |
113 |
114 o 1 "2: copy e from a, change b" files: b e
114 o 1 "2: copy e from a, change b" files: b e
115 |
115 |
116 o 0 "1: add c, move f to d" files: a b c d
116 o 0 "1: add c, move f to d" files: a b c d
117
117
118 $ cd conv1
118 $ cd conv1
119 $ hg up -q
119 $ hg up -q
120
120
121 Check copy preservation
121 Check copy preservation
122
122
123 $ hg st -C --change 2 e
123 $ hg st -C --change 2 e
124 M e
124 M e
125 $ hg st -C --change 1 e
125 $ hg st -C --change 1 e
126 A e
126 A e
127 a
127 a
128 $ hg st -C --change 0 a
128 $ hg st -C --change 0 a
129 A a
129 A a
130
130
131 (It seems like a bug in log that the following doesn't show rev 1.)
131 (It seems like a bug in log that the following doesn't show rev 1.)
132
132
133 $ hg log --follow --copies e
133 $ hg log --follow --copies e
134 changeset: 2:82bbac3d2cf4
134 changeset: 2:82bbac3d2cf4
135 user: test
135 user: test
136 date: Thu Jan 01 00:00:04 1970 +0000
136 date: Thu Jan 01 00:00:04 1970 +0000
137 summary: 4: merge 2 and 3
137 summary: 4: merge 2 and 3
138
138
139 changeset: 0:23c3be426dce
139 changeset: 0:23c3be426dce
140 user: test
140 user: test
141 date: Thu Jan 01 00:00:01 1970 +0000
141 date: Thu Jan 01 00:00:01 1970 +0000
142 summary: 1: add c, move f to d
142 summary: 1: add c, move f to d
143
143
144 Check copy removal on missing parent
144 Check copy removal on missing parent
145
145
146 $ hg log --follow --copies d
146 $ hg log --follow --copies d
147 changeset: 0:23c3be426dce
147 changeset: 0:23c3be426dce
148 user: test
148 user: test
149 date: Thu Jan 01 00:00:01 1970 +0000
149 date: Thu Jan 01 00:00:01 1970 +0000
150 summary: 1: add c, move f to d
150 summary: 1: add c, move f to d
151
151
152 $ hg cat -r tip a b
152 $ hg cat -r tip a b
153 a
153 a
154 a
154 a
155 a
155 a
156 b
156 b
157 b
157 b
158 $ hg -q verify
158 $ hg -q verify
159 $ cd ..
159 $ cd ..
160
160
161 Convert from merge
161 Convert from merge
162
162
163 $ hg convert --config convert.hg.startrev=4 source conv4
163 $ hg convert --config convert.hg.startrev=4 source conv4
164 initializing destination conv4 repository
164 initializing destination conv4 repository
165 scanning source...
165 scanning source...
166 sorting...
166 sorting...
167 converting...
167 converting...
168 1 4: merge 2 and 3
168 1 4: merge 2 and 3
169 0 5: change a
169 0 5: change a
170 $ glog conv4
170 $ glog conv4
171 o 1 "5: change a" files: a
171 o 1 "5: change a" files: a
172 |
172 |
173 o 0 "4: merge 2 and 3" files: a b c d e
173 o 0 "4: merge 2 and 3" files: a b c d e
174
174
175 $ cd conv4
175 $ cd conv4
176 $ hg up -C
176 $ hg up -C
177 5 files updated, 0 files merged, 0 files removed, 0 files unresolved
177 5 files updated, 0 files merged, 0 files removed, 0 files unresolved
178 $ hg cat -r tip a b
178 $ hg cat -r tip a b
179 a
179 a
180 a
180 a
181 a
181 a
182 b
182 b
183 b
183 b
184 $ hg -q verify
184 $ hg -q verify
185 $ cd ..
185 $ cd ..
186
187 Convert from revset in convert.hg.revs
188
189 $ hg convert --config convert.hg.revs='3:4+0' source revsetrepo
190 initializing destination revsetrepo repository
191 scanning source...
192 sorting...
193 converting...
194 2 0: add a b f
195 1 3: change a
196 0 4: merge 2 and 3
197
198 $ glog revsetrepo
199 o 2 "4: merge 2 and 3" files: b c d e f
200 |
201 o 1 "3: change a" files: a
202 |
203 o 0 "0: add a b f" files: a b f
204
205 $ cd ..
@@ -1,458 +1,457 b''
1 $ cat >> $HGRCPATH <<EOF
1 $ cat >> $HGRCPATH <<EOF
2 > [extensions]
2 > [extensions]
3 > convert=
3 > convert=
4 > [convert]
4 > [convert]
5 > hg.saverev=False
5 > hg.saverev=False
6 > EOF
6 > EOF
7 $ hg help convert
7 $ hg help convert
8 hg convert [OPTION]... SOURCE [DEST [REVMAP]]
8 hg convert [OPTION]... SOURCE [DEST [REVMAP]]
9
9
10 convert a foreign SCM repository to a Mercurial one.
10 convert a foreign SCM repository to a Mercurial one.
11
11
12 Accepted source formats [identifiers]:
12 Accepted source formats [identifiers]:
13
13
14 - Mercurial [hg]
14 - Mercurial [hg]
15 - CVS [cvs]
15 - CVS [cvs]
16 - Darcs [darcs]
16 - Darcs [darcs]
17 - git [git]
17 - git [git]
18 - Subversion [svn]
18 - Subversion [svn]
19 - Monotone [mtn]
19 - Monotone [mtn]
20 - GNU Arch [gnuarch]
20 - GNU Arch [gnuarch]
21 - Bazaar [bzr]
21 - Bazaar [bzr]
22 - Perforce [p4]
22 - Perforce [p4]
23
23
24 Accepted destination formats [identifiers]:
24 Accepted destination formats [identifiers]:
25
25
26 - Mercurial [hg]
26 - Mercurial [hg]
27 - Subversion [svn] (history on branches is not preserved)
27 - Subversion [svn] (history on branches is not preserved)
28
28
29 If no revision is given, all revisions will be converted. Otherwise,
29 If no revision is given, all revisions will be converted. Otherwise,
30 convert will only import up to the named revision (given in a format
30 convert will only import up to the named revision (given in a format
31 understood by the source).
31 understood by the source).
32
32
33 If no destination directory name is specified, it defaults to the basename
33 If no destination directory name is specified, it defaults to the basename
34 of the source with "-hg" appended. If the destination repository doesn't
34 of the source with "-hg" appended. If the destination repository doesn't
35 exist, it will be created.
35 exist, it will be created.
36
36
37 By default, all sources except Mercurial will use --branchsort. Mercurial
37 By default, all sources except Mercurial will use --branchsort. Mercurial
38 uses --sourcesort to preserve original revision numbers order. Sort modes
38 uses --sourcesort to preserve original revision numbers order. Sort modes
39 have the following effects:
39 have the following effects:
40
40
41 --branchsort convert from parent to child revision when possible, which
41 --branchsort convert from parent to child revision when possible, which
42 means branches are usually converted one after the other.
42 means branches are usually converted one after the other.
43 It generates more compact repositories.
43 It generates more compact repositories.
44 --datesort sort revisions by date. Converted repositories have good-
44 --datesort sort revisions by date. Converted repositories have good-
45 looking changelogs but are often an order of magnitude
45 looking changelogs but are often an order of magnitude
46 larger than the same ones generated by --branchsort.
46 larger than the same ones generated by --branchsort.
47 --sourcesort try to preserve source revisions order, only supported by
47 --sourcesort try to preserve source revisions order, only supported by
48 Mercurial sources.
48 Mercurial sources.
49 --closesort try to move closed revisions as close as possible to parent
49 --closesort try to move closed revisions as close as possible to parent
50 branches, only supported by Mercurial sources.
50 branches, only supported by Mercurial sources.
51
51
52 If "REVMAP" isn't given, it will be put in a default location
52 If "REVMAP" isn't given, it will be put in a default location
53 ("<dest>/.hg/shamap" by default). The "REVMAP" is a simple text file that
53 ("<dest>/.hg/shamap" by default). The "REVMAP" is a simple text file that
54 maps each source commit ID to the destination ID for that revision, like
54 maps each source commit ID to the destination ID for that revision, like
55 so:
55 so:
56
56
57 <source ID> <destination ID>
57 <source ID> <destination ID>
58
58
59 If the file doesn't exist, it's automatically created. It's updated on
59 If the file doesn't exist, it's automatically created. It's updated on
60 each commit copied, so "hg convert" can be interrupted and can be run
60 each commit copied, so "hg convert" can be interrupted and can be run
61 repeatedly to copy new commits.
61 repeatedly to copy new commits.
62
62
63 The authormap is a simple text file that maps each source commit author to
63 The authormap is a simple text file that maps each source commit author to
64 a destination commit author. It is handy for source SCMs that use unix
64 a destination commit author. It is handy for source SCMs that use unix
65 logins to identify authors (e.g.: CVS). One line per author mapping and
65 logins to identify authors (e.g.: CVS). One line per author mapping and
66 the line format is:
66 the line format is:
67
67
68 source author = destination author
68 source author = destination author
69
69
70 Empty lines and lines starting with a "#" are ignored.
70 Empty lines and lines starting with a "#" are ignored.
71
71
72 The filemap is a file that allows filtering and remapping of files and
72 The filemap is a file that allows filtering and remapping of files and
73 directories. Each line can contain one of the following directives:
73 directories. Each line can contain one of the following directives:
74
74
75 include path/to/file-or-dir
75 include path/to/file-or-dir
76
76
77 exclude path/to/file-or-dir
77 exclude path/to/file-or-dir
78
78
79 rename path/to/source path/to/destination
79 rename path/to/source path/to/destination
80
80
81 Comment lines start with "#". A specified path matches if it equals the
81 Comment lines start with "#". A specified path matches if it equals the
82 full relative name of a file or one of its parent directories. The
82 full relative name of a file or one of its parent directories. The
83 "include" or "exclude" directive with the longest matching path applies,
83 "include" or "exclude" directive with the longest matching path applies,
84 so line order does not matter.
84 so line order does not matter.
85
85
86 The "include" directive causes a file, or all files under a directory, to
86 The "include" directive causes a file, or all files under a directory, to
87 be included in the destination repository, and the exclusion of all other
87 be included in the destination repository, and the exclusion of all other
88 files and directories not explicitly included. The "exclude" directive
88 files and directories not explicitly included. The "exclude" directive
89 causes files or directories to be omitted. The "rename" directive renames
89 causes files or directories to be omitted. The "rename" directive renames
90 a file or directory if it is converted. To rename from a subdirectory into
90 a file or directory if it is converted. To rename from a subdirectory into
91 the root of the repository, use "." as the path to rename to.
91 the root of the repository, use "." as the path to rename to.
92
92
93 The splicemap is a file that allows insertion of synthetic history,
93 The splicemap is a file that allows insertion of synthetic history,
94 letting you specify the parents of a revision. This is useful if you want
94 letting you specify the parents of a revision. This is useful if you want
95 to e.g. give a Subversion merge two parents, or graft two disconnected
95 to e.g. give a Subversion merge two parents, or graft two disconnected
96 series of history together. Each entry contains a key, followed by a
96 series of history together. Each entry contains a key, followed by a
97 space, followed by one or two comma-separated values:
97 space, followed by one or two comma-separated values:
98
98
99 key parent1, parent2
99 key parent1, parent2
100
100
101 The key is the revision ID in the source revision control system whose
101 The key is the revision ID in the source revision control system whose
102 parents should be modified (same format as a key in .hg/shamap). The
102 parents should be modified (same format as a key in .hg/shamap). The
103 values are the revision IDs (in either the source or destination revision
103 values are the revision IDs (in either the source or destination revision
104 control system) that should be used as the new parents for that node. For
104 control system) that should be used as the new parents for that node. For
105 example, if you have merged "release-1.0" into "trunk", then you should
105 example, if you have merged "release-1.0" into "trunk", then you should
106 specify the revision on "trunk" as the first parent and the one on the
106 specify the revision on "trunk" as the first parent and the one on the
107 "release-1.0" branch as the second.
107 "release-1.0" branch as the second.
108
108
109 The branchmap is a file that allows you to rename a branch when it is
109 The branchmap is a file that allows you to rename a branch when it is
110 being brought in from whatever external repository. When used in
110 being brought in from whatever external repository. When used in
111 conjunction with a splicemap, it allows for a powerful combination to help
111 conjunction with a splicemap, it allows for a powerful combination to help
112 fix even the most badly mismanaged repositories and turn them into nicely
112 fix even the most badly mismanaged repositories and turn them into nicely
113 structured Mercurial repositories. The branchmap contains lines of the
113 structured Mercurial repositories. The branchmap contains lines of the
114 form:
114 form:
115
115
116 original_branch_name new_branch_name
116 original_branch_name new_branch_name
117
117
118 where "original_branch_name" is the name of the branch in the source
118 where "original_branch_name" is the name of the branch in the source
119 repository, and "new_branch_name" is the name of the branch is the
119 repository, and "new_branch_name" is the name of the branch is the
120 destination repository. No whitespace is allowed in the branch names. This
120 destination repository. No whitespace is allowed in the branch names. This
121 can be used to (for instance) move code in one repository from "default"
121 can be used to (for instance) move code in one repository from "default"
122 to a named branch.
122 to a named branch.
123
123
124 Mercurial Source
124 Mercurial Source
125 ################
125 ################
126
126
127 The Mercurial source recognizes the following configuration options, which
127 The Mercurial source recognizes the following configuration options, which
128 you can set on the command line with "--config":
128 you can set on the command line with "--config":
129
129
130 convert.hg.ignoreerrors
130 convert.hg.ignoreerrors
131 ignore integrity errors when reading. Use it to fix
131 ignore integrity errors when reading. Use it to fix
132 Mercurial repositories with missing revlogs, by converting
132 Mercurial repositories with missing revlogs, by converting
133 from and to Mercurial. Default is False.
133 from and to Mercurial. Default is False.
134 convert.hg.saverev
134 convert.hg.saverev
135 store original revision ID in changeset (forces target IDs
135 store original revision ID in changeset (forces target IDs
136 to change). It takes a boolean argument and defaults to
136 to change). It takes a boolean argument and defaults to
137 False.
137 False.
138 convert.hg.startrev
138 convert.hg.revs
139 convert start revision and its descendants. It takes a hg
139 revset specifying the source revisions to convert.
140 revision identifier and defaults to 0.
141
140
142 CVS Source
141 CVS Source
143 ##########
142 ##########
144
143
145 CVS source will use a sandbox (i.e. a checked-out copy) from CVS to
144 CVS source will use a sandbox (i.e. a checked-out copy) from CVS to
146 indicate the starting point of what will be converted. Direct access to
145 indicate the starting point of what will be converted. Direct access to
147 the repository files is not needed, unless of course the repository is
146 the repository files is not needed, unless of course the repository is
148 ":local:". The conversion uses the top level directory in the sandbox to
147 ":local:". The conversion uses the top level directory in the sandbox to
149 find the CVS repository, and then uses CVS rlog commands to find files to
148 find the CVS repository, and then uses CVS rlog commands to find files to
150 convert. This means that unless a filemap is given, all files under the
149 convert. This means that unless a filemap is given, all files under the
151 starting directory will be converted, and that any directory
150 starting directory will be converted, and that any directory
152 reorganization in the CVS sandbox is ignored.
151 reorganization in the CVS sandbox is ignored.
153
152
154 The following options can be used with "--config":
153 The following options can be used with "--config":
155
154
156 convert.cvsps.cache
155 convert.cvsps.cache
157 Set to False to disable remote log caching, for testing and
156 Set to False to disable remote log caching, for testing and
158 debugging purposes. Default is True.
157 debugging purposes. Default is True.
159 convert.cvsps.fuzz
158 convert.cvsps.fuzz
160 Specify the maximum time (in seconds) that is allowed
159 Specify the maximum time (in seconds) that is allowed
161 between commits with identical user and log message in a
160 between commits with identical user and log message in a
162 single changeset. When very large files were checked in as
161 single changeset. When very large files were checked in as
163 part of a changeset then the default may not be long enough.
162 part of a changeset then the default may not be long enough.
164 The default is 60.
163 The default is 60.
165 convert.cvsps.mergeto
164 convert.cvsps.mergeto
166 Specify a regular expression to which commit log messages
165 Specify a regular expression to which commit log messages
167 are matched. If a match occurs, then the conversion process
166 are matched. If a match occurs, then the conversion process
168 will insert a dummy revision merging the branch on which
167 will insert a dummy revision merging the branch on which
169 this log message occurs to the branch indicated in the
168 this log message occurs to the branch indicated in the
170 regex. Default is "{{mergetobranch ([-\w]+)}}"
169 regex. Default is "{{mergetobranch ([-\w]+)}}"
171 convert.cvsps.mergefrom
170 convert.cvsps.mergefrom
172 Specify a regular expression to which commit log messages
171 Specify a regular expression to which commit log messages
173 are matched. If a match occurs, then the conversion process
172 are matched. If a match occurs, then the conversion process
174 will add the most recent revision on the branch indicated in
173 will add the most recent revision on the branch indicated in
175 the regex as the second parent of the changeset. Default is
174 the regex as the second parent of the changeset. Default is
176 "{{mergefrombranch ([-\w]+)}}"
175 "{{mergefrombranch ([-\w]+)}}"
177 convert.localtimezone
176 convert.localtimezone
178 use local time (as determined by the TZ environment
177 use local time (as determined by the TZ environment
179 variable) for changeset date/times. The default is False
178 variable) for changeset date/times. The default is False
180 (use UTC).
179 (use UTC).
181 hooks.cvslog Specify a Python function to be called at the end of
180 hooks.cvslog Specify a Python function to be called at the end of
182 gathering the CVS log. The function is passed a list with
181 gathering the CVS log. The function is passed a list with
183 the log entries, and can modify the entries in-place, or add
182 the log entries, and can modify the entries in-place, or add
184 or delete them.
183 or delete them.
185 hooks.cvschangesets
184 hooks.cvschangesets
186 Specify a Python function to be called after the changesets
185 Specify a Python function to be called after the changesets
187 are calculated from the CVS log. The function is passed a
186 are calculated from the CVS log. The function is passed a
188 list with the changeset entries, and can modify the
187 list with the changeset entries, and can modify the
189 changesets in-place, or add or delete them.
188 changesets in-place, or add or delete them.
190
189
191 An additional "debugcvsps" Mercurial command allows the builtin changeset
190 An additional "debugcvsps" Mercurial command allows the builtin changeset
192 merging code to be run without doing a conversion. Its parameters and
191 merging code to be run without doing a conversion. Its parameters and
193 output are similar to that of cvsps 2.1. Please see the command help for
192 output are similar to that of cvsps 2.1. Please see the command help for
194 more details.
193 more details.
195
194
196 Subversion Source
195 Subversion Source
197 #################
196 #################
198
197
199 Subversion source detects classical trunk/branches/tags layouts. By
198 Subversion source detects classical trunk/branches/tags layouts. By
200 default, the supplied "svn://repo/path/" source URL is converted as a
199 default, the supplied "svn://repo/path/" source URL is converted as a
201 single branch. If "svn://repo/path/trunk" exists it replaces the default
200 single branch. If "svn://repo/path/trunk" exists it replaces the default
202 branch. If "svn://repo/path/branches" exists, its subdirectories are
201 branch. If "svn://repo/path/branches" exists, its subdirectories are
203 listed as possible branches. If "svn://repo/path/tags" exists, it is
202 listed as possible branches. If "svn://repo/path/tags" exists, it is
204 looked for tags referencing converted branches. Default "trunk",
203 looked for tags referencing converted branches. Default "trunk",
205 "branches" and "tags" values can be overridden with following options. Set
204 "branches" and "tags" values can be overridden with following options. Set
206 them to paths relative to the source URL, or leave them blank to disable
205 them to paths relative to the source URL, or leave them blank to disable
207 auto detection.
206 auto detection.
208
207
209 The following options can be set with "--config":
208 The following options can be set with "--config":
210
209
211 convert.svn.branches
210 convert.svn.branches
212 specify the directory containing branches. The default is
211 specify the directory containing branches. The default is
213 "branches".
212 "branches".
214 convert.svn.tags
213 convert.svn.tags
215 specify the directory containing tags. The default is
214 specify the directory containing tags. The default is
216 "tags".
215 "tags".
217 convert.svn.trunk
216 convert.svn.trunk
218 specify the name of the trunk branch. The default is
217 specify the name of the trunk branch. The default is
219 "trunk".
218 "trunk".
220 convert.localtimezone
219 convert.localtimezone
221 use local time (as determined by the TZ environment
220 use local time (as determined by the TZ environment
222 variable) for changeset date/times. The default is False
221 variable) for changeset date/times. The default is False
223 (use UTC).
222 (use UTC).
224
223
225 Source history can be retrieved starting at a specific revision, instead
224 Source history can be retrieved starting at a specific revision, instead
226 of being integrally converted. Only single branch conversions are
225 of being integrally converted. Only single branch conversions are
227 supported.
226 supported.
228
227
229 convert.svn.startrev
228 convert.svn.startrev
230 specify start Subversion revision number. The default is 0.
229 specify start Subversion revision number. The default is 0.
231
230
232 Perforce Source
231 Perforce Source
233 ###############
232 ###############
234
233
235 The Perforce (P4) importer can be given a p4 depot path or a client
234 The Perforce (P4) importer can be given a p4 depot path or a client
236 specification as source. It will convert all files in the source to a flat
235 specification as source. It will convert all files in the source to a flat
237 Mercurial repository, ignoring labels, branches and integrations. Note
236 Mercurial repository, ignoring labels, branches and integrations. Note
238 that when a depot path is given you then usually should specify a target
237 that when a depot path is given you then usually should specify a target
239 directory, because otherwise the target may be named "...-hg".
238 directory, because otherwise the target may be named "...-hg".
240
239
241 It is possible to limit the amount of source history to be converted by
240 It is possible to limit the amount of source history to be converted by
242 specifying an initial Perforce revision:
241 specifying an initial Perforce revision:
243
242
244 convert.p4.startrev
243 convert.p4.startrev
245 specify initial Perforce revision (a Perforce changelist
244 specify initial Perforce revision (a Perforce changelist
246 number).
245 number).
247
246
248 Mercurial Destination
247 Mercurial Destination
249 #####################
248 #####################
250
249
251 The following options are supported:
250 The following options are supported:
252
251
253 convert.hg.clonebranches
252 convert.hg.clonebranches
254 dispatch source branches in separate clones. The default is
253 dispatch source branches in separate clones. The default is
255 False.
254 False.
256 convert.hg.tagsbranch
255 convert.hg.tagsbranch
257 branch name for tag revisions, defaults to "default".
256 branch name for tag revisions, defaults to "default".
258 convert.hg.usebranchnames
257 convert.hg.usebranchnames
259 preserve branch names. The default is True.
258 preserve branch names. The default is True.
260
259
261 options:
260 options:
262
261
263 -s --source-type TYPE source repository type
262 -s --source-type TYPE source repository type
264 -d --dest-type TYPE destination repository type
263 -d --dest-type TYPE destination repository type
265 -r --rev REV import up to source revision REV
264 -r --rev REV import up to source revision REV
266 -A --authormap FILE remap usernames using this file
265 -A --authormap FILE remap usernames using this file
267 --filemap FILE remap file names using contents of file
266 --filemap FILE remap file names using contents of file
268 --splicemap FILE splice synthesized history into place
267 --splicemap FILE splice synthesized history into place
269 --branchmap FILE change branch names while converting
268 --branchmap FILE change branch names while converting
270 --branchsort try to sort changesets by branches
269 --branchsort try to sort changesets by branches
271 --datesort try to sort changesets by date
270 --datesort try to sort changesets by date
272 --sourcesort preserve source changesets order
271 --sourcesort preserve source changesets order
273 --closesort try to reorder closed revisions
272 --closesort try to reorder closed revisions
274
273
275 use "hg -v help convert" to show the global options
274 use "hg -v help convert" to show the global options
276 $ hg init a
275 $ hg init a
277 $ cd a
276 $ cd a
278 $ echo a > a
277 $ echo a > a
279 $ hg ci -d'0 0' -Ama
278 $ hg ci -d'0 0' -Ama
280 adding a
279 adding a
281 $ hg cp a b
280 $ hg cp a b
282 $ hg ci -d'1 0' -mb
281 $ hg ci -d'1 0' -mb
283 $ hg rm a
282 $ hg rm a
284 $ hg ci -d'2 0' -mc
283 $ hg ci -d'2 0' -mc
285 $ hg mv b a
284 $ hg mv b a
286 $ hg ci -d'3 0' -md
285 $ hg ci -d'3 0' -md
287 $ echo a >> a
286 $ echo a >> a
288 $ hg ci -d'4 0' -me
287 $ hg ci -d'4 0' -me
289 $ cd ..
288 $ cd ..
290 $ hg convert a 2>&1 | grep -v 'subversion python bindings could not be loaded'
289 $ hg convert a 2>&1 | grep -v 'subversion python bindings could not be loaded'
291 assuming destination a-hg
290 assuming destination a-hg
292 initializing destination a-hg repository
291 initializing destination a-hg repository
293 scanning source...
292 scanning source...
294 sorting...
293 sorting...
295 converting...
294 converting...
296 4 a
295 4 a
297 3 b
296 3 b
298 2 c
297 2 c
299 1 d
298 1 d
300 0 e
299 0 e
301 $ hg --cwd a-hg pull ../a
300 $ hg --cwd a-hg pull ../a
302 pulling from ../a
301 pulling from ../a
303 searching for changes
302 searching for changes
304 no changes found
303 no changes found
305
304
306 conversion to existing file should fail
305 conversion to existing file should fail
307
306
308 $ touch bogusfile
307 $ touch bogusfile
309 $ hg convert a bogusfile
308 $ hg convert a bogusfile
310 initializing destination bogusfile repository
309 initializing destination bogusfile repository
311 abort: cannot create new bundle repository
310 abort: cannot create new bundle repository
312 [255]
311 [255]
313
312
314 #if unix-permissions
313 #if unix-permissions
315
314
316 conversion to dir without permissions should fail
315 conversion to dir without permissions should fail
317
316
318 $ mkdir bogusdir
317 $ mkdir bogusdir
319 $ chmod 000 bogusdir
318 $ chmod 000 bogusdir
320
319
321 $ hg convert a bogusdir
320 $ hg convert a bogusdir
322 abort: Permission denied: 'bogusdir'
321 abort: Permission denied: 'bogusdir'
323 [255]
322 [255]
324
323
325 user permissions should succeed
324 user permissions should succeed
326
325
327 $ chmod 700 bogusdir
326 $ chmod 700 bogusdir
328 $ hg convert a bogusdir
327 $ hg convert a bogusdir
329 initializing destination bogusdir repository
328 initializing destination bogusdir repository
330 scanning source...
329 scanning source...
331 sorting...
330 sorting...
332 converting...
331 converting...
333 4 a
332 4 a
334 3 b
333 3 b
335 2 c
334 2 c
336 1 d
335 1 d
337 0 e
336 0 e
338
337
339 #endif
338 #endif
340
339
341 test pre and post conversion actions
340 test pre and post conversion actions
342
341
343 $ echo 'include b' > filemap
342 $ echo 'include b' > filemap
344 $ hg convert --debug --filemap filemap a partialb | \
343 $ hg convert --debug --filemap filemap a partialb | \
345 > grep 'run hg'
344 > grep 'run hg'
346 run hg source pre-conversion action
345 run hg source pre-conversion action
347 run hg sink pre-conversion action
346 run hg sink pre-conversion action
348 run hg sink post-conversion action
347 run hg sink post-conversion action
349 run hg source post-conversion action
348 run hg source post-conversion action
350
349
351 converting empty dir should fail "nicely
350 converting empty dir should fail "nicely
352
351
353 $ mkdir emptydir
352 $ mkdir emptydir
354
353
355 override $PATH to ensure p4 not visible; use $PYTHON in case we're
354 override $PATH to ensure p4 not visible; use $PYTHON in case we're
356 running from a devel copy, not a temp installation
355 running from a devel copy, not a temp installation
357
356
358 $ PATH="$BINDIR" $PYTHON "$BINDIR"/hg convert emptydir
357 $ PATH="$BINDIR" $PYTHON "$BINDIR"/hg convert emptydir
359 assuming destination emptydir-hg
358 assuming destination emptydir-hg
360 initializing destination emptydir-hg repository
359 initializing destination emptydir-hg repository
361 emptydir does not look like a CVS checkout
360 emptydir does not look like a CVS checkout
362 emptydir does not look like a Git repository
361 emptydir does not look like a Git repository
363 emptydir does not look like a Subversion repository
362 emptydir does not look like a Subversion repository
364 emptydir is not a local Mercurial repository
363 emptydir is not a local Mercurial repository
365 emptydir does not look like a darcs repository
364 emptydir does not look like a darcs repository
366 emptydir does not look like a monotone repository
365 emptydir does not look like a monotone repository
367 emptydir does not look like a GNU Arch repository
366 emptydir does not look like a GNU Arch repository
368 emptydir does not look like a Bazaar repository
367 emptydir does not look like a Bazaar repository
369 cannot find required "p4" tool
368 cannot find required "p4" tool
370 abort: emptydir: missing or unsupported repository
369 abort: emptydir: missing or unsupported repository
371 [255]
370 [255]
372
371
373 convert with imaginary source type
372 convert with imaginary source type
374
373
375 $ hg convert --source-type foo a a-foo
374 $ hg convert --source-type foo a a-foo
376 initializing destination a-foo repository
375 initializing destination a-foo repository
377 abort: foo: invalid source repository type
376 abort: foo: invalid source repository type
378 [255]
377 [255]
379
378
380 convert with imaginary sink type
379 convert with imaginary sink type
381
380
382 $ hg convert --dest-type foo a a-foo
381 $ hg convert --dest-type foo a a-foo
383 abort: foo: invalid destination repository type
382 abort: foo: invalid destination repository type
384 [255]
383 [255]
385
384
386 testing: convert must not produce duplicate entries in fncache
385 testing: convert must not produce duplicate entries in fncache
387
386
388 $ hg convert a b
387 $ hg convert a b
389 initializing destination b repository
388 initializing destination b repository
390 scanning source...
389 scanning source...
391 sorting...
390 sorting...
392 converting...
391 converting...
393 4 a
392 4 a
394 3 b
393 3 b
395 2 c
394 2 c
396 1 d
395 1 d
397 0 e
396 0 e
398
397
399 contents of fncache file:
398 contents of fncache file:
400
399
401 $ cat b/.hg/store/fncache | sort
400 $ cat b/.hg/store/fncache | sort
402 data/a.i
401 data/a.i
403 data/b.i
402 data/b.i
404
403
405 test bogus URL
404 test bogus URL
406
405
407 $ hg convert -q bzr+ssh://foobar@selenic.com/baz baz
406 $ hg convert -q bzr+ssh://foobar@selenic.com/baz baz
408 abort: bzr+ssh://foobar@selenic.com/baz: missing or unsupported repository
407 abort: bzr+ssh://foobar@selenic.com/baz: missing or unsupported repository
409 [255]
408 [255]
410
409
411 test revset converted() lookup
410 test revset converted() lookup
412
411
413 $ hg --config convert.hg.saverev=True convert a c
412 $ hg --config convert.hg.saverev=True convert a c
414 initializing destination c repository
413 initializing destination c repository
415 scanning source...
414 scanning source...
416 sorting...
415 sorting...
417 converting...
416 converting...
418 4 a
417 4 a
419 3 b
418 3 b
420 2 c
419 2 c
421 1 d
420 1 d
422 0 e
421 0 e
423 $ echo f > c/f
422 $ echo f > c/f
424 $ hg -R c ci -d'0 0' -Amf
423 $ hg -R c ci -d'0 0' -Amf
425 adding f
424 adding f
426 created new head
425 created new head
427 $ hg -R c log -r "converted(09d945a62ce6)"
426 $ hg -R c log -r "converted(09d945a62ce6)"
428 changeset: 1:98c3dd46a874
427 changeset: 1:98c3dd46a874
429 user: test
428 user: test
430 date: Thu Jan 01 00:00:01 1970 +0000
429 date: Thu Jan 01 00:00:01 1970 +0000
431 summary: b
430 summary: b
432
431
433 $ hg -R c log -r "converted()"
432 $ hg -R c log -r "converted()"
434 changeset: 0:31ed57b2037c
433 changeset: 0:31ed57b2037c
435 user: test
434 user: test
436 date: Thu Jan 01 00:00:00 1970 +0000
435 date: Thu Jan 01 00:00:00 1970 +0000
437 summary: a
436 summary: a
438
437
439 changeset: 1:98c3dd46a874
438 changeset: 1:98c3dd46a874
440 user: test
439 user: test
441 date: Thu Jan 01 00:00:01 1970 +0000
440 date: Thu Jan 01 00:00:01 1970 +0000
442 summary: b
441 summary: b
443
442
444 changeset: 2:3b9ca06ef716
443 changeset: 2:3b9ca06ef716
445 user: test
444 user: test
446 date: Thu Jan 01 00:00:02 1970 +0000
445 date: Thu Jan 01 00:00:02 1970 +0000
447 summary: c
446 summary: c
448
447
449 changeset: 3:4e0debd37cf2
448 changeset: 3:4e0debd37cf2
450 user: test
449 user: test
451 date: Thu Jan 01 00:00:03 1970 +0000
450 date: Thu Jan 01 00:00:03 1970 +0000
452 summary: d
451 summary: d
453
452
454 changeset: 4:9de3bc9349c5
453 changeset: 4:9de3bc9349c5
455 user: test
454 user: test
456 date: Thu Jan 01 00:00:04 1970 +0000
455 date: Thu Jan 01 00:00:04 1970 +0000
457 summary: e
456 summary: e
458
457
General Comments 0
You need to be logged in to leave comments. Login now