
    d                     4   d Z ddlmZmZmZmZmZmZ erddlm	Z	m
Z
mZ ddlmZmZ ddlmZ deeef         defd	Zd
ddeeef         ddfdZd
ddeeef         ddfdZded         deeef         ddfdZ	 d(ded         ded         deeef         dedeed         ed         ef         f
dZ	 d(ded         ded         deeee         f         defdZd Zd
ddeeef         ded          fd!Z G d" d#e          Zd$ Zd
dd%eeef         dd fd&Zd'S ))zObject specification.    )TYPE_CHECKINGIteratorListOptionalTupleUnion   )CommitShaFileTree)RefRefsContainer)Repotextreturnc                 R    t          | dd           |                     d          } | S )Nencodeascii)getattrr   )r   s    V/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/objectspec.pyto_bytesr      s*    tXt$$0{{7##K    repor   	objectishr   c                 0    t          |          }| |         S )zParse a string referring to an object.

    Args:
      repo: A `Repo` object
      objectish: A string referring to an object
    Returns: A git object
    Raises:
      KeyError: If the object can not be found
    )r   )r   r   s     r   parse_objectr   %   s     ##I	?r   treeishr   c                     t          |          }	 t          | |          }n# t          $ r Y nw xY w| |         }|j        dk    r| |j                 S |S )zParse a string referring to a tree.

    Args:
      repo: A `Repo` object
      treeish: A string referring to a tree
    Returns: A git object
    Raises:
      KeyError: If the object can not be found
    s   commit)r   	parse_refKeyError	type_nametree)r   r   os      r   
parse_treer$   3   sn     wGD'**   WA{iAF|Hs   " 
//	container)r   r   refspecr   c                     t          |          }|d|z   d|z   d|z   d|z   d|z   dz   g}|D ]
}|| v r|c S t          |          )zParse a string referring to a reference.

    Args:
      container: A RefsContainer object
      refspec: A string referring to a ref
    Returns: A ref
    Raises:
      KeyError: If the ref can not be found
    s   refs/s
   refs/tags/   refs/heads/s   refs/remotes/s   /HEAD)r   r    )r%   r&   possible_refsrefs       r   r   r   H   s     wG7 7"7"X-M   )JJJ 
7

r   Flh_containerrh_containerforcec                 H   t          |          }|                    d          rd}|dd         }d|v r|                    d          \  }}n|x}}|dk    rd}nt          | |          }|dk    rd}n+	 t          ||          }n# t          $ r d|vrd|z   }Y nw xY w|||fS )	a  Parse a reftuple spec.

    Args:
      lh_container: A RefsContainer object
      rh_container: A RefsContainer object
      refspec: A string
    Returns: A tuple with left and right ref
    Raises:
      KeyError: If one of the refs can not be found
       +Tr	   N   :r      /r(   )r   
startswithsplitr   r    )r+   r,   r&   r-   lhrhs         r   parse_reftupler6   a   s     wG$ !""+ w==&&RRR	Syy|R((	Syy	)<,,BB 	) 	) 	)2~~#b(	) E?s   5B BBrefspecsc           	          t          |t                    s|g}g }|D ](}|                    t          | |||                     )|S )aX  Parse a list of reftuple specs to a list of reftuples.

    Args:
      lh_container: A RefsContainer object
      rh_container: A RefsContainer object
      refspecs: A list of refspecs or a string
      force: Force overwriting for all reftuples
    Returns: A list of refs
    Raises:
      KeyError: If one of the refs can not be found
    )r-   )
isinstancelistappendr6   )r+   r,   r7   r-   retr&   s         r   parse_reftuplesr=      s^      h%% :
C U U

>,gUSSSTTTTJr   c                     t          |t                    s|g}g }|D ]%}|                    t          | |                     &|S )zParse a list of refspecs to a list of refs.

    Args:
      container: A RefsContainer object
      refspecs: A list of refspecs or a string
    Returns: A list of refs
    Raises:
      KeyError: If one of the refs can not be found
    )r9   r:   r;   r   )r%   r7   r<   r&   s       r   
parse_refsr?      sU     h%% :
C 2 2

9Y001111Jr   committishsr
   c                 \    t          |          }t          t          | |          g          S )a@  Parse a string referring to a range of commits.

    Args:
      repo: A `Repo` object
      committishs: A string referring to a range of commits.
    Returns: An iterator over `Commit` objects
    Raises:
      KeyError: When the reference commits can not be found
      ValueError: If the range can not be parsed
    )r   iterparse_commit)r   r@   s     r   parse_commit_rangerD      s,     ;''KdK001222r   c                       e Zd ZdZd ZdS )AmbiguousShortIdzThe short id is ambiguous.c                 "    || _         || _        d S )N)prefixoptions)selfrH   rI   s      r   __init__zAmbiguousShortId.__init__   s    r   N)__name__
__module____qualname____doc__rK    r   r   rF   rF      s)        $$    r   rF   c                     g }| D ]2}|                     |          r|                    | |                    3|st          |          t          |          dk    r|d         S t	          ||          )z$Scan an object store for a short id.r	   r   )r2   r;   r    lenrF   )object_storerH   r<   	object_ids       r   scan_for_short_idrU      s     C! 0 0	'' 	0JJ|I./// v
3xx1}}1v
63
'
''r   
committishc                    t          |          }	 | |         S # t          $ r Y nw xY w	 | t          | |                   S # t          $ r Y nw xY wt          |          dk    rZt          |          dk     rG	 t	          |d           	 t          | j        |          S # t          $ r Y nw xY w# t          $ r Y nw xY wt          |          )a'  Parse a string referring to a single commit.

    Args:
      repo: A` Repo` object
      committish: A string referring to a single commit.
    Returns: A Commit object
    Raises:
      KeyError: When the reference commits can not be found
      ValueError: If the range can not be parsed
       (      )r   r    r   rR   intrU   rS   
ValueError)r   rV   s     r   rC   rC      s    *%%JJ   IdJ//00   
:!J" 4 4	
B():JGGG     	 	 	D	 :

sA    
&&A   
AA7B- B 
B*)B*-
B:9B:N)F) rO   typingr   r   r   r   r   r   objectsr
   r   r   refsr   r   r   r   strbytesr   r   r$   r   boolr6   r=   r?   rD   	ExceptionrF   rU   rC   rP   r   r   <module>rd      s  *   H H H H H H H H H H H H H H H H ..........((((((((5e$     v %s
*; 	    V eE3J&7 F    *67 %U
BS X]    8 % %34%34%?DS%Z?P% % !&huox&L M% % % %X 	 3434 tE{*+ 	   2  &3V 3%U
2C 3QYHZ 3 3 3 3     y   ( ( (v 5e+<       r   