annotate hgext/convert/cvs.py @ 40811:e13ab4acf555

rust: peek_mut optim for lazy ancestors This is one of the two optimizations that are also present in the Python code: replacing pairs of pop/push on the BinaryHeap by single updates, hence having it under the hood maintain its consistency (sift) only once. On Mozilla central, the measured gain (see details below) is around 7%. Creating the PeekMut object by calling peek_mut() right away instead of peek() first is less efficient (gain is only 4%, stats not included). Our interpretation is that its creation has a cost which is vasted in the cases where it ends by droping the value (Peekmut::pop() just does self.heap.pop() anyway). On the other hand, the immutable peek() is very fast: it's just taking a reference in the underlying vector. The Python version still has another optimization: if parent(current) == current-1, then the heap doesn't need to maintain its consistency, since we already know that it's bigger than all the others in the heap. Rust's BinaryHeap doesn't allow us to mutate its biggest element with no housekeeping, but we tried it anyway, with a copy of the BinaryHeap implementation with a dedicaded added method: it's not worth the technical debt in our opinion (we measured only a further 1.6% improvement). One possible explanation would be that the sift is really fast anyway in that case, whereas it's not in the case of Python, because it's at least partly done in slow Python code. Still it's possible that replacing BinaryHeap by something more dedicated to discrete ordered types could be faster. Measurements on mozilla-central: Three runs of 'hg perfancestors' on the parent changeset: Moyenne des médianes: 0.100587 ! wall 0.100062 comb 0.100000 user 0.100000 sys 0.000000 (best of 98) ! wall 0.135804 comb 0.130000 user 0.130000 sys 0.000000 (max of 98) ! wall 0.102864 comb 0.102755 user 0.099286 sys 0.003469 (avg of 98) ! wall 0.101486 comb 0.110000 user 0.110000 sys 0.000000 (median of 98) ! wall 0.096804 comb 0.090000 user 0.090000 sys 0.000000 (best of 100) ! wall 0.132235 comb 0.130000 user 0.120000 sys 0.010000 (max of 100) ! wall 0.100258 comb 0.100300 user 0.096000 sys 0.004300 (avg of 100) ! wall 0.098384 comb 0.100000 user 0.100000 sys 0.000000 (median of 100) ! wall 0.099925 comb 0.100000 user 0.100000 sys 0.000000 (best of 98) ! wall 0.133518 comb 0.140000 user 0.130000 sys 0.010000 (max of 98) ! wall 0.102381 comb 0.102449 user 0.098265 sys 0.004184 (avg of 98) ! wall 0.101891 comb 0.090000 user 0.090000 sys 0.000000 (median of 98) Mean of the medians: 0.100587 On the present changeset: ! wall 0.091344 comb 0.090000 user 0.090000 sys 0.000000 (best of 100) ! wall 0.122728 comb 0.120000 user 0.110000 sys 0.010000 (max of 100) ! wall 0.093268 comb 0.093300 user 0.089300 sys 0.004000 (avg of 100) ! wall 0.092567 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) ! wall 0.093294 comb 0.080000 user 0.080000 sys 0.000000 (best of 100) ! wall 0.144887 comb 0.150000 user 0.140000 sys 0.010000 (max of 100) ! wall 0.097708 comb 0.097700 user 0.093400 sys 0.004300 (avg of 100) ! wall 0.094980 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) ! wall 0.091262 comb 0.090000 user 0.080000 sys 0.010000 (best of 100) ! wall 0.123772 comb 0.130000 user 0.120000 sys 0.010000 (max of 100) ! wall 0.093188 comb 0.093200 user 0.089300 sys 0.003900 (avg of 100) ! wall 0.092364 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) Mean of the medians is 0.0933 Differential Revision: https://phab.mercurial-scm.org/D5358
author Georges Racinet <gracinet@anybox.fr>
date Thu, 29 Nov 2018 09:13:13 +0000
parents 24e493ec2229
children 876494fd967d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
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
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9543
diff changeset
6 # GNU General Public License version 2 or any later version.
28413
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
7 from __future__ import absolute_import
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4515
diff changeset
8
28413
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
9 import errno
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
10 import os
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
11 import re
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
12 import socket
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
13
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28861
diff changeset
14 from mercurial.i18n import _
28413
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
15 from mercurial import (
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
16 encoding,
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
17 error,
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
18 util,
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
19 )
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
20 from mercurial.utils import (
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
21 dateutil,
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
22 procutil,
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
23 )
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
24
28413
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
25 from . import (
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
26 common,
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
27 cvsps,
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
28 )
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
29
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28413
diff changeset
30 stringio = util.stringio
28413
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
31 checktool = common.checktool
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
32 commit = common.commit
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
33 converter_source = common.converter_source
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
34 makedatetimestamp = common.makedatetimestamp
6bda82107e05 convert: cvs use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
35 NoRepo = common.NoRepo
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
36
4448
af013ae3ca10 use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents: 4447
diff changeset
37 class convert_cvs(converter_source):
35176
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 34156
diff changeset
38 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: 34156
diff changeset
39 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
40
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
41 cvs = os.path.join(path, "CVS")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
42 if not os.path.exists(cvs):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10800
diff changeset
43 raise NoRepo(_("%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
44
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
45 checktool('cvs')
5497
f0a3918abd42 convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents: 5381
diff changeset
46
8048
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
47 self.changeset = None
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
48 self.files = {}
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
49 self.tags = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
50 self.lastbranch = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
51 self.socket = None
36132
42a393ea56d2 convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents: 35176
diff changeset
52 self.cvsroot = open(os.path.join(cvs, "Root"), 'rb').read()[:-1]
42a393ea56d2 convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents: 35176
diff changeset
53 self.cvsrepo = open(os.path.join(cvs, "Repository"), 'rb').read()[:-1]
11987
3145951e50fe convert: use encoding.encoding instead of locale.getpreferredencoding()
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
54 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
55
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
56 self._connect()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
57
8048
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
58 def _parse(self):
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
59 if self.changeset is not None:
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
60 return
8048
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
61 self.changeset = {}
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
62
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
63 maxrev = 0
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25660
diff changeset
64 if self.revs:
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25660
diff changeset
65 if len(self.revs) > 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
66 raise error.Abort(_('cvs source does not support specifying '
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25660
diff changeset
67 'multiple revs'))
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
68 # TODO: handle tags
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
69 try:
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
70 # patchset number?
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25660
diff changeset
71 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
72 except ValueError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
73 raise error.Abort(_('revision %s is not a patchset number')
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25660
diff changeset
74 % self.revs[0])
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
75
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 37658
diff changeset
76 d = encoding.getcwd()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
77 try:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
78 os.chdir(self.path)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
79 id = None
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
80
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
81 cache = 'update'
34153
8860100908eb configitems: register the 'convert.cvsps.cache' config
Boris Feld <boris.feld@octobus.net>
parents: 30638
diff changeset
82 if not self.ui.configbool('convert', 'cvsps.cache'):
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
83 cache = None
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
84 db = cvsps.createlog(self.ui, cache=cache)
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
85 db = cvsps.createchangeset(self.ui, db,
34154
50f1c2d98db0 configitems: register the 'convert.cvsps.fuzz' config
Boris Feld <boris.feld@octobus.net>
parents: 34153
diff changeset
86 fuzz=int(self.ui.config('convert', 'cvsps.fuzz')),
34156
698cccf1ad28 configitems: register the 'convert.cvsps.mergeto' config
Boris Feld <boris.feld@octobus.net>
parents: 34155
diff changeset
87 mergeto=self.ui.config('convert', 'cvsps.mergeto'),
34155
6ea92f1b7a87 configitems: register the 'convert.cvsps.mergefrom' config
Boris Feld <boris.feld@octobus.net>
parents: 34154
diff changeset
88 mergefrom=self.ui.config('convert', 'cvsps.mergefrom'))
5920
5df7cb799baf CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5521
diff changeset
89
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
90 for cs in db:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
91 if maxrev and cs.id > maxrev:
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
92 break
37658
34758397ad1b py3: use b"%d" instead of str() to convert integers to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37120
diff changeset
93 id = (b"%d" % cs.id)
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
94 cs.author = self.recode(cs.author)
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
95 self.lastbranch[cs.branch] = id
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
96 cs.comment = self.recode(cs.comment)
17974
337d728e644f convert: add config option to use the local time zone
Julian Cowley <julian@lava.net>
parents: 17424
diff changeset
97 if self.ui.configbool('convert', 'localtimezone'):
337d728e644f convert: add config option to use the local time zone
Julian Cowley <julian@lava.net>
parents: 17424
diff changeset
98 cs.date = makedatetimestamp(cs.date[0])
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36393
diff changeset
99 date = dateutil.datestr(cs.date, '%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
100 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
101
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
102 files = {}
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
103 for f in cs.entries:
37658
34758397ad1b py3: use b"%d" instead of str() to convert integers to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37120
diff changeset
104 files[f.file] = "%s%s" % ('.'.join([(b"%d" % x)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
105 for x in f.revision]),
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
106 ['', '(DEAD)'][f.dead])
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
107
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
108 # add current commit to set
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
109 c = commit(author=cs.author, date=date,
37658
34758397ad1b py3: use b"%d" instead of str() to convert integers to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37120
diff changeset
110 parents=[(b"%d" % p.id) for p in cs.parents],
9543
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
111 desc=cs.comment, branch=cs.branch or '')
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
112 self.changeset[id] = c
56a5f80556f5 convert/cvs: stop supporting external cvsps
Patrick Mezard <pmezard@gmail.com>
parents: 9102
diff changeset
113 self.files[id] = files
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
114
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
115 self.heads = self.lastbranch.values()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
116 finally:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
117 os.chdir(d)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
118
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
119 def _connect(self):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
120 root = self.cvsroot
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
121 conntype = None
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
122 user, host = None, None
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
123 cmd = ['cvs', 'server']
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
124
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6816
diff changeset
125 self.ui.status(_("connecting to %s\n") % root)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
126
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
127 if root.startswith(":pserver:"):
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
128 root = root[9:]
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
129 m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)',
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
130 root)
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
131 if m:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
132 conntype = "pserver"
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
133 user, passw, serv, port, root = m.groups()
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
134 if not user:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
135 user = "anonymous"
5082
dc2e512cb89a CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4698
diff changeset
136 if not port:
dc2e512cb89a CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4698
diff changeset
137 port = 2401
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
138 else:
5082
dc2e512cb89a CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4698
diff changeset
139 port = int(port)
dc2e512cb89a CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4698
diff changeset
140 format0 = ":pserver:%s@%s:%s" % (user, serv, root)
dc2e512cb89a CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4698
diff changeset
141 format1 = ":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
142
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
143 if not passw:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
144 passw = "A"
7442
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
145 cvspass = os.path.expanduser("~/.cvspass")
7444
f792c7bb2fb3 Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7442
diff changeset
146 try:
36132
42a393ea56d2 convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents: 35176
diff changeset
147 pf = open(cvspass, 'rb')
7442
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
148 for line in pf.read().splitlines():
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
149 part1, part2 = line.split(' ', 1)
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16514
diff changeset
150 # /1 :pserver:user@example.com:2401/cvsroot/foo
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16514
diff changeset
151 # Ah<Z
7442
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
152 if part1 == '/1':
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
153 part1, part2 = part2.split(' ', 1)
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
154 format = format1
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16514
diff changeset
155 # :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
156 else:
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
157 format = format0
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
158 if part1 == format:
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
159 passw = part2
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
160 break
a14ce129cfcd convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents: 7441
diff changeset
161 pf.close()
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24395
diff changeset
162 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
163 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
164 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
165 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
166 raise
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
167
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
168 sck = socket.socket()
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
169 sck.connect((serv, port))
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
170 sck.send("\n".join(["BEGIN AUTH REQUEST", root, user, passw,
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
171 "END AUTH REQUEST", ""]))
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
172 if sck.recv(128) != "I LOVE YOU\n":
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
173 raise error.Abort(_("CVS pserver authentication failed"))
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
174
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
175 self.writep = self.readp = sck.makefile('r+')
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
176
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
177 if not conntype and root.startswith(":local:"):
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
178 conntype = "local"
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
179 root = root[7:]
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
180
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
181 if not conntype:
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
182 # :ext:user@host/home/user/path/to/cvsroot
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
183 if root.startswith(":ext:"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
184 root = root[5:]
36393
54f4328a07c2 py3: make sure regexes are bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36132
diff changeset
185 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
186 # 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
187 if os.path.isdir(root) or not m:
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
188 conntype = "local"
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
189 else:
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
190 conntype = "rsh"
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
191 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
192
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
193 if conntype != "pserver":
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4515
diff changeset
194 if conntype == "rsh":
30638
1c5cbf28f007 py3: replace os.environ with encoding.environ (part 5 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30519
diff changeset
195 rsh = encoding.environ.get("CVS_RSH") or "ssh"
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
196 if user:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
197 cmd = [rsh, '-l', user, host] + cmd
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
198 else:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
199 cmd = [rsh, host] + cmd
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
200
5303
a76c61679b71 convert: call popen2 in binary mode, with a command string.
Patrick Mezard <pmezard@gmail.com>
parents: 5082
diff changeset
201 # popen2 does not support argument lists under Windows
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
202 cmd = [procutil.shellquote(arg) for arg in cmd]
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
203 cmd = procutil.quotecommand(' '.join(cmd))
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36607
diff changeset
204 self.writep, self.readp = procutil.popen2(cmd)
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
205
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
206 self.realroot = root
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
207
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
208 self.writep.write("Root %s\n" % root)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
209 self.writep.write("Valid-responses ok error Valid-requests Mode"
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
210 " M Mbinary E Checked-in Created Updated"
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
211 " Merged Removed\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
212 self.writep.write("valid-requests\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
213 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
214 r = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
215 if not r.startswith("Valid-requests"):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
216 raise error.Abort(_('unexpected response from CVS server '
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
217 '(expected "Valid-requests", but got %r)')
9095
89fd11257d75 convert/cvs: improve error message on unexpected server output.
Greg Ward <greg-hg@gerg.ca>
parents: 8598
diff changeset
218 % r)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
219 if "UseUnchanged" in r:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
220 self.writep.write("UseUnchanged\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
221 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
222 r = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
223
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
224 def getheads(self):
8048
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
225 self._parse()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
226 return self.heads
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
227
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
228 def getfile(self, name, rev):
5539
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
229
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
230 def chunkedread(fp, count):
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 16683
diff changeset
231 # 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
232 # large read() requests very well.
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
233 chunksize = 65536
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28413
diff changeset
234 output = stringio()
5539
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
235 while count > 0:
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
236 data = fp.read(min(count, chunksize))
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
237 if not data:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
238 raise error.Abort(_("%d bytes missing from remote file")
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
239 % count)
5539
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
240 count -= len(data)
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
241 output.write(data)
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
242 return output.getvalue()
954e68e54dea convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
243
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
244 self._parse()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
245 if rev.endswith("(DEAD)"):
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 17974
diff changeset
246 return None, None
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
247
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
248 args = ("-N -P -kk -r %s --" % rev).split()
5305
87348cdce88c convert: fix remote cvs file paths separator
Patrick Mezard <pmezard@gmail.com>
parents: 5304
diff changeset
249 args.append(self.cvsrepo + '/' + name)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
250 for x in args:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
251 self.writep.write("Argument %s\n" % x)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
252 self.writep.write("Directory .\n%s\nco\n" % self.realroot)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
253 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
254
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
255 data = ""
10800
49c109d037dd convert.cvs: Initialize state variable and abort on cvs error
Mads Kiilerich <mads@kiilerich.com>
parents: 10282
diff changeset
256 mode = None
14494
1ffeeb91c55d check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents: 12063
diff changeset
257 while True:
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
258 line = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
259 if line.startswith("Created ") or line.startswith("Updated "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
260 self.readp.readline() # path
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
261 self.readp.readline() # entries
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
262 mode = self.readp.readline()[:-1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
263 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
264 data = chunkedread(self.readp, count)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
265 elif line.startswith(" "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
266 data += line[1:]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
267 elif line.startswith("M "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
268 pass
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
269 elif line.startswith("Mbinary "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
270 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
271 data = chunkedread(self.readp, count)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
272 else:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
273 if line == "ok\n":
10800
49c109d037dd convert.cvs: Initialize state variable and abort on cvs error
Mads Kiilerich <mads@kiilerich.com>
parents: 10282
diff changeset
274 if mode is None:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
275 raise error.Abort(_('malformed response from CVS'))
4082
6b2909e84203 convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents: 4062
diff changeset
276 return (data, "x" in mode and "x" or "")
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
277 elif line.startswith("E "):
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6816
diff changeset
278 self.ui.warn(_("cvs server: %s\n") % line[2:])
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
279 elif line.startswith("Remove"):
7874
d812029cda85 cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7519
diff changeset
280 self.readp.readline()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
281 else:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
282 raise error.Abort(_("unknown CVS response: %s") % line)
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
283
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
284 def getchanges(self, rev, full):
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
285 if full:
26779
aaa33ec3c951 grammar: use does instead of do where appropriate
timeless@mozdev.org
parents: 26587
diff changeset
286 raise error.Abort(_("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
287 self._parse()
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
288 return sorted(self.files[rev].iteritems()), {}, set()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
289
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
290 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
291 self._parse()
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
292 return self.changeset[rev]
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
293
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
294 def gettags(self):
8048
d22432bdcba1 convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents: 7874
diff changeset
295 self._parse()
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
296 return self.tags
5381
6874368120dc convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5308
diff changeset
297
6874368120dc convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5308
diff changeset
298 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
299 self._parse()
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8169
diff changeset
300 return sorted(self.files[rev])