
    6h                    f   S SK Jr  S SKrS SKrSSKJr  SSKJr  SSKJ	r
JrJrJr  SSKJr  SSKJrJr  \R(                  " S	S
S9rS rS rS rS+S jrS+S jrS rS rS rS rS rS r S r!Sr"Sr#S r$S r%S r&S r'S r(S,S jr)S r*S r+S+S  jr,S! r-S" r.S# r/ " S$ S%5      r0S& r1S' r2S( r3S) r4S* r5g)-    )annotationsN   )_)nullrev)matchpathutilpolicyutil)
stringutil)flagutilsidedatacopy_tracingT)pyo3c                ~    [        UR                  5       5       H   u  p4X4:X  a  X#	 M  X@;  a  X#	 M  X1;  d  M  X#	 M"     g)z)filters out invalid copies after chainingN)listitems)srcdsttkvs        2/usr/lib/python3/dist-packages/mercurial/copies.py_filterr   "   s8    , QWWY6\\      c                ~    U R                  5       nUR                  5        H  u  p4U R                  XD5      X#'   M     U$ )z.chain two sets of copies 'prefix' and 'suffix')copyr   get)prefixsuffixresultkeyvalues        r   _chainr#   C   s4    [[]Flln
jj. %Mr   c                   U R                  5        Hl  nUR                  5       nUR                  US5      UR                  5       :X  a  Us  $ U(       d  MD  UR                  US5      UR                  5       :X  d  Mj  Us  $    g)zreturn file context that is the ancestor of fctx present in ancestor
manifest am

Note: we used to try and stop after a given limit, however checking if that
limit is reached turned out to be very expensive. we are better off
disabling that feature.N)	ancestorspathr   filenode)fctxambasemffr&   s        r   
_tracefiler,   K   s`     ^^vvx66$-K6fjjt,

<K r   c                    U R                   nUR                  5       R                  5       n[        U5       H=  nUR	                  U5      R
                  (       a  U(       d  M,  U" U5      (       a  M;  X4	 M?     U$ N)dirstatecopiesr   r   	get_entrytracked)repor   dscr   s        r   _dirstatecopiesr6   [   sV    	B
		A!W||A&&55q  Hr   c                `    U R                  5       nUR                  5       nUR                  X2S9$ )zComputes which files are in b but not a.
This is its own function so extensions can easily wrap this call to see what
files _forwardcopies is about to process.
r   )manifest
filesnotin)abr   mambs        r   _computeforwardmissingr?   d   s+    
 
B	
B===))r   c                h    U R                   S:X  a  gU R                  R                  SS5      nSnX;   $ )z9Checks if we should use changeset-centric copy algorithms   changeset-sidedataT   experimentals   copies.read-from)s   changeset-onlys   compatibility)filecopiesmodeuiconfig)r3   readfromchangesetsources      r   usechangesetcentricalgorH   n   s7    33ww~~o/BCH;O&&r   c                   U R                   n[        U5      (       a  [        XU5      $ UR                  R                  =(       a    UR                  R                  SS5      nUR                  R                  nU(       a  U" SX4-  5        U R                  5       nUc  SOUR                  5       n0 n	Un
UR                  5       U :X  a`  UR                  5       R                  5       [        :X  a:  [        R                  " UR                  5       5      n[        R                  " X;5      n
UR                  R                  SS5      (       a6  [!        UR#                  U5      5      nU(       a  U" S[%        U5      -  5        O%['        XU
S9nU(       a  U" S[%        U5      -  5        U R                   R(                  R+                  UR                  5       /S	S
9n[-        U5       H  nU(       a  U" SU-  5        X   nXl        U(       a  [0        R2                  " 5       n[5        XU5      nU(       a  U(       a  U" SU-  5        UX'   U(       d  Mm  U" S[0        R2                  " 5       W-
  -  5        M     U	$ )z@Like _forwardcopies(), but b.rev() cannot be None (working copy)   devel   debug.copiess3   debug.copies:    looking into rename from %s to %s
Ns   copy-tracing.trace-all-filess+   debug.copies:      searching all files: %d
r8   s/   debug.copies:      missing files to search: %d
T	inclusives&   debug.copies:        tracing file: %s
s%   debug.copies:          rename of: %s
s(   debug.copies:          time: %f seconds
)_reporH   _changesetforwardcopiesrD   	debugflag
configbooldebugr9   p1p2revr   matchmodexactfilesintersectmatchersr   walklenr?   	changelogr%   sorted_ancestrycontextr
   timerr,   )r;   r<   baser   r3   rR   dbgr)   r*   cmforwardmissingmatchfilesmatchermissingancestrycontextr+   r(   startopaths                     r   _committedforwardcopiesri   w   s    77Dt$$&qU33GGO$''"4"4X"OE
''--CCqfLM	
B\Tt}}F
 
B  ttv{qttvzz|w.~~aggi0&88Mww($CDDqvve}%?#g,NO(5HICg,
 gg''111557)t1LOG_:Q>?t /JJLE4V,=EFBE5<::<%') $ Ir   c                   ^^^^ U R                   nUR                  mUR                  m[        R                  mUR
                  m[        b  UUUU4S jnU$ UUUU4S jnU$ )zreturns a function that returns the following data given a <rev>"

* p1: revision number of first parent
* p2: revision number of first parent
* changes: a ChangingFiles object
c                   > T" U 5      u  pT" U 5      T-  (       a0  T" U 5      R                   R                  [        R                  5      nOS nXU4$ r.   )	_sidedatar   sidedatamodSD_FILES)rU   rS   rT   rawHASCOPIESINFOchangelogrevisionflagsparentss       r   revinfo _revinfo_getter.<locals>.revinfo   sJ    S\FBSzM)',66::;;O;OPC= r   c                j   > T" U 5      u  pT" U 5      T-  (       a  T" U 5      R                   nOS nXU4$ r.   )changes)rU   rS   rT   rw   rp   rq   rr   rs   s       r   rt   ru      s:    S\FBSzM)+C088G$$r   )r\   
parentrevsrr   r   REVIDX_HASCOPIESINFOrq   rustmod)r3   r   clrt   rp   rq   rr   rs   s       @@@@r   _revinfo_getterr|      s_     
BmmGHHE11M,,	! 	!$ N	% 	% Nr   c                   ^ ^ 0 mUU 4S jnU$ )z&return a cached version of is_ancestorc                h   > X:  a  gX:X  a  gX4nTR                  U5      nUc  T" X5      =nTU'   U$ )NFT)r   )ancdescr!   retcacheis_ancestors       r   _is_ancestor(cached_is_ancestor.<locals>._is_ancestor   sD    :[kiin;*355C%*
r    )r   r   r   s   ` @r   cached_is_ancestorr      s    E	 r   c           
        U R                  5       [        UR                  5       4;   a  0 $ U R                  5       R                  5       nUR                  nUR
                  nUR                  n[        [        4nUR                  U R                  5       /SS9nUR                  U R                  5       /UR                  5       /S9n	[        5       n
SnUR                  R                  SS5      nU	 H^  nU" U5      nX:X  a  SnM  Uu  nnU[        :w  a  X;   a  U
R                  U5        U[        :w  d  ME  UU;   d  MM  U
R                  U5        M`     U
(       d  0 $ U(       a]  [        U
5      n
[        U
5      nUR                  5       /nUR                  UUU
SS9n[        U5      nU	 Vs/ s H  oU;   d  M
  UPM     n	nUR                   S:X  a  U
 Vs0 s H  oS	_M     nnU	 HA  nUR#                  U5       H)  nU[        :X  a  M  S	UU'   UU;   d  M  UU==   S
-  ss'   M+     MC     [%        X25      nUR                  R'                  5          [)        U	UUR                  5       UUUU5      sS S S 5        $ U
 Vs0 s H  o/ _M     nnU	 HH  nUR#                  U5       H0  nU[        :X  a  M  / UU'   UU;   d  M  UU   R+                  U5        M2     MJ     U	R-                  5       nUUR                  5       :X  d   eU	R/                  U
5        U	R1                  5         [3        U5      n[5        U	UUR                  5       UX%5      $ s  snf s  snf ! , (       d  f       g = fs  snf )NTrL   )commonheadsFrJ   s   copy-tracing.multi-thread)includepathrA   r   r   )rU   r   r3   
unfilteredr\   isancestorrev_uncheckedparentrevsr%   findmissingrevssetrD   rQ   addr   minreachablerootsrC   rx   r|   reading_combine_changeset_copiesappendpopextendsort_revinfo_getter_extra_combine_changeset_copies_extra)r;   r<   r   r3   r{   
isancestorrs   graph_rootsr%   revsrootshas_graph_rootsmulti_threadrpsrS   rT   mhroots_to_headchildren_countprt   childrenxs                            r   rO   rO      s   uuw7AEEG$$	668 D	B!!J %%GG$KaeegY$7IaeegYquuwi@DEEO77%%h0LML QZ"OFB W}		"W}y		"  	 UJUUWI))!Q4)HM*64a#54633 )..1Q$.A]]1%<$%q!&"1%*% &  "$.^^##%, &% $))5arE5)A]]1%< =QK&&q) &  HHJAEEG||E		'-.(AEEGWe
 	
a 7 / &% *s$   *	M7MM
M:M 
Mc           	        UR                  5       n[        b"  [        R                  [        U 5      XX65      nGO[	        U5      n0 n	U  GH  n
U" U
5      u  pnSnSU4SU44 GHp  u  nnU[
        :X  a  M  UR                  U5      nUc  M)  US-  nUUU'   U(       a  U	R                  US5      nOU	R                  US5      nUc  0 =nnOU(       a  UR                  5       nOUnUb  0 nUS:X  a  UR                  nOUS:X  a  UR                  nU(       aW  UR                  5       nUR                  5        H,  u  nnUR                  U5      nUb  US   b  US   nU
U4UU'   M.     UULd   eUR                  (       a7  UR                   H'  nUU;   d  M  UUL a  UR                  5       nU
S4UU'   M)     Uc  UnGMY  US:X  d   e[        UUUUU
5      nGMs     XU
'   GM     0 nX   nUc   eUR                  5        H  u  nu  nnUc  M  UUU'   M     U(       d2  [        UR                  5       5       H  nU" U5      (       a  M  UU	 M     U$ )a  combine the copies information for each item of iterrevs

revs: sorted iterable of revision to visit
children_count: a {parent: <number-of-relevant-children>} mapping.
targetrev: the final copies destination revision (not in iterrevs)
revinfo(rev): a function that return (p1, p2, p1copies, p2copies, removed)
match: a matcher

It returns the aggregated copies information for `targetrev`.
Nr      )alwaysrz   combine_changeset_copiesr   r   r   r   r   r   copied_from_p1copied_from_p2r   removed_merge_copies_dictkeys)r   r   	targetrevrt   r   r   r   alwaysmatchfinal_copies
all_copiescurrent_revrS   rT   rw   current_copiesparent
parent_revremaining_childrenr0   	newcopieschildcopiesdestsourceprevr+   targetrev_itemsttfilenames                               r   r   r   ^  s    ,,.K77J7
 (
3

K%k2OBG!N )*2wB&8"
(%3%7%7
%C"%-"a'"-?z*%'^^J=F'^^J=F>)++I' &I &I&"$K{&-&<&<1&-&<&<"$*KKM	,7,=,=,?LD&#)::f#5D#/DG4G)-a/:F.CIdO	 -@
  )666!(A I~#,#6 17I0;T/B	! "1 ")%.N "Q;&;%7!&"#&Nu '9B '5{#M  R $/***"1"7"7"9D,2v!%+T" #: \..01H?? * 2 r   r   c                    UR                  5        Hc  u  pVU R                  U5      nUc  X`U'   M  [        X2XWU5      u  pU	(       a  U[        :X  a
  XFS   4X'   MI  XGS   4X'   MS  U[        :X  d  M_  X`U'   Me     U $ )a  merge two copies-mapping together, minor and major

In case of conflict, value from "major" will be picked.

- `isancestors(low_rev, high_rev)`: callable return True if `low_rev` is an
                                    ancestors of `high_rev`,

- `ismerged(path)`: callable return True if `path` have been merged in the
                    current revision,

return the resulting dict (in practice, the "minor" object, updated)
r   )r   r   _compare_values
PICK_MAJOR)
minormajorr   rw   current_merger   r"   otherpick	overwrites
             r   r   r     s     {{}		$=$K-T%OD :%#0(";EK#0(";EK##d % Lr   c                   Uu  pVUu  pxXW:X  a  Xh:X  d   e[         S4$ U b  Ub  Uc  X R                  ;   a  [        S4$ U b  Ub  Uc  X R                  ;   a  [        S4$ U" Xu5      (       a"  U b  X R                  ;   a  [        S4$ [        S4$ U" XW5      (       a"  U b  X R                  ;   a  [        S4$ [        S4$ Uc  [        S4$ Uc  [        S4$ [        S4$ )zcompare two value within a _merge_copies_dict loop iteration

return (pick, overwrite).

- pick is one of PICK_MINOR, PICK_MAJOR or PICK_EITHER
- overwrite is True if pick is a return of an ambiguity that needs resolution.
FT)PICK_EITHERsalvaged
PICK_MINORr   merged)	rw   r   r   r   r   major_ttmajor_valueminor_ttminor_values	            r   r   r     s    "H!H)))E!!#$$$ 4#$$$ 4	H	'	'4>>#9 t##u$$	H	'	'4>>#9 t##u$$		4		4 4r   c                X   ^ ^^ T R                   nUR                  mU 4S jmUUU 4S jnU$ )a;  return a function that return multiple data given a <rev>"i

* p1: revision number of first parent
* p2: revision number of first parent
* p1copies: mapping of copies from p1
* p2copies: mapping of copies from p2
* removed: a list of removed files
* ismerged: a callback to know if file was merged in that revision
c                "   >^ TU    mUU4S jnU$ )Nc                   > U TR                  5       ;  a  gTU    nUR                  R                  UR                  5      nSnU H  nUTR                  :w  d  M  US-  nM     US:  $ )NFr   r   r   )rX   _filelogrs   	_filenodenullid)r&   r(   rs   
nb_parentsnctxr3   s        r   ismerged=_revinfo_getter_extra.<locals>.get_ismerged.<locals>.ismerged>  se    399;&t9Dmm++DNN;GJ#!OJ  ?"r   r   )rU   r   r   r3   s     @r   get_ismerged+_revinfo_getter_extra.<locals>.get_ismerged;  s    3i		# r   c                v   > T" U 5      u  pT	U    nUR                   u  pEUR                  5       nXXEUT" U 5      4$ r.   )_copiesfilesremoved)
rU   rS   rT   r   p1copiesp2copiesr   r   rs   r3   s
          r   rt   &_revinfo_getter_extra.<locals>.revinfoK  sE    3i [[""$x7L4EEEr   )r\   rx   )r3   r{   rt   r   rs   s   `  @@r   r   r   .  s)     
BmmG F Nr   c           	     ^   0 nUR                  5       nU  GHb  nUR                  US5      n	U	c  0 n	[        X   5       GH5  u  pU" U5      u  ppnnX:X  a  SnUnOX:X  d   eSnUnU(       d5  UR                  5        VVs0 s H  u  nnU" U5      (       d  M  UU_M     nnnU	nU(       aW  U	R	                  5       nUR                  5        H,  u  nnU	R                  U5      nUb  US   b  US   nUU4UU'   M.     UU	Ld   eU H'  nUU;   d  M  UU	L a  U	R	                  5       nUS4UU'   M)     UR                  U5      nUc  UXk'   GM  US:X  a  [        UUUU5        GM#  [        UUUU5        UXk'   GM8     GMe     0 nXb   R                  5        H  u  nu  nnUc  M  UUU'   M     U$ s  snnf )zuversion of `_combine_changeset_copies` that works with the Google
specific "extra" based storage for copy informationNr   r   )r   r   	enumerater   r   r   _merge_copies_dict_extra)r   r   r   rt   r   r   r   r   r   r0   ir5   rS   rT   r   r   r   r   r   r   r   r   r   r   r   r   r+   othercopiesr   r   s                                 r   r   r   U  s   
 J,,.K4(>Fhk*DA<CAJ9BHw&ww&-8->->-@-@cE#JHCH-@   I"KKM	$/$5$5$7LD&!::f-D'DG,?!%a'(&kIdO	 %8
 !...	> F* %+KKM	$%t9IaL  %..+K" )
 Q;,#Y
H -!;
H %.JMc + p L(399;lr6!'L < [s   ?F)
F)
c                    UR                  5        H\  u  pEU R                  U5      nUc  XPU'   M  US   nUS   nUS   US   :X  a  M7  Xx:X  d  U" Xx5      (       a  U" U5      (       d  MX  XPU'   M^     g)znversion of `_merge_copies_dict` that works with the Google
specific "extra" based storage for copy informationNr   r   )r   r   )	r   r   r   r   r   r"   r   new_ttother_tts	            r   r   r     sw     {{}		$=$K1XFQxHQx58# "!&33D>>#d! %r   c                    Uc  U nU R                  5       R                  U5      nUR                  5       c<  [        XR	                  5       X#5      n[        U[        UR                  U5      5      nU$ [        XX#5      nU$ )z<find {dst@b: src@a} copy mapping where a is an ancestor of b)r3   narrowmatchrU   ri   rS   r#   r6   rN   )r;   r<   r`   r   rb   r0   s         r   _forwardcopiesr     sr     |FFH  'Euuw$Q<OAGGU;< M )t;Mr   c                    U R                   R                  R                  SS5      S:X  a  0 $ [        X5      n[	        X0U5      $ )zfind renames from a to brB   	   copytraces   off)rN   rD   rE   r   _reverse_renames)r;   r<   r   r0   s       r   _backwardrenamesr     s=    wwzz,76A	
 A!FFu--r   c                    0 n[        U R                  5       5       H&  u  pEU(       a  U" U5      (       d  M  XQ;   a  M"  XCU'   M(     U$ )z>given copies to context 'dst', finds renames from that context)r]   r   )r0   r   r   r   r   r   s         r   r   r     sD    
 	Av||~&q8! ' Hr   c                   U R                   nUR                  R                  =(       a    UR                  R                  SS5      nU(       a  UR                  R	                  SX4-  5        X:X  d  U (       a  U(       d  0 $ UR                  5       c@  XR                  5       :X  a-  U(       a  UR                  R	                  S5        [        X25      $ UR                  U 5      nXP:X  a-  U(       a  UR                  R	                  S5        [        XUS9nOXQ:X  a-  U(       a  UR                  R	                  S5        [        XUS9nOU(       a  UR                  R	                  S	5        SnUR                  5       [        :w  a  U n[        XP5      n[        XQXrS9n	[        U5      [        U	5      -  n
U
 H-  nUR                  U5      U	R                  U5      :X  d  M)  X	 X	 M/     [        XU5      n[        UU	5      n[!        XU5        U$ )
z5find {dst@y: src@x} copy mapping for directed comparerJ   rK   s-   debug.copies: searching copies from %s to %s
Ns$   debug.copies: search mode: dirstate
s#   debug.copies: search mode: forward
r8   s$   debug.copies: search mode: backward
s$   debug.copies: search mode: combined
)rN   rD   rP   rQ   rR   rU   rS   r6   ancestorr   r   r   r   r   r   r#   r   )r   yr   r3   rR   r;   r0   r`   x_copiesy_copies	same_keysr   x_backward_renamess                r   
pathcopiesr    s   77DGGO$''"4"4X"OE=F	
 	vQa	uuw1;GGMMBCt++	

1AvGGMMABE2	
GGMMBC!!e4GGMMBC557gD!!'!!:MCM1	A||A(,,q/1KK  .h5A
 A&Mr   c                   U(       a  U(       a  X:X  a  [        5       [        5       0 4$ UR                  5       R                  5       nUR                  5       cK  UR                  5       U R                  R                  5       :X  a  [        [        X5      5      [        5       0 4$ U R                  R                  SS5      n[        R                  " U5      SL a  [        5       [        5       0 4$ [        U 5      (       a  [        XX#5      $ US:X  a)  [        XU5      (       a  [        XX#5      $ [        XX#5      $ [        XX#5      $ )az  
Finds moves and copies between context c1 and c2 that are relevant for
merging. 'base' will be used as the merge base.

Copytracing is used in commands like rebase, merge, unshelve, etc to merge
files that were moved/ copied in one merge parent and modified in another.
For example:

o          ---> 4 another commit
|
|   o      ---> 3 commit that modifies a.txt
|  /
o /        ---> 2 commit that moves a.txt to b.txt
|/
o          ---> 1 merge base

If we try to rebase revision 3 on revision 4, since there is no a.txt in
revision 4, and if user have copytrace disabled, we prints the following
message:

```other changed <file> which local deleted```

Returns a tuple where:

"branch_copies" an instance of branch_copies.

"diverge" is a mapping of source name -> list of destination names
for divergent renames.

This function calls different copytracing algorithms based on config.
rB   r   Fs
   heuristics)branch_copiesr3   r   noder/   rS   r6   rD   rE   r   	parseboolrH   _fullcopytracing_isfullcopytraceable_heuristicscopytracing)r3   c1c2r`   r   copytracings         r   mergecopiesr    s   B R2833'')'')K 
wwyRWWY$--*:*:*<</$<=O
 	
 ''..,?KK(E1 33t$$"33
 m#  $//#Db77%d99"33r   c                J   UR                  5       c  UR                  5       nUR                  5       (       am  UR                  5       (       aX  U R                  R	                  SS5      n[        U R                  SUR                  5       UR                  5       5      5      nXC:  $ g)a  Checks that if base, source and destination are all no-public branches,
if yes let's use the full copytrace algorithm for increased capabilities
since it will be fast enough.

`experimental.copytrace.sourcecommitlimit` can be used to set a limit for
number of changesets from c1 to base such that if number of changesets are
more than the limit, full copytracing algorithm won't be used.
rB   s   copytrace.sourcecommitlimit   %d::%dF)rU   rS   mutablerD   	configintr[   r   )r3   r	  r`   sourcecommitlimitcommitss        r   r  r  Q  s|     
vvxUUW	zz|| GG--;
 dii	488:rvvx@A**r   c	                    X;  a  X;  a  XU '   g g X;  a  g X@   X0   :w  a  [        XP   X`   5      (       d  g X@   X0   :w  d$  UR                  U 5      UR                  U 5      :w  a  U H  n	XU	'   M	     g g r.   )_relatedrr   )
r   dsts1m1m2r>   r
  r`   r   renamedeleter   s
             r   _checksinglesidecopiesr  e  s     }= %  
 		BG	HRWdi$@$@	BG	rxx}=CI   >r   c                  *    \ rS rSrSr SS jrS rSrg)r  iz  a  Information about copies made on one side of a merge/graft.

"copy" is a mapping from destination name -> source name,
where source is in c1 and destination is in c2 or vice-versa.

"movewithdir" is a mapping from source name -> destination name,
where the file at source present in one context but not the other
needs to be moved to destination by the merge process, because the
other context moved the directory it is in.

"renamedelete" is a mapping of source name -> list of destination
names for files deleted in c1 that were renamed in c2 or vice-versa.

"dirmove" is a mapping of detected source dir -> destination dir renames.
This is needed for handling changes to new files previously grafted into
renamed directories.
Nc                p    Uc  0 OUU l         Uc  0 OUU l        Uc  0 OUU l        Uc  0 U l        g UU l        g r.   r   r  dirmovemovewithdir)selfr   r  r  r  s        r   __init__branch_copies.__init__  sA     ,BD	"."6BL$_r'!,!42+r   c           	     x    SU R                   < SU R                  < SU R                  < SU R                  < S3	$ )Nz<branch_copies
  copy=z
  renamedelete=z
  dirmove=z
  movewithdir=z
>r  )r  s    r   __repr__branch_copies.__repr__  s.     		!!  	
r   )r   r  r  r  )NNNN)__name__
__module____qualname____firstlineno____doc__r   r#  __static_attributes__r   r   r   r  r  z  s    & GKF	
r   r  c                  ^ ^$^%^&^'^( UR                  5       m&UR                  5       m'UR                  5       m([        X15      n[        X25      nU(       d  U(       d  [        5       [        5       0 4$ 0 n0 nUR                  5        H&  u  pUR	                  U	/ 5      R                  U5        M(     UR                  5        H&  u  pUR	                  U	/ 5      R                  U5        M(     0 n
0 n0 n0 n0 n[        U5      [        U5      -  nU H  n	UR                  U	5      nUR                  U	5      nU(       a  U(       a  U	T&;  aN  U	T';  aH  [        U5      n[        U5      nUU-  (       a  UU-   H  nXU'   XU'   M     Mu  [        UU-  5      X'   M  U	T&;   a4  U	T';   a,  [        U5      n[        U5      nUU-   H  nXU'   XU'   M     M  M  M  U(       a  [        U	UT&T'T(X#X5	        M  U(       d  M  [        U	UT'T&T(XX5	        M     / m%U%U&U'U(U 4S jm$U$4S jnU$4S jnT R                  R                  (       Ga  U" 5       nU" 5       nSnU(       a2  T R                  R                  SUS-  SR                  U5      4-  5        U(       a2  T R                  R                  SUS-  SR                  U5      4-  5        [        5       n[        5       nUR                  5        H  nUR                  U5        M     UR                  5        H  nUR                  U5        M     UR                  5        H  nUR                  U5        M     T R                  R                  S	5        SU4S
U44 H  u  nnU(       d  M  T R                  R                  SU-  5        [        U5       HP  nSnUU
;   d  UU;   a  US-  nUU;   a  US-  nUU;   a  US-  nT R                  R                  SUU   UU4-  5        MR     M     AAT R                  R                  S5        [!        T XUU5      u  nn[!        T X+UU5      u  n n![        XUU!5      n"[        XU U5      n#U"U#U4$ )a  The full copytracing algorithm which finds all the new files that were
added from merge base up to the top commit and for each file it checks if
this file was copied from another file.

This is pretty slow when a lot of changesets are involved but will track all
the copies.
c                   > T(       dl  TR                  TT	R                  5       5      nTR                  TT	R                  5       5      n[        X-
  5      n[        X!-
  5      nTR                  X445        TU    $ r.   )r:   r   r]   r   )
idx	addedinm1	addedinm2u1u2r   r  r  r>   r3   s
        r   _get_addedfiles)_fullcopytracing.<locals>._get_addedfiles  sj    b$*:*:*<=Ib$*:*:*<=I	-.B	-.BLL""Szr   c                    > T " S5      $ )Nr   r   r2  s   r   <lambda>"_fullcopytracing.<locals>.<lambda>  
    ?1%r   c                    > T " S5      $ )Nr   r   r5  s   r   r6  r7    r8  r   s     unmatched files in %ss
   %s:
   %s
s   locals   
   s   othersK     all copies found (* = to merge, ! = divergent, % = renamed and deleted):
s   remotes      on %s side:
r      *   !   %s       src: '%s' -> dst: '%s' %s
s!     checking for directory renames
)r9   r  r  r   
setdefaultr   r   r   r]   r  rD   rP   rR   joinvaluesupdate_dir_renames))r3   r	  r
  r`   copies1copies2inversecopies1inversecopies2r   r   copy1copy2divergerenamedelete1renamedelete2
allsourcesr  dsts2u1fnu2fnr0  r1  headerrenamedeleteset
divergesetdstssider0   r+   notedirmove1movewithdir2dirmove2movewithdir1branch_copies1branch_copies2r2  r   r  r  r>   s)   `                                   @@@@@r   r  r    s!    
B	B	B"G"Gw33NNMMO!!#r*11#6 $MMO!!#r*11#6 $ EEGMM^$s>'::J""3'""3'U"}BE
E

 5=$u}%(c
%(c
  - $*%%-#8GLsbyE
E
 5=C!$#J!$#J )	  ) "UBB% U"UBB%G P E  &D%DwwVV+GGMM6H#4hmmB6G"HH GGMM6H#4hmmB6G"HH %U
NN$Dd# %!((*D""4( +!((*D""4( + 	+	
 '09g2FGLD&GGMM-45F^:eDLD
?DLD'DLD6&)Q9MM $	 H GGMM78)$7DIHl)$7DIHl"5<PN"5<PN>722r   c                v   [        5       n0 nUR                  5        H  u  px[        R                  " U5      [        R                  " U5      pX;   a  M7  UR	                  U	5      (       a)  UR	                  U
5      (       a  UR                  U	5        Mv  X;   a  Xi   U
:w  a  UR                  U	5        M  XU	'   M     U H  nX;   d  M
  Xk	 M     AU(       d  0 0 4$ UR                  5        VVs0 s H  u  pUS-   US-   _M     nnnU H%  nU R                  R                  SXU   4-  5        M'     [        USS9n0 nU" 5        Hk  nUU;  d  M  U HZ  nUR                  U5      (       d  M  Xn   U[        U5      S -   nUU;  a%  UUU'   U R                  R                  SUU4-  5          Mi     Mm     UU4$ s  snnf )ai  Finds moved directories and files that should move with them.

ctx: the context for one of the sides
copy: files copied on the same side (as ctx)
fullcopy: files copied on the same side (as ctx), including those that
          merge.manifestmerge() won't care about
addedfilesfn: function returning added files on the other side (compared to
              ctx)
   /s)      discovered dir src: '%s' -> dst: '%s'
T)reverseNs'      pending file src: '%s' -> dst: '%s'
)r   r   r   dirnamehasdirr   rD   rR   r]   
startswithr[   )r3   r   r   fullcopyaddedfilesfninvalidr  r   r   dsrcddstr   r   r   ddirmove_children_firstr  r+   dfs                      r   rA  rA  -  s    eGG NN$%%c*H,<,<S,Ad?ZZ#**T"2"2KK_$!6KK !DM % <
  	2v.5mmo>odaq4xT!oG>9Q
OK	
  $GT:K^H+<<?? aAk1B~)+AG "g&  ,  K; ?s   ,F5c                  ^^^ UR                  5       c  UR                  5       nTR                  5       c  TR                  5       m[        5       nUR                  5       mU R	                  STR                  5       TR                  5       5      (       d(  U R
                  R                  S5        [        XTT5      $ TnUT:w  a|  [        UR                  5       5      S:X  a(  U R
                  R                  S5        [        XTT5      $ UR                  UR                  5       5        UR                  5       nUT:w  a  M|  0 n[        TT5      nUR                  5        H  u  pU	T;   d  M  XU'   M     UUU4S jn
U Vs/ s H  o" U5      (       d  M  UPM     nn0 nU(       Ga  [        R                  " [         5      n[        R                  " [         5      nTR#                  TR                  5       5       Hi  n[$        R&                  R)                  U5      n[$        R&                  R+                  U5      nUU   R-                  U5        UU   R-                  U5        Mk     U H  n[$        R&                  R)                  U5      n[$        R&                  R+                  U5      nUU   nUU   nUU-   nTR/                  U5      nU R
                  R1                  SS5      n[        U5      U:  a4  U R
                  R3                  [5        S5      U[        U5      4-  5        M  U H+  nUR/                  U5      n[7        UU5      (       d  M'  XU'   M-     M     [9        U5      [9        U5      0 4$ s  snf )	aA  Fast copytracing using filename heuristics

Assumes that moves or renames are of following two types:

1) Inside a directory only (same directory name but different filenames)
2) Move from one directory to another
                (same filenames but different directory names)

Works only when there are no merge commits in the "source branch".
Source branch is commits from base up to c2 not including base.

If merge is involved it fallbacks to _fullcopytracing().

Can be used by setting the following config:

    [experimental]
    copytrace = heuristics

In some cases the copy/move candidates found by heuristics can be very large
in number and that will make the algorithm slow. The number of possible
candidates to check can be limited by using the config
`experimental.copytrace.movecandidateslimit` which defaults to 100.
r  s?   switching to full copytracing as base is not an ancestor of c2
r   s0   switching to full copytracing because of merges
c                >   > U T;  =(       a    U T;   =(       a    U T;   $ r.   r   )r+   r`   r
  r  s    r   r6  (_heuristicscopytracing.<locals>.<lambda>  s    Qb[:Q$Y:17:r   rB   s   copytrace.movecandidateslimitsB   skipping copytracing for '%s', more candidates than the limit: %d
)rU   rS   r   r9   r   rD   rR   r  r[   rs   r@  rX   r   r   collectionsdefaultdictr   r:   osr&   basenamer^  r   filectxr  statusr   r  r  )r3   r	  r
  r`   changedfilesr   rC  cpr   r   filtr+   missingfilesrB  basenametofilenamedirnametofilenamero  r^  samebasenamesamedirnamemovecandidatesf2maxcandidates	candidatef1r  s     ``                     @r   r  r  t  s   2 
vvxUUW	vvxUUW5L	B99Y
BFFH55#	
  "d33
C
+s{{}"GGMMNO#Db$77CIIK(ffh + G	b	!BHHJ"9CL  ;D+7|!tAwA|L7G(44T:'33D9t}}/Aww''*Hggooa(Gx(//2g&--a0	 0 Aww''*Hggooa(G-h7L+G4K)K7N AB !GG--!AM >"]2; #n-.	/ +	ZZ	*B## *+I& ,3 B !=#92==] 8s   ?M3M3c                t   X:X  a  gU R                  5       UR                  5       p2 U R                  5       UR                  5       pTUc  [        U5      n Uc  [        U5      n U R                  5       UR                  5       pTXE:  a  [        U5      n OXT:  a  [        U5      nOX:H  $ MG  ! [         a     gf = f)a2  return True if f1 and f2 filectx have a common ancestor

Walk back to common ancestor to see if the two files originate
from the same file. Since workingfilectx's rev() is None it messes
up the integer comparison logic, hence the pre-step check for
None (f1 and f2 can only be workingfilectx's initially).
TF)r%   linkrevnextStopIteration)r~  r{  g1g2f1rf2rs         r   r  r    s     
x\\^R\\^::<S;bB;bBzz|RZZ\y"X"Xx   s   B B* (B* *
B76B7c                    [        X!5      nU R                  5       n[        X@U5        [        UR	                  5       5       H  u  pVXT;   d  M  X5	 M     UR	                  5        H  u  pxX   R                  U5        M     g)a  reproduce copies between base and ctx in the wctx

Unlike mergecopies(), this function will only consider copies between base
and ctx; it will ignore copies between base and wctx. Also unlike
mergecopies(), this function will apply copies to the working copy (instead
of just returning information about the copies). That makes it cheaper
(especially in the common case of base==ctx.p1()) and useful also when
experimental.copytrace=off.

merge.update() will have already marked most copies, but it will only
mark copies if it thinks the source files are related (see
merge._related()). It will also not mark copies if the file wasn't modified
on the local side. This function adds the copies that were "missed"
by merge.update().
N)r  rS   r   r   r   
markcopied)	wctxr   r`   
new_copiesr   r   __r   r   s	            r   graftcopiesr    sq      D&JWWYFF*% ))+,>  - $$&	S! 'r   r.   )NN)6
__future__r   rl  rn  i18nr   r  r    r   rV   r   r	   r
   utilsr   revlogutilsr   r   rm   
importrustrz   r   r#   r,   r6   r?   rH   ri   r|   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rA  r  r  r  r   r   r   <module>r     s    #  	    
 

N
6B *'@F#L$i
Xnd 

>7 t$NCL$, 	. +\C4L(*$
 $
NI3XD Nj>ZB"r   