
    6h                        S SK Jr  S SKrS SKrS SKrS SKrS SKJrJr  SSK	J
r
  Sr\R                   " S S\5      5       rSS	 jrSS
 jrSS jr      SS jr      SS jrSrSS jrg)    )annotationsN)OptionalTuple   )erroric                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )	timestamp   a  
A Unix timestamp with optional nanoseconds precision,
modulo 2**31 seconds.

A 3-tuple containing:

`truncated_seconds`: seconds since the Unix epoch,
truncated to its lower 31 bits

`subsecond_nanoseconds`: number of nanoseconds since `truncated_seconds`.
When this is zero, the sub-second precision is considered unknown.

`second_ambiguous`: whether this timestamp is still "reliable"
(see `reliable_mtime_of`) if we drop its sub-second component.
c                B   > Uu  p#nU[         -  X44n[        TU ]	  X5      $ )N)	rangemasksuper__new__)clsvaluetruncated_secondssubsec_nanossecond_ambiguous	__class__s        C/usr/lib/python3/dist-packages/mercurial/dirstateutils/timestamp.pyr   timestamp.__new__&   s-    <A9)9"Y.Ows**    c                .    [         R                  " S5      eNz+timestamp should never be compared directlyr   ProgrammingErrorselfothers     r   __eq__timestamp.__eq__+       $$9
 	
r   c                .    [         R                  " S5      er   r   r   s     r   __gt__timestamp.__gt__0   r!   r    )
__name__
__module____qualname____firstlineno____doc__r   r   r#   __static_attributes____classcell__)r   s   @r   r	   r	      s     +



 
r   r	   c                   U R                  5       u  p [        [        R                  " U5      5      [        R                  " U5        U R                  U5        $ ! [        R                  " U5        U R                  U5        f = f)zvreturn a timestamp for "now" in the current vfs

This will raise an exception if no temporary files could be created.
)mkstempmtime_ofosfstatcloseunlink)vfstmpfdtmpnames      r   
get_fs_nowr7   6   sX    
 [[]NE(


7 	

7s   A )Bc                 6    [         R                  [        S5      $ )z,
Returns the `timestamp` at the Unix epoch.
)r   r   )tupler   r	   r%   r   r   zeror:   C   s     ==F++r   c                     U R                   n[        S5      nX-  nX-  n[        X4S45      $ ! [         a    U [        R                     nSn N.f = f)zc
Takes an `os.stat_result`-like object and returns a `timestamp` object
for its modification time.
g    eAr   F)st_mtime_nsintAttributeErrorstatST_MTIMEr	   )stat_resultnanosbillionsecsr   s        r   r/   r/   J   sd    
'
 '' c(d%011   4==)s   . AAc                .    [        U 5      n[        X!5      $ )z2Wrapper for `make_mtime_reliable` for stat objects)r/   make_mtime_reliable)rA   present_mtime
file_mtimes      r   reliable_mtime_ofrI   d   s     +&Jz99r   c                    U S   nU S   nUS   nUS   nXB:X  a!  U(       a  U(       a  X5:  a  [        X#S45      $ gXBs=:  a
  SU-   :  a   g  U $ U $ )a   Same as `mtime_of`, but return `None` or a `Timestamp` with
`second_ambiguous` set if the date might be ambiguous.

A modification time is reliable if it is older than "present_time" (or
sufficiently in the future).

Otherwise a concurrent modification might happens with the same mtime.
r      TNiQ )r	   )file_timestamprG   file_secondfile_nsboundary_secondboundary_nss         r   rF   rF   l   sx     !#KQG#A&O"K %{$ +!=>>		F)o*E	F 
G ~r   g?c                D   [         R                  " 5       n [        U 5      n[        U 5      nUS   US   :X  aU  US   US   :X  aI  [         R                  " 5       U-
  [        :  a  US4$ [        U 5      nUS   US   :X  a  US   US   :X  a  MI  US4$ ! [         a     gf = f)aP  Wait until the next update from the filesystem time by writing in a loop
a new temporary file inside the working directory and checking if its time
differs from the first one observed.

Returns `None` if we are unable to get the filesystem time,
`(timestamp, True)` if we've timed out waiting for the filesystem clock
to tick, and `(timestamp, False)` if we've waited successfully.

On Linux, your average tick is going to be a "jiffy", or 1/HZ.
HZ is your kernel's tick rate (if it has one configured) and the value
is the one returned by `grep 'CONFIG_HZ=' /boot/config-$(uname -r)`,
again assuming a normal setup.

In my case (Alphare) at the time of writing, I get `CONFIG_HZ=250`,
which equates to 4ms.
This might change with a series that could make it to Linux 6.12:
https://lore.kernel.org/all/20241002-mgtime-v10-8-d1c4717f5284@kernel.org
r   rK   TFN)time	monotonicr7   FS_TICK_WAIT_TIMEOUTOSError)r4   startold_fs_timenew_fs_times       r   wait_until_fs_tickrY      s    & NNE$ o o Nk!n,A+a.0~~%'*>>#T**$S/K Nk!n,A+a.0 U##  s   AB )#B 
BB)returnOptional[timestamp])rZ   r	   )rA   os.stat_resultrZ   r	   )rA   r\   rG   r	   rZ   r[   )rL   r	   rG   r	   rZ   r[   )rZ   z Optional[Tuple[timestamp, bool]])
__future__r   	functoolsr0   r?   rR   typingr   r    r   r   total_orderingr9   r	   r7   r:   r/   rI   rF   rT   rY   r%   r   r   <module>rb      s    #  	   "  	 
 
 
B
,24::09::.7D  #$r   