o ]Lb}@sddlmZddlZddlZddlZddlmZmZddlm Z ddl m Z m Z m Z mZddl mZddl mZe jZejZejZejZejZd Zd Zd Zd Z dZ!d Z"d Z#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/e j0dddGddde1Z2dd Z3Gd!d"d"e1Z4Gd#d$d$e4Z5Gd%d&d&e5Z6Gd'd(d(e4Z7ej8fd)d*Z9d+d,Z:Gd-d.d.e5Z;Gd/d0d0e;Zd5d6Z?dS)7)absolute_importN)nullrevsha1nodeconstants)attr)errorpycompat revlogutilsutil)nodemap) constants @iiiii i@iTF)slotsinitc@seZdZdZeZeZeZeZ eZ eZ eZ eZ eZeZ        dCddZeddZed d Zd d Zd dZddZddZddZeddZeddZeddZddZeddZedd Zed!d"Z e j!d#d$Z"ed%d&Z#ed'd(Z$e$j!d)d*Z%ed+d,Z&ed-d.Z'ed/d0Z(ed1d2Z)ed3d4Z*ed5d6Z+ed7d8Z,d9d:Z-d;d<Z.d=d>Z/d?d@Z0dAdBZ1dS)D DirstateItemarepresent a dirstate entry It hold multiple attributes # about file tracking - wc_tracked: is the file tracked by the working copy - p1_tracked: is the file tracked in working copy first parent - p2_info: the file has been involved in some merge operation. Either because it was actually merged, or because the p2 version was ahead, or because some rename moved it there. In either case `hg status` will want it displayed as modified. # about the file state expected from p1 manifest: - mode: the file mode in p1 - size: the file size in p1 These value can be set to None, which mean we don't have a meaningful value to compare with. Either because we don't really care about them as there `status` is known without having to look at the disk or because we don't know these right now and a full comparison will be needed to find out if the file is clean. # about the file state on disk last time we saw it: - mtime: the last known clean mtime for the file. This value can be set to None if no cachable state exist. Either because we do not care (see previous section) or because we could not cache something yet. FTNc Cs||_||_||_||_||_d|_d|_d|_d|_d|_ |dur'd}d}n|ddur/d}|r;|d|_|d|_|rI|d\|_|_|_ dSdS)NFrrr) _wc_tracked _p1_tracked_p2_info_fallback_exec_fallback_symlink_mode_size_mtime_s _mtime_ns_mtime_second_ambiguous) self wc_tracked p1_trackedp2_infohas_meaningful_datahas_meaningful_mtimeparentfiledata fallback_execfallback_symlinkr-8/usr/lib/python3/dist-packages/mercurial/pure/parsers.py__init__ms2    zDirstateItem.__init__c Cst|t@}t|t@}d}|t @rd}d}d}|t@r!|t@}d} |t@r+|t@} |rLtj dks4J|t @r;d}nd}|t @rG|tj O}n|tj O}|t@} |t|t@t|t@t|t@||||||| ff|| dS)z,Build a new DirstateItem object from V2 dataNFrii)r%r&r'r(r)r*r+r,)boolDIRSTATE_V2_HAS_MODE_AND_SIZEDIRSTATE_V2_HAS_MTIME&DIRSTATE_V2_EXPECTED_STATE_IS_MODIFIEDDIRSTATE_V2_HAS_FALLBACK_EXECDIRSTATE_V2_FALLBACK_EXEC DIRSTATE_V2_HAS_FALLBACK_SYMLINKDIRSTATE_V2_FALLBACK_SYMLINKstatS_IXUSRDIRSTATE_V2_MODE_EXEC_PERMDIRSTATE_V2_MODE_IS_SYMLINKS_IFLNKS_IFREG"DIRSTATE_V2_MTIME_SECOND_AMBIGUOUSDIRSTATE_V2_WDIR_TRACKEDDIRSTATE_V2_P1_TRACKEDDIRSTATE_V2_P2_INFO) clsflagssizemtime_smtime_ns has_mode_sizer)moder+r,second_ambiguousr-r-r. from_v2_datas>        zDirstateItem.from_v2_datacCs|dkr |ddddS|dkr|ddS|dkr4|tkr!d}d}n |tkr*d}d}nd}d}|||dS|d krh|tkrB|ddd S|tkrL|ddd S|tkr[|ddd||d fd S|dd|||ddffdStd|)zBuild a new DirstateItem object from V1 data Since the dirstate-v1 format is frozen, the signature of this function is not expected to change, unlike the __init__ one. mT)r%r&r'a)r%rF)r&r'n)r%r')r%r&)*rF)r%r&r)r*r)r%r&r*sunknown state: %s) NONNORMALFROM_P2AMBIGUOUS_TIME RuntimeError)rBstaterHrDmtimer&r'r-r-r. from_v1_datas@     zDirstateItem.from_v1_datacCsd|_d|_dS)zMark a file as "possibly dirty" This means the next status call will have to actually check its content to make sure it is correct. N)r!r"r$r-r-r.set_possibly_dirtys zDirstateItem.set_possibly_dirtycCs,d|_d|_||_||_|\|_|_|_dS)aqmark a file as "clean" cancelling potential "possibly dirty call" Note: this function is a descendant of `dirstate.normal` and is currently expected to be call on "normal" entry only. There are not reason for this to not change in the future as long as the ccode is updated to preserve the proper state of the non-normal files. TN)rrrr r!r"r#)r$rHrDrUr-r-r. set_cleans zDirstateItem.set_cleancCsd|_d|_d|_dS)zumark a file as tracked in the working copy This will ultimately be called by command like `hg add`. TN)rr!r"rWr-r-r. set_trackeds zDirstateItem.set_trackedcCs"d|_d|_d|_d|_d|_dS)zzmark a file as untracked in the working copy This will ultimately be called by command like `hg remove`. FN)rrr r!r"rWr-r-r. set_untrackeds  zDirstateItem.set_untrackedcCs,|jrd|_d|_d|_d|_d|_dSdS)zremove all "merge-only" from a DirstateItem This is to be call by the dirstatemap code when the second parent is dropped FN)rrr r!r"rWr-r-r.drop_merge_datas zDirstateItem.drop_merge_datacC|SN)v1_moderWr-r-r.rH%zDirstateItem.modecCr]r^)v1_sizerWr-r-r.rD)r`zDirstateItem.sizecCr]r^)v1_mtimerWr-r-r.rU-r`zDirstateItem.mtimecCsT|j}|dur dS|j}|\}}}||krdS|dks|dkr&|jr$dSdS||kS)NFrT)r!r"r#)r$ other_mtimeself_secself_ns other_secother_nsrIr-r-r.mtime_likely_equal_to1s z"DirstateItem.mtime_likely_equal_tocCs|jsdS|S)a\ States are: n normal m needs merging r marked for removal a marked for addition XXX This "state" is a bit obscure and mostly a direct expression of the dirstatev1 format. It would make sense to ultimately deprecate it in favor of the more "semantic" attributes. ?) any_trackedv1_staterWr-r-r.rTGs zDirstateItem.statecC |jduS)aTrue if "fallback" information are available for the "exec" bit Fallback information can be stored in the dirstate to keep track of filesystem attribute tracked by Mercurial when the underlying file system or operating system does not support that property, (e.g. Windows). Not all version of the dirstate on-disk storage support preserving this information. NrrWr-r-r.has_fallback_execXs zDirstateItem.has_fallback_execcC|jS)a "fallback" information for the executable bit True if the file should be considered executable when we cannot get this information from the files system. False if it should be considered non-executable. See has_fallback_exec for details.rmrWr-r-r.r+f zDirstateItem.fallback_execcC |dur d|_dSt||_dS)acontrol "fallback" executable bit Set to: - True if the file should be considered executable, - False if the file should be considered non-executable, - None if we do not have valid fallback data. See has_fallback_exec for details.N)rr0r$valuer-r-r.set_fallback_execq zDirstateItem.set_fallback_execcCrl)aTrue if "fallback" information are available for symlink status Fallback information can be stored in the dirstate to keep track of filesystem attribute tracked by Mercurial when the underlying file system or operating system does not support that property, (e.g. Windows). Not all version of the dirstate on-disk storage support preserving this information.NrrWr-r-r.has_fallback_symlinks z!DirstateItem.has_fallback_symlinkcCro)a  "fallback" information for symlink status True if the file should be considered executable when we cannot get this information from the files system. False if it should be considered non-executable. See has_fallback_exec for details.rvrWr-r-r.r,rpzDirstateItem.fallback_symlinkcCrq)acontrol "fallback" symlink status Set to: - True if the file should be considered a symlink, - False if the file should be considered not a symlink, - None if we do not have valid fallback data. See has_fallback_symlink for details.N)rr0rrr-r-r.set_fallback_symlinkruz!DirstateItem.set_fallback_symlinkcCro)z/True is the file is tracked in the working copy)rrWr-r-r.trackedzDirstateItem.trackedcCs|jp|jp|jS)z4True is the file is tracked anywhere (wc or parents)rrrrWr-r-r.rjszDirstateItem.any_trackedcCs|jo |jp|j S)zTrue if the file has been addedr{rWr-r-r.addedzDirstateItem.addedcCs"|jsdS|js dS|jrdSdS)z8True if the file has a chance to be in the "clean" stateFTr{rWr-r-r. maybe_cleanszDirstateItem.maybe_cleancCro)z8True if the file is tracked in the first parent manifest)rrWr-r-r.r&rzzDirstateItem.p1_trackedcCs |jo|jS)zvTrue if the file needed to merge or apply any input from p2 See the class documentation for details. )rrrWr-r-r.r's zDirstateItem.p2_infocCs|j o |jp |jS)z!True if the file has been removedr{rWr-r-r.removedr}zDirstateItem.removedcCsd}|jr |tO}|jr|tO}|jr|tO}|jdur9|jdur9|tO}|j t j @r/|t O}t |j r9|tO}|jdurB|tO}|jrI|tO}|jdurY|tO}|jrY|tO}|jduri|tO}|jri|tO}||jpnd|jprd|jpvdfS)z7Returns (flags, mode, size, mtime) for v2 serializationrN)rr?rr@rrArr r1rHr8r9r:S_ISLNKr;r!r2r#r>rr4r5rr6r7r")r$rCr-r-r.v2_datas4     zDirstateItem.v2_datacCs6|jstd|jr dS|jr|jrdS|jrdSdS)z.return a "state" suitable for v1 serializationuntracked itemrMrKrLrN)rjrSrrrr|rWr-r-r.rks zDirstateItem.v1_statecCs|jdur|jSdS)z-return a "mode" suitable for v1 serializationNr)rrWr-r-r.r_szDirstateItem.v1_modecCsV|jstd|jr|jr|jrtS|jrtS|jrdS|jr!tS|jdur(tS|jS)z-return a "size" suitable for v1 serializationrrN) rjrSrrrrPrQr|r rWr-r-r.ra s zDirstateItem.v1_sizecCsJ|jstd|jr dS|jdurtS|jrtS|jstS|jr"tS|jS)z.return a "mtime" suitable for v1 serializationrrN)rjrSrr!rRrrr#rWr-r-r.rbs zDirstateItem.v1_mtime)FFFTTNNN)2__name__ __module__ __qualname____doc__ribrrrrr r!r"rrr#r/ classmethodrJrVrXrYrZr[r\propertyrHrDrUrhrTrnr+setterrtrwr,rxryrjr|r~r&r'rrrkr_rarbr-r-r-r.rBs & + *                    # rcCs t|d@S)Ni)int)qr-r-r.gettype0 rc @seZdZdZejZedZ edZ ddddddde j ddej ej ejf ZejddZejddZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Z d#S)$BaseIndexObjectrs>Q>ircCs|jjSr^) index_formatrDrWr-r-r. entry_sizeNr`zBaseIndexObject.entry_sizecCs<ttjti}tdt|D] }||d}|||<q|S)Nr) nodemaputilNodeMaprnullidrrangelen)r$r rnr-r-r._nodemapRs   zBaseIndexObject._nodemapcCs ||jvS)z*return True if the node exist in the indexrr$noder-r-r.has_nodeZs zBaseIndexObject.has_nodecC |j|S)zQreturn a revision for a node If the node is unknown, raise a RevlogErrorrrr-r-r.rev^s zBaseIndexObject.revcCs |j|S)zIreturn a revision for a node If the node is unknown, return None)rgetrr-r-r.get_revds zBaseIndexObject.get_revcCs<dt|vrt|t|D]}||d}|j|=q dSdSNrr)varsrrr)r$startrrr-r-r. _stripnodesjs   zBaseIndexObject._stripnodescCs|jdddS)Nr)__dict__poprWr-r-r. clearcachespszBaseIndexObject.clearcachescCs|jt|jSr^)_lgtr_extrarWr-r-r.__len__sszBaseIndexObject.__len__cCs>dt|vrt||j|d<|t||}|j|dSr)rrr _pack_entryrappend)r$tupdatar-r-r.rvs zBaseIndexObject.appendcCs4|ddksJ|ddksJ|jj|ddS)Nrr rpackr$rentryr-r-r.r|szBaseIndexObject._pack_entrycCs2t|ts td|dks|t|krt|dS)Nsexpecting int indexesr) isinstancer TypeErrorr IndexErrorr$ir-r-r. _check_indexs zBaseIndexObject._check_indexcCs|dkr|jS||||jkr|j||j}n||}|j|||j}|||}|jrI|dkrIt dt |d}|f|dd}|S)Nrrr) null_itemrrr_calculate_index_datar _unpack_entryr offset_typer)r$rrindexroffsetr-r-r. __getitem__s    zBaseIndexObject.__getitem__cCs(|j|}|ddtjtjtjf}|SNr)runpackrevlog_constantsCOMP_MODE_INLINE RANK_UNKNOWN)r$rrrr-r-r.rs zBaseIndexObject._unpack_entrycCstj}||S)!pack header information as binary)r INDEX_HEADERr)r$headerv_fmtr-r-r. pack_headers zBaseIndexObject.pack_headercCs8||}tjj|dd}|dkr|tjjd}|S)4return the raw binary string representing a revisionNrr)rINDEX_ENTRY_V1rrrD)r$rrpr-r-r. entry_binarys zBaseIndexObject.entry_binaryN)!rrrrust_ext_compatrrrstructcalcsize big_int_sizeint_sizerrrrrr propertycacherrrrrrrrrrrrrrrr-r-r-r.r4sH     rc@s$eZdZddZddZddZdS) IndexObjectcCsPt||jdksJt||jt||jf||_t||j|_g|_dSr)rrrrr)r$rr-r-r.r/s  zIndexObject.__init__cCs ||jSr^)rrr-r-r.r zIndexObject._calculate_indexcCst|tr|jdkr|jdurtd|j}||||||jkr8|j d||j |_ ||_g|_ dS|j d||j|_ dSNrs.deleting slices only supports a:-1 with step 1) rslicestopstep ValueErrorrrrrrrrrr-r-r. __delitem__s    zIndexObject.__delitem__N)rrrr/rrr-r-r-r.rs rc@s(eZdZdZddZddZddZdS) PersistentNodeMapIndexObjectaa Debug oriented class to test persistent nodemap We need a simple python object to test API and higher level behavior. See the Rust implementation for more serious usage. This should be used only through the dedicated `devel.persistent-nodemap` config. cCs t|S)zReturn bytes containing a full serialization of a nodemap The nodemap should be valid for the full set of revisions in the index.)rpersistent_datarWr-r-r.nodemap_data_alls z-PersistentNodeMapIndexObject.nodemap_data_allcCsL|jdurdS|j}t||j|j|jj\}}d|_|_|_|||fS)zReturn bytes containing a incremental update to persistent nodemap This containst the data for an append-only update of the data provided in the last call to `update_nodemap_data`. N)_nm_root _nm_docketrupdate_persistent_data _nm_max_idxtip_rev)r$docketchangedrr-r-r.nodemap_data_incrementals  z5PersistentNodeMapIndexObject.nodemap_data_incrementalcCsD|dur t|\|_|_|jr||_dSd|_|_|_dSdS)zprovide full block of persisted binary data for a nodemap The data are expected to come from disk. See `nodemap_data_all` for a produceur of such data.N)r parse_datarrr)r$rnm_datar-r-r.update_nodemap_datas  z0PersistentNodeMapIndexObject.update_nodemap_dataN)rrrrrrrr-r-r-r.rs  rc@s.eZdZd ddZddZddZdd Zd S) InlinedIndexObjectrcCs(||_|d|_||jg|_dSr^)r _inline_scanrr)r$rinliner-r-r.r/s   zInlinedIndexObject.__init__cCsd}|dur dg||_d}|t|j|jkrJ||j}td|j|||j\}|dur5||j|<|d7}||j|7}|t|j|jks|t|jkrUtd|S)Nrrrscorrupted data) _offsetsrrrrrrrr)r$lgtoffcountrsr-r-r.rs$    zInlinedIndexObject._inline_scancCst|tr|jdkr|jdurtd|j}||||||jkr5|j d||_ ||_g|_ dS|j d||j|_ dSr) rrrrrrrrrrrrr-r-r.rs    zInlinedIndexObject.__delitem__cCrr^)rrr-r-r.rrz#InlinedIndexObject._calculate_indexNr)rrrr/rrrr-r-r-r.rs   rcCsL|tjkr t|S|s|tjkrt}nt}||dfSt}|||d|ffSr)r CHANGELOGV2parse_index_cl_v2REVLOGV2 IndexObject2rr)rrformatrBr-r-r. parse_index2"s   rcCs t|dfSr^)IndexChangelogV2)rr-r-r.r/rrc@s:eZdZejZddZddZddZddZ d d Z d S) rc Cs|dkrt||||jkrd}t|t||}||d<||d<||d<||d<t|}|||}||j||j<dS)z Replace an existing index entry's sidedata offset and length with new ones. This cannot be used outside of the context of sidedata rewriting, inside the transaction that creates the revision `rev`. rs2cannot rewrite entries outside of this transactionrr N)KeyErrorrrlisttuplerr) r$rsidedata_offsetsidedata_length offset_flagscompression_modemsgrnewr-r-r.replace_sidedata_info6s    z"IndexObject2.replace_sidedata_infocCsD|j|}|dd}|dd@}|dd@d?}|||tjfS)N  r)rrrr)r$rrr data_comp sidedata_compr-r-r.rTs   zIndexObject2._unpack_entrycCsB|dd}|dd@}|dd@d>}|||Bf7}|jj|S)Nr r rrr)r$rrrr rr-r-r.r[s   zIndexObject2._pack_entrycCs||}|||S)r)rrr-r-r.rcs zIndexObject2.entry_binarycCsd}||;}t|)rz9version header should go in the docket, not the index: %d)rProgrammingError)r$rrr-r-r.rhs zIndexObject2.pack_headerN) rrrrINDEX_ENTRY_V2rr rrrrr-r-r-r.r3s rc@sHeZdZejZejdejdejejdZdddZ ddZ dS) rNrTcCsx|j|}|tj|tj|tj|||tj|tj|tj|tj |tj |tj d@|tj d?d@|tj f SNr r) rrrINDEX_ENTRY_V2_IDX_OFFSET$INDEX_ENTRY_V2_IDX_COMPRESSED_LENGTH&INDEX_ENTRY_V2_IDX_UNCOMPRESSED_LENGTHINDEX_ENTRY_V2_IDX_PARENT_1INDEX_ENTRY_V2_IDX_PARENT_2INDEX_ENTRY_V2_IDX_NODEID"INDEX_ENTRY_V2_IDX_SIDEDATA_OFFSET-INDEX_ENTRY_V2_IDX_SIDEDATA_COMPRESSED_LENGTH#INDEX_ENTRY_V2_IDX_COMPRESSION_MODEINDEX_ENTRY_V2_IDX_RANK)r$rrritemsr-r-r.rxs&   zIndexChangelogV2._unpack_entryc Cs|tj}|tj}||ksJ||f||ksJ||f|tj|tj|tj|tj|tj|tj|tj |tj |tj d@|tj d@d>B|tj f }|jj|Sr)rENTRY_DELTA_BASEENTRY_LINK_REVENTRY_DATA_OFFSETENTRY_DATA_COMPRESSED_LENGTHENTRY_DATA_UNCOMPRESSED_LENGTHENTRY_PARENT_1ENTRY_PARENT_2 ENTRY_NODE_IDENTRY_SIDEDATA_OFFSET ENTRY_SIDEDATA_COMPRESSED_LENGTHENTRY_DATA_COMPRESSION_MODEENTRY_SIDEDATA_COMPRESSION_MODE ENTRY_RANKrr)r$rrbaselink_revrr-r-r.rs(     zIndexChangelogV2._pack_entry)T) rrrrINDEX_ENTRY_CL_V2rrrr)rrr-r-r-r.ros  rcCs t|dfS)zBlike parse_index2, but alway return a PersistentNodeMapIndexObjectN)r)rrr-r-r.parse_index_devel_nodemaps r-c Cs|dd|ddg}d}t|}d}t|}||krT||}td|||} || d}|||} d| vrE| d\} } | || <tj| dd|| <||ks|S)N(>cllllr)rrr_unpacksplitrrV) dmapcopymapstparentsre_sizepos1lpos2efcr-r-r.parse_dirstates     r?c Cst}|j}|d|t|D]+\}}||vr"d|||f}td|||| t |}||||q| S)Ns%s%sr0) stringiowritejoinr iteritems_packrkr_rarbrgetvalue)r4r5plcsrBr=r<r-r-r. pack_dirstates" rI)@ __future__rr8rzlibrrr thirdpartyrrrr r r rr rbytesiorArrErr2compress _compress decompress _decompressrQrPrRr?r@rAr:r;r4r5r6r7r3r1r2r>DIRSTATE_V2_DIRECTORY DIRSTATE_V2_ALL_UNKNOWN_RECORDED DIRSTATE_V2_ALL_IGNORED_RECORDEDrobjectrrrrrrREVLOGV1rrrrr-r?rIr-r-r-r.sd     p{,+ <5