
    6h}                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJrJrJrJrJrJrJr  SSKJrJr  \R,                  " S	5      r\R0                  r\R4                  r\R8                  r\R<                  rS
rSr Sr!Sr"S r#S r$S r%\RL                  r&\RN                  r'Sr(Sr)Sr*\" \)5      r+\" \*5      r,S r-S r.S r/S r0Sr1Sr2Sr3Sr4\" \35      r5\" \45      r6\" \25      r7Sr8Sr9\" \95      r:S r;S r<S r=\(\-\.4\1\=\<40r>S r?\R                  SAS j5       rA\(4S  jrBS!\(4S" jrC\R                  S# 5       rD\R                  S$ 5       rE\R                  S% 5       rFS& rG " S' S(5      rHS) rIS* rJS+rKS, rLS- rMS. rN0 rOS/ rPS0 rQS1 rRS2 rS\P" S35      S4 5       rT\P" S55      S6 5       rU\P" S75      S8 5       rV\P" S95      S: 5       rW\P" S;5      S< 5       rX\P" S=5      S> 5       rYS? rZ SBS@ jr[g)Ca  Obsolete marker handling

An obsolete marker maps an old changeset to a list of new
changesets. If the list of new changesets is empty, the old changeset
is said to be "killed". Otherwise, the old changeset is being
"replaced" by the new changesets.

Obsolete markers can be used to record and distribute changeset graph
transformations performed by history rewrite operations, and help
building new tools to reconcile conflicting rewrite actions. To
facilitate conflict resolution, markers include various annotations
besides old and news changeset identifiers, such as creation date or
author name.

The old obsoleted changeset is called a "predecessor" and possible
replacements are called "successors". Markers that used changeset X as
a predecessor are called "successor markers of X" because they hold
information about the successors of X. Markers that use changeset Y as
a successors are call "predecessor markers of Y" because they hold
information about the predecessors of Y.

Examples:

- When changeset A is replaced by changeset A', one marker is stored:

    (A, (A',))

- When changesets A and B are folded into a new changeset C, two markers are
  stored:

    (A, (C,)) and (B, (C,))

- When changeset A is simply "pruned" from the graph, a marker is created:

    (A, ())

- When changeset A is split into B and C, a single marker is used:

    (A, (B, C))

  We use a single marker to distinguish the "split" case from the "divergence"
  case. If two independent operations rewrite the same changeset A in to A' and
  A'', we have an error case: divergent rewriting. We can detect it because
  two markers will be created independently:

  (A, (B,)) and (A, (C,))

Format
------

Markers are stored in an append-only file stored in
'.hg/store/obsstore'.

The file starts with a version header:

- 1 unsigned byte: version number, starting at zero.

The header is followed by the markers. Marker format depend of the version. See
comment associated with each format for details.

    )annotationsN   )_)binhex)encodingerrorobsutilphasespolicypycompatutil)dateutilhashutilparsers   createmarkerss   allowunstables   allowdivergences   exchangec                   SU-  nU R                   R                  SU5      nUb  U$  U R                   R                  SS5      $ ! [        R                  [        4 ah    [        U R                   R                  SS5      5      nSU;   a   gU R                   R                  SS5      nU(       a  UR                  S5        X;   s $ f = f)LReturns True if the given repository has the given obsolete option
enabled.
s   evolution.%s   experimentals	   evolutions   allTs   evolution.createmarkersr   )	ui
configboolr	   ConfigErrorAttributeErrorset
configlistconfigadd)repooption	configkey	newconfigresults        4/usr/lib/python3/dist-packages/mercurial/obsolete.py_getoptionvaluer$   n   s      &(I""?I>I  ww!!/<@@~.   TWW''FGV GGNN?4NO	JJ'( s   A AC8CCc                    [        U [        5      nU(       a1  [        U [        5      n[        U [        5      n[        U [        5      nOSnSnSn[        U[        U[        U[        U0$ )z5Returns dicts showing state of obsolescence features.F)r$   createmarkersoptallowunstableoptallowdivergenceoptexchangeopt)r   createmarkersvalueunstablevaluedivergencevalueexchangevalues        r#   
getoptionsr.      sm     )/?@'.>?)$0BC'k:  	,-O]	     c                    [        U 5      U   $ )r   )r.   )r   r   s     r#   	isenabledr1      s     dF##r/   s   >BIB20ss   20sc              #    #    X:  Ga  XU[         -    nU[         -  n[        [        U5      u  pEpgSnU(       a&  [        U-  n	XX-    n[        [        U-  U5      nX-  nXX-    n
[        U
5      U:w  a-  [        R                  " [        S5      U[        U
5      4-  5      eX-  n[        U
5      n
 U
R                  SS5      R                  S5      u  p[        U5      [        U5      4nS nSU
;   a%  U
R                  SS 5      U
R                  SS 5      4nO"SU
;   a  U
R                  SS 5      4nOS	U
;   a  SnUb0   [        S
 U 5       5      nU H  n[        U5      S:w  d  M  S n  O    [        [%        U
R'                  5       5      5      n
XxXjX4v   X:  a  GM  g g ! [         a    Sn Nf = f! [         R"                   a    S n N]f = f7f)N sI   parsing obsolete marker: metadata is too short, %d bytes expected, got %d   dates   0 0    )g        r   s   p2s   p1   p0c              3  8   #    U  H  n[        U5      v   M     g 7fN)r   .0ps     r#   	<genexpr>"_fm0readmarkers.<locals>.<genexpr>   s     81As      )	_fm0fsize_unpack	_fm0fixed_fm0fnodesize_fm0nodelenr	   Abortr   _fm0decodemetapopsplitfloatint
ValueErrortuplebinasciiErrorsorteditems)dataoffstopcurnumsucmdsizeflagspresucssmetadatawhenoffsetdateparentsr;   s                   r#   _fm0readmarkersr`      s    
*y)y%,Y%<"&ASW%C8f,c2DHC cl+x=F"++8 3x=)	*  	!(+	#<<8>>tDLD;F+D H||E40(,,ud2KLGh||E402GhG	888 A1v|"& !  012%499g **8  	D	" >> sg   B.G19F *AG=$F1 %F1 (G)F1 +/GGF.+G-F..G1G
G	G

Gc                   U u  pp4pVU[         -  (       a  [        R                  " [        S5      5      e[	        U5      nUu  pxSXx4-  US'   Ub2  U(       d  SUS'   [        US5       H  u  p[        U
5      USU	-  '   M     [        U5      n[        U5      n[        [        U-  -   nU[        U5      X1/nUR                  U5        [        U/UQ76 U-   $ )Ns-   cannot handle sha256 with old obsstore formats   %r %ir4   r/   r6   r   s   p%i)usingsha256r	   rE   r   dict	enumerater   _fm0encodemetarD   rA   rC   extend_pack)markerrX   rY   rW   r[   r^   r_   timetzir;   rU   formatrQ   s                 r#   _fm0encodeonemarkerrm     s    06-Cu{kk!LMNNH~HHD D:-HW!HUOgq)DA#&q6HVaZ  *h'HYF(V+,FCM5.DKK$(**r/   c           	         U R                  5        H-  u  pSU;   d  SU;   a  [        S5      eSU;   d  M$  [        S5      e   SR                  [        U 5       Vs/ s H  nSX0U   4-  PM     sn5      $ s  snf )ziReturn encoded metadata string to string mapping.

Assume no ':' in key and no ' ' in both key and value.   :    s*   ':' and ' ' are forbidden in metadata key's#   ':' is forbidden in metadata value's   %s:%s)rP   rK   joinrO   )metakeyvalueks       r#   re   re     st     jjl
3;%3,KLLE>CDD	 #
 ::tE1x11g,.EFFEs   A4c                |    0 nU R                  S5       H$  nU(       d  M  UR                  SS5      u  p4XAU'   M&     U$ )z8Return string to string dictionary from encoded version.rp   ro   r   )rH   )rQ   dlrs   rt   s        r#   rF   rF   #  s?    
AZZ1q)JCcF  Hr/   s   >IdhHBBBs   32s   s   BBc              #    #    [         n[        n[        n[        n[        n[
        n[        n	[        n
[        n[        n[        R                  " [        5      R                  nX:  Ga  X-   nU" XU 5      u  nnnnnnnUU-  (       a  UnUnOUnUnU" UXUU-    5      u  nUU-  nUS:X  a  UU-   nXU 4nOUUU-  -   nU" UU-  XU 5      nUU:X  a  UnS nO)US:X  a  UU-   nU UU 4nOUUU-  -   nU" UU-  U UU 5      nUU	U-  -   nU" SU
U-  -   U UU 5      n/ n[        S[        U5      S5       H/  nUUU   -   nUUUS-      -   nUR!                  XU XU 45        UnM1     UUU[#        U5      UUS-  4U4v   X:  a  GM  g g 7f)Nr      >r      <   )_fm1parentnonerb   _fm1nodesha1size_fm1nodesha256size_fm1nodesha1_fm1nodesha256_fm1metapairsize_fm1metapair	_fm1fsizer@   structStruct	_fm1fixedunpackrangerD   appendrL   ) rQ   rR   rS   noneflagsha2flagsha1sizesha2sizesha1fmtsha2fmtmetasizemetafmtfsizer   ufixedo1tsecsrj   rW   rU   numparnummetanodefmtnodesizepreco2rY   o3r_   metapairsizer[   idxs                                    r#   _fm1purereadmarkersr   [  s    HHH!HGGHGEF ]]9%,,F
*[6<Tb\6J34UFFG8GHGH$BM":;
h Q;hBBK>Dh''B'F*DBK8D XBGq[hBBr{nGh''BWv-tBr{;G 8g%%dg&78$r#,GC-q1C|C((Bl37++BOOTb\42;78C	 2 T5%/D"r'?GLLY **s   FF	F	c           	     8   U u  pp4pV[         nU[        -  (       a  [        n[        U5      nSU-   n	Uc  [        n
O[        U5      n
X-  n	Xy-  n[
        [        U5      -  n[        U-   U-   nUS   S-  nS US   XX[        U5      U/nUR                  U5        Ub  UR                  U5        [        U5      nU H  u  nn[        U5      n[        U5      nUS:  a  SUU4-  n[        R                  " U5      eUS:  a  SUUU4-  n[        R                  " U5      eUR                  U5        UR                  U5        UUU-   -  nM     UUS'   [        U/UQ76 /nU H(  u  nnUR                  U5        UR                  U5        M*     SR                  U5      $ )Nr   r}   r      sL   obsstore metadata key cannot be longer than 255 bytes (key "%s" is %u bytes)s]   obsstore metadata value cannot be longer than 255 bytes (value "%s" for key "%s" is %u bytes)r/   )r   rb   r   rD   r~   r   r   rf   	_calcsizer	   ProgrammingErrorr   rg   rq   )rh   rX   rY   rW   r[   r^   r_   _fm1noderU   numextranodesr   formatnodes
formatmetarl   rj   rQ   	totalsizers   rt   lklvmsgs                         r#   _fm1encodeonemarkerr     s   06-CuH{!YFJMW*KH-J$z1F	aBB$q'2fc(mSIDKKG&!I
UXZ8+b	C ((--8:R !C ((--BBR"W	# $ DG& 4 !D
UCE  88D>r/   c                \    [        [        SS 5      nU(       d  [        XU5      $ U" XU5      $ )Nfm1readmarkers)getattrr   r   )rQ   rR   rS   natives       r#   _fm1readmarkersr     s.    W.5F"4d33$T""r/   c                &    [        SU SS 5      S   $ )N   >Br   r   )r@   )rQ   s    r#   _readmarkerversionr     s    5$q)$Q''r/   c                    [        U 5      nU(       d  SnUc  [        U 5      nU[        ;  a"  [        S5      U-  n[        R
                  " XCS9eU[        U   S   " XU5      4$ )z(Read and enumerate markers from raw datar   s+   parsing obsolete marker: unknown version %rversionr   )r   rD   formatsr   r	   UnknownVersion)rQ   rR   rS   diskversionr   s        r#   _readmarkersr     si     %T*K|4y'!>?+M""3<<,Q/4@@@r/   c                    [        SU 5      $ )Nr   )rg   r   s    r#   encodeheaderr     s      r/   Fc              #  r   #    [         U   S   nU(       a  [        U5      v   U  H  nU" U5      v   M     g 7fNr   )r   r   )markers	addheaderr   	encodeonerh   s        r#   encodemarkersr     s9       #I7## s   57c                n    U H/  nU R                  US   [        5       5      R                  U5        M1     g )Nr   
setdefaultr   r   )
successorsr   marks      r#   _addsuccessorsr     s-    d1gsu-11$7 r/   c                    U H8  nUS    H,  nU R                  U[        5       5      R                  U5        M.     M:     g r   r   )predecessorsr   r   sucs       r#   _addpredecessorsr      s7    7C##C/33D9  r/   c                    U H?  nUS   nUc  M  U H,  nU R                  U[        5       5      R                  U5        M.     MA     g )N   r   )childrenr   r   r_   r;   s        r#   _addchildrenr     sB    q'##Asu-11$7  r/   c                z    U H5  nU R                   US   ;   d  M  [        R                  " [        S5      5      e   g)zsearch for marker with invalid data and raise error if needed

Exist as a separated function to allow the evolve extension for a more
subtle handling.
r   s;   bad obsolescence marker detected: invalid successors nullidN)nullidr	   rE   r   )r   r   r   s      r#   _checkinvalidmarkersr     s<     ;;$q'!++1  r/   c                      \ rS rSrSrSr\S4S jr\S 5       r	S r
S rS	 r\r\S
 5       r      SS jrS rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS rSS jrSrg)obsstorei   zStore obsolete markers

Markers can be accessed with two mappings:
- predecessors[x] -> set(markers on predecessors edges of x)
- successors[x] -> set(markers on successors edges of x)
- children[x]   -> set(markers on predecessors edges of children(x)
)s   precs   succss   flags   metar4   s   parentsFc                l    0 U l         X l        [        R                  " U5      U l        X0l        X@l        g r8   )cachessvfsweakrefref_repo_defaultformat	_readonly)selfr   r   defaultformatreadonlys        r#   __init__obsstore.__init__2  s)    	[[&
+!r/   c                \    U R                  5       nUc  Sn[        R                  " U5      eU$ )Nz(using the obsstore of a deallocated repo)r   r	   r   )r   rr   s      r#   r   obsstore.repo:  s-    JJL9<C((--r/   c                ,    [        U R                  5      $ r8   )iter_allr   s    r#   __iter__obsstore.__iter__B  s    DIIr/   c                ,    [        U R                  5      $ r8   )rD   r   r   s    r#   __len__obsstore.__len__E  s    499~r/   c                P   SSK Jn  [        U R                  UR                  5      (       a  [        U R                  5      S:  $ U R                  S5      (       d)   U R                  R                  S5      R                  S:  $ [        U R                  5      $ ! [         a     N!f = f)Nr   )statichttprepor      obsstore) r   
isinstancer   statichttprepositoryrD   _data_cachedr   statst_sizeFileNotFoundErrorboolr   )r   r   s     r#   __nonzero__obsstore.__nonzero__H  s    $dii!D!DEE tzz?Q&&||F##yy~~k2::Q>>
 DII	 %  s   'B 
B%$B%c                    U R                   $ )z_True if marker creation is disabled

Remove me in the future when obsolete marker is always on.)r   r   s    r#   r   obsstore.readonlyZ  s    
 ~~r/   Nc	           	        [        U5      nUc  0 nUco  SU;   a&  [        R                  " UR                  S5      5      nOCUb+  UR	                  SS5      nUc  [        R
                  " 5       nO[        R
                  " 5       nU[        -  (       a>  [        U5      S:w  a  [        U5      eU H  n	[        U	5      S:w  d  M  [        U	5      e   O=[        U5      S:w  a  [        U5      eU H  n	[        U	5      S:w  d  M  [        U	5      e   X#;   a  [        SUR                  5       -  5      e[        [        UR                  5       5      5      nU H(  u  p U
R                  S5        UR                  S5        M*     ['        U5      [        U5      XGXe4n[)        U R+                  X/5      5      $ ! [         aD    [        R                   " S["        R$                  " U
5      ["        R$                  " U5      4-  5      ef = f)	a>  obsolete: add a new obsolete marker

* ensuring it is hashable
* check mandatory metadata
* encode metadata

If you are a human writing code creating marker you want to use the
`createmarkers` function in this module instead.

return True if a new marker have been added, False if the markers
already existed (no op).
r4      devels   default-date    r>   zin-marker cycle with %szutf-8sE   obsstore metadata must be valid UTF-8 sequence (key = %r, value = %r))rJ   r   	parsedaterG   
configdatemakedaterb   rD   rK   r   rL   rO   rP   decodeUnicodeDecodeErrorr	   r   r   bytestrbytesr   r   )r   transactionr   succsflagr_   r^   r[   r   succru   vrh   s                r#   createobsstore.createa  s   . 4yH<("))(,,w*?@}}X?<#,,.D((*+4yB &&t9?$T**  4yB &&t9?$T**  =6CDD 012DA	!!	  +uU|TTKDHH[(344 & ,,.''*H,<,<Q,?@A s   "F00AG>c                   U R                   (       a  [        R                  " [        S5      5      e[	        5       nU R
                  R                  n/ nU H=  nXd" US   S5      ;  d  M  Xc;  d  M  UR                  U5        UR                  U5        M?     U(       a  U R                  SS5      n UR                  5       nUR                  SU5        SR                  [        XXS:H  U R                  5      5      n	UR                  U	5        UR                  5         UR                   R                  S5      n
U
b  U
R#                  U5        U R%                  XY5        U R&                  R)                  5         [+        UR,                  R                  SS	5      5      nS
U[/        U5      -   -  UR,                  S'   [/        U5      $ ! UR                  5         f = f)z`Add new markers to the store

Take care of filtering duplicate.
Return the number of new marker.s5   creating obsolete markers is not enabled on this repor   r3   r   s   abr/   s
   obsmarkerss   new_obsmarkers   0   %d)r   r	   rE   r   r   r   getr   r   r   tellrq   r   _versionwriteclosechangesupdate_addmarkersr   clearrJ   hookargsrD   )r   r  r   knowngetsuccessorsnewmfr]   rQ   addedmarkerspreviouss               r#   r   obsstore.add  sz   
 >>++JK  ++AadB//AN		!

1  		+u-A	V4xxcQ; NO 	&..22=AL'##C(S'KK{++//0A4HI278c#h;N2O./3x 	s   0AG Gc                >    [        U5      u  p4U R                  X5      $ )z^merge a binary stream of markers inside the obsstore

Returns the number of new markers added.)r   r   )r   r  rQ   r   r   s        r#   mergemarkersobsstore.mergemarkers  s      (-xx--r/   c                8    U R                   R                  S5      $ )Nr   )r   tryreadr   s    r#   r   obsstore._data  s    yy  --r/   c                v    [        U R                  5      S:  a  [        U R                  5      $ U R                  $ r   )rD   r   r   r   r   s    r#   r  obsstore._version  s-    tzz?a%djj11&&&r/   c                    U R                   nU(       d  / $ [        U5      u  U l        n[        U5      n[	        U R
                  U5        U$ r8   )r   r   r  listr   r   )r   rQ   r   s      r#   r   obsstore._all  s@    zzI!-d!3ww-TYY0r/   c                4    0 n[        XR                  5        U$ r8   )r   r   )r   r   s     r#   r   obsstore.successors  s    
z99-r/   c                4    0 n[        XR                  5        U$ r8   )r   r   )r   r   s     r#   r   obsstore.predecessors  s    yy1r/   c                4    0 n[        XR                  5        U$ r8   )r   r   )r   r   s     r#   r   obsstore.children  s    Xyy)r/   c                    XR                   ;   $ r8   )__dict__)r   attrs     r#   r   obsstore._cached  s    }}$$r/   c                   [        U5      nU R                  U-   U l        U R                  R                  U5        U R	                  S5      (       a  [        U R                  U5        U R	                  S5      (       a  [        U R                  U5        U R	                  S5      (       a  [        U R                  U5        [        U R                  U5        g )Nr   r   r   )r2  r   r   rf   r   r   r   r   r   r   r   r   r   )r   r   rawdatas      r#   r  obsstore._addmarkers  s    w-ZZ')
		!<<%%4??G4<<''T..8<<
##0TYY0r/   c                   Uc
  [        5       nUc
  [        5       nU R                  R                  5       R                  R                  n[        5       nU R
                  nU R                  nU R                  nU H%  nX;   d  X;   d  X;   d  M  UR                  U5        M'     U H-  n	U" U	5      nX;   d  X;   d  X;   d  M  UR                  U5        M/     [        5       n
UR                  5       nU(       a  [        5       nU H  nUR                  UR                  US5      5        UR                  US5       Vs/ s H  oS   (       a  M  UPM     nnUR                  U5        UR                  US5       Vs/ s H  oS   (       a  M  UPM     nnUR                  U5        M     X-  nU Vs1 s H  oS   iM	     nnX-  n
XK-  nX-  nU(       a  M  U
$ s  snf s  snf s  snf )a[  return a set of all obsolescence markers relevant to a set of
nodes or revisions.

"relevant" to a set of nodes or revisions mean:

- marker that use this changeset as successor
- prune marker of direct children on this changeset
- recursive application of the two rules on predecessors of these
  markers

It is a set so you cannot rely on order.r3   r   r   )r   r   
unfiltered	changelognoder   r   r   r   copyr  r  )r   nodesrevstonodependingnodesprecursorsmarkerssuccsmarkersr   rD  revseenmarkers	seennodesdirectcurrentr$  pruneds                   r#   relevantmarkersobsstore.relevantmarkers  s    =EE<5D%%'1166u --==D)'#  &  C#;D)'#  &  e %%'	UF'/33GR@A%-\\'2%>K%>d!%>Kf%%1%5%5gr%BO%BA$!%BOf% ( !F*01&QaD&L1!K%L%I l  LO 2s   :GG8G	G.G)r   r   r   r   r  r   r   )r3   r   NNNNNN)__name__
__module____qualname____firstlineno____doc__fields_fm1versionr   propertyr   r   r   r   __bool__r   r  r   r*  propertycacher   r  r   r   r   r   r   r  rR  __static_attributes__r3   r/   r#   r   r      s    HF 2=u "    H  A5F%N. . . ' '    
  
  
%
14r/   r   c                   U R                  SS5      n0 nUb  X#S'   [        U[        5      (       + n[        XR                  4SU0UD6nU(       a6  U(       a/  U R                  [        S5      [        [        U5      5      -  5        U$ )z(Create an obsstore instance from a repo.s   formats   obsstore-versionr   r   s5   "obsolete" feature not enabled but %i markers found!
)		configintr1   r&   r   r   warnr   rD   r2  )r   r   r   kwargsr   stores         r#   	makestorere  ?  s     LL,?@MF "/T#344HT99BxB6BE
GH$u+	
 Lr/   c                P    U R                  SS9  U  H  nU[        ;   d  M  Us  $    g)ztReturn the newest version listed in both versions and our local formats.

Returns None if no common version exists.
T)reverseN)sortr   )versionsr  s     r#   commonversionrj  R  s-    
 MM$M<H  r/   i  c                   0 n/ n[         S-  nU  HX  n[        U5      n[        U5      U-   [         :  a  / nSnUR                  U5        WR                  U5        U[        U5      -  nMZ     [	        [        U5      5       HD  u  pxSR                  [        S[        5      /U-   5      n	[        R                  " U	5      USU-  '   MF     U$ )zencode markers into a dict suitable for pushkey exchange

- binary data is base85 encoded
- split in chunks smaller than 5300 bytesr|   r   r/   r   s   dump%i)_maxpayloadrm   rD   r   rd   reversedrq   rg   _fm0versionr   	b85encode)
r   keysparts
currentlenrh   nextdatacurrentpartr   partrQ   s
             r#   _pushkeyescaperv  f  s    
 DEqJ&v.x=:%3KJLL%8$c(m#
  x/	xxuk23d:; $t 4Y_ 0 Kr/   c                d    U R                   (       d  0 $ [        [        U R                   5      5      $ )zList markers over pushkey)r   rv  rO   r   s    r#   listmarkersry  |  s"    ==	&/00r/   c                   UR                  S5      (       d(  U R                  R                  [        S5      U-  5        gU(       a(  U R                  R                  [        S5      U-  5        g[        R
                  " U5      nU R                  5          U R                  S5       nU R                  R                  XT5        U R                  5          SSS5        SSS5        g! , (       d  f       O= fSSS5        g! , (       d  f       g= f)zPush markers over pushkeys   dumps   unknown key: %rFs   unexpected old value for %rs   pushkey: obsolete markersNT)
startswithr   rb  r   r   	b85decodelockr  r   r*  invalidatevolatilesets)r   rs   oldr#  rQ   trs         r#   
pushmarkerr    s    >>'""Q)*S01
Q56<=>>#D	d&&'CD""2,##% EDDs$   C>&-C$C>$
C2	.C>>
Dc                   ^  U 4S jnU$ )zADecorator to register a function as computing the cache for a setc                v   > T[         ;   a$  Sn[        R                  " UT[         T   4-  5      eU [         T'   U $ )Ns;   duplicated registration for volatileset '%s' (existing: %r))
cachefuncsr	   r   )funcr   names     r#   	decoratorcachefor.<locals>.decorator  s?    :PC((j6F/G)GHH
4r/   r3   )r  r  s   ` r#   cacheforr    s     r/   c                ~   U R                  5       n [        R                  " SU5         U R                  (       d  [	        5       sSSS5        $ XR                  R
                  ;  a&  [        U   " U 5      U R                  R
                  U'   U R                  R
                  U   sSSS5        $ ! , (       d  f       g= f)zuReturn the set of revision that belong to the <name> set

Such access may compute the set and cache it for future usez
getrevs %sN)rB  r   timedcmr   	frozensetr   r  )r   r  s     r#   getrevsr    s     ??D	lD	)}}; 
*	) }}+++)3D)9$)?DMM  &}}##D) 
*	)	)s   B.AB..
B<c                n    SU R                   ;   a%  U R                  R                  R                  5         gg)zRemove all obsolescence related cache from a repo

This remove all cache in obsstore is the obsstore already exist on the
repo.

(We could be smarter here given the exact event that trigger the cache
clearing)r   N)
_filecacher   r   r  rx  s    r#   clearobscachesr    s+     doo%""$ &r/   c                V    U R                   R                  U [        R                  5      $ )z-the set of mutable revision in the repository)_phasecache	getrevsetr   relevant_mutable_phasesrx  s    r#   _mutablerevsr    s!    %%dF,J,JKKr/      obsoletec                   ^^ U R                   R                  m[        U 5      nU R                  R                  R
                  m[        UU4S jU 5       5      $ )zthe set of obsolete revisionsc              3  R   >#    U  H  nT" T" U5      5      (       d  M  Uv   M     g 7fr8   r3   )r:   r   getnodeisobss     r#   r<   &_computeobsoleteset.<locals>.<genexpr>  s     ?	1U71:->QQ	s   '	')rC  rD  r  r   r   __contains__r  )r   	notpublicr  r  s     @@r#   _computeobsoletesetr    sD     nn!!GT"IMM$$11E?	???r/      orphanc                   U R                   R                  n[        U 5      n[        U S5      nX#-
  n[	        5       n[        U5       H0  nU" U5       H!  nXs;   d  Xu;   d  M  UR                  U5          M.     M2     [        U5      $ )z7the set of non obsolete revisions with obsolete parentsr  )rC  
parentrevsr  r  r   rO   r   r  )r   pfuncmutableobsoleteothersunstabler   r;   s           r#   _computeorphansetr    sz     NN%%E4 Gt[)HFuHF^ qA}Q   Xr/   	   suspendedc                   ^ U R                   R                  [        U S5      5      m[        U4S j[        U S5       5       5      $ )z9the set of obsolete parents with non obsolete descendantsr  c              3  6   >#    U  H  oT;   d  M
  Uv   M     g 7fr8   r3   )r:   r   	suspendeds     r#   r<   '_computesuspendedset.<locals>.<genexpr>  s     M :19nQQ :s   		r  )rC  	ancestorsr  r  )r   r  s    @r#   _computesuspendedsetr    s8     ((y)ABIMk :MMMr/   s   extinctc                4    [        U S5      [        U S5      -
  $ )z<the set of obsolete parents without non obsolete descendantsr  r  )r  rx  s    r#   _computeextinctsetr    s     4%l(CCCr/   s   phasedivergentc                   [        5       nU R                  R                  n[        R                  nU R
                  nUR                  R                  nUR                  nU R                  n[        [        U 5      [        U S5      -
  5      nU HY  n	U" U	5      n
[        R                  " Xz/[        S9 H0  nU" U5      nUc  M  U" X5      U::  d  M  UR!                  U	5          MW     M[     [#        U5      $ )z3the set of revs trying to obsolete public revisionsr  )ignoreflags)r   r  phaser   publicrC  indexget_revrD  r   rO   r  r  r
   allpredecessors	bumpedfixr   r  )r   bumpedr  r  cltorevrH  r   
candidatesrL  rD  pnodeprevs                r#   _computephasedivergentsetr    s     UF""E]]F	BHHEWWF}}HT*WT;-GGHJc{,,f)
E <D uT'8F'B

3
	  Vr/   s   contentdivergentc                  ^ [        5       nU R                  n0 nU R                  R                  n[	        [        U 5      [        U S5      -
  5      nU GH  nU" U5      mUR                  R                  TS5      n[        U5      n[        5       n	U(       d  MF  UR                  5       S   n
X;   a  M#  U	R                  U
5        X;  a  [        R                  " X
US9  X:    Vs/ s H  o(       d  M  UPM     nn[        U5      S:  a-  [        U4S jU 5       5      (       a  UR                  U5        M  UR                  UR                  R                  U
S5      5        U(       a  M  GM     [!        U5      $ s  snf )zHthe set of rev that compete to be the final successors of some revision.r  r3   r   )cacher   c              3  8   >#    U  H  nTU;  d  M  Uv   M     g 7fr8   r3   )r:   nrD  s     r#   r<   ._computecontentdivergentset.<locals>.<genexpr>"  s     %HA$a-aas   
	)r   r   rC  rD  rO   r  r  r   r  rG   r   r
   successorssetsrD   anyr  r  )r   	divergentr   newermaprH  r  rL  r   	toprocessseenr   r  newerrD  s                @r#   _computecontentdivergentsetr    s;    I}}HH^^  FT*WT;-GGHJc{$$((r2I	ui==?1%D|HHTN#&&tB (41!QE4 5zA~#%H%H"H"Hc"X2266tR@A i & Y 5s   $
E:2E:c                   [         R                  " U5      nU S   U S   -    HD  nUR                  SUR                  5       -  5        UR                  UR	                  5       5        MF     [        UR                  5       5      S S $ )Nr   r   r     )r   sha1r  rL  rD  r   digest)relationuser
folddigestr;   s       r#   
makefoldidr  )  sp    t$Ja[8A;&%!%%'/*!&&(# '
 z  "#BQ''r/   c                2   Uc  0 nSU;  aV  U R                   R                  SS5      =(       d    U R                   R                  5       n[        R                  " U5      US'   U R                   R                  SS5      nU(       a  U(       a  XTS'   U R                   R                  SS5      nU R                  S	5       n	/ n
U GH  nUS
   n[        U[        5      (       d  U4n[        U5      S:  a9  [        US   5      S:w  a'  Sn[        R                  " U[        US   5      -  5      eSn[        U5      nSU:  a  [        XS   5      n[        US5       GHI  u  nnUS   nUR                  5       n[        U5      S:  a  UR                  US   5        Ub  UUS'   SU-  US'   SU-  US'   UR!                  5       (       d!  [        R"                  " [%        S5      U-  SS9eUR'                  5       n[        S U 5       5      nSnU(       d   [        S UR)                  5        5       5      nUU;   a"  [        R"                  " [%        S5      U-  5      eU(       a-  [*        R,                  " UU5      nSU-  U[*        R.                  '   U
R1                  UUUU45        GML     GM     U
 HN  nUu  nnnnU R2                  R5                  U	UUUUUUU R                   S9  U R6                  R9                  5         MP     SSS5        g! , (       d  f       g= f)a  Add obsolete markers between changesets in a repo

<relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
tuple. `old` and `news` are changectx. metadata is an optional dictionary
containing metadata for this marker only. It is merged with the global
metadata specified through the `metadata` argument of this function.
Any string values in metadata must be UTF-8 bytes.

Trying to obsolete a public changeset will raise an exception.

Current user and date are used except if specified otherwise in the
metadata attribute.

This function operates within a transaction of its own, but does
not take any lock on the repo.
Ns   userr  s   user.obsmarkerr   s   evolution.track-operations	   operations   evolution.effect-flagss   add-obsolescence-markerr   r   s/   Fold markers can only have 1 successors, not %dr|   s   fold-idr  s   fold-idxs	   fold-sizes$   cannot obsolete public changeset: %ss    see 'hg help phases' for details)hintc              3  @   #    U  H  oR                  5       v   M     g 7fr8   rD  )r:   rZ   s     r#   r<    createmarkers.<locals>.<genexpr>y  s     51ffhh   c              3  @   #    U  H  oR                  5       v   M     g 7fr8   r  r9   s     r#   r<   r  |  s     !CNq&&((Nr  s#   changeset %s cannot obsolete itself)r_   r^   r[   r   )r   r   usernamer   	fromlocalr   r  r   rL   rD   r	   r   r  rd   rE  r  r  rE   r   rD  r_   r
   geteffectflagEFFECTFLAGFIELDr   r   r  filteredrevcacher  )r   	relationsr  r^   r[   	operationluseruseoperationsaveeffectflagr  
markerargsrelr   r   foldidfoldsizefoldidxr   rY   localmetadatanprecnsucsnpare
effectflagargss                            r#   createmarkersr  3  s   ( hGGNN8%67M477;K;K;M 	 %..u5 77%%5L 	!* WW''2N 
		4	5
Cq6LlE22 ,< 1$SV)9H,,S3s1v;->??F<(H8|#C'):;!*<!;1v (s8a<!((Q0%06M*-16M+.27(2BM,/||~~++ABTI@  		555!!CDLLN!CCEE>++@ADH 
 " ")!6!6tT!BJ=BZ=OM'"9"9: !!5%"FGI "< d D15.E5%MM  &77 ! 	 !!'') i 
6	5	5s   =IL
LrT  )r   NNN)\rY  
__future__r   rM   r   r   i18nr   rD  r   r   r   r   r	   r
   r   r   r   r   utilsr   r   	importmodr   packrg   r   r@   calcsizer   r^  r&   r'   r(   r)   r$   r.   r1   r  rb   rn  rA   rC   r?   rB   r`   rm   re   rF   r[  r   r   r   r   r   r   r~   r   r   r   r   r   r   r   nogcr   r   r   r   r   r   r   r   re  rj  rl  rv  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r3   r/   r#   <module>r     s  <| #      
 

9
%
--OO	"" $ # '  <.$ 	!!, 	i 	(#5:p+*	GX 	\* ~. i 	\* <M~.b# /#67/#67( 
A 
A % ! &+K   8 8
 : : 8 8 \ \~&
" ,1  


*&
%L
 
+@ @ 
) " 
,N N 
*D D
 

 4 

   :( BFh*r/   