Mercurial > public > mercurial-scm > hg-stable
diff mercurial/narrowspec.py @ 38908:ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
I want to move .hg/narrowspec to .hg/store/narrowspec and we need to
decouple the narrowspec update from the dirstate update for that. This
patch lets the callers call the narrowspec backup functions directly,
in addition to the dirstate backup functions. The narrowspec methods
are made to check if narrowing is enabled. For that, a repo instance
was needed, which all the callers luckily already had available.
Differential Revision: https://phab.mercurial-scm.org/D4096
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 03 Aug 2018 11:09:41 -0700 |
parents | 794afa91f0a5 |
children | ae2962bb56a3 |
line wrap: on
line diff
--- a/mercurial/narrowspec.py Sat Aug 04 23:15:06 2018 -0700 +++ b/mercurial/narrowspec.py Fri Aug 03 11:09:41 2018 -0700 @@ -13,6 +13,7 @@ from . import ( error, match as matchmod, + repository, sparse, util, ) @@ -129,15 +130,22 @@ spec = format(includepats, excludepats) repo.vfs.write(FILENAME, spec) -def savebackup(vfs, backupname): +def savebackup(repo, backupname): + if repository.NARROW_REQUIREMENT not in repo.requirements: + return + vfs = repo.vfs vfs.tryunlink(backupname) util.copyfile(vfs.join(FILENAME), vfs.join(backupname), hardlink=True) -def restorebackup(vfs, backupname): - vfs.rename(backupname, FILENAME, checkambig=True) +def restorebackup(repo, backupname): + if repository.NARROW_REQUIREMENT not in repo.requirements: + return + repo.vfs.rename(backupname, FILENAME, checkambig=True) -def clearbackup(vfs, backupname): - vfs.unlink(backupname) +def clearbackup(repo, backupname): + if repository.NARROW_REQUIREMENT not in repo.requirements: + return + repo.vfs.unlink(backupname) def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes): r""" Restricts the patterns according to repo settings,