
    q&f2"                         d dl mZ d dlmZmZmZ ddlmZmZ  G d dej                        Z
d Zd Zd	 ZeeegZd
 Zy)   )_)errorrequirementsscmutil   )actionsenginec                   "     e Zd ZdZ fdZ xZS )AutoUpgradeOperationznA limited Upgrade Operation used to run simple auto upgrade task

    (Expand it as needed in the future)
    c                 (    t         |   |d       y )NF)new_requirementsbackup_store)super__init__)selfreq	__class__s     F/usr/lib/python3/dist-packages/mercurial/upgrade_utils/auto_upgrade.pyr   zAutoUpgradeOperation.__init__   s      	 	
    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    

 
r   r   c                 n   	  j                   	 j                  	j                  dd      }	j                  dd      d}|rnt        j                  vr\	j                  dd      }t        j
                  v }|r|st        d      d 	fd}|S |r|st        d	      d 	fd
}|S )zreturn an automatic-upgrade action for `share-safe` if applicable

    If no action is needed, return None, otherwise return a callback to upgrade
    or downgrade the repository according the configuration and repository
    format.
       formats<   use-share-safe.automatic-upgrade-of-mismatching-repositoriessB   use-share-safe.automatic-upgrade-of-mismatching-repositories:quietNs   use-share-safes?   automatically upgrading repository to the `share-safe` feature
s9   (see `hg help config.format.use-share-safe` for details)
c                      j                   s$ s"j                         j                         j                  t        j                         t        j                         y N)quiet	write_erraddrequirementsmodSHARESAFE_REQUIREMENTr   writereporequirementsauto_upgrade_quiethintmsgrepor   uis   r   actionz%get_share_safe_action.<locals>.actionC   sI    $6LL%LL&  !F!FG--dLAr   sC   automatically downgrading repository from the `share-safe` feature
c                      j                   s$ s"j                         j                         j                  t        j                         t        j                         y r   )r   r    discardr"   r#   r   r$   r%   s   r   r+   z%get_share_safe_action.<locals>.actionQ   sI    $6LL%LL&$$_%J%JK--dLAr   )r*   r   
configboolr"   SHARED_REQUIREMENTr#   r   )
r)   auto_upgrade_share_sourcer+   	sf_configsf_localr&   r'   r(   r   r*   s
   `    @@@@@r   get_share_safe_actionr3   "   s     
B$$L "G! M
 F 	"..lBMM)->?	"88LHXC QDB B* M iC QDB B Mr   c                 \   	  j                   	t         j                        	j                  dd      }	j                  dd      d}|r\	j                  dd      }t        j
                  v }|r|st        d      d 	fd}|S |r|st        d	      d 	fd
}|S )zreturn an automatic-upgrade action for `tracked-hint` if applicable

    If no action is needed, return None, otherwise return a callback to upgrade
    or downgrade the repository according the configuration and repository
    format.
    r   sG   use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositoriessM   use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories:quietNs   use-dirstate-tracked-hintsA   automatically upgrading repository to the `tracked-hint` feature
sD   (see `hg help config.format.use-dirstate-tracked-hint` for details)
c                      j                   s$s"j                         j                         j                  t        j                         t              } t        j                  | d       y )NTr!   )r   r    r!   r"   DIRSTATE_TRACKED_HINT_V1r   r	   upgrade_tracked_hintopr&   r'   r(   r)   r   r*   s    r   r+   z'get_tracked_hint_action.<locals>.actiony   sW    $6LL%LL&  !I!IJ),7++BbdCr   sE   automatically downgrading repository from the `tracked-hint` feature
c                      j                   s$s"j                         j                         j                  t        j                         t              } t        j                  | d       y )NFr6   )r   r    r-   r"   r7   r   r	   r8   r9   s    r   r+   z'get_tracked_hint_action.<locals>.action   sW    $6LL%LL&$$_%M%MN),7++BbeDr   )r*   setr   r.   r"   r7   r   )
r)   auto_upgrade_tracked_hintr+   	th_configth_localr&   r'   r(   r   r*   s
   `    @@@@@r   get_tracked_hint_actionr@   [   s     
Bt(()L "R! X
 F MM)-IJ	";;|KXC \DD D. M iC \DE E Mr   c                 \   	  j                   	t         j                        	j                  dd      }	j                  dd      d}|r\	j                  dd      }t        j
                  v }|r|st        d      d 	fd}|S |r|st        d	      d 	fd
}|S )zreturn an automatic-upgrade action for `dirstate-v2` if applicable

    If no action is needed, return None, otherwise return a callback to upgrade
    or downgrade the repository according the configuration and repository
    format.
    r   s=   use-dirstate-v2.automatic-upgrade-of-mismatching-repositoriessC   use-dirstate-v2.automatic-upgrade-of-mismatching-repositories:quietNs   use-dirstate-v2s@   automatically upgrading repository to the `dirstate-v2` feature
s:   (see `hg help config.format.use-dirstate-v2` for details)
c                      j                   s$s"j                         j                         j                  t        j                         t              } t        j                  j                  | dd       y )N   v1   v2)	r   r    r!   r"   DIRSTATE_V2_REQUIREMENTr   r	   upgrade_dirstater*   fake_opauto_upgrade_dv2_quietr'   r(   r)   r   r*   s    r   r+   z&get_dirstate_v2_action.<locals>.action   s]    $:LL%LL&  !H!HI.|<''wuMr   sD   automatically downgrading repository from the `dirstate-v2` feature
c                      j                   s$s"j                         j                         j                  t        j                         t              } t        j                  j                  | dd       y )NrD   rC   )	r   r    r-   r"   rE   r   r	   rF   r*   rG   s    r   r+   z&get_dirstate_v2_action.<locals>.action   s]    $:LL%LL&$$_%L%LM.|<''wuMr   )r*   r<   r   r.   r"   rE   r   )
r)   auto_upgrade_dv2r+   	d2_configd2_localrI   r'   r(   r   r*   s
   `    @@@@@r   get_dirstate_v2_actionrN      s     
Bt(()L}}H  ]]N
 FMM)-?@	"::lJXC
 O N N2 M# iC
 O N N Mr   c                    d}d}	 |s|dz  }|dkD  rt        j                  d      d}t        D ]]  } ||       }|d}| j                  d      5  | j	                  d      5   ||       }| |         |       } ddd       ddd       _ |s| S # 1 sw Y   xY w# 1 sw Y   zxY w# t         j
                  $ r Y | S w xY w)	a%  potentially perform auto-upgrade and return the final repository to use

    Auto-upgrade are "quick" repository upgrade that might automatically be run
    by "any" repository access. See `hg help config.format` for automatic
    upgrade documentation.

    note: each relevant upgrades are done one after the other for simplicity.
    This avoid having repository is partially inconsistent state while
    upgrading.

    repo: the current repository instance
    maker_func: a factory function that can recreate a repository after an upgrade
    F    r   d   zToo many auto upgrade loopsTN)wait)r   ProgrammingErrorAUTO_UPGRADE_ACTIONSwlocklock	LockError)r)   
maker_funcclearloop
get_actionr+   s         r   may_auto_upgrader\      s     EDAIDcz,,-JKKE2 ,
#D)%!E/ ,1F ,!+D!1!-"H)|	, , ,	, * K, , , ,
 ??  	KsF   6B, B, B $B=B B, BB  B)	%B, ,CCN)i18nr    r   r   r"   r   r   r	   BaseOperationr   r3   r@   rN   rT   r\    r   r   <module>ra      sU     

700 

6r5p9z  (r   