comparison hgext/narrow/narrowspec.py @ 36159:0fe7e39dc683

hg: move share._getsrcrepo into core The fact we were calling this from extensions was a sign that it should live in core. We were also able to remove some extra attribute aliases from the share extension. Differential Revision: https://phab.mercurial-scm.org/D2200
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 12 Feb 2018 16:15:34 -0800
parents 8fd0a9e2d7e9
children
comparison
equal deleted inserted replaced
36158:802742769680 36159:0fe7e39dc683
10 import errno 10 import errno
11 11
12 from mercurial.i18n import _ 12 from mercurial.i18n import _
13 from mercurial import ( 13 from mercurial import (
14 error, 14 error,
15 hg,
15 match as matchmod, 16 match as matchmod,
16 util, 17 util,
17 )
18
19 from .. import (
20 share,
21 ) 18 )
22 19
23 FILENAME = 'narrowspec' 20 FILENAME = 'narrowspec'
24 21
25 def _parsestoredpatterns(text): 22 def _parsestoredpatterns(text):
131 def needsexpansion(includes): 128 def needsexpansion(includes):
132 return [i for i in includes if i.startswith('include:')] 129 return [i for i in includes if i.startswith('include:')]
133 130
134 def load(repo): 131 def load(repo):
135 if repo.shared(): 132 if repo.shared():
136 repo = share._getsrcrepo(repo) 133 repo = hg.sharedreposource(repo)
137 try: 134 try:
138 spec = repo.vfs.read(FILENAME) 135 spec = repo.vfs.read(FILENAME)
139 except IOError as e: 136 except IOError as e:
140 # Treat "narrowspec does not exist" the same as "narrowspec file exists 137 # Treat "narrowspec does not exist" the same as "narrowspec file exists
141 # and is empty". 138 # and is empty".
148 return _parsestoredpatterns(spec) 145 return _parsestoredpatterns(spec)
149 146
150 def save(repo, includepats, excludepats): 147 def save(repo, includepats, excludepats):
151 spec = format(includepats, excludepats) 148 spec = format(includepats, excludepats)
152 if repo.shared(): 149 if repo.shared():
153 repo = share._getsrcrepo(repo) 150 repo = hg.sharedreposource(repo)
154 repo.vfs.write(FILENAME, spec) 151 repo.vfs.write(FILENAME, spec)
155 152
156 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes): 153 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
157 r""" Restricts the patterns according to repo settings, 154 r""" Restricts the patterns according to repo settings,
158 results in a logical AND operation 155 results in a logical AND operation