
    	^cl                     X   d dl Z d dlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZmZ  e
j        d          Zd	 Zd
 Zd Zd(dZd(dZd Zd Zd Zd Zd Zd Zd ZdZ dZ!d Z"d Z#d Z$d Z%d Z&d)dZ'd Z(d Z)d(dZ*d Z+d Z,d  Z- G d! d"          Z.d# Z/d$ Z0d% Z1d& Z2d' Z3dS )*    N   )_)nullrev)matchpathutilpolicyutil)
stringutil)flagutilsidedatacopy_tracingc                     t          |                                          D ]\  }}||k    r||= || vr||= ||vr||= dS )z)filters out invalid copies after chainingN)listitems)srcdsttkvs        2/usr/lib/python3/dist-packages/mercurial/copies.py_filterr   "   sd    , QWWYY  166!c\\!c\\!     c                     |                                  }|                                D ]\  }}|                     ||          ||<   |S )z.chain two sets of copies 'prefix' and 'suffix')copyr   get)prefixsuffixresultkeyvalues        r   _chainr!   C   sH    [[]]Fllnn / /
Ujj..sMr   c                     |                                  D ]x}|                                }|                    |d          |                                k    r|c S |r0|                    |d          |                                k    r|c S ydS )a	  return 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     ^^  vvxx66$--KKK 	fjjt,,

<<KKK r   c                     | j         }|                                                                }t          |          D ],}|                    |          j        r|r ||          s||= -|S N)dirstatecopiesr   r   	get_entrytracked)repor   dscr   s        r   _dirstatecopiesr4   [   so    	B
		A!WW  ||A& 	5 	q 	!Hr   c                     |                                  }|                                 }|                    ||          S )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   s4    
 
B	
B==5=)))r   c                 ^    | j         dk    rdS | j                            dd          }d}||v S )z9Checks if we should use changeset-centric copy algorithms   changeset-sidedataT   experimentals   copies.read-from)s   changeset-onlys   compatibility)filecopiesmodeuiconfig)r1   readfromchangesetsources      r   usechangesetcentricalgorF   n   s<    333tw~~o/BCCH;O&&r   c                    | j         }t          |          rt          | ||          S |j        j        o|j                            dd          }|j        j        }|r |d| |fz             |                                 }|dn|                                }i }	|}
|                                | k    rj|	                                
                                t          k    r;t          j        |                                          }t          j        ||          }
|j                            dd          r@t!          |                    |                    }|r |dt%          |          z             n/t'          | ||
          }|r |dt%          |          z             | j         j                            |
                                gd	
          }t-          |          D ]}|r |d|z             ||         }||_        |rt1          j                    }t5          |||          }|r|r |d|z             ||	|<   |r" |dt1          j                    |z
  z             |	S )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
r6   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
)_reporF   _changesetforwardcopiesrB   	debugflag
configbooldebugr7   p1p2revr   matchmodexactfilesintersectmatchersr   walklenr=   	changelogr#   sorted_ancestrycontextr	   timerr*   )r9   r:   baser   r1   rP   dbgr'   r(   cmforwardmissingmatchfilesmatchermissingancestrycontextr)   r&   startopaths                     r   _committedforwardcopiesrg   w   s    7Dt$$ 4&q!U333GO$'"4"4X"O"OE
'-C NCq!fLMMM	
B\TTt}}F
 
B  ttvv{{qttvvzz||w..~aggii00&8MMw($CDD qvve}}%% 	PC?#g,,NOOO(A5HIII 	CCg,,  
 g'1115577)t1LLOG__   	@C:Q>???t / 	!JLLE4V,, 	 G=EFFFBqE 	C<:<<%')   Ir   c                     | j         }|j        |j        t          j        |j        t          	fd}nfd}|S )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
    Nc                      |           \  }} |           z  r. |           j                             t          j                  }nd }|||fS r,   )	_sidedatar   sidedatamodSD_FILES)rS   rQ   rR   rawHASCOPIESINFOchangelogrevisionflagsparentss       r   revinfoz _revinfo_getter.<locals>.revinfo   s`    WS\\FBuSzzM) '',,6::;;OPPC= r   c                 l     |           \  }} |           z  r |           j         }nd }|||fS r,   )changes)rS   rQ   rR   rt   rn   ro   rp   rq   s       r   rr   z _revinfo_getter.<locals>.revinfo   sP    WS\\FBuSzzM) ++C008G$$r   )rZ   
parentrevsrp   r   REVIDX_HASCOPIESINFOro   rustmod)r1   r   clrr   rn   ro   rp   rq   s       @@@@r   _revinfo_getterry      s     
BmGHE1M,	! 	! 	! 	! 	! 	! 	! 	! 	!	% 	% 	% 	% 	% 	% 	% 	% Nr   c                      i  fd}|S )z&return a cached version of is_ancestorc                     | |k    rdS | |k    rdS | |f}                     |          }| | |          x}|<   |S )NFT)r   )ancdescr   retcacheis_ancestors       r   _is_ancestorz(cached_is_ancestor.<locals>._is_ancestor   s[    ::5D[[4Dkiinn;*{3555C%*
r    )r   r   r   s   ` @r   cached_is_ancestorr      s/    E	 	 	 	 	 	 r   c           
      J   |                                  t          |                                 fv ri S |                                                                 }|j        }|j        }|j        }t          t          f}|                    |                                  gd          }|                    |                                  g|                                 g          }	t                      }
d}|j
                            dd          }|	D ]c} ||          }||k    rd}|\  }}|t          k    r||v r|
                    |           |t          k    r||v r|
                    |           d|
si S |rit          |
          }
t          |
          }|                                 g}|                    |||
d          t                    fd|	D             }	|j        d	k    rt#          d
 |
D                       }|	D ]?}|                    |          D ]'}|t          k    rd||<   ||v r||xx         dz  cc<   (@t'          ||          }|j                                        5  t+          |	||                                 ||||          cd d d            S # 1 swxY w Y   d S t#          d |
D                       }|	D ]J}|                    |          D ]2}|t          k    rg ||<   ||v r||                             |           3K|	                                }||                                 k    sJ |	                    |
           |	                                 t5          |          }t7          |	||                                 |||          S )NTrJ   )commonheadsFrH   s   copy-tracing.multi-thread)includepathc                     g | ]}|v |	S r   r   ).0rroots_to_heads     r   
<listcomp>z+_changesetforwardcopies.<locals>.<listcomp>)  s#    666a1#5#5#5#5#5r   r?   c              3      K   | ]}|d fV  	dS )r   Nr   r   r   s     r   	<genexpr>z*_changesetforwardcopies.<locals>.<genexpr>5  s&      44q!f444444r   r   r   c              3      K   | ]}|g fV  	d S r,   r   r   s     r   r   z*_changesetforwardcopies.<locals>.<genexpr>K  s&      //AB//////r   )rS   r   r1   
unfilteredrZ   isancestorrev_uncheckedparentrevsr#   findmissingrevssetrB   rO   addr   minreachablerootsrA   dictru   ry   reading_combine_changeset_copiesappendpopextendsort_revinfo_getter_extra_combine_changeset_copies_extra)r9   r:   r   r1   rx   
isancestorrq   graph_rootsr#   revsrootshas_graph_rootsmulti_threadr   psrQ   rR   mhchildren_countprr   childrenxr   s                           @r   rM   rM      s   uuww7AEEGG$$$	6688  D	B!J %GG$KaeeggY$77IaeeggYquuwwi@@DEEEO7%%h0LMML   WQZZ"OOFB W}}y		"W}}y		" 	 7 UJJUUWWI))!Q4)HHM**66664666333 44e44444 	+ 	+A]]1%% + +<<$%q!&&"1%%%*%%%+ "$..^##%% 		 		, 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 /////// 	* 	*A]]1%% * *<< ==QK&&q)))* HHJJAEEGG||||E		'--.(AEEGGWeZ
 
 	
s   2'J&&J*-J*c           	         |                                 }t          -t                              t          |           ||||          }nt	          |          }i }	| D ]~}
 ||
          \  }}}d}d|fd|ffD ][\  }}|t
          k    r|                    |          }|*|dz  }|||<   |r|	                    |d          }n|	                    |d          }|i x}}n|r|                                }n|}|i }|dk    r|j	        }n|dk    r|j
        }|rb|                                }|                                D ]3\  }}|                    |          }||d         |d         }|
|f||<   4||usJ |j        r-|j        D ]%}||v r||u r|                                }|
df||<   &||}@|dk    sJ t          |||||
          }]||	|
<   i }|	|         }|J |                                D ]\  }\  }}||||<   |s2t          |                                          D ]} ||          s||= |S )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      )alwaysrw   combine_changeset_copiesr   r   r   r   r   r   copied_from_p1copied_from_p2r   removed_merge_copies_dictkeys)r   r   	targetrevrr   r   r   r   alwaysmatchfinal_copies
all_copiescurrent_revrQ   rR   rt   current_copiesparent
parent_revremaining_childrenr.   	newcopieschildcopiesdestsourceprevr)   targetrev_itemsttfilenames                               r   r   r   ^  s(    ,,..K77JJ	7L
 
 (
33

 F	5 F	5K%gk22OBG!N )*2wB&8 @ @"
((%3%7%7
%C%C"%-"a'"-?z*% >'^^J==FF'^^J==F>)++I' ' &II &I&"$K{{&-&<1&-&<" 7$*KKMM	,7,=,=,?,? D DLD&#)::f#5#5D#/DG4G)-a/:F.CIdOO(6666 C!( C CA I~~#,#6#6 17I0;T/B	! ")%.NN "Q;;;;%7!&"#& &NN '5J{## $Y/***"1"7"7"9"9 	, 	,D,2v!%+T" +\..0011 	+ 	+H5?? + *r   r   c                    |                                 D ]q\  }}|                     |          }||| |<   "t          |||||          \  }}	|	r'|t          k    r||d         f| |<   S||d         f| |<   a|t          k    r|| |<   r| S )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)
    Nr   )r   r   _compare_values
PICK_MAJOR)
minormajorr   rt   current_merger   r    otherpick	overwrites
             r   r   r     s     {{}} $ $e		$=E$KK-T5% OD)  $:%%#0%(";E$KK#0%(";E$KK###dLr   c                    |\  }}|\  }}||k    r||k    sJ t           dfS | |||| j        v r	t          dfS | |||| j        v r	t          dfS  |||          r| || j        v r	t          dfS t          dfS  |||          r| || j        v r	t          dfS t          dfS |	t          dfS |	t          dfS t          dfS )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.
    FNT)PICK_EITHERsalvaged
PICK_MINORr   merged)	rt   r   r   r   r   major_ttmajor_valueminor_ttminor_values	            r   r   r     sD    "Hk!Hk8k))))E!!#G$$$ 4#G$$$ 4	Hh	'	'  47>#9#9 t##u$$	Hh	'	'  47>#9#9 t##u$$		4		4 4r   c                 @      j         }|j         fd fd}|S )aW  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                 &    |          fd}|S )Nc                     |                                  vrdS |          }|j                            |j                  }d}|D ]}|j        k    r|dz  }|dk    S )NFr   r   r   )rV   _filelogrq   	_filenodenullid)r$   r&   rq   
nb_parentsnctxr1   s        r   ismergedz=_revinfo_getter_extra.<locals>.get_ismerged.<locals>.ismerged>  sp    399;;&&ut9Dm++DN;;GJ $ $##!OJ?"r   r   )rS   r   r   r1   s     @r   get_ismergedz+_revinfo_getter_extra.<locals>.get_ismerged;  s2    3i		# 		# 		# 		# 		# 		# r   c                      |           \  }}	|          }|j         \  }}|                                }||||| |           fS r,   )_copiesfilesremoved)
rS   rQ   rR   r   p1copiesp2copiesr   r   rq   r1   s
          r   rr   z&_revinfo_getter_extra.<locals>.revinfoK  sW    B3i [(""$$2x7LL4E4EEEr   )rZ   ru   )r1   rx   rr   r   rq   s   `  @@r   r   r   .  s_     
BmG     F F F F F F F Nr   c                 V   i }                                 }| D ]a}|                    |d          }	|	i }	t          ||                   D ]-\  }
} ||          \  }}}}}}||k    rd}|}n||k    sJ d}|}|s fd|                                D             }|	}|rb|	                                }|                                D ]3\  }}|	                    |          }||d         |d         }||f||<   4||	usJ |D ]%}||v r||	u r|	                                }|df||<   &|                    |          }||||<   |dk    rt          ||||           t          ||||           |||<   /ci }||                                         D ]\  }\  }}||||<   |S )zyversion of `_combine_changeset_copies` that works with the Google
    specific "extra" based storage for copy informationNr   r   c                 2    i | ]\  }} |          ||S r   r   )r   r   r   r   s      r   
<dictcomp>z3_combine_changeset_copies_extra.<locals>.<dictcomp>k  s<       !)cEE#JJ  r   )r   r   	enumerater   r   r   _merge_copies_dict_extra)r   r   r   rr   r   r   r   r   r   r.   ir3   rQ   rR   r   r   r   r   r   r   r   r   r   r   r)   othercopiesr   r   s       `                       r   r   r   U  sm   
 J,,..K 6. 6.4((>Fhqk** 1	. 1	.DAq<CGAJJ9BHhBww&Bwwww&    -8->->-@-@   I /"KKMM	$/$5$5$7$7 2 2LD&!::f--D'DG,?!%a'(&kIdOO .... - -	>> F** %+KKMM	$%t9IaL$..++K" )
1 Q;;,#Y
H    -!;
H   %.JqMMc1	.f L(399;; ( (lr6!'Lr   c                     |                                 D ]g\  }}|                     |          }||| |<   "|d         }|d         }|d         |d         k    rE||k    s |||          r ||          r|| |<   hdS )zrversion 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     s     {{}} $ $e		$=E$KK1XFQxHQx58## (""!z&(33 #8D>> # $d!$ $r   c                 8   || }|                                                      |          }|                                Ht          | |                                ||          }t          |t          |j        |                    }nt          | |||          }|S )z<find {dst@b: src@a} copy mapping where a is an ancestor of b)r1   narrowmatchrS   rg   rQ   r!   r4   rL   )r9   r:   r^   r   r`   r.   s         r   _forwardcopiesr     s     |FFHH  ''Euuww$Qe<<OAGU;;<<(AtU;;Mr   c                     | j         j                            dd          dk    ri S t          ||           }t	          || |          S )zfind renames from a to br@   	   copytraces   off)rL   rB   rC   r   _reverse_renames)r9   r:   r   r.   s       r   _backwardrenamesr     sI    wz,776AA	
 Aq!!FFAu---r   c                     i }t          |                                           D ]\  }}|r ||          s||v r|||<   |S )z>given copies to context 'dst', finds renames from that context)r[   r   )r.   r   r   r   r   r   s         r   r   r     sb    
 	Av||~~&&  1 	q 	88!Hr   c                 <   | j         }|j        j        o|j                            dd          }|r|j                            d| |fz             | |k    s| r|si S |                                D| |                                k    r,|r|j                            d           t          ||          S |                    |           }|| k    r0|r|j                            d           t          | ||          }n||k    r/|r|j                            d           t          | ||          }n|r|j                            d	           d}|                                t          k    r| }t          ||           }t          ||||          }	t          |          t          |	          z  }
|
D ]4}|                    |          |	                    |          k    r||= |	|= 5t          || |          }t          ||	          }t!          | ||           |S )
z5find {dst@y: src@x} copy mapping for directed comparerH   rI   s-   debug.copies: searching copies from %s to %s
Ns$   debug.copies: search mode: dirstate
s#   debug.copies: search mode: forward
r6   s$   debug.copies: search mode: backward
s$   debug.copies: search mode: combined
)rL   rB   rN   rO   rP   rS   rQ   r4   ancestorr   r   r   r   r   r   r!   r   )r   yr   r1   rP   r9   r.   r^   x_copiesy_copies	same_keysr   x_backward_renamess                r   
pathcopiesr    s5   7DGO$'"4"4X"O"OE 
=AF	
 	
 	
 	AvvQvav	uuww1;; 	DGMMBCCCtU+++	

1AAvv 	CGMMABBB1E222	
a 	DGMMBCCC!!Qe444 	DGMMBCCC5577gD!!Q''!!QE:::MMCMM1	 	  	 A||A(,,q//11QKQK-h5AA
 
 Aq&Mr   c                    |r|r||k    rt                      t                      i fS |                                                                }|                                [|                                | j                                        k    r,t          t          | |                    t                      i fS | j                            dd          }t          j
        |          du rt                      t                      i fS t          |           rt          | |||          S |dk    r5t          | ||          rt          | |||          S t          | |||          S t          | |||          S )a  
    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.
    Nr@   r   Fs
   heuristics)branch_copiesr1   r   noder-   rQ   r4   rB   rC   r
   	parseboolrF   _fullcopytracing_isfullcopytraceable_heuristicscopytracing)r1   c1c2r^   r   copytracings         r   mergecopiesr    sj   B  4R 428833''))''))K 
wwyyRWWYY$-*:*:*<*<<</$<<==OO
 	
 '..,??KK((E11 33t$$ 4b"d333
 m##  b$// 	8#D"b$777%dBD999b"d333r   c                 x   |                                 |                                }|                                r}|                                ri| j                            dd          }t          |                     d|                                 |                                                     }||k     S dS )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.
    Nr@   s   copytrace.sourcecommitlimit   %d::%dF)rS   rQ   mutablerB   	configintrY   r   )r1   r  r^   sourcecommitlimitcommitss        r   r
  r
  Q  s     
vvxxUUWW	zz|| + + G--;
 
 dii	488::rvvxx@@AA***5r   c	                 (   | |vr| |vr||| <   d S d S | |vrd S ||          ||          k    rt          ||          ||                    sd S ||          ||          k    s,|                    |           |                    |           k    r
|D ]	}	| ||	<   d S d S r,   )_relatedrp   )
r   dsts1m1m2r<   r  r^   r   renamedeleter   s
             r   _checksinglesidecopiesr  e  s     "}}b== %L = 
B 		CBsG		HRWd3i$@$@		CBsG		rxx}}== 	 	CDII  >=	 	r   c                   "    e Zd ZdZ	 ddZd ZdS )r  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                 ^    |i n|| _         |i n|| _        |i n|| _        |i n|| _        d S r,   r   r  dirmovemovewithdir)selfr   r  r   r!  s        r   __init__zbranch_copies.__init__  sJ     ,BBD	"."6BBL$_rr'!,!422+r   c           	      H    d| j         d| j        d| j        d| j        d	S )Nz<branch_copies
  copy=z
  renamedelete=z
  dirmove=z
  movewithdir=z
>r  )r"  s    r   __repr__zbranch_copies.__repr__  s8     IIILLL	
 	
r   )NNNN)__name__
__module____qualname____doc__r#  r%  r   r   r   r  r  z  sL         & GKF F F F
 
 
 
 
r   r  c                 	   $%&'( |                                 &|                                 '|                                 (t          ||          }t          ||          }|s|st                      t                      i fS i }i }|                                D ].\  }}	|                    |	g                               |           /|                                D ].\  }}	|                    |	g                               |           /i }
i }i }i }i }t          |          t          |          z  }|D ]}	|                    |	          }|                    |	          }|r|r|	&vrP|	'vrLt          |          }t          |          }||z  r||z  D ]}|	|
|<   |	||<   nt          ||z            ||	<   |	&v r4|	'v r0t          |          }t          |          }||z  D ]}|	|
|<   |	||<   |rt          |	|&'(|||
|	  	         |rt          |	|'&(||||	  	         g %%&'( fd$$fd}$fd} j
        j        r |            } |            }d}|r5 j
                            d|dz  d                    |          fz             |r5 j
                            d|dz  d                    |          fz             t                      }t                      }|                                D ]}|                    |           |                                D ]}|                    |           |                                D ]}|                    |            j
                            d	           d|fd
|ffD ]~\  }}|s j
                            d|z             t          |          D ]I}d}||
v s||v r|dz  }||v r|dz  }||v r|dz  } j
                            d||         ||fz             J~~ j
                            d           t!           ||
||          \  }}t!           ||||          \  } }!t          |
|||!          }"t          ||| |          }#|"|#|fS )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                 .   s                     	                                          }                     	                                          }t          ||z
            }t          ||z
            }                    ||f           |          S r,   )r8   r   r[   r   )
idx	addedinm1	addedinm2u1u2r   r  r  r<   r1   s
        r   _get_addedfilesz)_fullcopytracing.<locals>._get_addedfiles  s     	#b$*:*:*<*<==Ib$*:*:*<*<==I	I-..B	I-..BLL"b"""Szr   c                        d          S )Nr   r   r1  s   r   <lambda>z"_fullcopytracing.<locals>.<lambda>      ??1%% r   c                        d          S )Nr   r   r3  s   r   r4  z"_fullcopytracing.<locals>.<lambda>  r5  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
)r7   r  r  r   
setdefaultr   r   r   r[   r  rB   rN   rP   joinvaluesupdate_dir_renames))r1   r  r  r^   copies1copies2inversecopies1inversecopies2r   r   copy1copy2divergerenamedelete1renamedelete2
allsourcesr  dsts2u1fnu2fnr/  r0  headerrenamedeleteset
divergesetdstssider.   r)   notedirmove1movewithdir2dirmove2movewithdir1branch_copies1branch_copies2r1  r   r  r  r<   s)   `                                   @@@@@r   r	  r	    s    
B	B	Br""Gr""G 4w 433NNMMOO 7 7S!!#r**11#6666MMOO 7 7S!!#r**11#6666EEGMM^$$s>':'::J % %""3''""3'' "	U "	"}}BE

E


 5= 9$u} ) )%(c
%(c

) $*%%-#8#8GCLLsbyyE

E

 5= % %C!$E#J!$E#JJ  		"UBBD%     	"UBBD%  
 E         &%%%D%%%%Dw +TVVTVV+ 	GMM6H#4hmmB6G6G"HH    	GMM6H#4hmmB6G6G"HH   %%UU
NN$$ 	$ 	$Dd####!((** 	) 	)D""4((((!((** 	) 	)D""4((((+	
 	
 	
 '09g2FG 	 	LD& GMM-4555F^^ 
 
::eDLD
??DLD''DLD6&)Q9MM   
 GMM7888)$E7DIIHl)$E7DIIHl"5-<PPN"5-<PPN>722r   c                 T   t                      }i }|                                D ]\  }}t          j        |          t          j        |          }
}	|	|v r2|                    |	          r+|                    |
          r|                    |	           r|	|v r"||	         |
k    r|                    |	           |
||	<   |D ]	}||v r||= 
~|si i fS d |                                D             }|D ]'}| j                            d|||         fz             (t          |d          }i } |            D ]j}||vrd|D ]a}|	                    |          rJ||         |t          |          d         z   }||vr$|||<   | j                            d||fz              nbk||fS )a  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)
    c                 &    i | ]\  }}|d z   |d z   S )   /r   )r   r   r   s      r   r   z _dir_renames.<locals>.<dictcomp>Q  s&    >>>daq4xT>>>r   s)      discovered dir src: '%s' -> dst: '%s'
T)reverseNs'      pending file src: '%s' -> dst: '%s'
)r   r   r   dirnamehasdirr   rB   rP   r[   
startswithrY   )r1   r   r   fullcopyaddedfilesfninvalidr   r   r   dsrcddstr   ddirmove_children_firstr!  r)   dfs                    r   r>  r>  *  s&    eeGG NN$$ ! !S%c**H,<S,A,Ad7??ZZ 	!#**T"2"2 	!KKW__$!6!6KK !GDMM  <<
 2v>>gmmoo>>>G 
 
9Q
OK	
 	
 	
 	
 $GT:::K\^^  H+ 
 
<<?? 	 aAk1B~~)+AG "g&   E	 Kr   c                 x   |                                 |                                }                                                                 t                      }|                                |                     d                                                                            s,| j                            d           t          | |          S }|k    rt          |	                                          dk    r,| j                            d           t          | |          S |
                    |                                           |                                }|k    i }t                    }|                                D ]\  }}	|	v r|	||<   fdfd|D             }
i }|
rt          j        t                     }t          j        t                     }                                                              D ]v}t$          j                            |          }t$          j                            |          }||                             |           ||                             |           w|
D ]}t$          j                            |          }t$          j                            |          }||         }||         }||z   }                    |          }| j                            dd	          }t          |          |k    r:| j                            t5          d
          |t          |          fz             |D ],}|                    |          }t7          ||          r|||<   -t9          |          t9          |          i fS )a}  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.
    Nr  s?   switching to full copytracing as base is not an ancestor of c2
r   s0   switching to full copytracing because of merges
c                     | vo| v o| v S r,   r   )r)   r^   r  r  s    r   r4  z(_heuristicscopytracing.<locals>.<lambda>  s    Qb[:Q$Y:17 r   c                 *    g | ]} |          |S r   r   )r   r)   filts     r   r   z*_heuristicscopytracing.<locals>.<listcomp>  s&    777!ttAww7A777r   r@   s   copytrace.movecandidateslimitsB   skipping copytracing for '%s', more candidates than the limit: %d
)rS   rQ   r   r7   r   rB   rP   r	  rY   rq   r=  rV   r   r   collectionsdefaultdictr   r8   osr$   basenamer\  r   filectxr  statusr   r  r  )r1   r  r  r^   changedfilesr   r@  cpr   r   missingfilesr?  basenametofilenamedirnametofilenamer)   rn  r\  samebasenamesamedirnamemovecandidatesf2maxcandidates	candidatef1rj  r  s     ``                    @@r   r  r  q  s   2 
vvxxUUWW	vvxxUUWW55L	B99Y

BFFHH55 4#	
 	
 	
  b"d333
C
++s{{}}""GMMNOOO#D"b$777CIIKK(((ffhh ++ G	b	!	!BHHJJ  S"99GCL ;:::::D7777|777LG )+(4T::'3D99t}}// 	1 	1Aw''**Hgooa((Gx(//222g&--a0000 	+ 	+Aw''**Hgooa((G-h7L+G4K)K7N AB !G--!A M >""]22;  #n--.	/   + + +	ZZ	**B## + *+GI&+ !!=#9#92==r   c                    | |k    rdS |                                  |                                 }}	 |                                 |                                }}|t          |          } |t          |          }	 |                                 |                                }}||k    rt          |          } n||k    rt          |          }n| |k    S [# t          $ r Y dS w xY w)aF  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).
    TNF)r#   linkrevnextStopIteration)r|  ry  g1g2f1rf2rs         r   r  r    s     
Rxxt\\^^R\\^^B::<<S;bB;bB	 zz||RZZ\\CSyy"XXs"XXRx	     uus   B$C C 
C&%C&c                 6   t          ||          }|                                 }t          || |           t          |                                          D ]\  }}||v r||= |                                D ] \  }}| |                             |           !dS )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  rQ   r   r   r   
markcopied)	wctxr   r^   
new_copiesr   r   __r   r   s	            r   graftcopiesr    s      D#&&JWWYYFFD*%%% ))++,, ! !b6>>4 $$&& " "SS	S!!!!" "r   r,   )NN)4rk  rm  i18nr   r  r    r   rT   r   r   r	   utilsr
   revlogutilsr   r   rk   
importrustrw   r   r!   r*   r4   r=   rF   rg   ry   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r	  r>  r  r  r  r   r   r   <module>r     s       				                                    
 &
N
+
+  B        * * * *' ' '@ @ @F# # #L  $i
 i
 i
Xn n nd 

  >7  7  7 t$ $ $NC C CL$ $ $,    	. 	. 	.   + + + +\C4 C4 C4L  (  *!
 !
 !
 !
 !
 !
 !
 !
HI3 I3 I3XD  D  D Nj> j> j>Z  B" " " " "r   