[PATCH stable v2] progress: disable progress when the terminal resembles cmd.exe (issue4801)

Augie Fackler raf at durin42.com
Tue Mar 1 19:42:29 UTC 2016


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1456860899 18000
#      Tue Mar 01 14:34:59 2016 -0500
# Branch stable
# Node ID 301d88f9aeeae128fa8a4e15303f4ac64c7afc69
# Parent  5f95d6a70e9b37bf11487580a5c750d861baa8f5
# EXP-Topic progress-cmd
progress: disable progress when the terminal resembles cmd.exe (issue4801)

It appears that cmd.exe is hopelessly unreliable when it comes to
handling carriage returns, based on my own web searching. The blessed
mechanism for performing cursor positioning appears to be
SetConsoleCursorPosition(), but I don't have easy access to a Windows
machine, and we need a simple fix for stable anyway.

Ideally, someone on Windows can write a fix for this and contribute it.

diff --git a/mercurial/progress.py b/mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+import os
 import sys
 import threading
 import time
@@ -18,8 +19,17 @@ def spacejoin(*args):
     return ' '.join(s for s in args if s)
 
 def shouldprint(ui):
-    return not (ui.quiet or ui.plain()) and (
-        ui._isatty(sys.stderr) or ui.configbool('progress', 'assume-tty'))
+    if ui.configbool('progress', 'assume-tty'):
+        return True
+    if os.name == 'nt' and 'TERM' not in os.environ:
+        # We think this is cmd.exe, which means we're going to skip
+        # progress. It appears that carriage returns are unreliable
+        # for cursor positioning in cmd.exe, and that we should
+        # instead be using SetConsoleCursorPosition() to move the
+        # cursor for progress writes. See issue4801 for the report
+        # that revealed this problem.
+        return False
+    return not (ui.quiet or ui.plain()) and ui._isatty(sys.stderr)
 
 def fmtremaining(seconds):
     """format a number of remaining seconds in human readable way


More information about the Mercurial-devel mailing list