mercurial/sparse.py
branchstable
changeset 49366 288de6f5d724
parent 49354 216f273b6b30
child 49959 c166b212bdee
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
     3 # Copyright 2014 Facebook, Inc.
     3 # Copyright 2014 Facebook, Inc.
     4 #
     4 #
     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
       
     9 
     8 
    10 import os
     9 import os
    11 
    10 
    12 from .i18n import _
    11 from .i18n import _
    13 from .node import hex
    12 from .node import hex
    27 
    26 
    28 # Whether sparse features are enabled. This variable is intended to be
    27 # Whether sparse features are enabled. This variable is intended to be
    29 # temporary to facilitate porting sparse to core. It should eventually be
    28 # temporary to facilitate porting sparse to core. It should eventually be
    30 # a per-repo option, possibly a repo requirement.
    29 # a per-repo option, possibly a repo requirement.
    31 enabled = False
    30 enabled = False
       
    31 
       
    32 
       
    33 def use_sparse(repo):
       
    34     if getattr(repo, "_has_sparse", False):
       
    35         # When enabling sparse the first time we need it to be enabled before
       
    36         # actually enabling it.  This hack could be avoided if the code was
       
    37         # improved further, however this is an improvement over the previously
       
    38         # existing global variable.
       
    39         return True
       
    40     return requirements.SPARSE_REQUIREMENT in repo.requirements
    32 
    41 
    33 
    42 
    34 def parseconfig(ui, raw, action):
    43 def parseconfig(ui, raw, action):
    35     """Parse sparse config file content.
    44     """Parse sparse config file content.
    36 
    45 
   113 
   122 
   114     Returns a tuple of iterables representing includes, excludes, and
   123     Returns a tuple of iterables representing includes, excludes, and
   115     patterns.
   124     patterns.
   116     """
   125     """
   117     # Feature isn't enabled. No-op.
   126     # Feature isn't enabled. No-op.
   118     if not enabled:
   127     if not use_sparse(repo):
   119         return set(), set(), set()
   128         return set(), set(), set()
   120 
   129 
   121     raw = repo.vfs.tryread(b'sparse')
   130     raw = repo.vfs.tryread(b'sparse')
   122     if not raw:
   131     if not raw:
   123         return set(), set(), set()
   132         return set(), set(), set()
   259         includes.add(i)
   268         includes.add(i)
   260     writetemporaryincludes(repo, includes)
   269     writetemporaryincludes(repo, includes)
   261 
   270 
   262 
   271 
   263 def prunetemporaryincludes(repo):
   272 def prunetemporaryincludes(repo):
   264     if not enabled or not repo.vfs.exists(b'tempsparse'):
   273     if not use_sparse(repo) or not repo.vfs.exists(b'tempsparse'):
   265         return
   274         return
   266 
   275 
   267     s = repo.status()
   276     s = repo.status()
   268     if s.modified or s.added or s.removed or s.deleted:
   277     if s.modified or s.added or s.removed or s.deleted:
   269         # Still have pending changes. Don't bother trying to prune.
   278         # Still have pending changes. Don't bother trying to prune.
   312     revs.
   321     revs.
   313 
   322 
   314     ``includetemp`` indicates whether to use the temporary sparse profile.
   323     ``includetemp`` indicates whether to use the temporary sparse profile.
   315     """
   324     """
   316     # If sparse isn't enabled, sparse matcher matches everything.
   325     # If sparse isn't enabled, sparse matcher matches everything.
   317     if not enabled:
   326     if not use_sparse(repo):
   318         return matchmod.always()
   327         return matchmod.always()
   319 
   328 
   320     if not revs or revs == [None]:
   329     if not revs or revs == [None]:
   321         revs = [
   330         revs = [
   322             repo.changelog.rev(node)
   331             repo.changelog.rev(node)
   366     return result
   375     return result
   367 
   376 
   368 
   377 
   369 def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult):
   378 def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult):
   370     """Filter updates to only lay out files that match the sparse rules."""
   379     """Filter updates to only lay out files that match the sparse rules."""
   371     if not enabled:
   380     if not use_sparse(repo):
   372         return
   381         return
   373 
   382 
   374     oldrevs = [pctx.rev() for pctx in wctx.parents()]
   383     oldrevs = [pctx.rev() for pctx in wctx.parents()]
   375     oldsparsematch = matcher(repo, oldrevs)
   384     oldsparsematch = matcher(repo, oldrevs)
   376 
   385 
   553                 b'--force to bring them back dirty)'
   562                 b'--force to bring them back dirty)'
   554             )
   563             )
   555         )
   564         )
   556 
   565 
   557     # Check for files that were only in the dirstate.
   566     # Check for files that were only in the dirstate.
   558     for file, state in pycompat.iteritems(dirstate):
   567     for file, state in dirstate.items():
   559         if not file in files:
   568         if not file in files:
   560             old = origsparsematch(file)
   569             old = origsparsematch(file)
   561             new = sparsematch(file)
   570             new = sparsematch(file)
   562             if old and not new:
   571             if old and not new:
   563                 dropped.append(file)
   572                 dropped.append(file)