-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyc


:Nc@@s%dZddlmZddlZddlZddlmZejedddlmZm	Z	m
Z
mZmZm
Z
ddlmZdd	d	ZejZee_d
ZdZdZd
ZdZejZejdedefdYZdefdYZeZ defdYZ!defdYZ"dZ#defdYZ$edZ%y,ddl&m'Z'm(Z(m)Z)m*Z*m+Z+WnHe,k
rZ-e
j.e-ddl/m'Z'm(Z(m)Z)m*Z*m+Z+nXejde(ejde)dZ0dS( s}Persistent maps from tuple_of_strings->string using CHK stores.

Overview and current status:

The CHKMap class implements a dict from tuple_of_strings->string by using a trie
with internal nodes of 8-bit fan out; The key tuples are mapped to strings by
joining them by , and  padding shorter keys out to the length of the
longest key. Leaf nodes are packed as densely as possible, and internal nodes
are all an additional 8-bits wide leading to a sparse upper tree.

Updates to a CHKMap are done preferentially via the apply_delta method, to
allow optimisation of the update operation; but individual map/unmap calls are
possible and supported. Individual changes via map/unmap are buffered in memory
until the _save method is called to force serialisation of the tree.
apply_delta records its changes immediately by performing an implicit _save.

TODO:
-----

Densely packed upper nodes.

i(tabsolute_importN(tlazy_imports(
from bzrlib import (
    errors,
    )
(terrorst	lru_cachetosutilstregistrytstatic_tuplettrace(tStaticTupleiicC@s=ttdd}|dkr9tjt}|t_n|S(sGet the per-thread page cache.

    We need a function to do this because in a new thread the _thread_caches
    threading.local object does not have the cache initialized yet.
    t
page_cacheN(tgetattrt_thread_cachestNoneRtLRUSizeCachet_PAGE_CACHE_SIZER	(R	((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt
_get_cacheIs
cC@stjdS(N(Rtclear(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytclear_cacheWsi2icC@s
dj|S(sDMap the key tuple into a search string that just uses the key bytes.t(tjoin(tkey((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_search_key_plainastplaintCHKMapcB@seZdZdZddZdZdZdZdZ	e
d	Zed
Z
edddd
ZeddddZeddddZdZddZdZdZdZdZedZdZdZRS(s=A persistent map from string to string backed by a CHK store.t_storet
_root_nodet_search_key_funccC@s^||_|dkrt}n||_|dkrHtd||_n|j||_dS(soCreate a CHKMap object.

        :param store: The store the CHKMap is stored in.
        :param root_key: The root key of the map. None to create an empty
            CHKMap.
        :param search_key_func: A function mapping a key => bytes. These bytes
            are then used by the internal nodes to split up leaf nodes into
            multiple pages.
        tsearch_key_funcN(RRRRtLeafNodeRt	_node_key(tselftstoretroot_keyR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt__init__os
			c
C@s0t}tj}tg|D]3\}}}|dk	r|dkr||^q}t|jd|}|rtj|d|nxK|D]C\}}	}|dk	r||	kr|j	|dtt
}qqWx6|D].\}}	}|	dk	r|j|	|qqW|r&|jn|j
S(sApply a delta to the map.

        :param delta: An iterable of old_key, new_key, new_value tuples.
            If new_key is not None, then new_key->new_value is inserted
            into the map; if old_key is not None, then the old mapping
            of old_key is removed.
        t
key_filters$New items are already in the map %r.tcheck_remapN(tFalseRt
from_sequencetsetRtlistt	iteritemsRtInconsistentDeltaDeltatunmaptTruetmapt_check_remapt_save(
Rtdeltathas_deletestas_sttoldRtvaluet	new_itemstexisting_newtnew((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytapply_deltas$	-	

cC@s1t|jtkr-|j|j|_ndS(s1Ensure that the root node is an object not a key.N(ttypeRRt	_get_node(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_ensure_rootscC@s?t|tkr7|j|}t||d|jS|SdS(sGet a node.

        Note that this does not update the _items dict in objects containing a
        reference to this node. As such it does not prevent subsequent IO being
        performed.

        :param node: A tuple key or node object.
        :return: A node object.
        RN(R8Rt_read_bytest_deserialiseR(Rtnodetbytes((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR9s


cC@seyt|SWnOtk
r`|jj|gdt}|jjd}|t|<|SXdS(Nt	unorderedtfulltext(RtKeyErrorRtget_record_streamR+tnexttget_bytes_as(RRtstreamR>((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR;s

cC@sH|j|j|jddddd|}|jddj|S(s+Return the tree in a string representation.tprefixttindenttinclude_keyss
(R:t_dump_tree_nodeRtappendR(RRItres((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt
_dump_trees

	
cC@s(g}|sd}n2|j}|d	k	rAd|df}nd}|jd|||jj|ft|tkrt|j|j	xt
|jjD]2\}}|j
|j|||dd|qWnCx@t
|jjD])\}	}
|jdt|	|
fqW|S(
sAFor this node and all children, generate a string representation.RGs %sis Nones	%s%r %s%ss  RIs      %r %rN(RRRKt	__class__t__name__R8tInternalNodeR't_iter_nodesRtsortedt_itemsR(textendRJttuple(RR=RFRHRItresulttkey_strtnode_keytsubRR3((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRJs"	""!iic	C@sV|j||d|d|d|}t|tk	rRtdt|fn|S(s5Create a CHKMap in store with initial_value as the content.

        :param store: The store to record initial_value in, a VersionedFiles
            object with 1-tuple keys supporting CHK key generation.
        :param initial_value: A dict to store in store. Its keys and values
            must be bytestrings.
        :param maximum_size: The maximum_size rule to apply to nodes. This
            determines the size at which no new data is added to a single node.
        :param key_width: The number of elements in each key_tuple being stored
            in this map.
        :param search_key_func: A function mapping a key => bytes. These bytes
            are then used by the internal nodes to split up leaf nodes into
            multiple pages.
        :return: The root chk of the resulting CHKMap.
        tmaximum_sizet	key_widthRs$we got a %s instead of a StaticTuple(t_create_directlyR8RtAssertionError(tklassRt
initial_valueRZR[RR ((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt	from_dicts	cC@s}||dd|}|jj|||j_g}x0|jD]"\}}	|jd||	fqDW|j|}
|
S(NR(RRtset_maximum_sizet
_key_widthtitemsRKR7(R^RR_RZR[RRVR/RR3R ((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_create_via_mapscC@std|}|j|||_tj}tg|jD]\}}	|||	f^q>|_tg|jjD]\}}
|j	||
^q{|_
t|j|_|j
|j|jdkrz|rz|j|krz|j|\}}t|dkr(tdnt|d|}|j|||_x'|D]\}
}|j|
|qWWnt|j|}|dS(NRis!Failed to split using node._spliti(RRaRbRR%tdictR(RStsumt_key_value_lent	_raw_sizetlent_lent_compute_search_prefixt_compute_serialised_prefixt
_current_sizet_splitR]RPtadd_nodeR't	serialise(R^RR_RZR[RR=R1RtvalR3RFtnode_detailstsplittsubnodetkeys((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR\s0
		47


	c#@sNjjjjkr(dSjjtj}j}ggdfdfdfd}||d|dt}t}tfd}d}xMs	rI|d7}sxD]\}	}
}}||rDq nj|}|
dk	rp|
|dfVq x.|jjD]\}
}
|
|
dfVqWq WdSs?xD]\}	}
}}||rqnj|}|
dk	r|
d|fVqx.|jjD]\}
}
|
d|
fVqWqWdSddddkrtj	\}	}
}}||rqn|
dk	r|
d|fVqF||qqddddkr=tj	\}	}
}}||rqn|
dk	r$|
|dfVqF||qqdddkrZt
}nt}dddkr}t
}nt}|r|rtj	}tj	}|d	|d	kr|d|d	|d	fVqqnjdd	jdd	kr4tj	tj	qn|r|rtj	\}}}}tj	\}}}}||krtd
||fn|||||qn|rtj	\}	}
}}||rqn||n|rtj	\}	}
}}||r0qn||qqWdS(sIterate over the changes between basis and self.

        :return: An iterator of tuples: (key, old_value, new_value). Old_value
            is None for keys only in self; new_value is None for keys only in
            basis.
        Nc	S@s|j|}t|tkr~|j|f}x|jjD]7\}}|j|}tj|||||fq@WnK|j|f}x9|jjD](\}}tj||d||fqWdS(N(
R9R8Rt_keyRSRcRtheapqtheappushR(	R=tpathta_maptpendingRR3t
search_keyRFtchild((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytprocess_nodeKs#c@st|jj}t|jj}|jdf}x4||D](\}}tj|d||fqDW|jdf}x4||D](\}}tj|d||fqWdS(N(R&RSRcRvRRwRx(t	self_nodet
basis_nodet
self_itemstbasis_itemsRyRFR}(t
basis_pendingtself_pending(s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytprocess_common_internal_nodesZs c@st|jj}t|jj}|jdf}xC||D]7\}}j|}tj||||fqDW|jdf}xC||D]7\}}j|}tj||||fqWdS(N(R&RSRcRvRRRwRx(RRRRRyRR3RF(tbasisRRR(s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytprocess_common_leaf_nodescs c@sj|}j|}t|tkrRt|tkrR||nZt|tkrt|tkr||n&||||dS(N(R9R8RPR(Rt	self_pathRt
basis_path(RRRRR~RR(s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytprocess_common_prefix_nodesnsc@s3x,|dk	r.|\}}|krtSqWtS(N(RR+R$(tkey_pathR(t
excluded_keys(s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytcheck_excludeds
iiis%r != %r(
RRR:R&RR9R(RRwtheappopR+R$R](RRRRRt	self_seent
basis_seenRtloop_counterRFRR=RyR3t	read_selft
read_basistself_detailst
basis_detailstself_prefixt_Rtbasis_prefixR((RRRRRR~RRs2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytiter_changes#s$

					!			
		


cC@sZ|j|dk	rAtj}g|D]}||^q&}n|jj|jd|S(s*Iterate over the entire CHKMap's contents.R"N(R:RRR%RR(R(RR"R1R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR(s

	"cC@s*t|jtkr|jS|jjSdS(sReturn the key for this map.N(R8RRRv(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRscC@s|jt|jS(N(R:RiR(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt__len__s
cC@stj|}|j|jj|j||\}}t|dkr`|dd|_ntt|d|j|_|jj	|ddj
|ddj|j_x'|D]\}}|jj||qWdS(sMap a key tuple to value.
        
        :param key: A key to map.
        :param value: The value to assign to key.
        iiRN(
RR%R:RR,RRiRPRRaRZRbRo(RRR3RFRrRsR=((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR,s
!	cC@sEt|tkr$tj|}nt|tkr:|S|jSdS(s4Get the key for a node whether it's a tuple or node.N(R8RURR%Rv(RR=((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR's
cC@sttj|}|jt|jtkrO|jj|j|d|}n|jj|j|}||_dS(sremove key from the map.R#N(RR%R:R8RRPR*R(RRR#tunmapped((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR*0s
cC@s>|jt|jtkr:|jj|j|_ndS(s Check if nodes can be collapsed.N(R:R8RRPR-R(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR-;s
cC@s?t|jtkr|jSt|jj|j}|dS(sMSave the map completely.

        :return: The key of the root node.
        i(R8RRR'RpR(RRu((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR.As(s_stores
_root_nodes_search_key_funcN(ROt
__module__t__doc__t	__slots__RR!R7R:R9R;R$RMR+RJtclassmethodR`RdR\RR(RRR,RR*R-R.(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRjs6					
							tNodecB@sqeZdZdZd	d
ZdZdZd
ZedZ	dZ
edZedZ
RS(sBase class defining the protocol for CHK Map nodes.

    :ivar _raw_size: The total size of the serialized key:value data, before
        adding the header bytes, and without prefix compression.
    RvRjt
_maximum_sizeRbRhRSt_search_prefixRicC@sCd|_d|_d|_||_d|_i|_d|_dS(sSCreate a node.

        :param key_width: The width of keys for this node.
        iN(RRvRjRRbRhRSR(RR[((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR!Xs						cC@sjtt|j}t|dkr8|d d}nd|jj|j|j|j|j	|j
|fS(Niis...]s3%s(key:%s len:%s size:%s max:%s prefix:%s items:%s)(tstrRRRSRiRNRORvRjRhRR(Rt	items_str((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt__repr__iscC@s|jS(N(Rv(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRqscC@s|jS(N(Rj(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRtscC@s|jS(s8What is the upper limit for adding references to a node.(R(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRZwscC@s
||_dS(sSet the size threshold for nodes.

        :param new_size: The size at which no data is added to a node. 0 for
            unlimited.
        N(R(Rtnew_size((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRa|scC@sq|j|r|Sd}xCtt||D],\}\}}||kr/|d8}Pq/q/W||d }|S(sGiven 2 strings, return the longest prefix common to both.

        :param prefix: This has been the common prefix for other keys, so it is
            more likely to be the common prefix in this case as well.
        :param key: Another string to compare to
        ii(t
startswitht	enumeratetzip(tclsRFRtpostlefttrighttcommon((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt
common_prefixs(
cC@sOd}xB|D]:}|dkr+|}q
n|j||}|s
dSq
W|S(sGiven a list of keys, find their common prefix.

        :param keys: An iterable of strings.
        :return: The longest common prefix of all keys.
        RGN(RR(RRuRR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytcommon_prefix_for_keyss
(s_keys_lens
_maximum_sizes
_key_widths	_raw_sizes_itemss_search_prefixs_search_key_func(RORRRR!RRRtpropertyRZRaRRR(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRMs				RcB@seZdZdZddZdZdZeddZ	ddZ
dZdZd	Z
d
ZdZdjZd
ZdZdZdZdZdZRS(sA node containing actual key:value pairs.

    :ivar _items: A dict of key->value items. The key is in tuple form.
    :ivar _size: The number of bytes that would be used by serializing all of
        the key/value pairs.
    t_common_serialised_prefixcC@s;tj|d|_|dkr.t|_n	||_dS(N(RR!RRRR(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR!s

	c	C@sptt|j}t|dkr8|d d}nd|jj|j|j|j|j	|j
|j|fS(Niis...]s?%s(key:%s len:%s size:%s max:%s prefix:%s keywidth:%s items:%s)(RRRRSRiRNRORvRjRhRRRb(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRscC@s|jdkrd}d}n#t|j}|j||j}dtt|jdtt|jdtt|jd|d|S(sAnswer the current serialised size of this node.

        This differs from self._raw_size in that it includes the bytes used for
        the header.
        ii	iN(RRRiRhRjRRRb(Rtbytes_for_itemst
prefix_len((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRms	cC@s"tj|}t||d|S(sDeserialise bytes, with key key, into a LeafNode.

        :param bytes: The bytes of the node.
        :param key: The key that the serialised node has.
        R(Rtexpect_static_tuplet_deserialise_leaf_node(R^R>RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytdeserialisescc@s|dk	ri}xx|D]p}t||jkray||j|fVWqtk
r]qXq|jt|t}|j|qW|r|j}xN|jj	D]:}x1|D])\}}|d| |kr|VPqqWqWqnx|jj	D]}|VqWdS(sIterate over items in the node.

        :param key_filter: A filter to apply to the node. It should be a
            list/set/dict or similar repeatedly iterable container.
        iN(
RRiRbRSRAt
setdefaultR&taddRcR((RRR"tfiltersRt
length_filtertitemtlength((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR(s&

cC@sBt|j|dtt|jddt|dS(Nis
(Rit_serialise_keyRtcount(RRR3((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRgscC@s
|j|S(N(R(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_search_keyscC@s+||j|<|j|j||7_|jd7_|j|}|jdkra||_n|j|j||_|j|}|j	t
kr|jn|j	dkr||_	n|j|j	||_	|jdkr'|jr'|j
|jkr'||j	ks |jr'tSntS(sMap a key to a value.

        This assumes either the key does not already exist, or you have already
        removed its size and length from self.

        :return: True if adding this node should cause us to split.
        iN(RSRhRgRjRRRRRRt_unknownRkRRmt_are_search_keys_identicalR+R$(RRR3tserialised_keyR|((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt
_map_no_splits,

	
cC@s|jtkrtdn|j}t|d}i}xb|jjD]Q\}}|j|}|| }t||kr|d|t|7}n||krtd|j}	|	j	|j
|j|	_|	||<n
||}	|	j|||\}
}t|dkrM||
kr9|j
|nt|
d|j}|j	|j
|j|_x$|D]\}
}	|j|
|	qqW|||<qMqMW||jfS(sWe have overflowed.

        Split this node into multiple LeafNodes, return it up the stack so that
        the next layer creates a new InternalNode and references the new nodes.

        :return: (common_serialised_prefix, [(node_serialised_prefix, node)])
        sSearch prefix must be knowniRR(RRR]RiRSR(RRRRaRRbR,tpopRPRoRc(RRRtsplit_atRVRR3R|RFR=t
sub_prefixRrtnew_nodeRs((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRn<s8	
	

	cC@s||jkrC|j|j||j|8_|jd8_nd|_|j||rk|j|S|jt	krt
d|jn|jd|fgfSdS(sMap key to value.is%r must be knownRGN(RSRhRgRjRRvRRnRRR](RRRR3((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR,ls"	
RcC@sdg}|jd|j|jd|j|jd|j|jdkr|jdt|jdkrtdqn&|jd|jft|j}xt	|jj
D]\}}tj|dg}d|j
|t|f}|j|js3td|j|fn|j|||j|qW|jd
d|\}}	}	td	|j|_d
j|}
t|
|jkrtdn|
t|j<|jgS(sSerialise the LeafNode to store.

        :param store: A VersionedFiles honouring the CHK extensions.
        :return: An iterable of the keys inserted by this operation.
        s	chkleaf:
s%d
s
is<If _common_serialised_prefix is None we should have no itemss%s
s%s%s
sKWe thought the common prefix was %r but entry %r does not have it in commonssha1:RGsInvalid _current_sizeN(N((RKRRbRjRRRiRSR]RRRcRtchunks_to_linesRRRTt	add_linesRtinternRvRRmR(RRtlinesRRR3tvalue_linest
serializedtsha1RR>((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRp{s4	
"cC@sgS(s7Return the references to other CHK's held by this node.((R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytrefsscC@s>g|jD]}|j|^q
}|j||_|jS(sDetermine the common search prefix for all keys in this node.

        :return: A bytestring of the longest search key prefix that is
            unique within this node.
        (RSRRR(RRtsearch_keys((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRks%cC@sRd}xE|jD]:}|j|}|dkr:|}q||krtSqWtS(sCheck to see if the search keys for all entries are the same.

        When using a hash as the search_key it is possible for non-identical
        keys to collide. If that happens enough, we may try overflow a
        LeafNode, but as all are collisions, we must not split.
        N(RRSRR$R+(Rtcommon_search_keyRR|((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRs	cC@s>g|jD]}|j|^q
}|j||_|jS(sDetermine the common prefix for serialised keys in this node.

        :return: A bytestring of the longest serialised key prefix that is
            unique within this node.
        (RSRRR(RRtserialised_keys((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRls%cC@sy&|j|j||j|8_Wn*tk
rRtjd||jnX|jd8_|j|=d|_|j	|j
|S(sUnmap key from the node.skey %s not found in %riN(RhRgRSRARtmutterRjRRvRkRl(RRR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR*s&

	

(s_common_serialised_prefixN(RORRRRR!RRmRRR(RgRRRnR,RRRpRRkRRlR*(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRs(				
#			$	0	
		%		
		RPcB@seZdZdZdddZdZdZeddZ	ddZ
dddZd	Zd
Z
dZdZd
ZdZdZddZedZdZRS(sA node that contains references to other nodes.

    An InternalNode is responsible for mapping search key prefixes to child
    nodes.

    :ivar _items: serialised_key => node dictionary. node may be a tuple,
        LeafNode or InternalNode.
    t_node_widthRGcC@sDtj|d|_||_|dkr7t|_n	||_dS(Ni(RR!RRRRR(RRFR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR!s
		cC@s&|jdkrtdn|j|jsLtd||jfnt|t|jdkrtd|t|jdfn|jt|7_t|jst||_n|jt|jdkrtd|jt|jdfn||j|<d|_dS(sAdd a child node with prefix prefix, and node node.

        :param prefix: The search key prefix for node.
        :param node: The node being added.
        s!_search_prefix should not be Nones(prefixes mismatch: %s must start with %sis&prefix wrong length: len(%s) is not %ds!node width mismatch: %d is not %dN(	RRR]RRiRjRSRRv(RRFR=((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRos  #
cC@s@|jtt|jtt|jtt|jS(s0Answer the current serialised size of this node.(RhRiRRjRbR(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRms,cC@s"tj|}t||d|S(sDeserialise bytes to an InternalNode, with key key.

        :param bytes: The bytes of the node.
        :param key: The key that the serialised node has.
        :return: An InternalNode instance.
        R(RRt_deserialise_internal_node(R^R>RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRscc@sOxH|j|d|D]1\}}x"|j|d|D]}|Vq8WqWdS(NR"(RQR((RRR"R=tnode_filterR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR(s"cc@si}t}|dkrnt}x|jjD]9\}}|jtkr\|df||<q.|dfVq.Wnt|dkrx|D]}PqW|j|}	t|	|j	krt}y|j|	}Wnt
k
rdSX|jtkr|	|gf||<q||gfVdSqn|si}
i}x^|D]V}|j|}	|jt|	t}|j
|	|
j|	gj|q8W|j	|kr3t|dkr3||j	}
x|
D]e}	y|j|	}Wnt
k
rqnX|
|	}|jtkr!|	|f||<q||fVqWq|j}x|jjD]\}}g}x>|D]6\}}|| }||krh|j|
|qhqhW|rO|jtkr||f||<q||fVqOqOWn|rt}x|D]{}yt|}Wnt
k
r"qqXt||d|j}||\}}||j|<|j
|||fVqWx|D]
}||=q{Wn|r|dkrt|}nt|}xtdt||D]}||||!}|j|dt}g}x{|D]s}|jd}t||jd|j}||j\}}|j||f||j|<|t|j<qWx|D]}|VqWqWndS(s`Iterate over node objects which match key_filter.

        :param store: A store to use for accessing content.
        :param key_filter: A key filter to filter nodes. Only nodes that might
            contain a key in key_filter will be returned.
        :param batch_size: If not None, then we will return the nodes that had
            to be read using get_record_stream in batches, rather than reading
            them all at once.
        :return: An iterable of nodes. This function does not have to be fully
            consumed.  (There will be no pending I/O when items are being returned.)
        iNRiR?R@(R$RR+RSR(RNRRit_search_prefix_filterRRARR&RRKRcRTRR<RR'trangeRBRDR(RRR"t
batch_sizeRutshortcutRFR=Rt
search_prefixtprefix_to_keystlength_filtersRtsearch_prefixestnode_key_filterRRt
found_keysR>t	key_ordertbatch_starttbatchREtnode_and_filterstrecordtinfo((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRQs









	







cC@sFt|jstdn|j|}|jt|jdkrrtd|jt|jdfn|j|js|j|j|}t|d|j	}|j
|j|j|_|j
|jt|d ||j|||Sg|j|d|gD]\}}|^q}	|	rB|	d}
n|j|t}
t|
}t|
tkr|
j}nd}|
j|||\}
}t|dkr|dd}
|j|t|
|_|
|j|<d|_|}t|
tkr|dkr5tjd|j|}q|
j}||}|dkrc|tkso|tkrtjd|||j|}qn|jdkrtd	n|jd
|fgfS|j|t}
|
|
_x$|D]\}}|
j
||qW|j|t|
|_d|_|jd
|fgfS(sMap key to value.s#can't map in an empty InternalNode.is!node width mismatch: %d is not %dRR"is*checking remap as InternalNode -> LeafNodes,checking remap as size shrunk by %d to be %ds!_search_prefix should not be NoneRGN(RiRSR]RRRRRRPRRaRRbRoR,RQt
_new_childRR8RmRRjRvRRR-t_INTERESTING_NEW_SIZEt_INTERESTING_SHRINKAGE_LIMIT(RRRR3R|t
new_prefixt
new_parentR=RtchildrenR}told_lentold_sizeRFRrRRt	shrinkageRs((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR,sl#		.

	


		cC@sB|}|j|j|j|_|j|_||j|<|S(s&Create a new child node of type klass.(RaRRbRRS(RR|R^R}((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRs	
c
c@sxc|jjD]R}t|tkr.qn|jd
k	rCqnx|j|D]}|VqSWqWdg}|jd|j|jd|j	|jd|j
|jd
krtdn|jd|jft
|j}xt|jjD]\}}t|tkr0|d}n
|jd}d||f}|j|js{td||jfn|j||qW|jdd|\}}	}	td|j|_d	j|t|j<|jVd
S(
sSerialise the node to store.

        :param store: A VersionedFiles honouring the CHK extensions.
        :return: An iterable of the keys inserted by this operation.
        s	chknode:
s%d
s!_search_prefix should not be Nones%s
is%s%s
s(prefixes mismatch: %s must start with %sssha1:RGN(N((RSt
itervaluesR8RRvRRpRKRRbRjRR]RiRRRcRRRRR(
RRR=RRRRFt
serialisedRR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRp	s8
	"

cC@s|j|d|j|j S(s/Return the serialised key for key in this node.R(RR(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR/scC@s|j||j S(s6Serialise key for use as a prefix filter in iteritems.(RR(RR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR5scc@sp||jkrLx6|jjD]%}x|j|D]}|Vq5WqWdSx|jjD]\}}q\WdS(sSplit this node into smaller nodes starting at offset.

        :param offset: The offset to start the new child nodes at.
        :return: An iterable of (prefix, node) tuples. prefix is a byte
            prefix for reaching node.
        N(RRStvaluesRnRc(RtoffsetR=RVR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRn9s
cC@sw|jdkrtdng}xL|jjD];}t|tkr\|j|q4|j|jq4W|S(s7Return the references to other CHK's held by this node.s unserialised nodes have no refs.N(	RvRR]RSRR8RRKR(RRR3((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRHscC@s|j|j|_|jS(sReturn the unique key prefix for this node.

        :return: A bytestring of the longest search key prefix that is
            unique within this node.
        (RRSR(Rt	extra_key((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRkTsc
C@s0t|jstdng|j|d|gD]\}}|^q7}|rb|d}nt||jd8_|j||}d|_|j	|}	t|dkr|j|	=d}n
||j|	<t|jdkr|jj
dSt|tkr|S|r(|j
|S|SdS(s+Remove key from this node and its children.s%can't unmap in an empty InternalNode.R"iiN(RiRSR]RQRARjR*RRvRRR8RPR-(
RRRR#R=RRR}RR|((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR*]s,.
	
	

cC@std|j}|j|j|j|_xo|j|ddD]X\}}t|tkrf|Sx3|jj	D]"\}}|j
||rv|SqvWqDWtjd|S(sCheck if all keys contained by children fit in a single LeafNode.

        :param store: A store to use for reading more nodes
        :return: Either self, or a new LeafNode which should replace self.
        RRisremap generated a new LeafNode(
RRRaRRbRQR8RPRSR(RRR(RRtnew_leafR=RRR3((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR-|s"
(s_node_widthN(RORRRRR!RoRmRRR(RQR,RRpRRRnRRkR+R*R-(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRPs&			N			&					cC@sd|jdr*tj||d|}n6|jdrTtj||d|}ntd|S(s7Helper for repositorydetails - convert bytes to a node.s	chkleaf:
Rs	chknode:
sUnknown node type.(RRRRPR](R>RRR=((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR<stCHKMapDifferencecB@sbeZdZd
dZdZdZdZdZdZ	dZ
dZd	ZRS(smIterate the stored pages and key,value pairs for (new - old).

    This class provides a generator over the stored CHK pages and the
    (key, value) pairs that are in any of the new maps and not in any of the
    old maps.

    Note that it may yield chk pages that are common (especially root nodes),
    but it won't yield (key,value) pairs that are common.
    cC@s||_||_||_||_t|j|_t|_t|_||_g|_	g|_
g|_d|_
dS(N(Rt_new_root_keyst_old_root_keyst_pbR&t
_all_old_chkst_all_old_itemst_processed_new_refsRt
_old_queuet
_new_queuet_new_item_queueRt_state(RRt
new_root_keyst
old_root_keysRtpb((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyR!s								c	c@stj}|jj|dt}x|D]}|jdk	rM|jjn|jdkrwt	j
|j|jn|jd}t
||jd|j}t|tkr|jj}g}ng}|jj}||||fVq(WdS(NR?tabsentR@R(RR%RRBR+RRtticktstorage_kindRtNoSuchRevisionRRDR<RR8RPRSRc(	RRuR1RERR>R=tprefix_refsRc((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_read_nodes_from_stores 	
	c	C@sg}|j}x|j|jD]\}}}}g|D]}|d|kr;|^q;}g|D]}|d^qd}|j||jj||j|q"W|S(Ni(RR
RtupdateRRT(	Rtold_chks_to_enqueuetall_old_chksRR=R	Rctp_rtnew_refs((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_read_old_roots
s	"

cC@szxs|D]k\}}t}x:tt|ddD] }|| |kr2t}Pq2q2W|rbqn|jj|qWdS(Nii(R+txrangeRiR$RRK(Rtnew_prefixesRRFtreftnot_interestingti((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_enqueue_oldscc@s|jst|j|_dS|j}t|jj|j}t}|j}|j	|x'|j
|D]\}}}}g|D]/}	|	d|jkr|	d|kr|	^q}g|D]}	|	d^q}
|j	g|D]}	|	d^q|jj|
g|D]}||jkr|^q}|j
j||j	g|D]}|j|d^qY|j	|
|VquWxGt|D]9}
|j	gtdt|
D]}|
| ^qqW|j||dS(sRead the root pages.

        This is structured as a generator, so that the root records can be
        yielded up to whoever needs them without any buffering.
        Nii(RR'RRRR&t
differenceRRRR
RTRRRRRiR(RRtnew_keysRtprocessed_new_refsRR=R	RcRRRR4RFR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_read_all_roots.s4			

$
	$
	7cc@skt|j}g|_|j}|j}|j}g|jD]}||kr=|^q=}g|_|rxd|fVn|j|}|j|x|rft}|j}x|j	|D]o\}	}
}}|rg|D]}||kr|^q}n|	|fV|g|D]}
|
d^q~qW|j|}|j|}|j||}qWdS(Ni(
R&RRRRRRRRR
(RRR
Rt
all_old_itemsRR4t	next_refstnext_refs_updateRRtp_refsRcR((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_flush_new_queueds4					
			"
!
cC@s|j}g|_|j}x{|j|D]j\}}}}|jj|g|D]\}}||krT|^qT}|jj||j|q+WdS(N(RRR
RRRT(RRR
RRR	Rctr((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_process_next_olds			"+cC@s$x|jr|jqW|jS(N(RR!R(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt_process_queuesscc@sNx|jD]}|gfVq
Wx%|jD]\}}||fVq/WdS(N(RR"(RRRc((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytprocesssN(
RORRRR!R
RRRRR!R"R#(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyRs	#	"			6	-	
	cC@s+t|||d|jd|}|jS(sGiven root keys, find interesting nodes.

    Evaluate nodes referenced by interesting_root_keys. Ones that are also
    referenced from uninteresting_root_keys are not considered interesting.

    :param interesting_root_keys: keys which should be part of the
        "interesting" nodes (which will be yielded)
    :param uninteresting_root_keys: keys which should be filtered out of the
        result set.
    :return: Yield
        (interesting record, {interesting key:values})
    RR(RRR#(Rtinteresting_root_keystuninteresting_root_keysRtiterator((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pytiter_interesting_nodess
			(t_bytes_to_text_keyt_search_key_16t_search_key_255RRshash-16-wayshash-255-waycC@st|tk	r1td|t|fnt|dkrbtd|t|fnt|dtk	rtd|t|dfn|djdstd|fndS(	sHelper function to assert that a key is properly formatted.

    This generally shouldn't be used in production code, but it can be helpful
    to debug problems.
    s key %r is not StaticTuple but %sis#key %r should have length 1, not %dis key %r should hold a str, not %rssha1:skey %r should point to a sha1:N(R8Rt	TypeErrorRit
ValueErrorRR(R((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt
_check_keys(1Rt
__future__RRwt	threadingtbzrlibRtglobalsRRRRRRtbzrlib.static_tupleRRtlocalRRR	RRRRRtRegistrytsearch_key_registrytregistertobjectRRRRRPR<RR'tbzrlib._chk_map_pyxR(R)R*RRtImportErrortetfailed_to_load_extensiontbzrlib._chk_map_pyR-(((s2/usr/lib/python2.7/dist-packages/bzrlib/chk_map.pyt<module>&sJ.				_	,	,
,

Copyright © 2017 || Recoded By Mr.Bumblebee