o ö]LbŸã@s¾dZddlmZddlZddlZddlmZmZddl m Z m Z ddl m Z dZdZd Zd Zd Zd Zd ZdZdZdZdZdZe d¡Ze d¡Zdd„Zdd„Zd dd„Zdd„Z dd„Z!dS)!aacore code for "sidedata" support The "sidedata" are stored alongside the revision without actually being part of its content and not affecting its hash. It's main use cases is to cache important information related to a changesets. The current implementation is experimental and subject to changes. Do not rely on it in production. Sidedata are stored in the revlog itself, thanks to a new version of the revlog. The following format is currently used:: initial header: sidedata (repeated N times): normal raw text: This is a simple and effective format. It should be enough to experiment with the concept. é)Úabsolute_importNé)ÚerrorÚ requirements)Ú constantsÚflagutil)Úhashutiléééééééé é é é z>Hz>HL20scCs~t| ¡ƒ}| ¡t t|ƒ¡g}|D]\}}t |¡ ¡}|  t  |t|ƒ|¡¡q|D] \}}|  |¡q.d  |¡}|S)Nó) ÚlistÚitemsÚsortÚSIDEDATA_HEADERÚpackÚlenrÚsha1ÚdigestÚappendÚSIDEDATA_ENTRYÚjoin)ÚsidedataÚbufÚkeyÚvaluer©r$ú@/usr/lib/python3/dist-packages/mercurial/revlogutils/sidedata.pyÚserialize_sidedata@s     r&c Cs¸i}d}t |dtj…¡\}|tj7}tjtj|}t|ƒD]9}|tj}t |||…¡\}}} |}||} t||| …ƒ} t | ¡ ¡} | | krSt   || | ¡‚| ||<| }q |S)Nr) rÚunpackÚsizerÚrangeÚbytesrrrrÚSidedataHashError) Úblobr ÚoffsetÚnbentryÚ dataoffsetÚiÚ nextoffsetr"r(Ú storeddigestÚnextdataoffsetÚ entrytextÚ readdigestr$r$r%Údeserialize_sidedataMs"   r6Fc Cs–t t¡}t t¡}||j}|j|}|r||}}|j ¡D]#\}}| ¡D]\} } | |vr7|| | ¡| |vrB|| | ¡q(q |||f} | S)a Returns a dictionary mapping revlog types to tuples of `(repo, computers, removers)`: * `repo` is used as an argument for computers * `computers` is a list of `(category, (keys, computer, flags)` that compute the missing sidedata categories that were asked: * `category` is the sidedata category * `keys` are the sidedata keys to be affected * `flags` is a bitmask (an integer) of flags to remove when removing the category. * `computer` is the function `(repo, store, rev, sidedata)` that returns a tuple of `(new sidedata dict, (flags to add, flags to remove))`. For example, it will return `({}, (0, 1 << 15))` to return no sidedata, with no flags to add and one flag to remove. * `removers` will remove the keys corresponding to the categories that are present, but not needed. If both `computers` and `removers` are empty, sidedata will simply not be transformed. )Ú collectionsÚ defaultdictrÚ_wanted_sidedataÚ_sidedata_computersrr) ÚrepoÚremote_sd_categoriesÚpullÚ sd_computersÚ sd_removersÚ to_generateÚ to_removeÚ revlog_kindÚ computersÚcategoryÚcomputerÚsidedata_helpersr$r$r%Úget_sidedata_helpersbs     €ü rGcCsœ|\}}}|j}d}d} | |g¡D]\} } } | ||||ƒ\}} || dO}| | dO} q| |g¡D]\}}} |D]}| |d¡q:| | O} q3||| ffS)aOReturns the sidedata for the given revision after running through the given helpers. - `store`: the revlog this applies to (changelog, manifest, or filelog instance) - `sidedata_helpers`: see `get_sidedata_helpers` - `sidedata`: previous sidedata at the given rev, if any - `rev`: affected rev of `store` rr N)rBÚgetÚpop)ÚstorerFr Úrevr;r>r?ÚkindÚ flags_to_addÚflags_to_removeÚ_keysÚ sd_computerÚ_flagsÚflagsÚkeysÚ _computerr"r$r$r%Úrun_sidedata_helpers‹s    rUcCs@ddlm}tj|jvr| t¡| tj ttf|j t j ¡dS)Nr)Úmetadata) ÚrVÚrequirementsmodÚCOPIESSDC_REQUIREMENTrÚregister_wanted_sidedataÚSD_FILESÚregister_sidedata_computerrÚKIND_CHANGELOGÚcopies_sidedata_computerrÚREVIDX_HASCOPIESINFO)r;rVr$r$r%Úset_sidedata_spec_for_repo£s   ûr`)F)"Ú__doc__Ú __future__rr7ÚstructrWrrrXÚ revlogutilsrrÚutilsrÚSD_TEST1ÚSD_TEST2ÚSD_TEST3ÚSD_TEST4ÚSD_TEST5ÚSD_TEST6ÚSD_TEST7Ú SD_P1COPIESÚ SD_P2COPIESÚ SD_FILESADDEDÚSD_FILESREMOVEDr[ÚStructrrr&r6rGrUr`r$r$r$r%Ús4     )