o ^Ub|0@sddlmZddlZddlmZddlmZmZmZm Z ddl m Z ej gdz"ddlZddlZddlZddlZejjZejZejZejZejWn eyUYnwdZGd d d e jZdS) )absolute_importN)_) demandimporterrorpycompatutil)common)sbreezy.transactionssbreezy.urlutilss ElementPath)filesymlinkcseZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZZS) bzr_sourcez>Reads Bazaar repositories by using the Bazaar Python librariesNcstt|j||||dtjtj|ds tt d|zt Wnt y8tt dt ddwt |}||zt j|}||_Wntjyctt d|wi|_|dd|_dS) N)revss.bzrs)%s does not look like a Bazaar repositorys"Bazaar modules could not be loadeds (try installing the %s package)sbzrsconverts bzr.saverev)superr __init__ospathexistsjoinr NoReporbzrdir NameErrorrabspath_checkrepotypeBzrDiropendecodeopen_repository sourcerepoerrorsNoRepositoryPresent _parentids configbool_saverev)selfuirepotyperr bzr_dir __class__3/usr/lib/python3/dist-packages/hgext/convert/bzr.pyr7s0       zbzr_source.__init__c CszHtj|d}z |jdd}|j}Wntjtjfy)d}| }Ynw|durC|j j j |j j j krF|j tdWdSWdSWdStyZ|j tdYdSw)NrF)recommend_upgradesawarning: lightweight checkouts may cause conversion failures, try with a regular branch instead. s(bzr source type could not be determined )rropen_containingropen_workingtreebranchr NoWorkingTree NotLocalUrl open_branch controldirroot_transportbaser$warnr Exceptionnote)r#rdirtreer.r)r)r*rRs.     zbzr_source._checkrepotypecCs|jdS)a Before the conversion begins, acquire a read lock for all the operations that might need it. Fortunately read locks don't block other reads or writes to the repository, so this shouldn't have any impact on the usage of the source repository. The alternative would be locking on every operation that needs locks (there are currently two: getting the file and getting the parent map) and releasing immediately after, but this approach can take even 40% longer.N)r lock_readr#r)r)r*beforels zbzr_source.beforecCs|jdSN)runlockr;r)r)r*afteryzbzr_source.aftercCs|jjddS)NT)using)r find_branchesr;r)r)r* _bzrbranches|r@zbzr_source._bzrbranchesc Cs|jstdd|D}n>d}|D]$}z|jd}tj|}||}Wn tj y5Ynw|j }q|durJt t d|jd|g}dd|D}|S)NcSsg|]}|qSr)) last_revision).0br)r)r* z'bzr_source.getheads..rs%s is not a valid revisioncSsg|]}|dkr|qS)snull:r))rEhr)r)r*rG)r sortedrCr revisionspec RevisionSpec from_string in_historyrBzrErrorrev_idrAbortr)r#headsrevidr.revspecrinfor)r)r*getheadss&  zbzr_source.getheadscCs|}|j|}z||}Wn tjjyYdSw|tvr$dS|j| |f}|dkrK| |}|durEt t d||f| |fS||}||fS)N)NNr s%s.%s symlink has no target)rr revision_treekindbreezyr NoSuchFilesupportedkinds _modecacheencodeget_symlink_targetrrRrget_fileread)r#namerevrevtreerZmodetargetsior)r)r*getfiles&     zbzr_source.getfilecCs`|r ttdi|_|j||_|j|}|j|d}| |j|\}}||t fS)Ns(convert from cvs does not support --fullr) rrRrr^rrY_revtreer pop_gettreechangesset)r#versionfull parentidsprevtreefileschangesr)r)r* getchangess  zbzr_source.getchangesc Cs|j|}|jsg}tjf|j|<n ||j}||j|<|jdd}|dkr+d}t j |d|j |j f| |j| |j|d||jdS)Nz branch-nickdefaulttrunks%d %dutf8)parentsdateauthordescr.rdsaverev)r get_revision parent_idsrevision NULL_REVISIONr _filterghosts propertiesgetr commit timestamptimezonerecode committermessager_r")r#rnrdrxr.r)r)r* getcommits$     zbzr_source.getcommitcCsRi}|D] }|siS|j}t|D] \}}||||<qq|Sr=)rC supports_tagstags get_tag_dictr iteritemsr)r#bytetagsr.tagdictrcrdr)r)r*gettagss  zbzr_source.gettagscCsZi|_|j|}|dur|j||}ntj}|j|}dd|||dD}|S)NcSg|]}|dqS)rr)rEer)r)r*rGrHz.bzr_source.getchangedfiles..r)r^rrYr rrrl)r#rdicurtreeparentidrqrsr)r)r*getchangedfiless  zbzr_source.getchangedfilescCsv|j}g}i}t}z|j}Wn ty|j}Ynwdd}t|||dd} | D] } | j} | j} | j } | ddksD| ddkrEq,| ddkr| dd vr]| | | d|f| ddkrd| vr| d| dk}| | d}| |D]T\}}|jdkrq{| | dd |}||vrq{|||sq{| | dd |}| ||f| ||f|j rd p|jd kod pd}||j||f<|||<q{q,| \}}|dur| |}|dur| |}||p||dur| ||fq,|r ||kr |||<| ||fdd| | fD\} } | rd p'| d kr&dp'd}||j||f<| ||fq,||fS)NcSs|jdp |jdp dS)Nrr)r)cr)r)r*keysz'bzr_source._gettreechanges..keyT)rreverserrr directory)Nr/xr scSr)rr)rr)r)r*rGGrHz.bzr_source._gettreechanges..l) _revision_idrmroot_inventoryAttributeError inventoryrK iter_changesrrZ executableappendrpath2id iter_entriesaddr^)r#currentoriginrTrsrenamesseenrr curchangeschangepathsrZrrenamingsubdirrcentryfrompathtopathrfrr)r)r*rls              zbzr_source._gettreechangescs&|j|tfdd|D}|S)zqFilters out ghost revisions which hg does not support, see csg|]}|vr|qSr)r))rEparent parentmapr)r*rGSrJz,bzr_source._filterghosts..)rget_parent_maptuple)r#idsrxr)rr*rNs zbzr_source._filterghostsr=)__name__ __module__ __qualname____doc__rrr<r?rCrXrirtrrrrlr __classcell__r)r)r'r*r 4s    gr ) __future__rrmercurial.i18nr mercurialrrrrrr IGNORESupdatebreezy.bzr.bzrdirr[ breezy.errorsbreezy.revisionbreezy.revisionspecbzrrrrrLrM ImportErrorr]converter_sourcer r)r)r)r*s.