Mercurial > hg
comparison hgext/convert/p4.py @ 9474:6ea653272c09
convert: fix marshalling in P4 convert extension to use a binary stream
The Perforce convert extension uses the p4 -G command line option and
marshal.load to obtain information about the history of a Perforce depot.
The method marshal.load must be provided with a binary stream (mode='rb') in
order to function reliably. Certain changelist descriptions or other elements
in a depot history could trigger a premature EOFError, causing the conversion
process to fail.
This may resolve the issue discussed in the following thread:
http://www.selenic.com/pipermail/mercurial/2009-July/026813.html
author | Peter Ingebretson <pingebre@yahoo.com> |
---|---|
date | Wed, 23 Sep 2009 15:36:51 +0200 |
parents | eb7b247a98ea |
children | a0e69510018b |
comparison
equal
deleted
inserted
replaced
9470:ba75830d17a9 | 9474:6ea653272c09 |
---|---|
51 self._parse(ui, path) | 51 self._parse(ui, path) |
52 | 52 |
53 def _parse_view(self, path): | 53 def _parse_view(self, path): |
54 "Read changes affecting the path" | 54 "Read changes affecting the path" |
55 cmd = 'p4 -G changes -s submitted "%s"' % path | 55 cmd = 'p4 -G changes -s submitted "%s"' % path |
56 stdout = util.popen(cmd) | 56 stdout = util.popen(cmd, mode='rb') |
57 for d in loaditer(stdout): | 57 for d in loaditer(stdout): |
58 c = d.get("change", None) | 58 c = d.get("change", None) |
59 if c: | 59 if c: |
60 self.p4changes[c] = True | 60 self.p4changes[c] = True |
61 | 61 |
70 views = {path[:-3]:""} | 70 views = {path[:-3]:""} |
71 else: | 71 else: |
72 views = {"//": ""} | 72 views = {"//": ""} |
73 else: | 73 else: |
74 cmd = 'p4 -G client -o "%s"' % path | 74 cmd = 'p4 -G client -o "%s"' % path |
75 clientspec = marshal.load(util.popen(cmd)) | 75 clientspec = marshal.load(util.popen(cmd, mode='rb')) |
76 | 76 |
77 views = {} | 77 views = {} |
78 for client in clientspec: | 78 for client in clientspec: |
79 if client.startswith("View"): | 79 if client.startswith("View"): |
80 sview, cview = clientspec[client].split() | 80 sview, cview = clientspec[client].split() |
103 # now read the full changelists to get the list of file revisions | 103 # now read the full changelists to get the list of file revisions |
104 ui.status(_('collecting p4 changelists\n')) | 104 ui.status(_('collecting p4 changelists\n')) |
105 lastid = None | 105 lastid = None |
106 for change in self.p4changes: | 106 for change in self.p4changes: |
107 cmd = "p4 -G describe %s" % change | 107 cmd = "p4 -G describe %s" % change |
108 stdout = util.popen(cmd) | 108 stdout = util.popen(cmd, mode='rb') |
109 d = marshal.load(stdout) | 109 d = marshal.load(stdout) |
110 | 110 |
111 desc = self.recode(d["desc"]) | 111 desc = self.recode(d["desc"]) |
112 shortdesc = desc.split("\n", 1)[0] | 112 shortdesc = desc.split("\n", 1)[0] |
113 t = '%s %s' % (d["change"], repr(shortdesc)[1:-1]) | 113 t = '%s %s' % (d["change"], repr(shortdesc)[1:-1]) |
145 def getheads(self): | 145 def getheads(self): |
146 return self.heads | 146 return self.heads |
147 | 147 |
148 def getfile(self, name, rev): | 148 def getfile(self, name, rev): |
149 cmd = 'p4 -G print "%s#%s"' % (self.depotname[name], rev) | 149 cmd = 'p4 -G print "%s#%s"' % (self.depotname[name], rev) |
150 stdout = util.popen(cmd) | 150 stdout = util.popen(cmd, mode='rb') |
151 | 151 |
152 mode = None | 152 mode = None |
153 contents = "" | 153 contents = "" |
154 keywords = None | 154 keywords = None |
155 | 155 |