HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/branch.cpython-39.pyc
a

�*�^��@s�ddlmZddlmZee�d�ddlmZmZmZddlm	Z	ddl
mZddlm
Z
dd	lmZmZdd
lmZmZmZmZmZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�de	�Ze�e_Gdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�dej"�Z#e�$�Z%e#e%�Z&e&�'ddd�e&�'ddd �e&�'d!dd"�e&�'d#dd$�e&�'d%dd&�e&�(d!�Gd'd(�d(e
�Z)Gd)d*�d*e�Z*Gd+d,�d,e*�Z+Gd-d.�d.e*�Z,Gd/d0�d0e�Z-Gd1d2�d2e�Z.d3d4�Z/Gd5d6�d6e.�Z0e.�1e0�d7S)8�)�absolute_import�)�lazy_importaH
import itertools
from breezy import (
    cleanup,
    config as _mod_config,
    debug,
    memorytree,
    repository,
    revision as _mod_revision,
    tag as _mod_tag,
    transport,
    ui,
    urlutils,
    )
from breezy.bzr import (
    fetch,
    remote,
    vf_search,
    )
from breezy.i18n import gettext, ngettext
)�
controldir�errors�registry)�Hooks)�InterObject)�LogicalLockResult)�	text_type�	viewitems)�mutter�mutter_callsite�note�is_quiet�warningc@seZdZdZdd�ZdS)�UnstackableBranchFormatzzThe branch '%(url)s'(%(format)s) is not a stackable format. You will need to upgrade the branch to permit branch stacking.cCstj�|�||_||_dS�N)r�BzrError�__init__�format�url)�selfrr�r�//usr/lib/python3/dist-packages/breezy/branch.pyr>sz UnstackableBranchFormat.__init__N)�__name__�
__module__�__qualname__Z_fmtrrrrrr9src@s�eZdZdZdZedd��Zedd��Zd�dd�Zd	d
�Z	dd�Z
d
d�Zdd�Zd�dd�Z
dd�Zed�dd��Zed�dd��Zed�dd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd�d(d)�Zd*d+�Zeee�Zd,d-�Zd�d.d/�Zd�d0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d�d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(d�dHdI�Z)dJdK�Z*dLdM�Z+dNdO�Z,dPdQ�Z-dRdS�Z.dTdU�Z/dVdW�Z0d�dXdY�Z1dZd[�Z2d\d]�Z3d�d^d_�Z4d�d`da�Z5dbdc�Z6ddde�Z7d�dfdg�Z8dhdi�Z9djdk�Z:dldm�Z;dndo�Z<dpdq�Z=drds�Z>dtdu�Z?dvdw�Z@dxdy�ZAdzd{�ZBd|d}�ZCd~d�ZDd�d��ZEd�d�d��ZFd�d��ZGd�d�d��ZHd�d�d��ZId�d�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d�d��ZNd�d�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d�d��Z\d�d�d��Z]d�d��Z^d�d�d��Z_d�d��Z`d�d��Zad�d�d��Zbd�d�d��Zcd�d�d��Zdd�d�d„Zed�dĄZfd�dƄZgd�dȄZhd�dʄZid�d̄Zjd�d΄ZkdS)��Brancha>Branch holding a history of revisions.

    :ivar base:
        Base directory/url of the branch; using control_url and
        control_transport is more standardized.
    :ivar hooks: An instance of BranchHooks.
    :ivar _master_branch_cache: cached result of get_master_branch, see
        _clear_cached_state.
    NcCs|jSr)Z
_transport�rrrr�control_transportRszBranch.control_transportcCs|jjSr)r�user_transportrrrrr!VszBranch.user_transportcCsb|j�|�|_d|_d|_i|_g|_d|_d|_d|_	|�
|�tjd}|D]}||�qPdS)N�open)
�_format�	make_tags�tags�_revision_history_cache�_revision_id_to_revno_cache�#_partial_revision_id_to_revno_cache�_partial_revision_history_cache�_last_revision_info_cache�_master_branch_cache�_merge_sorted_revisions_cache�
_open_hookr�hooks)r�possible_transportsr.�hookrrrrZs

zBranch.__init__cCsdS)z<Called by init to allow simpler extension of the base class.Nr�rr/rrrr-hszBranch._open_hookcCs`|jjD] }|j|krtd||�dSq|�||�}|�|j�rPt�|j|��|j�|�dS)zAActivate the branch/repository from url as a fallback repository.z)duplicate activation of fallback %r on %rN)	�
repository�_fallback_repositories�user_urlr
�_get_fallback_repository�has_same_locationrZUnstackableLocationErrorZadd_fallback_repository)rrr/Zexisting_fallback_repoZreporrr�_activate_fallback_locationks
z"Branch._activate_fallback_locationcCs0|j��|j��|��}|dur,|��dS)z�Break a lock if one is present from another instance.

        Uses the ui factory to ask for confirmation if the lock may be from
        an active process.

        This will probe the repository for its lock as well.
        N)�
control_files�
break_lockr2�get_master_branch)r�masterrrrr9ys


zBranch.break_lockcCs"|jjjst�|jj|jj��dSr)r2r#Zsupports_external_lookupsr�UnstackableRepositoryFormat�baserrrr�_check_stackable_repo�s
�zBranch._check_stackable_repocCsNt|j�dkr|��g|_tj|j|j||d�|jdtjkrJ|j��dS)a*Extend the partial history to include a given index

        If a stop_index is supplied, stop when that index has been reached.
        If a stop_revision is supplied, stop when that revision is
        encountered.  Otherwise, stop when the beginning of history is
        reached.

        :param stop_index: The index which should be present.  When it is
            present, history extension will stop.
        :param stop_revision: The revision id which should be present.  When
            it is encountered, history extension will stop.
        r)�
stop_index�
stop_revision���N)�lenr)�
last_revisionr2Z_iter_for_revno�
_mod_revision�
NULL_REVISION�pop)rr?r@rrr�_extend_partial_history�s
��zBranch._extend_partial_historycCs|��}d|fd|fgS)zJGet the references needed for check().

        See breezy.check.
        zrevision-existence�lefthand-distance)rC)r�revidrrr�_get_check_refs�szBranch._get_check_refsFcCs tjj|||d�}|j||d�S)z�Open the branch rooted at base.

        For instance, if the branch is at URL/.bzr/branch,
        Branch.open(URL) -> a Branch instance.
        )r/�_unsupported)�unsupportedr/)r�
ControlDirr"�open_branch)r=rKr/�controlrrrr"�s��zBranch.opencCstj�||�}|j|||d�S)z#Open the branch rooted at transport)�namerLr/)rrM�open_from_transportrN)�	transportrPrKr/rOrrrrQ�s��zBranch.open_from_transportcCs&tj�||�\}}|j|d�}||fS)aOpen an existing branch which contains url.

        This probes for a branch at url, and searches upwards from there.

        Basically we keep looking up until we find the control directory or
        run into the root.  If there isn't one, raises NotBranchError.
        If there is one and it is either an unrecognised format or an
        unsupported format, UnknownFormatError or UnsupportedFormatError are
        raised.  If there is one, it is returned, along with the unused portion
        of url.
        �r/)rrM�open_containingrN)rr/rO�relpath�branchrrrrT�s

�zBranch.open_containingcCs|��o|j��S)z�Should _basic_push merge this branch's tags into the target?

        The default implementation returns False if this branch has no tags,
        and True the rest of the time.  Subclasses may override this.
        )�
supports_tagsr%Zget_tag_dictrrrr�_push_should_merge_tags�szBranch._push_should_merge_tagscCs
t�|�S)z�Get a breezy.config.BranchConfig for this Branch.

        This can then be used to get and set configuration options for the
        branch.

        :return: A breezy.config.BranchConfig.
        )�_mod_configZBranchConfigrrrr�
get_config�szBranch.get_configcCs
t�|�S)z�Get a breezy.config.BranchStack for this Branch.

        This can then be used to get and set configuration options for the
        branch.

        :return: A breezy.config.BranchStack.
        )rYZBranchStackrrrr�get_config_stack�szBranch.get_config_stackcCst|j��dS)z�Store uncommitted changes from a ShelfCreator.

        :param creator: The ShelfCreator containing uncommitted changes, or
            None to delete any stored changes.
        :raises: ChangesAlreadyStored if the branch already has changes.
        N)�NotImplementedError�store_uncommitted)rZcreatorrrrr]�szBranch.store_uncommittedcCst|j��dS)z�Return a shelf.Unshelver for this branch and tree.

        :param tree: The tree to use to construct the Unshelver.
        :return: an Unshelver or None if no changes are stored.
        N)r\�
get_unshelver)r�treerrrr^�szBranch.get_unshelvercCs"t�|j|�}tj||d�}|jS)z)Get the repository we fallback to at url.rS)�urlutils�joinr=rr"r2)rrr/Za_branchrrrr5szBranch._get_fallback_repositoryc
Cs�|��}|s�|��s�z:|�|�}|r<|j|jkr<t�|j��|durL|jWSWn^tjyx}z|�WYd}~n>d}~0tjy�}ztdt	|��WYd}~n
d}~00|�
�S)Nz@Could not connect to bound branch, falling back to local nick.
 )rZZhas_explicit_nicknamer:r4rZ
RecursiveBind�nickrr
�strZget_nickname)r�localr/�configr;�errr�	_get_nicks
�zBranch._get_nickcCs|��jd|dd�dS)NZnicknameT)Zwarn_masked)rZZset_user_option)rrbrrr�	_set_nickszBranch._set_nickcCst|j��dSr)r\�	is_lockedrrrrri szBranch.is_lockedc	Cs�dtjvrtdd�|j��}|dur>|�||�s>t�||��|�|g�}||vr^t�	||��|}g}t
j}||vr�t||�dkr�||�|�
|�||d}|�|g�}ql|��|S)N�evil�z&_lefthand_history scales with history.r)�debug�debug_flagsrr2�	get_graph�is_ancestorr�DivergedBranches�get_parent_map�NoSuchRevisionrD�check_not_reserved_idrB�append�reverse)	r�revision_id�last_rev�other_branch�graphZparents_mapZcurrent_rev_idZnew_historyrsrrr�_lefthand_history#s*


�
zBranch._lefthand_historycCst|j��dS)z�Lock the branch for write operations.

        :param token: A token to permit reacquiring a previously held and
            preserved lock.
        :return: A BranchWriteLockResult.
        N)r\�
lock_write)r�tokenrrrr{>szBranch.lock_writecCst|j��dS)z`Lock the branch for read operations.

        :return: A breezy.lock.LogicalLockResult.
        N)r\�	lock_readrrrrr}GszBranch.lock_readcCst|j��dSr)r\�unlockrrrrr~Nsz
Branch.unlockcCst|j��dS)z1Return lock mode for the Branch: 'r', 'w' or NoneN)r\�peek_lock_moderrrrrQszBranch.peek_lock_modecCst|j��dSr)r\�get_physical_lock_statusrrrrr�UszBranch.get_physical_lock_statuscCsH|���,|�|�}|r"||j|<|Wd�S1s:0YdS)a�Return the revision_id for a dotted revno.

        :param revno: a tuple like (1,) or (1,1,2)
        :param _cache_reverse: a private parameter enabling storage
           of the reverse mapping in a top level cache. (This should
           only be done in selective circumstances as we want to
           avoid having the mapping cached multiple times.)
        :return: the revision_id
        :raises errors.NoSuchRevision: if the revno doesn't exist
        N)r}�_do_dotted_revno_to_revision_idr()r�revnoZ_cache_reverse�rev_idrrr�dotted_revno_to_revision_idXs



z"Branch.dotted_revno_to_revision_idc
s�t��dkrVz|��d�WStjyT}zt��d|j��WYd}~n
d}~00|��}�fdd�t|�D�}t|�dkr�|dSd�t	t
���}t�||��dS)z�Worker function for dotted_revno_to_revision_id.

        Subclasses should override this if they wish to
        provide a more efficient implementation.
        rrNcsg|]\}}�|kr|�qSrr)�.0rv�
this_revno�r�rr�
<listcomp>us�z:Branch._do_dotted_revno_to_revision_id.<locals>.<listcomp>�.)rB�
get_rev_idrZRevisionNotPresent�GhostRevisionsHaveNoRevnorv�get_revision_id_to_revno_maprra�maprcrr)rr�rf�revision_id_to_revnoZrevision_idsZ	revno_strrr�rr�is(
�z&Branch._do_dotted_revno_to_revision_idcCs6|���|�|�Wd�S1s(0YdS)zhGiven a revision id, return its dotted revno.

        :return: a tuple like (1,) or (400,1,3).
        N)r}�_do_revision_id_to_dotted_revno)rrvrrr�revision_id_to_dotted_revno~s
z"Branch.revision_id_to_dotted_revnocCs�|j�|�}|dur|S|jr>|j�|�}|dur>t�||��z|�|�}|fWStjy�|���|�}|dur�t�||��Yn0|S)z)Worker function for revision_id_to_revno.N)r(�getr'rrrr�r�)rrv�resultr�rrrr��s
z&Branch._do_revision_id_to_dotted_revnocCshdtjvrtdd�|���8|jdur0|j}n|��}|�|�|Wd�S1sZ0YdS)z�Return the revision_id => dotted revno map.

        This will be regenerated on demand, but will be cached.

        :return: A dictionary mapping revision_id => dotted revno.
            This dictionary should not be modified by the caller.
        rj�z2get_revision_id_to_revno_map scales with ancestry.N)rlrmrr}r'�_gen_revno_map�_cache_revision_id_to_revno)r�mappingrrrr��s
�


z#Branch.get_revision_id_to_revno_mapcCsdd�|��D�}|S)aVCreate a new mapping from revision ids to dotted revnos.

        Dotted revnos are generated based on the current tip in the revision
        history.
        This is the worker function for get_revision_id_to_revno_map, which
        just caches the return value.

        :return: A dictionary mapping revision_id => dotted revno.
        cSsi|]\}}}}||�qSrr)r�r�Zdepthr��end_of_mergerrr�
<dictcomp>�sz)Branch._gen_revno_map.<locals>.<dictcomp>)�iter_merge_sorted_revisions�rr�rrrr��s
�zBranch._gen_revno_map�excluderucCs�|����|jdur6|��}|j�|g�}|�|�|_|�|j|||�}|�|�}|dkrl|Wd�S|dkr�tt	|��Wd�St
d|��Wd�n1s�0YdS)a�Walk the revisions for a branch in merge sorted order.

        Merge sorted order is the output from a merge-aware,
        topological sort, i.e. all parents come before their
        children going forward; the opposite for reverse.

        :param start_revision_id: the revision_id to begin walking from.
            If None, the branch tip is used.
        :param stop_revision_id: the revision_id to terminate the walk
            after. If None, the rest of history is included.
        :param stop_rule: if stop_revision_id is not None, the precise rule
            to use for termination:

            * 'exclude' - leave the stop revision out of the result (default)
            * 'include' - the stop revision is the last item in the result
            * 'with-merges' - include the stop revision and all of its
              merged revisions in the result
            * 'with-merges-without-common-ancestry' - filter out revisions
              that are in both ancestries
        :param direction: either 'reverse' or 'forward':

            * reverse means return the start_revision_id first, i.e.
              start at the most recent revision and go backwards in history
            * forward returns tuples in the opposite order to reverse.
              Note in particular that forward does *not* do any intelligent
              ordering w.r.t. depth as some clients of this API may like.
              (If required, that ought to be done at higher layers.)

        :return: an iterator over (revision_id, depth, revno, end_of_merge)
            tuples where:

            * revision_id: the unique id of the revision
            * depth: How many levels of merging deep this node has been
              found.
            * revno_sequence: This field provides a sequence of
              revision numbers for all revisions. The format is:
              (REVNO, BRANCHNUM, BRANCHREVNO). BRANCHNUM is the number of the
              branch that the revno is on. From left to right the REVNO numbers
              are the sequence numbers within that branch of the revision.
            * end_of_merge: When True the next node (earlier in history) is
              part of a different merge.
        NruZforwardzinvalid direction %r)r}r,rCr2Zget_known_graph_ancestryZ
merge_sort�_filter_merge_sorted_revisions�_filter_start_non_ancestors�reversed�list�
ValueError)r�start_revision_id�stop_revision_id�	stop_rule�	directionrCZknown_graphZfilteredrrrr��s&-

���
z"Branch.iter_merge_sorted_revisionsccs
t|�}|durB|D],}|j}||kr*qqt�t|g�|�}qBq|durr|D]}|j}||j|j|jfVqN�n�|dkr�|D],}|j}||kr�dS||j|j|jfVq~�nV|dkr�|D],}|j}||j|j|jfV||kr�dSq��n|dk�rF|j��}|�	||g�}	|D].}|j}||	v�r,�q||j|j|jfV�qn�|dk�r�|j�
|�}
|
j�rp|
jd}ntj
}d}g}
|D]t}|j}||k�r�dS|�r�||
v�r�||j|j|jfV|�s�||k�r�|j�
|�}|j�r�d}|
�|j��q�ntd	|��dS)
z4Iterate over an inclusive range of sorted revisions.Nr�Zincludez#with-merges-without-common-ancestryzwith-mergesrFTzinvalid stop_rule %r)�iter�key�	itertools�chain�merge_depthr�r�r2rnZfind_unique_ancestorsZget_revisionZ
parent_idsrDrE�extendr�)rZmerge_sorted_revisionsr�r�r��rev_iter�noder�ryZ	ancestorsZstop_revZleft_parentZreached_stop_revision_idZrevision_id_whitelistZrevrrrr�s�
�
�
�

�

�

�
�z%Branch._filter_merge_sorted_revisionsccs�zt|�}Wnty YdS0|\}}}}|V|sH|D]
}|Vq<d}t�}	|j�|g�}
|
�|g�}|r||	�|�ndS|D]d\}}}}|s�||	vr�|j�|g�}
|
�|g�}|	�|�|	�|�|dkr�d}nq�||||fVq�dS)NFrT)�next�
StopIteration�setr2rqr��update�remove)rr��firstr�r�r�r�r�ZcleanZ	whitelistZpmap�parentsrrrr�Qs6

z"Branch._filter_start_non_ancestorscCs|j��dS)z�Tell this branch object not to release the physical lock when this
        object is unlocked.

        If lock_write doesn't return a token, then this method is not
        supported.
        N)r8Zleave_in_placerrrr�leave_lock_in_place�szBranch.leave_lock_in_placecCs|j��dS)z�Tell this branch object to release the physical lock when this
        object is unlocked, even if it didn't originally acquire it.

        If lock_write doesn't return a token, then this method is not
        supported.
        N)r8Zdont_leave_in_placerrrr�dont_leave_lock_in_place�szBranch.dont_leave_lock_in_placecCst�|j��dS)zyBind the local branch the other branch.

        :param other: The branch to bind to
        :type other: Branch
        N�r�UpgradeRequiredr4�r�otherrrr�bind�szBranch.bindcCs|j��sdS|���d�S)zHWhether it is only possible to append revisions to the history.
        F�append_revisions_only)r#�"supports_set_append_revisions_onlyr[r�rrrr�get_append_revisions_only�s
z Branch.get_append_revisions_onlycCs*|j��st�|j��|���d|�dS)Nr�)r#r�rr�r4r[r�)rZenabledrrr�set_append_revisions_only�s
z Branch.set_append_revisions_onlycCsD|���(t�||�j|||d�Wd�S1s60YdS)a;Copy revisions from from_branch into this branch.

        :param from_branch: Where to copy from.
        :param stop_revision: What revision to stop at (None for at the end
                              of the branch.
        :param limit: Optional rough limit of revisions to fetch
        :return: None
        )�limit�lossyN)r{�InterBranchr��fetch)r�from_branchr@r�r�rrrr��s	
�zBranch.fetchcCsdS)z�Return the URL of the branch we are bound to.

        Older format branches cannot bind, please be sure to use a metadir
        branch.
        Nrrrrr�get_bound_location�szBranch.get_bound_locationcCst�|j��dS)z<Return the URL of the branch we used to be bound to
        Nr�rrrr�get_old_bound_location�szBranch.get_old_bound_locationc		Cs,|dur|��}|j�|||||||||�	S)aaObtain a CommitBuilder for this branch.

        :param parents: Revision ids of the parents of the new revision.
        :param config: Optional configuration to use.
        :param timestamp: Optional timestamp recorded for commit.
        :param timezone: Optional timezone for timestamp.
        :param committer: Optional committer to set for commit.
        :param revprops: Optional dictionary of revision properties.
        :param revision_id: Optional revision id.
        :param lossy: Whether to discard data that can not be natively
            represented, when pushing to a foreign VCS
        N)r[r2�get_commit_builder)	rr�Zconfig_stackZ	timestamp�timezoneZ	committerZrevpropsrvr�rrrr��s�zBranch.get_commit_buildercCsdS)zVReturn the branch we are bound to.

        :return: Either a Branch, or None
        Nrr1rrrr:�szBranch.get_master_branchcCst|j��dS)z�Get the URL this branch is stacked against.

        :raises NotStacked: If the branch is not stacked.
        :raises UnstackableBranchFormat: If the branch does not support
            stacking.
        N)r\�get_stacked_on_urlrrrrr��szBranch.get_stacked_on_urlcCst|j��dS)a�Set the last revision of this branch.

        The caller is responsible for checking that the revno is correct
        for this revision id.

        It may be possible to set the branch last revision to an id not
        present in the repository.  However, branches can also be
        configured to check constraints on history, in which case this may not
        be permitted.
        N)r\�set_last_revision_info)rr�rvrrrr��szBranch.set_last_revision_infoc	Cs�|���p|j��}|��\}}||ftjdfg}|durR|�||�sRt�||��|�	||�}|�
||�Wd�n1s~0YdS)z$See Branch.generate_revision_historyrN)r{r2rn�last_revision_inforDrErorrp�find_distance_to_nullr�)	rrvrwrxry�
last_revno�
last_revidZknown_revision_idsr�rrr�generate_revision_history�s

��z Branch.generate_revision_historycCs�|durNt|t�r@z|�d�Wnty>t�|d��Yn0t�|j|�}|���|�	|�Wd�n1sv0YdS)zSee Branch.set_parent.N�asciiz4Urls must be 7-bit ascii, use breezy.urlutils.escape)
�
isinstancer�encode�UnicodeEncodeErrorr`�
InvalidURL�relative_urlr=r{Z_set_parent_location�rrrrr�
set_parents
�

zBranch.set_parentcCs�|j��st|j|j��|���~|��|spz|��Wn*tjttj	fydYWd�dS0|�
�n|j||jj
gd�|�d|�Wd�n1s�0YdS)z�Set the URL this branch is stacked against.

        :raises UnstackableBranchFormat: If the branch does not support
            stacking.
        :raises UnstackableRepositoryFormat: If the repository does not support
            stacking.
        NrSZstacked_on_location)r#�supports_stackingrr4r{r>r�rZ
NotStackedr<�_unstackr7r�root_transport�_set_config_locationr�rrr�set_stacked_on_urls 

�


�zBranch.set_stacked_on_urlc

Cs�tj�����}|�td��|j}t|j�dkrBtd||jf��t	j
�|j	jj
�}|��}|jrrtd|jf��|��j}||_t|tj�r�|jdur�||j_|jj|d�|dur�|��|��|dur�|j��d}z|��Wntj�yY�qYn0|d7}q�|dk�r"td��t|d�D]}|j���q.|���pzt|j���}Wntj�yxt�}Yn0t j!|j||�"�g|d	d
��#�}	|jj$||	d�Wd�n1�s�0YWd�n1�s�0YdS)z�Change a branch to be unstacked, copying data as needed.

        Don't call this directly, use set_stacked_on_url(None).
        Z
Unstackingrz;can't cope with fallback repositories of %r (fallbacks: %r)z.didn't expect %r to have fallback_repositoriesN)r|rz5old_repository should have been locked at least once.T)Zrequired_idsZif_present_idsZfind_ghosts)�
fetch_spec)%ZuiZ
ui_factoryZnested_progress_barr��gettextr2rBr3�AssertionErrorrrMr"r�r=Zfind_repositoryr{Zrepository_tokenr��remoteZRemoteBranchZ_real_branchr�r~r�rZLockNotHeld�ranger}r�r%�get_reverse_tag_dict�TagsNotSupportedZ	vf_searchZNotInOtherForRevsrCZexecuter�)
rZpbZold_repositoryZ
new_bzrdirZnew_repositoryZ
lock_tokenZold_lock_count�iZ
tags_to_fetchr�rrrr�6sl������




�
�
zBranch._unstackcCs
||_dS)aSet the cached revision history to rev_history.

        The revision_history method will use this cache to avoid regenerating
        the revision history.

        This API is semi-public; it only for use by subclasses, all other code
        should consider it to be private.
        N)r&)rZrev_historyrrr�_cache_revision_history�s	zBranch._cache_revision_historycCs
||_dS)z�Set the cached revision_id => revno map to revision_id_to_revno.

        This API is semi-public; it only for use by subclasses, all other code
        should consider it to be private.
        N)r'r�rrrr��sz"Branch._cache_revision_id_to_revnocCs.d|_d|_d|_d|_d|_g|_i|_dS)a0Clear any cached data on this branch, e.g. cached revision history.

        This means the next call to revision_history will need to call
        _gen_revision_history.

        This API is semi-public; it is only for use by subclasses, all other
        code should consider it to be private.
        N)r&r'r*r+r,r)r(rrrr�_clear_cached_state�s	zBranch._clear_cached_statecCst|j��dS)aReturn sequence of revision hashes on to this branch.

        Unlike revision_history, this method always regenerates or rereads the
        revision history, i.e. it does not cache the result, so repeated calls
        may be expensive.

        Concrete subclasses should override this instead of revision_history so
        that subclasses do not need to deal with caching logic.

        This API is semi-public; it only for use by subclasses, all other code
        should consider it to be private.
        N)r\�_gen_revision_historyrrrrr��s
zBranch._gen_revision_historycCs@dtjvrtdd�|jdur&|j}n|��}|�|�t|�S)Nrjr�z%revision_history scales with history.)rlrmrr&r�r�r�)r�historyrrr�_revision_history�s



zBranch._revision_historycCs|��dS)z�Return current revision number for this branch.

        That is equivalent to the number of revisions committed to
        this branch.
        r�r�rrrrr��szBranch.revnocCst�|j��dS)z,Older format branches cannot bind or unbind.Nr�rrrr�unbind�sz
Branch.unbindcCs|��dS)z*Return last revision id, or NULL_REVISION.rr�rrrrrC�szBranch.last_revisioncCsF|���*|jdur|��|_|jWd�S1s80YdS)zdReturn information about the last revision.

        :return: A tuple (revno, revision_id).
        N)r}r*�_read_last_revision_inforrrrr��s


�zBranch.last_revision_infocCst|j��dSr)r\r�rrrrr��szBranch._read_last_revision_infocCs.|j�|j�s|�||�|�||�||fS)a�Set the last revision info, importing from another repo if necessary.

        This is used by the bound branch code to upload a revision to
        the master branch first before updating the tip of the local branch.
        Revisions referenced by source's tags are also transferred.

        :param source: Source branch to optionally fetch from
        :param revno: Revision number of the new tip
        :param revid: Revision id of the new tip
        :param lossy: Whether to discard metadata that can not be
            natively represented
        :return: Tuple with the new revision number and revision id
            (should only be different from the arguments when lossy=True)
        )r2r6r�r�)r�sourcer�rIr�rrr�"import_last_revision_info_and_tags�sz)Branch.import_last_revision_info_and_tagscCsJt�|�rdS|��}z|�|�dWStyDt�||��Yn0dS)z%Given a revision id, return its revnorrN)rD�is_nullr��indexr�rrr)rrvr�rrrr��s
zBranch.revision_id_to_revnocCs�|����|dkr&tjWd�S|��\}}||krL|Wd�S|dks\||krht�||��||}t|j�|kr�|�|�|j|Wd�S1s�0YdS)z,Find the revision id of the specified revno.rN)	r}rDrEr�rrrrBr)rG)rr�r�r�r�Zdistance_from_lastrrrr�s

zBranch.get_rev_idcOs t�||�j||||d�|��S)z�Mirror source into this branch.

        This branch is considered to be 'local', having low latency.

        :returns: PullResult instance
        )�	overwriter@r/)r�r��pull)rr�r�r@r/�args�kwargsrrrr�s���zBranch.pullcOs$t�||�j|||g|�Ri|��S)znMirror this branch into target.

        This branch is considered to be 'local', having low latency.
        )r�r��push)r�targetr�r@r�r�r�rrrr�s���zBranch.pushcCs|j�|���S)z'Return `Tree` object for last revision.)r2Z
revision_treerCrrrr�
basis_tree&szBranch.basis_treecCsh|��}|dur|S|�d�r(t�|�}zt�|jdd�|�WStjybt�||j	��Yn0dS)z�Return the parent location of the branch.

        This is the default location for pull/missing.  The usual
        pattern is that the user can override it by specifying a
        location.
        N�/rA)
�_get_parent_location�
startswithr`Zlocal_path_to_urlrar=ZInvalidURLJoinr�InaccessibleParentr4)r�parentrrr�
get_parent*s

zBranch.get_parentcCst|j��dSr)r\r�rrrrr�=szBranch._get_parent_locationcCs@|dur|��}|durd}n|r0t�|j|�}|�||�dS�N�)r[r`r�r=r�)rrPrreZ
make_relativerrrr�@szBranch._set_config_locationcCs*|dur|��}|�|�}|dkr&d}|Sr��r[r�)rrPre�locationrrr�_get_config_locationJs
zBranch._get_config_locationcCs|���d�S)z:Return the preferred format of submissions to this branch.Zchild_submit_formatr�rrrr�get_child_submit_formatRszBranch.get_child_submit_formatcCs|���d�S)��Return the submit location of the branch.

        This is the default location for bundle.  The usual
        pattern is that the user can override it by specifying a
        location.
        �
submit_branchr�rrrr�get_submit_branchVszBranch.get_submit_branchcCs|���d|�dS)rrN)r[r��rrrrr�set_submit_branch_szBranch.set_submit_branchcCs
|�d�S)z]Return the public location of the branch.

        This is used by merge directives.
        �
public_branch)rrrrr�get_public_branchhszBranch.get_public_branchcCs|�d|�dS)rrN)r�rrrr�set_public_branchoszBranch.set_public_branchcCs|���d�S)z3Return None or the location to push this branch to.Z
push_locationr�rrrr�get_push_locationxszBranch.get_push_locationcCst|j��dS)z(Set a new push location for this branch.N)r\�set_push_locationrrrrr|szBranch.set_push_locationcCsDtjd}|sdS|��\}}t|||||�}|D]}||�q2dS)z%Run the post_change_branch_tip hooks.�post_change_branch_tipN�rr.r��ChangeBranchTipParams)r�	old_revno�	old_revidr.�	new_revno�	new_revid�paramsr0rrr�!_run_post_change_branch_tip_hooks�s

�z(Branch._run_post_change_branch_tip_hookscCsDtjd}|sdS|��\}}t|||||�}|D]}||�q2dS)z$Run the pre_change_branch_tip hooks.�pre_change_branch_tipNr)rrrr.rrrr0rrr� _run_pre_change_branch_tip_hooks�s

�z'Branch._run_pre_change_branch_tip_hookscCsdS)z�Synchronise this branch with the master branch if any.

        :return: None or the last_revision pivoted out during the update.
        Nrrrrrr��sz
Branch.updatecCs|dkr|�|�dS)zy        Check whether a revno corresponds to any revision.
        Zero (the NULL revision) is considered valid.
        rN)�check_real_revno�rr�rrr�check_revno�szBranch.check_revnocCs"|dks||��krt�|��dS)z}        Check whether a revno corresponds to a real revision.
        Zero (the NULL revision) is considered invalid
        rN)r�rZInvalidRevisionNumberrrrrr�szBranch.check_real_revnoc	Cs�|j|d�}|���Z|���2|dur2|�|�|j|||d�Wd�n1sV0YWd�n1st0Y|S)aPClone this branch into to_controldir preserving all semantic values.

        Most API users will want 'create_clone_on_transport', which creates a
        new bzrdir and branch on the fly.

        revision_id: if not None, the revision history in the new branch will
                     be truncated to end with revision_id.
        )rPN�rv�tag_selector)�
create_branchr}r{�configure_branch�copy_content_into)r�
to_controldirrvrP�repository_policyrr�rrr�clone�s

�BzBranch.clonec		Cs�|dur|��r|jjdd�|j|d�}|r:t�||��|����|���Z|dur`|�|�|j	|||d�|�
�}|dur�|�|j�n
|�|�Wd�n1s�0YWd�n1s�0Y|S)aCreate a new line of development from the branch, into to_controldir.

        to_controldir controls the branch format.

        revision_id: if not None, the revision history in the new branch will
                     be truncated to end with revision_id.
        NT)Z
_skip_repo)r2r)
Zrequires_stackingr#Zrequire_stackingrr�LossyPushToSameVCSr}r{rrr�r�r4)	rr rvr!r2r�rr�Z
master_urlrrr�sprout�s$	�
�Fz
Branch.sproutcCsj|��\}}|dur ||}}n:|j��}z|�|||fg�}WntjyXd}Yn0|�||�dS)aSynchronize last revision and revision history between branches.

        This version is most efficient when the destination is also a
        BzrBranch6, but works for BzrBranch5, as long as the destination's
        repository contains all the lefthand ancestors of the intended
        last_revision.  If not, set_last_revision_info will fail.

        :param destination: The branch to copy the history into
        :param revision_id: The revision-id to truncate history at.  May
          be None to copy complete history.
        Nr)r�r2rnr�rr�r�)r�destinationrvZsource_revnoZsource_revision_idr�ryrrr�_synchronize_history�s

�
zBranch._synchronize_historycCst�||�j||d�S)aQCopy the content of self into destination.

        revision_id: if not None, the revision history in the new branch will
                     be truncated to end with revision_id.
        tag_selector: Optional callback that receives a tag name
            and should return a boolean to indicate whether a tag should be copied
        r)r�r�r)rr%rvrrrrr�s�zBranch.copy_content_intocCs|jjsdSt�||���Sr)r#�supports_reference_locationsr�r��update_references)rr�rrrr(�szBranch.update_referencescCsr|���Vt|�}|��\}}|d|f}||krL|j�t�d||f��|Wd�S1sd0YdS)a�Check consistency of the branch.

        In particular this checks that revisions given in the revision-history
        do actually match up in the revision graph, and that they're all
        present in the repository.

        Callers will typically also want to check the repository.

        :param refs: Calculated refs for this branch as specified by
            branch._get_check_refs()
        :return: A BranchCheckResult.
        rHz+revno does not match len(mainline) %s != %sN)r}�BranchCheckResultr�rrtZ
BzrCheckError)rZrefsr�r�Zlast_revision_idZactual_revnorrr�checks

��zBranch.checkcCs|jj��}|�|j�|S)z�Return the most suitable metadir for a checkout of this branch.
        Weaves are used if this branch's repository uses weaves.
        )r2rZcheckout_metadirZset_branch_formatr#)r�lightweightrrrr�_get_checkout_formatszBranch._get_checkout_formatc		Cs2|dur|��}|jj|||||||d�}|��S)a�Create a clone of this branch and its bzrdir.

        :param to_transport: The transport to clone onto.
        :param revision_id: The revision id to use as tip in the new branch.
            If None the tip is obtained from this branch.
        :param stacked_on: An optional URL to stack the clone on.
        :param create_prefix: Create any missing directories leading up to
            to_transport.
        :param use_existing_dir: Use an existing directory if one exists.
        N)rv�
stacked_on�
create_prefix�use_existing_dir�no_treer)rCrZclone_on_transportrN)	rZto_transportrvr-r.r/r0rZdir_torrr�create_clone_on_transport's�z Branch.create_clone_on_transportTcCslt�|�}|��|j|d�}z|�|�}	Wndtjy�tj�	|�}	z|	�
�WntjyhYn0t�|j��|	j
j|jj
jkr�d}Yn0|r�|	j|d�}
n4|	��}|��|	��}|�|�|j||d�d}
|	j||
||d�}
|
��}|���\|��D]B}|
�|�}|du�r*td|��q|�|
�|�|�|�|��qWd�n1�s^0Y|
S)aCreate a checkout of a branch.

        :param to_location: The url to produce the checkout at
        :param revision_id: The revision to check out
        :param lightweight: If True, produce a lightweight checkout, otherwise,
            produce a bound branch (heavyweight checkout)
        :param accelerator_tree: A tree which can be used for retrieving file
            contents more quickly than the revision tree, i.e. a workingtree.
            The revision tree will be used for cases where accelerator_tree's
            content is different.
        :param hardlink: If true, hard-link files from accelerator_tree,
            where possible.
        :param recurse_nested: Whether to recurse into nested trees
        :return: The tree of the created checkout
        )r+T)�
target_branch�r@N)r��accelerator_tree�hardlinkzBranch location for %s unknown.)rRZ
get_transportZensure_baser,Zinitialize_on_transportrZAlreadyControlDirErrorrrMrQrNZNotBranchErrorr=r Zset_branch_referenceZdetermine_repository_policyZacquire_repositoryrr�r�Zcreate_workingtreer�r}Ziter_references�reference_parentr�create_checkout�abspathZget_reference_revision)rZto_locationrvr+r4r5Zrecurse_nested�trZcheckoutr�ZpolicyZcheckout_branchr_r��pathr6rrrr7AsR
�

�




�(zBranch.create_checkoutcCst|j��dS)znMake sure the data stored in this branch is consistent.

        :return: A `ReconcileResult` object.
        N)r\�	reconcile)rZthoroughrrrr;�szBranch.reconcilecCs
|j��Sr)r#rWrrrrrW�szBranch.supports_tagscCs.tjdD]}|||�}|dur
|Sq
dS)z�Try to automatically find the tag name for a revision.

        :param revision_id: Revision id of the revision.
        :return: A tag name or None if no tag name could be determined.
        �automatic_tag_nameN)rr.)rrvr0Zretrrrr<�s


zBranch.automatic_tag_namecCsN|�|||�}|dkrdS|dkr0t�||��n|dkr<dStd|f��dS)a
Ensure that revision_b is a descendant of revision_a.

        This is a helper function for update_revisions.

        :raises: DivergedBranches if revision_b has diverged from revision_a.
        :returns: True if revision_b is a descendant of revision_a.
        �b_descends_from_aT�diverged�a_descends_from_bFzinvalid relation: %rN)�_revision_relationsrrpr�)r�
revision_a�
revision_bryrxZrelationrrr� _check_if_descendant_or_diverged�s	z'Branch._check_if_descendant_or_divergedcCsL|�||g�}||hkrdS|||hkr,dS||hkr:dStd|f��dS)z�Determine the relationship between two revisions.

        :returns: One of: 'a_descends_from_b', 'b_descends_from_a', 'diverged'
        r=r>r?zinvalid heads: %rN)�headsr�)rrArBryrDrrrr@�s

zBranch._revision_relationscCsf|��h}t�}|���d�rFzt|j���}WntjyDYn0|�t	j
�|�t	j
�||fS)a}Return the heads that must and that should be fetched to copy this
        branch into another repo.

        :returns: a 2-tuple of (must_fetch, if_present_fetch).  must_fetch is a
            set of heads that must be fetched.  if_present_fetch is a set of
            heads that must be fetched if present, but no error is necessary if
            they are not present.
        zbranch.fetch_tags)rCr�r[r�r%r�rr��discardrDrE)rZ
must_fetchZif_present_fetchrrr�heads_to_fetch�s
zBranch.heads_to_fetchcCstj�|�S)zbCreate a memory tree for this branch.

        :return: An in-memory MutableTree instance
        )Z
memorytreeZ
MemoryTreeZcreate_on_branchrrrr�create_memorytree�szBranch.create_memorytree)N)NN)FN)NFN)N)FN)NN)N)F)NNr�ru)NNF)NNNNNNF)N)NN)F)N)FNN)FNF)NF)N)NNNN)NNNFN)NN)F)NNFFNN)NFNFT)T)lrrr�__doc__r=�propertyr r!rr-r7r9r>rGrJ�staticmethodr"rQrTrXrZr[r]r^r5rgrhrbrirzr{r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r:r�r�r�r�r�r�r�r�r�r�r�r�r�rCr�r�r�r�r�r�r�r�r�r�r�rrrrr	r
rrrrr�rrr"r$r&rr(r*r,r1r7r;rWr<rCr@rFrGrrrrrDs




�	

	

�

	
�
DL0		

�

	
�
R
�


�

	�


			�
�


�
�
B
rc@s�eZdZdZdd�Zdd�Zd,dd�Zed	d
��Zdd�Z	d
d�Z
d-dd�Zdd�Zdd�Z
dd�Zd.dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZdS)/�BranchFormata�An encapsulation of the initialization and open routines for a format.

    Formats provide three things:
     * An initialization routine,
     * a format description
     * an open routine.

    Formats are placed in an dict by their format string for reference
    during branch opening. It's not required that these be instances, they
    can be classes themselves with class methods - it simply depends on
    whether state is needed for a given format or not.

    Once a format is deprecated, just deprecate the initialize and open
    methods on the format class. Do not deprecate the object, as the
    object will be created every time regardless.
    cCs|j|juSr��	__class__r�rrr�__eq__�szBranchFormat.__eq__cCs
||kSrrr�rrr�__ne__�szBranchFormat.__ne__NcCsdS)a�Get the target reference of the branch in controldir.

        format probing must have been completed before calling
        this method - it is assumed that the format of the branch
        in controldir is correct.

        :param controldir: The controldir to get the branch data from.
        :param name: Name of the colocated branch to fetch
        :return: None if the branch is not a reference branch.
        Nr)rrrPrrr�
get_reference�szBranchFormat.get_referencecCst|j��dS)a�Set the target reference of the branch in controldir.

        format probing must have been completed before calling
        this method - it is assumed that the format of the branch
        in controldir is correct.

        :param controldir: The controldir to set the branch reference for.
        :param name: Name of colocated branch to set, None for default
        :param to_branch: branch that the checkout is to reference
        N)r\�
set_reference)rrrP�	to_branchrrrrQ�szBranchFormat.set_referencecCst|j��dS)z4Return the short format description for this format.N)r\�get_format_descriptionrrrrrS
sz#BranchFormat.get_format_descriptioncCs6tjd}|sdSt||||�}|D]}||�q$dS)N�post_branch_init)rr.�BranchInitHookParams)rrrPrVr.rr0rrr�_run_post_branch_init_hookss
z(BranchFormat._run_post_branch_init_hookscCst|j��dS)ztCreate a branch of this format in controldir.

        :param name: Name of the colocated branch to create.
        N)r\�
initialize)rrrPr2r�rrrrWszBranchFormat.initializecCsdS)z�Is this format supported?

        Supported formats can be initialized and opened.
        Unsupported formats may not support initialization or committing or
        some other features depending on the reason for not being supported.
        Trrrrr�is_supported!szBranchFormat.is_supportedcCs
t�|�S)a�Create a tags object for branch.

        This method is on BranchFormat, because BranchFormats are reflected
        over the wire via network_name(), whereas full Branch instances require
        multiple VFS method calls to operate at all.

        The default implementation returns a disabled-tags instance.

        Note that it is normal for branch to be a RemoteBranch when using tags
        on a RemoteBranch.
        )Z_mod_tagZDisabledTags�rrVrrrr$*szBranchFormat.make_tagscCst|j��dS)aPA simple byte string uniquely identifying this format for RPC calls.

        MetaDir branch formats use their disk format string to identify the
        repository over the wire. All in one formats such as bzr < 0.8, and
        foreign formats like svn/git and hg should use some marker which is
        unique and immutable.
        N)r\�network_namerrrrrZ8szBranchFormat.network_nameFcCst|j��dS)a�Return the branch object for controldir.

        :param controldir: A ControlDir that contains a branch.
        :param name: Name of colocated branch to open
        :param _found: a private parameter, do not use it. It is used to
            indicate if format probing has already be done.
        :param ignore_fallbacks: when set, no fallback branches will be opened
            (if there are any).  Default is to open fallbacks.
        N)r\r")rrrPZ_foundZignore_fallbacksZfound_repositoryr/rrrr"BszBranchFormat.opencCsdS)z7True if this format supports set_append_revisions_only.Frrrrrr�Osz/BranchFormat.supports_set_append_revisions_onlycCsdS)z0True if this format records a stacked-on branch.Frrrrrr�SszBranchFormat.supports_stackingcCsdS)z4True if this format supports leaving locks in place.Frrrrr�supports_leaving_lockWsz"BranchFormat.supports_leaving_lockcCs|����Sr)rS�rstriprrrr�__str__[szBranchFormat.__str__cCsdS)z6True if this format supports tags stored in the branchFrrrrrrW^szBranchFormat.supports_tagscCsdS)z8Whether the tag container for this branch versions tags.Frrrrr�tags_are_versionedbszBranchFormat.tags_are_versionedcCsdS)z+True if tags can reference ghost revisions.Trrrrr� supports_tags_referencing_ghostsfsz-BranchFormat.supports_tags_referencing_ghostscCsdS)z9True if uncommitted changes can be stored in this branch.Trrrrr�supports_store_uncommittedjsz'BranchFormat.supports_store_uncommittedcCsdS)z2True if this branch format store revision numbers.Trrrrr�stores_revnonszBranchFormat.stores_revno)N)NNN)NFFNN)rrrrHrNrOrP�classmethodrQrSrVrWrXr$rZr"r�r�r[r]rWr^r_r`rarrrrrK�s4



�
	
�

rKc@seZdZdZdd�ZdS)�BranchHooksz�A dictionary mapping hook name to a list of callables for branch hooks.

    e.g. ['post_push'] Is the list of items to be called when the
    push function is invoked.
    cCs�t�|dd�|�ddd�|�ddd�|�d	d
d�|�ddd
�|�ddd�|�ddd�|�ddd�|�ddd�|�ddd�|�ddd�|�ddd�|�d d!d�d"S)#z�Create the default hooks.

        These are all empty initially, because by default nothing should get
        notified.
        z
breezy.branchzBranch.hooksr"zLCalled with the Branch object that has been opened after a branch is opened.)r��	post_pushz�Called after a push operation completes. post_push is called with a breezy.branch.BranchPushResult object and only runs in the bzr client.)r��	post_pullz�Called after a pull operation completes. post_pull is called with a breezy.branch.PullResult object and only runs in the bzr client.Z
pre_commita�Called after a commit is calculated but before it is completed. pre_commit is called with (local, master, old_revno, old_revid, future_revno, future_revid, tree_delta, future_tree). old_revid is NULL_REVISION for the first commit to a branch, tree_delta is a TreeDelta object describing changes from the basis revision. hooks MUST NOT modify this delta.  future_tree is an in-memory tree obtained from CommitBuilder.revision_tree() and hooks MUST NOT modify this tree.)r�[Zpost_commitz�Called in the bzr client after a commit has completed. post_commit is called with (local, master, old_revno, old_revid, new_revno, new_revid). old_revid is NULL_REVISION for the first commit to a branch.Z
post_uncommitaCalled in the bzr client after an uncommit completes. post_uncommit is called with (local, master, old_revno, old_revid, new_revno, new_revid) where local is the local branch or None, master is the target branch, and an empty branch receives new_revno of 0, new_revid of None.rz�Called in bzr client and server before a change to the tip of a branch is made. pre_change_branch_tip is called with a breezy.branch.ChangeBranchTipParams. Note that push, pull, commit, uncommit will all trigger this hook.)r�r
z�Called in bzr client and server after a change to the tip of a branch is made. post_change_branch_tip is called with a breezy.branch.ChangeBranchTipParams. Note that push, pull, commit, uncommit will all trigger this hook.)rrkZtransform_fallback_locationaqCalled when a stacked branch is activating its fallback locations. transform_fallback_location is called with (branch, url), and should return a new url. Returning the same url allows it to be used as-is, returning a different one can be used to cause the branch to stack on a closer copy of that fallback_location. Note that the branch cannot have history accessing methods called on it during this hook because the fallback locations have not been activated. When there are multiple hooks installed for transform_fallback_location, all are called with the url returned from the previous hook.The order is however undefined.)r�	r<z�Called to determine an automatic tag name for a revision. automatic_tag_name is called with (branch, revision_id) and should return a tag name or None if no tag name could be determined. The first non-None tag name returned will be used.)�rkrTz�Called after new branch initialization completes. post_branch_init is called with a breezy.branch.BranchInitHookParams. Note that init, branch and checkout (both heavyweight and lightweight) will all trigger this hook.Zpost_switchzeCalled after a checkout switches branch. post_switch is called with a breezy.branch.SwitchHookParams.N)rrZadd_hookrrrrrzsz��������
�
���zBranchHooks.__init__N)rrrrHrrrrrrcssrcc@s(eZdZdZdd�Zdd�Zdd�ZdS)	ra�Object holding parameters passed to `*_change_branch_tip` hooks.

    There are 5 fields that hooks may wish to access:

    :ivar branch: the branch being changed
    :ivar old_revno: revision number before the change
    :ivar new_revno: revision number after the change
    :ivar old_revid: revision id before the change
    :ivar new_revid: revision id after the change

    The revid fields are strings. The revno fields are integers.
    cCs"||_||_||_||_||_dS)aZCreate a group of ChangeBranchTip parameters.

        :param branch: The branch being changed.
        :param old_revno: Revision number before the change.
        :param new_revno: Revision number after the change.
        :param old_revid: Tip revision id before the change.
        :param new_revid: Tip revision id after the change.
        N)rVrrrr)rrVrrrrrrrr�s
	zChangeBranchTipParams.__init__cCs|j|jkSr��__dict__r�rrrrN�szChangeBranchTipParams.__eq__cCs"d|jj|j|j|j|j|jfS)Nz$<%s of %s from (%s, %s) to (%s, %s)>)rMrrVrrrrrrrr�__repr__�s
�zChangeBranchTipParams.__repr__N�rrrrHrrNrnrrrrr�s
rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	rUaObject holding parameters passed to `*_branch_init` hooks.

    There are 4 fields that hooks may wish to access:

    :ivar format: the branch format
    :ivar bzrdir: the ControlDir where the branch will be/has been initialized
    :ivar name: name of colocated branch, if any (or None)
    :ivar branch: the branch created

    Note that for lightweight checkouts, the bzrdir and format fields refer to
    the checkout, hence they are different from the corresponding fields in
    branch, which refer to the original branch.
    cCs||_||_||_||_dS)aCreate a group of BranchInitHook parameters.

        :param format: the branch format
        :param controldir: the ControlDir where the branch will be/has been
            initialized
        :param name: name of colocated branch, if any (or None)
        :param branch: the branch created

        Note that for lightweight checkouts, the bzrdir and format fields refer
        to the checkout, hence they are different from the corresponding fields
        in branch, which refer to the original branch.
        N)rrrPrV)rrrrPrVrrrrs
zBranchInitHookParams.__init__cCs|j|jkSrrlr�rrrrN szBranchInitHookParams.__eq__cCsd|jj|jfS)Nz
<%s of %s>)rMrrVrrrrrn#szBranchInitHookParams.__repr__NrorrrrrU�srUc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SwitchHookParamsalObject holding parameters passed to `*_switch` hooks.

    There are 4 fields that hooks may wish to access:

    :ivar control_dir: ControlDir of the checkout to change
    :ivar to_branch: branch that the checkout is to reference
    :ivar force: skip the check for local commits in a heavy checkout
    :ivar revision_id: revision ID to switch to (or None)
    cCs||_||_||_||_dS)a@Create a group of SwitchHook parameters.

        :param control_dir: ControlDir of the checkout to change
        :param to_branch: branch that the checkout is to reference
        :param force: skip the check for local commits in a heavy checkout
        :param revision_id: revision ID to switch to (or None)
        N)�control_dirrR�forcerv)rrqrRrrrvrrrr2szSwitchHookParams.__init__cCs|j|jkSrrlr�rrrrN?szSwitchHookParams.__eq__cCsd|jj|j|j|jfS)Nz<%s for %s to (%s, %s)>)rMrrqrRrvrrrrrnBs�zSwitchHookParams.__repr__Nrorrrrrp's

rpcs:eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Z�ZS)�BranchFormatRegistryzBranch format registry.Ncs tt|��|�d|_d|_dSr)�superrsr�_default_format�_default_format_key)rZother_registryrLrrrKszBranchFormatRegistry.__init__cCs(|jdur"|jdur"|�|j�|_|jS)z"Return the current default format.N)rvrur�rrrr�get_defaultPs

�z BranchFormatRegistry.get_defaultcCs||_d|_dS)zSet the default format.N)rurv)rrrrr�set_defaultWsz BranchFormatRegistry.set_defaultcCs||_d|_dS)z,Set the default format by its format string.N)rvru)r�
format_stringrrr�set_default_key\sz$BranchFormatRegistry.set_default_key)N)	rrrrHrrwrxrz�
__classcell__rrrLrrsHs
rssBazaar-NG branch format 5
zbreezy.bzr.fullhistoryZBzrBranchFormat5s"Bazaar Branch Format 6 (bzr 0.15)
zbreezy.bzr.branchZBzrBranchFormat6s'Bazaar Branch Format 7 (needs bzr 1.6)
ZBzrBranchFormat7s(Bazaar Branch Format 8 (needs bzr 1.15)
ZBzrBranchFormat8s$Bazaar-NG Branch Reference Format 1
ZBranchReferenceFormatc@seZdZdZdd�ZdS)�BranchWriteLockResultz�The result of write locking a branch.

    :ivar token: The token obtained from the underlying branch lock, or
        None.
    :ivar unlock: A callable which will unlock the lock.
    cCsd|j|jfS)NzBranchWriteLockResult(%r, %r))r~r|rrrrrn�szBranchWriteLockResult.__repr__N)rrrrHrnrrrrr|�sr|c@seZdZdd�ZdS)�_ResultcCs@t|dd�sdS|�d�|jD]\}}}|�d|f�q dS)N�
tag_conflictszConflicting tags:
z    %s
)�getattr�writer~)r�to_filerPZvalue1Zvalue2rrr�_show_tag_conficts�s

z_Result._show_tag_confictsN)rrrr�rrrrr}�sr}c@seZdZdZdd�ZdS)�
PullResulta�Result of a Branch.pull operation.

    :ivar old_revno: Revision number before pull.
    :ivar new_revno: Revision number after pull.
    :ivar old_revid: Tip revision id before pull.
    :ivar new_revid: Tip revision id after pull.
    :ivar source_branch: Source (local) branch object. (read locked)
    :ivar master_branch: Master branch of the target, or the target if no
        Master
    :ivar local_branch: target branch if there is a Master, else None
    :ivar target_branch: Target/destination branch object. (write locked)
    :ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
    :ivar tag_updates: A dict with new tags, see BasicTags.merge_to
    cCs�t|dd�}t|dd�}t�sz|j|jkr:|�d|j�|rP|�dt|��|j|jkrz|sz|sp|�d�n
|�d�|�|�dS)Nr~�tag_updateszNow on revision %d.
z%d tag(s) updated.
zNo revisions or tags to pull.
zNo revisions to pull.
)rrrrr�rrBr��rr�r~r�rrr�report�s
zPullResult.reportN�rrrrHr�rrrrr��sr�c@seZdZdZdd�ZdS)�BranchPushResultauResult of a Branch.push operation.

    :ivar old_revno: Revision number (eg 10) of the target before push.
    :ivar new_revno: Revision number (eg 12) of the target after push.
    :ivar old_revid: Tip revision id (eg joe@foo.com-1234234-aoeua34) of target
        before the push.
    :ivar new_revid: Tip revision id (eg joe@foo.com-5676566-boa234a) of target
        after the push.
    :ivar source_branch: Source branch object that the push was from. This is
        read locked, and generally is a local (and thus low latency) branch.
    :ivar master_branch: If target is a bound branch, the master branch of
        target, or target itself. Always write locked.
    :ivar target_branch: The direct Branch where data is being sent (write
        locked).
    :ivar local_branch: If the target is a bound branch this will be the
        target, otherwise it will be None.
    cCs�t|dd�}t|dd�}t�s�|j|jkr\|jdurFttd�|j�nttd�|j�d��|r|ttddt	|��t	|��|j|jkr�|s�|s�ttd��nttd	��|�
|�dS)
Nr~r�zPushed up to revision %d.zPushed up to revision id %s.zutf-8z%d tag updated.z%d tags updated.z!No new revisions or tags to push.zNo new revisions to push.)rrrrrrr��decodeZngettextrBr�r�rrrr��s,
�
���zBranchPushResult.reportNr�rrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)r)zDResults of checking branch consistency.

    :see: Branch.check
    cCs||_g|_dSr)rVrrYrrrr�szBranchCheckResult.__init__cCs:ttd��|jj|jj��|jD]}ttd�|�q"dS)z�Report the check results via trace.note.

        :param verbose: Requests more detailed display of what was checked,
            if any.
        zchecked branch {0} format {1}zfound error:%sN)rr�rrVr4r#r)r�verbose�errorrrr�report_results�s

�
z BranchCheckResult.report_resultsN)rrrrHrr�rrrrr)�sr)c@sPeZdZdZgZedd��Zddd�Zddd	�Zdd
d�Z	ddd
�Z
dd�ZdS)r�z�This class represents operations taking place between two branches.

    Its instances have methods like pull() and push() and contain
    references to the source and target repositories these operations
    can be carried out on.
    cCst|j��dS)z�Return an iterable of format tuples for testing.

        :return: An iterable of (from_format, to_format) to use when testing
            this InterBranch class. Each InterBranch class should define this
            method itself.
        N)r\�_get_branch_formats_to_test��klassrrrr�
sz'InterBranch._get_branch_formats_to_testFNcCst|j��dS)z�Mirror source into target branch.

        The target branch is considered to be 'local', having low latency.

        :returns: PullResult instance
        N)r\r�)rr�r@r/rdrrrrr�szInterBranch.pullcCst|j��dS)z�Mirror the source branch into the target branch.

        The source branch is considered to be 'local', having low latency.
        N)r\r�)rr�r@r��_override_hook_source_branchrrrrr�szInterBranch.pushcCst|j��dS)a(Copy the content of source into target

        :param revision_id:
            if not None, the revision history in the new branch will
            be truncated to end with revision_id.
        :param tag_selector: Optional callback that can decide
            to copy or not copy tags.
        N)r\r)rrvrrrrr&s	zInterBranch.copy_content_intocCst|j��dS)z�Fetch revisions.

        :param stop_revision: Last revision to fetch
        :param limit: Optional rough limit of revisions to fetch
        :return: FetchResult object
        N)r\r�)rr@r�r�rrrr�1szInterBranch.fetchcCst|j��dS)z<Import reference information from source to target.
        N)r\r(rrrrr(:szInterBranch.update_references)FNNFN)FNFNN)NN)NNF)rrrrHZ_optimisersrbr�r�r�rr�r(rrrrr��s
	�

�


	r�cCst|t�r|rddgSgS|S)Nr�r%)r��bool)r�rrr�_fix_overwrite_type@s

r�c	@s�eZdZdZedd��Zedd��Zedd��Zdd	d
�Zddd
�Z	ddd�Z
ddd�Zddd�Zd dd�Z
d!dd�Zdd�ZdS)"�GenericInterBranchz=InterBranch implementation that uses public Branch functions.cCsdS)NTr)r�r�r�rrr�
is_compatibleLsz GenericInterBranch.is_compatiblecCst��t��fgSr)�format_registryrwr�rrrr�Qsz.GenericInterBranch._get_branch_formats_to_testcCst|tj�r|��|jS|Sr)r�r�ZRemoteBranchFormatZ_ensure_realZ_custom_format)r�rrrr�
unwrap_formatUsz GenericInterBranch.unwrap_formatNcCs�|j����|j����|j�|j|�|��z|j��}Wn4tjyr}zt	dt
|��WYd}~nd}~00|r�|j�|�|j��r�|jj
j|jj
|d�Wd�n1s�0YWd�n1s�0YdS)z�Copy the content of source into target

        revision_id: if not None, the revision history in the new branch will
                     be truncated to end with revision_id.
        z%parent was not accessible to copy: %sN��selector)r�r}r�r{r&r(r�rr�r
rcr�rXr%�merge_to)rrvrr�rfrrrr\s$
z$GenericInterBranch.copy_content_intoFc	Cs�|jj|jjkrdgfS|j����|j���xt��}|j|_||_|jj	|_
|jj	|_tjj
|_||_|��}|jj	j|jj	||d�Wd�Wd�S1s�0YWd�n1s�0YdS)Nr)r�r�)r�r=r�r}r{r�ZFetchSpecFactory�
source_branchZsource_branch_stop_revision_idr2Zsource_repoZtarget_repoZTargetRepoKindsZPREEXISTINGZtarget_repo_kindr�Zmake_fetch_spec)rr@r�r�Zfetch_spec_factoryr�rrrr�os"

��zGenericInterBranch.fetchc
	Cs^|j����<|j����|j��\}}d}|durd|}t�|�r`Wd�Wd�dS|}t�|j���}|j	|d�|s�|dur�|jj
��}|j�||||j�r�Wd�Wd�dS|du�r|dur�|jj
��}|j��\}}	|�
|||f|	|fg�}|j�||�Wd�n1�s00YWd�n1�sP0YdS)Nr3)r�r}r�r{r�rDr�Zensure_nullrCr�r2rnrCr�r�)
rr@r�ryZother_revnoZother_last_revisionZ
stop_revnorwr�Zthis_last_revisionrrr�_update_revisions�s8

�
���z$GenericInterBranch._update_revisionsTc
Cst����}|�|j���|j��}	|r4|	s4t���d}
d}|	r�t�	|	�}z|j
j�|�}
|
dk}Wntj
tjfy�d}Yn0|s�|	r�|s�|j�|�}
|�|
���|
r�|
j|j
||d|d�|j|||
||||d�Wd�S1�s�0YdS)z�Pull from source into self, updating my master if any.

        :param run_hooks: Private parameter - if false, this branch
            is being called because it's the master of the primary branch,
            so it should not run its hooks.
        NFr�)�	run_hooksr)�_hook_masterr��_override_hook_target�merge_tags_to_masterr)Zcleanup�	ExitStack�
enter_contextr�r{r�r�LocalRequiresBoundBranchr`Z
normalize_urlr�r!rUZPathNotChildr�r:r��_pull)rr�r@r/r�r�rdrZ
exit_stack�bound_location�
master_branchZsource_is_masterZ
normalizedrUrrrr��s>




�
��zGenericInterBranch.pullc

sJ|rt�|j|j����fdd�}|j����|j����|j��}|r�|jj|kr�|j��}|���Rt	�
|j|�}	|	j|||d�|j|||d��|�_|j�_
|�Wd�q�1s�0Yn(d}|j|||d��|j�_d�_
|��Wd�Wd�S1�s0YWd�n1�s<0YdS)a\See InterBranch.push.

        This is the basic concrete implementation of push()

        :param _override_hook_source_branch: If specified, run the hooks
            passing this Branch as the source, rather than self.  This is for
            use of RemoteBranch, where push is delegated to the underlying
            vfs-based Branch.
        cs&�r
��_tjdD]}|��qdS)Nre)r�rr.)r0�r�r�rr�
_run_hooks�sz+GenericInterBranch.push.<locals>._run_hooks)rN)rr#r�r�r}r{r�r=r:r�r��_basic_pushr��local_branch)
rr�r@r�r�rr�r�r�Zmaster_interrr�rr��s4


��&�zGenericInterBranch.pushcCs�t�}|j|_|j|_|j��\|_|_t|�}|j|kr`|jj	�
|jj	�}|j|d|v|d�|j��r�|jj
j|jj
d|v|d�\|_|_|��|j��\|_|_|S)z�Basic implementation of push without bound branches or hooks.

        Must be called with source read locked and target write locked.
        r��r�ryr%r�)r�r�r�r�r2r�rrr�r2rnr�rXr%r�r�r~r(rr)rr�r@rr�ryrrrr�	s$

�
��
zGenericInterBranch._basic_pushc

Cs&|rt���t�}
|j|
_|dur,|j|
_n||
_|j����|jj�	|jj�}|j�
�\|
_|
_t
|�}|j|d|v|d�|jjj|jjd|v||	d�\|
_|
_|��|j�
�\|
_|
_|r�||
_|
j|
_n|
j|
_d|
_|r�tjdD]}||
�q�|
Wd�S1�s0YdS)a1See Branch.pull.

        This function is the core worker, used by GenericInterBranch.pull to
        avoid duplication when pulling source->master and source->local.

        :param _hook_master: Private parameter - set the branch to
            be supplied as the master to pull hooks.
        :param run_hooks: Private parameter - if false, this branch
            is being called because it's the master of the primary branch,
            so it should not run its hooks.
            is being called because it's the master of the primary branch,
            so it should not run its hooks.
        :param _override_hook_target: Private parameter - set the branch to be
            supplied as the target_branch to pull hooks.
        :param local: Only update the local branch, and not the bound branch.
        Nr�r�r%)Z
ignore_masterr�rg)rr�r�r�r�r�r2r}r2rnr�rrr�r�r%r�r�r~r(rrr�r�rr.)
rr�r@r/r�r�r�rdr�rr�ryr0rrrr�#	sB
�

���
�


zGenericInterBranch._pullc	Cs�t|jjdd�sdS|j��}t|�dkr.dS|jj}|jj}|j��}t|�D]P\}\}}zt�	|||�}Wn tj
y�t�||�}Yn0|�|||f�qP|j�
|�dS)Nr'Fr)rr�r#Z_get_all_reference_inforBr=r�rr`Z
rebase_urlZInvalidRebaseURLsra�
setdefaultZ_set_all_reference_info)rZreference_dictZold_base�new_baseZtarget_reference_dictZ	tree_pathZbranch_locationZfile_idrrrr(b	s&

��z$GenericInterBranch.update_references)NN)NNF)NFN)FNNTNFN)FNFNN)N)	FNNNTNFTN)rrrrHrbr�r�r�rr�r�r�r�r�r�r(rrrrr�Is6




�
'�
+�
8
�
?r�N)2Z
__future__rr�globalsr�rrrr.rZinterr	�lockr
ZsixishrrZtracer
rrrrrrZControlComponentrZControlComponentFormatrKrc�objectrrUrpZControlComponentFormatRegistryrsZFormatRegistryZnetwork_format_registryr�Z
register_lazyrzr|r}r�r�r)r�r�r�Zregister_optimiserrrrr�<module>s~!c&(!�����

 -A	0