Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG58f73e9ccfff: httppeer: use context manager when writing temporary bundle to send
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/httppeer.py (13 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
43d78611f563 | 2c74337e6483 | Martin von Zweigbergk | Sep 4 2019, 1:42 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz |
if err.args[0] in (errno.ECONNRESET, errno.EPIPE): | if err.args[0] in (errno.ECONNRESET, errno.EPIPE): | ||||
raise error.Abort(_('push failed: %s') % err.args[1]) | raise error.Abort(_('push failed: %s') % err.args[1]) | ||||
raise error.Abort(err.args[1]) | raise error.Abort(err.args[1]) | ||||
finally: | finally: | ||||
fp.close() | fp.close() | ||||
os.unlink(tempname) | os.unlink(tempname) | ||||
def _calltwowaystream(self, cmd, fp, **args): | def _calltwowaystream(self, cmd, fp, **args): | ||||
fh = None | |||||
fp_ = None | fp_ = None | ||||
filename = None | filename = None | ||||
try: | try: | ||||
# dump bundle to disk | # dump bundle to disk | ||||
fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg") | fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg") | ||||
fh = os.fdopen(fd, r"wb") | with os.fdopen(fd, r"wb") as fh: | ||||
d = fp.read(4096) | d = fp.read(4096) | ||||
while d: | while d: | ||||
fh.write(d) | fh.write(d) | ||||
d = fp.read(4096) | d = fp.read(4096) | ||||
fh.close() | |||||
# start http push | # start http push | ||||
fp_ = httpconnection.httpsendfile(self.ui, filename, "rb") | fp_ = httpconnection.httpsendfile(self.ui, filename, "rb") | ||||
headers = {r'Content-Type': r'application/mercurial-0.1'} | headers = {r'Content-Type': r'application/mercurial-0.1'} | ||||
return self._callstream(cmd, data=fp_, headers=headers, **args) | return self._callstream(cmd, data=fp_, headers=headers, **args) | ||||
finally: | finally: | ||||
if fp_ is not None: | if fp_ is not None: | ||||
fp_.close() | fp_.close() | ||||
if fh is not None: | if filename is not None: | ||||
fh.close() | |||||
os.unlink(filename) | os.unlink(filename) | ||||
def _callcompressable(self, cmd, **args): | def _callcompressable(self, cmd, **args): | ||||
return self._callstream(cmd, _compressible=True, **args) | return self._callstream(cmd, _compressible=True, **args) | ||||
def _abort(self, exception): | def _abort(self, exception): | ||||
raise exception | raise exception | ||||