[Updated] [+- ] D8640: ui: add option to timestamp status and diagnostic messages

joerg.sonnenberger (Joerg Sonnenberger) phabricator at mercurial-scm.org
Thu Jun 18 21:45:08 UTC 2020


joerg.sonnenberger updated this revision to Diff 21665.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8640?vs=21662&id=21665

BRANCH
  stable

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8640/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8640

AFFECTED FILES
  mercurial/configitems.py
  mercurial/ui.py
  tests/test-pull.t

CHANGE DETAILS

diff --git a/tests/test-pull.t b/tests/test-pull.t
--- a/tests/test-pull.t
+++ b/tests/test-pull.t
@@ -142,9 +142,9 @@
   pulling from ssh://fakehost%7Ctouch%24%7BIFS%7Downed/path
   abort: no suitable response from remote hg!
   [255]
-  $ hg pull 'ssh://fakehost%7Ctouch%20owned/path'
-  pulling from ssh://fakehost%7Ctouch%20owned/path
-  abort: no suitable response from remote hg!
+  $ hg --config ui.timestamp=true pull 'ssh://fakehost%7Ctouch%20owned/path'
+  \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] pulling from ssh://fakehost%7Ctouch%20owned/path (re)
+  \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] abort: no suitable response from remote hg! (re)
   [255]
 
   $ [ ! -f owned ] || echo 'you got owned'
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -9,6 +9,7 @@
 
 import collections
 import contextlib
+import datetime
 import errno
 import getpass
 import inspect
@@ -242,6 +243,7 @@
         self._terminfoparams = {}
         self._styles = {}
         self._uninterruptible = False
+        self.showtimestamp = False
 
         if src:
             self._fout = src._fout
@@ -561,6 +563,7 @@
             self._reportuntrusted = self.debugflag or self.configbool(
                 b"ui", b"report_untrusted"
             )
+            self.showtimestamp = self.configbool(b'ui', b'timestamp')
             self.tracebackflag = self.configbool(b'ui', b'traceback')
             self.logblockedtimes = self.configbool(b'ui', b'logblockedtimes')
 
@@ -1217,7 +1220,12 @@
             ) * 1000
 
     def _writemsg(self, dest, *args, **opts):
+        timestamp = opts.pop('timestamp', False)
+        if timestamp:
+            args = (b'[%s] ' % bytes(datetime.datetime.now().isoformat(), 'ASCII'),) + args
         _writemsgwith(self._write, dest, *args, **opts)
+        if timestamp:
+            dest.flush()
 
     def _writemsgnobuf(self, dest, *args, **opts):
         _writemsgwith(self._writenobuf, dest, *args, **opts)
@@ -1726,21 +1734,21 @@
         This adds an output label of "ui.status".
         '''
         if not self.quiet:
-            self._writemsg(self._fmsgout, type=b'status', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'status', timestamp=self.showtimestamp, *msg, **opts)
 
     def warn(self, *msg, **opts):
         '''write warning message to output (stderr)
 
         This adds an output label of "ui.warning".
         '''
-        self._writemsg(self._fmsgerr, type=b'warning', *msg, **opts)
+        self._writemsg(self._fmsgerr, type=b'warning', timestamp=self.showtimestamp, *msg, **opts)
 
     def error(self, *msg, **opts):
         '''write error message to output (stderr)
 
         This adds an output label of "ui.error".
         '''
-        self._writemsg(self._fmsgerr, type=b'error', *msg, **opts)
+        self._writemsg(self._fmsgerr, type=b'error', timestamp=self.showtimestamp, *msg, **opts)
 
     def note(self, *msg, **opts):
         '''write note to output (if ui.verbose is True)
@@ -1748,7 +1756,7 @@
         This adds an output label of "ui.note".
         '''
         if self.verbose:
-            self._writemsg(self._fmsgout, type=b'note', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'note', timestamp=self.showtimestamp, *msg, **opts)
 
     def debug(self, *msg, **opts):
         '''write debug message to output (if ui.debugflag is True)
@@ -1756,7 +1764,7 @@
         This adds an output label of "ui.debug".
         '''
         if self.debugflag:
-            self._writemsg(self._fmsgout, type=b'debug', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'debug', timestamp=self.showtimestamp, *msg, **opts)
             self.log(b'debug', b'%s', b''.join(msg))
 
     # Aliases to defeat check-code.
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1391,6 +1391,9 @@
     b'ui', b'timeout.warn', default=0,
 )
 coreconfigitem(
+    b'ui', b'timestamp', default=False,
+)
+coreconfigitem(
     b'ui', b'traceback', default=False,
 )
 coreconfigitem(



To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200618/785b0ba0/attachment-0002.html>


More information about the Mercurial-patches mailing list