comparison hgext/convert/monotone.py @ 26587:56b2bcea2529

error: get Abort from 'error' instead of 'util' The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be confused about that and gives all the credit to 'util' instead of the hardworking 'error'. In a spirit of equity, we break the cycle of injustice and give back to 'error' the respect it deserves. And screw that 'util' poser. For great justice.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 08 Oct 2015 12:55:45 -0700
parents baea47cafe75
children aaa33ec3c951
comparison
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
5 # 5 #
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 import os, re 9 import os, re
10 from mercurial import util 10 from mercurial import util, error
11 from common import NoRepo, commit, converter_source, checktool 11 from common import NoRepo, commit, converter_source, checktool
12 from common import commandline 12 from common import commandline
13 from mercurial.i18n import _ 13 from mercurial.i18n import _
14 14
15 class monotone_source(converter_source, commandline): 15 class monotone_source(converter_source, commandline):
16 def __init__(self, ui, path=None, revs=None): 16 def __init__(self, ui, path=None, revs=None):
17 converter_source.__init__(self, ui, path, revs) 17 converter_source.__init__(self, ui, path, revs)
18 if revs and len(revs) > 1: 18 if revs and len(revs) > 1:
19 raise util.Abort(_('monotone source does not support specifying ' 19 raise error.Abort(_('monotone source does not support specifying '
20 'multiple revs')) 20 'multiple revs'))
21 commandline.__init__(self, ui, 'mtn') 21 commandline.__init__(self, ui, 'mtn')
22 22
23 self.ui = ui 23 self.ui = ui
24 self.path = path 24 self.path = path
108 read = None 108 read = None
109 commandnbr = '' 109 commandnbr = ''
110 while read != ':': 110 while read != ':':
111 read = self.mtnreadfp.read(1) 111 read = self.mtnreadfp.read(1)
112 if not read: 112 if not read:
113 raise util.Abort(_('bad mtn packet - no end of commandnbr')) 113 raise error.Abort(_('bad mtn packet - no end of commandnbr'))
114 commandnbr += read 114 commandnbr += read
115 commandnbr = commandnbr[:-1] 115 commandnbr = commandnbr[:-1]
116 116
117 stream = self.mtnreadfp.read(1) 117 stream = self.mtnreadfp.read(1)
118 if stream not in 'mewptl': 118 if stream not in 'mewptl':
119 raise util.Abort(_('bad mtn packet - bad stream type %s') % stream) 119 raise error.Abort(_('bad mtn packet - bad stream type %s') % stream)
120 120
121 read = self.mtnreadfp.read(1) 121 read = self.mtnreadfp.read(1)
122 if read != ':': 122 if read != ':':
123 raise util.Abort(_('bad mtn packet - no divider before size')) 123 raise error.Abort(_('bad mtn packet - no divider before size'))
124 124
125 read = None 125 read = None
126 lengthstr = '' 126 lengthstr = ''
127 while read != ':': 127 while read != ':':
128 read = self.mtnreadfp.read(1) 128 read = self.mtnreadfp.read(1)
129 if not read: 129 if not read:
130 raise util.Abort(_('bad mtn packet - no end of packet size')) 130 raise error.Abort(_('bad mtn packet - no end of packet size'))
131 lengthstr += read 131 lengthstr += read
132 try: 132 try:
133 length = long(lengthstr[:-1]) 133 length = long(lengthstr[:-1])
134 except TypeError: 134 except TypeError:
135 raise util.Abort(_('bad mtn packet - bad packet size %s') 135 raise error.Abort(_('bad mtn packet - bad packet size %s')
136 % lengthstr) 136 % lengthstr)
137 137
138 read = self.mtnreadfp.read(length) 138 read = self.mtnreadfp.read(length)
139 if len(read) != length: 139 if len(read) != length:
140 raise util.Abort(_("bad mtn packet - unable to read full packet " 140 raise error.Abort(_("bad mtn packet - unable to read full packet "
141 "read %s of %s") % (len(read), length)) 141 "read %s of %s") % (len(read), length))
142 142
143 return (commandnbr, stream, length, read) 143 return (commandnbr, stream, length, read)
144 144
145 def mtnstdioreadcommandoutput(self, command): 145 def mtnstdioreadcommandoutput(self, command):
150 (commandnbr, stream, length)) 150 (commandnbr, stream, length))
151 151
152 if stream == 'l': 152 if stream == 'l':
153 # End of command 153 # End of command
154 if output != '0': 154 if output != '0':
155 raise util.Abort(_("mtn command '%s' returned %s") % 155 raise error.Abort(_("mtn command '%s' returned %s") %
156 (command, output)) 156 (command, output))
157 break 157 break
158 elif stream in 'ew': 158 elif stream in 'ew':
159 # Error, warning output 159 # Error, warning output
160 self.ui.warn(_('%s error:\n') % self.command) 160 self.ui.warn(_('%s error:\n') % self.command)
227 else: 227 else:
228 return self.revs 228 return self.revs
229 229
230 def getchanges(self, rev, full): 230 def getchanges(self, rev, full):
231 if full: 231 if full:
232 raise util.Abort(_("convert from monotone do not support --full")) 232 raise error.Abort(_("convert from monotone do not support --full"))
233 revision = self.mtnrun("get_revision", rev).split("\n\n") 233 revision = self.mtnrun("get_revision", rev).split("\n\n")
234 files = {} 234 files = {}
235 ignoremove = {} 235 ignoremove = {}
236 renameddirs = [] 236 renameddirs = []
237 copies = {} 237 copies = {}
328 version = 0.0 328 version = 0.0
329 try: 329 try:
330 versionstr = self.mtnrunsingle("interface_version") 330 versionstr = self.mtnrunsingle("interface_version")
331 version = float(versionstr) 331 version = float(versionstr)
332 except Exception: 332 except Exception:
333 raise util.Abort(_("unable to determine mtn automate interface " 333 raise error.Abort(_("unable to determine mtn automate interface "
334 "version")) 334 "version"))
335 335
336 if version >= 12.0: 336 if version >= 12.0:
337 self.automatestdio = True 337 self.automatestdio = True
338 self.ui.debug("mtn automate version %s - using automate stdio\n" % 338 self.ui.debug("mtn automate version %s - using automate stdio\n" %
342 self.mtnwritefp, self.mtnreadfp = self._run2('automate', 'stdio', 342 self.mtnwritefp, self.mtnreadfp = self._run2('automate', 'stdio',
343 '-d', self.path) 343 '-d', self.path)
344 # read the headers 344 # read the headers
345 read = self.mtnreadfp.readline() 345 read = self.mtnreadfp.readline()
346 if read != 'format-version: 2\n': 346 if read != 'format-version: 2\n':
347 raise util.Abort(_('mtn automate stdio header unexpected: %s') 347 raise error.Abort(_('mtn automate stdio header unexpected: %s')
348 % read) 348 % read)
349 while read != '\n': 349 while read != '\n':
350 read = self.mtnreadfp.readline() 350 read = self.mtnreadfp.readline()
351 if not read: 351 if not read:
352 raise util.Abort(_("failed to reach end of mtn automate " 352 raise error.Abort(_("failed to reach end of mtn automate "
353 "stdio headers")) 353 "stdio headers"))
354 else: 354 else:
355 self.ui.debug("mtn automate version %s - not using automate stdio " 355 self.ui.debug("mtn automate version %s - not using automate stdio "
356 "(automate >= 12.0 - mtn >= 0.46 is needed)\n" % version) 356 "(automate >= 12.0 - mtn >= 0.46 is needed)\n" % version)
357 357