comparison hgext/narrow/narrowrepo.py @ 36464:3f0af89e008d

narrow: move requirement constant to core My short-term goal is to move narrowrepo.narrowmatch() onto localrepo and this is a necessary step for that. I put the constant in changegroup.py, unlike REVLOGV2_REQUIREMENT, which is in localrepo.py, since we'll need to access it from the changegroup module eventually. Differential Revision: https://phab.mercurial-scm.org/D2487
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 28 Feb 2018 10:21:43 -0800
parents 9fd8c2a3db5a
children a8b4d7673d8e
comparison
equal deleted inserted replaced
36463:1bd132a021dd 36464:3f0af89e008d
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 from mercurial import ( 10 from mercurial import (
11 bundlerepo, 11 bundlerepo,
12 changegroup,
12 hg, 13 hg,
13 localrepo, 14 localrepo,
14 match as matchmod, 15 match as matchmod,
15 narrowspec, 16 narrowspec,
16 scmutil, 17 scmutil,
18 19
19 from . import ( 20 from . import (
20 narrowrevlog, 21 narrowrevlog,
21 ) 22 )
22 23
23 # When narrowing is finalized and no longer subject to format changes,
24 # we should move this to just "narrow" or similar.
25 REQUIREMENT = 'narrowhg-experimental'
26
27 def wrappostshare(orig, sourcerepo, destrepo, **kwargs): 24 def wrappostshare(orig, sourcerepo, destrepo, **kwargs):
28 orig(sourcerepo, destrepo, **kwargs) 25 orig(sourcerepo, destrepo, **kwargs)
29 if REQUIREMENT in sourcerepo.requirements: 26 if changegroup.NARROW_REQUIREMENT in sourcerepo.requirements:
30 with destrepo.wlock(): 27 with destrepo.wlock():
31 with destrepo.vfs('shared', 'a') as fp: 28 with destrepo.vfs('shared', 'a') as fp:
32 fp.write(narrowspec.FILENAME + '\n') 29 fp.write(narrowspec.FILENAME + '\n')
33 30
34 def unsharenarrowspec(orig, ui, repo, repopath): 31 def unsharenarrowspec(orig, ui, repo, repopath):
35 if (REQUIREMENT in repo.requirements 32 if (changegroup.NARROW_REQUIREMENT in repo.requirements
36 and repo.path == repopath and repo.shared()): 33 and repo.path == repopath and repo.shared()):
37 srcrepo = hg.sharedreposource(repo) 34 srcrepo = hg.sharedreposource(repo)
38 with srcrepo.vfs(narrowspec.FILENAME) as f: 35 with srcrepo.vfs(narrowspec.FILENAME) as f:
39 spec = f.read() 36 spec = f.read()
40 with repo.vfs(narrowspec.FILENAME, 'w') as f: 37 with repo.vfs(narrowspec.FILENAME, 'w') as f: