comparison mercurial/ui.py @ 26312:60558319ce72

ui: avoid mutable default arguments I almost introduced a bug around this code by accidentally mutating a default argument. There's no reason for these to exist. It is OK to not assign {} to environ in ui.system because util.system knows how to deal with that.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 22 Sep 2015 16:56:34 -0700
parents 6c962145f523
children c8f42c1926a5
comparison
equal deleted inserted replaced
26311:60dd8e3977f0 26312:60558319ce72
832 This adds an output label of "ui.debug". 832 This adds an output label of "ui.debug".
833 ''' 833 '''
834 if self.debugflag: 834 if self.debugflag:
835 opts['label'] = opts.get('label', '') + ' ui.debug' 835 opts['label'] = opts.get('label', '') + ' ui.debug'
836 self.write(*msg, **opts) 836 self.write(*msg, **opts)
837 def edit(self, text, user, extra={}, editform=None): 837 def edit(self, text, user, extra=None, editform=None):
838 if extra is None:
839 extra = {}
838 (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt", 840 (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt",
839 text=True) 841 text=True)
840 try: 842 try:
841 f = os.fdopen(fd, "w") 843 f = os.fdopen(fd, "w")
842 f.write(text) 844 f.write(text)
864 finally: 866 finally:
865 os.unlink(name) 867 os.unlink(name)
866 868
867 return t 869 return t
868 870
869 def system(self, cmd, environ={}, cwd=None, onerr=None, errprefix=None): 871 def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None):
870 '''execute shell command with appropriate output stream. command 872 '''execute shell command with appropriate output stream. command
871 output will be redirected if fout is not stdout. 873 output will be redirected if fout is not stdout.
872 ''' 874 '''
873 out = self.fout 875 out = self.fout
874 if any(s[1] for s in self._bufferstates): 876 if any(s[1] for s in self._bufferstates):