65 '''return rc paths in defaultrc''' |
65 '''return rc paths in defaultrc''' |
66 defaultpath = os.path.join(resourceutil.datapath, b'defaultrc') |
66 defaultpath = os.path.join(resourceutil.datapath, b'defaultrc') |
67 return _expandrcpath(defaultpath) |
67 return _expandrcpath(defaultpath) |
68 |
68 |
69 |
69 |
|
70 def default_rc_resources(): |
|
71 """return rc resource IDs in defaultrc""" |
|
72 rsrcs = resourceutil.contents(b'mercurial.defaultrc') |
|
73 return [ |
|
74 (b'mercurial.defaultrc', r) |
|
75 for r in sorted(rsrcs) |
|
76 if resourceutil.is_resource(b'mercurial.defaultrc', r) |
|
77 and r.endswith(b'.rc') |
|
78 ] |
|
79 |
|
80 |
70 def rccomponents(): |
81 def rccomponents(): |
71 '''return an ordered [(type, obj)] about where to load configs. |
82 '''return an ordered [(type, obj)] about where to load configs. |
72 |
83 |
73 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
84 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is |
74 used. if $HGRCPATH is not set, the platform default will be used. |
85 used. if $HGRCPATH is not set, the platform default will be used. |
75 |
86 |
76 if a directory is provided, *.rc files under it will be used. |
87 if a directory is provided, *.rc files under it will be used. |
77 |
88 |
78 type could be either 'path' or 'items', if type is 'path', obj is a string, |
89 type could be either 'path', 'items' or 'resource'. If type is 'path', |
79 and is the config file path. if type is 'items', obj is a list of (section, |
90 obj is a string, and is the config file path. if type is 'items', obj is a |
80 name, value, source) that should fill the config directly. |
91 list of (section, name, value, source) that should fill the config directly. |
|
92 If type is 'resource', obj is a tuple of (package name, resource name). |
81 ''' |
93 ''' |
82 envrc = (b'items', envrcitems()) |
94 envrc = (b'items', envrcitems()) |
83 |
95 |
84 if b'HGRCPATH' in encoding.environ: |
96 if b'HGRCPATH' in encoding.environ: |
85 # assume HGRCPATH is all about user configs so environments can be |
97 # assume HGRCPATH is all about user configs so environments can be |
88 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): |
100 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): |
89 if not p: |
101 if not p: |
90 continue |
102 continue |
91 _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) |
103 _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) |
92 else: |
104 else: |
|
105 _rccomponents = [(b'resource', r) for r in default_rc_resources()] |
|
106 |
93 normpaths = lambda paths: [ |
107 normpaths = lambda paths: [ |
94 (b'path', os.path.normpath(p)) for p in paths |
108 (b'path', os.path.normpath(p)) for p in paths |
95 ] |
109 ] |
96 _rccomponents = normpaths(defaultrcpath() + systemrcpath()) |
110 _rccomponents.extend(normpaths(defaultrcpath() + systemrcpath())) |
97 _rccomponents.append(envrc) |
111 _rccomponents.append(envrc) |
98 _rccomponents.extend(normpaths(userrcpath())) |
112 _rccomponents.extend(normpaths(userrcpath())) |
99 return _rccomponents |
113 return _rccomponents |
100 |
114 |
101 |
115 |