##// END OF EJS Templates
sparse: move pruning of temporary includes into core...
Gregory Szorc -
r33321:d09e948d default
parent child Browse files
Show More
@@ -119,7 +119,8 b' def reposetup(ui, repo):'
119 if not util.safehasattr(repo, 'dirstate'):
119 if not util.safehasattr(repo, 'dirstate'):
120 return
120 return
121
121
122 _wraprepo(ui, repo)
122 if 'dirstate' in repo._filecache:
123 repo.dirstate.repo = repo
123
124
124 def replacefilecache(cls, propname, replacement):
125 def replacefilecache(cls, propname, replacement):
125 """Replace a filecache property with a new class. This allows changing the
126 """Replace a filecache property with a new class. This allows changing the
@@ -224,17 +225,6 b' def _setupupdates(ui):'
224
225
225 extensions.wrapfunction(mergemod, 'calculateupdates', _calculateupdates)
226 extensions.wrapfunction(mergemod, 'calculateupdates', _calculateupdates)
226
227
227 def _update(orig, repo, node, branchmerge, *args, **kwargs):
228 results = orig(repo, node, branchmerge, *args, **kwargs)
229
230 # If we're updating to a location, clean up any stale temporary includes
231 # (ex: this happens during hg rebase --abort).
232 if not branchmerge and util.safehasattr(repo, 'prunetemporaryincludes'):
233 repo.prunetemporaryincludes()
234 return results
235
236 extensions.wrapfunction(mergemod, 'update', _update)
237
238 def _setupcommit(ui):
228 def _setupcommit(ui):
239 def _refreshoncommit(orig, self, node):
229 def _refreshoncommit(orig, self, node):
240 """Refresh the checkout when commits touch .hgsparse
230 """Refresh the checkout when commits touch .hgsparse
@@ -251,8 +241,7 b' def _setupcommit(ui):'
251 origsparsematch = sparse.matcher(repo)
241 origsparsematch = sparse.matcher(repo)
252 _refresh(repo.ui, repo, origstatus, origsparsematch, True)
242 _refresh(repo.ui, repo, origstatus, origsparsematch, True)
253
243
254 if util.safehasattr(repo, 'prunetemporaryincludes'):
244 sparse.prunetemporaryincludes(repo)
255 repo.prunetemporaryincludes()
256
245
257 extensions.wrapfunction(context.committablectx, 'markcommitted',
246 extensions.wrapfunction(context.committablectx, 'markcommitted',
258 _refreshoncommit)
247 _refreshoncommit)
@@ -403,47 +392,6 b' def _setupdirstate(ui):'
403 return orig(self, *args)
392 return orig(self, *args)
404 extensions.wrapfunction(dirstate.dirstate, func, _wrapper)
393 extensions.wrapfunction(dirstate.dirstate, func, _wrapper)
405
394
406 def _wraprepo(ui, repo):
407 class SparseRepo(repo.__class__):
408 def prunetemporaryincludes(self):
409 if repo.vfs.exists('tempsparse'):
410 origstatus = self.status()
411 modified, added, removed, deleted, a, b, c = origstatus
412 if modified or added or removed or deleted:
413 # Still have pending changes. Don't bother trying to prune.
414 return
415
416 sparsematch = sparse.matcher(self, includetemp=False)
417 dirstate = self.dirstate
418 actions = []
419 dropped = []
420 tempincludes = sparse.readtemporaryincludes(self)
421 for file in tempincludes:
422 if file in dirstate and not sparsematch(file):
423 message = 'dropping temporarily included sparse files'
424 actions.append((file, None, message))
425 dropped.append(file)
426
427 typeactions = collections.defaultdict(list)
428 typeactions['r'] = actions
429 mergemod.applyupdates(self, typeactions, self[None], self['.'],
430 False)
431
432 # Fix dirstate
433 for file in dropped:
434 dirstate.drop(file)
435
436 self.vfs.unlink('tempsparse')
437 sparse.invalidatesignaturecache(self)
438 msg = _("cleaned up %d temporarily added file(s) from the "
439 "sparse checkout\n")
440 ui.status(msg % len(tempincludes))
441
442 if 'dirstate' in repo._filecache:
443 repo.dirstate.repo = repo
444
445 repo.__class__ = SparseRepo
446
447 @command('^debugsparse', [
395 @command('^debugsparse', [
448 ('I', 'include', False, _('include files in the sparse checkout')),
396 ('I', 'include', False, _('include files in the sparse checkout')),
449 ('X', 'exclude', False, _('exclude files in the sparse checkout')),
397 ('X', 'exclude', False, _('exclude files in the sparse checkout')),
@@ -1514,6 +1514,8 b' def update(repo, node, branchmerge, forc'
1514
1514
1515 Return the same tuple as applyupdates().
1515 Return the same tuple as applyupdates().
1516 """
1516 """
1517 # Avoid cycle.
1518 from . import sparse
1517
1519
1518 # This function used to find the default destination if node was None, but
1520 # This function used to find the default destination if node was None, but
1519 # that's now in destutil.py.
1521 # that's now in destutil.py.
@@ -1703,6 +1705,11 b' def update(repo, node, branchmerge, forc'
1703 if not branchmerge:
1705 if not branchmerge:
1704 repo.dirstate.setbranch(p2.branch())
1706 repo.dirstate.setbranch(p2.branch())
1705
1707
1708 # If we're updating to a location, clean up any stale temporary includes
1709 # (ex: this happens during hg rebase --abort).
1710 if not branchmerge:
1711 sparse.prunetemporaryincludes(repo)
1712
1706 if not partial:
1713 if not partial:
1707 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
1714 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
1708 return stats
1715 return stats
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import collections
10 import hashlib
11 import hashlib
11 import os
12 import os
12
13
@@ -15,6 +16,7 b' from .node import nullid'
15 from . import (
16 from . import (
16 error,
17 error,
17 match as matchmod,
18 match as matchmod,
19 merge as mergemod,
18 pycompat,
20 pycompat,
19 )
21 )
20
22
@@ -197,6 +199,41 b' def addtemporaryincludes(repo, additiona'
197 includes.add(i)
199 includes.add(i)
198 writetemporaryincludes(repo, includes)
200 writetemporaryincludes(repo, includes)
199
201
202 def prunetemporaryincludes(repo):
203 if not enabled or not repo.vfs.exists('tempsparse'):
204 return
205
206 origstatus = repo.status()
207 modified, added, removed, deleted, a, b, c = origstatus
208 if modified or added or removed or deleted:
209 # Still have pending changes. Don't bother trying to prune.
210 return
211
212 sparsematch = matcher(repo, includetemp=False)
213 dirstate = repo.dirstate
214 actions = []
215 dropped = []
216 tempincludes = readtemporaryincludes(repo)
217 for file in tempincludes:
218 if file in dirstate and not sparsematch(file):
219 message = _('dropping temporarily included sparse files')
220 actions.append((file, None, message))
221 dropped.append(file)
222
223 typeactions = collections.defaultdict(list)
224 typeactions['r'] = actions
225 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
226
227 # Fix dirstate
228 for file in dropped:
229 dirstate.drop(file)
230
231 repo.vfs.unlink('tempsparse')
232 invalidatesignaturecache(repo)
233 msg = _('cleaned up %d temporarily added file(s) from the '
234 'sparse checkout\n')
235 repo.ui.status(msg % len(tempincludes))
236
200 def matcher(repo, revs=None, includetemp=True):
237 def matcher(repo, revs=None, includetemp=True):
201 """Obtain a matcher for sparse working directories for the given revs.
238 """Obtain a matcher for sparse working directories for the given revs.
202
239
General Comments 0
You need to be logged in to leave comments. Login now