Patchwork D1882: atomicupdate: add an experimental option to use atomictemp when updating

login
register
mail settings
Submitter phabricator
Date Jan. 18, 2018, 12:39 p.m.
Message ID <differential-rev-PHID-DREV-3rez6hucklsuvxvfm2bc-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26865/
State Superseded
Headers show

Comments

phabricator - Jan. 18, 2018, 12:39 p.m.
lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  In some cases Mercurial truncating files when updating causes problems. It can
  happens when processes are currently reading the file or with big file or on
  NFS mounts.
  
  We add an experimental option to use the atomictemp option of vfs.__call__ in
  order to avoid the problem.
  
  The localrepository.wwrite seems to assume the files are created without the
  `x` flag; with atomictempfile, the new file might inherit the `x` flag from
  the destination. We force remove it afterward. This code could be refactored
  and the flag processing could be moved inside vfs.
  
  This patch should be tested with
  `--extra-config-opt experimental.update.atomic-file=True`
  as we disabled the option by default.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/merge.py

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1376,7 +1376,9 @@ 
                 if repo.wvfs.lexists(absf):
                     util.rename(absf, orig)
             wctx[f].clearunknown()
-            wctx[f].write(fctx(f).data(), flags, backgroundclose=True)
+            atomictemp = ui.configbool("experimental", "update.atomic-file")
+            wctx[f].write(fctx(f).data(), flags, backgroundclose=True,
+                          atomictemp=atomictemp)
             if i == 100:
                 yield i, f
                 i = 0
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1112,6 +1112,8 @@ 
                             **kwargs)
             if 'x' in flags:
                 self.wvfs.setflags(filename, False, True)
+            else:
+                self.wvfs.setflags(filename, False, False)
         return len(data)
 
     def wwritedata(self, filename, data):
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -562,6 +562,9 @@ 
 coreconfigitem('experimental', 'treemanifest',
     default=False,
 )
+coreconfigitem('experimental', 'update.atomic-file',
+    default=False,
+)
 coreconfigitem('extensions', '.*',
     default=None,
     generic=True,