mercurial/ui.py
changeset 30976 e92daf156d5c
parent 30945 8b83b626fb1e
child 30978 fdecd24ca4dc
equal deleted inserted replaced
30975:22fbca1d11ed 30976:e92daf156d5c
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
       
    10 import collections
    10 import contextlib
    11 import contextlib
    11 import errno
    12 import errno
    12 import getpass
    13 import getpass
    13 import inspect
    14 import inspect
    14 import os
    15 import os
   136         self._trustusers = set()
   137         self._trustusers = set()
   137         self._trustgroups = set()
   138         self._trustgroups = set()
   138         self.callhooks = True
   139         self.callhooks = True
   139         # Insecure server connections requested.
   140         # Insecure server connections requested.
   140         self.insecureconnections = False
   141         self.insecureconnections = False
       
   142         # Blocked time
       
   143         self.logblockedtimes = False
   141 
   144 
   142         if src:
   145         if src:
   143             self.fout = src.fout
   146             self.fout = src.fout
   144             self.ferr = src.ferr
   147             self.ferr = src.ferr
   145             self.fin = src.fin
   148             self.fin = src.fin
   153             self.callhooks = src.callhooks
   156             self.callhooks = src.callhooks
   154             self.insecureconnections = src.insecureconnections
   157             self.insecureconnections = src.insecureconnections
   155             self.fixconfig()
   158             self.fixconfig()
   156 
   159 
   157             self.httppasswordmgrdb = src.httppasswordmgrdb
   160             self.httppasswordmgrdb = src.httppasswordmgrdb
       
   161             self._blockedtimes = src._blockedtimes
   158         else:
   162         else:
   159             self.fout = util.stdout
   163             self.fout = util.stdout
   160             self.ferr = util.stderr
   164             self.ferr = util.stderr
   161             self.fin = util.stdin
   165             self.fin = util.stdin
   162 
   166 
   163             # shared read-only environment
   167             # shared read-only environment
   164             self.environ = encoding.environ
   168             self.environ = encoding.environ
   165 
   169 
   166             self.httppasswordmgrdb = httppasswordmgrdbproxy()
   170             self.httppasswordmgrdb = httppasswordmgrdbproxy()
       
   171             self._blockedtimes = collections.defaultdict(int)
   167 
   172 
   168         allowed = self.configlist('experimental', 'exportableenviron')
   173         allowed = self.configlist('experimental', 'exportableenviron')
   169         if '*' in allowed:
   174         if '*' in allowed:
   170             self._exportableenviron = self.environ
   175             self._exportableenviron = self.environ
   171         else:
   176         else:
   189     def resetstate(self):
   194     def resetstate(self):
   190         """Clear internal state that shouldn't persist across commands"""
   195         """Clear internal state that shouldn't persist across commands"""
   191         if self._progbar:
   196         if self._progbar:
   192             self._progbar.resetstate()  # reset last-print time of progress bar
   197             self._progbar.resetstate()  # reset last-print time of progress bar
   193         self.httppasswordmgrdb = httppasswordmgrdbproxy()
   198         self.httppasswordmgrdb = httppasswordmgrdbproxy()
       
   199 
       
   200     @contextlib.contextmanager
       
   201     def timeblockedsection(self, key):
       
   202         starttime = util.timer()
       
   203         try:
       
   204             yield
       
   205         finally:
       
   206             self._blockedtimes[key + '_blocked'] += \
       
   207                 (util.timer() - starttime) * 1000
   194 
   208 
   195     def formatter(self, topic, opts):
   209     def formatter(self, topic, opts):
   196         return formatter.formatter(self, topic, opts)
   210         return formatter.formatter(self, topic, opts)
   197 
   211 
   198     def _trusted(self, fp, f):
   212     def _trusted(self, fp, f):
   293             if self.verbose and self.quiet:
   307             if self.verbose and self.quiet:
   294                 self.quiet = self.verbose = False
   308                 self.quiet = self.verbose = False
   295             self._reportuntrusted = self.debugflag or self.configbool("ui",
   309             self._reportuntrusted = self.debugflag or self.configbool("ui",
   296                 "report_untrusted", True)
   310                 "report_untrusted", True)
   297             self.tracebackflag = self.configbool('ui', 'traceback', False)
   311             self.tracebackflag = self.configbool('ui', 'traceback', False)
       
   312             self.logblockedtimes = self.configbool('ui', 'logblockedtimes')
   298 
   313 
   299         if section in (None, 'trusted'):
   314         if section in (None, 'trusted'):
   300             # update trust information
   315             # update trust information
   301             self._trustusers.update(self.configlist('trusted', 'users'))
   316             self._trustusers.update(self.configlist('trusted', 'users'))
   302             self._trustgroups.update(self.configlist('trusted', 'groups'))
   317             self._trustgroups.update(self.configlist('trusted', 'groups'))