Patchwork [1,of,2] util: extract stub function to get mtime with second accuracy

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 6, 2015, 2:44 p.m.
Message ID <869c9d9c777435f94a84.1444142666@mimosa>
Download mbox | patch
Permalink /patch/10830/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 6, 2015, 2:44 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1443965129 -32400
#      Sun Oct 04 22:25:29 2015 +0900
# Node ID 869c9d9c777435f94a84d7284d6ba5c6a39e5ded
# Parent  efd57cd6fd1d5eb76102fabfc45676873bbba29d
util: extract stub function to get mtime with second accuracy

This function is trivial but will need a long comment why it can't use
st.st_mtime. See the next patch for details.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1690,7 +1690,7 @@  class workingfilectx(committablefilectx)
     def date(self):
         t, tz = self._changectx.date()
         try:
-            return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz)
+            return (util.statmtimesec(self._repo.wvfs.lstat(self._path)), tz)
         except OSError as err:
             if err.errno != errno.ENOENT:
                 raise
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -428,7 +428,7 @@  class dirstate(object):
     def normal(self, f):
         '''Mark a file normal and clean.'''
         s = os.lstat(self._join(f))
-        mtime = int(s.st_mtime)
+        mtime = util.statmtimesec(s)
         self._addpath(f, 'n', s.st_mode,
                       s.st_size & _rangemask, mtime & _rangemask)
         if f in self._copymap:
@@ -998,7 +998,7 @@  class dirstate(object):
             if not st and state in "nma":
                 dadd(fn)
             elif state == 'n':
-                mtime = int(st.st_mtime)
+                mtime = util.statmtimesec(st)
                 if (size >= 0 and
                     ((size != st.st_size and size != st.st_size & _rangemask)
                      or ((mode ^ st.st_mode) & 0o100 and checkexec))
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -952,6 +952,9 @@  def fstat(fp):
     except AttributeError:
         return os.stat(fp.name)
 
+def statmtimesec(st):
+    return int(st.st_mtime)
+
 # File system features
 
 def checkcase(path):