o ]Lb@sdddlmZddlmZddlmZmZddZddZd d Z d d Z d dZ ddZ ddZ dS))absolute_import)_)mdiffpycompatc csi}|jjtdt|t|tdd}|D]}|t|}||vr.|g||<q|||q|D]$}||}t|}||gD]}||kr[||fVnqLq8| dS)zfind renamed files that have no changes Takes a list of new filectxs and a list of removed filectxs, and yields (before, after) tuples of exact matches. ssearching for exact renamesfiles)totalunitN) ui makeprogressrlen incrementhashdataappendgetcomplete) repoaddedremovedhashesprogressfctxhadatarfctxr3/usr/lib/python3/dist-packages/mercurial/similar.py_findexactmatchess0     rcCs|}|t|fSN)rr splitnewlines)rorigrrr_ctxdata6sr"c Csl|\}}|}d}t||}|D]\}}} } || | D]} |t| 7}qqt|t|} |d| S)Nrg@)rrblocksr ) r otherdatar!linestextequalmatchesx1x2y1y2linelengthsrrr_score<s  r/cCst|t|Sr)r/r")fctx1fctx2rrrscoreKr2ccsi}|jjtdtdt|d}|D].}|d}|D]#}||d|fd} |dur2t|}t||} | | krA|| f||<qq|t |D]\} } | \} }| | |fVqLdS)zfind potentially renamed files based on similar file content Takes a list of new filectxs and a list of removed filectxs, and yields (before, after, score) tuples of partial matches. ssearching for similar filesr)r rNr) r r rr r rr"r/rr iteritems)rrr thresholdcopiesrrra bestscoremyscoredestvsourcebscorerrr_findsimilarmatchesOs,  r?cCsdd|DS)NcSsg|] }|dkr|qS)r)size.0xrrr ksz_dropempty..r)fctxsrrr _dropemptyjr3rFc #s|dtfddt|D}tfddt|D}tt|||D]\}}|||dfVq,|dkrdfdd|D}t||||D]\}}}|||fVqTdSdS)z:find renamed files -- yields (before, after, score) tuplesNc3s|]}|VqdSrrrBfp)wctxrr vszfindrenames..c3s |] }|vr|VqdSrrrG)pctxrrrJwsg?csg|]}|vr|qSrrrA) matchedfilesrrrDszfindrenames..)p1rFsortedsetraddpathr?) rrrr5 addedfiles removedfilesr8br2r)rLrKrIr findrenamesns" rUN) __future__ri18nrrrrr"r/r2r?rFrUrrrrs  %