diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -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( 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-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) diff --git a/tests/test-progress.t b/tests/test-progress.t --- a/tests/test-progress.t +++ b/tests/test-progress.t @@ -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 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-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'