hgext/sparse.py
changeset 33302 36a415b5a4b2
parent 33301 ca4b78eb11e7
child 33303 8b571495d811
equal deleted inserted replaced
33301:ca4b78eb11e7 33302:36a415b5a4b2
   419 
   419 
   420         def _sparsesignature(self, includetemp=True):
   420         def _sparsesignature(self, includetemp=True):
   421             """Returns the signature string representing the contents of the
   421             """Returns the signature string representing the contents of the
   422             current project sparse configuration. This can be used to cache the
   422             current project sparse configuration. This can be used to cache the
   423             sparse matcher for a given set of revs."""
   423             sparse matcher for a given set of revs."""
   424             signaturecache = self.signaturecache
   424             signaturecache = self._sparsesignaturecache
   425             signature = signaturecache.get('signature')
   425             signature = signaturecache.get('signature')
   426             if includetemp:
   426             if includetemp:
   427                 tempsignature = signaturecache.get('tempsignature')
   427                 tempsignature = signaturecache.get('tempsignature')
   428             else:
   428             else:
   429                 tempsignature = 0
   429                 tempsignature = 0
   443                     except (OSError, IOError):
   443                     except (OSError, IOError):
   444                         pass
   444                         pass
   445                     signaturecache['tempsignature'] = tempsignature
   445                     signaturecache['tempsignature'] = tempsignature
   446             return '%s %s' % (str(signature), str(tempsignature))
   446             return '%s %s' % (str(signature), str(tempsignature))
   447 
   447 
   448         def invalidatecaches(self):
       
   449             self.invalidatesignaturecache()
       
   450             return super(SparseRepo, self).invalidatecaches()
       
   451 
       
   452         def invalidatesignaturecache(self):
       
   453             self.signaturecache.clear()
       
   454 
       
   455         def sparsematch(self, *revs, **kwargs):
   448         def sparsematch(self, *revs, **kwargs):
   456             """Returns the sparse match function for the given revs.
   449             """Returns the sparse match function for the given revs.
   457 
   450 
   458             If multiple revs are specified, the match function is the union
   451             If multiple revs are specified, the match function is the union
   459             of all the revs.
   452             of all the revs.
   468             includetemp = kwargs.get('includetemp', True)
   461             includetemp = kwargs.get('includetemp', True)
   469             signature = self._sparsesignature(includetemp=includetemp)
   462             signature = self._sparsesignature(includetemp=includetemp)
   470 
   463 
   471             key = '%s %s' % (str(signature), ' '.join([str(r) for r in revs]))
   464             key = '%s %s' % (str(signature), ' '.join([str(r) for r in revs]))
   472 
   465 
   473             result = self.sparsecache.get(key, None)
   466             result = self._sparsematchercache.get(key, None)
   474             if result:
   467             if result:
   475                 return result
   468                 return result
   476 
   469 
   477             matchers = []
   470             matchers = []
   478             for rev in revs:
   471             for rev in revs:
   511 
   504 
   512             if kwargs.get('includetemp', True):
   505             if kwargs.get('includetemp', True):
   513                 tempincludes = self.gettemporaryincludes()
   506                 tempincludes = self.gettemporaryincludes()
   514                 result = forceincludematcher(result, tempincludes)
   507                 result = forceincludematcher(result, tempincludes)
   515 
   508 
   516             self.sparsecache[key] = result
   509             self._sparsematchercache[key] = result
   517 
   510 
   518             return result
   511             return result
   519 
   512 
   520         def writesparseconfig(self, include, exclude, profiles):
   513         def writesparseconfig(self, include, exclude, profiles):
   521             raw = '%s[include]\n%s\n[exclude]\n%s\n' % (
   514             raw = '%s[include]\n%s\n[exclude]\n%s\n' % (
   522                 ''.join(['%%include %s\n' % p for p in sorted(profiles)]),
   515                 ''.join(['%%include %s\n' % p for p in sorted(profiles)]),
   523                 '\n'.join(sorted(include)),
   516                 '\n'.join(sorted(include)),
   524                 '\n'.join(sorted(exclude)))
   517                 '\n'.join(sorted(exclude)))
   525             self.vfs.write("sparse", raw)
   518             self.vfs.write("sparse", raw)
   526             self.invalidatesignaturecache()
   519             sparse.invalidatesignaturecache(self)
   527 
   520 
   528         def addtemporaryincludes(self, files):
   521         def addtemporaryincludes(self, files):
   529             includes = self.gettemporaryincludes()
   522             includes = self.gettemporaryincludes()
   530             for file in files:
   523             for file in files:
   531                 includes.add(file)
   524                 includes.add(file)
   539             return existingtemp
   532             return existingtemp
   540 
   533 
   541         def _writetemporaryincludes(self, includes):
   534         def _writetemporaryincludes(self, includes):
   542             raw = '\n'.join(sorted(includes))
   535             raw = '\n'.join(sorted(includes))
   543             self.vfs.write('tempsparse', raw)
   536             self.vfs.write('tempsparse', raw)
   544             self.invalidatesignaturecache()
   537             sparse.invalidatesignaturecache(self)
   545 
   538 
   546         def prunetemporaryincludes(self):
   539         def prunetemporaryincludes(self):
   547             if repo.vfs.exists('tempsparse'):
   540             if repo.vfs.exists('tempsparse'):
   548                 origstatus = self.status()
   541                 origstatus = self.status()
   549                 modified, added, removed, deleted, a, b, c = origstatus
   542                 modified, added, removed, deleted, a, b, c = origstatus
   570                 # Fix dirstate
   563                 # Fix dirstate
   571                 for file in dropped:
   564                 for file in dropped:
   572                     dirstate.drop(file)
   565                     dirstate.drop(file)
   573 
   566 
   574                 self.vfs.unlink('tempsparse')
   567                 self.vfs.unlink('tempsparse')
   575                 self.invalidatesignaturecache()
   568                 sparse.invalidatesignaturecache(self)
   576                 msg = _("cleaned up %d temporarily added file(s) from the "
   569                 msg = _("cleaned up %d temporarily added file(s) from the "
   577                         "sparse checkout\n")
   570                         "sparse checkout\n")
   578                 ui.status(msg % len(tempincludes))
   571                 ui.status(msg % len(tempincludes))
   579 
   572 
   580     if 'dirstate' in repo._filecache:
   573     if 'dirstate' in repo._filecache:
   581         repo.dirstate.repo = repo
   574         repo.dirstate.repo = repo
   582     repo.sparsecache = {}
   575 
   583     repo.signaturecache = {}
       
   584     repo.__class__ = SparseRepo
   576     repo.__class__ = SparseRepo
   585 
   577 
   586 @command('^debugsparse', [
   578 @command('^debugsparse', [
   587     ('I', 'include', False, _('include files in the sparse checkout')),
   579     ('I', 'include', False, _('include files in the sparse checkout')),
   588     ('X', 'exclude', False, _('exclude files in the sparse checkout')),
   580     ('X', 'exclude', False, _('exclude files in the sparse checkout')),