403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib64/python3.9/site-packages/hgext/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib64/python3.9/site-packages/hgext/__pycache__/phabricator.cpython-39.opt-1.pyc
a

�+�b�B�@s&dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z/m0Z0dd	l1m2Z2m3Z3m4Z4d
dl5m6Z6dZ7e��Z8e8j9Z9e8j:Z:e8j;Z;e8j<Z<e8j=Z>e8j?d
ddd�e8j?d
ddd�e8j?d
ddd�e8j?d
ddd�e8j?d
ddd�e8j?d
ddd�e8j?d
dd
d�e8j?d
ddd�e8j?dddd�e8j?dddd�e8j?dddd�dddd d!d"dd#d$d$d%�
Z@d&d'd&ed(�fgZAe8�Bed)�d*d+��ZCd�d,d-�ZDd.d/�ZEd0d1�ZFd2d3�ZGd4d5�ZHeDd6ged7�d8d9�d:d;��ZId<d=�ZJe
�Kd>�ZLe
�Kd?e
jM�ZNd@dA�ZOdBdC�ZPdDdE�ZQGdFdG�dGeR�ZSGdHdI�dIeR�ZTejUGdJdK�dKeV��ZWejUGdLdM�dMeR��ZXejUGdNdO�dOeR��ZYdPdQ�ZZdRdS�Z[dTdU�Z\dVdW�Z]dXdY�Z^dZd[d\d]�Z_d^d_�Z`d`da�Zadbdc�Zbddde�Zcdfdg�Zddhdi�Zed�djdk�Zfdldm�Zgdndo�Zhdpdq�ZieDddrdsgedt�edu�fd&dvd8edw�fd&dxgedy�fd&dzged{�fd|d}d&ed~�fd&dded�fd&d�ded��fged��e:jjd��d�d���Zke0�lgd���Zmd�d��Znhd��Zod�d��Zpd�d�d�d�d�d�d�d�d��Zqd�d��Zrd�d��Zsd�d��Ztd�d��Zud�d��Zvd�d��Zwd�d��Zxd�d��Zyd�d��Zzd�d��Z{d�d��Z|eDd�d&d�ded��fged��e:jjd8d��d�d���Z}eDdd&d�ded��fged��e:jjd��d�d���Z~eDd�d&d�ded��fd&d�ded��fd&d�ded��fd&d�ded��fd&d�ded��fd&d�ded��fd&d�dedƒfd&d�dedăfd&d�dedƃfd&d�dedȃfd|d}d&edɃfdrdsd&edʃedu�fged˃e:jjd8d��d�d̈́�Ze8j<d�d�hdЍd�d҄�Z�e8j<d�hdԣdЍd�dք�Z�e6j�d�d�d؍d�dڄ�Z�dS)�asimple Phabricator integration (EXPERIMENTAL)

This extension provides a ``phabsend`` command which sends a stack of
changesets to Phabricator, and a ``phabread`` command which prints a stack of
revisions in a format suitable for :hg:`import`, and a ``phabupdate`` command
to update statuses in batch.

A "phabstatus" view for :hg:`show` is also provided; it displays status
information of Phabricator differentials associated with unfinished
changesets.

By default, Phabricator requires ``Test Plan`` which might prevent some
changeset from being sent. The requirement could be disabled by changing
``differential.require-test-plan-field`` config server side.

Config::

    [phabricator]
    # Phabricator URL
    url = https://phab.example.com/

    # Repo callsign. If a repo has a URL https://$HOST/diffusion/FOO, then its
    # callsign is "FOO".
    callsign = FOO

    # curl command to use. If not set (default), use builtin HTTP library to
    # communicate. If set, use the specified curl command. This could be useful
    # if you need to specify advanced options that is not easily supported by
    # the internal library.
    curlcmd = curl --connect-timeout 2 --retry 3 --silent

    # retry failed command N time (default 0). Useful when using the extension
    # over flakly connection.
    #
    # We wait `retry.interval` between each retry, in seconds.
    # (default 1 second).
    retry = 3
    retry.interval = 10

    # the retry option can combine well with the http.timeout one.
    #
    # For example to give up on http request after 20 seconds:
    [http]
    timeout=20

    [auth]
    example.schemes = https
    example.prefix = phab.example.com

    # API token. Get it from https://$HOST/conduit/login/
    example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
�)�absolute_importN)�bin�short)�_)�getattr)�attr)�cmdutil�context�copies�encoding�error�	exthelper�graphmod�httpconnection�	localrepo�
logcmdutil�match�mdiff�obsutil�parser�patch�phases�pycompat�rewriteutil�scmutil�smartset�tags�templatefilters�templateutil�url�util)�procutil�
stringutil�urlutil�)�showsships-with-hg-core�phabricator�	batchsize���default�callsign�curlcmd�debugF�repophid�retry�retry.interval�url�phabsend�confirm�
phabimport�secret�obsoletesgreensmagentasboldsmagenta dims
green boldsyellowsred)
sphabricator.action.createdsphabricator.action.skippedsphabricator.action.updated�phabricator.drevsphabricator.status.abandonedsphabricator.status.acceptedsphabricator.status.closedsphabricator.status.needsreviews phabricator.status.needsrevisions!phabricator.status.changesplanned�stest-vcrs�Path to a vcr file. If nonexistent, will record a new vcr transcript, otherwise will mock all http requests using the specified vcr file. (ADVANCED)Zloadhgrcc	Os�d}i}z.t�|�d��}	t�dd�t�|	��}d}Wn:ty`|�td�|�	d��Ynt
ypYn0t��}
d|vr�|d|
d<d	|vr�|d	|
d
<|
r�|j
|
|�	d�d�|||||g|�Ri|��p�|S)zBLoad ``.arcconfig`` content into a ui instance on repository open.Fs
.arcconfigcSst|tj�rt�|�S|S�N��
isinstancerZunicoder�
unitolocal��x�r?�7/usr/lib64/python3.9/site-packages/hgext/phabricator.py�<lambda>�s
�z_loadhgrc.<locals>.<lambda>Tsinvalid JSON in %s
srepository.callsign)r&r+sphabricator.uri�r&r1)�source)r�unifromlocal�readr�rapply�
json_loads�
ValueError�warnr�join�IOErrorr �sortdictZapplyconfig)Zorig�uiZwdirvfsZhgvfsZrequirements�args�opts�resultZ	arcconfig�	rawparamsZcfgr?r?r@�	_loadhgrc�s,��rRcs>|t�dd��dd��dd����������fdd�}|S)	NcSs�|j|jks|j|jkrdStj�|j�}tj�|j�}|D]t}||vrNdS||d}|�d�r�|�d�r�t�	|�}t�	||d�}||kr�dSq<||d|kr<dSq<dS)NFr�{�}T)
�uri�methodr �urlreqZparseqs�body�
startswith�endswithrrG)Zr1Zr2Zr1paramsZr2params�key�valueZr1jsonZr2jsonr?r?r@�	hgmatcher�s 
zvcrcommand.<locals>.hgmatchercSst�dd|j�|_|S)Ns
cli-[a-z0-9]+scli-hahayouwish)�re�subrX)�requestr?r?r@�sanitiserequests�z#vcrcommand.<locals>.sanitiserequestcSsd|dvr|dd=|S)Nz
set-cookieZheadersr?)Zresponser?r?r@�sanitiseresponses
z$vcrcommand.<locals>.sanitiseresponsecsF����fdd�}tj|dd�}�j|_�j|_t�����d�|�S)Nc	s�|�d�}|r�t�|�}ddl}|����ddl}ddlm}|jd��t	d|j
ft	d|jfgd�}|�d��|j
|dgd��,�|i|��Wd�Wd�S1s�0YWd�n1s�0Y�|i|��S)	NZtest_vcrr�jsonrZhttpsconnection)Z
serializerZbefore_record_requestZbefore_record_responseZcustom_patchesr])Zmatch_on)�popr�fsdecode�hgdemandimportZdeactivated�vcrZ	vcr.stubs�stubsZVCR�urlmodZVCRHTTPConnectionZVCRHTTPSConnectionZregister_matcherZuse_cassette)rN�kwargsrgZcassetterfZvcrmodrh)�fnr]rarbr?r@�inners2


����Xz+vcrcommand.<locals>.decorate.<locals>.inner�)�depth��helpcategory�optionalrepo)r Zchecksignature�__name__�__doc__�command)rkrl�cmd�Z	fullflagsrpr]�namerqrarb�spec)rkr@�decorates ��zvcrcommand.<locals>.decorate)�
_VCR_FLAGS)rw�flagsrxrprqryr?rvr@�
vcrcommand�s-r|cOs@|�dd�r<|j}z d|_|j|i|��W||_n||_0dS)z�write debug output for Phabricator if ``phabricator.debug`` is set

    Specifically, this avoids dumping Conduit and HTTP auth chatter that is
    printed with the --debug argument.
    r&r-TN)�
configboolZ	debugflag�write)rM�msgrO�flagr?r?r@�_debugKsr�cs,t�����fdd���d|�tj���S)alike urlencode, but works with nested parameters.

    For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be
    flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
    urlencode. Note: the encoding is consistent with PHP's http_build_query.
    cs�t|t�rddd�|}dd�}t|tdd�i�t|��}|durL|�|<n4||�D]*\}}|rt�d||f|�qT�||�qTdS)Nstruesfalse)TFcSsdd�t|�D�S)NcSsg|]\}}d||f�qS)�%dr?)�.0�k�vr?r?r@�
<listcomp>fr8zFurlencodenested.<locals>.process.<locals>.<lambda>.<locals>.<listcomp>)�	enumerate)�lr?r?r@rAfr8z2urlencodenested.<locals>.process.<locals>.<lambda>cSs|��Sr9)�itemsr=r?r?r@rAgr8s%s[%s])r;�bool�list�dict�get�type)�prefix�objZlisterr�r�r��Z
flatparams�processr?r@r�cs

z urlencodenested.<locals>.processr8)r rLr#rW�	urlencode)�paramsr?r�r@�urlencodenestedZs
r�cCs�|�dd�}|s"t�td�d��t�||t�|�j�}d}|r`|\}}|�	d|�|�
d�}|sxt�td�|f��||fS)	z�return conduit url, token and make sure they exist

    Currently read from [auth] config section. In the future, it might
    make sense to read from .arcconfig and .arcrc as well.
    r&r1sconfig %s.%s is requiredrBNs#using auth.%s.* for authentication
s	phabtokens)Can't find conduit token associated to %s)�configr�Abortr�httpconnectionmodZreadauthforurir#r�user�debugr�)rMr�res�token�groupZauthr?r?r@�readurltokenus 
�
�r�cCst|�\}}t�d�|d|g����\}}|�d|t�|�f�|��}d|i|d<t	�
|�ddd�}t|�}|�d	d
�}	|	r�t
�d|	t
�|�f�\}
}|
�|�|
��|��}�nt�||�}
tjjt�|�|d�}|�d	d
�d}|�tdd�}t|�D]�}zJt�|
j||d���}|��}Wd�n1�s<0YW�q�Wnhtj j!�y�}zJ||dk�rv�|�d|d||f�|�d	d�}t"�#|�WYd}~n
d}~00�q|�d|�t�$dd�t�%t&�'|���}|�(d��rt)d�|d|df}t*�+|��|dS)zEcall Conduit API, params is a dict. return json.loads result, or None�/sapisConduit Call: %s %s
stoken�__conduit__sjsonr$)sparamssoutputr�r&r,s%s -d @- %s)�datar/shttpstimeout)�timeoutNs'Conduit Request failed (try %d/%d): %r
r0sConduit Response: %s
cSst|tj�rt�|�S|Sr9r:r=r?r?r@rA�s
�zcallconduit.<locals>.<lambda>s
error_codesConduit Error (%s): %ss
error_infosresult),r�r#rrJ�authinfor�rZbyterepr�copyrrcr�r�r!Zpopen2Z
shellquoter~�closerEri�openerr rWr`Zstrurl�	configintZ
configwith�float�range�
contextlib�closing�open�urlerr�urlerror�time�sleeprFrGrrDr�rrr�)rMrwr��hostr�rr�Zrawdatar�ZcurlcmdZsinZsoutrXZ	urlopenerr`Zmax_tryr�Z	try_countZrsp�errZretry_interval�parsedrr?r?r@�callconduit�sj���
�(��$��
r�sdebugcallconduitsMETHODT)rqcCsht�|j���}t�dd�t�|��}t�dd�t|||��}tj	|dddd�}|�
dt�|��d	S)
z�call Conduit API

    Call parameters are read from stdin as a JSON blob. Result will be written
    to stdout as a JSON blob.
    cSst|tj�rt�|�S|Sr9r:r=r?r?r@rA�s
�z"debugcallconduit.<locals>.<lambda>cSst|t�rt�|�S|Sr9)r;�bytesrrDr=r?r?r@rA�r8Trm)�,z: )Z	sort_keys�indentZ
separatorss%s
N)rrDZfinrErrFrGr�rc�dumpsr~r<)rM�reporwrQr�rP�sr?r?r@�debugcallconduit�s�
�r�cCs||j�dd�}|r|S|j�dd�}|s,dSt|jddd|gii�}t|d�d	krXdS|dd	d
}|j�dd|�|S)z.given callsign, return repository PHID or Noner&r.r+Nsdiffusion.repository.search�constraintss	callsigns�datar�phid)rMr�r��len�	setconfig)r��repophidZcallsign�queryr?r?r@�getrepophid�s �r�s\AD([1-9][0-9]*)\Zs>^Differential Revision:\s*(?P<url>(?:.*)D(?P<id>[1-9][0-9]*))$c
s|��}|jjj}i}t��}|D]�}||}tt�|j	|g��}|D]P}	||	�rF|�
|	�D]2}
t�|
�}|r\dt
|�t|�d��f||<q�q\qFq"qFt�|���}|r"dt
|�t|�d��f||<q"|�rdd�|��D�}t|jdd|i�}
dd	��|��D�]\}\}���fd
d�|
��D�}��fdd�|D�}|�s�|�s�d
�}tj|||jddddd�|j�td����qd}}|�rt|dd�d�}�|��}t|jdt|�t� dd�t!|�D��f�t"|�dk�r�|d}|�r||��sd}||�f||<�q|S)a�find previous nodes that has been sent to Phabricator

    return {node: (oldnode, Differential diff, Differential Revision ID)}
    for node in nodelist with known previous sent versions, or associated
    Differential Revision IDs. ``oldnode`` and ``Differential diff`` could
    be ``None``.

    Examines commit messages like "Differential Revision:" to get the
    association information.

    If such commit message line is not found, examines all precursors and their
    tags. Tags with format like "D1234" are considered a match and the node
    with that tag, and the number after "D" (ex. 1234) will be returned.

    The ``old node``, if not None, is guaranteed to be the last diff of
    corresponding Differential Revision, and exist in the repo.
    rr$�idcSsg|]\}}}|�qSr?r?)r��forceZprecs�drevr?r?r@r�4r8z%getoldnodedrevmap.<locals>.<listcomp>�differential.querydiffssrevisionIDscs�fdd�t|�D�S)Ncsg|]}|�vr|�qSr?r?�r��n��precsetr?r@r�<r8z7getoldnodedrevmap.<locals>.getnodes.<locals>.<listcomp>)�getlocalcommits)�dr�r?r�r@�getnodes9sz#getoldnodedrevmap.<locals>.getnodescs g|]}t|d��kr|�qS)s
revisionID��int�r�r��r�r?r@r�?scs h|]}�|��D]}|�qqSr?r?)r�r�r�)r�r�r?r@�	<setcomp>Dr8z$getoldnodedrevmap.<locals>.<setcomp>�D%dNT��messager��date�locals=D%d: local tag removed - does not match Differential history
cSst|d�S)N�idr�)r�r?r?r@rA`r8z#getoldnodedrevmap.<locals>.<lambda>)r[s%s mapped to old nodes %s
cSsg|]}t|��qSr?�rr�r?r?r@r�hr8)#�
unfilteredZ	changelog�index�has_noder rLr�rZallpredecessorsZobsstore�nodetags�_differentialrevisiontagrer�setr�r��_differentialrevisiondescre�search�description�valuesr�rMr�r�tag�nullidrIr�maxr�rr"�pprint�sortedr�)r�Znodelist�unfir�rPZ	toconfirm�node�ctxZ	precnodesr�r��m�drevsZalldiffs�newnoder��diffsZ	phprecset�tagname�oldnodeZlastdiffZoldnodesr?)r�r�r�r@�getoldnodedrevmaps�

�
��	���
���r�cCs�i}|D]r}d||<||}t�|���}|rBt|�d��||<q|�|���D](}t�|�}|rPt|�d��||<qqPq|S)z\Return a dict mapping each rev in `revs` to their Differential Revision
    ID or None.
    Nr�r$)	r�r�r�r�r�r�r�r�r)r��revsrP�revr�r�r�r?r?r@�
getdrevmap�s
r�cCsHt��}tj|��|����|��d|d�D]\}}|�|�q,|��S)z:plain-text diff without header (user, commit message, etc)N�rO)	r ZstringiorZdiffuir��p1r�r~�getvalue)�basectxr��diffopts�output�chunkZ_labelr?r?r@�getdiff�s�r�c@s,eZdZdZdZdZdZdZdZdZ	dZ
d	S)
�DiffChangeTyper$rm������N)rr�
__module__�__qualname__�ADD�CHANGE�DELETE�	MOVE_AWAY�	COPY_AWAY�	MOVE_HERE�	COPY_HERE�	MULTICOPYr?r?r?r@r��sr�c@seZdZdZdZdZdS)�DiffFileTyper$rmrN)rrrr�TEXT�IMAGE�BINARYr?r?r?r@r�src@sdeZdZdZejdd�Zejdd�Zejdd�Zejdd�Z	ejdd�Z
ejdd�Zejdd�ZdS)�phabhunkzGRepresents a Differential hunk, which is owned by a Differential changerr)�N)
rrrrrsr�ib�	oldOffset�	oldLength�	newOffset�	newLength�corpus�addLines�delLinesr?r?r?r@r�src@s�eZdZdZejdd�Zejdd�Zeje�e	�d�Z
eje�e�d�Zeje�e�d�Z
eje�e�d�Zejejd�Zejejd�Zejdd�Zejdd�Zejdd�Zeje�e	�d�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�
phabchangez�Represents a Differential change, owns Differential hunks and owned by a
    Differential diff.  Each one represents one file in a diff.
    Nr)rcCs4t|j���D] }|�dd�}|j||j|<qdS)Nsnew:sold:)r��metadata�keys�replace)�selfr[Znewkeyr?r?r@�copynewmetadatatoold�szphabchange.copynewmetadatatooldcCs||jd<dS�Ns
unix:filemode)�
oldProperties�r"r\r?r?r@�
addoldmode�szphabchange.addoldmodecCs||jd<dSr$)�
newPropertiesr&r?r?r@�
addnewmode�szphabchange.addnewmodecCsPt|t�st�d��|j�t�t�	|���|j
|j
7_
|j|j7_dS)Ns'phabchange.addhunk only takes phabhunks)r;rrr��hunks�appendr�byteskwargsr�asdictrr)r"Zhunkr?r?r@�addhunk�s


zphabchange.addhunk)rrrrrsrr�currentPath�oldPath�Factoryr��	awayPathsr�rr%r(r�r	r�rr�fileTypeZ
commitHashrrr*r#r'r)r.r?r?r?r@r�s"rc@s�eZdZdZejdd�Zejdd�Zejdd�Zejdd�Z	ejdd�Z
ejdd�Zejdd�Zejd	d�Z
ejd
d�Zejd
d�Zeje�e�d�Zejdd�Zdd�ZdS)
�phabdiffz]Represents a Differential diff, owns Differential changes.  Corresponds
    to a commit.
    r8r)r�s(0000000000000000000000000000000000000000shgsdefaultNr2snonecCs0t|t�st�d��t�t�|��|j|j	<dS)Ns)phabdiff.addchange only takes phabchanges)
r;rrr�rr,rr-�changesr/)r"Zchanger?r?r@�	addchanges


�zphabdiff.addchange)rrrrrsrrZ
sourceMachineZ
sourcePath�sourceControlBaseRevisionZsourceControlPathZsourceControlSystem�branchZbookmarkZcreationMethodZ
lintStatusZ
unitStatusr1r�r5�repositoryPHIDr6r?r?r?r@r4�sr4cCs�|��}t�|g�}tjddd�}ttj||��|||d��\}}}	}
|
D]r}|\\}}
}}}d�	|dd��}t
|	�}|�|�t�t�
t�|���\}}}}}|�t||
|||||��qJdS)z'populate the phabchange for a text fileT���gitr	r�r8r$N)r�r�exactrr��nextrZ	diffhunksr�rJr��extendZdiffstatsumZdiffstatdatar Z	iterlinesr.r)�pchanger�r��fnamer�Zfmatcherr�Z_pfctxZ_fctx�headerZfhunksZfhunkrrrr�linesrZshunkZ_mfZ_mtrrZ_hbr?r?r@�maketext	s2�
���rDcCs�|��j}t|dd|i�}|jtd�td�t|�d��l}|D]V}|��|drRq<t|d�}t|d�}t|d	||t�	|�
�||��d
d��q<Wd�n1s�0YdS)
ztupload large binary files as separate chunks.
    Phab requests chunking over 8MiB, and splits into 4MiB chunks
    sfile.querychunks�filePHIDsuploading file chunksschunks)Zunit�totalscomplete�	byteStartsbyteEndsfile.uploadchunksbase64)rErGr�sdataEncodingN)r�rMr�Zmakeprogressrr�Z	incrementr��base64�	b64encoder�)�fctx�fphidrM�chunksZprogressr�ZbstartZbendr?r?r@�uploadchunks's*
���rMc
Cs�|��}|j}|��}|��}t�t�|����	��}|||d�}t
|d|�}|d}|dr�|�td�t
|��|s�|t�|���d�}	t
|d|	�}q�t||�n|�dt
|��|s�t�d	t
|���|S)
z"upload binary files to Phabricator)�names
contentLengthscontentHashs
file.allocaterEsuploads
uploading %s
)rNsdata_base64sfile.uploadsserver already has %s
sUpload of %s failed.)r�rM�path�sizer�bytestr�hashlibZsha256r��	hexdigestr�r~rr�rHrIrMr�rr�)
rJr�rMrArPZfhashZallocateparamsZ	fileallocrKZuploadparamsr?r?r@�
uploadfileBs.��rTcCsp|r|�|�r\|��|jd<t�t�|����\}}|rHt�	|�|jd<t
|�}||jd<ntj|_
|��dS)z�add the metadata for the previous version of a binary file to the
    phabchange for the new version

    ``oldfctx`` is the previous version of the file; ``fctx`` is the new
    version of the file, or None if the file is being removed.
    s
old:file:sizesold:file:mime-typesold:binary-phidN)�cmprPr�	mimetypes�
guess_typerrDrOrrQrTrrr3r#)r@�oldfctxrJ�	mimeguess�_encrKr?r?r@�addoldbinarygs��
r[cCsntj|_t|�}||jd<|��|jd<t�t�	|�
���\}}|rjt�|�}||jd<|�
d�rjtj|_dS)z)populate the phabchange for a binary filesnew:binary-phids
new:file:sizesnew:file:mime-typesimage/N)rrr3rTrrPrVrWrrDrOrrQrYr)r@rJrKrYrZr?r?r@�
makebinary�s



r\s120000s100755s100644)�l�xr8cCsJz|���d�WdStyD|��j�td�|���YdS0dS)z[detect non-UTF-8 text files since Phabricator requires them to be marked
    as binary
    zutf-8Fs0file %s detected as non-UTF-8, marked as binary
TN)r��decode�UnicodeDecodeErrorr�rMr~rrO)rJr?r?r@�notutf8�s
��racCsd|D]Z}t||tjd�}|��|}|�t|���|��sTt|�sTt	||||�|�
|�qdS)z:add removed files to the phabdiff. Shouldn't include moves)r/r0r�N)rr�r
r�r'�gitmoder{�isbinaryrarDr6)�pdiffr�r��removedrAr@rXr?r?r@�
addremoved�s�rfc
Cs�|D]�}||}|��|}t||d�}t|��}t|��}	||	kr\|�|	�|�|�|��s|t|�s||��s|t|�r�t||�t	|||�nt
||||�|�|�qdS)z"add modified files to the phabdiff)r/r0N)r�rrbr{r'r)rcrar\r[rDr6)
rdr�r��modifiedrArJrXr@�filemode�originalmoder?r?r@�addmodified�s*

����
rjcCs,i}i}i}||kr$t�|��|�}|D�]�}||}	d}
t|d�}t|	��}|rb|�||�}
n|}
|	��rz|	��d}
||
k}|�rl|��|
}
t|
��}|
|_|
|vr�t|
|
t	j
|gd�}|||
<|�|
�t	j|_
nn|
|v�rt	j||
_
||
j�|�t	j|_
n>|
|v�r0t|
t	jd�}|||
<n||
}|j�|�t	j|_
||k�r�|�|�|�|�n|�t|	���t	j|_
|	���s�t|	��s�|
�r�|
���s�t|
��r�t||	�|�r�t||
|	�nt||||�|�|�q(|��D]\}}|�|��q�|��D]\}}|�|��qdS)z>add file adds to the phabdiff, both new files and copies/movesN)r/r)r/r0r�r2)r/r�)r
Z
pathcopiesr�rrbr{r��renamedr0r�r�remover
r�rr2r+rrr'r)rrcrar\r[rDr6r�)rdr�r��addedreZ
copiedchangesZmovedchangesr�rArJrXr@rhZ
originalfnamerkriZorigpchange�_pathZcopiedchangeZmovedchanger?r?r@�addadded�s�

�




�


�����
rocCs�|��}t|�}td|����d|��d�}|���|�\}}}}}	}
}t|||||�t||||�t	||||�|r�||_
t|jdt
�t�|���}|s�||kr�td�||f}
ntd�|}
t�|
��|S)zcreate a Differential Diffs%s)r7r8sdifferential.creatediffscannot create diff for %s::%sscannot create diff for %s)r�r�r4r��hexr8�statusrorjrfr9r�rMrr,rr-rrr�)r�r�r�r�rdrgrmreZ_dZ_uZ_iZ_c�diffrr?r?r@�
creatediffs.
��
rsc
Cs�|�d|�d��}|d}|d}|dt�|��d|��|��|��|����d��d�}t|�	�j
d	|�i}|D]P}t�|���t�
|���t|��d�|��|����g|��d
�||��<qv|dt�|�d�}t|�	�j
d	|�dS)
z�write metadata to diff so patches could be applied losslessly

    ``ctxs`` is the list of commits that created the diff, in ascending order.
    The list is generally a single commit, but may be several when using
    ``phabsend --fold``.
    sdiffidr�r����hg:metas%d %d)�user�date�branch�node�parent)sdiff_idrNr�sdifferential.setdiffproperty)�author�authorEmail�time�commit�parentsrx�
local:commitsN)r�rrcr�r�r8rpr�r�r�rMr"ZpersonZemailr�)�ctxsrr�diffidr�Ztipctxr��commitsr�r?r?r@�writediffproperties;s:

���
�	�r�c	Cs|d}|d}	|��}
|r\tjddd�}|
��}||}
||}t|	||�t||
|�k}nd}g}|r�t|	|�}|�d|dd��|r�|�d	|d��n|}t||�|r�|�d
|gd��|r�||7}t�	�}t
|�D]�\}}|��}t|
j
dd|i�}d
D]j}|d�|�}|�s�q|dk�r:|��||<�qn|dk�rHd}d�td|�|�|��g��||<�qq�|��D]\}}|�||d���qxd|i}|du�r�||d<t|
j
d|�}|�s�t|�dk�r�td�|}ntd�|	|f}t�|��||fS)a�create or update a Differential Revision

    If revid is None, create a new Differential Revision, otherwise update
    revid. If parentrevphid is not None, set it as a dependency.

    If there is a single commit for the new Differential Revision, ``ctxs`` will
    be a list of that single context.  Otherwise, it is a list that covers the
    range of changes for the differential, where ``ctxs[0]`` is the first change
    to include and ``ctxs[-1]`` is the last.

    If oldnode is not None, check if the patch content (without commit message
    and metadata) has changed before creating another diff.  For a Revision with
    a single commit, ``oldbasenode`` and ``oldnode`` have the same value.  For a
    Revision covering multiple commits, ``oldbasenode`` corresponds to
    ``ctxs[0]`` the previous time this Revision was posted, and ``oldnode``
    corresponds to ``ctxs[-1]``.

    If actions is not None, they will be appended to the transaction.
    rtrTr:r;supdater��stypesvalue�commentsparents.setsdifferential.parsecommitmessagescorpus)�title�summary�testPlan�fieldsr�r��

N�transactions�objectIdentifier�differential.revision.editr$scannot create revision for %ss!cannot create revision for %s::%s)r�rr�r�r�rsr+r�r rLr�r�r�rMr��rstriprJ�filterr�r�rrr�)r��revidZ
parentrevphid�oldbasenoder��olddiff�actionsZcommentr�r�r�r�r�ZoldctxZ
oldbasectxZneednewdiff�transactionsrr�fields�iZ_ctx�desc�infor�r�r��revisionrr?r?r@�createdifferentialrevisionhsl�


�	�

(

r�cCsvdd�|D�}dd|ii}t|d|�}|d}dd�|D�}t|�|}|rht�td	�d
�t|����dd�|D�S)zconvert user names to PHIDscSsg|]}|���qSr?��lower)r�rwr?r?r@r��r8zuserphids.<locals>.<listcomp>r�s	usernamessuser.searchr�cSsh|]}|dd���qS)r�susernamer��r��entryr?r?r@r��r8zuserphids.<locals>.<setcomp>sunknown username: %s� cSsg|]}|d�qS)r�r?r�r?r?r@r��r8)r�r�rr�rrJr�)rM�namesr�rPr�ZresolvedZ
unresolvedr?r?r@�	userphids�s�r�cCsb|�td�td�td�d�|d|�}|�d|d�}t�||d�}|�td	�|||f�d
S)z�print the ``action`` that occurred when posting ``ctx`` for review

    This is a utility function for the sending phase of ``phabsend``, which
    makes it easier to show a status for all local commits with `--fold``.
    �created�skipped�updated)r�r�r�sphabricator.action.%sr�r7r2s
%s - %s - %s
N)�labelrr�format_changeset_summaryr~)rMr��newrevid�actionZ
actiondesc�drevdesc�summaryr?r?r@�_print_phabsend_action�s���r�csht�jdt�dd�|D���zt�fdd�|D�|�Wn&tjjyb�j�d|�Yn0dS)z�update the local commit list for the ``diff`` associated with ``drevid``

    This is a utility function for the amend phase of ``phabsend``, which
    converts failures to warning messages.
    snew commits: %s
cSsg|]}t|��qSr?r�r�r?r?r@r�r8z*_amend_diff_properties.<locals>.<listcomp>csg|]}�|�qSr?r?)r�r��r�r?r@r�r8s"Failed to update metadata for D%d
N)	r�rMr"r�r�r r�r�Z
warnnoi18n)r��drevid�newnodesrrr?r�r@�_amend_diff_propertiess�r��r�revsrevisions to sendsREV�amendsupdate commit messages�reviewersspecify reviewers�blockersspecify blocking reviewers�mr�s1add a comment to Revisions with new/updated Diffss#ask for confirmation before sending�folds%combine the revisions into one reviews
REV [OPTIONS])rpc1
s t�|�}t|�|�dg�}t��|�}|��|sDt�t	d���|�d�rXt
����fdd�|D�}tdd�|D��r�t�t	d����fd	d
�}��
d|�}t|�dkr�||d
���
d|�}t|�dkr�||d�|�d�}|�rTt|�dk�rt�t	d���|�d��s t�t	d���dd�|D�}	tdd�|	D��dk�rTt�t	d���t��fdd�|D��}
|�dd�}|t|�d��O}|�r�t�||
�}|�s�t�t	d���g}
|�dg�}|�dg�}g}|�r�|�t�j|��|�r
|�tdd�t�j|���|�r |
�d|d ��g}i}d!}|D�]�}|�r\|�d"|��|d#��f�n|�d$|���|
�|��d%�\}}}|||}}}|�r�|
�|d#��d%�\}}}||��k�s�|�d��r�t|�r�|n|g||||||
|�d&��\}}|�r|D]}|||��<�qn|||��<t|d'd(�}|d'd)}|�rNd*}nd+}|�s�t�|���} | �r�t| � d,��|k�r�d-|}!t!j"�|!|��d!d!d!d.d/�n t#�jd0|�d1d)}|}d2}|�|�|}|�r|D]4}"|
�|"��d%�d3�r�d*}nd+}t$||"||��q��q,t$||||��q0|�d��r��%�}#t&|d4d5|i�}$��'������(������)d���Vd6d���*d7||�D�}%|#d8��}&i}'g}(|d1�t+|�D�]�\})}*|#|*}+|�s�||)��fd9d�|$D�d1},t,|,|+|�}-|+��|-k�s&|+�-���|'v�s&|+�.���|'v�r4|+�/�t0j1k�rR|�2t	d:�t3�4|+���q�|'�|+�-���|+�-�f�d1|'�|+�.���|+�.�f�d1g}.t5�6�|-|'�}-t7j8�|+|.|-|+�9�|+�:�|+�;�d;�}/|/�<�}0|0g|'|+��<|�r�|(�|0��q�t=|#�|0g||+���d-�}!|!��!�v�rHt!j"�|!�j>d!d!d!d.d/�n|�r�|(�|+����q�|�r�|(�r�||+��}|�r|t*|(�t?|�k�r�t@|d<��t=|#�|(|�nt@|d=��n|�r�t@|d>�|%D]�}+|'�|+�-���|+�-�f�d1|'�|+�.���|+�.�f�d1g}.t7j8�|+|.t5�6�|+��|'�|+�9�|+�:�|+�;�d;�}/|/�<�}0|0|+��k�rt|0g|'|+��<t@|d?tA|+���tA|0�f�nt@|d@tA|+�����q�t3jB�|'dd.dA�|&|'v�r�|#�C|'|&d1�Wd!�n1�s�0YWd!�n1�s�0YWd!�n1�s0Yd!S)Ba�upload changesets to Phabricator

    If there are multiple revisions specified, they will be send as a stack
    with a linear dependencies relationship using the order specified by the
    revset.

    For the first time uploading changesets, local tags will be created to
    maintain the association. After the first time, phabsend will check
    obsstore and tags information so it can figure out whether to update an
    existing Differential Revision, or create a new one.

    If --amend is set, update commit messages so they have the
    ``Differential Revision`` URL, remove related tags. This is similar to what
    arcanist will do, and is more desired in author-push workflows. Otherwise,
    use local tags to record the ``Differential Revision`` association.

    The --confirm option lets you confirm changesets before sending them. You
    can also add following to your configuration file to make it default
    behaviour::

        [phabsend]
        confirm = true

    By default, a separate review will be created for each commit that is
    selected, and will have the same parent/child relationship in Phabricator.
    If ``--fold`` is set, multiple commits are rolled up into a single review
    as if diffed from the parent of the first revision to the last.  The commit
    messages are concatenated in the summary field on Phabricator.

    phabsend will check obsstore and the above association to decide whether to
    update an existing Differential Revision, or create a new one.
    r�s(phabsend requires at least one changesetr�csg|]}�|�qSr?r?)r�r��r�r?r@r�Ur8zphabsend.<locals>.<listcomp>css|]}|��r|VqdSr9)Zobsolete�r��cr?r?r@�	<genexpr>Wr8zphabsend.<locals>.<genexpr>s,obsolete commits cannot be posted for reviewcs<�fdd�|D�}tjtd�|t��|�ftd�d��dS)Ncsg|]}�|���qSr?�r��r��rr�r?r@r�_r8z:phabsend.<locals>._fail_nonlinear_revs.<locals>.<listcomp>s)cannot phabsend multiple %s revisions: %ss&the revisions must form a linear chain)�hint)rr�rr�
nodesummaries)r�ZrevtypeZbadnodesr�r?r@�_fail_nonlinear_revs^s��z&phabsend.<locals>._fail_nonlinear_revss
heads(%ld)r$sheads
roots(%ld)srootr�scannot fold a single revisionscannot fold with --no-amendcSsg|]}t�|����qSr?)r�r�r�)r�r�r?r?r@r��s�cSsh|]}|r|�d��qS)r)r�)r�r�r?r?r@r��r8zphabsend.<locals>.<setcomp>s0cannot fold revisions with different DREV valuescsg|]}�|���qSr?r�r�r�r?r@r��r8r2r3sphabsend cancelledr�r�cSsd|S)Nsblocking(%s)r?)�phidr?r?r@rA�r8zphabsend.<locals>.<lambda>s
reviewers.addr�Nssending rev %d::%d
rtssending rev %d
�NNNr�sobjectr�r�r�r�r�r�Tr�r�rr�rm�differential.query�idscSsg|]}|�qSr?r?r�r?r?r@r�s�s4(%ld::) - (%ld) - unstable() - obsolete() - public()�.cs g|]}t|d��kr|�qS)r�r�r�)r�r?r@r�r8s'warning: not updating public commit %s
)�parents�textr�r��extras#updating local commit list for D%d
s0local commit list for D%d is already up-to-date
sno newnodes to update
srestabilizing %s as %s
snot restabilizing unchanged %s
)Zfixphase)Drr,r�r�r�revrange�sortrr�rrZcheckunfinished�anyr�r�r�r}r��_confirmbeforesendr?r�rM�mapr+r�r�r�r�r�r�r�r�r�rr��	querydrevr�r�r��wlock�lock�transactionr�r��get_amended_descr�Zp2ZphaserZpublicrIrZformatchangeidrZupdate_hash_refsr	Zmetadataonlyctxr�r�r��commitr�r�r�r�rZcleanupnodesZ
setparents)1rMr�r�rOr�r�Zheads�rootsZfoldZdrevmatchers�oldmapZconfirmZ	confirmedr�Z	reviewersZblockersZphids�drevidsZdiffmapZlastrevphidr�r�r�r�r�ZoldbasediffZoldbaserevidr�rrr�Z
newrevphidr�r�r�r�r�r�ZrestackZwnode�mappingr�r�r��oldr�Znewdescr��newr�r?)r�r�r@�phabsends�4





��
��
 �
��
&��
��������

��	��
�
�����
r�))rvsUser)rwsDate)rxsBranch)rysNode ID)rzsParent c
Cs�t|j�\}}|j}|D]h}||}|�|��d�\}}	}
|
rP|�d|
d�}n|�td�d�}|�td�|t�||d�f�q|�	td�|�r�dSd	S)
Nr�r�r7sNEWs%s - %s
r2s1Send the above changes to %s (Y/n)?$$ &Yes $$ &NoFT)
r�rMr�r�r�rr~rr�Zpromptchoice)r�r�r�rr�rMr�r�r�r�r�r�r?r?r@r��s(���
�r�>s	abandonedsclosedschangesplanneds
needsrevisionsacceptedsneedsreviewcCs|d�dd���S)z7get normalized status name from a Differential Revision�
statusNamer�r8)r!r�r�r?r?r@�_getstatusname�sr�)r(N)�groupr$�)NN)rN)�	ancestorsrNN)rNN)�and_rN)rNN)�addrN)rNN)�subrN)rNNNN)r�symbolNNN)�(�:�&�+�-r�r��endc
#s�t|�}d�d}t|�}||kr�d�t��fdd�t�||d����}|rfd||fV|t|�7}q|||d�dkr�|||d�d|fV|d7}qd	d|fVdS)
Ns():+-& rr8cs|�vSr9r?)Zch�Zspecialr?r@rA�r8z_tokenize.<locals>.<lambda>r�r$r�r�)�
memoryviewr�rJ�	itertools�	takewhilerZiterbytestr)r��view�pos�length�symbolr?r�r@�	_tokenize�s"��
r�cCs4t�t��t|��\}}|t|�kr0t�d|��|S)Ns
invalid token)r�	_elements�parser�r�rZ
ParseError)r��treer�r?r?r@�_parse�sr�cCs>|�d�r*|dd���r*t|dd��S|��r:t|�SdS)z<str -> int or None, ex. 'D45' -> 45; '12' -> 12; 'x' -> None�Dr$N)rY�isdigitr�)r�r?r?r@�
_parsedrev�sr�cCs�t�}t�}|d}|dkr8t|d�}|r�|�|�nj|dkrpt|d�\}}|�|�|�|�|�|�n2|dd�D]$}t|�\}}|�|�|�|�q|||fS)z9return ({single-drev-id}, {ancestor-drev-id}) to prefetchrr�r$r�N)r�r��add�_prefetchdrevs�update)r�r��
ancestordrevs�opr��a�tr?r?r@r�s"


r�cs���fdd���fdd��i�t|�}t|�\}}��dd�}t|�}|D]"}|�ttd||�|d��qJ|r��dt|�i�tt�t|���t|�B������fd	d
���fdd��|�D�S)
a�return a list of "Differential Revision" dicts

    spec is a string using a simple query language, see docstring in phabread
    for details.

    A "Differential Revision dict" looks like:

        {
            "activeDiffPHID": "PHID-DIFF-xoqnjkobbm6k4dk6hi72",
            "authorPHID": "PHID-USER-tv3ohwc4v4jeu34otlye",
            "auxiliary": {
              "phabricator:depends-on": [
                "PHID-DREV-gbapp366kutjebt7agcd"
              ]
              "phabricator:projects": [],
            },
            "branch": "default",
            "ccs": [],
            "commits": [],
            "dateCreated": "1499181406",
            "dateModified": "1499182103",
            "diffs": [
              "3",
              "4",
            ],
            "hashes": [],
            "id": "2",
            "lineCount": "2",
            "phid": "PHID-DREV-672qvysjcczopag46qty",
            "properties": {},
            "repositoryPHID": "PHID-REPO-hub2hx62ieuqeheznasv",
            "reviewers": [],
            "sourcePath": null
            "status": "0",
            "statusName": "Needs Review",
            "summary": "",
            "testPlan": "",
            "title": "example",
            "uri": "https://phab.example.com/D2",
        }
    cs�|�d�p|�d�pdgd}|�vr.�|St�d|�}|D] }|�|d<|�t|d�<q>|�vrzt�td�|���|S)	zparams -> single drev or Noner��phidsNrr�r�r�s#cannot get Differential Revision %r)r�r�r�rr�r)r�r[r�r�)�
prefetchedrMr?r@�fetchDs
�zquerydrev.<locals>.fetchc	s�t�}g}dd�|D�}|r�|��}�|�}|d|vr:q|�|d�|�t|d��|�di�}|�dg�}|D]}|�d|gi�qvq|��t�|�S)z6given a top, get a stack from the bottom, [id] -> [id]cSsg|]}d|gi�qS)r�r?)r�r�r?r?r@r�Xr8z/querydrev.<locals>.getstack.<locals>.<listcomp>r�s	auxiliarysphabricator:depends-onr)	r�rdr�r+r�r��reverser�baseset)	Z
topdrevidsZvisitedrPZqueuer�r�Z	auxiliaryZdependsr�)rr?r@�getstackTs zquerydrev.<locals>.getstackr&r'r$r�cs��d}|dkrnt�d�}|r,t�|g�S�dtvrV��fdd��D�}t�|�St�td��d��nb|dvr�tt|���d���d��S|d	kr���d�S|d
krˆ��d��St�	d���dS)Nrr�r$cs$g|]}t�|��dkr|�qS)r$)r�r�)rr�r?r@r��s�z+querydrev.<locals>.walk.<locals>.<listcomp>sunknown symbol: %s>r�r�r�rmr�r�sillegal tree: %r)
r�rr�_knownstatusnamesrr�rr�operatorZProgrammingError)r�r�r�r�)rr�validids�walk)r�r@rys$�
 zquerydrev.<locals>.walkcsg|]}�|�qSr?r?r�)rr?r@r��r8zquerydrev.<locals>.<listcomp>)	r�r�r�r�r�r�r�r�r�)rMrxr�r�r�Z	batchsizeZtofetchr�r?)rrrrMr
rr@r�s. r�cCsP|d}|d��}|d��}|r,d|}d|d}d�td||||g��S)	z�get description (commit message) from "Differential Revision"

    This is similar to differential.getcommitmessage API. But we only care
    about limited fields: title, summary, test plan, and URL.
    r�r�r�s
Test Plan:
%s�Differential Revision: %s�urir�N)r�rJr�)r��titler�ZtestplanrUr?r?r@�getdescfromdrev�srcCsL|st|�Sd|d}t�|���}|s<d�|��|g�St�||���S)a1similar to ``getdescfromdrev``, but supports a folded series of commits

    This is used when determining if an individual commit needs to have its
    message amended after posting it for review.  The determination is made for
    each individual commit, even when they were folded into one review.
    rr
r�)rr�r�r�rJr_)r�r�ZfoldedrUr�r?r?r@r��s
r�cCsT|�d�pi}|�d�pi}t|�dkr:dd�|��D�Stt|��dd��pPdhS)	zkget the set of local commits from a diff object

    See ``getdiffmeta()`` for an example diff object.
    �
propertiesr�r$cSsh|]}t|��qSr?)rr�r?r?r@r��r8z"getlocalcommits.<locals>.<setcomp>ryr8N)r�r�r r�getdiffmeta)rr�propsr�r?r?r@r��s
r�cCsF|�d�pi}|�d�}|s�|�d�r�t|d���d}i}d|vrfd|vrfd|d|df|d<d	|vr�d
t|d	�|d<d|vr�|d|d<|�d
|�d��}|r�||d<t|�dd��dkr�|dd|d<ni}d|vr�d|vr�d|d|d<d|v�r |�d��r |d|d<d|v�rB|�d��rB|d|d<|S)a�get commit metadata (date, node, user, p1) from a diff object

    The metadata could be "hg:meta", sent by phabsend, like:

        "properties": {
          "hg:meta": {
            "branch": "default",
            "date": "1499571514 25200",
            "node": "98c08acae292b2faf60a279b4189beb6cff1414d",
            "user": "Foo Bar <foo@example.com>",
            "parent": "6d0abad76b30e4724a37ab8721d630394070fe16"
          }
        }

    Or converted from "local:commits", sent by "arc", like:

        "properties": {
          "local:commits": {
            "98c08acae292b2faf60a279b4189beb6cff1414d": {
              "author": "Foo Bar",
              "authorEmail": "foo@example.com"
              "branch": "default",
              "commit": "98c08acae292b2faf60a279b4189beb6cff1414d",
              "local": "1000",
              "message": "...",
              "parents": ["6d0abad76b30e4724a37ab8721d630394070fe16"],
              "rev": "98c08acae292b2faf60a279b4189beb6cff1414d",
              "summary": "...",
              "tag": "",
              "time": 1499546314,
            }
          }
        }

    Note: metadata extracted from "local:commits" will lose time zone
    information.
    rrur�rr{r|s%s <%s>rvr}s%d 0rwrxr~r�ryrr?r$rzsdateCreateds%s 0ssourceControlBaseRevision)r�r�r�r�r�)rrr�metar�r�r?r?r@r�s8&

�
rcsNt|�dkr<�fdd�}d�t�||��}t||�}|r<|St�td���dS)z�convert user supplied DREVSPECs into "Differential Revision" dicts

    See ``hg help phabread`` for how to specify each DREVSPEC.
    rcs�rd|}d|S)Ns:(%s)s(%s)r?)r���stackr?r@�_formatspecsz_getdrevs.<locals>._formatspecr�sempty DREVSPEC setN)r�rJrZmaplistr�rr�r)rMr�specsrrxr�r?rr@�	_getdrevss
rcCs�tdd�|D��}t|dd|i�}g}|D]�}|�td�|d�tdd�|d	D��}t|d
d|i�}t|�}	d}
t|d
|�}t��D]$}||vr�|
dt|||f7}
q�d|
|	|f}
|�	|d|
f�q*||�dS)a/generate plain-text patch readable by 'hg import'

    write takes a list of (DREV, bytes), where DREV is the differential number
    (as bytes, without the "D" prefix) and the bytes are the text of a patch
    to be imported. drevs is what "querydrev" returns, results of
    "differential.query".
    cSs"h|]}tdd�|dD���qS)css|]}t|�VqdSr9r��r�r�r?r?r@r�1r8z&readpatch.<locals>.<setcomp>.<genexpr>�diffs)r�)r�r�r?r?r@r�1r8zreadpatch.<locals>.<setcomp>r�r�sreading D%s
r�css|]}t|�VqdSr9r�rr?r?r@r�:r8zreadpatch.<locals>.<genexpr>rsdifferential.getrawdiffsdiffIDs# HG changeset patch
r�s# %s %s
s%s%s
%sN)
r�r��noterr�rr�_metanamemapr r+)rMr�r~Zdiffidsr��patchesr�r�rXr�rBrr��contentr?r?r@�	readpatch(s 	rsphabread�stacksread dependenciessDREVSPEC... [OPTIONS]rocs8t�|�}t�|�d�|�}�fdd�}t�||�dS)aprint patches from Phabricator suitable for importing

    DREVSPEC could be a Differential Revision identity, like ``D123``, or just
    the number ``123``. It could also have common operators like ``+``, ``-``,
    ``&``, ``(``, ``)`` for complex queries. Prefix ``:`` could be used to
    select a stack.  If multiple DREVSPEC values are given, the result is the
    union of each individually evaluated value.  No attempt is currently made
    to reorder the values to run from parent to child.

    ``abandoned``, ``accepted``, ``closed``, ``needsreview``, ``needsrevision``
    could be used to filter patches by status. For performance reason, they
    only represent a subset of non-status selections and cannot be used alone.

    For example, ``:D6+8-(2+D4)`` selects a stack up to D6, plus D8 and exclude
    D2 and D4. ``:D9 & needsreview`` selects "Needs Review" revisions in a
    stack up to D9.

    If --stack is given, follow dependencies information and read all patches.
    It is equivalent to the ``:`` operator.
    r cs|D]\}}��|�qdSr9)r~)rr�r�rMr?r@�_writemszphabread.<locals>._writeN)rr,rr�r)rMr�rrOr�r"r?r!r@�phabreadNs
r#simport dependencies as wellcs�t����d�d<d�d<d�d<d�d<��d	d
�r>d�d
<��d	d�rRd�d<���fdd�}t���d
�|�}t�j||�dS)z�import patches from Phabricator for the specified Differential Revisions

    The patches are read and applied starting at the parent of the working
    directory.

    See ``hg help phabread`` for how to specify DREVSPEC.
    Tsbypassr$sstripr8sprefixFr6r4r5cs(�d��}������������d���|D]�\}}��td�|�t��t�	|���Z}t
���||�gd�\}}}|s�t�
td�|����|d��|g}Wd�q01s�0Yq0Wd�n1s�0YWd�n1s�0YWd�n1�s0YdS)Nr4sapplying patch from D%s
sD%s: no diffs found�
)r�r�r�r�rqrr�extractrZbytesiorZtryimportonerr�r)rr�r��contentsZ	patchdatarr�Zrej�rOr�rMr?r@r"�s$ �

zphabimport.<locals>._writer N)rr,r}rr�rrM)rMr�rrOr"r�r?r'r@�
phabimportts
r(s
phabupdate�acceptsaccept revisions�rejectsreject revisions�request-reviewsrequest review on revisions�abandonsabandon revisions�reclaimsreclaim revisions�closesclose revisions�reopensreopen revisions�plan-changessplan changes for revisions�resigns#resign as a reviewer from revisions�
commandeerscommandeer revisionsscomment on the last revisionslocal revision to updates"[DREVSPEC...| -r REV...] [OPTIONS]cs�t����gd�}�fdd�|D�}t|�dkrHt�td�d�|���g}|D]}|�|dd��qP��d	�}|�r|s�t�	td
���|r�t�	td���t
|t�||g��}	g}g}
t�
|	�D].\}}|dur�|
�||�q�|�d
|�q�|
�rt�	td�t�||
���t|��d�|�}
t|
�D]\\}}|dt|
�k�rd��d��rd|�d�dd��|�r*|d|d�}t|d|��q*dS)zrupdate Differential Revision in batch

    DREVSPEC selects revisions. See :hg:`help phabread` for its usage.
    )
r,r)r.r2r0r-r*r/r+r1cs"g|]}��|�dd��r|�qS)r��_)r�r!r�r�r?r@r��r8zphabupdate.<locals>.<listcomp>r$s%s cannot be used togethers, Tr�r�s--rev requires a repositorys&cannot specify both DREVSPEC and --revNr�s-selected revisions without a Differential: %sr r�r�)r�r�r�)rr,r�rr�rrJr+r�Z
InputErrorr�rr��	iteritemsrr�rr�r�)rMr�rrOr�r{r��fr��drevmap�unknownr�r�r�r�r�r�r?r�r@�
phabupdate�sH


���r8s
phabreview�ctx)ZrequirescCs�|�|d�}t�|���}|r>t�|�d�d|�d�d��S|���|�	��}|D]N}t
�|�rT|��j�
dd�}|�d�s�|d7}||7}t�||d��SqTd	S)
ze:phabreview: Object describing the review for this changeset.
    Has attributes `url` and `id`.
    r9rsD%sr�)r1r�r&r1r�N)�resourcer�r�r�r�
hybriddictr�r�r�r�r�rrMr�rZ)r	r�r�r�rrrr?r?r@�template_review	s*��

��
r<s
phabstatus>�uir9�repoc	Cs�|�|d�}|�|d�}|�|d�}|��}zt||g�|}WntyTYdS0t|dd|gi�}|D]0}t|d�|krlt�|d|d	d
��SqldS)z8:phabstatus: String. Status of Phabricator differential.r9r>r=Nr�r�r�r
r�)r1sstatus)r:r�r��KeyErrorr�r�rr;)	r	r�r�r�rMr�r�r�r�r?r?r@�template_status!	s"��
r@swork)Z	csettopiccs|�d�}t||�}gt�i}}}t�|�D]:\}}	|	dur`|�|	�|�|	t���|�q0|�|�q0t�ddt	|�i�}
i�|
D]"}|t
|d�D]}|�|<q�q���fdd�}|t�|�8}t
�||�}
��dd	d
�||_t�||�}tj�||
|t
jd|id�dS)
z Phabricator differiential statuszsort(_underway(), topo)Nr�r�r�cs>�|��}��d|dt|��}��d|d|f�dS)Ns%(statusName)ssphabricator.status.%ss
%s %s
r
)r�r�r�r~)r�r�rq�Z
drevsbyrevrMr?r@�
phabstatusL	s
�z&phabstatusshowview.<locals>.phabstatussexperimentalsgraphshortenTsnodelen)r)r�r�r�rr4r��
setdefaultr+r�r�r�rrrZ	dagwalkerr�Z_exthookr%ZlongestshortestrZdisplaygraphZ
asciiedges)rMr�Z	displayerr�r6Zunknownrevsr�Zrevsbydrevidr�r�r�r�rBZrevdagZnodelenr?rAr@�phabstatusshowview9	s6


�rD)NF)NNNNNNN)�rsZ
__future__rrHr�rRr�rcrVr	r^r�Zmercurial.noderrZmercurial.i18nrZmercurial.pycompatrZmercurial.thirdpartyrZ	mercurialrr	r
rrr
rrr�rrrrrrrrrrrrrrrrrir Zmercurial.utilsr!r"r#rr%Z
testedwithZehZcmdtablertZconfigtableZtemplatekeywordZfinaluisetupZuisetupZ
configitemZ
colortablerzZwrapfunctionrRr|r�r�r�r�r�r��compiler��Mr�r�r�r��objectr�rr�r�rrr4rDrMrTr[r\rbrarfrjrorsr�r�r�r�r�ZCATEGORY_IMPORT_EXPORTr�rLrr�rr�r�r�r�r�r�r�rr�r�rrrr#r(r8r<r@ZshowviewrDr?r?r?r@�<module>s�5l���������������

&
Q>

�

(%S/�
x���
o�

�
E&�
�
7��
<



Youez - 2016 - github.com/yon3zu
LinuXploit