Mercurial > hg-stable
changeset 45035:24b1a8eb73aa
ui: add option to timestamp status and diagnostic messages
Differential Revision: https://phab.mercurial-scm.org/D8640
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Thu, 18 Jun 2020 15:13:38 +0200 |
parents | 4a503c1b664a |
children | df3660cc60f5 |
files | mercurial/configitems.py mercurial/ui.py tests/test-progress.t tests/test-pull.t |
diffstat | 4 files changed, 63 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/configitems.py Mon Jun 29 20:53:32 2020 +0900 +++ b/mercurial/configitems.py Thu Jun 18 15:13:38 2020 +0200 @@ -1384,6 +1384,9 @@ b'ui', b'timeout.warn', default=0, ) coreconfigitem( + b'ui', b'timestamp-output', default=False, +) +coreconfigitem( b'ui', b'traceback', default=False, ) coreconfigitem(
--- a/mercurial/ui.py Mon Jun 29 20:53:32 2020 +0900 +++ b/mercurial/ui.py Thu Jun 18 15:13:38 2020 +0200 @@ -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-output') self.tracebackflag = self.configbool(b'ui', b'traceback') self.logblockedtimes = self.configbool(b'ui', b'logblockedtimes') @@ -1217,7 +1220,20 @@ ) * 1000 def _writemsg(self, dest, *args, **opts): + timestamp = self.showtimestamp and opts.get('type') in { + b'debug', + b'error', + b'note', + b'status', + b'warning', + } + 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)
--- a/tests/test-progress.t Mon Jun 29 20:53:32 2020 +0900 +++ b/tests/test-progress.t Thu Jun 18 15:13:38 2020 +0200 @@ -18,7 +18,8 @@ > @command(b'loop', > [(b'', b'total', b'', b'override for total'), > (b'', b'nested', False, b'show nested results'), - > (b'', b'parallel', False, b'show parallel sets of results')], + > (b'', b'parallel', False, b'show parallel sets of results'), + > (b'', b'warn', False, b'show warning if step divisible by 3')], > b'hg loop LOOPS', > norepo=True) > def loop(ui, loops, **opts): @@ -32,6 +33,7 @@ > if opts.get('nested', None): > nested = True > loops = abs(loops) + > showwarn = opts.get('warn', False) > > progress = ui.makeprogress(topiclabel, unit=b'loopnum', total=total) > other = ui.makeprogress(b'other', unit=b'othernum', total=total) @@ -48,6 +50,8 @@ > for j in range(nested_steps): > nested.update(j, item=b'nested.%d' % j) > nested.complete() + > if showwarn and i % 3 == 0: + > ui.warn(b'reached step %d\n' %i) > progress.complete() > > topiclabel = b'loop' @@ -179,6 +183,42 @@ loop [ <=> ] 5/4\r (no-eol) (esc) \r (no-eol) (esc) +test interaction with ui.warn + + $ hg loop --warn 6 + \r (no-eol) (esc) + loop [ ] 0/6\r (no-eol) (esc) + \r (no-eol) (esc) + reached step 0 + \r (no-eol) (esc) + loop [=======> ] 1/6\r (no-eol) (esc) + loop [===============> ] 2/6\r (no-eol) (esc) + loop [=======================> ] 3/6\r (no-eol) (esc) + \r (no-eol) (esc) + reached step 3 + \r (no-eol) (esc) + loop [===============================> ] 4/6\r (no-eol) (esc) + loop [=======================================> ] 5/6\r (no-eol) (esc) + \r (no-eol) (esc) + +test interaction with ui.timestamp-output + + $ hg loop --warn --config ui.timestamp-output=true 6 + \r (no-eol) (esc) + loop [ ] 0/6\r (no-eol) (esc) + \r (no-eol) (esc) + \[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]\] reached step 0 (re) + \r (no-eol) (esc) + loop [=======> ] 1/6\r (no-eol) (esc) + loop [===============> ] 2/6\r (no-eol) (esc) + loop [=======================> ] 3/6\r (no-eol) (esc) + \r (no-eol) (esc) + \[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]\] reached step 3 (re) + \r (no-eol) (esc) + loop [===============================> ] 4/6\r (no-eol) (esc) + loop [=======================================> ] 5/6\r (no-eol) (esc) + \r (no-eol) (esc) + test immediate progress completion $ hg -y loop 0
--- a/tests/test-pull.t Mon Jun 29 20:53:32 2020 +0900 +++ b/tests/test-pull.t Thu Jun 18 15:13:38 2020 +0200 @@ -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-output=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'