[PATCH 3 of 7] scmutil: narrow ImportError handling in termwidth()

Yuya Nishihara yuya at tcha.org
Fri Nov 4 03:48:58 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1476967829 -32400
#      Thu Oct 20 21:50:29 2016 +0900
# Node ID 96aa6ffa3be75ea5a4fa9fe2d0440758d744b6af
# Parent  433d529a9bbb4017281215dd3fa028410682e4dc
# EXP-Topic stdio
scmutil: narrow ImportError handling in termwidth()

The array module must exist. It's sufficient to suppress the ImportError of
termios. Also salvaged the comment why we have to handle AttributeError, from
7002bb17cc5e.

diff --git a/mercurial/scmposix.py b/mercurial/scmposix.py
--- a/mercurial/scmposix.py
+++ b/mercurial/scmposix.py
@@ -1,5 +1,6 @@
 from __future__ import absolute_import
 
+import array
 import errno
 import fcntl
 import os
@@ -43,8 +44,11 @@ def userrcpath():
 
 def termwidth(ui):
     try:
-        import array
         import termios
+        TIOCGWINSZ = termios.TIOCGWINSZ  # unavailable on IRIX (issue3449)
+    except (AttributeError, ImportError):
+        return 80
+    if True:
         for dev in (ui.ferr, ui.fout, ui.fin):
             try:
                 try:
@@ -53,13 +57,11 @@ def termwidth(ui):
                     continue
                 if not os.isatty(fd):
                     continue
-                try:
-                    arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
+                if True:
+                    arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
                     width = array.array('h', arri)[1]
                     if width > 0:
                         return width
-                except AttributeError:
-                    pass
             except ValueError:
                 pass
             except IOError as e:
@@ -67,6 +69,4 @@ def termwidth(ui):
                     pass
                 else:
                     raise
-    except ImportError:
-        pass
     return 80


More information about the Mercurial-devel mailing list