comparison mercurial/chgserver.py @ 31108:3f8f53190d6a

chg: deduplicate error handling of ui.system() This moves 'onerr' handling from low-level util.system() to higher level, which seems better API separation.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 19 Feb 2017 01:16:45 +0900
parents fbce78c58f1e
children 82b3ec04b652
comparison
equal deleted inserted replaced
31107:fbce78c58f1e 31108:3f8f53190d6a
177 if src: 177 if src:
178 self._csystem = getattr(src, '_csystem', csystem) 178 self._csystem = getattr(src, '_csystem', csystem)
179 else: 179 else:
180 self._csystem = csystem 180 self._csystem = csystem
181 181
182 def _runsystem(self, cmd, environ, cwd, onerr, errprefix, out): 182 def _runsystem(self, cmd, environ, cwd, out):
183 # fallback to the original system method if the output needs to be 183 # fallback to the original system method if the output needs to be
184 # captured (to self._buffers), or the output stream is not stdout 184 # captured (to self._buffers), or the output stream is not stdout
185 # (e.g. stderr, cStringIO), because the chg client is not aware of 185 # (e.g. stderr, cStringIO), because the chg client is not aware of
186 # these situations and will behave differently (write to stdout). 186 # these situations and will behave differently (write to stdout).
187 if (out is not self.fout 187 if (out is not self.fout
188 or not util.safehasattr(self.fout, 'fileno') 188 or not util.safehasattr(self.fout, 'fileno')
189 or self.fout.fileno() != util.stdout.fileno()): 189 or self.fout.fileno() != util.stdout.fileno()):
190 return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr, 190 return util.system(cmd, environ=environ, cwd=cwd, out=out)
191 errprefix=errprefix, out=out)
192 self.flush() 191 self.flush()
193 rc = self._csystem(cmd, util.shellenviron(environ), cwd) 192 return self._csystem(cmd, util.shellenviron(environ), cwd)
194 if rc and onerr:
195 errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
196 util.explainexit(rc)[0])
197 if errprefix:
198 errmsg = '%s: %s' % (errprefix, errmsg)
199 raise onerr(errmsg)
200 return rc
201 193
202 def _runpager(self, cmd): 194 def _runpager(self, cmd):
203 self._csystem(cmd, util.shellenviron(), type='pager', 195 self._csystem(cmd, util.shellenviron(), type='pager',
204 cmdtable={'attachio': attachio}) 196 cmdtable={'attachio': attachio})
205 197