
    X              	           d Z ddlmZmZmZ d Zd Zd Zd ZddZ		 ddee
ee
   eee
e
f      f   d	efd
Zd Zd Z G d de      Zd Zd Zy)zObject specification.    )UnionListTuplec                 B    t        | dd       | j                  d      } | S )Nencodeascii)getattrr   )texts    %lib/third_party/dulwich/objectspec.pyto_bytesr      s$    tXt$0{{7#K    c                 "    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   )repo	objectishs     r   parse_objectr       s     #I	?r   c                 b    t        |      }| |   }|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   	type_nametree)r   treeishos      r   
parse_treer   .   s6     wGWA{{iAFF|Hr   c                     t        |      }|d|z   d|z   d|z   d|z   d|z   dz   g}|D ]
  }|| v s|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   KeyError)	containerrefspecpossible_refsrefs       r   	parse_refr   ?   sk     wG7 7"7"X-M )J  7
r   c                    t        |      }|j                  d      rd}|dd }d|v r|j                  d      \  }}n|x}}|dk(  rd}nt        | |      }|dk(  rd}n	 t        ||      }|||fS # t        $ r d|vrd|z   }Y w xY w)	a  Parse a reftuple spec.

    Args:
      lh_container: A RefsContainer object
      hh_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
       +T   N   :r      /r   )r   
startswithsplitr   r   )lh_containerrh_containerr   forcelhrhs         r   parse_reftupler,   X   s     wG$!"+w==&RR	Sy|R(	Sy	)<,B
 E?	  	)2~#b(	)s   A/ /BBrefspecsr)   c           	      z    t        |t              s|g}g }|D ]   }|j                  t        | |||             " |S )aX  Parse a list of reftuple specs to a list of reftuples.

    Args:
      lh_container: A RefsContainer object
      hh_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(   r-   r)   retr   s         r   parse_reftuplesr3   {   s@     h%:
C

>,gUST Jr   c                 t    t        |t              s|g}g }|D ]  }|j                  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
    )r/   r0   r1   r   )r   r-   r2   r   s       r   
parse_refsr5      s<     h%:
C

9Y01 Jr   c                 D    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   committishss     r   parse_commit_ranger:      s#     ;'KdK0122r   c                       e Zd ZdZd Zy)AmbiguousShortIdzThe short id is ambiguous.c                      || _         || _        y )N)prefixoptions)selfr>   r?   s      r   __init__zAmbiguousShortId.__init__   s    r   N)__name__
__module____qualname____doc__rA    r   r   r<   r<      s
    $r   r<   c                     g }| D ](  }|j                  |      s|j                  | |          * |st        |      t        |      dk(  r|d   S t	        ||      )z$Scan an object store for a short id.r"   r   )r%   r1   r   lenr<   )object_storer>   r2   	object_ids       r   scan_for_short_idrK      sc     C!	'JJ|I./ " v
3x1}1v
63
''r   c                 z   t        |      }	 | |   S # t        $ r Y nw xY w	 | t        | |         S # t        $ r Y nw xY wt        |      dk\  rdt        |      dk  rV	 t	        |d       	 t        | j                  |      S # t        $ r Y t        |      w xY w# t        $ r Y t        |      w xY wt        |      )a&  Parse a string referring to a single commit.

    Args:
      repo: A` Repo` object
      commitish: 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   rH   intrK   rI   
ValueError)r   
committishs     r   r8   r8      s     *%JJ IdJ/00 
:!J" 4	
B():):JGG 
:
  	 :
	 :
s<    	1 	==B *B   	BB	B/.B/N)F)rE   typingr   r   r   r   r   r   r   r,   bytesboolr3   r5   r:   	Exceptionr<   rK   r8   rF   r   r   <module>rW      s   *  % %"2 L tE{Due|1D,EEF 0&3 y (r   