# HG changeset patch # User Martin von Zweigbergk # Date 2018-12-30 07:01:12 # Node ID 50ca531f1f248d398cbcff40eadb32ec4e349354 # Parent 3b35ebdb9f8c8d772c023020de8a146599ecd291 narrow: copy store narrowspec to working copy immediately We no longer need to delay it until the end of the transaction since we now restore a backup if the transaction aborts. Differential Revision: https://phab.mercurial-scm.org/D5506 diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py --- a/hgext/narrow/narrowcommands.py +++ b/hgext/narrow/narrowcommands.py @@ -432,9 +432,9 @@ def trackedcmd(ui, repo, remotepath=None return 0 if update_working_copy: - with repo.wlock(), repo.lock(), repo.transaction('narrow-wc') as tr: + with repo.wlock(), repo.lock(), repo.transaction('narrow-wc'): narrowspec.updateworkingcopy(repo) - narrowspec.copytoworkingcopy(repo, tr) + narrowspec.copytoworkingcopy(repo) return 0 if not widening and not narrowing: diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -334,7 +334,7 @@ def postshare(sourcerepo, destrepo, defa destrepo.vfs.write('hgrc', util.tonativeeol(template % default)) if repositorymod.NARROW_REQUIREMENT in sourcerepo.requirements: with destrepo.wlock(): - narrowspec.copytoworkingcopy(destrepo, None) + narrowspec.copytoworkingcopy(destrepo) def _postshareupdate(repo, update, checkout=None): """Maybe perform a working directory update after a shared repo is created. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1252,7 +1252,7 @@ class localrepository(object): def setnarrowpats(self, newincludes, newexcludes): narrowspec.save(self, newincludes, newexcludes) - narrowspec.copytoworkingcopy(self, self.currenttransaction()) + narrowspec.copytoworkingcopy(self) self.invalidate(clearfilecache=True) # So the next access won't be considered a conflict # TODO: It seems like there should be a way of doing this that diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py --- a/mercurial/narrowspec.py +++ b/mercurial/narrowspec.py @@ -161,17 +161,9 @@ def save(repo, includepats, excludepats) spec = format(includepats, excludepats) repo.svfs.write(FILENAME, spec) -def copytoworkingcopy(repo, tr): - if tr: - def write(file): - spec = repo.svfs.read(FILENAME) - file.write(spec) - file.close() - tr.addfilegenerator('narrowspec', (DIRSTATE_FILENAME,), write, - location='plain') - else: - spec = repo.svfs.read(FILENAME) - repo.vfs.write(DIRSTATE_FILENAME, spec) +def copytoworkingcopy(repo): + spec = repo.svfs.read(FILENAME) + repo.vfs.write(DIRSTATE_FILENAME, spec) def savebackup(repo, backupname): if repository.NARROW_REQUIREMENT not in repo.requirements: