Patchwork D4095: narrow: extract part of narrowspec backup to core

login
register
mail settings
Submitter phabricator
Date Aug. 3, 2018, 10:01 p.m.
Message ID <6bd93f2ca54efa8fcce59a0b42940eba@localhost.localdomain>
Download mbox | patch
Permalink /patch/33195/
State Not Applicable
Headers show

Comments

phabricator - Aug. 3, 2018, 10:01 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGfed6fe856333: narrow: extract part of narrowspec backup to core (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4095?vs=9857&id=9864

REVISION DETAIL
  https://phab.mercurial-scm.org/D4095

AFFECTED FILES
  hgext/narrow/narrowdirstate.py
  mercurial/narrowspec.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -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
diff --git a/hgext/narrow/narrowdirstate.py b/hgext/narrow/narrowdirstate.py
--- a/hgext/narrow/narrowdirstate.py
+++ b/hgext/narrow/narrowdirstate.py
@@ -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