[Updated] D11783: dirstate: move "get fs now" in the timestamp utility module

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Dec 1 15:21:34 UTC 2021


Closed by commit rHG08b060abd658: dirstate: move "get fs now" in the timestamp utility module (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11783?vs=31224&id=31245

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11783/new/

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

AFFECTED FILES
  mercurial/dirstate.py
  mercurial/dirstateutils/timestamp.py
  tests/fakedirstatewritetime.py

CHANGE DETAILS

diff --git a/tests/fakedirstatewritetime.py b/tests/fakedirstatewritetime.py
--- a/tests/fakedirstatewritetime.py
+++ b/tests/fakedirstatewritetime.py
@@ -9,7 +9,6 @@
 
 from mercurial import (
     context,
-    dirstate,
     dirstatemap as dirstatemapmod,
     extensions,
     policy,
@@ -73,19 +72,19 @@
         )
         dirstatemapmod.dirstatemap.write = wrapper
 
-    orig_dirstate_getfsnow = dirstate._getfsnow
+    orig_get_fs_now = timestamp.get_fs_now
     wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
 
     orig_module = parsers
     orig_pack_dirstate = parsers.pack_dirstate
 
     orig_module.pack_dirstate = wrapper
-    dirstate._getfsnow = lambda *args: fakenow
+    timestamp.get_fs_now = lambda *args: fakenow
     try:
         return func()
     finally:
         orig_module.pack_dirstate = orig_pack_dirstate
-        dirstate._getfsnow = orig_dirstate_getfsnow
+        timestamp.get_fs_now = orig_get_fs_now
         if has_rust_dirstate:
             dirstatemapmod.dirstatemap.write = orig_dirstatemap_write
 
diff --git a/mercurial/dirstateutils/timestamp.py b/mercurial/dirstateutils/timestamp.py
--- a/mercurial/dirstateutils/timestamp.py
+++ b/mercurial/dirstateutils/timestamp.py
@@ -6,6 +6,7 @@
 from __future__ import absolute_import
 
 import functools
+import os
 import stat
 
 
@@ -54,6 +55,19 @@
         return self_subsec_nanos > other_subsec_nanos
 
 
+def get_fs_now(vfs):
+    """return a timestamp for "now" in the current vfs
+
+    This will raise an exception if no temporary files could be created.
+    """
+    tmpfd, tmpname = vfs.mkstemp()
+    try:
+        return mtime_of(os.fstat(tmpfd))
+    finally:
+        os.close(tmpfd)
+        vfs.unlink(tmpname)
+
+
 def zero():
     """
     Returns the `timestamp` at the Unix epoch.
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -66,16 +66,6 @@
         return obj._join(fname)
 
 
-def _getfsnow(vfs):
-    '''Get "now" timestamp on filesystem'''
-    tmpfd, tmpname = vfs.mkstemp()
-    try:
-        return timestamp.mtime_of(os.fstat(tmpfd))
-    finally:
-        os.close(tmpfd)
-        vfs.unlink(tmpname)
-
-
 def requires_parents_change(func):
     def wrap(self, *args, **kwargs):
         if not self.pendingparentchange():
@@ -787,7 +777,7 @@
             # https://www.mercurial-scm.org/wiki/DirstateTransactionPlan
 
             # record when mtime start to be ambiguous
-            now = _getfsnow(self._opener)
+            now = timestamp.get_fs_now(self._opener)
 
             # delay writing in-memory changes out
             tr.addfilegenerator(



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20211201/057ee610/attachment-0001.html>


More information about the Mercurial-patches mailing list