comparison mercurial/util.py @ 1951:696230e52e4d

add HGRCPATH env var, list of places to look for hgrc files. if set, override default hgrc search path. if empty, only .hg/hgrc of current repo read. for each element, if directory, all entries in directory with end in ".rc" are added to path. else, element is added to path. big thing about this change is that user "~/.hgrc" and system hgrc not longer breaks tests. run-tests makes HGRCPATH empty now.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 14 Mar 2006 21:40:46 -0800
parents b7cc0f323a4c
children 379ab45b91b7 16750010813d
comparison
equal deleted inserted replaced
1950:5f581f337b05 1951:696230e52e4d
504 self.close() 504 self.close()
505 raise IOError(errno.EPIPE, 'Broken pipe') 505 raise IOError(errno.EPIPE, 'Broken pipe')
506 506
507 sys.stdout = winstdout(sys.stdout) 507 sys.stdout = winstdout(sys.stdout)
508 508
509 try: 509 def os_rcpath():
510 import win32api, win32process 510 '''return default os-specific hgrc search path'''
511 filename = win32process.GetModuleFileNameEx(win32api.GetCurrentProcess(), 0) 511 try:
512 systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') 512 import win32api, win32process
513 513 proc = win32api.GetCurrentProcess()
514 except ImportError: 514 filename = win32process.GetModuleFileNameEx(proc, 0)
515 systemrc = r'c:\mercurial\mercurial.ini' 515 systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
516 pass 516 except ImportError:
517 517 systemrc = r'c:\mercurial\mercurial.ini'
518 rcpath = (systemrc, 518
519 os.path.join(os.path.expanduser('~'), 'mercurial.ini')) 519 return [systemrc,
520 os.path.join(os.path.expanduser('~'), 'mercurial.ini')]
520 521
521 def parse_patch_output(output_line): 522 def parse_patch_output(output_line):
522 """parses the output produced by patch and returns the file name""" 523 """parses the output produced by patch and returns the file name"""
523 pf = output_line[14:] 524 pf = output_line[14:]
524 if pf[0] == '`': 525 if pf[0] == '`':
589 try: 590 try:
590 rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) 591 rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir)
591 if f.endswith(".rc")]) 592 if f.endswith(".rc")])
592 except OSError, inst: pass 593 except OSError, inst: pass
593 return rcs 594 return rcs
594 rcpath = [] 595
595 if len(sys.argv) > 0: 596 def os_rcpath():
596 rcpath.extend(rcfiles(os.path.dirname(sys.argv[0]) + '/../etc/mercurial')) 597 '''return default os-specific hgrc search path'''
597 rcpath.extend(rcfiles('/etc/mercurial')) 598 path = []
598 rcpath.append(os.path.expanduser('~/.hgrc')) 599 if len(sys.argv) > 0:
599 rcpath = [os.path.normpath(f) for f in rcpath] 600 path.extend(rcfiles(os.path.dirname(sys.argv[0]) +
601 '/../etc/mercurial'))
602 path.extend(rcfiles('/etc/mercurial'))
603 path.append(os.path.expanduser('~/.hgrc'))
604 path = [os.path.normpath(f) for f in path]
605 return path
600 606
601 def parse_patch_output(output_line): 607 def parse_patch_output(output_line):
602 """parses the output produced by patch and returns the file name""" 608 """parses the output produced by patch and returns the file name"""
603 pf = output_line[14:] 609 pf = output_line[14:]
604 if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0: 610 if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0:
766 for d in dirs: 772 for d in dirs:
767 if d == '.hg': 773 if d == '.hg':
768 yield root 774 yield root
769 dirs[:] = [] 775 dirs[:] = []
770 break 776 break
777
778 _rcpath = None
779
780 def rcpath():
781 '''return hgrc search path. if env var HGRCPATH is set, use it.
782 for each item in path, if directory, use files ending in .rc,
783 else use item.
784 make HGRCPATH empty to only look in .hg/hgrc of current repo.
785 if no HGRCPATH, use default os-specific path.'''
786 global _rcpath
787 if _rcpath is None:
788 if 'HGRCPATH' in os.environ:
789 _rcpath = []
790 for p in os.environ['HGRCPATH'].split(os.pathsep):
791 if not p: continue
792 try:
793 for f in os.listdir(p):
794 if f.endswith('.rc'):
795 _rcpath.append(os.path.join(p, f))
796 continue
797 except:
798 pass
799 _rcpath.append(p)
800 else:
801 _rcpath = os_rcpath()
802 return _rcpath