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