annotate hgext/convert/p4.py @ 16233:3f79b110c4f0

patchbomb: add (optional) note to 0 of 0 prompt
author Matt Mackall <mpm@selenic.com>
date Thu, 08 Mar 2012 15:59:41 -0600
parents b69fd38a034e
children 363e808de349
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
1 # Perforce source for convert extension.
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
2 #
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
3 # Copyright 2009, Frank Kingswood <frank@kingswood-consulting.co.uk>
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9476
diff changeset
6 # GNU General Public License version 2 or any later version.
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
7
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
8 from mercurial import util
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
9 from mercurial.i18n import _
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
10
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7905
diff changeset
11 from common import commit, converter_source, checktool, NoRepo
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
12 import marshal
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
13 import re
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
14
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
15 def loaditer(f):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
16 "Yield the dictionary objects generated by p4"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
17 try:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
18 while True:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
19 d = marshal.load(f)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
20 if not d:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
21 break
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
22 yield d
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
23 except EOFError:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
24 pass
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
25
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
26 class p4_source(converter_source):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
27 def __init__(self, ui, path, rev=None):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
28 super(p4_source, self).__init__(ui, path, rev=rev)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
29
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
30 if "/" in path and not path.startswith('//'):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
31 raise NoRepo(_('%s does not look like a P4 repository') % path)
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7905
diff changeset
32
7905
d596b1f2935a convert: missing p4 tool is only slightly fatal
Mads Kiilerich <mads@kiilerich.com>
parents: 7869
diff changeset
33 checktool('p4', abort=False)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
34
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
35 self.p4changes = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
36 self.heads = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
37 self.changeset = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
38 self.files = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
39 self.tags = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
40 self.lastbranch = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
41 self.parent = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
42 self.encoding = "latin_1"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
43 self.depotname = {} # mapping from local name to depot name
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
44 self.re_type = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
45 "([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)"
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
46 "(\+\w+)?$")
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
47 self.re_keywords = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
48 r"\$(Id|Header|Date|DateTime|Change|File|Revision|Author)"
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
49 r":[^$\n]*\$")
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
50 self.re_keywords_old = re.compile("\$(Id|Header):[^$\n]*\$")
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
51
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
52 self._parse(ui, path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
53
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
54 def _parse_view(self, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
55 "Read changes affecting the path"
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
56 cmd = 'p4 -G changes -s submitted %s' % util.shellquote(path)
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
57 stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
58 for d in loaditer(stdout):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
59 c = d.get("change", None)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
60 if c:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
61 self.p4changes[c] = True
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
62
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
63 def _parse(self, ui, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
64 "Prepare list of P4 filenames and revisions to import"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
65 ui.status(_('reading p4 views\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
66
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
67 # read client spec or view
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
68 if "/" in path:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
69 self._parse_view(path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
70 if path.startswith("//") and path.endswith("/..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
71 views = {path[:-3]:""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
72 else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
73 views = {"//": ""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
74 else:
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
75 cmd = 'p4 -G client -o %s' % util.shellquote(path)
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
76 clientspec = marshal.load(util.popen(cmd, mode='rb'))
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
77
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
78 views = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
79 for client in clientspec:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
80 if client.startswith("View"):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
81 sview, cview = clientspec[client].split()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
82 self._parse_view(sview)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
83 if sview.endswith("...") and cview.endswith("..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
84 sview = sview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
85 cview = cview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
86 cview = cview[2:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
87 cview = cview[cview.find("/") + 1:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
88 views[sview] = cview
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
89
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
90 # list of changes that affect our source files
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
91 self.p4changes = self.p4changes.keys()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
92 self.p4changes.sort(key=int)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
93
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
94 # list with depot pathnames, longest first
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
95 vieworder = views.keys()
9039
8761863c3118 p4: simplify sort key
Martin Geisler <mg@lazybytes.net>
parents: 8843
diff changeset
96 vieworder.sort(key=len, reverse=True)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
97
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
98 # handle revision limiting
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
99 startrev = self.ui.config('convert', 'p4.startrev', default=0)
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
100 self.p4changes = [x for x in self.p4changes
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
101 if ((not startrev or int(x) >= int(startrev)) and
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
102 (not self.rev or int(x) <= int(self.rev)))]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
103
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
104 # now read the full changelists to get the list of file revisions
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
105 ui.status(_('collecting p4 changelists\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
106 lastid = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
107 for change in self.p4changes:
12891
b69fd38a034e convert: Work around p4 instability (issue2465)
Mike Sperber <sperber@deinprogramm.de>
parents: 12401
diff changeset
108 cmd = "p4 -G describe -s %s" % change
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
109 stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
110 d = marshal.load(stdout)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
111 desc = self.recode(d["desc"])
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
112 shortdesc = desc.split("\n", 1)[0]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
113 t = '%s %s' % (d["change"], repr(shortdesc)[1:-1])
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
114 ui.status(util.ellipsis(t, 80) + '\n')
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
115
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
116 if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
117 parents = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
118 else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
119 parents = []
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
120
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
121 date = (int(d["time"]), 0) # timezone not set
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
122 c = commit(author=self.recode(d["user"]), date=util.datestr(date),
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
123 parents=parents, desc=desc, branch='',
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
124 extra={"p4": change})
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
125
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
126 files = []
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
127 i = 0
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
128 while ("depotFile%d" % i) in d and ("rev%d" % i) in d:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
129 oldname = d["depotFile%d" % i]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
130 filename = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
131 for v in vieworder:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
132 if oldname.startswith(v):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
133 filename = views[v] + oldname[len(v):]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
134 break
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
135 if filename:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
136 files.append((filename, d["rev%d" % i]))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
137 self.depotname[filename] = oldname
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
138 i += 1
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
139 self.changeset[change] = c
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
140 self.files[change] = files
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
141 lastid = change
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
142
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
143 if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
144 self.heads = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
145
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
146 def getheads(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
147 return self.heads
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
148
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
149 def getfile(self, name, rev):
11348
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
150 cmd = 'p4 -G print %s' \
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
151 % util.shellquote("%s#%s" % (self.depotname[name], rev))
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
152 stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
153
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
154 mode = None
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
155 contents = ""
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
156 keywords = None
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
157
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
158 for d in loaditer(stdout):
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
159 code = d["code"]
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
160 data = d.get("data")
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
161
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
162 if code == "error":
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
163 raise IOError(d["generic"], data)
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
164
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
165 elif code == "stat":
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
166 p4type = self.re_type.match(d["type"])
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
167 if p4type:
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
168 mode = ""
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
169 flags = (p4type.group(1) or "") + (p4type.group(3) or "")
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
170 if "x" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
171 mode = "x"
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
172 if p4type.group(2) == "symlink":
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
173 mode = "l"
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
174 if "ko" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
175 keywords = self.re_keywords_old
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
176 elif "k" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
177 keywords = self.re_keywords
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
178
12401
4cdaf1adafc8 backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents: 12387
diff changeset
179 elif code == "text" or code == "binary":
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
180 contents += data
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
181
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
182 if mode is None:
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
183 raise IOError(0, "bad stat")
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
184
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
185 if keywords:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
186 contents = keywords.sub("$\\1$", contents)
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
187 if mode == "l" and contents.endswith("\n"):
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
188 contents = contents[:-1]
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
189
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
190 return contents, mode
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
191
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
192 def getchanges(self, rev):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
193 return self.files[rev], {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
194
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
195 def getcommit(self, rev):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
196 return self.changeset[rev]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
197
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
198 def gettags(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
199 return self.tags
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
200
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
201 def getchangedfiles(self, rev, i):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8066
diff changeset
202 return sorted([x[0] for x in self.files[rev]])