o ]Lb@sdZddlmZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZmZiZe eZdZed ged ejd dd d ZddZddZddZdS)z-recreates hardlinks between repository clones)absolute_importN)_)open)errorhg registrarutil) stringutilurlutilsships-with-hg-corerelinks[ORIGIN]) helpcategoryc Ks\ttdr ttdsttd|durd|jvrd}td|||\}}t |j |}| td|j j |j j f|j|jkrM| tddSt|j j |j j s^ttd |B|%tt||}t||j j |j j |}t|j j |j j ||Wdn1swYWddSWddS1swYdS) arecreate hardlinks between two repositories When repositories are cloned locally, their data files will be hardlinked so that they only use the space of a single repository. Unfortunately, subsequent pulls into either repository will break hardlinks for any files touched by the new changesets, even if both repositories end up pulling the same changes. Similarly, passing --rev to "hg clone" will fail to use any hardlinks, falling back to a complete copy of the source repository. This command lets you recreate those hardlinks and reclaim that wasted space. This repository will be relinked to share space with ORIGIN, which must be on the same local disk. If ORIGIN is omitted, looks for "default-relink", then "default", in [paths]. Do not attempt any read operations on this repository while the command is running. (Both repositories will be locked against writes.) ssamefiles samedevices*hardlinks are not supported on this systemNsdefault-relinkr srelinking %s to %s sthere is nothing to relink /source and destination are on different devices)r safehasattrrAbortrpathsr get_unique_pull_pathr repositorybaseuistatusstorepathroot samedevicelocksortedcollectprune do_relink) uirepooriginoptsr__src candidatestargetsr&./usr/lib/python3/dist-packages/hgext/relink.pyrelink$s& Pr(cCs*ttjj}g}t|d}|dd}|jj}|jtdtd|d}d}|td||ft |D]K\}} } | |t||d} t | D]3} | d dd vrZqOt tj || } t | jskqO|d 7}|tj | | | f|j|| d qOq8||td t||S)Nstips collectingfilesunittotalrs6tip has %d files, estimated total number of files: %d )s.ds.iitems%collected %d candidate storage files )lenosrsepmanifestr makeprogressrrwalksortrstatjoinS_ISREGst_modeappendupdatecomplete)r#rseplenr$liver.progressposdirpathdirnames filenamesrelpathfilenamestr&r&r'rXs8     rc Csdd}g}|jtdtdt|d}d}|D]5\}} |d7}tj||} tj||} || | | } | s>|d|q||| jf|j ||d q| | td t||S) NcSsbzt|}Wn tyYdSwt||rdSt||s'ttd|j |j kr/dS|S)NFr ) r4r:OSErrorrsamefilerrrrst_size)r#dstrJtsr&r&r' linkfilter}s    zprune..linkfilterspruningr+r,rr0not linkable: %s r1s,pruned down to %d probably relinkable files ) r7rr3r4rr;debugr>rMr?r@r) r$r#rNrrPr%rCrDfnrJsrcpathtgtrOr&r&r'r|s*  rc Cs^dd}d}d}d}|jtdtdt|d}d} |D]~\} } | d7} tj|| } tj|| } t| d }t| d }||}|rT||}||krMn||}|sC|||rf| d | qz|| | |j | | d |d7}|| 7}Wqt y}z| d | t |fWYd}~qd}~ww||td |t|fdS)NcSsP|d}t||zt||Wnty t||wt|dS)Ns.bak)r4renameroslinkrKremove)r#rNbakr&r&r' relinkfiles   zdo_relink..relinkfileirs relinkingr+r,r0srbrQr1s%s: %s s!relinked %d files (%s reclaimed) )r7rr3r4rr;rreadcloserRr?rKwarnr forcebytestrr@rr bytecount)r#rNfilesrrZCHUNKLENrelinked savedbytesrCrDfszsourcerUsfpdfpsindininstr&r&r'rsR         $ r)N)__doc__ __future__rr4r:mercurial.i18nrmercurial.pycompatr mercurialrrrrmercurial.utilsr r cmdtablecommand testedwithCATEGORY_MAINTENANCEr(rrrr&r&r&r's$     1$ )