Mercurial > hg-stable
annotate hgext/convert/cvs.py @ 50168:de42ba9dd852
dirstate: use the new `check_invalidated` decorator for `_changing`
WeeeEEeee, less code.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 20 Feb 2023 15:52:55 +0100 |
parents | 8f9fbc665928 |
children | 18c8c18993f0 |
rev | line source |
---|---|
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
1 # cvs.py: CVS conversion code inspired by hg-cvs-import and git-cvsimport |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
44926
diff
changeset
|
3 # Copyright 2005-2009 Olivia Mackall <olivia@selenic.com> and others |
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
4 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4515
diff
changeset
|
7 |
28413
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
8 import errno |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
9 import os |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
10 import re |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
11 import socket |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
12 |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28861
diff
changeset
|
13 from mercurial.i18n import _ |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
14 from mercurial.pycompat import ( |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
15 getattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
16 open, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
17 ) |
28413
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
18 from mercurial import ( |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
19 encoding, |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
20 error, |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
21 util, |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
22 ) |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
23 from mercurial.utils import ( |
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
24 dateutil, |
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
25 procutil, |
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
26 ) |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
27 |
28413
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
28 from . import ( |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
29 common, |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
30 cvsps, |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
31 ) |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
32 |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28413
diff
changeset
|
33 stringio = util.stringio |
28413
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
34 checktool = common.checktool |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
35 commit = common.commit |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
36 converter_source = common.converter_source |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
37 makedatetimestamp = common.makedatetimestamp |
6bda82107e05
convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
38 NoRepo = common.NoRepo |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
39 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
40 |
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
41 class convert_cvs(converter_source): |
35187
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34168
diff
changeset
|
42 def __init__(self, ui, repotype, path, revs=None): |
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34168
diff
changeset
|
43 super(convert_cvs, self).__init__(ui, repotype, path, revs=revs) |
4807
15a3cbfc6568
convert: call superclass init from engine init functions
Brendan Cully <brendan@kublai.com>
parents:
4762
diff
changeset
|
44 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
45 cvs = os.path.join(path, b"CVS") |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
46 if not os.path.exists(cvs): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
47 raise NoRepo(_(b"%s does not look like a CVS checkout") % path) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
48 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 checktool(b'cvs') |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5381
diff
changeset
|
50 |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
51 self.changeset = None |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
52 self.files = {} |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
53 self.tags = {} |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
54 self.lastbranch = {} |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
55 self.socket = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
56 self.cvsroot = open(os.path.join(cvs, b"Root"), b'rb').read()[:-1] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 self.cvsrepo = open(os.path.join(cvs, b"Repository"), b'rb').read()[:-1] |
11987
3145951e50fe
convert: use encoding.encoding instead of locale.getpreferredencoding()
Brodie Rao <brodie@bitheap.org>
parents:
11134
diff
changeset
|
58 self.encoding = encoding.encoding |
6690
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
59 |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
60 self._connect() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
61 |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
62 def _parse(self): |
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
63 if self.changeset is not None: |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
64 return |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
65 self.changeset = {} |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
66 |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
67 maxrev = 0 |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
68 if self.revs: |
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
69 if len(self.revs) > 1: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
70 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 b'cvs source does not support specifying ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
73 b'multiple revs' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
74 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
75 ) |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
76 # TODO: handle tags |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
77 try: |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
78 # patchset number? |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
79 maxrev = int(self.revs[0]) |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
80 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
81 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 _(b'revision %s is not a patchset number') % self.revs[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
83 ) |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
84 |
39823
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37658
diff
changeset
|
85 d = encoding.getcwd() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
86 try: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
87 os.chdir(self.path) |
6690
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
88 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
89 cache = b'update' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
90 if not self.ui.configbool(b'convert', b'cvsps.cache'): |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
91 cache = None |
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
92 db = cvsps.createlog(self.ui, cache=cache) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
93 db = cvsps.createchangeset( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
94 self.ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
95 db, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
96 fuzz=int(self.ui.config(b'convert', b'cvsps.fuzz')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 mergeto=self.ui.config(b'convert', b'cvsps.mergeto'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 mergefrom=self.ui.config(b'convert', b'cvsps.mergefrom'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
99 ) |
5920
5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5521
diff
changeset
|
100 |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
101 for cs in db: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
102 if maxrev and cs.id > maxrev: |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
103 break |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
104 id = b"%d" % cs.id |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
105 cs.author = self.recode(cs.author) |
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
106 self.lastbranch[cs.branch] = id |
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
107 cs.comment = self.recode(cs.comment) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
108 if self.ui.configbool(b'convert', b'localtimezone'): |
17974
337d728e644f
convert: add config option to use the local time zone
Julian Cowley <julian@lava.net>
parents:
17424
diff
changeset
|
109 cs.date = makedatetimestamp(cs.date[0]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
110 date = dateutil.datestr(cs.date, b'%Y-%m-%d %H:%M:%S %1%2') |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
111 self.tags.update(dict.fromkeys(cs.tags, id)) |
5920
5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5521
diff
changeset
|
112 |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
113 files = {} |
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
114 for f in cs.entries: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 files[f.file] = b"%s%s" % ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
116 b'.'.join([(b"%d" % x) for x in f.revision]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
117 [b'', b'(DEAD)'][f.dead], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
118 ) |
6690
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
119 |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
120 # add current commit to set |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
121 c = commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
122 author=cs.author, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
123 date=date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
124 parents=[(b"%d" % p.id) for p in cs.parents], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
125 desc=cs.comment, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
126 branch=cs.branch or b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
127 ) |
9543
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
128 self.changeset[id] = c |
56a5f80556f5
convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents:
9102
diff
changeset
|
129 self.files[id] = files |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
130 |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
131 self.heads = self.lastbranch.values() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
132 finally: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
133 os.chdir(d) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
134 |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
135 def _connect(self): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
136 root = self.cvsroot |
4047 | 137 conntype = None |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
138 user, host = None, None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 cmd = [b'cvs', b'server'] |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
140 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 self.ui.status(_(b"connecting to %s\n") % root) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
142 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 if root.startswith(b":pserver:"): |
4047 | 144 root = root[9:] |
49633
9282930f8b52
convert: turn the last str regex into bytes in cvs.py (issue6789)
Anton Shestakov <av6@dwimlabs.net>
parents:
49005
diff
changeset
|
145 m = re.match( |
9282930f8b52
convert: turn the last str regex into bytes in cvs.py (issue6789)
Anton Shestakov <av6@dwimlabs.net>
parents:
49005
diff
changeset
|
146 br'(?:(.*?)(?::(.*?))?@)?([^:/]*)(?::(\d*))?(.*)', root |
9282930f8b52
convert: turn the last str regex into bytes in cvs.py (issue6789)
Anton Shestakov <av6@dwimlabs.net>
parents:
49005
diff
changeset
|
147 ) |
4047 | 148 if m: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
149 conntype = b"pserver" |
4047 | 150 user, passw, serv, port, root = m.groups() |
151 if not user: | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
152 user = b"anonymous" |
5082
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
153 if not port: |
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
154 port = 2401 |
4047 | 155 else: |
5082
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
156 port = int(port) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 format0 = b":pserver:%s@%s:%s" % (user, serv, root) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 format1 = b":pserver:%s@%s:%d%s" % (user, serv, port, root) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
159 |
4047 | 160 if not passw: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 passw = b"A" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 cvspass = os.path.expanduser(b"~/.cvspass") |
7444
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
163 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 pf = open(cvspass, b'rb') |
7442
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
165 for line in pf.read().splitlines(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 part1, part2 = line.split(b' ', 1) |
16683 | 167 # /1 :pserver:user@example.com:2401/cvsroot/foo |
168 # Ah<Z | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
169 if part1 == b'/1': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
170 part1, part2 = part2.split(b' ', 1) |
7442
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
171 format = format1 |
16683 | 172 # :pserver:user@example.com:/cvsroot/foo Ah<Z |
7442
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
173 else: |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
174 format = format0 |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
175 if part1 == format: |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
176 passw = part2 |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
177 break |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
178 pf.close() |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
179 except IOError as inst: |
7444
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
180 if inst.errno != errno.ENOENT: |
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
181 if not getattr(inst, 'filename', None): |
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
182 inst.filename = cvspass |
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
183 raise |
4047 | 184 |
185 sck = socket.socket() | |
186 sck.connect((serv, port)) | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
187 sck.send( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 b"\n".join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
189 [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 b"BEGIN AUTH REQUEST", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
191 root, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
192 user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
193 passw, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
194 b"END AUTH REQUEST", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 b"", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
196 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
197 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
198 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 if sck.recv(128) != b"I LOVE YOU\n": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 raise error.Abort(_(b"CVS pserver authentication failed")) |
4047 | 201 |
49634
8f9fbc665928
convert: change socket mode from b'r+' to 'rwb' in cvs.py (issue6789)
Anton Shestakov <av6@dwimlabs.net>
parents:
49633
diff
changeset
|
202 self.writep = self.readp = sck.makefile('rwb') |
4047 | 203 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 if not conntype and root.startswith(b":local:"): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 conntype = b"local" |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
206 root = root[7:] |
4047 | 207 |
208 if not conntype: | |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
209 # :ext:user@host/home/user/path/to/cvsroot |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
210 if root.startswith(b":ext:"): |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
211 root = root[5:] |
36423
54f4328a07c2
py3: make sure regexes are bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36170
diff
changeset
|
212 m = re.match(br'(?:([^@:/]+)@)?([^:/]+):?(.*)', root) |
5304
b85f7cc133cc
convert: avoid interpreting Windows path as CVS connection strings.
Patrick Mezard <pmezard@gmail.com>
parents:
5303
diff
changeset
|
213 # Do not take Windows path "c:\foo\bar" for a connection strings |
b85f7cc133cc
convert: avoid interpreting Windows path as CVS connection strings.
Patrick Mezard <pmezard@gmail.com>
parents:
5303
diff
changeset
|
214 if os.path.isdir(root) or not m: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 conntype = b"local" |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
216 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 conntype = b"rsh" |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
218 user, host, root = m.group(1), m.group(2), m.group(3) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
219 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
220 if conntype != b"pserver": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 if conntype == b"rsh": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
222 rsh = encoding.environ.get(b"CVS_RSH") or b"ssh" |
4047 | 223 if user: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
224 cmd = [rsh, b'-l', user, host] + cmd |
4047 | 225 else: |
226 cmd = [rsh, host] + cmd | |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
227 |
5303
a76c61679b71
convert: call popen2 in binary mode, with a command string.
Patrick Mezard <pmezard@gmail.com>
parents:
5082
diff
changeset
|
228 # popen2 does not support argument lists under Windows |
44926
8e8fd938ca07
cleanup: eliminate procutil.quotecommand()
Manuel Jacob <me@manueljacob.de>
parents:
44023
diff
changeset
|
229 cmd = b' '.join(procutil.shellquote(arg) for arg in cmd) |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
230 self.writep, self.readp = procutil.popen2(cmd) |
4047 | 231 |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
232 self.realroot = root |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
233 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
234 self.writep.write(b"Root %s\n" % root) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
235 self.writep.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 b"Valid-responses ok error Valid-requests Mode" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 b" M Mbinary E Checked-in Created Updated" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 b" Merged Removed\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
239 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
240 self.writep.write(b"valid-requests\n") |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
241 self.writep.flush() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
242 r = self.readp.readline() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
243 if not r.startswith(b"Valid-requests"): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
244 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
245 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 b'unexpected response from CVS server ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
247 b'(expected "Valid-requests", but got %r)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
248 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
249 % r |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
250 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
251 if b"UseUnchanged" in r: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
252 self.writep.write(b"UseUnchanged\n") |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
253 self.writep.flush() |
41387
876494fd967d
cleanup: delete lots of unused local variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
39823
diff
changeset
|
254 self.readp.readline() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
255 |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
256 def getheads(self): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
257 self._parse() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
258 return self.heads |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
259 |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
260 def getfile(self, name, rev): |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
261 def chunkedread(fp, count): |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16683
diff
changeset
|
262 # file-objects returned by socket.makefile() do not handle |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
263 # large read() requests very well. |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
264 chunksize = 65536 |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28413
diff
changeset
|
265 output = stringio() |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
266 while count > 0: |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
267 data = fp.read(min(count, chunksize)) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
268 if not data: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
269 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
270 _(b"%d bytes missing from remote file") % count |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
271 ) |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
272 count -= len(data) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
273 output.write(data) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
274 return output.getvalue() |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
275 |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
276 self._parse() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
277 if rev.endswith(b"(DEAD)"): |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17974
diff
changeset
|
278 return None, None |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
279 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
280 args = (b"-N -P -kk -r %s --" % rev).split() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
281 args.append(self.cvsrepo + b'/' + name) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
282 for x in args: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
283 self.writep.write(b"Argument %s\n" % x) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
284 self.writep.write(b"Directory .\n%s\nco\n" % self.realroot) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
285 self.writep.flush() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
286 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
287 data = b"" |
10800
49c109d037dd
convert.cvs: Initialize state variable and abort on cvs error
Mads Kiilerich <mads@kiilerich.com>
parents:
10282
diff
changeset
|
288 mode = None |
14494
1ffeeb91c55d
check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents:
12063
diff
changeset
|
289 while True: |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
290 line = self.readp.readline() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 if line.startswith(b"Created ") or line.startswith(b"Updated "): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
292 self.readp.readline() # path |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
293 self.readp.readline() # entries |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
294 mode = self.readp.readline()[:-1] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
295 count = int(self.readp.readline()[:-1]) |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
296 data = chunkedread(self.readp, count) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
297 elif line.startswith(b" "): |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
298 data += line[1:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
299 elif line.startswith(b"M "): |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
300 pass |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
301 elif line.startswith(b"Mbinary "): |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
302 count = int(self.readp.readline()[:-1]) |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
303 data = chunkedread(self.readp, count) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
304 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 if line == b"ok\n": |
10800
49c109d037dd
convert.cvs: Initialize state variable and abort on cvs error
Mads Kiilerich <mads@kiilerich.com>
parents:
10282
diff
changeset
|
306 if mode is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 raise error.Abort(_(b'malformed response from CVS')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
308 return (data, b"x" in mode and b"x" or b"") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
309 elif line.startswith(b"E "): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
310 self.ui.warn(_(b"cvs server: %s\n") % line[2:]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
311 elif line.startswith(b"Remove"): |
7874
d812029cda85
cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7519
diff
changeset
|
312 self.readp.readline() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
313 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 raise error.Abort(_(b"unknown CVS response: %s") % line) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
315 |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
316 def getchanges(self, rev, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
317 if full: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
318 raise error.Abort(_(b"convert from cvs does not support --full")) |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
319 self._parse() |
49005
417a1691a273
convert: remove pycompat.iteritems()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
320 return sorted(self.files[rev].items()), {}, set() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
321 |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
322 def getcommit(self, rev): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
323 self._parse() |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
324 return self.changeset[rev] |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
325 |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
326 def gettags(self): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
327 self._parse() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
328 return self.tags |
5381
6874368120dc
convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5308
diff
changeset
|
329 |
6874368120dc
convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5308
diff
changeset
|
330 def getchangedfiles(self, rev, i): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
331 self._parse() |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8169
diff
changeset
|
332 return sorted(self.files[rev]) |