Rev 4864: Revisit priority order for COLUMNS in http://bazaar.launchpad.net/~vila/bzr/integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Dec 4 11:29:25 GMT 2009


At http://bazaar.launchpad.net/~vila/bzr/integration

------------------------------------------------------------
revno: 4864 [merge]
revision-id: v.ladeuil+lp at free.fr-20091204112911-qe7brgtb6l04nc69
parent: pqm at pqm.ubuntu.com-20091204105949-cp822ctg4bp7vgd4
parent: v.ladeuil+lp at free.fr-20091204112757-2dz18xsbug1322q7
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Fri 2009-12-04 12:29:11 +0100
message:
  Revisit priority order for COLUMNS
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2009-12-04 10:09:11 +0000
+++ b/bzrlib/osutils.py	2009-12-04 11:27:57 +0000
@@ -1358,17 +1358,21 @@
     if sys.platform == 'win32':
         return win32utils.get_console_size(defaultx=None)[0]
 
+    # If COLUMNS is set, take it, the terminal knows better (at least under
+    # emacs, COLUMNS gives an accurate answer while the fcntl.ioctl call below
+    # doesn't) -- vila 20091204
+    try:
+        return int(os.environ['COLUMNS'])
+    except (KeyError, ValueError):
+        pass
+
     try:
         import struct, fcntl, termios
         s = struct.pack('HHHH', 0, 0, 0, 0)
         x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
         width = struct.unpack('HHHH', x)[1]
     except (IOError, AttributeError):
-        # If COLUMNS is set, take it
-        try:
-            return int(os.environ['COLUMNS'])
-        except (KeyError, ValueError):
-            return None
+        return None
 
     if width <= 0:
         # Consider invalid values as meaning no width

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2009-12-04 10:09:11 +0000
+++ b/bzrlib/tests/test_osutils.py	2009-12-04 11:27:57 +0000
@@ -1936,6 +1936,11 @@
         os.environ['BZR_COLUMNS'] = '12'
         self.assertEquals(12, osutils.terminal_width())
 
+    def test_falls_back_to_COLUMNS(self):
+        del os.environ['BZR_COLUMNS']
+        os.environ['COLUMNS'] = '42'
+        self.assertEquals(42, osutils.terminal_width())
+
     def test_tty_default_without_columns(self):
         del os.environ['BZR_COLUMNS']
         del os.environ['COLUMNS']



More information about the bazaar-commits mailing list