hgext/narrow/narrowrepo.py
changeset 38872 576eef1ab43d
parent 38835 a232e6744ba3
child 39528 2862e9b868c5
equal deleted inserted replaced
38871:204e074c188e 38872:576eef1ab43d
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
    10 from mercurial import (
       
    11     hg,
       
    12     narrowspec,
       
    13     repository,
       
    14 )
       
    15 
       
    16 from . import (
    10 from . import (
    17     narrowdirstate,
    11     narrowdirstate,
    18     narrowrevlog,
    12     narrowrevlog,
    19 )
    13 )
    20 
       
    21 def wrappostshare(orig, sourcerepo, destrepo, **kwargs):
       
    22     orig(sourcerepo, destrepo, **kwargs)
       
    23     if repository.NARROW_REQUIREMENT in sourcerepo.requirements:
       
    24         with destrepo.wlock():
       
    25             with destrepo.vfs('shared', 'a') as fp:
       
    26                 fp.write(narrowspec.FILENAME + '\n')
       
    27 
       
    28 def unsharenarrowspec(orig, ui, repo, repopath):
       
    29     if (repository.NARROW_REQUIREMENT in repo.requirements
       
    30         and repo.path == repopath and repo.shared()):
       
    31         srcrepo = hg.sharedreposource(repo)
       
    32         with srcrepo.vfs(narrowspec.FILENAME) as f:
       
    33             spec = f.read()
       
    34         with repo.vfs(narrowspec.FILENAME, 'w') as f:
       
    35             f.write(spec)
       
    36     return orig(ui, repo, repopath)
       
    37 
    14 
    38 def wraprepo(repo):
    15 def wraprepo(repo):
    39     """Enables narrow clone functionality on a single local repository."""
    16     """Enables narrow clone functionality on a single local repository."""
    40 
    17 
    41     class narrowrepository(repo.__class__):
    18     class narrowrepository(repo.__class__):