Mercurial > hg
comparison mercurial/dirstateutils/timestamp.py @ 48263:83d0bd45b662
dirstate-v2: actually use sub-second mtime precision
Instead of zero, set the nanoseconds field to its correct value whenever
possible and preserve it across serialization+parsing.
Differential Revision: https://phab.mercurial-scm.org/D11702
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 13 Oct 2021 15:58:14 +0200 |
parents | 68bb472aee9c |
children | 08b060abd658 |
comparison
equal
deleted
inserted
replaced
48262:68bb472aee9c | 48263:83d0bd45b662 |
---|---|
64 def mtime_of(stat_result): | 64 def mtime_of(stat_result): |
65 """ | 65 """ |
66 Takes an `os.stat_result`-like object and returns a `timestamp` object | 66 Takes an `os.stat_result`-like object and returns a `timestamp` object |
67 for its modification time. | 67 for its modification time. |
68 """ | 68 """ |
69 # https://docs.python.org/2/library/os.html#os.stat_float_times | 69 try: |
70 # "For compatibility with older Python versions, | 70 # TODO: add this attribute to `osutil.stat` objects, |
71 # accessing stat_result as a tuple always returns integers." | 71 # see `mercurial/cext/osutil.c`. |
72 secs = stat_result[stat.ST_MTIME] | 72 # |
73 # This attribute is also not available on Python 2. | |
74 nanos = stat_result.st_mtime_ns | |
75 except AttributeError: | |
76 # https://docs.python.org/2/library/os.html#os.stat_float_times | |
77 # "For compatibility with older Python versions, | |
78 # accessing stat_result as a tuple always returns integers." | |
79 secs = stat_result[stat.ST_MTIME] | |
73 | 80 |
74 # For now | 81 subsec_nanos = 0 |
75 subsec_nanos = 0 | 82 else: |
83 billion = int(1e9) | |
84 secs = nanos // billion | |
85 subsec_nanos = nanos % billion | |
76 | 86 |
77 return timestamp((secs, subsec_nanos)) | 87 return timestamp((secs, subsec_nanos)) |