narrow: extract part of narrowspec backup to core
Just a little preparation for the next patch.
Differential Revision: https://phab.mercurial-scm.org/D4095
--- a/hgext/narrow/narrowdirstate.py Fri Aug 03 11:02:34 2018 -0700
+++ b/hgext/narrow/narrowdirstate.py Fri Aug 03 10:56:07 2018 -0700
@@ -12,7 +12,6 @@
error,
match as matchmod,
narrowspec,
- util as hgutil,
)
def wrapdirstate(repo, dirstate):
@@ -79,21 +78,17 @@
super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles)
def restorebackup(self, tr, backupname):
- self._opener.rename(_narrowbackupname(backupname),
- narrowspec.FILENAME, checkambig=True)
+ narrowspec.restorebackup(self._opener,
+ _narrowbackupname(backupname))
super(narrowdirstate, self).restorebackup(tr, backupname)
def savebackup(self, tr, backupname):
super(narrowdirstate, self).savebackup(tr, backupname)
-
- narrowbackupname = _narrowbackupname(backupname)
- self._opener.tryunlink(narrowbackupname)
- hgutil.copyfile(self._opener.join(narrowspec.FILENAME),
- self._opener.join(narrowbackupname), hardlink=True)
+ narrowspec.savebackup(self._opener, _narrowbackupname(backupname))
def clearbackup(self, tr, backupname):
super(narrowdirstate, self).clearbackup(tr, backupname)
- self._opener.unlink(_narrowbackupname(backupname))
+ narrowspec.clearbackup(self._opener, _narrowbackupname(backupname))
dirstate.__class__ = narrowdirstate
return dirstate
--- a/mercurial/narrowspec.py Fri Aug 03 11:02:34 2018 -0700
+++ b/mercurial/narrowspec.py Fri Aug 03 10:56:07 2018 -0700
@@ -145,6 +145,16 @@
spec = format(includepats, excludepats)
repo.vfs.write(FILENAME, spec)
+def savebackup(vfs, backupname):
+ vfs.tryunlink(backupname)
+ util.copyfile(vfs.join(FILENAME), vfs.join(backupname), hardlink=True)
+
+def restorebackup(vfs, backupname):
+ vfs.rename(backupname, FILENAME, checkambig=True)
+
+def clearbackup(vfs, backupname):
+ vfs.unlink(backupname)
+
def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
r""" Restricts the patterns according to repo settings,
results in a logical AND operation