##// END OF EJS Templates
convert: add svnrev, svnpath and svnuuid template keywords...
Patrick Mezard -
r13691:ad02eba5 default
parent child Browse files
Show More
@@ -1,336 +1,364
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 import convcmd
11 11 import cvsps
12 12 import subversion
13 from mercurial import commands
13 from mercurial import commands, templatekw
14 14 from mercurial.i18n import _
15 15
16 16 # Commands definition was moved elsewhere to ease demandload job.
17 17
18 18 def convert(ui, src, dest=None, revmapfile=None, **opts):
19 19 """convert a foreign SCM repository to a Mercurial one.
20 20
21 21 Accepted source formats [identifiers]:
22 22
23 23 - Mercurial [hg]
24 24 - CVS [cvs]
25 25 - Darcs [darcs]
26 26 - git [git]
27 27 - Subversion [svn]
28 28 - Monotone [mtn]
29 29 - GNU Arch [gnuarch]
30 30 - Bazaar [bzr]
31 31 - Perforce [p4]
32 32
33 33 Accepted destination formats [identifiers]:
34 34
35 35 - Mercurial [hg]
36 36 - Subversion [svn] (history on branches is not preserved)
37 37
38 38 If no revision is given, all revisions will be converted.
39 39 Otherwise, convert will only import up to the named revision
40 40 (given in a format understood by the source).
41 41
42 42 If no destination directory name is specified, it defaults to the
43 43 basename of the source with ``-hg`` appended. If the destination
44 44 repository doesn't exist, it will be created.
45 45
46 46 By default, all sources except Mercurial will use --branchsort.
47 47 Mercurial uses --sourcesort to preserve original revision numbers
48 48 order. Sort modes have the following effects:
49 49
50 50 --branchsort convert from parent to child revision when possible,
51 51 which means branches are usually converted one after
52 52 the other. It generates more compact repositories.
53 53
54 54 --datesort sort revisions by date. Converted repositories have
55 55 good-looking changelogs but are often an order of
56 56 magnitude larger than the same ones generated by
57 57 --branchsort.
58 58
59 59 --sourcesort try to preserve source revisions order, only
60 60 supported by Mercurial sources.
61 61
62 62 If ``REVMAP`` isn't given, it will be put in a default location
63 63 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
64 64 text file that maps each source commit ID to the destination ID
65 65 for that revision, like so::
66 66
67 67 <source ID> <destination ID>
68 68
69 69 If the file doesn't exist, it's automatically created. It's
70 70 updated on each commit copied, so :hg:`convert` can be interrupted
71 71 and can be run repeatedly to copy new commits.
72 72
73 73 The authormap is a simple text file that maps each source commit
74 74 author to a destination commit author. It is handy for source SCMs
75 75 that use unix logins to identify authors (eg: CVS). One line per
76 76 author mapping and the line format is::
77 77
78 78 source author = destination author
79 79
80 80 Empty lines and lines starting with a ``#`` are ignored.
81 81
82 82 The filemap is a file that allows filtering and remapping of files
83 83 and directories. Each line can contain one of the following
84 84 directives::
85 85
86 86 include path/to/file-or-dir
87 87
88 88 exclude path/to/file-or-dir
89 89
90 90 rename path/to/source path/to/destination
91 91
92 92 Comment lines start with ``#``. A specified path matches if it
93 93 equals the full relative name of a file or one of its parent
94 94 directories. The ``include`` or ``exclude`` directive with the
95 95 longest matching path applies, so line order does not matter.
96 96
97 97 The ``include`` directive causes a file, or all files under a
98 98 directory, to be included in the destination repository, and the
99 99 exclusion of all other files and directories not explicitly
100 100 included. The ``exclude`` directive causes files or directories to
101 101 be omitted. The ``rename`` directive renames a file or directory if
102 102 it is converted. To rename from a subdirectory into the root of
103 103 the repository, use ``.`` as the path to rename to.
104 104
105 105 The splicemap is a file that allows insertion of synthetic
106 106 history, letting you specify the parents of a revision. This is
107 107 useful if you want to e.g. give a Subversion merge two parents, or
108 108 graft two disconnected series of history together. Each entry
109 109 contains a key, followed by a space, followed by one or two
110 110 comma-separated values::
111 111
112 112 key parent1, parent2
113 113
114 114 The key is the revision ID in the source
115 115 revision control system whose parents should be modified (same
116 116 format as a key in .hg/shamap). The values are the revision IDs
117 117 (in either the source or destination revision control system) that
118 118 should be used as the new parents for that node. For example, if
119 119 you have merged "release-1.0" into "trunk", then you should
120 120 specify the revision on "trunk" as the first parent and the one on
121 121 the "release-1.0" branch as the second.
122 122
123 123 The branchmap is a file that allows you to rename a branch when it is
124 124 being brought in from whatever external repository. When used in
125 125 conjunction with a splicemap, it allows for a powerful combination
126 126 to help fix even the most badly mismanaged repositories and turn them
127 127 into nicely structured Mercurial repositories. The branchmap contains
128 128 lines of the form::
129 129
130 130 original_branch_name new_branch_name
131 131
132 132 where "original_branch_name" is the name of the branch in the
133 133 source repository, and "new_branch_name" is the name of the branch
134 134 is the destination repository. No whitespace is allowed in the
135 135 branch names. This can be used to (for instance) move code in one
136 136 repository from "default" to a named branch.
137 137
138 138 Mercurial Source
139 139 ''''''''''''''''
140 140
141 141 The Mercurial source recognizes the following configuration
142 142 options, which you can set on the command line with ``--config``:
143 143
144 144 :convert.hg.ignoreerrors: ignore integrity errors when reading.
145 145 Use it to fix Mercurial repositories with missing revlogs, by
146 146 converting from and to Mercurial. Default is False.
147 147
148 148 :convert.hg.saverev: store original revision ID in changeset
149 149 (forces target IDs to change). It takes and boolean argument
150 150 and defaults to False.
151 151
152 152 :convert.hg.startrev: convert start revision and its descendants.
153 153 It takes a hg revision identifier and defaults to 0.
154 154
155 155 CVS Source
156 156 ''''''''''
157 157
158 158 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
159 159 to indicate the starting point of what will be converted. Direct
160 160 access to the repository files is not needed, unless of course the
161 161 repository is ``:local:``. The conversion uses the top level
162 162 directory in the sandbox to find the CVS repository, and then uses
163 163 CVS rlog commands to find files to convert. This means that unless
164 164 a filemap is given, all files under the starting directory will be
165 165 converted, and that any directory reorganization in the CVS
166 166 sandbox is ignored.
167 167
168 168 The following options can be used with ``--config``:
169 169
170 170 :convert.cvsps.cache: Set to False to disable remote log caching,
171 171 for testing and debugging purposes. Default is True.
172 172
173 173 :convert.cvsps.fuzz: Specify the maximum time (in seconds) that is
174 174 allowed between commits with identical user and log message in
175 175 a single changeset. When very large files were checked in as
176 176 part of a changeset then the default may not be long enough.
177 177 The default is 60.
178 178
179 179 :convert.cvsps.mergeto: Specify a regular expression to which
180 180 commit log messages are matched. If a match occurs, then the
181 181 conversion process will insert a dummy revision merging the
182 182 branch on which this log message occurs to the branch
183 183 indicated in the regex. Default is ``{{mergetobranch
184 184 ([-\\w]+)}}``
185 185
186 186 :convert.cvsps.mergefrom: Specify a regular expression to which
187 187 commit log messages are matched. If a match occurs, then the
188 188 conversion process will add the most recent revision on the
189 189 branch indicated in the regex as the second parent of the
190 190 changeset. Default is ``{{mergefrombranch ([-\\w]+)}}``
191 191
192 192 :hook.cvslog: Specify a Python function to be called at the end of
193 193 gathering the CVS log. The function is passed a list with the
194 194 log entries, and can modify the entries in-place, or add or
195 195 delete them.
196 196
197 197 :hook.cvschangesets: Specify a Python function to be called after
198 198 the changesets are calculated from the the CVS log. The
199 199 function is passed a list with the changeset entries, and can
200 200 modify the changesets in-place, or add or delete them.
201 201
202 202 An additional "debugcvsps" Mercurial command allows the builtin
203 203 changeset merging code to be run without doing a conversion. Its
204 204 parameters and output are similar to that of cvsps 2.1. Please see
205 205 the command help for more details.
206 206
207 207 Subversion Source
208 208 '''''''''''''''''
209 209
210 210 Subversion source detects classical trunk/branches/tags layouts.
211 211 By default, the supplied ``svn://repo/path/`` source URL is
212 212 converted as a single branch. If ``svn://repo/path/trunk`` exists
213 213 it replaces the default branch. If ``svn://repo/path/branches``
214 214 exists, its subdirectories are listed as possible branches. If
215 215 ``svn://repo/path/tags`` exists, it is looked for tags referencing
216 216 converted branches. Default ``trunk``, ``branches`` and ``tags``
217 217 values can be overridden with following options. Set them to paths
218 218 relative to the source URL, or leave them blank to disable auto
219 219 detection.
220 220
221 221 The following options can be set with ``--config``:
222 222
223 223 :convert.svn.branches: specify the directory containing branches.
224 224 The default is ``branches``.
225 225
226 226 :convert.svn.tags: specify the directory containing tags. The
227 227 default is ``tags``.
228 228
229 229 :convert.svn.trunk: specify the name of the trunk branch. The
230 230 default is ``trunk``.
231 231
232 232 Source history can be retrieved starting at a specific revision,
233 233 instead of being integrally converted. Only single branch
234 234 conversions are supported.
235 235
236 236 :convert.svn.startrev: specify start Subversion revision number.
237 237 The default is 0.
238 238
239 239 Perforce Source
240 240 '''''''''''''''
241 241
242 242 The Perforce (P4) importer can be given a p4 depot path or a
243 243 client specification as source. It will convert all files in the
244 244 source to a flat Mercurial repository, ignoring labels, branches
245 245 and integrations. Note that when a depot path is given you then
246 246 usually should specify a target directory, because otherwise the
247 247 target may be named ``...-hg``.
248 248
249 249 It is possible to limit the amount of source history to be
250 250 converted by specifying an initial Perforce revision:
251 251
252 252 :convert.p4.startrev: specify initial Perforce revision (a
253 253 Perforce changelist number).
254 254
255 255 Mercurial Destination
256 256 '''''''''''''''''''''
257 257
258 258 The following options are supported:
259 259
260 260 :convert.hg.clonebranches: dispatch source branches in separate
261 261 clones. The default is False.
262 262
263 263 :convert.hg.tagsbranch: branch name for tag revisions, defaults to
264 264 ``default``.
265 265
266 266 :convert.hg.usebranchnames: preserve branch names. The default is
267 267 True.
268 268 """
269 269 return convcmd.convert(ui, src, dest, revmapfile, **opts)
270 270
271 271 def debugsvnlog(ui, **opts):
272 272 return subversion.debugsvnlog(ui, **opts)
273 273
274 274 def debugcvsps(ui, *args, **opts):
275 275 '''create changeset information from CVS
276 276
277 277 This command is intended as a debugging tool for the CVS to
278 278 Mercurial converter, and can be used as a direct replacement for
279 279 cvsps.
280 280
281 281 Hg debugcvsps reads the CVS rlog for current directory (or any
282 282 named directory) in the CVS repository, and converts the log to a
283 283 series of changesets based on matching commit log entries and
284 284 dates.'''
285 285 return cvsps.debugcvsps(ui, *args, **opts)
286 286
287 287 commands.norepo += " convert debugsvnlog debugcvsps"
288 288
289 289 cmdtable = {
290 290 "convert":
291 291 (convert,
292 292 [('', 'authors', '',
293 293 _('username mapping filename (DEPRECATED, use --authormap instead)'),
294 294 _('FILE')),
295 295 ('s', 'source-type', '',
296 296 _('source repository type'), _('TYPE')),
297 297 ('d', 'dest-type', '',
298 298 _('destination repository type'), _('TYPE')),
299 299 ('r', 'rev', '',
300 300 _('import up to target revision REV'), _('REV')),
301 301 ('A', 'authormap', '',
302 302 _('remap usernames using this file'), _('FILE')),
303 303 ('', 'filemap', '',
304 304 _('remap file names using contents of file'), _('FILE')),
305 305 ('', 'splicemap', '',
306 306 _('splice synthesized history into place'), _('FILE')),
307 307 ('', 'branchmap', '',
308 308 _('change branch names while converting'), _('FILE')),
309 309 ('', 'branchsort', None, _('try to sort changesets by branches')),
310 310 ('', 'datesort', None, _('try to sort changesets by date')),
311 311 ('', 'sourcesort', None, _('preserve source changesets order'))],
312 312 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
313 313 "debugsvnlog":
314 314 (debugsvnlog,
315 315 [],
316 316 'hg debugsvnlog'),
317 317 "debugcvsps":
318 318 (debugcvsps,
319 319 [
320 320 # Main options shared with cvsps-2.1
321 321 ('b', 'branches', [], _('only return changes on specified branches')),
322 322 ('p', 'prefix', '', _('prefix to remove from file names')),
323 323 ('r', 'revisions', [],
324 324 _('only return changes after or between specified tags')),
325 325 ('u', 'update-cache', None, _("update cvs log cache")),
326 326 ('x', 'new-cache', None, _("create new cvs log cache")),
327 327 ('z', 'fuzz', 60, _('set commit time fuzz in seconds')),
328 328 ('', 'root', '', _('specify cvsroot')),
329 329 # Options specific to builtin cvsps
330 330 ('', 'parents', '', _('show parent changesets')),
331 331 ('', 'ancestors', '', _('show current changeset in ancestor branches')),
332 332 # Options that are ignored for compatibility with cvsps-2.1
333 333 ('A', 'cvs-direct', None, _('ignored for compatibility')),
334 334 ],
335 335 _('hg debugcvsps [OPTION]... [PATH]...')),
336 336 }
337
338 def kwconverted(ctx, name):
339 rev = ctx.extra().get('convert_revision', '')
340 if rev.startswith('svn:'):
341 if name == 'svnrev':
342 return str(subversion.revsplit(rev)[2])
343 elif name == 'svnpath':
344 return subversion.revsplit(rev)[1]
345 elif name == 'svnuuid':
346 return subversion.revsplit(rev)[0]
347 return rev
348
349 def kwsvnrev(repo, ctx, **args):
350 """:svnrev: String. Converted subversion revision number."""
351 return kwconverted(ctx, 'svnrev')
352
353 def kwsvnpath(repo, ctx, **args):
354 """:svnpath: String. Converted subversion revision project path."""
355 return kwconverted(ctx, 'svnpath')
356
357 def kwsvnuuid(repo, ctx, **args):
358 """:svnuuid: String. Converted subversion revision repository identifier."""
359 return kwconverted(ctx, 'svnuuid')
360
361 def extsetup(ui):
362 templatekw.keywords['svnrev'] = kwsvnrev
363 templatekw.keywords['svnpath'] = kwsvnpath
364 templatekw.keywords['svnuuid'] = kwsvnuuid
@@ -1,86 +1,101
1 1
2 2 $ "$TESTDIR/hghave" svn svn-bindings || exit 80
3 3
4 4 $ cat >> $HGRCPATH <<EOF
5 5 > [extensions]
6 6 > convert =
7 7 > graphlog =
8 8 > EOF
9 9
10 10 $ svnadmin create svn-repo
11 11 $ svnadmin load -q svn-repo < "$TESTDIR/svn/branches.svndump"
12 12
13 13 Convert trunk and branches
14 14
15 15 $ cat > branchmap <<EOF
16 16 > old3 newbranch
17 17 > EOF
18 18 $ hg convert --branchmap=branchmap --datesort -r 10 svn-repo A-hg
19 19 initializing destination A-hg repository
20 20 scanning source...
21 21 sorting...
22 22 converting...
23 23 10 init projA
24 24 9 hello
25 25 8 branch trunk, remove c and dir
26 26 7 change a
27 27 6 change b
28 28 5 move and update c
29 29 4 move and update c
30 30 3 change b again
31 31 2 move to old2
32 32 1 move back to old
33 33 0 last change to a
34 34
35 Test template keywords
36
37 $ hg -R A-hg log --template '{rev} {svnuuid}{svnpath}@{svnrev}\n'
38 10 644ede6c-2b81-4367-9dc8-d786514f2cde/trunk@10
39 9 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old@9
40 8 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old2@8
41 7 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old@7
42 6 644ede6c-2b81-4367-9dc8-d786514f2cde/trunk@6
43 5 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old@6
44 4 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old@5
45 3 644ede6c-2b81-4367-9dc8-d786514f2cde/trunk@4
46 2 644ede6c-2b81-4367-9dc8-d786514f2cde/branches/old@3
47 1 644ede6c-2b81-4367-9dc8-d786514f2cde/trunk@2
48 0 644ede6c-2b81-4367-9dc8-d786514f2cde/trunk@1
49
35 50 Convert again
36 51
37 52 $ hg convert --branchmap=branchmap --datesort svn-repo A-hg
38 53 scanning source...
39 54 sorting...
40 55 converting...
41 56 0 branch trunk@1 into old3
42 57
43 58 $ cd A-hg
44 59 $ hg glog --template 'branch={branches} {rev} {desc|firstline} files: {files}\n'
45 60 o branch=newbranch 11 branch trunk@1 into old3 files:
46 61 |
47 62 | o branch= 10 last change to a files: a
48 63 | |
49 64 | | o branch=old 9 move back to old files:
50 65 | | |
51 66 | | o branch=old2 8 move to old2 files:
52 67 | | |
53 68 | | o branch=old 7 change b again files: b
54 69 | | |
55 70 | o | branch= 6 move and update c files: b
56 71 | | |
57 72 | | o branch=old 5 move and update c files: c
58 73 | | |
59 74 | | o branch=old 4 change b files: b
60 75 | | |
61 76 | o | branch= 3 change a files: a
62 77 | | |
63 78 | | o branch=old 2 branch trunk, remove c and dir files: c
64 79 | |/
65 80 | o branch= 1 hello files: a b c dir/e
66 81 |/
67 82 o branch= 0 init projA files:
68 83
69 84
70 85 $ hg branches
71 86 newbranch 11:08fca3ff8634
72 87 default 10:098988aa63ba
73 88 old 9:b308f345079b
74 89 old2 8:49f2336c7b8b (inactive)
75 90 $ hg tags -q
76 91 tip
77 92 $ cd ..
78 93
79 94 Test hg failing to call itself
80 95
81 96 $ HG=foobar hg convert svn-repo B-hg
82 97 * (glob)
83 98 initializing destination B-hg repository
84 99 abort: Mercurial failed to run itself, check hg executable is in PATH
85 100 [255]
86 101
General Comments 0
You need to be logged in to leave comments. Login now