Manuel Jacob <me@manueljacob.de> [Wed, 08 Jul 2020 08:57:21 +0200] rev 45048
archival: abort if compression method is unavailable
`tarfile.CompressionError` is documented to be the "exception for unavailable
compression methods".
Also, make tests conditional on whether the lzma module is available or not.
Manuel Jacob <me@manueljacob.de> [Wed, 08 Jul 2020 08:25:30 +0200] rev 45047
demandimport: ignore `lzma` module for demandimport
This makes importing the module fail if the `_lzma` module is not present.
This makes e.g. tarfile correctly recognize if LZMA support is not present. It
changes the exception
File "/usr/lib/python3.6/tarfile.py", line 1694, in xzopen
fileobj = lzma.LZMAFile(fileobj or name, mode, preset=preset)
AttributeError: module 'lzma' has no attribute 'LZMAFile'
to the more correct exception
File "/usr/lib/python3.6/tarfile.py", line 1692, in xzopen
raise CompressionError("lzma module is not available")
tarfile.CompressionError: lzma module is not available
Also, it prevents that the error "abort: No module named '_lzma'!" is shown when
a development warning is to be shown. The reason why that happened is that for
showing the warning, we get information about the stack frames from the inspect
module, which accesses the `__file__` attribute of all modules in `sys.modules`
to build some cache, causing all modules (including `lzma`) to be imported.
Augie Fackler <augie@google.com> [Mon, 06 Jul 2020 22:02:50 -0400] rev 45046
merge with stable
Manuel Jacob <me@manueljacob.de> [Sun, 05 Jul 2020 13:09:22 +0200] rev 45045
procutil: make mercurial.utils.procutil.stderr unbuffered
For most Mercurial code, it doesn’t make a difference, as the ui object flushes
stderr explicitly (after the change, we could get rid of the explicit flush).
One example where it makes a observable difference is mercurial.util.timed().
Without the patch, the time is not immediately shown on Python 3. With the
patch, it’s shown immediately on all Python versions and platforms.
Manuel Jacob <me@manueljacob.de> [Sun, 05 Jul 2020 13:05:06 +0200] rev 45044
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de> [Sat, 04 Jul 2020 11:41:39 +0200] rev 45043
procutil: make stdout line-buffered on Windows if connected to TTY
Windows doesn’t support line buffering. Previously, we worked around that by
setting the stream unbuffered. Instead, we can use our own line buffering we
already use on Python 3.
Manuel Jacob <me@manueljacob.de> [Sat, 04 Jul 2020 11:21:44 +0200] rev 45042
procutil: split import and reassignment
Besides making the code clearer, it will reduce the diff in the next patch.
Manuel Jacob <me@manueljacob.de> [Sat, 04 Jul 2020 11:15:58 +0200] rev 45041
procutil: move assignments closer to reassignments
Doing reassignments is an anti-pattern IMHO, but I see how it makes sense here.
When first looking at this code after jumping here with ctags, I missed the
fact that stdout was reassigned. To make the code clearer, the assignments
should be as close as possible to the reassignments.
Manuel Jacob <me@manueljacob.de> [Sat, 04 Jul 2020 12:15:41 +0200] rev 45040
procutil: factor out conditional creation of LineBufferedWrapper
At the same time, document the logic and generalize it to work on all Python
versions.
Manuel Jacob <me@manueljacob.de> [Thu, 02 Jul 2020 04:37:18 +0200] rev 45039
procutil: define LineBufferedWrapper on all Python versions
There’s nothing Python 3-only about LineBufferedWrapper. In the future, we may
want to use it on Windows, to work around missing line-buffering support.
Manuel Jacob <me@manueljacob.de> [Sat, 04 Jul 2020 10:47:04 +0200] rev 45038
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de> [Thu, 02 Jul 2020 02:51:09 +0200] rev 45037
cleanup: use slightly more meaningful name for temporary variable
Not that it makes a big difference, but using `p` instead of `x` is clearer to
me.
Manuel Jacob <me@manueljacob.de> [Thu, 02 Jul 2020 02:46:15 +0200] rev 45036
cleanup: use any() instead of checking truthiness of temporary list
It was not immediately obvious to me, when first seeing this, why a list was
created. It needed a second look to understand that the purpose was to check
whether the condition is true for any of the parents. Using any() for that is
clearer.
Pulkit Goyal <7895pulkit@gmail.com> [Fri, 03 Jul 2020 13:45:59 +0530] rev 45035
chg: suppress OSError in _restoreio() and add some logging (
issue6330)
According to
issue6330, running chg on heavy loaded systems can lead to
following error:
```
Traceback (most recent call last):
File "path-to-hg/mercurial/commandserver.py", line 650, in _acceptnewconnection
self._runworker(conn)
File "path-to-hg/mercurial/commandserver.py", line 701, in _runworker
prereposetups=[self._reposetup],
File "path-to-hg/mercurial/commandserver.py", line 470, in _serverequest
sv.cleanup()
File "path-to-hg/mercurial/chgserver.py", line 381, in cleanup
self._restoreio()
File "path-to-hg/mercurial/chgserver.py", line 444, in _restoreio
os.dup2(fd, fp.fileno())
OSError: [Errno 16] Device or resource busy
```
[man dup2] indicates that, on Linux, EBUSY comes from a race condition
between open() and dup2().
However it's not clear why open() race occurred for newfd=stdin/out/err.
We suppress the OSError in _restoreio() since the forked worker process will
finish anyway and add some logging.
Thanks to Mitchell Plamann for a detailed bug description and Yuya Nishihara for
suggesting the fix.
Manuel Jacob <me@manueljacob.de> [Fri, 03 Jul 2020 23:25:19 +0200] rev 45034
py3: fix crash when server address is 0.0.0.0 (
issue6362)
`socket.getfqdn()` assumes that the name is passed as `str` on Python 3 and
always returns `str` in this case. Mercurial passed `bytes` (but still expected
a `str` result), which worked by chance in many cases, except for e.g.
b'0.0.0.0', which was returned unchanged, breaking later code.
Instead of calling `socket.getfqdn()`, we can also use `self.server_name` from
the base `HTTPServer` class, which already stores the FQDN of the locally-bound
socket name (see `BaseHTTPServer.py` in the Python 2 stdlib and
`http/server.py` in the Python 3 stdlib).