##// END OF EJS Templates
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
Augie Fackler -
r36922:ffa3026d default
parent child Browse files
Show More
@@ -65,6 +65,7 b' from __future__ import absolute_import'
65 65 import os
66 66 import re
67 67 import shutil
68 import stat
68 69 import tempfile
69 70 from mercurial.i18n import _
70 71 from mercurial.node import (
@@ -297,7 +298,8 b' def dodiff(ui, repo, cmdline, pats, opts'
297 298 # copyfile() carries over the permission, so the mode check could
298 299 # be in an 'elif' branch, but for the case where the file has
299 300 # changed without affecting mtime or size.
300 if (cpstat.st_mtime != st.st_mtime or cpstat.st_size != st.st_size
301 if (cpstat[stat.ST_MTIME] != st[stat.ST_MTIME]
302 or cpstat.st_size != st.st_size
301 303 or (cpstat.st_mode & 0o100) != (st.st_mode & 0o100)):
302 304 ui.debug('file changed while diffing. '
303 305 'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn))
@@ -25,6 +25,7 b' from __future__ import absolute_import'
25 25 import collections
26 26 import errno
27 27 import itertools
28 import stat
28 29
29 30 from mercurial.i18n import _
30 31 from mercurial import (
@@ -283,7 +284,7 b' def cleanupoldbackups(repo):'
283 284 maxbackups = repo.ui.configint('shelve', 'maxbackups')
284 285 hgfiles = [f for f in vfs.listdir()
285 286 if f.endswith('.' + patchextension)]
286 hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
287 hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles])
287 288 if 0 < maxbackups and maxbackups < len(hgfiles):
288 289 bordermtime = hgfiles[-maxbackups][0]
289 290 else:
@@ -542,7 +543,7 b' def listshelves(repo):'
542 543 if not pfx or sfx != patchextension:
543 544 continue
544 545 st = shelvedfile(repo, name).stat()
545 info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
546 info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename()))
546 547 return sorted(info, reverse=True)
547 548
548 549 def listcmd(ui, repo, pats, opts):
@@ -45,6 +45,7 b' import inspect'
45 45 import os
46 46 import re
47 47 import socket
48 import stat
48 49 import struct
49 50 import time
50 51
@@ -161,7 +162,7 b' def _mtimehash(paths):'
161 162 def trystat(path):
162 163 try:
163 164 st = os.stat(path)
164 return (st.st_mtime, st.st_size)
165 return (st[stat.ST_MTIME], st.st_size)
165 166 except OSError:
166 167 # could be ENOENT, EPERM etc. not fatal in any case
167 168 pass
@@ -546,9 +547,9 b' class chgunixservicehandler(object):'
546 547
547 548 def _issocketowner(self):
548 549 try:
549 stat = os.stat(self._realaddress)
550 return (stat.st_ino == self._socketstat.st_ino and
551 stat.st_mtime == self._socketstat.st_mtime)
550 st = os.stat(self._realaddress)
551 return (st.st_ino == self._socketstat.st_ino and
552 st[stat.ST_MTIME] == self._socketstat[stat.ST_MTIME])
552 553 except OSError:
553 554 return False
554 555
@@ -1893,7 +1893,7 b' class workingfilectx(committablefilectx)'
1893 1893 def date(self):
1894 1894 t, tz = self._changectx.date()
1895 1895 try:
1896 return (self._repo.wvfs.lstat(self._path).st_mtime, tz)
1896 return (self._repo.wvfs.lstat(self._path)[stat.ST_MTIME], tz)
1897 1897 except OSError as err:
1898 1898 if err.errno != errno.ENOENT:
1899 1899 raise
@@ -16,6 +16,7 b' import os'
16 16 import random
17 17 import socket
18 18 import ssl
19 import stat
19 20 import string
20 21 import subprocess
21 22 import sys
@@ -1373,9 +1374,9 b' def debuglocks(ui, repo, **opts):'
1373 1374 l.release()
1374 1375 else:
1375 1376 try:
1376 stat = vfs.lstat(name)
1377 age = now - stat.st_mtime
1378 user = util.username(stat.st_uid)
1377 st = vfs.lstat(name)
1378 age = now - st[stat.ST_MTIME]
1379 user = util.username(st.st_uid)
1379 1380 locker = vfs.readlock(name)
1380 1381 if ":" in locker:
1381 1382 host, pid = locker.split(':')
@@ -49,7 +49,7 b' def _getfsnow(vfs):'
49 49 '''Get "now" timestamp on filesystem'''
50 50 tmpfd, tmpname = vfs.mkstemp()
51 51 try:
52 return os.fstat(tmpfd).st_mtime
52 return os.fstat(tmpfd)[stat.ST_MTIME]
53 53 finally:
54 54 os.close(tmpfd)
55 55 vfs.unlink(tmpname)
@@ -387,7 +387,7 b' class dirstate(object):'
387 387 def normal(self, f):
388 388 '''Mark a file normal and clean.'''
389 389 s = os.lstat(self._join(f))
390 mtime = s.st_mtime
390 mtime = s[stat.ST_MTIME]
391 391 self._addpath(f, 'n', s.st_mode,
392 392 s.st_size & _rangemask, mtime & _rangemask)
393 393 self._map.copymap.pop(f, None)
@@ -626,7 +626,7 b' class dirstate(object):'
626 626 self._origpl = None
627 627 # use the modification time of the newly created temporary file as the
628 628 # filesystem's notion of 'now'
629 now = util.fstat(st).st_mtime & _rangemask
629 now = util.fstat(st)[stat.ST_MTIME] & _rangemask
630 630
631 631 # enough 'delaywrite' prevents 'pack_dirstate' from dropping
632 632 # timestamp of each entries in dirstate, because of 'now > mtime'
@@ -1068,9 +1068,10 b' class dirstate(object):'
1068 1068 or size == -2 # other parent
1069 1069 or fn in copymap):
1070 1070 madd(fn)
1071 elif time != st.st_mtime and time != st.st_mtime & _rangemask:
1071 elif (time != st[stat.ST_MTIME]
1072 and time != st[stat.ST_MTIME] & _rangemask):
1072 1073 ladd(fn)
1073 elif st.st_mtime == lastnormaltime:
1074 elif st[stat.ST_MTIME] == lastnormaltime:
1074 1075 # fn may have just been marked as normal and it may have
1075 1076 # changed in the same second without changing its size.
1076 1077 # This can happen if we quickly do multiple commits.
@@ -12,6 +12,7 b' import errno'
12 12 import hashlib
13 13 import os
14 14 import shutil
15 import stat
15 16
16 17 from .i18n import _
17 18 from .node import (
@@ -1113,8 +1114,8 b' class cachedlocalrepo(object):'
1113 1114 st = os.stat(p)
1114 1115 except OSError:
1115 1116 st = os.stat(prefix)
1116 state.append((st.st_mtime, st.st_size))
1117 maxmtime = max(maxmtime, st.st_mtime)
1117 state.append((st[stat.ST_MTIME], st.st_size))
1118 maxmtime = max(maxmtime, st[stat.ST_MTIME])
1118 1119
1119 1120 return tuple(state), maxmtime
1120 1121
@@ -12,6 +12,7 b' import base64'
12 12 import errno
13 13 import mimetypes
14 14 import os
15 import stat
15 16
16 17 from .. import (
17 18 encoding,
@@ -132,7 +133,7 b' def get_stat(spath, fn):'
132 133 return os.stat(spath)
133 134
134 135 def get_mtime(spath):
135 return get_stat(spath, "00changelog.i").st_mtime
136 return get_stat(spath, "00changelog.i")[stat.ST_MTIME]
136 137
137 138 def ispathsafe(path):
138 139 """Determine if a path is safe to use for filesystem access."""
@@ -617,8 +617,8 b' class cachestat(object):'
617 617 self.stat.st_uid == other.stat.st_uid and
618 618 self.stat.st_gid == other.stat.st_gid and
619 619 self.stat.st_size == other.stat.st_size and
620 self.stat.st_mtime == other.stat.st_mtime and
621 self.stat.st_ctime == other.stat.st_ctime)
620 self.stat[stat.ST_MTIME] == other.stat[stat.ST_MTIME] and
621 self.stat[stat.ST_CTIME] == other.stat[stat.ST_CTIME])
622 622 except AttributeError:
623 623 return False
624 624
@@ -1567,7 +1567,8 b' def copyfile(src, dest, hardlink=False, '
1567 1567 newstat = filestat.frompath(dest)
1568 1568 if newstat.isambig(oldstat):
1569 1569 # stat of copied file is ambiguous to original one
1570 advanced = (oldstat.stat.st_mtime + 1) & 0x7fffffff
1570 advanced = (
1571 oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff
1571 1572 os.utime(dest, (advanced, advanced))
1572 1573 except shutil.Error as inst:
1573 1574 raise Abort(str(inst))
@@ -1963,8 +1964,8 b' class filestat(object):'
1963 1964 # avoided, comparison of size, ctime and mtime is enough
1964 1965 # to exactly detect change of a file regardless of platform
1965 1966 return (self.stat.st_size == old.stat.st_size and
1966 self.stat.st_ctime == old.stat.st_ctime and
1967 self.stat.st_mtime == old.stat.st_mtime)
1967 self.stat[stat.ST_CTIME] == old.stat[stat.ST_CTIME] and
1968 self.stat[stat.ST_MTIME] == old.stat[stat.ST_MTIME])
1968 1969 except AttributeError:
1969 1970 pass
1970 1971 try:
@@ -2003,7 +2004,7 b' class filestat(object):'
2003 2004 S[n].mtime", even if size of a file isn't changed.
2004 2005 """
2005 2006 try:
2006 return (self.stat.st_ctime == old.stat.st_ctime)
2007 return (self.stat[stat.ST_CTIME] == old.stat[stat.ST_CTIME])
2007 2008 except AttributeError:
2008 2009 return False
2009 2010
@@ -2018,7 +2019,7 b' class filestat(object):'
2018 2019
2019 2020 Otherwise, this returns True, as "ambiguity is avoided".
2020 2021 """
2021 advanced = (old.stat.st_mtime + 1) & 0x7fffffff
2022 advanced = (old.stat[stat.ST_MTIME] + 1) & 0x7fffffff
2022 2023 try:
2023 2024 os.utime(path, (advanced, advanced))
2024 2025 except OSError as inst:
@@ -2069,7 +2070,7 b' class atomictempfile(object):'
2069 2070 newstat = filestat.frompath(filename)
2070 2071 if newstat.isambig(oldstat):
2071 2072 # stat of changed file is ambiguous to original one
2072 advanced = (oldstat.stat.st_mtime + 1) & 0x7fffffff
2073 advanced = (oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff
2073 2074 os.utime(filename, (advanced, advanced))
2074 2075 else:
2075 2076 rename(self._tempname, filename)
@@ -6,6 +6,7 b' from __future__ import absolute_import'
6 6 Without this svn will not detect workspace changes."""
7 7
8 8 import os
9 import stat
9 10 import sys
10 11
11 12 text = sys.argv[1]
@@ -13,16 +14,15 b' fname = sys.argv[2]'
13 14
14 15 f = open(fname, "ab")
15 16 try:
16 before = os.fstat(f.fileno()).st_mtime
17 before = os.fstat(f.fileno())[stat.ST_MTIME]
17 18 f.write(text)
18 19 f.write("\n")
19 20 finally:
20 21 f.close()
21 22 inc = 1
22 now = os.stat(fname).st_mtime
23 now = os.stat(fname)[stat.ST_MTIME]
23 24 while now == before:
24 25 t = now + inc
25 26 inc += 1
26 27 os.utime(fname, (t, t))
27 now = os.stat(fname).st_mtime
28
28 now = os.stat(fname)[stat.ST_MTIME]
@@ -3,6 +3,7 b' from __future__ import absolute_import'
3 3 import glob
4 4 import os
5 5 import shutil
6 import stat
6 7 import tempfile
7 8 import unittest
8 9
@@ -66,7 +67,7 b' class testatomictempfile(unittest.TestCa'
66 67 for i in xrange(5):
67 68 atomicwrite(False)
68 69 oldstat = os.stat(self._filename)
69 if oldstat.st_ctime != oldstat.st_mtime:
70 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]:
70 71 # subsequent changing never causes ambiguity
71 72 continue
72 73
@@ -77,14 +78,14 b' class testatomictempfile(unittest.TestCa'
77 78 for j in xrange(repetition):
78 79 atomicwrite(True)
79 80 newstat = os.stat(self._filename)
80 if oldstat.st_ctime != newstat.st_ctime:
81 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]:
81 82 # timestamp ambiguity was naturally avoided while repetition
82 83 continue
83 84
84 85 # st_mtime should be advanced "repetition" times, because
85 86 # all atomicwrite() occurred at same time (in sec)
86 self.assertTrue(newstat.st_mtime ==
87 ((oldstat.st_mtime + repetition) & 0x7fffffff))
87 oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7fffffff
88 self.assertTrue(newstat[stat.ST_MTIME] == oldtime)
88 89 # no more examination is needed, if assumption above is true
89 90 break
90 91 else:
@@ -1,5 +1,6 b''
1 1 from __future__ import absolute_import, print_function
2 2 import os
3 import stat
3 4 from mercurial.node import hex
4 5 from mercurial import (
5 6 context,
@@ -170,7 +171,8 b" for i in [b'1', b'2', b'3']:"
170 171 # touch 00manifest.i mtime so storecache could expire.
171 172 # repo.__dict__['manifestlog'] is deleted by transaction releasefn.
172 173 st = repo.svfs.stat('00manifest.i')
173 repo.svfs.utime('00manifest.i', (st.st_mtime + 1, st.st_mtime + 1))
174 repo.svfs.utime('00manifest.i',
175 (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1))
174 176
175 177 # read the file just committed
176 178 try:
@@ -1,5 +1,6 b''
1 1 from __future__ import absolute_import, print_function
2 2 import os
3 import stat
3 4 import subprocess
4 5 import sys
5 6
@@ -200,7 +201,7 b' def antiambiguity():'
200 201 fp.close()
201 202
202 203 oldstat = os.stat(filename)
203 if oldstat.st_ctime != oldstat.st_mtime:
204 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]:
204 205 # subsequent changing never causes ambiguity
205 206 continue
206 207
@@ -219,16 +220,17 b' def antiambiguity():'
219 220 fp.write('BAR')
220 221
221 222 newstat = os.stat(filename)
222 if oldstat.st_ctime != newstat.st_ctime:
223 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]:
223 224 # timestamp ambiguity was naturally avoided while repetition
224 225 continue
225 226
226 227 # st_mtime should be advanced "repetition * 2" times, because
227 228 # all changes occurred at same time (in sec)
228 expected = (oldstat.st_mtime + repetition * 2) & 0x7fffffff
229 if newstat.st_mtime != expected:
230 print("'newstat.st_mtime %s is not %s (as %s + %s * 2)" %
231 (newstat.st_mtime, expected, oldstat.st_mtime, repetition))
229 expected = (oldstat[stat.ST_MTIME] + repetition * 2) & 0x7fffffff
230 if newstat[stat.ST_MTIME] != expected:
231 print("'newstat[stat.ST_MTIME] %s is not %s (as %s + %s * 2)" %
232 (newstat[stat.ST_MTIME], expected,
233 oldstat[stat.ST_MTIME], repetition))
232 234
233 235 # no more examination is needed regardless of result
234 236 break
General Comments 0
You need to be logged in to leave comments. Login now