comparison mercurial/dirstateutils/timestamp.py @ 48397:8d585aa9becf

dirstate: drop comparison primitive on the timestamp class All comparison are now managed without using operator : - the status mtime comparisons is handled by the DirstateItem, - the fixup reliability check, - the update "hack". So we no longer needs the operator and should discourage its usage. Differential Revision: https://phab.mercurial-scm.org/D11841
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 23 Nov 2021 19:27:17 +0100
parents 9ae0353c9f5d
children 111098af6356
comparison
equal deleted inserted replaced
48396:c0d88407b7d4 48397:8d585aa9becf
6 from __future__ import absolute_import 6 from __future__ import absolute_import
7 7
8 import functools 8 import functools
9 import os 9 import os
10 import stat 10 import stat
11
12 from .. import error
11 13
12 14
13 rangemask = 0x7FFFFFFF 15 rangemask = 0x7FFFFFFF
14 16
15 17
32 truncated_seconds, subsec_nanos = value 34 truncated_seconds, subsec_nanos = value
33 value = (truncated_seconds & rangemask, subsec_nanos) 35 value = (truncated_seconds & rangemask, subsec_nanos)
34 return super(timestamp, cls).__new__(cls, value) 36 return super(timestamp, cls).__new__(cls, value)
35 37
36 def __eq__(self, other): 38 def __eq__(self, other):
37 self_secs, self_subsec_nanos = self 39 raise error.ProgrammingError(
38 other_secs, other_subsec_nanos = other 40 'timestamp should never be compared directly'
39 return self_secs == other_secs and (
40 self_subsec_nanos == other_subsec_nanos
41 or self_subsec_nanos == 0
42 or other_subsec_nanos == 0
43 ) 41 )
44 42
45 def __gt__(self, other): 43 def __gt__(self, other):
46 self_secs, self_subsec_nanos = self 44 raise error.ProgrammingError(
47 other_secs, other_subsec_nanos = other 45 'timestamp should never be compared directly'
48 if self_secs > other_secs: 46 )
49 return True
50 if self_secs < other_secs:
51 return False
52 if self_subsec_nanos == 0 or other_subsec_nanos == 0:
53 # they are considered equal, so not "greater than"
54 return False
55 return self_subsec_nanos > other_subsec_nanos
56 47
57 48
58 def get_fs_now(vfs): 49 def get_fs_now(vfs):
59 """return a timestamp for "now" in the current vfs 50 """return a timestamp for "now" in the current vfs
60 51