##// END OF EJS Templates
dirstate: move "get fs now" in the timestamp utility module...
marmoute -
r49202:08b060ab default
parent child Browse files
Show More
@@ -66,16 +66,6 b' class rootcache(filecache):'
66 66 return obj._join(fname)
67 67
68 68
69 def _getfsnow(vfs):
70 '''Get "now" timestamp on filesystem'''
71 tmpfd, tmpname = vfs.mkstemp()
72 try:
73 return timestamp.mtime_of(os.fstat(tmpfd))
74 finally:
75 os.close(tmpfd)
76 vfs.unlink(tmpname)
77
78
79 69 def requires_parents_change(func):
80 70 def wrap(self, *args, **kwargs):
81 71 if not self.pendingparentchange():
@@ -787,7 +777,7 b' class dirstate(object):'
787 777 # https://www.mercurial-scm.org/wiki/DirstateTransactionPlan
788 778
789 779 # record when mtime start to be ambiguous
790 now = _getfsnow(self._opener)
780 now = timestamp.get_fs_now(self._opener)
791 781
792 782 # delay writing in-memory changes out
793 783 tr.addfilegenerator(
@@ -6,6 +6,7 b''
6 6 from __future__ import absolute_import
7 7
8 8 import functools
9 import os
9 10 import stat
10 11
11 12
@@ -54,6 +55,19 b' class timestamp(tuple):'
54 55 return self_subsec_nanos > other_subsec_nanos
55 56
56 57
58 def get_fs_now(vfs):
59 """return a timestamp for "now" in the current vfs
60
61 This will raise an exception if no temporary files could be created.
62 """
63 tmpfd, tmpname = vfs.mkstemp()
64 try:
65 return mtime_of(os.fstat(tmpfd))
66 finally:
67 os.close(tmpfd)
68 vfs.unlink(tmpname)
69
70
57 71 def zero():
58 72 """
59 73 Returns the `timestamp` at the Unix epoch.
@@ -9,7 +9,6 b' from __future__ import absolute_import'
9 9
10 10 from mercurial import (
11 11 context,
12 dirstate,
13 12 dirstatemap as dirstatemapmod,
14 13 extensions,
15 14 policy,
@@ -73,19 +72,19 b' def fakewrite(ui, func):'
73 72 )
74 73 dirstatemapmod.dirstatemap.write = wrapper
75 74
76 orig_dirstate_getfsnow = dirstate._getfsnow
75 orig_get_fs_now = timestamp.get_fs_now
77 76 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
78 77
79 78 orig_module = parsers
80 79 orig_pack_dirstate = parsers.pack_dirstate
81 80
82 81 orig_module.pack_dirstate = wrapper
83 dirstate._getfsnow = lambda *args: fakenow
82 timestamp.get_fs_now = lambda *args: fakenow
84 83 try:
85 84 return func()
86 85 finally:
87 86 orig_module.pack_dirstate = orig_pack_dirstate
88 dirstate._getfsnow = orig_dirstate_getfsnow
87 timestamp.get_fs_now = orig_get_fs_now
89 88 if has_rust_dirstate:
90 89 dirstatemapmod.dirstatemap.write = orig_dirstatemap_write
91 90
General Comments 0
You need to be logged in to leave comments. Login now