o ]Lb @s~ddlmZddlZddlZddlmZddlmZddlm Z m Z m Z m Z mZddlmZddlmZmZe d Zd d Zd d ZddZdEddZdEddZddZddZddZddZddZ ddZ!dZ"dZ#d Z$d!d"Z%d#d$Z&d%d&Z'd'd(Z(d)d*Z)dFd+d,Z*d-d.Z+d/d0Z,dEd1d2Z-d3d4Z.d5d6Z/d7d8Z0Gd9d:d:e1Z2d;d<Z3d=d>Z4d?d@Z5dAdBZ6dCdDZ7dS)G)absolute_importN)_)nullrev)matchpathutilpolicypycompatutil) stringutil)flagutilsidedata copy_tracingcCsHt|D]\}}||kr||=q||vr||=q||vr!||=qdS)z)filters out invalid copies after chainingN)listitems)srcdsttkvr2/usr/lib/python3/dist-packages/mercurial/copies.py_filter$srcCs0|}t|D] \}}|||||<q |S)z.chain two sets of copies 'prefix' and 'suffix')copyr iteritemsget)prefixsuffixresultkeyvaluerrr_chainEsr!cCsV|D]$}|}||d|kr|S|r(||d|kr(|SqdS)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) ancestorspathrfilenode)fctxambasemffr#rrr _tracefileMs r)cCsB|j}|}t|D]}||jr|r||s||=q |SN)dirstatecopiesrr get_entrytracked)repordscrrrr_dirstatecopies]s  r2cCs|}|}|j||dS)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)abrmambrrr_computeforwardmissingfsr:cCs(|jdkrdS|jdd}d}||vS)z9Checks if we should use changeset-centric copy algorithmschangeset-sidedataT experimentalscopies.read-from)schangeset-onlys compatibility)filecopiesmodeuiconfig)r/readfromchangesetsourcerrrusechangesetcentricalgops rBcCs|j}t|r t|||S|jjo|jdd}|jj}|r&|d||f|}|dur0dn|}i} |} ||krS| t krSt |} t || } |jddrlt||} |rk|dt| nt||| d} |r}|dt| |jjj| gd d } t| D]7}|r|d |||}| |_|rt}t|||}|r|r|d ||| |<|r|d t|q| S)z@Like _forwardcopies(), but b.rev() cannot be None (working copy)devel debug.copiess3debug.copies: looking into rename from %s to %s Nscopy-tracing.trace-all-filess+debug.copies: searching all files: %d r3s/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 )_reporB_changesetforwardcopiesr> debugflag configbooldebugr4p1p2revrmatchmodexactfilesintersectmatchersrwalklenr: changelogr"sorted_ancestrycontextr timerr))r6r7baserr/rKdbgr&r'cmforwardmissingmatch filesmatchermissingancestrycontextr(r%startopathrrr_committedforwardcopiesys^       rbcsR|j}|j|jtj|jtdurfdd}|Sfdd}|S)zreturns a function that returns the following data given a " * p1: revision number of first parent * p2: revision number of first parent * changes: a ChangingFiles object Ncs:|\}}|@r|jtj}nd}|||fSr*) _sidedatar sidedatamodSD_FILES)rNrLrMraw HASCOPIESINFOchangelogrevisionflagsparentsrrrevinfos   z _revinfo_getter..revinfocs2|\}}|@r|j}nd}|||fSr*)changes)rNrLrMrmrgrrrls    )rU parentrevsrjr REVIDX_HASCOPIESINFOrirustmod)r/rclrlrrgr_revinfo_gettersrrcsifdd}|S)z&return a cached version of is_ancestorcsH||krdS||kr dS||f}|}|dur"||}|<|S)NFT)r)ancdescrretcache is_ancestorrr _is_ancestors z(cached_is_ancestor.._is_ancestorr)rxryrrvrcached_is_ancestors rzc s|t|fvr iS|}|j}|j}|j}ttf}|j|gdd}|j|g|gd} t } d} |j dd} | D]+} || }||krQd} qD|\}}|tkrb||vrb| ||tkro||vro| |qD| stiS| rt | } t| }|g}|j||| ddt fdd | D} |jd krtd d | D}| D]} || D]}|tkrqd || <||vr||d7<qqt||}|jt| |||||| WdS1swYdStdd | D}| D]"} || D]}|tkr qg|| <||vr||| qq| }||ks,J| | | t|}t| |||||S)NTrE)commonheadsFrCscopy-tracing.multi-thread) includepathcsg|]}|vr|qSrr.0r roots_to_headrr +z+_changesetforwardcopies..r;css|]}|dfVqdS)rNrr~rrr 7z*_changesetforwardcopies..rrcss|]}|gfVqdSr*rr~rrrrMr)rNrr/ unfilteredrU isancestorrev_uncheckedparentrevsr"findmissingrevssetr>rJaddrminreachablerootsr=dictrnrrreading_combine_changeset_copiesappendpopextendsort_revinfo_getter_extra_combine_changeset_copies_extra)r6r7rr/rq isancestorrk graph_rootsr"revsrootshas_graph_roots multi_threadrpsrLrMmhchildren_countprlchildrenxrrrrHs        $    rHcCs8|}tdurtt|||||}nt|}i} |D]} || \} } } d}d| fd| ffD]\}}|tkr8q/||}|durBq/|d8}|||<|rS| |d}n| |d}|durbi}}n |ri|}n|}| duri}|dkry| j }n|dkr| j }|r|}t |D]\}}||}|dur|ddur|d}| |f||<q||usJ| j r| j D]}||vr||ur|}| df||<q|dur|}q/|dksJt|||| | }q/|| | <qi}| |}|dusJ|D]\}\}}|dur|||<q|st|D] }||s||=q|S)acombine the copies information for each item of iterrevs revs: sorted iterable of revision to visit children_count: a {parent: } 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)alwaysrpcombine_changeset_copiesrrzrrrrcopied_from_p1copied_from_p2r rremoved_merge_copies_dictrkeys)rr targetrevrlrrr alwaysmatch final_copies all_copies current_revrLrMrmcurrent_copiesparent parent_revremaining_childrenr, newcopies childcopiesdestsourceprevr(targetrev_itemsttfilenamerrrr`s             rrc Cs|D]<\}}||}|dur|||<qt|||||\}} | r8|tkr/||df||<q||df||<q|tkr@|||<q|S)amerge 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)rr_compare_values PICK_MAJOR) minormajorrrm current_mergerr otherpick overwriterrrrs   rc Cs|\}}|\}}||kr||ksJtdfS|dur+|dur+|dur+||jvr+tdfS|dur@|dur@|dur@||jvr@tdfS|||rV|durR||jvrRtdfStdfS|||rl|durh||jvrhtdfStdfS|durttdfS|dur|tdfStdfS)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_EITHERsalvaged PICK_MINORrmerged) rmrrrrmajor_tt major_valueminor_tt minor_valuerrrrs8     rcs,j}|jfddfdd}|S)aWreturn a function that return multiple data given a "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 cs|fdd}|S)NcsN|vrdS|}|j|j}d}|D] }|jkr"|d7}q|dkS)NFrrr)rQ_filelogrk _filenodenullid)r#r%rk nb_parentsn)ctxr/rrismerged@s  z=_revinfo_getter_extra..get_ismerged..ismergedr)rNr)r/)rr get_ismerged=s z+_revinfo_getter_extra..get_ismergedcs:|\}}|}|j\}}|}||||||fSr*)_copies filesremoved)rNrLrMrp1copiesp2copiesrrrkr/rrrlMs  z&_revinfo_getter_extra..revinfo)rUrn)r/rqrlrrrr0s   rcsi}}|D]}||d} | duri} t||D]\} } || \} } }}}}|| kr3d}|}n || ks9Jd}|}|sJfdd|D}| }|r{| }t|D]\}}| |}|durn|ddurn|d}| |f||<qW|| us{J|D]}||vr|| ur| }| df||<q}|| }|dur||| <q|dkrt||||qt||||||| <qqi}||D]\}\}}|dur|||<q|S)zyversion of `_combine_changeset_copies` that works with the Google specific "extra" based storage for copy informationNrrcsi|] \}}|r||qSrr)rrrr3rr ms  z3_combine_changeset_copies_extra..) rr enumeraterrr rr_merge_copies_dict_extra)rrrrlrrrrrr,ir1rLrMrrrrrrrrrrr( othercopiesrrrr3rrWsf          3rc Csv|D]4\}}||}|dur|||<q|d}|d}|d|dkr'q||ks4|||r4||r8|||<qdS)zrversion of `_merge_copies_dict` that works with the Google specific "extra" based storage for copy informationNrr)rr) rrrrrr rnew_ttother_ttrrrrs   rcCs`|dur|}||}|dur't||||}t|t|j|}|St||||}|S)zr?r_reverse_renames)r6r7rr,rrr_backwardrenamess  rcCs@i}tt|D]\}}|r||sq ||vrq |||<q |S)z>given copies to context 'dst', finds renames from that context)rVr r)r,rrrrrrrrrs  rc Csr|j}|jjo |jdd}|r|jd||f||ks"|r"|s$iS|dur=||kr=|r8|jdt||S||}||krV|rN|jdt |||d}n[||krj|rb|jdt |||d}nG|rr|jd d}|t kr||}t ||}t ||||d} t |t | @} | D]} | | | | kr|| =| | =qt|||} t| | }t||||S) z5find {dst@y: src@x} copy mapping for directed comparerCrDs-debug.copies: searching copies from %s to %s Ns$debug.copies: search mode: dirstate s#debug.copies: search mode: forward r3s$debug.copies: search mode: backward s$debug.copies: search mode: combined )rGr>rIrJrKrNrLr2ancestorrrrrrrr!r) ryrr/rKr6r,rYx_copiesy_copies same_keysrx_backward_renamesrrr pathcopiessR           rcCs|r|r||krttifS|}|dur/||jkr/tt||tifS|jdd}t |durDttifSt |rOt ||||S|dkrgt |||r`t ||||St||||St ||||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 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<rFs heuristics) branch_copiesr/rnoder+rLr2r>r?r parseboolrB_fullcopytracing_isfullcopytraceable_heuristicscopytracing)r/c1c2rYr copytracingrrr mergecopies s$!   rcCsX|dur |}|r*|r*|jdd}t|d||}||kSdS)aChecks 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<scopytrace.sourcecommitlimit%d::%dF)rNrLmutabler> configintrTr)r/rrYsourcecommitlimitcommitsrrrrSs rc Cs||vr||vr|||<dSdS||vrdS||||kr)t||||s)dS||||ks;||||krD|D]} ||| <q=dSdSr*)_relatedrj) rdsts1m1m2r9rrYr renamedeleterrrr_checksinglesidecopiesgs "$ rc@s$eZdZdZ dddZddZdS)ra 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. NcCsR|durin||_|durin||_|durin||_|dur$i|_dS||_dSr*rrdirmove movewithdir)selfrrrrrrr__init__szbranch_copies.__init__cCsd|j|j|j|jfS)NzJr)rrrr__repr__s zbranch_copies.__repr__)NNNN)__name__ __module__ __qualname____doc__rrrrrrr|s  rc$ s|||t||}t||}|s!|s!ttifSi}i}|D] \}} || g|q)|D] \}} || g|q;i} i} i} i} i}t|t|B}|D]z} || }|| }|r|r| vr| vrt|}t|}||@r||@D] }| | |<| | |<qq]t||B| | <q]| vr| vrt|}t|}||@D] }| | |<| | |<qq]|rt | |||| | q]|rt | |||| | q]gfddfdd}fdd}j j r|}|}d}|rj d|dd |f|r!j d|d d |ft}t}| D]}||q+| D]}||q8|D]}||qEj d d|fd |ffD]I\}}|seq\j d |t|D]2}d}|| vs|| vr|d7}||vr|d7}||vr|d7}j d||||fqqq\~~j dt|| ||\}}t|| ||\} }!t| | ||!}"t| || |}#|"|#| fS)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. csRs%}}t||}t||}||f|Sr*)r5rrVr)idx addedinm1 addedinm2u1u2)rwrrr9r/rr_get_addedfiless  z)_fullcopytracing.._get_addedfilescdS)Nrrrrrrz"_fullcopytracing..cr)Nrrrrrrrrs unmatched files in %ss %s: %s slocals sothersK all copies found (* = to merge, ! = divergent, % = renamed and deleted): sremotes on %s side: *!%s src: '%s' -> dst: '%s' %s s! checking for directory renames )r4rrr setdefaultrrrrVrr>rIrKjoinvaluesupdate _dir_renames)$r/rrrYcopies1copies2inversecopies1inversecopies2rrcopy1copy2diverge renamedelete1 renamedelete2 allsourcesrdsts2u1fnu2fnrrheaderrenamedeleteset divergesetdstssider,r(notedirmove1 movewithdir2dirmove2 movewithdir1branch_copies1branch_copies2r)rrwrrr9r/rrs                   rcCsbt}i}t|D]8\}}t|t|} } | |vrq || r.|| r.|| q | |vr>|| | kr>|| q | || <q |D] } | |vrN|| =qE~|sViifSddt|D}|D]} |jd| || fqbt |dd} i}|D]0}||vr| D]'} | | r|| |t | d}||vr|||<|jd||fnqq|||fS)aFinds 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) cSsi|] \}}|d|dqS)/r)rrrrrrrSsz _dir_renames..s) discovered dir src: '%s' -> dst: '%s' T)reverseNs' pending file src: '%s' -> dst: '%s' ) rr rrdirnamehasdirrr>rKrV startswithrT)r/rrfullcopy addedfilesfninvalidrrrdsrcddstrddirmove_children_firstrr(dfrrrr,sR        rcs*|dur |}durt}||ds3|jdt||S}|kr]t| dkrN|jdt||S| | |}|ks9i}t }t |D] \}} | vru| ||<qifddfdd |D} i} | r tt} tt} D]}tj|}tj|}| ||| ||q| D]O}tj|}tj|}| |}| |}||}|}|jd d }t||kr|jtd |t|fq|D]}||}t||r || |<qqt| t|ifS) 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. Nrs?switching to full copytracing as base is not an ancestor of c2 rs0switching to full copytracing because of merges cs|vo |vo |vSr*r)r()rYrrrrrrz(_heuristicscopytracing..csg|]}|r|qSrr)rr()filtrrrrz*_heuristicscopytracing..r<scopytrace.movecandidateslimitsBskipping copytracing for '%s', more candidates than the limit: %d )rNrLrr4rr>rKrrTrkrrQrr r collections defaultdictrr5osr#basenamer;rfilectxrstatusrrr)r/rrrY changedfilesrr!cprr missingfilesr basenametofilenamedirnametofilenamer(rJr; samebasename samedirnamemovecandidatesf2 maxcandidates candidatef1r)rYrrFrrrss|               rcCs||krdS||}}z;||}}|dur!t|}|dur)t|} ||}}||krsT     !    C&lr:'F  .F$ Gm !