author | Patrick Mezard <pmezard@gmail.com> |
Sun, 26 Apr 2009 16:30:37 +0200 | |
changeset 8169 | 6584953be356 |
parent 8048 | d22432bdcba1 |
child 8209 | a1a5a57efe90 |
permissions | -rw-r--r-- |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
1 |
# CVS conversion code inspired by hg-cvs-import and git-cvsimport |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4515
diff
changeset
|
2 |
|
7444
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
3 |
import os, locale, re, socket, errno |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
4 |
from cStringIO import StringIO |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
5 |
from mercurial import util |
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
|
6 |
from mercurial.i18n import _ |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
7 |
|
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5381
diff
changeset
|
8 |
from common import NoRepo, commit, converter_source, checktool |
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
|
9 |
import cvsps |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
10 |
|
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
11 |
class convert_cvs(converter_source): |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
12 |
def __init__(self, ui, path, rev=None): |
4807
15a3cbfc6568
convert: call superclass init from engine init functions
Brendan Cully <brendan@kublai.com>
parents:
4762
diff
changeset
|
13 |
super(convert_cvs, self).__init__(ui, path, rev=rev) |
15a3cbfc6568
convert: call superclass init from engine init functions
Brendan Cully <brendan@kublai.com>
parents:
4762
diff
changeset
|
14 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
15 |
cvs = os.path.join(path, "CVS") |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
16 |
if not os.path.exists(cvs): |
5521
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5481
diff
changeset
|
17 |
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
|
18 |
|
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
|
19 |
checktool('cvs') |
7101
e786192d995d
convert: make built-in cvsps the default
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
20 |
self.cmd = ui.config('convert', 'cvsps', 'builtin') |
6318
308988071b90
convert: Add convert.cvsps option to set up an alternate cvsps command line.
Eric Hopper <hopper@omnifarious.org>
parents:
6077
diff
changeset
|
21 |
cvspsexe = self.cmd.split(None, 1)[0] |
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
|
22 |
self.builtin = cvspsexe == 'builtin' |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
23 |
|
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
24 |
if not self.builtin: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
25 |
checktool(cvspsexe) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5381
diff
changeset
|
26 |
|
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
27 |
self.changeset = None |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
28 |
self.files = {} |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
29 |
self.tags = {} |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
30 |
self.lastbranch = {} |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
31 |
self.parent = {} |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
32 |
self.socket = None |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
33 |
self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
34 |
self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
35 |
self.encoding = locale.getpreferredencoding() |
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
|
36 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
37 |
self._connect() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
38 |
|
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
39 |
def _parse(self): |
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
40 |
if self.changeset is not None: |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
41 |
return |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
42 |
self.changeset = {} |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
43 |
|
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
44 |
maxrev = 0 |
6318
308988071b90
convert: Add convert.cvsps option to set up an alternate cvsps command line.
Eric Hopper <hopper@omnifarious.org>
parents:
6077
diff
changeset
|
45 |
cmd = self.cmd |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
46 |
if self.rev: |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
47 |
# TODO: handle tags |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
48 |
try: |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
49 |
# patchset number? |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
50 |
maxrev = int(self.rev) |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
51 |
except ValueError: |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
52 |
try: |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
53 |
# date |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
54 |
util.parsedate(self.rev, ['%Y/%m/%d %H:%M:%S']) |
5308 | 55 |
cmd = '%s -d "1970/01/01 00:00:01" -d "%s"' % (cmd, self.rev) |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
56 |
except util.Abort: |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
57 |
raise util.Abort(_('revision %s is not a patchset number or date') % self.rev) |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4759
diff
changeset
|
58 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
59 |
d = os.getcwd() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
60 |
try: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
61 |
os.chdir(self.path) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
62 |
id = None |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
63 |
state = 0 |
5920
5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5521
diff
changeset
|
64 |
filerevids = {} |
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
|
65 |
|
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
66 |
if self.builtin: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
67 |
# builtin cvsps code |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
68 |
self.ui.status(_('using builtin cvsps\n')) |
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
|
69 |
|
8169
6584953be356
convert/cvs: add an option to disable remote log caching
Patrick Mezard <pmezard@gmail.com>
parents:
8048
diff
changeset
|
70 |
cache = 'update' |
6584953be356
convert/cvs: add an option to disable remote log caching
Patrick Mezard <pmezard@gmail.com>
parents:
8048
diff
changeset
|
71 |
if not self.ui.configbool('convert', 'cvsps.cache', True): |
6584953be356
convert/cvs: add an option to disable remote log caching
Patrick Mezard <pmezard@gmail.com>
parents:
8048
diff
changeset
|
72 |
cache = None |
6584953be356
convert/cvs: add an option to disable remote log caching
Patrick Mezard <pmezard@gmail.com>
parents:
8048
diff
changeset
|
73 |
db = cvsps.createlog(self.ui, cache=cache) |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
74 |
db = cvsps.createchangeset(self.ui, db, |
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
75 |
fuzz=int(self.ui.config('convert', 'cvsps.fuzz', 60)), |
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
76 |
mergeto=self.ui.config('convert', 'cvsps.mergeto', None), |
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
77 |
mergefrom=self.ui.config('convert', 'cvsps.mergefrom', 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
|
78 |
|
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
79 |
for cs in db: |
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 |
if maxrev and cs.id>maxrev: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
81 |
break |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
82 |
id = str(cs.id) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
83 |
cs.author = self.recode(cs.author) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
84 |
self.lastbranch[cs.branch] = id |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
85 |
cs.comment = self.recode(cs.comment) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
86 |
date = util.datestr(cs.date) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
87 |
self.tags.update(dict.fromkeys(cs.tags, id)) |
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 |
|
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
89 |
files = {} |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
90 |
for f in cs.entries: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
91 |
files[f.file] = "%s%s" % ('.'.join([str(x) for x in f.revision]), |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
92 |
['', '(DEAD)'][f.dead]) |
5920
5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5521
diff
changeset
|
93 |
|
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
|
94 |
# add current commit to set |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
95 |
c = commit(author=cs.author, date=date, |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
96 |
parents=[str(p.id) for p in cs.parents], |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
97 |
desc=cs.comment, branch=cs.branch or '') |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
98 |
self.changeset[id] = c |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
99 |
self.files[id] = files |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
100 |
else: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
101 |
# external cvsps |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
102 |
for l in util.popen(cmd): |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
103 |
if state == 0: # header |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
104 |
if l.startswith("PatchSet"): |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
105 |
id = l[9:-2] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
106 |
if maxrev and int(id) > maxrev: |
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 |
# ignore everything |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
108 |
state = 3 |
7441
4fecd17f2de9
convert cvs: Fix branch name parsing
Mads Kiilerich <mads@kiilerich.com>
parents:
7106
diff
changeset
|
109 |
elif l.startswith("Date:"): |
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
|
110 |
date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
111 |
date = util.datestr(date) |
7441
4fecd17f2de9
convert cvs: Fix branch name parsing
Mads Kiilerich <mads@kiilerich.com>
parents:
7106
diff
changeset
|
112 |
elif l.startswith("Branch:"): |
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
|
113 |
branch = l[8:-1] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
114 |
self.parent[id] = self.lastbranch.get(branch, 'bad') |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
115 |
self.lastbranch[branch] = id |
7441
4fecd17f2de9
convert cvs: Fix branch name parsing
Mads Kiilerich <mads@kiilerich.com>
parents:
7106
diff
changeset
|
116 |
elif l.startswith("Ancestor branch:"): |
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
|
117 |
ancestor = l[17:-1] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
118 |
# figure out the parent later |
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 |
self.parent[id] = self.lastbranch[ancestor] |
7441
4fecd17f2de9
convert cvs: Fix branch name parsing
Mads Kiilerich <mads@kiilerich.com>
parents:
7106
diff
changeset
|
120 |
elif l.startswith("Author:"): |
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
|
121 |
author = self.recode(l[8:-1]) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
122 |
elif l.startswith("Tag:") or l.startswith("Tags:"): |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
123 |
t = l[l.index(':')+1:] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
124 |
t = [ut.strip() for ut in t.split(',')] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
125 |
if (len(t) > 1) or (t[0] and (t[0] != "(none)")): |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
126 |
self.tags.update(dict.fromkeys(t, id)) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
127 |
elif l.startswith("Log:"): |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
128 |
# switch to gathering log |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
129 |
state = 1 |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
130 |
log = "" |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
131 |
elif state == 1: # log |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
132 |
if l == "Members: \n": |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
133 |
# switch to gathering members |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
134 |
files = {} |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
135 |
oldrevs = [] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
136 |
log = self.recode(log[:-1]) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
137 |
state = 2 |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
138 |
else: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
139 |
# gather log |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
140 |
log += l |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
141 |
elif state == 2: # members |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
142 |
if l == "\n": # start of next entry |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
143 |
state = 0 |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
144 |
p = [self.parent[id]] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
145 |
if id == "1": |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
146 |
p = [] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
147 |
if branch == "HEAD": |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
148 |
branch = "" |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
149 |
if branch: |
7472
9d457bb38de5
convert/cvs: do not compare None with int
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7444
diff
changeset
|
150 |
latest = 0 |
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
|
151 |
# the last changeset that contains a base |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
152 |
# file is our parent |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
153 |
for r in oldrevs: |
7472
9d457bb38de5
convert/cvs: do not compare None with int
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7444
diff
changeset
|
154 |
latest = max(filerevids.get(r, 0), latest) |
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
|
155 |
if latest: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
156 |
p = [latest] |
5920
5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5521
diff
changeset
|
157 |
|
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
|
158 |
# add current commit to set |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
159 |
c = commit(author=author, date=date, parents=p, |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
160 |
desc=log, branch=branch) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
161 |
self.changeset[id] = c |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
162 |
self.files[id] = files |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
163 |
else: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
164 |
colon = l.rfind(':') |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
165 |
file = l[1:colon] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
166 |
rev = l[colon+1:-2] |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
167 |
oldrev, rev = rev.split("->") |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
168 |
files[file] = rev |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
169 |
|
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
170 |
# save some information for identifying branch points |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
171 |
oldrevs.append("%s:%s" % (oldrev, file)) |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
172 |
filerevids["%s:%s" % (rev, file)] = id |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
173 |
elif state == 3: |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
174 |
# swallow all input |
127e8c3466d1
convert: cvs.py - Allow user to use built-in CVS changeset code.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
6318
diff
changeset
|
175 |
continue |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
176 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
177 |
self.heads = self.lastbranch.values() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
178 |
finally: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
179 |
os.chdir(d) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
180 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
181 |
def _connect(self): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
182 |
root = self.cvsroot |
4047 | 183 |
conntype = None |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
184 |
user, host = None, None |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
185 |
cmd = ['cvs', 'server'] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
186 |
|
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
187 |
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
|
188 |
|
4047 | 189 |
if root.startswith(":pserver:"): |
190 |
root = root[9:] |
|
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
191 |
m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
192 |
root) |
4047 | 193 |
if m: |
194 |
conntype = "pserver" |
|
195 |
user, passw, serv, port, root = m.groups() |
|
196 |
if not user: |
|
197 |
user = "anonymous" |
|
5082
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
198 |
if not port: |
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
199 |
port = 2401 |
4047 | 200 |
else: |
5082
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
201 |
port = int(port) |
dc2e512cb89a
CVS import: Support new-style .cvspass-file format.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4698
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
|
4047 | 205 |
if not passw: |
206 |
passw = "A" |
|
7442
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
207 |
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
|
208 |
try: |
7442
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
209 |
pf = open(cvspass) |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
210 |
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
|
211 |
part1, part2 = line.split(' ', 1) |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
212 |
if part1 == '/1': |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
213 |
# /1 :pserver:user@example.com:2401/cvsroot/foo Ah<Z |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
214 |
part1, part2 = part2.split(' ', 1) |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
215 |
format = format1 |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
216 |
else: |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
217 |
# :pserver:user@example.com:/cvsroot/foo Ah<Z |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
218 |
format = format0 |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
219 |
if part1 == format: |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
220 |
passw = part2 |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
221 |
break |
a14ce129cfcd
convert: check existence of ~/.cvspass before reading it
Edouard Gomez <ed.gomez@free.fr>
parents:
7441
diff
changeset
|
222 |
pf.close() |
7444
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
223 |
except IOError, inst: |
f792c7bb2fb3
Improvement to 14ce129cfcd: Use try/except and pass filename on errors
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7442
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
raise |
4047 | 228 |
|
229 |
sck = socket.socket() |
|
230 |
sck.connect((serv, port)) |
|
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
231 |
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
|
232 |
"END AUTH REQUEST", ""])) |
4047 | 233 |
if sck.recv(128) != "I LOVE YOU\n": |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
234 |
raise util.Abort(_("CVS pserver authentication failed")) |
4047 | 235 |
|
236 |
self.writep = self.readp = sck.makefile('r+') |
|
237 |
||
238 |
if not conntype and root.startswith(":local:"): |
|
239 |
conntype = "local" |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
240 |
root = root[7:] |
4047 | 241 |
|
242 |
if not conntype: |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
243 |
# :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
|
244 |
if root.startswith(":ext:"): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
245 |
root = root[5:] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
246 |
m = re.match(r'(?:([^@:/]+)@)?([^:/]+):?(.*)', root) |
5304
b85f7cc133cc
convert: avoid interpreting Windows path as CVS connection strings.
Patrick Mezard <pmezard@gmail.com>
parents:
5303
diff
changeset
|
247 |
# 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
|
248 |
if os.path.isdir(root) or not m: |
4047 | 249 |
conntype = "local" |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
250 |
else: |
4047 | 251 |
conntype = "rsh" |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
252 |
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
|
253 |
|
4047 | 254 |
if conntype != "pserver": |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4515
diff
changeset
|
255 |
if conntype == "rsh": |
5860
493632bb171c
convert should use default value when CVS_RSH is not set, that value
Kostantinos Koukopoulos <kouk@noc.uoa.gr>
parents:
5539
diff
changeset
|
256 |
rsh = os.environ.get("CVS_RSH") or "ssh" |
4047 | 257 |
if user: |
258 |
cmd = [rsh, '-l', user, host] + cmd |
|
259 |
else: |
|
260 |
cmd = [rsh, host] + cmd |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
261 |
|
5303
a76c61679b71
convert: call popen2 in binary mode, with a command string.
Patrick Mezard <pmezard@gmail.com>
parents:
5082
diff
changeset
|
262 |
# popen2 does not support argument lists under Windows |
a76c61679b71
convert: call popen2 in binary mode, with a command string.
Patrick Mezard <pmezard@gmail.com>
parents:
5082
diff
changeset
|
263 |
cmd = [util.shellquote(arg) for arg in cmd] |
a76c61679b71
convert: call popen2 in binary mode, with a command string.
Patrick Mezard <pmezard@gmail.com>
parents:
5082
diff
changeset
|
264 |
cmd = util.quotecommand(' '.join(cmd)) |
7106
4674706b5b95
python2.6: use subprocess if available
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7101
diff
changeset
|
265 |
self.writep, self.readp = util.popen2(cmd, 'b') |
4047 | 266 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
267 |
self.realroot = root |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
268 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
269 |
self.writep.write("Root %s\n" % root) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
270 |
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
|
271 |
" M Mbinary E Checked-in Created Updated" |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
272 |
" Merged Removed\n") |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
273 |
self.writep.write("valid-requests\n") |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
274 |
self.writep.flush() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
275 |
r = self.readp.readline() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
276 |
if not r.startswith("Valid-requests"): |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
277 |
raise util.Abort(_("server sucks")) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
278 |
if "UseUnchanged" in r: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
279 |
self.writep.write("UseUnchanged\n") |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
280 |
self.writep.flush() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
281 |
r = self.readp.readline() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
282 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
283 |
def getheads(self): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
284 |
self._parse() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
285 |
return self.heads |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
286 |
|
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
287 |
def _getfile(self, name, rev): |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
288 |
|
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
289 |
def chunkedread(fp, count): |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
290 |
# file-objects returned by socked.makefile() do not handle |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
291 |
# large read() requests very well. |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
292 |
chunksize = 65536 |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
293 |
output = StringIO() |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
294 |
while count > 0: |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
295 |
data = fp.read(min(count, chunksize)) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
296 |
if not data: |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
297 |
raise util.Abort(_("%d bytes missing from remote file") % count) |
5539
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
298 |
count -= len(data) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
299 |
output.write(data) |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
300 |
return output.getvalue() |
954e68e54dea
convert: read CVS files in chunks (issue 800)
Patrick Mezard <pmezard@gmail.com>
parents:
5528
diff
changeset
|
301 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
302 |
if rev.endswith("(DEAD)"): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
303 |
raise IOError |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
304 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
305 |
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
|
306 |
args.append(self.cvsrepo + '/' + name) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
307 |
for x in args: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
308 |
self.writep.write("Argument %s\n" % x) |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
309 |
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
|
310 |
self.writep.flush() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
311 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
312 |
data = "" |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
313 |
while 1: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
314 |
line = self.readp.readline() |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
315 |
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
|
316 |
self.readp.readline() # path |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
317 |
self.readp.readline() # entries |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
318 |
mode = self.readp.readline()[:-1] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
319 |
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
|
320 |
data = chunkedread(self.readp, count) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
321 |
elif line.startswith(" "): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
322 |
data += line[1:] |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
323 |
elif line.startswith("M "): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
324 |
pass |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
325 |
elif line.startswith("Mbinary "): |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
326 |
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
|
327 |
data = chunkedread(self.readp, count) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
328 |
else: |
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
329 |
if line == "ok\n": |
4082
6b2909e84203
convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents:
4062
diff
changeset
|
330 |
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
|
331 |
elif line.startswith("E "): |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
332 |
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
|
333 |
elif line.startswith("Remove"): |
7874
d812029cda85
cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7519
diff
changeset
|
334 |
self.readp.readline() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
335 |
else: |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6816
diff
changeset
|
336 |
raise util.Abort(_("unknown CVS response: %s") % line) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
337 |
|
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
338 |
def getfile(self, file, rev): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
339 |
self._parse() |
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
340 |
data, mode = self._getfile(file, rev) |
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
341 |
self.modecache[(file, rev)] = mode |
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
342 |
return data |
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
343 |
|
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
344 |
def getmode(self, file, rev): |
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
345 |
return self.modecache[(file, rev)] |
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
346 |
|
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
347 |
def getchanges(self, rev): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
348 |
self._parse() |
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
349 |
self.modecache = {} |
6762 | 350 |
return util.sort(self.files[rev].items()), {} |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
351 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
352 |
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
|
353 |
self._parse() |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
354 |
return self.changeset[rev] |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
355 |
|
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
356 |
def gettags(self): |
8048
d22432bdcba1
convert/cvs: delay CVS log parsing after initialization (issue1581/2)
Patrick Mezard <pmezard@gmail.com>
parents:
7874
diff
changeset
|
357 |
self._parse() |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
358 |
return self.tags |
5381
6874368120dc
convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5308
diff
changeset
|
359 |
|
6874368120dc
convert_cvs: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5308
diff
changeset
|
360 |
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
|
361 |
self._parse() |
6762 | 362 |
return util.sort(self.files[rev].keys()) |