Debian Codegraph @

tests/test-convert.t

raw
1 $ cat >> $HGRCPATH <<EOF
2 > [extensions]
3 > convert=
4 > [convert]
5 > hg.saverev=False
6 > EOF
7 $ hg help convert
8 hg convert [OPTION]... SOURCE [DEST [REVMAP]]
9
10 convert a foreign SCM repository to a Mercurial one.
11
12 Accepted source formats [identifiers]:
13
14 - Mercurial [hg]
15 - CVS [cvs]
16 - Darcs [darcs]
17 - git [git]
18 - Subversion [svn]
19 - Monotone [mtn]
20 - GNU Arch [gnuarch]
21 - Bazaar [bzr]
22 - Perforce [p4]
23
24 Accepted destination formats [identifiers]:
25
26 - Mercurial [hg]
27 - Subversion [svn] (history on branches is not preserved)
28
29 If no revision is given, all revisions will be converted. Otherwise, convert
30 will only import up to the named revision (given in a format understood by the
31 source).
32
33 If no destination directory name is specified, it defaults to the basename of
34 the source with "-hg" appended. If the destination repository doesn't exist,
35 it will be created.
36
37 By default, all sources except Mercurial will use --branchsort. Mercurial uses
38 --sourcesort to preserve original revision numbers order. Sort modes have the
39 following effects:
40
41 --branchsort convert from parent to child revision when possible, which
42 means branches are usually converted one after the other.
43 It generates more compact repositories.
44 --datesort sort revisions by date. Converted repositories have good-
45 looking changelogs but are often an order of magnitude
46 larger than the same ones generated by --branchsort.
47 --sourcesort try to preserve source revisions order, only supported by
48 Mercurial sources.
49 --closesort try to move closed revisions as close as possible to parent
50 branches, only supported by Mercurial sources.
51
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 maps
54 each source commit ID to the destination ID for that revision, like so:
55
56 <source ID> <destination ID>
57
58 If the file doesn't exist, it's automatically created. It's updated on each
59 commit copied, so 'hg convert' can be interrupted and can be run repeatedly to
60 copy new commits.
61
62 The authormap is a simple text file that maps each source commit author to a
63 destination commit author. It is handy for source SCMs that use unix logins to
64 identify authors (e.g.: CVS). One line per author mapping and the line format
65 is:
66
67 source author = destination author
68
69 Empty lines and lines starting with a "#" are ignored.
70
71 The filemap is a file that allows filtering and remapping of files and
72 directories. Each line can contain one of the following directives:
73
74 include path/to/file-or-dir
75
76 exclude path/to/file-or-dir
77
78 rename path/to/source path/to/destination
79
80 Comment lines start with "#". A specified path matches if it equals the full
81 relative name of a file or one of its parent directories. The "include" or
82 "exclude" directive with the longest matching path applies, so line order does
83 not matter.
84
85 The "include" directive causes a file, or all files under a directory, to be
86 included in the destination repository. The default if there are no "include"
87 statements is to include everything. If there are any "include" statements,
88 nothing else is included. The "exclude" directive causes files or directories
89 to be omitted. The "rename" directive renames a file or directory if it is
90 converted. To rename from a subdirectory into the root of the repository, use
91 "." as the path to rename to.
92
93 "--full" will make sure the converted changesets contain exactly the right
94 files with the right content. It will make a full conversion of all files, not
95 just the ones that have changed. Files that already are correct will not be
96 changed. This can be used to apply filemap changes when converting
97 incrementally. This is currently only supported for Mercurial and Subversion.
98
99 The splicemap is a file that allows insertion of synthetic history, letting
100 you specify the parents of a revision. This is useful if you want to e.g. give
101 a Subversion merge two parents, or graft two disconnected series of history
102 together. Each entry contains a key, followed by a space, followed by one or
103 two comma-separated values:
104
105 key parent1, parent2
106
107 The key is the revision ID in the source revision control system whose parents
108 should be modified (same format as a key in .hg/shamap). The values are the
109 revision IDs (in either the source or destination revision control system)
110 that should be used as the new parents for that node. For example, if you have
111 merged "release-1.0" into "trunk", then you should specify the revision on
112 "trunk" as the first parent and the one on the "release-1.0" branch as the
113 second.
114
115 The branchmap is a file that allows you to rename a branch when it is being
116 brought in from whatever external repository. When used in conjunction with a
117 splicemap, it allows for a powerful combination to help fix even the most
118 badly mismanaged repositories and turn them into nicely structured Mercurial
119 repositories. The branchmap contains lines of the form:
120
121 original_branch_name new_branch_name
122
123 where "original_branch_name" is the name of the branch in the source
124 repository, and "new_branch_name" is the name of the branch is the destination
125 repository. No whitespace is allowed in the new branch name. This can be used
126 to (for instance) move code in one repository from "default" to a named
127 branch.
128
129 Mercurial Source
130 ################
131
132 The Mercurial source recognizes the following configuration options, which you
133 can set on the command line with "--config":
134
135 convert.hg.ignoreerrors
136 ignore integrity errors when reading. Use it to fix Mercurial
137 repositories with missing revlogs, by converting from and to
138 Mercurial. Default is False.
139 convert.hg.saverev
140 store original revision ID in changeset (forces target IDs to
141 change). It takes a boolean argument and defaults to False.
142 convert.hg.startrev
143 specify the initial Mercurial revision. The default is 0.
144 convert.hg.revs
145 revset specifying the source revisions to convert.
146
147 Bazaar Source
148 #############
149
150 The following options can be used with "--config":
151
152 convert.bzr.saverev
153 whether to store the original Bazaar commit ID in the metadata
154 of the destination commit. The default is True.
155
156 CVS Source
157 ##########
158
159 CVS source will use a sandbox (i.e. a checked-out copy) from CVS to indicate
160 the starting point of what will be converted. Direct access to the repository
161 files is not needed, unless of course the repository is ":local:". The
162 conversion uses the top level directory in the sandbox to find the CVS
163 repository, and then uses CVS rlog commands to find files to convert. This
164 means that unless a filemap is given, all files under the starting directory
165 will be converted, and that any directory reorganization in the CVS sandbox is
166 ignored.
167
168 The following options can be used with "--config":
169
170 convert.cvsps.cache
171 Set to False to disable remote log caching, for testing and
172 debugging purposes. Default is True.
173 convert.cvsps.fuzz
174 Specify the maximum time (in seconds) that is allowed between
175 commits with identical user and log message in a single
176 changeset. When very large files were checked in as part of a
177 changeset then the default may not be long enough. The default
178 is 60.
179 convert.cvsps.logencoding
180 Specify encoding name to be used for transcoding CVS log
181 messages. Multiple encoding names can be specified as a list
182 (see 'hg help config.Syntax'), but only the first acceptable
183 encoding in the list is used per CVS log entries. This
184 transcoding is executed before cvslog hook below.
185 convert.cvsps.mergeto
186 Specify a regular expression to which commit log messages are
187 matched. If a match occurs, then the conversion process will
188 insert a dummy revision merging the branch on which this log
189 message occurs to the branch indicated in the regex. Default is
190 "{{mergetobranch ([-\w]+)}}"
191 convert.cvsps.mergefrom
192 Specify a regular expression to which commit log messages are
193 matched. If a match occurs, then the conversion process will add
194 the most recent revision on the branch indicated in the regex as
195 the second parent of the changeset. Default is
196 "{{mergefrombranch ([-\w]+)}}"
197 convert.localtimezone
198 use local time (as determined by the TZ environment variable)
199 for changeset date/times. The default is False (use UTC).
200 hooks.cvslog Specify a Python function to be called at the end of gathering
201 the CVS log. The function is passed a list with the log entries,
202 and can modify the entries in-place, or add or delete them.
203 hooks.cvschangesets
204 Specify a Python function to be called after the changesets are
205 calculated from the CVS log. The function is passed a list with
206 the changeset entries, and can modify the changesets in-place,
207 or add or delete them.
208
209 An additional "debugcvsps" Mercurial command allows the builtin changeset
210 merging code to be run without doing a conversion. Its parameters and output
211 are similar to that of cvsps 2.1. Please see the command help for more
212 details.
213
214 Subversion Source
215 #################
216
217 Subversion source detects classical trunk/branches/tags layouts. By default,
218 the supplied "svn://repo/path/" source URL is converted as a single branch. If
219 "svn://repo/path/trunk" exists it replaces the default branch. If
220 "svn://repo/path/branches" exists, its subdirectories are listed as possible
221 branches. If "svn://repo/path/tags" exists, it is looked for tags referencing
222 converted branches. Default "trunk", "branches" and "tags" values can be
223 overridden with following options. Set them to paths relative to the source
224 URL, or leave them blank to disable auto detection.
225
226 The following options can be set with "--config":
227
228 convert.svn.branches
229 specify the directory containing branches. The default is
230 "branches".
231 convert.svn.tags
232 specify the directory containing tags. The default is "tags".
233 convert.svn.trunk
234 specify the name of the trunk branch. The default is "trunk".
235 convert.localtimezone
236 use local time (as determined by the TZ environment variable)
237 for changeset date/times. The default is False (use UTC).
238
239 Source history can be retrieved starting at a specific revision, instead of
240 being integrally converted. Only single branch conversions are supported.
241
242 convert.svn.startrev
243 specify start Subversion revision number. The default is 0.
244
245 Git Source
246 ##########
247
248 The Git importer converts commits from all reachable branches (refs in
249 refs/heads) and remotes (refs in refs/remotes) to Mercurial. Branches are
250 converted to bookmarks with the same name, with the leading 'refs/heads'
251 stripped. Git submodules are converted to Git subrepos in Mercurial.
252
253 The following options can be set with "--config":
254
255 convert.git.similarity
256 specify how similar files modified in a commit must be to be
257 imported as renames or copies, as a percentage between "0"
258 (disabled) and "100" (files must be identical). For example,
259 "90" means that a delete/add pair will be imported as a rename
260 if more than 90% of the file hasn't changed. The default is
261 "50".
262 convert.git.findcopiesharder
263 while detecting copies, look at all files in the working copy
264 instead of just changed ones. This is very expensive for large
265 projects, and is only effective when "convert.git.similarity" is
266 greater than 0. The default is False.
267 convert.git.renamelimit
268 perform rename and copy detection up to this many changed files
269 in a commit. Increasing this will make rename and copy detection
270 more accurate but will significantly slow down computation on
271 large projects. The option is only relevant if
272 "convert.git.similarity" is greater than 0. The default is
273 "400".
274 convert.git.committeractions
275 list of actions to take when processing author and committer
276 values.
277
278 Git commits have separate author (who wrote the commit) and committer (who
279 applied the commit) fields. Not all destinations support separate author
280 and committer fields (including Mercurial). This config option controls
281 what to do with these author and committer fields during conversion.
282
283 A value of "messagedifferent" will append a "committer: ..." line to the
284 commit message if the Git committer is different from the author. The
285 prefix of that line can be specified using the syntax
286 "messagedifferent=<prefix>". e.g. "messagedifferent=git-committer:". When
287 a prefix is specified, a space will always be inserted between the prefix
288 and the value.
289
290 "messagealways" behaves like "messagedifferent" except it will always
291 result in a "committer: ..." line being appended to the commit message.
292 This value is mutually exclusive with "messagedifferent".
293
294 "dropcommitter" will remove references to the committer. Only references
295 to the author will remain. Actions that add references to the committer
296 will have no effect when this is set.
297
298 "replaceauthor" will replace the value of the author field with the
299 committer. Other actions that add references to the committer will still
300 take effect when this is set.
301
302 The default is "messagedifferent".
303
304 convert.git.extrakeys
305 list of extra keys from commit metadata to copy to the
306 destination. Some Git repositories store extra metadata in
307 commits. By default, this non-default metadata will be lost
308 during conversion. Setting this config option can retain that
309 metadata. Some built-in keys such as "parent" and "branch" are
310 not allowed to be copied.
311 convert.git.remoteprefix
312 remote refs are converted as bookmarks with
313 "convert.git.remoteprefix" as a prefix followed by a /. The
314 default is 'remote'.
315 convert.git.saverev
316 whether to store the original Git commit ID in the metadata of
317 the destination commit. The default is True.
318 convert.git.skipsubmodules
319 does not convert root level .gitmodules files or files with
320 160000 mode indicating a submodule. Default is False.
321
322 Perforce Source
323 ###############
324
325 The Perforce (P4) importer can be given a p4 depot path or a client
326 specification as source. It will convert all files in the source to a flat
327 Mercurial repository, ignoring labels, branches and integrations. Note that
328 when a depot path is given you then usually should specify a target directory,
329 because otherwise the target may be named "...-hg".
330
331 The following options can be set with "--config":
332
333 convert.p4.encoding
334 specify the encoding to use when decoding standard output of the
335 Perforce command line tool. The default is default system
336 encoding.
337 convert.p4.startrev
338 specify initial Perforce revision (a Perforce changelist
339 number).
340
341 Mercurial Destination
342 #####################
343
344 The Mercurial destination will recognize Mercurial subrepositories in the
345 destination directory, and update the .hgsubstate file automatically if the
346 destination subrepositories contain the <dest>/<sub>/.hg/shamap file.
347 Converting a repository with subrepositories requires converting a single
348 repository at a time, from the bottom up.
349
350 The following options are supported:
351
352 convert.hg.clonebranches
353 dispatch source branches in separate clones. The default is
354 False.
355 convert.hg.tagsbranch
356 branch name for tag revisions, defaults to "default".
357 convert.hg.usebranchnames
358 preserve branch names. The default is True.
359 convert.hg.sourcename
360 records the given string as a 'convert_source' extra value on
361 each commit made in the target repository. The default is None.
362 convert.hg.preserve-hash
363 only works with mercurial sources. Make convert prevent
364 performance improvement to the list of modified files in commits
365 when such an improvement would cause the hash of a commit to
366 change. The default is False.
367
368 All Destinations
369 ################
370
371 All destination types accept the following options:
372
373 convert.skiptags
374 does not convert tags from the source repo to the target repo.
375 The default is False.
376
377 Subversion Destination
378 ######################
379
380 Original commit dates are not preserved by default.
381
382 convert.svn.dangerous-set-commit-dates
383 preserve original commit dates, forcefully setting "svn:date"
384 revision properties. This option is DANGEROUS and may break some
385 subversion functionality for the resulting repository (e.g.
386 filtering revisions with date ranges in "svn log"), as original
387 commit dates are not guaranteed to be monotonically increasing.
388
389 For commit dates setting to work destination repository must have "pre-
390 revprop-change" hook configured to allow setting of "svn:date" revision
391 properties. See Subversion documentation for more details.
392
393 options ([+] can be repeated):
394
395 -s --source-type TYPE source repository type
396 -d --dest-type TYPE destination repository type
397 -r --rev REV [+] import up to source revision REV
398 -A --authormap FILE remap usernames using this file
399 --filemap FILE remap file names using contents of file
400 --full apply filemap changes by converting all files again
401 --splicemap FILE splice synthesized history into place
402 --branchmap FILE change branch names while converting
403 --branchsort try to sort changesets by branches
404 --datesort try to sort changesets by date
405 --sourcesort preserve source changesets order
406 --closesort try to reorder closed revisions
407
408 (some details hidden, use --verbose to show complete help)
409 $ hg init a
410 $ cd a
411 $ echo a > a
412 $ hg ci -d'0 0' -Ama
413 adding a
414 $ hg cp a b
415 $ hg ci -d'1 0' -mb
416 $ hg rm a
417 $ hg ci -d'2 0' -mc
418 $ hg mv b a
419 $ hg ci -d'3 0' -md
420 $ echo a >> a
421 $ hg ci -d'4 0' -me
422 $ cd ..
423 $ hg convert a 2>&1 | grep -v 'subversion python bindings could not be loaded'
424 assuming destination a-hg
425 initializing destination a-hg repository
426 scanning source...
427 sorting...
428 converting...
429 4 a
430 3 b
431 2 c
432 1 d
433 0 e
434 $ hg --cwd a-hg pull ../a
435 pulling from ../a
436 searching for changes
437 no changes found
438 5 local changesets published
439
440 conversion to existing file should fail
441
442 $ touch bogusfile
443 $ hg convert a bogusfile
444 initializing destination bogusfile repository
445 abort: cannot create new bundle repository
446 [255]
447
448 #if unix-permissions no-root
449
450 conversion to dir without permissions should fail
451
452 $ mkdir bogusdir
453 $ chmod 000 bogusdir
454
455 $ hg convert a bogusdir
456 abort: $EACCES$: *bogusdir* (glob)
457 [255]
458
459 user permissions should succeed
460
461 $ chmod 700 bogusdir
462 $ hg convert a bogusdir
463 initializing destination bogusdir repository
464 scanning source...
465 sorting...
466 converting...
467 4 a
468 3 b
469 2 c
470 1 d
471 0 e
472
473 #endif
474
475 test pre and post conversion actions
476
477 $ echo 'include b' > filemap
478 $ hg convert --debug --filemap filemap a partialb | \
479 > grep 'run hg'
480 run hg source pre-conversion action
481 run hg sink pre-conversion action
482 run hg sink post-conversion action
483 run hg source post-conversion action
484
485 converting empty dir should fail "nicely
486
487 $ mkdir emptydir
488
489 override $PATH to ensure p4 not visible; use $PYTHON in case we're
490 running from a devel copy, not a temp installation
491
492 $ PATH="$BINDIR" "$PYTHON" "$BINDIR"/hg convert emptydir
493 assuming destination emptydir-hg
494 initializing destination emptydir-hg repository
495 emptydir does not look like a CVS checkout
496 $TESTTMP/emptydir does not look like a Git repository
497 emptydir does not look like a Subversion repository
498 emptydir is not a local Mercurial repository
499 emptydir does not look like a darcs repository
500 emptydir does not look like a monotone repository
501 emptydir does not look like a GNU Arch repository
502 emptydir does not look like a Bazaar repository
503 cannot find required "p4" tool
504 abort: emptydir: missing or unsupported repository
505 [255]
506
507 convert with imaginary source type
508
509 $ hg convert --source-type foo a a-foo
510 initializing destination a-foo repository
511 abort: foo: invalid source repository type
512 [255]
513
514 convert with imaginary sink type
515
516 $ hg convert --dest-type foo a a-foo
517 abort: foo: invalid destination repository type
518 [255]
519
520 testing: convert must not produce duplicate entries in fncache
521
522 $ hg convert a b
523 initializing destination b repository
524 scanning source...
525 sorting...
526 converting...
527 4 a
528 3 b
529 2 c
530 1 d
531 0 e
532
533 contents of fncache file:
534
535 $ cat b/.hg/store/fncache | sort
536 data/a.i
537 data/b.i
538
539 test bogus URL
540
541 #if no-msys
542 $ hg convert -q bzr+ssh://[email protected]/baz baz
543 abort: bzr+ssh://[email protected]/baz: missing or unsupported repository
544 [255]
545 #endif
546
547 test revset converted() lookup
548
549 $ hg --config convert.hg.saverev=True convert a c
550 initializing destination c repository
551 scanning source...
552 sorting...
553 converting...
554 4 a
555 3 b
556 2 c
557 1 d
558 0 e
559 $ echo f > c/f
560 $ hg -R c ci -d'0 0' -Amf
561 adding f
562 created new head
563 $ hg -R c log -r "converted(09d945a62ce6)"
564 changeset: 1:98c3dd46a874
565 user: test
566 date: Thu Jan 01 00:00:01 1970 +0000
567 summary: b
568
569 $ hg -R c log -r "converted()"
570 changeset: 0:31ed57b2037c
571 user: test
572 date: Thu Jan 01 00:00:00 1970 +0000
573 summary: a
574
575 changeset: 1:98c3dd46a874
576 user: test
577 date: Thu Jan 01 00:00:01 1970 +0000
578 summary: b
579
580 changeset: 2:3b9ca06ef716
581 user: test
582 date: Thu Jan 01 00:00:02 1970 +0000
583 summary: c
584
585 changeset: 3:4e0debd37cf2
586 user: test
587 date: Thu Jan 01 00:00:03 1970 +0000
588 summary: d
589
590 changeset: 4:9de3bc9349c5
591 user: test
592 date: Thu Jan 01 00:00:04 1970 +0000
593 summary: e
594
595
596 test specifying a sourcename
597 $ echo g > a/g
598 $ hg -R a ci -d'0 0' -Amg
599 adding g
600 $ hg --config convert.hg.sourcename=mysource --config convert.hg.saverev=True convert a c
601 scanning source...
602 sorting...
603 converting...
604 0 g
605 $ hg -R c log -r tip --template '{extras % "{extra}\n"}'
606 branch=default
607 convert_revision=a3bc6100aa8ec03e00aaf271f1f50046fb432072
608 convert_source=mysource
609
610 $ cat > branchmap.txt << EOF
611 > old branch new_branch
612 > EOF
613
614 $ hg -R a branch -q 'old branch'
615 $ echo gg > a/g
616 $ hg -R a ci -m 'branch name with spaces'
617 $ hg convert --branchmap branchmap.txt a d
618 initializing destination d repository
619 scanning source...
620 sorting...
621 converting...
622 6 a
623 5 b
624 4 c
625 3 d
626 2 e
627 1 g
628 0 branch name with spaces
629
630 $ hg -R a branches
631 old branch 6:a24a66ade009
632 default 5:a3bc6100aa8e (inactive)
633 $ hg -R d branches
634 new_branch 6:64ed208b732b
635 default 5:a3bc6100aa8e (inactive)