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