https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/hgext/fastannotate/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/hgext/fastannotate/__pycache__/context.cpython-310.pyc
o

�]Lb/{�@sTddlmZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZm
Z
mZddlmZmZmZmZmZmZmZddlmZmZdd	lmZmZej d
d��Z!d&d
d�Z"dd�Z#dd�Z$e� ej%�Z&d'dd�Z'dd�Z(dd�Z)e)ej*�Z+Gdd�de,�Z-e-�Z*Gdd�de,�Z.dd�Z/Gd d!�d!e,�Z0ej1e*dfd"d#��Z2d(d$d%�Z3dS))�)�absolute_importN)�_)�getattr�open�setattr)�bin�hex�short)�error�linelog�lock�mdiff�pycompat�scmutil�util)�hashutil�
stringutil�)r
�revmapcCs
|�|�S�N)�file)�repo�path�r�</usr/lib/python3/dist-packages/hgext/fastannotate/context.py�_getflog-s
rTcsN�j���}|s�fdd�|D�}|D]}d|jvr$t�j|���|_q|S)Ncs g|]}|�����kr|�qSr�r)�.0�p��frr�
<listcomp>=s z_parents.<locals>.<listcomp>�_filelog)�	_changeid�parents�__dict__r�_reporr")r �follow�plrrrr�_parents3s
�r)csD���}|�d�}|r|�d�s|d7}�fdd�t�|�D�|fS)N�
rcsg|]}�|f�qSrr)r�i��fctxrrr!Osz_decorate.<locals>.<listcomp>)�data�count�endswithr�xrange)r-�text�	linecountrr,r�	_decorateJs

r4cCs>|D]\\}}}}}|dkr|d||�|d||�<q|S)N�=rr)�parent�child�blocks�a1�a2�b1�b2�trrr�_pairUs
�r>FcCs�|rt|t�s|durt||�}n||}|dur0|��dur%||}|S|j||��d�}|S||}|dkr=|��}n|��}||��krO||_|||_|S)a2(repo, str, str) -> fctx

    get the filectx object from repo, rev, path, in an efficient way.

    if resolverev is True, "rev" is a revision specified by the revset
    language, otherwise "rev" is a nodeid, or a revision number that can
    be consumed by repo.__getitem__.

    if adjustctx is not None, the returned fctx will point to a changeset
    that introduces the change (last modified the file). if adjustctx
    is 'linkrev', trust the linkrev and do not adjust it. this is noticeably
    faster for big repos but is incorrect for some cases.
    N)�changeid�linkrev)	�
isinstance�int�
_revsingle�rev�filectx�linkrev�introrevr#�
_changectx)rrDr�
resolverev�	adjustctx�ctxr-rGrrr�resolvefctxcs"�
�

rLcCs$|�dd��dd��dd��dd�S)	Ns.hg/s.hg.hg/s.l/s.l.hg/s.m/s.m.hg/s.lock/s	.lock.hg/)�replacerrrr�	encodedir�s

�rNcs:t�t�fdd�tjjD���}tt�|��	��dd�S)Nc3s�|]
}|t�|�fVqdSr)r)r�k��diffoptsrr�	<genexpr>�s�zhashdiffopts.<locals>.<genexpr>�)
r�pprint�sortedr
rQ�defaultsrr�sha1�digest)rQ�
diffoptstrrrPr�hashdiffopts�s�rZc@s2eZdZdZdddd�Zdd�Zejdd��ZdS)	�annotateoptsz�like mercurial.mdiff.diffopts, but is for annotate

    followrename: follow renames, like "hg annotate -f"
    followmerge: follow p2 of a merge changeset, otherwise p2 is ignored
    NT)sdiffoptssfollowrenamesfollowmergecKs8t�|�}t�|j�D]\}}t|||�||��qdSr)r�byteskwargs�	iteritemsrVr�get)�self�optsrO�vrrr�__init__�s
�zannotateopts.__init__cCsbd}|js	|d7}|js|d7}|jdur-t|jtj�sJ�t|j�}|tkr-|d|7}|p0dS)z?represent opts in a short string, suitable for a directory name�sr0sm0N�isdefault)�followrename�followmergerQrAr
rZ�_defaultdiffopthash)r_�result�diffopthashrrr�shortstr�s

zannotateopts.shortstr)	�__name__�
__module__�__qualname__�__doc__rVrbr�
propertycacherjrrrrr[�s�r[c@s�eZdZdZdd�Zedd��Zedd��Zdd	�ZeZ	d
d�Z
edd
��Zd/dd�Zd0dd�Z
dd�Zd1dd�Zdd�Zdd�Zdd�Zd2dd �Zd!d"�Zed2d#d$��Zd2d%d&�Zd'd(�Zejd)d*��Zejd+d,��Zd2d-d.�ZdS)3�_annotatecontextz{do not use this class directly as it does not use lock to protect
    writes. use "with annotatecontext(...)" instead.
    cCs<||_|j|_||_||_||_||_d|_d|_i|_dSr)	r�uirr`�linelogpath�
revmappath�_linelog�_revmap�
_node2path)r_rrrrrsr`rrrrb�s
z_annotatecontext.__init__c	Cs�|jdurPtj�|j�rKt|jd��.}ztj�|�	��|_Wntj
y-t��|_Yn
wWd�|jSWd�|jS1sCwY|jSt��|_|jS)Nsrb)rt�osr�existsrrr�
linelogmodr�fromdata�read�LineLogError�r_r rrrr�s$
��
��
��
�z_annotatecontext.linelogcCs|jdurt�|j�|_|jSr)ru�	revmapmodrrs�r_rrrr�s
z_annotatecontext.revmapcCsn|jdur
|j��d|_|jdur5t|jd��}|�|j���Wd�n1s+wYd|_dSdS)Nswb)ru�flushrtrrr�write�encoder}rrr�close�s


�
�z_annotatecontext.closecCs&|��|j��t|j|jg�dS)z0delete linelog and revmap, useful for rebuildingN)r�rv�clear�_unlinkpathsrsrrrrrr�rebuild�s
z_annotatecontext.rebuildcCs&|jdurt�|j�S|j�|jj�S)z6return last node in revmap, or None if revmap is emptyN)rur~�getlastnoders�rev2hsh�maxrevrrrr�lastnode�s
z_annotatecontext.lastnodeTcCsh|j}z&|j|dd�}|jj�|���}|s%|r%||kr%|j�|�duWS||kWSty3YdSw)areturn True if the revmap / linelog is up-to-date, or the file
        does not exist in the master revision. False otherwise.

        it tries to be fast and could return false negatives, because of the
        use of linkrev instead of introrev.

        useful for both server and client to decide whether to update
        fastannotate cache or not.

        if strict is True, even if fctx exists in the revmap, but is not the
        last node, isuptodate will return False. it's good for performance - no
        expensive check was done.

        if strict is False, if fctx exists in the revmap, this function may
        return True. this is useful for the client to skip downloading the
        cache if the client's master is behind the server's.
        T)rIN)	r��_resolvefctxr�	changelog�noderFr�hsh2rev�LookupError)r_�master�strictr�r �linknoderrr�
isuptodates
�z_annotatecontext.isuptodateNFc
s6t|t�rt�jj�|��}��|�\}}|r4�jjr-�j�	d�j
t�t
�|d��f���|||�Sd}|rSz
�j|ddd�}Wn	tyKYnw|�jvrSd}|g}|rn|��duritjtd�td�d��|�|�|dd�}	i}
|d	i}i}|	r�|	��}
|
|
vs�|
|vr�q||
�jvr��j�|
���}�j�|��jj}||
��f||
<q|��|
�}||
|
<|D]}|�|d
�d	||<||
vr�|	�|�q�|	s~t �}|}
|
r�|
�jvr�|�!|
�|
|
}|r�|d
}
nd}
n|
r�|
�jvs�|dur���"|
��jj�r|�r�j�	d�j
t#|�f�n|�s�j�	d�j
��j��jj$�|dd�}	�jj%d
t#|�d�}|	�r|	d}
|
|v�rI|	���q7d}|
|
}|D]}||v�r_d}|	�|��qQ|�sf�q7|	��d}|
|v}|
|v�swJ�t&|
�}t'|�D]<\}}t(��)||d	|d	��}|d
k�r�|�r�|}t*||||�}||d	k�r�||=||=�q||d	8<�q|||
<|
|
=|�r�|�+�d}t#|�dk�r܈j,j-�r�|d
}|du�r�t(��)d|d	��}��.|
||�n|�r�|
�
��j/|
��<|	�s:|�0��fdd�||d
D�}��1||||�S)a�incrementally update the cache so it includes revisions in the main
        branch till 'master'. and run annotate on 'rev', which may or may not be
        included in the main branch.

        if master is None, do not update linelog.

        the first value returned is the annotate result, it is [(node, linenum)]
        by default. [(node, linenum, path)] if showpath is True.

        if showlines is True, a second value will be returned, it is a list of
        corresponding line contents.
        s6fastannotate: %s: using fast path (resolved fctx: %s)
snodeNT�rIrJscannot update linelog to wdir()sset fastannotate.mainbranch)�hintrrs7fastannotate: %s: %d new changesets in the main branch
sBfastannotate: %s: linelog cannot help in annotating this revision
sbuilding cache)�total���F�rccs2g|]\}}t|t�r�j�|�n|��|f�qSr)rArBrr�r�)r�fr�lrrrr!�s ��z-_annotatecontext.annotate.<locals>.<listcomp>)2rArBrrr�r��canannotatedirectlyrq�	debugflag�debugrrrTr�safehasattr�annotatedirectlyr�r�rrDr
�Abortr�append�popr�r�annotate�annotateresultr.�_parentfuncr^�set�add�_checklastmasterhead�lenr��makeprogressr4�	enumerate�list�_diffblocksr>�	incrementr`rf�
_appendrevrv�complete�_refineannotateresult)r_rDr��showpath�	showlines�directly�revfctx�
masterfctx�	initvisit�visit�pcache�needed�histr �llrevrhr(r�
newmainbranch�progress�readyr8�ismainbranch�currr+�bs�
bannotatedrrrr�(s
���
��
�



��

�

�����


�

�0

�z_annotatecontext.annotatecCs�d}d}t|t�s*|dur*ttd��t|�dd��|�}|dur*||jf|jvr*|}|durO|jr3dnd}|j	||dd�}||jv}|sO|jrO|j	|ddd�}||fS)z�(str) -> bool, fctx or node.
        return (True, f) if we can annotate without updating the linelog, pass
        f to annotatedirectly.
        return (False, f) if we need extra calculation. f is the fctx resolved
        from rev.
        TN)��(cSsdSrr)�xrrr�<lambda>�sz6_annotatecontext.canannotatedirectly.<locals>.<lambda>r@)rJrI)
rArB�bytesrr^r�rr�	_perfhackr�)r_rDrhr �hshrJrrrr��s

z$_annotatecontext.canannotatedirectlycsB|j|ddd�}||jvrm|g}d}	|d}|�|�}|sn|d|jvr-|d��}n|�|d�qt��}	|	�|j�|	�|	j	�t
�����|j�t|�D]}|��}
t|�
||
��}|�|	�||�|
}qSn|j}	|j�|	��}|��}
��|
����fdd�|D�}|r�|�|��}|r�|�|�|	�}||f}|S)a
(rev : str) -> [(node : str, linenum : int, path : str)]

        the result has the same format with annotate, but include all (including
        deleted) lines up to rev. call this after calling annotate(rev, ...) for
        better performance and accuracy.
        Tr�rcr�rcs&g|]\}}|�kr��|�|f�qSr)r��r�rr��r�rrrr!/s&z5_annotatecontext.annotatealllines.<locals>.<listcomp>)r�rr�r.r�ryr�copyfromr�r�r~�reversedr�r��_doappendrev�getalllinesr�r��_addpathtoresult�
_resolvelines)r_rDr�r�r��chain�ar r(r�br8�linesr�rh�linecontentsrr�r�annotatealllinessJ

��
z!_annotatecontext.annotatealllinescs�fdd�|D�}dgt|�}t�t�}t�t|��D]}|||||df�|�q|�rd}zt�|�D]\\}	}
}��|	�t	j
@rHq9||dd}Wnty]|YSw|dur�i}t�|�D]D\\}	}
}|	|vr�||dd}|jj
r�|j�dt|�|
|f�|�|��|	��}t�|���}|||	<|D]
}||	|
||<q�qitdd�|D��s�J�|S|j�d	t|��|�|	�|�|��|	��}|j}t�|���}t|�t|�kr�t�d
��t|�D]\}}||}||v�r	||D]}|||<q�||=q�|s1|S)ah(annotateresult) -> [line]. designed for annotatealllines.
        this is probably the most inefficient code in the whole fastannotate
        directory. but we have made a decision that the linelog does not
        store line contents. so getting them requires random accesses to
        the revlog data, since they can be many, it can be very slow.
        csg|]	}��|d��qS)r)r�)rr��rrrr!Asz2_annotatecontext._resolvelines.<locals>.<listcomp>Nrrs6fastannotate: reading %s line #%d to resolve lines %r
css�|]}|duVqdSrr)rr�rrrrRds�z1_annotatecontext._resolvelines.<locals>.<genexpr>s+fastannotate: annotate %s to resolve lines
sunexpected annotated lines)r��collections�defaultdictr�rr1r�r]�rev2flagr~�sidebranchflag�
StopIterationrqr�r�r	r��rev2pathr
�
splitnewlinesr.�allr�r��faerror�CorruptedFileErrorr�)r_r�rr�revsrh�key2idxsr+r�rD�_linenum�idxs�revlines�linenumr-r��idx�	annotated�linerOrr�rr�9sl
 �����
�



��1z_annotatecontext._resolvelinescs�t|t�r|}n|��}�j�|�}|st�dt|����j�|�t	j
@dkr1t�dt|����j�|��fdd��jj
D�}��||||�S)alike annotate, but when we know that f is in linelog.
        f can be either a 20-char str (node) or a fctx. this is for perf - in
        the best case, the user provides a node and we don't need to read the
        filelog or construct any filecontext.
        s%s is not in revmaprs%s is not in revmap mainbranchcs g|]\}}�j�|�|f�qSr)rr�r�rrrr!�s�z5_annotatecontext.annotatedirectly.<locals>.<listcomp>)rAr�r�rr�r�r�rr�r~r�rr�r�r�)r_r r�r�r�r�rhrrrr�zs

�
�z!_annotatecontext.annotatedirectlycCst|r|�|�}|r8t|t�r|j�|�}|�||j�|��}n|}t�|�	��}t
|�t
|�kr4t���||f}|S)znadd the missing path or line contents, they can be expensive.
        f could be either node or fctx.
        )
r�rAr�rr�r�r�r
r�r.r�r�r�)r_rhr r�r�r�r-r�rrrr��s

z&_annotatecontext._refineannotateresultcCs|�|j|j|||�dSr)r�rr)r_r-r8r�rrrr��sz_annotatecontext._appendrevcCst�|||jj�Sr)r
�	allblocksr`rQ)r_r�r�rrrr��sz_annotatecontext._diffblockscs�fdd�}g}i�|dur*|D]\\}}}	}
}|dkr)|dd�||	|
�D�7}qt|�}||vr7|�|�|D]}||��|<q9�j|��|��d�}
|
�|<t|�D]0\\}}}	}
}|dkrbqU|durp|�|
|||	|
�qU�fdd�||	|
�D�}|�|
|||�qUdS)	z'append a revision to linelog and revmapcsFt|t�r
t�d��|��}��|�}|dur!�j|d|��d�}|S)z
(fctx) -> intsf should not be an intNT)�
sidebranchr)rArBr
�ProgrammingErrorr�r�r�r)r r�rDr�rr�getllrev�s


z/_annotatecontext._doappendrev.<locals>.getllrevNr5cSsg|]\}}t|t�s|�qSr�rArB)rr r�rrrr!�s��z1_annotatecontext._doappendrev.<locals>.<listcomp>rcs*g|]\}}t|t�r
|n�||f�qSrr�r�)�
siderevmaprrr!�s��)r��remover�r�rr��replacelines�replacelines_vec)rrr-r8r�r��siderevsr9r:r;r<�opr r��blinesr)rr�rr��s6

��


��z_annotatecontext._doappendrevcs.�dur�j���fdd���fdd�|D�S)z6(revmap, [(node, linenum)]) -> [(node, linenum, path)]Ncs2�j�|�}|dur����|��}|�j|<|Sr)rvr^r�r�)�nodeidr)rr_rr�_getpath�s

z3_annotatecontext._addpathtoresult.<locals>._getpathcsg|]\}}||�|�f�qSrr)r�nr�)r�rrr!�sz5_annotatecontext._addpathtoresult.<locals>.<listcomp>r�)r_r�rr)r�rr_rr��sz!_annotatecontext._addpathtoresultcCsB|durd}n|j�|���}|st���|jj|krt���dS)z:check if fctx is the master's head last time, raise if notNr)rr�r�r��CannotReuseErrorrr�)r_r-r�rrrr��s�z%_annotatecontext._checklastmasterheadcs"|jj�|jj���fdd�}|S)z-> (fctx) -> [fctx]cs t|�d�}�s|dd�}|S)N)r'r)r))r r(�rfrerrr$�sz-_annotatecontext._parentfunc.<locals>.parents)r`rerf)r_r$rr�rr��sz_annotatecontext._parentfunccCs|j�dd�S)N�fastannotatesperfhack)rq�
configboolrrrrr�sz_annotatecontext._perfhackcKst|j||p|jfi|��Sr)rLrr)r_rDr�kwdsrrrr�sz_annotatecontext._resolvefctx�T)NFF)FFr)rkrlrmrnrb�propertyrrr��__del__r�r�r�r�r�r�r�r�r�r�r��staticmethodr�r�r�rror�r�r�rrrrrp�s>

	


#C
8A

1

rpc	Cs.|D]}zt�|�WqtyYqwdS)zsilent, best-effort unlinkN)r�unlink�OSError)�pathsrrrrr�
s��r�c@sHeZdZdZefdd�Zedd��Zedd��Zdd	�Z	ed
d��Z
dS)
�
pathhelperz9helper for getting paths for lockfile, linelog and revmapcCs"tj�d|jt|��|_||_dS)Nr�)rwr�joinrjrN�_vfspathr&)r_rrr`rrrrbs�
zpathhelper.__init__cCstj�|jj�|j��Sr)rwr�dirnamer&�vfsr
rrrrrrszpathhelper.dirnamecC�|jj�|jd�S)Ns.l�r&r
r
rrrrrrr!�zpathhelper.linelogpathcCst�|jj|jd�S)Ns.lock)�lockmodrr&r
rrrrrr%szpathhelper.lockcCr)Ns.mrrrrrrs(rzpathhelper.revmappathN)rkrlrmrn�defaultoptsrbrrrrrrsrrrrr	s

r	ccs��t|||�}t�|j�|j}|j}d}zMz'|���t|||||�}|r*|��|VWd�n1s7wYWnt	yU|durL|��|j
�d|��wW|dura|��dSdS|durl|��ww)acontext needed to perform (fast) annotate on a file

    an annotatecontext of a single file consists of two structures: the
    linelog and the revmap. this function takes care of locking. only 1
    process is allowed to write that file's linelog and revmap at a time.

    when something goes wrong, this function will assume the linelog and the
    revmap are in a bad state, and remove them from disk.

    use this function in the following way:

        with annotatecontext(...) as actx:
            actx. ....
    Ns+fastannotate: %s: cache broken and deleted
)
r	r�makedirsrrsrrrrpr��	Exceptionrqr�r�)rrr`r��helperrsrr�actxrrr�annotatecontext-s4�
�����
�rcCs:|j}|j}|j�ddd�rd}t||d�}t||||�S)zdlike annotatecontext but get the context from a fctx. convenient when
    used in fctx.annotate
    r�sforcefollowT)rQre)r&�_pathrqrr[r)r-r'rQr�rr�aoptsrrr�fctxannotatecontextRsrr)FN)TNF)4�
__future__rr��
contextlibrw�mercurial.i18nr�mercurial.pycompatrrr�mercurial.noderrr	�	mercurialr
rryrrr
rrr�mercurial.utilsrr�r�rr~�lrucachefuncrr)r4r>�	revsinglerCrLrNrZrrg�objectr[rpr�r	�contextmanagerrrrrrr�<module>s@$	


-	
"F	$

https://t.me/RX1948 - 2025