##// END OF EJS Templates
configitems: register the 'convert.git.extrakeys' config
Boris Feld -
r34157:89e66679 default
parent child Browse files
Show More
@@ -1,528 +1,531 b''
1 1 # convert.py Foreign SCM converter
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 '''import revisions from foreign VCS repositories into Mercurial'''
9 9
10 10 from __future__ import absolute_import
11 11
12 12 from mercurial.i18n import _
13 13 from mercurial import (
14 14 registrar,
15 15 )
16 16
17 17 from . import (
18 18 convcmd,
19 19 cvsps,
20 20 subversion,
21 21 )
22 22
23 23 cmdtable = {}
24 24 command = registrar.command(cmdtable)
25 25 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
26 26 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
27 27 # be specifying the version(s) of Mercurial they are tested with, or
28 28 # leave the attribute unspecified.
29 29 testedwith = 'ships-with-hg-core'
30 30
31 31 configtable = {}
32 32 configitem = registrar.configitem(configtable)
33 33
34 34 configitem('convert', 'cvsps.cache',
35 35 default=True,
36 36 )
37 37 configitem('convert', 'cvsps.fuzz',
38 38 default=60,
39 39 )
40 40 configitem('convert', 'cvsps.mergefrom',
41 41 default=None,
42 42 )
43 43 configitem('convert', 'cvsps.mergeto',
44 44 default=None,
45 45 )
46 46 configitem('convert', 'git.committeractions',
47 47 default=lambda: ['messagedifferent'],
48 48 )
49 configitem('convert', 'git.extrakeys',
50 default=list,
51 )
49 52
50 53 # Commands definition was moved elsewhere to ease demandload job.
51 54
52 55 @command('convert',
53 56 [('', 'authors', '',
54 57 _('username mapping filename (DEPRECATED) (use --authormap instead)'),
55 58 _('FILE')),
56 59 ('s', 'source-type', '', _('source repository type'), _('TYPE')),
57 60 ('d', 'dest-type', '', _('destination repository type'), _('TYPE')),
58 61 ('r', 'rev', [], _('import up to source revision REV'), _('REV')),
59 62 ('A', 'authormap', '', _('remap usernames using this file'), _('FILE')),
60 63 ('', 'filemap', '', _('remap file names using contents of file'),
61 64 _('FILE')),
62 65 ('', 'full', None,
63 66 _('apply filemap changes by converting all files again')),
64 67 ('', 'splicemap', '', _('splice synthesized history into place'),
65 68 _('FILE')),
66 69 ('', 'branchmap', '', _('change branch names while converting'),
67 70 _('FILE')),
68 71 ('', 'branchsort', None, _('try to sort changesets by branches')),
69 72 ('', 'datesort', None, _('try to sort changesets by date')),
70 73 ('', 'sourcesort', None, _('preserve source changesets order')),
71 74 ('', 'closesort', None, _('try to reorder closed revisions'))],
72 75 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]'),
73 76 norepo=True)
74 77 def convert(ui, src, dest=None, revmapfile=None, **opts):
75 78 """convert a foreign SCM repository to a Mercurial one.
76 79
77 80 Accepted source formats [identifiers]:
78 81
79 82 - Mercurial [hg]
80 83 - CVS [cvs]
81 84 - Darcs [darcs]
82 85 - git [git]
83 86 - Subversion [svn]
84 87 - Monotone [mtn]
85 88 - GNU Arch [gnuarch]
86 89 - Bazaar [bzr]
87 90 - Perforce [p4]
88 91
89 92 Accepted destination formats [identifiers]:
90 93
91 94 - Mercurial [hg]
92 95 - Subversion [svn] (history on branches is not preserved)
93 96
94 97 If no revision is given, all revisions will be converted.
95 98 Otherwise, convert will only import up to the named revision
96 99 (given in a format understood by the source).
97 100
98 101 If no destination directory name is specified, it defaults to the
99 102 basename of the source with ``-hg`` appended. If the destination
100 103 repository doesn't exist, it will be created.
101 104
102 105 By default, all sources except Mercurial will use --branchsort.
103 106 Mercurial uses --sourcesort to preserve original revision numbers
104 107 order. Sort modes have the following effects:
105 108
106 109 --branchsort convert from parent to child revision when possible,
107 110 which means branches are usually converted one after
108 111 the other. It generates more compact repositories.
109 112
110 113 --datesort sort revisions by date. Converted repositories have
111 114 good-looking changelogs but are often an order of
112 115 magnitude larger than the same ones generated by
113 116 --branchsort.
114 117
115 118 --sourcesort try to preserve source revisions order, only
116 119 supported by Mercurial sources.
117 120
118 121 --closesort try to move closed revisions as close as possible
119 122 to parent branches, only supported by Mercurial
120 123 sources.
121 124
122 125 If ``REVMAP`` isn't given, it will be put in a default location
123 126 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
124 127 text file that maps each source commit ID to the destination ID
125 128 for that revision, like so::
126 129
127 130 <source ID> <destination ID>
128 131
129 132 If the file doesn't exist, it's automatically created. It's
130 133 updated on each commit copied, so :hg:`convert` can be interrupted
131 134 and can be run repeatedly to copy new commits.
132 135
133 136 The authormap is a simple text file that maps each source commit
134 137 author to a destination commit author. It is handy for source SCMs
135 138 that use unix logins to identify authors (e.g.: CVS). One line per
136 139 author mapping and the line format is::
137 140
138 141 source author = destination author
139 142
140 143 Empty lines and lines starting with a ``#`` are ignored.
141 144
142 145 The filemap is a file that allows filtering and remapping of files
143 146 and directories. Each line can contain one of the following
144 147 directives::
145 148
146 149 include path/to/file-or-dir
147 150
148 151 exclude path/to/file-or-dir
149 152
150 153 rename path/to/source path/to/destination
151 154
152 155 Comment lines start with ``#``. A specified path matches if it
153 156 equals the full relative name of a file or one of its parent
154 157 directories. The ``include`` or ``exclude`` directive with the
155 158 longest matching path applies, so line order does not matter.
156 159
157 160 The ``include`` directive causes a file, or all files under a
158 161 directory, to be included in the destination repository. The default
159 162 if there are no ``include`` statements is to include everything.
160 163 If there are any ``include`` statements, nothing else is included.
161 164 The ``exclude`` directive causes files or directories to
162 165 be omitted. The ``rename`` directive renames a file or directory if
163 166 it is converted. To rename from a subdirectory into the root of
164 167 the repository, use ``.`` as the path to rename to.
165 168
166 169 ``--full`` will make sure the converted changesets contain exactly
167 170 the right files with the right content. It will make a full
168 171 conversion of all files, not just the ones that have
169 172 changed. Files that already are correct will not be changed. This
170 173 can be used to apply filemap changes when converting
171 174 incrementally. This is currently only supported for Mercurial and
172 175 Subversion.
173 176
174 177 The splicemap is a file that allows insertion of synthetic
175 178 history, letting you specify the parents of a revision. This is
176 179 useful if you want to e.g. give a Subversion merge two parents, or
177 180 graft two disconnected series of history together. Each entry
178 181 contains a key, followed by a space, followed by one or two
179 182 comma-separated values::
180 183
181 184 key parent1, parent2
182 185
183 186 The key is the revision ID in the source
184 187 revision control system whose parents should be modified (same
185 188 format as a key in .hg/shamap). The values are the revision IDs
186 189 (in either the source or destination revision control system) that
187 190 should be used as the new parents for that node. For example, if
188 191 you have merged "release-1.0" into "trunk", then you should
189 192 specify the revision on "trunk" as the first parent and the one on
190 193 the "release-1.0" branch as the second.
191 194
192 195 The branchmap is a file that allows you to rename a branch when it is
193 196 being brought in from whatever external repository. When used in
194 197 conjunction with a splicemap, it allows for a powerful combination
195 198 to help fix even the most badly mismanaged repositories and turn them
196 199 into nicely structured Mercurial repositories. The branchmap contains
197 200 lines of the form::
198 201
199 202 original_branch_name new_branch_name
200 203
201 204 where "original_branch_name" is the name of the branch in the
202 205 source repository, and "new_branch_name" is the name of the branch
203 206 is the destination repository. No whitespace is allowed in the new
204 207 branch name. This can be used to (for instance) move code in one
205 208 repository from "default" to a named branch.
206 209
207 210 Mercurial Source
208 211 ################
209 212
210 213 The Mercurial source recognizes the following configuration
211 214 options, which you can set on the command line with ``--config``:
212 215
213 216 :convert.hg.ignoreerrors: ignore integrity errors when reading.
214 217 Use it to fix Mercurial repositories with missing revlogs, by
215 218 converting from and to Mercurial. Default is False.
216 219
217 220 :convert.hg.saverev: store original revision ID in changeset
218 221 (forces target IDs to change). It takes a boolean argument and
219 222 defaults to False.
220 223
221 224 :convert.hg.startrev: specify the initial Mercurial revision.
222 225 The default is 0.
223 226
224 227 :convert.hg.revs: revset specifying the source revisions to convert.
225 228
226 229 CVS Source
227 230 ##########
228 231
229 232 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
230 233 to indicate the starting point of what will be converted. Direct
231 234 access to the repository files is not needed, unless of course the
232 235 repository is ``:local:``. The conversion uses the top level
233 236 directory in the sandbox to find the CVS repository, and then uses
234 237 CVS rlog commands to find files to convert. This means that unless
235 238 a filemap is given, all files under the starting directory will be
236 239 converted, and that any directory reorganization in the CVS
237 240 sandbox is ignored.
238 241
239 242 The following options can be used with ``--config``:
240 243
241 244 :convert.cvsps.cache: Set to False to disable remote log caching,
242 245 for testing and debugging purposes. Default is True.
243 246
244 247 :convert.cvsps.fuzz: Specify the maximum time (in seconds) that is
245 248 allowed between commits with identical user and log message in
246 249 a single changeset. When very large files were checked in as
247 250 part of a changeset then the default may not be long enough.
248 251 The default is 60.
249 252
250 253 :convert.cvsps.logencoding: Specify encoding name to be used for
251 254 transcoding CVS log messages. Multiple encoding names can be
252 255 specified as a list (see :hg:`help config.Syntax`), but only
253 256 the first acceptable encoding in the list is used per CVS log
254 257 entries. This transcoding is executed before cvslog hook below.
255 258
256 259 :convert.cvsps.mergeto: Specify a regular expression to which
257 260 commit log messages are matched. If a match occurs, then the
258 261 conversion process will insert a dummy revision merging the
259 262 branch on which this log message occurs to the branch
260 263 indicated in the regex. Default is ``{{mergetobranch
261 264 ([-\\w]+)}}``
262 265
263 266 :convert.cvsps.mergefrom: Specify a regular expression to which
264 267 commit log messages are matched. If a match occurs, then the
265 268 conversion process will add the most recent revision on the
266 269 branch indicated in the regex as the second parent of the
267 270 changeset. Default is ``{{mergefrombranch ([-\\w]+)}}``
268 271
269 272 :convert.localtimezone: use local time (as determined by the TZ
270 273 environment variable) for changeset date/times. The default
271 274 is False (use UTC).
272 275
273 276 :hooks.cvslog: Specify a Python function to be called at the end of
274 277 gathering the CVS log. The function is passed a list with the
275 278 log entries, and can modify the entries in-place, or add or
276 279 delete them.
277 280
278 281 :hooks.cvschangesets: Specify a Python function to be called after
279 282 the changesets are calculated from the CVS log. The
280 283 function is passed a list with the changeset entries, and can
281 284 modify the changesets in-place, or add or delete them.
282 285
283 286 An additional "debugcvsps" Mercurial command allows the builtin
284 287 changeset merging code to be run without doing a conversion. Its
285 288 parameters and output are similar to that of cvsps 2.1. Please see
286 289 the command help for more details.
287 290
288 291 Subversion Source
289 292 #################
290 293
291 294 Subversion source detects classical trunk/branches/tags layouts.
292 295 By default, the supplied ``svn://repo/path/`` source URL is
293 296 converted as a single branch. If ``svn://repo/path/trunk`` exists
294 297 it replaces the default branch. If ``svn://repo/path/branches``
295 298 exists, its subdirectories are listed as possible branches. If
296 299 ``svn://repo/path/tags`` exists, it is looked for tags referencing
297 300 converted branches. Default ``trunk``, ``branches`` and ``tags``
298 301 values can be overridden with following options. Set them to paths
299 302 relative to the source URL, or leave them blank to disable auto
300 303 detection.
301 304
302 305 The following options can be set with ``--config``:
303 306
304 307 :convert.svn.branches: specify the directory containing branches.
305 308 The default is ``branches``.
306 309
307 310 :convert.svn.tags: specify the directory containing tags. The
308 311 default is ``tags``.
309 312
310 313 :convert.svn.trunk: specify the name of the trunk branch. The
311 314 default is ``trunk``.
312 315
313 316 :convert.localtimezone: use local time (as determined by the TZ
314 317 environment variable) for changeset date/times. The default
315 318 is False (use UTC).
316 319
317 320 Source history can be retrieved starting at a specific revision,
318 321 instead of being integrally converted. Only single branch
319 322 conversions are supported.
320 323
321 324 :convert.svn.startrev: specify start Subversion revision number.
322 325 The default is 0.
323 326
324 327 Git Source
325 328 ##########
326 329
327 330 The Git importer converts commits from all reachable branches (refs
328 331 in refs/heads) and remotes (refs in refs/remotes) to Mercurial.
329 332 Branches are converted to bookmarks with the same name, with the
330 333 leading 'refs/heads' stripped. Git submodules are converted to Git
331 334 subrepos in Mercurial.
332 335
333 336 The following options can be set with ``--config``:
334 337
335 338 :convert.git.similarity: specify how similar files modified in a
336 339 commit must be to be imported as renames or copies, as a
337 340 percentage between ``0`` (disabled) and ``100`` (files must be
338 341 identical). For example, ``90`` means that a delete/add pair will
339 342 be imported as a rename if more than 90% of the file hasn't
340 343 changed. The default is ``50``.
341 344
342 345 :convert.git.findcopiesharder: while detecting copies, look at all
343 346 files in the working copy instead of just changed ones. This
344 347 is very expensive for large projects, and is only effective when
345 348 ``convert.git.similarity`` is greater than 0. The default is False.
346 349
347 350 :convert.git.renamelimit: perform rename and copy detection up to this
348 351 many changed files in a commit. Increasing this will make rename
349 352 and copy detection more accurate but will significantly slow down
350 353 computation on large projects. The option is only relevant if
351 354 ``convert.git.similarity`` is greater than 0. The default is
352 355 ``400``.
353 356
354 357 :convert.git.committeractions: list of actions to take when processing
355 358 author and committer values.
356 359
357 360 Git commits have separate author (who wrote the commit) and committer
358 361 (who applied the commit) fields. Not all destinations support separate
359 362 author and committer fields (including Mercurial). This config option
360 363 controls what to do with these author and committer fields during
361 364 conversion.
362 365
363 366 A value of ``messagedifferent`` will append a ``committer: ...``
364 367 line to the commit message if the Git committer is different from the
365 368 author. The prefix of that line can be specified using the syntax
366 369 ``messagedifferent=<prefix>``. e.g. ``messagedifferent=git-committer:``.
367 370 When a prefix is specified, a space will always be inserted between the
368 371 prefix and the value.
369 372
370 373 ``messagealways`` behaves like ``messagedifferent`` except it will
371 374 always result in a ``committer: ...`` line being appended to the commit
372 375 message. This value is mutually exclusive with ``messagedifferent``.
373 376
374 377 ``dropcommitter`` will remove references to the committer. Only
375 378 references to the author will remain. Actions that add references
376 379 to the committer will have no effect when this is set.
377 380
378 381 ``replaceauthor`` will replace the value of the author field with
379 382 the committer. Other actions that add references to the committer
380 383 will still take effect when this is set.
381 384
382 385 The default is ``messagedifferent``.
383 386
384 387 :convert.git.extrakeys: list of extra keys from commit metadata to copy to
385 388 the destination. Some Git repositories store extra metadata in commits.
386 389 By default, this non-default metadata will be lost during conversion.
387 390 Setting this config option can retain that metadata. Some built-in
388 391 keys such as ``parent`` and ``branch`` are not allowed to be copied.
389 392
390 393 :convert.git.remoteprefix: remote refs are converted as bookmarks with
391 394 ``convert.git.remoteprefix`` as a prefix followed by a /. The default
392 395 is 'remote'.
393 396
394 397 :convert.git.saverev: whether to store the original Git commit ID in the
395 398 metadata of the destination commit. The default is True.
396 399
397 400 :convert.git.skipsubmodules: does not convert root level .gitmodules files
398 401 or files with 160000 mode indicating a submodule. Default is False.
399 402
400 403 Perforce Source
401 404 ###############
402 405
403 406 The Perforce (P4) importer can be given a p4 depot path or a
404 407 client specification as source. It will convert all files in the
405 408 source to a flat Mercurial repository, ignoring labels, branches
406 409 and integrations. Note that when a depot path is given you then
407 410 usually should specify a target directory, because otherwise the
408 411 target may be named ``...-hg``.
409 412
410 413 The following options can be set with ``--config``:
411 414
412 415 :convert.p4.encoding: specify the encoding to use when decoding standard
413 416 output of the Perforce command line tool. The default is default system
414 417 encoding.
415 418
416 419 :convert.p4.startrev: specify initial Perforce revision (a
417 420 Perforce changelist number).
418 421
419 422 Mercurial Destination
420 423 #####################
421 424
422 425 The Mercurial destination will recognize Mercurial subrepositories in the
423 426 destination directory, and update the .hgsubstate file automatically if the
424 427 destination subrepositories contain the <dest>/<sub>/.hg/shamap file.
425 428 Converting a repository with subrepositories requires converting a single
426 429 repository at a time, from the bottom up.
427 430
428 431 .. container:: verbose
429 432
430 433 An example showing how to convert a repository with subrepositories::
431 434
432 435 # so convert knows the type when it sees a non empty destination
433 436 $ hg init converted
434 437
435 438 $ hg convert orig/sub1 converted/sub1
436 439 $ hg convert orig/sub2 converted/sub2
437 440 $ hg convert orig converted
438 441
439 442 The following options are supported:
440 443
441 444 :convert.hg.clonebranches: dispatch source branches in separate
442 445 clones. The default is False.
443 446
444 447 :convert.hg.tagsbranch: branch name for tag revisions, defaults to
445 448 ``default``.
446 449
447 450 :convert.hg.usebranchnames: preserve branch names. The default is
448 451 True.
449 452
450 453 :convert.hg.sourcename: records the given string as a 'convert_source' extra
451 454 value on each commit made in the target repository. The default is None.
452 455
453 456 All Destinations
454 457 ################
455 458
456 459 All destination types accept the following options:
457 460
458 461 :convert.skiptags: does not convert tags from the source repo to the target
459 462 repo. The default is False.
460 463 """
461 464 return convcmd.convert(ui, src, dest, revmapfile, **opts)
462 465
463 466 @command('debugsvnlog', [], 'hg debugsvnlog', norepo=True)
464 467 def debugsvnlog(ui, **opts):
465 468 return subversion.debugsvnlog(ui, **opts)
466 469
467 470 @command('debugcvsps',
468 471 [
469 472 # Main options shared with cvsps-2.1
470 473 ('b', 'branches', [], _('only return changes on specified branches')),
471 474 ('p', 'prefix', '', _('prefix to remove from file names')),
472 475 ('r', 'revisions', [],
473 476 _('only return changes after or between specified tags')),
474 477 ('u', 'update-cache', None, _("update cvs log cache")),
475 478 ('x', 'new-cache', None, _("create new cvs log cache")),
476 479 ('z', 'fuzz', 60, _('set commit time fuzz in seconds')),
477 480 ('', 'root', '', _('specify cvsroot')),
478 481 # Options specific to builtin cvsps
479 482 ('', 'parents', '', _('show parent changesets')),
480 483 ('', 'ancestors', '', _('show current changeset in ancestor branches')),
481 484 # Options that are ignored for compatibility with cvsps-2.1
482 485 ('A', 'cvs-direct', None, _('ignored for compatibility')),
483 486 ],
484 487 _('hg debugcvsps [OPTION]... [PATH]...'),
485 488 norepo=True)
486 489 def debugcvsps(ui, *args, **opts):
487 490 '''create changeset information from CVS
488 491
489 492 This command is intended as a debugging tool for the CVS to
490 493 Mercurial converter, and can be used as a direct replacement for
491 494 cvsps.
492 495
493 496 Hg debugcvsps reads the CVS rlog for current directory (or any
494 497 named directory) in the CVS repository, and converts the log to a
495 498 series of changesets based on matching commit log entries and
496 499 dates.'''
497 500 return cvsps.debugcvsps(ui, *args, **opts)
498 501
499 502 def kwconverted(ctx, name):
500 503 rev = ctx.extra().get('convert_revision', '')
501 504 if rev.startswith('svn:'):
502 505 if name == 'svnrev':
503 506 return str(subversion.revsplit(rev)[2])
504 507 elif name == 'svnpath':
505 508 return subversion.revsplit(rev)[1]
506 509 elif name == 'svnuuid':
507 510 return subversion.revsplit(rev)[0]
508 511 return rev
509 512
510 513 templatekeyword = registrar.templatekeyword()
511 514
512 515 @templatekeyword('svnrev')
513 516 def kwsvnrev(repo, ctx, **args):
514 517 """String. Converted subversion revision number."""
515 518 return kwconverted(ctx, 'svnrev')
516 519
517 520 @templatekeyword('svnpath')
518 521 def kwsvnpath(repo, ctx, **args):
519 522 """String. Converted subversion revision project path."""
520 523 return kwconverted(ctx, 'svnpath')
521 524
522 525 @templatekeyword('svnuuid')
523 526 def kwsvnuuid(repo, ctx, **args):
524 527 """String. Converted subversion revision repository identifier."""
525 528 return kwconverted(ctx, 'svnuuid')
526 529
527 530 # tell hggettext to extract docstrings from these functions:
528 531 i18nfunctions = [kwsvnrev, kwsvnpath, kwsvnuuid]
General Comments 0
You need to be logged in to leave comments. Login now