Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHG4eae533354ae: dispatch: remove Python 2 function variants
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
| Alphare |
| hg-reviewers |
| No Linters Available |
| No Unit Test Coverage |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/dispatch.py (148 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 8ed908ed2b7e | 7c293703dfd9 | Gregory Szorc | Feb 21 2022, 12:28 PM |
| _silencestdio() | _silencestdio() | ||||
| except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
| # Catch early/late KeyboardInterrupt as last ditch. Here nothing will | # Catch early/late KeyboardInterrupt as last ditch. Here nothing will | ||||
| # be printed to console to avoid another IOError/KeyboardInterrupt. | # be printed to console to avoid another IOError/KeyboardInterrupt. | ||||
| status = -1 | status = -1 | ||||
| sys.exit(status & 255) | sys.exit(status & 255) | ||||
| if pycompat.ispy3: | |||||
| def initstdio(): | def initstdio(): | ||||
| # stdio streams on Python 3 are io.TextIOWrapper instances proxying another | # stdio streams on Python 3 are io.TextIOWrapper instances proxying another | ||||
| # buffer. These streams will normalize \n to \r\n by default. Mercurial's | # buffer. These streams will normalize \n to \r\n by default. Mercurial's | ||||
| # preferred mechanism for writing output (ui.write()) uses io.BufferedWriter | # preferred mechanism for writing output (ui.write()) uses io.BufferedWriter | ||||
| # instances, which write to the underlying stdio file descriptor in binary | # instances, which write to the underlying stdio file descriptor in binary | ||||
| # mode. ui.write() uses \n for line endings and no line ending normalization | # mode. ui.write() uses \n for line endings and no line ending normalization | ||||
| # is attempted through this interface. This "just works," even if the system | # is attempted through this interface. This "just works," even if the system | ||||
| # preferred line ending is not \n. | # preferred line ending is not \n. | ||||
| # | # | ||||
| # But some parts of Mercurial (e.g. hooks) can still send data to sys.stdout | # But some parts of Mercurial (e.g. hooks) can still send data to sys.stdout | ||||
| # and sys.stderr. They will inherit the line ending normalization settings, | # and sys.stderr. They will inherit the line ending normalization settings, | ||||
| # potentially causing e.g. \r\n to be emitted. Since emitting \n should | # potentially causing e.g. \r\n to be emitted. Since emitting \n should | ||||
| # "just work," here we change the sys.* streams to disable line ending | # "just work," here we change the sys.* streams to disable line ending | ||||
| # normalization, ensuring compatibility with our ui type. | # normalization, ensuring compatibility with our ui type. | ||||
| if sys.stdout is not None: | if sys.stdout is not None: | ||||
| # write_through is new in Python 3.7. | # write_through is new in Python 3.7. | ||||
| kwargs = { | kwargs = { | ||||
| "newline": "\n", | "newline": "\n", | ||||
| "line_buffering": sys.stdout.line_buffering, | "line_buffering": sys.stdout.line_buffering, | ||||
| } | } | ||||
| if util.safehasattr(sys.stdout, "write_through"): | if util.safehasattr(sys.stdout, "write_through"): | ||||
| # pytype: disable=attribute-error | # pytype: disable=attribute-error | ||||
| kwargs["write_through"] = sys.stdout.write_through | kwargs["write_through"] = sys.stdout.write_through | ||||
| # pytype: enable=attribute-error | # pytype: enable=attribute-error | ||||
| sys.stdout = io.TextIOWrapper( | sys.stdout = io.TextIOWrapper( | ||||
| sys.stdout.buffer, | sys.stdout.buffer, sys.stdout.encoding, sys.stdout.errors, **kwargs | ||||
| sys.stdout.encoding, | |||||
| sys.stdout.errors, | |||||
| **kwargs | |||||
| ) | ) | ||||
| if sys.stderr is not None: | if sys.stderr is not None: | ||||
| kwargs = { | kwargs = { | ||||
| "newline": "\n", | "newline": "\n", | ||||
| "line_buffering": sys.stderr.line_buffering, | "line_buffering": sys.stderr.line_buffering, | ||||
| } | } | ||||
| if util.safehasattr(sys.stderr, "write_through"): | if util.safehasattr(sys.stderr, "write_through"): | ||||
| # pytype: disable=attribute-error | # pytype: disable=attribute-error | ||||
| kwargs["write_through"] = sys.stderr.write_through | kwargs["write_through"] = sys.stderr.write_through | ||||
| # pytype: enable=attribute-error | # pytype: enable=attribute-error | ||||
| sys.stderr = io.TextIOWrapper( | sys.stderr = io.TextIOWrapper( | ||||
| sys.stderr.buffer, | sys.stderr.buffer, sys.stderr.encoding, sys.stderr.errors, **kwargs | ||||
| sys.stderr.encoding, | |||||
| sys.stderr.errors, | |||||
| **kwargs | |||||
| ) | ) | ||||
| if sys.stdin is not None: | if sys.stdin is not None: | ||||
| # No write_through on read-only stream. | # No write_through on read-only stream. | ||||
| sys.stdin = io.TextIOWrapper( | sys.stdin = io.TextIOWrapper( | ||||
| sys.stdin.buffer, | sys.stdin.buffer, | ||||
| sys.stdin.encoding, | sys.stdin.encoding, | ||||
| sys.stdin.errors, | sys.stdin.errors, | ||||
| # None is universal newlines mode. | # None is universal newlines mode. | ||||
| newline=None, | newline=None, | ||||
| line_buffering=sys.stdin.line_buffering, | line_buffering=sys.stdin.line_buffering, | ||||
| ) | ) | ||||
| def _silencestdio(): | def _silencestdio(): | ||||
| for fp in (sys.stdout, sys.stderr): | for fp in (sys.stdout, sys.stderr): | ||||
| if fp is None: | if fp is None: | ||||
| continue | continue | ||||
| # Check if the file is okay | # Check if the file is okay | ||||
| try: | try: | ||||
| fp.flush() | fp.flush() | ||||
| continue | continue | ||||
| except IOError: | except IOError: | ||||
| pass | pass | ||||
| # Otherwise mark it as closed to silence "Exception ignored in" | # Otherwise mark it as closed to silence "Exception ignored in" | ||||
| # message emitted by the interpreter finalizer. | # message emitted by the interpreter finalizer. | ||||
| try: | try: | ||||
| fp.close() | fp.close() | ||||
| except IOError: | except IOError: | ||||
| pass | pass | ||||
| else: | |||||
| def initstdio(): | |||||
| for fp in (sys.stdin, sys.stdout, sys.stderr): | |||||
| procutil.setbinary(fp) | |||||
| def _silencestdio(): | |||||
| pass | |||||
| def _formatargs(args): | def _formatargs(args): | ||||
| return b' '.join(procutil.shellquote(a) for a in args) | return b' '.join(procutil.shellquote(a) for a in args) | ||||
| def dispatch(req): | def dispatch(req): | ||||
| """run the command specified in req.args; returns an integer status code""" | """run the command specified in req.args; returns an integer status code""" | ||||
| err = None | err = None | ||||