o
    Uh                     @   s  d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
 er,ddlmZmZ ddlmZ deeef d	efd
dZdddeeef d	dfddZdddeeef d	dfddZded deeef d	dfddZ	d3ded ded deeef ded	eed ed ef f
d d!Z	d3ded ded d"eeee f defd#d$Zd%d& Zddd'eeef d	ed( fd)d*ZG d+d, d,eZd-d. Zddd/eeef d	d(fd0d1Z d2S )4zObject specification.    )Iterator)TYPE_CHECKINGOptionalUnion   )CommitShaFileTree)RefRefsContainer)Repotextreturnc                 C   s   t | dd d ur| d} | S )Nencodeascii)getattrr   )r    r   f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/objectspec.pyto_bytes"   s   
r   repor   	objectishr   c                 C   s   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   r   r   r   parse_object(   s   
r   treeishr	   c                 C   sJ   t |}zt| |}W n	 ty   Y n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   or   r   r   
parse_tree6   s   


r   	container)r   r   refspecr
   c                 C   sR   t |}|d| d| d| d| d| d g}|D ]
}|| v r$|  S q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refr   r   r   r   K   s   
r   Flh_containerrh_containerforcec                 C   s   t |}|drd}|dd }d|v r|d\}}n| }}|dkr(d}nt| |}|dkr4d}nzt||}W n tyL   d|vrJd| }Y n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   
startswithsplitr   r   )r$   r%   r    r&   lhrhr   r   r   parse_reftuplef   s(   


r/   refspecsc              	   C   s8   t |ts|g}g }|D ]}|t| |||d q|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appendr/   )r$   r%   r0   r&   retr    r   r   r   parse_reftuples   s   
r5   c                 C   s2   t |ts|g}g }|D ]
}|t| | q|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
    )r1   r2   r3   r   )r   r0   r4   r    r   r   r   
parse_refs   s   
r6   committishsr   c                 C   s   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   r7   r   r   r   parse_commit_range   s   r:   c                   @   s   e Zd ZdZdddZdS )AmbiguousShortIdzThe short id is ambiguous.r   Nc                 C   s   || _ || _d S )N)prefixoptions)selfr<   r=   r   r   r   __init__   s   
zAmbiguousShortId.__init__)r   N)__name__
__module____qualname____doc__r?   r   r   r   r   r;      s    r;   c                 C   sZ   g }|  |D ]}| | }t||r|| q|st|t|dkr(|d S t||)z$Scan an object store for a short id.r   r   )iter_prefixr1   r3   r   lenr;   )object_storer<   tpr4   	object_idr   r   r   r   scan_for_short_id   s   


rI   
committishc                 C   s   t |}z| | W S  ty   Y nw z| t| | W S  ty$   Y nw t|dkrZt|dk rZzt|d W n tyD   Y t|w zt| j|tW S  tyY   Y t|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   rE   int
ValueErrorrI   rF   r   )r   rJ   r   r   r   r9      s2   
r9   N)F)!rC   collections.abcr   typingr   r   r   objectsr   r   r	   refsr
   r   r   r   strbytesr   r   r   r   booltupler/   r2   r5   r6   r:   	Exceptionr;   rI   r9   r   r   r   r   <module>   sd   



.


"