comparison mercurial/ui.py @ 30291:e9fca89c6d58

py3: use encoding.environ in ui.py Using source transformer we add b'' everywhere. So there are no chances that those bytes string will work with os.environ on Py3 as that returns a dict of unicodes. We are relying on the errors, even though no error is raised even in future, these pieces of codes will tend to do wrong things. if statements can result in wrong boolean and certain errors can be raised while using this piece of code. Let's not wait for them to happen, fix what is wrong. If this patch goes in, I will try to do it for all the cases. Leaving it as it is buggy.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 03 Nov 2016 03:12:57 +0530
parents 3d2ea1403c62
children 4b1af1c867fa
comparison
equal deleted inserted replaced
30290:c90a05124fae 30291:e9fca89c6d58
20 from .i18n import _ 20 from .i18n import _
21 from .node import hex 21 from .node import hex
22 22
23 from . import ( 23 from . import (
24 config, 24 config,
25 encoding,
25 error, 26 error,
26 formatter, 27 formatter,
27 progress, 28 progress,
28 scmutil, 29 scmutil,
29 util, 30 util,
567 568
568 The return value can either be 569 The return value can either be
569 - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT 570 - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
570 - True otherwise 571 - True otherwise
571 ''' 572 '''
572 if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ: 573 if ('HGPLAIN' not in encoding.environ and
574 'HGPLAINEXCEPT' not in encoding.environ):
573 return False 575 return False
574 exceptions = os.environ.get('HGPLAINEXCEPT', '').strip().split(',') 576 exceptions = encoding.environ.get('HGPLAINEXCEPT',
577 '').strip().split(',')
575 if feature and exceptions: 578 if feature and exceptions:
576 return feature not in exceptions 579 return feature not in exceptions
577 return True 580 return True
578 581
579 def username(self): 582 def username(self):
582 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL 585 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
583 and stop searching if one of these is set. 586 and stop searching if one of these is set.
584 If not found and ui.askusername is True, ask the user, else use 587 If not found and ui.askusername is True, ask the user, else use
585 ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". 588 ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname".
586 """ 589 """
587 user = os.environ.get("HGUSER") 590 user = encoding.environ.get("HGUSER")
588 if user is None: 591 if user is None:
589 user = self.config("ui", ["username", "user"]) 592 user = self.config("ui", ["username", "user"])
590 if user is not None: 593 if user is not None:
591 user = os.path.expandvars(user) 594 user = os.path.expandvars(user)
592 if user is None: 595 if user is None:
593 user = os.environ.get("EMAIL") 596 user = encoding.environ.get("EMAIL")
594 if user is None and self.configbool("ui", "askusername"): 597 if user is None and self.configbool("ui", "askusername"):
595 user = self.prompt(_("enter a commit username:"), default=None) 598 user = self.prompt(_("enter a commit username:"), default=None)
596 if user is None and not self.interactive(): 599 if user is None and not self.interactive():
597 try: 600 try:
598 user = '%s@%s' % (util.getuser(), socket.getfqdn()) 601 user = '%s@%s' % (util.getuser(), socket.getfqdn())
812 return i 815 return i
813 816
814 def termwidth(self): 817 def termwidth(self):
815 '''how wide is the terminal in columns? 818 '''how wide is the terminal in columns?
816 ''' 819 '''
817 if 'COLUMNS' in os.environ: 820 if 'COLUMNS' in encoding.environ:
818 try: 821 try:
819 return int(os.environ['COLUMNS']) 822 return int(encoding.environ['COLUMNS'])
820 except ValueError: 823 except ValueError:
821 pass 824 pass
822 return util.termwidth() 825 return util.termwidth()
823 826
824 def formatted(self): 827 def formatted(self):
1073 # instead default to E to plumb commit messages to 1076 # instead default to E to plumb commit messages to
1074 # avoid confusion. 1077 # avoid confusion.
1075 editor = 'E' 1078 editor = 'E'
1076 else: 1079 else:
1077 editor = 'vi' 1080 editor = 'vi'
1078 return (os.environ.get("HGEDITOR") or 1081 return (encoding.environ.get("HGEDITOR") or
1079 self.config("ui", "editor") or 1082 self.config("ui", "editor") or
1080 os.environ.get("VISUAL") or 1083 encoding.environ.get("VISUAL") or
1081 os.environ.get("EDITOR", editor)) 1084 encoding.environ.get("EDITOR", editor))
1082 1085
1083 @util.propertycache 1086 @util.propertycache
1084 def _progbar(self): 1087 def _progbar(self):
1085 """setup the progbar singleton to the ui object""" 1088 """setup the progbar singleton to the ui object"""
1086 if (self.quiet or self.debugflag 1089 if (self.quiet or self.debugflag