annotate hgext/convert/cvs.py @ 4698:30e826bd8ed1

convert: handle new cvsps with Tags: and multiple tags.
author Eric Hopper <hopper@omnifarious.org>
date Sun, 24 Jun 2007 07:22:58 -0700
parents cc9b79216a76
children 20ec5cc02f18 dc2e512cb89a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4534
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
4534
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
3 import os, locale, re, socket
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
4 from mercurial import util
4446
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
5
4534
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
6 from common import NoRepo, commit, converter_source
4446
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
7
4447
af013ae3ca10 use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents: 4446
diff changeset
8 class convert_cvs(converter_source):
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
9 def __init__(self, ui, path):
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
10 self.path = path
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
11 self.ui = ui
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
12 cvs = os.path.join(path, "CVS")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
13 if not os.path.exists(cvs):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
14 raise NoRepo("couldn't open CVS repo %s" % path)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
15
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
16 self.changeset = {}
3955
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
17 self.files = {}
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
18 self.tags = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
19 self.lastbranch = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
20 self.parent = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
21 self.socket = None
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
22 self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
23 self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
24 self.encoding = locale.getpreferredencoding()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
25 self._parse()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
26 self._connect()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
27
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
28 def _parse(self):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
29 if self.changeset:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
30 return
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
31
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
32 d = os.getcwd()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
33 try:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
34 os.chdir(self.path)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
35 id = None
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
36 state = 0
4109
59de487f43d7 Change a bit cvsps arguments
Edouard Gomez <ed.gomez@free.fr>
parents: 4082
diff changeset
37 for l in os.popen("cvsps -A -u --cvs-direct -q"):
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
38 if state == 0: # header
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
39 if l.startswith("PatchSet"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
40 id = l[9:-2]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
41 elif l.startswith("Date"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
42 date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"])
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
43 date = util.datestr(date)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
44 elif l.startswith("Branch"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
45 branch = l[8:-1]
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
46 self.parent[id] = self.lastbranch.get(branch, 'bad')
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
47 self.lastbranch[branch] = id
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
48 elif l.startswith("Ancestor branch"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
49 ancestor = l[17:-1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
50 self.parent[id] = self.lastbranch[ancestor]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
51 elif l.startswith("Author"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
52 author = self.recode(l[8:-1])
4698
30e826bd8ed1 convert: handle new cvsps with Tags: and multiple tags.
Eric Hopper <hopper@omnifarious.org>
parents: 4534
diff changeset
53 elif l.startswith("Tag:") or l.startswith("Tags:"):
30e826bd8ed1 convert: handle new cvsps with Tags: and multiple tags.
Eric Hopper <hopper@omnifarious.org>
parents: 4534
diff changeset
54 t = l[l.index(':')+1:]
30e826bd8ed1 convert: handle new cvsps with Tags: and multiple tags.
Eric Hopper <hopper@omnifarious.org>
parents: 4534
diff changeset
55 t = [ut.strip() for ut in t.split(',')]
30e826bd8ed1 convert: handle new cvsps with Tags: and multiple tags.
Eric Hopper <hopper@omnifarious.org>
parents: 4534
diff changeset
56 if (len(t) > 1) or (t[0] and (t[0] != "(none)")):
30e826bd8ed1 convert: handle new cvsps with Tags: and multiple tags.
Eric Hopper <hopper@omnifarious.org>
parents: 4534
diff changeset
57 self.tags.update(dict.fromkeys(t, id))
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
58 elif l.startswith("Log:"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
59 state = 1
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
60 log = ""
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
61 elif state == 1: # log
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
62 if l == "Members: \n":
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
63 files = {}
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
64 log = self.recode(log[:-1])
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
65 if log.isspace():
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
66 log = "*** empty log message ***\n"
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
67 state = 2
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
68 else:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
69 log += l
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
70 elif state == 2:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
71 if l == "\n": #
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
72 state = 0
3955
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
73 p = [self.parent[id]]
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
74 if id == "1":
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
75 p = []
4518
3e4aa4c9efe4 convert: map CVS HEAD to default branch
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4516
diff changeset
76 if branch == "HEAD":
3e4aa4c9efe4 convert: map CVS HEAD to default branch
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4516
diff changeset
77 branch = ""
3955
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
78 c = commit(author=author, date=date, parents=p,
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
79 desc=log, branch=branch)
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
80 self.changeset[id] = c
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
81 self.files[id] = files
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
82 else:
4515
86a66cce9566 Fixed python2.3 incompatibility (rsplit) in cvs code of convert extension
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4513
diff changeset
83 colon = l.rfind(':')
86a66cce9566 Fixed python2.3 incompatibility (rsplit) in cvs code of convert extension
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4513
diff changeset
84 file = l[1:colon]
86a66cce9566 Fixed python2.3 incompatibility (rsplit) in cvs code of convert extension
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4513
diff changeset
85 rev = l[colon+1:-2]
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
86 rev = rev.split("->")[1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
87 files[file] = rev
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
88
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
89 self.heads = self.lastbranch.values()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
90 finally:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
91 os.chdir(d)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
92
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
93 def _connect(self):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
94 root = self.cvsroot
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
95 conntype = None
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
96 user, host = None, None
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
97 cmd = ['cvs', 'server']
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
98
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
99 self.ui.status("connecting to %s\n" % root)
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
100
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
101 if root.startswith(":pserver:"):
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
102 root = root[9:]
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
103 m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)',
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
104 root)
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
105 if m:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
106 conntype = "pserver"
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
107 user, passw, serv, port, root = m.groups()
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
108 if not user:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
109 user = "anonymous"
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
110 rr = ":pserver:" + user + "@" + serv + ":" + root
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
111 if port:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
112 rr2, port = "-", int(port)
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
113 else:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
114 rr2, port = rr, 2401
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
115 rr += str(port)
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
116
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
117 if not passw:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
118 passw = "A"
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
119 pf = open(os.path.join(os.environ["HOME"], ".cvspass"))
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
120 for l in pf:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
121 # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
122 m = re.match(r'(/\d+\s+/)?(.*)', l)
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
123 l = m.group(2)
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
124 w, p = l.split(' ', 1)
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
125 if w in [rr, rr2]:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
126 passw = p
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
127 break
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
128 pf.close()
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
129
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
130 sck = socket.socket()
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
131 sck.connect((serv, port))
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
132 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
133 "END AUTH REQUEST", ""]))
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
134 if sck.recv(128) != "I LOVE YOU\n":
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
135 raise NoRepo("CVS pserver authentication failed")
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
136
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
137 self.writep = self.readp = sck.makefile('r+')
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
138
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
139 if not conntype and root.startswith(":local:"):
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
140 conntype = "local"
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
141 root = root[7:]
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
142
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
143 if not conntype:
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
144 # :ext:user@host/home/user/path/to/cvsroot
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
145 if root.startswith(":ext:"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
146 root = root[5:]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
147 m = re.match(r'(?:([^@:/]+)@)?([^:/]+):?(.*)', root)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
148 if not m:
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
149 conntype = "local"
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
150 else:
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
151 conntype = "rsh"
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
152 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: 3948
diff changeset
153
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
154 if conntype != "pserver":
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4515
diff changeset
155 if conntype == "rsh":
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
156 rsh = os.environ.get("CVS_RSH" or "rsh")
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
157 if user:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
158 cmd = [rsh, '-l', user, host] + cmd
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
159 else:
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
160 cmd = [rsh, host] + cmd
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
161
4047
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
162 self.writep, self.readp = os.popen2(cmd)
705d0792dbf2 add pserver support to convert_repo
csaba.henk@creo.hu
parents: 4006
diff changeset
163
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
164 self.realroot = root
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
165
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
166 self.writep.write("Root %s\n" % root)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
167 self.writep.write("Valid-responses ok error Valid-requests Mode"
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
168 " M Mbinary E Checked-in Created Updated"
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
169 " Merged Removed\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
170 self.writep.write("valid-requests\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
171 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
172 r = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
173 if not r.startswith("Valid-requests"):
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
174 raise util.Abort("server sucks")
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
175 if "UseUnchanged" in r:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
176 self.writep.write("UseUnchanged\n")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
177 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
178 r = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
179
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
180 def getheads(self):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
181 return self.heads
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
182
3957
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
183 def _getfile(self, name, rev):
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
184 if rev.endswith("(DEAD)"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
185 raise IOError
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
186
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
187 args = ("-N -P -kk -r %s --" % rev).split()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
188 args.append(os.path.join(self.cvsrepo, name))
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
189 for x in args:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
190 self.writep.write("Argument %s\n" % x)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
191 self.writep.write("Directory .\n%s\nco\n" % self.realroot)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
192 self.writep.flush()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
193
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
194 data = ""
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
195 while 1:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
196 line = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
197 if line.startswith("Created ") or line.startswith("Updated "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
198 self.readp.readline() # path
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
199 self.readp.readline() # entries
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
200 mode = self.readp.readline()[:-1]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
201 count = int(self.readp.readline()[:-1])
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
202 data = self.readp.read(count)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
203 elif line.startswith(" "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
204 data += line[1:]
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
205 elif line.startswith("M "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
206 pass
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
207 elif line.startswith("Mbinary "):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
208 count = int(self.readp.readline()[:-1])
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
209 data = self.readp.read(count)
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
210 else:
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
211 if line == "ok\n":
4082
6b2909e84203 convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents: 4062
diff changeset
212 return (data, "x" in mode and "x" or "")
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
213 elif line.startswith("E "):
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
214 self.ui.warn("cvs server: %s\n" % line[2:])
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
215 elif line.startswith("Remove"):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
216 l = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
217 l = self.readp.readline()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
218 if l != "ok\n":
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
219 raise util.Abort("unknown CVS response: %s" % l)
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
220 else:
4532
c3a78a49d7f0 Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4521
diff changeset
221 raise util.Abort("unknown CVS response: %s" % line)
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
222
3957
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
223 def getfile(self, file, rev):
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
224 data, mode = self._getfile(file, rev)
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
225 self.modecache[(file, rev)] = mode
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
226 return data
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
227
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
228 def getmode(self, file, rev):
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
229 return self.modecache[(file, rev)]
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
230
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
231 def getchanges(self, rev):
3957
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
232 self.modecache = {}
3955
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
233 files = self.files[rev]
3957
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3955
diff changeset
234 cl = files.items()
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
235 cl.sort()
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
236 return cl
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
237
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
238 def recode(self, text):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
239 return text.decode(self.encoding, "replace").encode("utf-8")
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
240
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
241 def getcommit(self, rev):
3955
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
242 return self.changeset[rev]
3954
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
243
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
244 def gettags(self):
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3948
diff changeset
245 return self.tags