
    .Phܟ                     >   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZmZ dd	lmZmZmZmZmZ dd
lmZ eZdZdZdZdZdZ ed          Z dZ!e!Z" G d de#          Z$dedefdZ%dede&fdZ' G d d          Z( G d de(          Z) G d de(          Z* G d d e(          Z+d! Z,d" Z-d# Z.d;d<d$Z/d% Z0d&efd'Z1d( Z2d) Z3d* Z4d<d+Z5d,e(d-ed.e	e         d/ed0e	e         defd1Z6d2 Z7	 	 	 d=d4e(d5e8d,e9e8e8f         d6e	e         d7e&d8e&ddfd9Z:d: Z;dS )>zRef handling.    N)Iterator)suppress)AnyOptional   )PackedRefsExceptionRefFormatError)GitFileensure_dir_exists)ZERO_SHAObjectIDTaggit_linevalid_hexsha)ObjectContainers   HEADs   ref: s   refs/heads/s
   refs/tags/   refs/remotes/s    ~^:?*[s   ^{}c                       e Zd ZdZddZdS )
SymrefLoopz,There is a loop between one or more symrefs.returnNc                 "    || _         || _        d S N)refdepth)selfr   r   s      L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/refs.py__init__zSymrefLoop.__init__5   s    


    r   N)__name__
__module____qualname____doc__r    r   r   r   r   2   s.        66     r   r   contentsr   c                     |                      t                    r/| t          t                    d                             d          S t	          |           )z`Parse a symref value.

    Args:
      contents: Contents to parse
    Returns: Destination
    N   
)
startswithSYMREFlenrstrip
ValueError)r$   s    r   parse_symref_valuer,   :   sK     6"" 7F&--g666
X

r   refnamec                 0   d| v s|                      d          rdS d| vrdS d| v rdS t          |           D ]/\  }}t          | ||dz                      dk     s	|t          v r dS 0| d         dv rdS |                     d	          rdS d
| v rdS d| v rdS dS )a+  Check if a refname is correctly formatted.

    Implements all the same rules as git-check-ref-format[1].

    [1]
    http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html

    Args:
      refname: The refname to check
    Returns: True if refname is valid, False otherwise
    s   /.   .F   /s   ..r       s   .locks   @{   \T)r'   	enumerateordBAD_REF_CHARSendswith)r-   ics      r   check_ref_formatr:   F   s     7--d33u7uu'""  1wq1q5y!""T))Q--?-?55 .@r{eu!! uuu4r   c                      e Zd ZdZd%d&dZ	 	 	 	 d'	 d&dZ	 	 	 	 d'	 d&dZdeee	f         fdZ
deeee	         f         ddfd	Zdee	         fd
Z	 	 	 	 	 d(dedeee	f         dee         dee         dee         dee         deddfdZdee         fdZd Zd%dZd Zd%deee	f         fdZd&dZd ZdefdZdeee         ef         fdZdefdZde	fdZ	 	 	 	 d'defdZ	 d'defd Z d&d!Z!	 	 	 	 d'defd"Z"d&d#Z#d$ Z$dS ))RefsContainerzA container for refs.Nr   c                     || _         d S r   _logger)r   loggers     r   r   zRefsContainer.__init__k   s    r   c           	      V    | j         d S |d S |                      |||||||           d S r   r>   )r   r   old_shanew_sha	committer	timestamptimezonemessages           r   _logzRefsContainer._logn   s?     <F?FS'7Iy(GTTTTTr   c                 *    t          | j                  )zMake a ref point at another ref.

        Args:
          name: Name of the ref to set
          other: Name of the ref to point at
          message: Optional message
        )NotImplementedErrorset_symbolic_ref)r   nameotherrD   rE   rF   rG   s          r   rK   zRefsContainer.set_symbolic_ref~   s      "$"7888r   c                 *    t          | j                  )Get contents of the packed-refs file.

        Returns: Dictionary mapping ref names to SHA1s

        Note: Will return an empty dictionary when no packed-refs file is
            present.
        )rJ   get_packed_refsr   s    r   rP   zRefsContainer.get_packed_refs   s     "$"6777r   new_refsc                 *    t          | j                  )Add the given refs as packed refs.

        Args:
          new_refs: A mapping of ref names to targets; if a target is None that
            means remove the ref
        )rJ   add_packed_refs)r   rR   s     r   rU   zRefsContainer.add_packed_refs   s     "$"6777r   c                     dS ae  Return the cached peeled value of a ref, if available.

        Args:
          name: Name of the ref to peel
        Returns: The peeled value of the ref. If the ref is known not point to
            a tag, this will be the SHA the ref refers to. If the ref may point
            to a tag, but no cached information is available, None is returned.
        Nr#   r   rL   s     r   
get_peeledzRefsContainer.get_peeled   s	     tr   FbaserM   rD   rE   rF   rG   prunec                    |r#t          |                     |                    }nt                      }|                                D ]t\  }	}
|
|                    |	           n.|                     d                    ||	f          d |
|           |r'	 |                    |	           d# t          $ r Y pw xY wu|D ]/}|                     d                    ||f          d |           0d S )Nr0   rG   )	setsubkeysitemsaddset_if_equalsjoinremoveKeyErrorremove_if_equals)r   rZ   rM   rD   rE   rF   rG   r[   	to_deleterL   valuer   s               r   import_refszRefsContainer.import_refs   s3     	DLL..//III ;;== 	 	KD%}d####""IItTl++T5' #     $$T****   D
  	Q 	QC!!$))T3K"8"8$!PPPP	Q 	Qs   B,,
B98B9c                 *    t          | j                  )z#All refs present in this container.)rJ   allkeysrQ   s    r   rk   zRefsContainer.allkeys   s    !$,///r   c                 D    t          |                                           S r   )iterrk   rQ   s    r   __iter__zRefsContainer.__iter__   s    DLLNN###r   c                 X    ||                      |          S |                                 S )zRefs present in this container.

        Args:
          base: An optional base to return refs under.
        Returns: An unsorted set of valid refs in this container, including
            packed refs.
        )r_   rk   )r   rZ   s     r   keyszRefsContainer.keys   s*     <<%%%<<>>!r   c                     t                      }t          |          dz   }|                                 D ]4}|                    |          r|                    ||d                    5|S )zRefs present in this container under a base.

        Args:
          base: The base to return refs under.
        Returns: A set of valid refs in this container under the base; the base
            prefix is stripped from the ref names returned.
        r   N)r^   r)   rk   r'   ra   )r   rZ   rp   base_lenr-   s        r   r_   zRefsContainer.subkeys   sj     uut99q=||~~ 	- 	-G!!$'' -+,,,r   c                     i }|                      |          }|d}n|                    d          }|D ]>}	 | |dz   |z                       d                   ||<   (# t          t          f$ r Y ;w xY w|S )z6Return the contents of this container as a dictionary.Nr   r0   )rp   r*   stripr   re   )r   rZ   retrp   keys        r   as_dictzRefsContainer.as_dict   s    yy<DD;;t$$D 	 	Cs!2 9 9$ ? ?@C)    
s   $AA0/A0c                     |t           dfv rdS |                    d          rt          |dd                   st          |          dS )a   Ensure a refname is valid and lives in refs or is HEAD.

        HEAD is not a valid refname according to git-check-ref-format, but this
        class needs to be able to touch HEAD. Also, check_ref_format expects
        refnames without the leading 'refs/', but this class requires that
        so it cannot touch anything outside the refs dir (or HEAD).

        Args:
          name: The name of the reference.

        Raises:
          KeyError: if a refname is not HEAD or is otherwise not valid.
        s
   refs/stashNs   refs/   )HEADREFr'   r:   r	   rX   s     r   _check_refnamezRefsContainer._check_refname   s]     G]+++Fx(( 	'0@abb0J0J 	' &&&	' 	'r   c                     |                      |          }|s(|                                                     |d          }|S )zRead a reference without following any references.

        Args:
          refname: The name of the reference
        Returns: The contents of the ref file, or None if it does
            not exist.
        N)read_loose_refrP   get)r   r-   r$   s      r   read_refzRefsContainer.read_ref  sF     &&w// 	A++--11'4@@Hr   c                 *    t          | j                  )zRead a loose reference and return its contents.

        Args:
          name: the refname to read
        Returns: The contents of the ref file, or None if it does
            not exist.
        )rJ   r}   rX   s     r   r}   zRefsContainer.read_loose_ref  s     "$"5666r   c                 V   t           |z   }d}g }|                    t                     r~|t          t                     d         }|                    |           |                     |          }|sn5|dz  }|dk    rt          ||          |                    t                     ~||fS )zFollow a reference name.

        Returns: a tuple of (refnames, sha), wheres refnames are the names of
            references in the chain
        r   Nr   ry   )r(   r'   r)   appendr   r   )r   rL   r$   r   refnamesr-   s         r   followzRefsContainer.follow(  s     D=!!&)) 	.s6{{}}-GOOG$$$}}W--H QJEqyy u--- !!&)) 	. !!r   c                 4    |                      |          rdS dS )NTF)r   )r   r-   s     r   __contains__zRefsContainer.__contains__<  s     ==!! 	4ur   c                 X    |                      |          \  }}|t          |          |S )zaGet the SHA1 for a reference name.

        This method follows all symbolic references.
        )r   re   )r   rL   _shas       r   __getitem__zRefsContainer.__getitem__A  s/    
 T""3;4.. 
r   c                 *    t          | j                  )a'  Set a refname to new_ref only if it currently equals old_ref.

        This method follows all symbolic references if applicable for the
        subclass, and can be used to perform an atomic compare-and-swap
        operation.

        Args:
          name: The refname to set.
          old_ref: The old sha the refname must refer to, or None to set
            unconditionally.
          new_ref: The new sha the refname will refer to.
          message: Message for reflog
        Returns: True if the set was successful, False otherwise.
        )rJ   rb   )r   rL   old_refnew_refrD   rE   rF   rG   s           r   rb   zRefsContainer.set_if_equalsK  s    0 "$"4555r   c                 *    t          | j                  )zAdd a new reference only if it does not already exist.

        Args:
          name: Ref name
          ref: Ref value
        )rJ   
add_if_newr   rL   r   rD   rE   rF   rG   s          r   r   zRefsContainer.add_if_newe  s     "$/222r   c                     t          |          s,|                    t                    st          |d          |                     |d|           dS )a  Set a reference name to point to the given SHA1.

        This method follows all symbolic references if applicable for the
        subclass.

        Note: This method unconditionally overwrites the contents of a
            reference. To update atomically only if the reference has not
            changed, use set_if_equals().

        Args:
          name: The refname to set.
          ref: The new sha the refname will refer to.
        z+ must be a valid sha (40 chars) or a symrefN)r   r'   r(   r+   rb   )r   rL   r   s      r   __setitem__zRefsContainer.__setitem__p  s^     S!! 	TS^^F%;%; 	TRRRSSS4s+++++r   c                 *    t          | j                  )a  Remove a refname only if it currently equals old_ref.

        This method does not follow symbolic references, even if applicable for
        the subclass. It can be used to perform an atomic compare-and-delete
        operation.

        Args:
          name: The refname to delete.
          old_ref: The old sha the refname must refer to, or None to
            delete unconditionally.
          message: Message for reflog
        Returns: True if the delete was successful, False otherwise.
        )rJ   rf   )r   rL   r   rD   rE   rF   rG   s          r   rf   zRefsContainer.remove_if_equals  s    , "$"7888r   c                 2    |                      |d           dS )as  Remove a refname.

        This method does not follow symbolic references, even if applicable for
        the subclass.

        Note: This method unconditionally deletes the contents of a reference.
            To delete atomically only if the reference has not changed, use
            remove_if_equals().

        Args:
          name: The refname to delete.
        N)rf   rX   s     r   __delitem__zRefsContainer.__delitem__  s      	dD)))))r   c                     i }|                                  D ]:}	 t          |                     |                    }|||<   +# t          $ r Y 7w xY w|S )zuGet a dict with all symrefs in this container.

        Returns: Dictionary mapping source ref to target ref
        )rk   r,   r   r+   )r   ru   srcdsts       r   get_symrefszRefsContainer.get_symrefs  st    
 <<>> 	 	C(s););<< C     
s   "A
AAr   r   NNNN)NNNNF)%r   r    r!   r"   r   rH   rK   dictRefr   rP   r   rU   rY   bytesboolri   r   rk   rn   rp   r_   rw   r{   r   r}   tuplelistr   r   r   rb   r   r   rf   r   r   r#   r   r   r<   r<   h   s{            U 
U U U U( 9 
9 9 9 9$8c8m!4 8 8 8 88S(82D-D(E 8$ 8 8 8 8	(8"4 	 	 	 	 &*%)$(#'Q QQ CM"Q E?	Q
 E?Q 5/Q %Q Q 
Q Q Q Q:0# 0 0 0 0$ $ $" " " "   Dh$7     ' ' ' '&  7e 7 7 7 7"eDK$67 " " " "(t    
8     6 6 
6 6 6 66 QU	3 	3		3 	3 	3 	3, , , ,, 9 9 
9 9 9 90* * * *    r   r<   c            	            e Zd ZdZdd fdZd Zd Zd ZddZ	 	 	 	 dd	e	d
e	ddfdZ
	 	 	 	 ddefdZ	 	 	 	 dd	e	dedee         defdZ	 	 	 	 ddefdZd ZddZddZ xZS )DictRefsContainerzRefsContainer backed by a simple dict.

    This container does not support symbolic or packed references and is not
    threadsafe.
    Nr   c                     t                                          |           || _        i | _        t	                      | _        d S )Nr@   )superr   _refs_peeledr^   	_watchers)r   refsr@   	__class__s      r   r   zDictRefsContainer.__init__  s;    '''
.0#&55r   c                 4    | j                                         S r   r   rp   rQ   s    r   rk   zDictRefsContainer.allkeys      z   r   c                 8    | j                             |d           S r   r   r~   rX   s     r   r}   z DictRefsContainer.read_loose_ref      z~~dD)))r   c                     i S r   r#   rQ   s    r   rP   z!DictRefsContainer.get_packed_refs      	r   c                 H    | j         D ]}|                    ||f           d S r   )r   _notify)r   r   newshawatchers       r   r   zDictRefsContainer._notify  s6    ~ 	+ 	+GOOS&M****	+ 	+r   rL   rM   c           	          |                      |          d         }t          |z   }|| j        |<   |                     ||           |                     |||||||           d S )Nr2   rD   rE   rF   rG   )r   r(   r   r   rH   )	r   rL   rM   rD   rE   rF   rG   oldnews	            r   rK   z"DictRefsContainer.set_symbolic_ref  s}     kk$#un
4T3		 	 	
 	
 	
 	
 	
r   c           
      f   |&| j                             |t                    |k    rdS |                     |          \  }}	|D ]m}
|                     |
           | j                             |
          }|| j         |
<   |                     |
|           |                     |
||||||           ndS NFr   T)r   r~   r   r   r{   r   rH   )r   rL   r   r   rD   rE   rF   rG   	realnamesr   realnamer   s               r   rb   zDictRefsContainer.set_if_equals  s     4:>>$#A#AW#L#L5{{4((	1! 	 	H)))*..**C#*DJx LL7+++II##!      tr   r   rG   c           	          || j         v rdS || j         |<   |                     ||           |                     |d |||||           dS r   )r   r   rH   r   s          r   r   zDictRefsContainer.add_if_new  sm     4:5
4T3		 	 	
 	
 	
 tr   c           	         |&| j                             |t                    |k    rdS 	 | j                             |          }|                     |d            |                     ||d ||||           n# t          $ r Y nw xY wdS r   )r   r~   r   popr   rH   re   )r   rL   r   rD   rE   rF   rG   r   s           r   rf   z"DictRefsContainer.remove_if_equals  s     4:>>$#A#AW#L#L5	*..&&C LLt$$$II##!     	  	 	 	D	 ts   A7 7
BBc                 6    | j                             |          S r   )r   r~   rX   s     r   rY   zDictRefsContainer.get_peeled;  s    |%%%r   c                 h    |                                 D ]\  }}|                     |d|           dS )z0Update multiple refs; intended only for testing.N)r`   rb   )r   r   r   r   s       r   _updatezDictRefsContainer._update>  sD     

 	/ 	/HCsD#....	/ 	/r   c                 :    | j                             |           dS )z5Update cached peeled refs; intended only for testing.N)r   update)r   peeleds     r   _update_peeledz DictRefsContainer._update_peeledE  s    F#####r   r   r   r   )r   r    r!   r"   r   rk   r}   rP   r   r   rK   r   rb   r   r   r   r   rf   rY   r   r   __classcell__r   s   @r   r   r     s        ) ) ) ) ) ) )! ! !* * *  + + + + 
 

 
 

 
 
 
8   
   B #'   % 
   8   
   8& & &/ / / /$ $ $ $ $ $ $ $r   r   c                   2    e Zd ZdZd	dZd Zd Zd Zd ZdS )
InfoRefsContainerz5Refs container that reads refs from a info/refs file.r   Nc                 x    i | _         i | _        t          |          }t          |          \  | _         | _        d S r   )r   r   read_info_refssplit_peeled_refs)r   fr   s      r   r   zInfoRefsContainer.__init__M  s7    
a  %6t%<%<"T\\\r   c                 4    | j                                         S r   r   rQ   s    r   rk   zInfoRefsContainer.allkeysS  r   r   c                 8    | j                             |d           S r   r   rX   s     r   r}   z InfoRefsContainer.read_loose_refV  r   r   c                     i S r   r#   rQ   s    r   rP   z!InfoRefsContainer.get_packed_refsY  r   r   c                 X    	 | j         |         S # t          $ r | j        |         cY S w xY wr   )r   re   r   rX   s     r   rY   zInfoRefsContainer.get_peeled\  sB    	$<%% 	$ 	$ 	$:d####	$s    ))r   )	r   r    r!   r"   r   rk   r}   rP   rY   r#   r   r   r   r   J  sj        ??= = = =! ! !* * *  $ $ $ $ $r   r   c            	            e Zd ZdZdd fdZdefdZd Zd Zd Z	d	 Z
d
eeee         f         ddfdZd Zd ZddZ	 	 	 	 d	 ddZ	 	 	 	 ddefdZ	 	 	 	 ddededee         defdZ	 	 	 	 ddefdZ xZS )DiskRefsContainerz)Refs container that reads refs from disk.Nr   c                     t                                          |           t          |dd           t          j        |          }|| _        ||}t          |dd           t          j        |          }|| _        d | _        d | _        d S )Nr   encode)	r   r   getattrosfsencodepathworktree_path_packed_refs_peeled_refs)r   r   r   r@   r   s       r   r   zDiskRefsContainer.__init__f  s    '''44((4;t$$D	  M=(D11=K66M*  r   c                 0    | j         j         d| j        dS )N())r   r   r   rQ   s    r   __repr__zDiskRefsContainer.__repr__s  s     .)::DI::::r   c                    t                      }|                     |          }t          j        |          D ]\  }}}|t	          |          d          }t          j        j        dk    r7|                    t          j        t          j        j                  d          }|	                    d          }|D ]J}d
                    |r|gng |gz             }	t          |dz   |	z             r|                    |	           K|                                 D ]T}
|
                    |          r=|                    |
t	          |          d          	                    d                     U|S )N/r0   )r^   refpathr   walkr)   r   sepreplacer   rt   rc   r:   ra   rP   r'   )r   rZ   r_   r   rootunused_dirsfilesdirfilenamer-   rv   s              r   r_   zDiskRefsContainer.subkeysv  sX   %%||D!!(* 
	) 
	)$D+us4yy{{#Cw{c!!kk"+bgk":":DAA))D//C! ) )))c%9cUUrhZ$GHH $D4K'$9:: )KK((() '')) 	: 	:C~~d## :CD		,22488999r   c                    t                      }t          j                            |                     t
                              r|                    t
                     |                     d          }|                     d          }t          j        |          D ]\  }}}|t          |          d          }t          j        j	        dk    r7|
                    t          j        t          j        j	                  d          }|D ]=}d                    ||g          }	t          |	          r|                    |	           >|                    |                                            |S )Nr      refsr   r0   )r^   r   r   existsr   rz   ra   r   r)   r   r   r   rc   r:   r   rP   )
r   rk   r   refspathr   r   r   r   r   r-   s
             r   rk   zDiskRefsContainer.allkeys  s6   %%7>>$,,w//00 	!KK   ||C  <<(((*(9(9 	) 	)$D+us4yy{{#Cw{c!!kk"+bgk":":DAA! ) )))S(O44#G,, )KK((() 	t++--...r   c                 D   t           j        j        dk    r7|                    dt          j        t           j        j                            }|t
          k    r%t           j                            | j        |          S t           j                            | j        |          S )zReturn the disk path of a ref.r   r0   )r   r   r   r   r   rz   rc   r   rX   s     r   r   zDiskRefsContainer.refpath  sn    7;#<<bk"'+&>&>??D 7??7<< 2D9997<<	4000r   c                 R   | j         i | _         i | _        t          j                            | j        d          }	 t          |d          }n# t          $ r i cY S w xY w|5  t          t          |                    	                                }|
                    d          r1d|v r-t          |          D ]\  }}}|| j         |<   |r
|| j        |<   n4|                    d           t          |          D ]\  }}|| j         |<   ddd           n# 1 swxY w Y   | j         S )rO   N   packed-refsrbs   # pack-refss    peeledr   )r   r   r   r   rc   r
   FileNotFoundErrornextrm   r*   r'   read_packed_refs_with_peeledseekread_packed_refs)r   r   r   
first_liner   rL   r   s          r   rP   z!DiskRefsContainer.get_packed_refs  s    $ !#D "D7<<	>::DD$''$   			 
6 
6!$q'']]1133
((88 6Z:=U=U-I!-L-L = =)T625)$/! =6<D-d3=
 FF1III%5a%8%8 6 6	T25)$//
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6   s$   A AA"B)DDDrR   c                 z   |sdS t           j                            | j        d          }t          |d          5 }|                                                                 }|                                D ]\  }}|t          k    rt          d          t          t                    5  t          j        |                     |                     ddd           n# 1 swxY w Y   ||||<   z|                    |d           t          ||| j                   || _        ddd           dS # 1 swxY w Y   dS )rT   Nr   wbzcannot pack HEAD)r   r   rc   r
   rP   copyr`   rz   r+   r   OSErrorrd   r   r   write_packed_refsr   r   )r   rR   r   r   packed_refsr   targets          r   rU   z!DiskRefsContainer.add_packed_refs  s     	Fw||DI~66T4   	,A..005577K'~~// / /V'>>$%7888
 g&& 1 1Idll3//0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 %'-K$$OOC....ad.?@@@ +D-	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s6   A.D0((CD0C  D0#C $?D00D47D4c                     |                                   | j        	|| j        vrdS || j        v r| j        |         S | |         S rW   )rP   r   r   rX   s     r   rY   zDiskRefsContainer.get_peeled  sY     	$D4E(E(E44$$$$T** :r   c                    |                      |          }	 t          |d          5 }|                    t          t                              }|t          k    r>|t          t          |                                        d          z   cddd           S ||                    dt          t                    z
            z   cddd           S # 1 swxY w Y   dS # t          t          f$ r Y dS w xY w)a  Read a reference file and return its contents.

        If the reference file a symbolic reference, only read the first line of
        the file. Otherwise, only read the first 40 bytes.

        Args:
          name: the refname to read, relative to refpath
        Returns: The contents of the ref file, or None if the file does not
            exist.

        Raises:
          IOError: if any other error occurs
        r   r&   N(   )
r   r
   readr)   r(   r   rm   r*   r   UnicodeError)r   rL   r   r   headers        r   r}   z DiskRefsContainer.read_loose_ref  sC    <<%%	4(( =AF,,V##!DaMM$8$8$A$AA	= = = = = = = = "AFF2F+;$<$<<= = = = = = = = = = = = = = = = = = & 	 	 	 44		sA   C A$CC ,CC CC CC C32C3c                 *   | j         d S t          j                            | j        d          }t	          |d          }	 d | _         |                                  || j         vr	 |                                 d S | j         |= t          t                    5  | j	        |= d d d            n# 1 swxY w Y   t          || j         | j	                   |                                 |                                 d S # |                                 w xY w)Nr   r   )r   r   r   rc   r
   rP   abortr   re   r   r  close)r   rL   r   r   s       r   _remove_packed_refz$DiskRefsContainer._remove_packed_ref  s<   $F7<<	>::Hd##	 $D  """4,,, GGIIIII !$'(## , ,%d+, , , , , , , , , , , , , , ,a!2D4EFFFGGIIIGGIIIIIAGGIIIIs6    $C< ;C< 	B, C< ,B00C< 3B042C< <Dc           	         |                      |           |                      |           |                     |          }t          |d          }	 |                    t          |z   dz              |                     |          d         }	|                     ||	|	||||           |                                 dS # t          $ r |	                                  w xY w)zMake a ref point at another ref.

        Args:
          name: Name of the ref to set
          other: Name of the ref to point at
          message: Optional message to describe the change
        r      
r2   r   N)
r{   r   r
   writer(   r   rH   r  BaseExceptionr  )
r   rL   rM   rD   rE   rF   rG   r   r   r   s
             r   rK   z"DiskRefsContainer.set_symbolic_ref/  s      	D!!!E"""<<%%Hd##	GGFUNU*+++++d##B'CII##!     GGIIIII	  	 	 	GGIII	s   AB> > Cc           
      R   |                      |           	 |                     |          \  }}	|d         }
n# t          t          t          f$ r |}
Y nw xY w|                     |
          }t          j                            |
          }| 	                                }|rF|
                    |d          t          |          t          j                            |          }|Ft          t          j                            |                     t          |d          5 }|	 |                     |
          }|-| 	                                
                    |
t                    }||k    r"|                                 	 ddd           dS n## t"          $ r |                                  w xY w	 |                    |dz              n## t"          $ r |                                  w xY w|                     |
||||||           ddd           n# 1 swxY w Y   dS )a  Set a refname to new_ref only if it currently equals old_ref.

        This method follows all symbolic references, and can be used to perform
        an atomic compare-and-swap operation.

        Args:
          name: The refname to set.
          old_ref: The old sha the refname must refer to, or None to set
            unconditionally.
          new_ref: The new sha the refname will refer to.
          message: Set message for reflog
        Returns: True if the set was successful, False otherwise.
        r2   Nr   Fr  r   T)r{   r   re   
IndexErrorr   r   r   r   dirnamerP   r~   NotADirectoryErrorr   r
   r}   r   r  r   r  rH   )r   rL   r   r   rD   rE   rF   rG   r   r   r   r   	probe_refr  r   orig_refs                   r   rb   zDiskRefsContainer.set_if_equalsU  s   . 	D!!!	;;t,,LIq }HH*j1 	 	 	HHH	<<)) GOOH--	**,, 	3y$//;(222	22I  	3
 	"'//(33444Xt$$ 	"
#228<<H'#'#7#7#9#9#=#=h#Q#Q7**			$	 	 	 	 	 	 	 	 +    GGIII%((((   			 II##!    %	 	 	 	 	 	 	 	 	 	 	 	 	 	 	6 tsR    8 AA#H'AFH F44H8GH G11HH #H rL   r   rG   c           
         	 |                      |          \  }}|dS |d         }	n# t          t          f$ r |}	Y nw xY w|                     |	           |                     |	          }
t          t          j                            |
                     t          |
d          5 }t          j        
                    |
          s||                                 v r"|                                 	 ddd           dS 	 |                    |dz              |                     |d|||||           n## t          $ r |                                  w xY w	 ddd           n# 1 swxY w Y   dS )a  Add a new reference only if it does not already exist.

        This method follows symrefs, and only ensures that the last ref in the
        chain does not exist.

        Args:
          name: The refname to set.
          ref: The new sha the refname will refer to.
          message: Optional message for reflog
        Returns: True if the add was successful, False otherwise.
        NFr2   r   r  r   T)r   re   r  r{   r   r   r   r   r  r
   r   rP   r  r  rH   r   )r   rL   r   rD   rE   rF   rG   r   r$   r   r   r   s               r   r   zDiskRefsContainer.add_if_new  s   (	"&++d"3"3Ix#u }HH*% 	 	 	HHH	H%%%<<))"'//(33444Xt$$ 	w~~h'' 443G3G3I3I+I+I				 	 	 	 	 	 	 	e$$$
 		''%#     	    				 	 	 	 	 	 	 	 	 	 	 	 	 	 	& ts;   ' ' ==&AE$?D4E$4 EE$$E(+E(c           	         |                      |           |                     |          }t          t          j                            |                     t          |d          }	 |a|                     |          }	|	-|                                 	                    |t                    }	|	|k    r	 |                                 dS 	 t          j                            |          }
n# t          $ r d}
Y nw xY w|
rt          j        |           |                     |           |                     ||d||||           |                                 n# |                                 w xY w|}	 	 |                    dd          \  }}n# t$          $ r Y nGw xY w|dk    rn<|                     |          }	 t          j        |           n# t          $ r Y nw xY wndS )	a  Remove a refname only if it currently equals old_ref.

        This method does not follow symbolic references. It can be used to
        perform an atomic compare-and-delete operation.

        Args:
          name: The refname to delete.
          old_ref: The old sha the refname must refer to, or None to
            delete unconditionally.
          message: Optional message
        Returns: True if the delete was successful, False otherwise.
        r   NFr   Tr0   r   r   )r{   r   r   r   r   r  r
   r}   rP   r~   r   r  lexistsr   rd   r  rH   rsplitr+   rmdir)r   rL   r   rD   rE   rF   rG   r   r   r  foundparentr   parent_filenames                 r   rf   z"DiskRefsContainer.remove_if_equals  s*   * 	D!!!<<%%"'//(33444Hd##	"..t44##335599$IIHw&& 0 GGIIIII+11     $	(#####D)))II##!     GGIIIIAGGIIII
 	"MM$22	      "ll622O))))   
 	$ tsV   (AE C, +E ,C;8E :C;;A
E E07F 
FF>G 
G G )NNr   r   )r   r    r!   r"   r   strr   r_   rk   r   rP   r   r   r   r   rU   rY   r}   r  rK   r   rb   r   r   rf   r   r   s   @r   r   r   c  s       33! ! ! ! ! ! !;# ; ; ; ;  &  "	1 	1 	1! ! !@",S(82D-D(E ",$ ", ", ", ",H  &  <   2 $ 
$ $ $ $V C C 
C C C CR #'1 11 1 %1 
1 1 1 1n O O 
O O O O O O O Or   r   c                 2   |                      d                              d          }t          |          dk    rt          d|           |\  }}t	          |          st          d|          t          |          st          d|          ||fS )z6Split a single ref line into a tuple of SHA1 and name.s   
       zinvalid ref line Invalid hex sha zinvalid ref name )r*   splitr)   r   r   r:   )linefieldsr   rL   s       r   _split_ref_liner(    s    [[!!''--F
6{{a!">d">">???IC >!"<S"<"<===D!! @!">d">">???;r   c              #      K   | D ]M}|                     d          r|                     d          rt          d          t          |          V  NdS )zRead a packed refs file.

    Args:
      f: file-like object to read from
    Returns: Iterator over tuples with SHA1s and ref names.
       #   ^z.found peeled ref in packed-refs without peeledN)r'   r   r(  )r   r&  s     r   r   r   ,  ss        $ $??4   	??4   	X%&VWWWd######$ $r   c              #     K   d}| D ]}|d         dk    r|                     d          }|                    d          rf|st          d          t          |dd                   st          d|dd                   t	          |          \  }}d}|||dd         fV  |rt	          |          \  }}||dfV  |}|rt	          |          \  }}||dfV  dS dS )	a	  Read a packed refs file including peeled refs.

    Assumes the "# pack-refs with: peeled" line was already read. Yields tuples
    with ref names, SHA1s, and peeled SHA1s (or None).

    Args:
      f: file-like object to read from, seek'ed to the second line
    Nr   r*  r&   r+  zunexpected peeled ref liner   r$  )r*   r'   r   r   r(  )r   lastr&  r   rL   s        r   r   r   <  sD      D  7d??{{7##??4   	 H)*FGGGQRR)) K)*IT!""X*I*IJJJ'--ICDd122h''''' (+D11	TD$''''DD  #D))	TD$   r   c                    |i }n|                      d           t          |                                          D ]P}|                      t          ||         |                     ||v r!|                      d||         z   dz              QdS )zWrite a packed refs file.

    Args:
      f: empty file-like object to write to
      packed_refs: dict of refname to sha of packed refs to write
      peeled_refs: dict of refname to peeled value of sha
    Ns   # pack-refs with: peeled
r+  r  )r  sortedrp   r   )r   r  peeled_refsr-   s       r   r  r  \  s     	-...+**,,-- 9 9	W-w77888k!!GGD;w//%78889 9r   c                     i }|                                  D ]3}|                    d                              dd          \  }}|||<   4|S )Nr&      	r   )	readlinesr*   r%  )r   ru   r&  r   rL   s        r   r   r   n  sS    
C  kk'**00::dD		Jr   storec              #   F  K   ddl m} t          |                                           D ]v\  }}|t          k    r	 ||         }n# t
          $ r Y 'w xY w |||          \  }}|j        dz   |z   dz   V  |j        |j        k    r|j        dz   |z   t          z   dz   V  wdS )zGenerate info refs.r   peel_shar2  r  N)object_storer7  r/  r`   rz   re   idPEELED_TAG_SUFFIX)r   r4  r7  rL   r   ounpeeledr   s           r   write_info_refsr=  v  s       '&&&&&DJJLL)) G G	c 7??	c
AA 	 	 	H	#8E3//&dUlT!E))))469)e#d*->>FFFFG Gs   A
AAc                 6    |                      t                    S r   )r'   LOCAL_BRANCH_PREFIX)xs    r   is_local_branchrA    s    <<+,,,r   c                 >    d |                                  D             S )zRemove all peeled refs.c                 N    i | ]"\  }}|                     t                    ||#S r#   )r7   r:  ).0r   r   s      r   
<dictcomp>z%strip_peeled_refs.<locals>.<dictcomp>  s@       c3s||DU7V7VS  r   )r`   )r   s    r   strip_peeled_refsrF    s+     #'::<<   r   c                     i }i }|                                  D ]E\  }}|                    t                    r!|||dt          t                              <   @|||<   F||fS )z$Split peeled refs from regular refs.N)r`   r7   r:  r)   )r   r   regularr   r   s        r   r   r     su    FGJJLL  S<<)** 	58F30#/0000122GCLLF?r   c                     d|z   dz   }|r_|                     t                    rG|t          z   }||t          t                    d          z   }|| v r|                     ||           d S d S d S d S )Nr   r0   )r'   r?  rz   r)   rK   )r   originorigin_headorigin_base
origin_ref
target_refs         r   _set_origin_headrO    s    "V+d2K :{--.ABB : 7*
 ;s3F/G/G/I/I#JJ
!!*j99999	: : : : r   r   rJ  rK  branchref_messagec                    d|z   dz   }|rn||z   }|| v r*t           |z   }|                     || |         |           |}nt          |z   | v rt          |z   }nt          t	          j        |          d          |rm|}|                    t                     r ||t          t                     d         z   }n|}	 |                     || |         |           n# t          $ r Y nw xY wt          d          |S )zSet the default branch.r   r0   z is not a valid branch or tagNz+neither origin_head nor branch are provided)	r?  r   LOCAL_TAG_PREFIXr+   r   r   r'   r)   re   )	r   rJ  rK  rP  rQ  rL  rM  	local_refhead_refs	            r   _set_default_branchrV    s=    #V+d2K H 6)
+f4IOOItJ'7EEE HH&$..'&0HHF 3 3TTTUUU	 H!!"566 	%${37J3K3K3M3M'NNJJ$J	OOHd:&6DDDD 	 	 	D	 FGGGOs   :C 
C%$C%c                    |                     t                    rh| |         }t          |t                    r$|j        \  }}|                    |          j        }| t          = |                     t          d ||           nU	 | |         }| 	                    t          |           |                     t          d ||           n# t          $ r d }Y nw xY w|S )Nr]   )r'   rS  
isinstancer   object
get_objectr9  rz   rb   rK   re   )r   rU  rQ  head_clsobjs         r   	_set_headr^    s    +,, H~dC   	*ID#>>#&&)DM7D$DDDD	>D!!'8444wdKHHHH 	 	 	DDD	Ks   AC CCFrefs_containerremote_namerG   r[   
prune_tagsc                 4   t          |          }d |                                D             }|                     d|                                z   |||           d |                                D             }|                     t          |||           d S )Nc                     i | ]<\  }}|                     t                    |t          t                    d          |=S r   )r'   r?  r)   rD  nvs      r   rE  z'_import_remote_refs.<locals>.<dictcomp>  sU       Q<<+,,	#!
"
"
$
$%q  r   r   )rG   r[   c                     i | ]V\  }}|                     t                    |                    t                    9|t	          t                    d          |WS r   )r'   rS  r7   r:  r)   rd  s      r   rE  z'_import_remote_refs.<locals>.<dictcomp>  sl       Q<<()) 34**=N2O2O	#


!
!"A  r   )rF  r`   ri   r   rS  )	r_  r`  r   rG   r[   ra  stripped_refsbranchestagss	            r   _import_remote_refsrk    s     &d++M #))++  H
 ;--///	     #))++  D
 $z      r   c           
         ddl m} i }|                                D ]\  }}	  || |          \  }}t          |t                    r|j        ||t          z   <   |j        ||<   G# t          $ rX t          j	        d
                    |                    dd          |                    d                    t                     Y w xY w|S )Nr   r6  z#ref {} points at non-present sha {}zutf-8r   ascii)r8  r7  r`   rX  r   r9  r:  re   warningswarnformatdecodeUserWarning)r4  r   r7  ru   r   r   r<  r   s           r   serialize_refsrs    s    &&&&&&
CJJLL # #S	#'xs33Hf (C(( 9/5yC++,{CHH  	 	 	M5<<JJw	22CJJw4G4G  	   H	 Js   A$$ACCr   r   )NFF)<r"   r   rn  collections.abcr   
contextlibr   typingr   r   errorsr   r	   filer
   r   objectsr   r   r   r   r   packr   r   r   rz   r(   r?  rS  LOCAL_REMOTE_PREFIXr^   r6   r:  ANNOTATED_TAG_SUFFIX	Exceptionr   r,   r   r:   r<   r   r   r   r(  r   r   r  r   r=  rA  rF  r   rO  rV  r^  r   r   rk  rs  r#   r   r   <module>r~     s  .   				  $ $ $ $ $ $                       7 7 7 7 7 7 7 7 , , , , , , , , D D D D D D D D D D D D D D ! ! ! ! ! !
	$   & N##  )        	 	5 	 	 	 	c d    DN N N N N N N Nb
N$ N$ N$ N$ N$ N$ N$ N$b$ $ $ $ $ $ $ $2y y y y y y y yx
 
 
$ $ $      @9 9 9 9 9$  G G G G G(- - -  	 	 	: : : :
 % 	
 %    D  0  $ ! sCx. e_	
   
   <    r   