Mercurial > hg
comparison mercurial/dispatch.py @ 34533:163fa0aea71e
dispatch: move initialization of sys.std* files
I'll add another Python 3 hack.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 02 Oct 2017 07:18:24 +0100 |
parents | b09b3eaf9c96 |
children | 021607b4ef49 |
comparison
equal
deleted
inserted
replaced
34532:b09b3eaf9c96 | 34533:163fa0aea71e |
---|---|
73 if exc is not None: | 73 if exc is not None: |
74 raise exc | 74 raise exc |
75 | 75 |
76 def run(): | 76 def run(): |
77 "run the command in sys.argv" | 77 "run the command in sys.argv" |
78 _initstdio() | |
78 req = request(pycompat.sysargv[1:]) | 79 req = request(pycompat.sysargv[1:]) |
79 err = None | 80 err = None |
80 try: | 81 try: |
81 status = (dispatch(req) or 0) & 255 | 82 status = (dispatch(req) or 0) & 255 |
82 except error.StdioError as e: | 83 except error.StdioError as e: |
92 if err is not None and err.errno != errno.EPIPE: | 93 if err is not None and err.errno != errno.EPIPE: |
93 req.ui.ferr.write('abort: %s\n' % | 94 req.ui.ferr.write('abort: %s\n' % |
94 encoding.strtolocal(err.strerror)) | 95 encoding.strtolocal(err.strerror)) |
95 req.ui.ferr.flush() | 96 req.ui.ferr.flush() |
96 sys.exit(status & 255) | 97 sys.exit(status & 255) |
98 | |
99 def _initstdio(): | |
100 for fp in (sys.stdin, sys.stdout, sys.stderr): | |
101 util.setbinary(fp) | |
97 | 102 |
98 def _getsimilar(symbols, value): | 103 def _getsimilar(symbols, value): |
99 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | 104 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() |
100 # The cutoff for similarity here is pretty arbitrary. It should | 105 # The cutoff for similarity here is pretty arbitrary. It should |
101 # probably be investigated and tweaked. | 106 # probably be investigated and tweaked. |