
    X              	           S r SSKJrJrJr  S rS rS rS rSS jr	 SS\\
\\
   \\\
\
4      4   S	\4S
 jjrS rS r " S S\5      rS rS rg)zObject specification.    )UnionListTuplec                 D    [        U SS 5      b  U R                  S5      n U $ )Nencodeascii)getattrr   )texts    %lib/third_party/dulwich/objectspec.pyto_bytesr      s$    tXt$0{{7#K    c                      [        U5      nX   $ )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                 `    [        U5      nX   nUR                  S:X  a  XR                     $ U$ )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   .   s2     wGA{{iFF|Hr   c                     [        U5      nUSU-   SU-   SU-   SU-   SU-   S-   /nU H  nX0;   d  M
  Us  $    [        U5      e)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   ?   si     wG7 7"7"X-M J  7
r   c                    [        U5      nUR                  S5      (       a  SnUSS nSU;   a  UR                  S5      u  pEOU=pEUS:X  a  SnO[        X5      nUS:X  a  SnO [        X5      nXEU4$ ! [         a    SU;  a  SU-   n Nf = f)	zParse 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	Sy|(	Sy	)<,B
 E?	  	)2~#b(	)s   $A3 3B
Brefspecsr)   c           
      ~    [        U[        5      (       d  U/n/ nU H  nUR                  [        XXSS95        M     U$ )a4  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

>,gST Jr   c                     [        U[        5      (       d  U/n/ nU H  nUR                  [        X5      5        M     U$ )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                 B    [        U5      n[        [        X5      /5      $ )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d0122r   c                       \ rS rSrSrS rSrg)AmbiguousShortId   zThe short id is ambiguous.c                     Xl         X l        g )N)prefixoptions)selfr?   r@   s      r   __init__AmbiguousShortId.__init__   s    r   )r@   r?   N)__name__
__module____qualname____firstlineno____doc__rB   __static_attributes__ r   r   r<   r<      s
    $r   r<   c                     / nU  H.  nUR                  U5      (       d  M  UR                  X   5        M0     U(       d  [        U5      e[        U5      S:X  a  US   $ [	        X5      e)z$Scan an object store for a short id.r"   r   )r%   r1   r   lenr<   )object_storer?   r2   	object_ids       r   scan_for_short_idrO      sb     C!	''JJ|./ " v
3x1}1v
6
''r   c                 Z   [        U5      n X   $ ! [         a     Of = f U [        X5         $ ! [         a     Of = f[        U5      S:  aS  [        U5      S:  aD   [	        US5         [        U R                  U5      $ ! [         a     Of = f! [         a     Of = f[        U5      e)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   rL   intrO   rM   
ValueError)r   
committishs     r   r8   r8      s     *%J Id/00 
:!J" 4	
B():):JGG   		 :
s<    
0 
==B ,B 
BB
BBN)F)rH   typingr   r   r   r   r   r   r   r,   bytesboolr3   r5   r:   	Exceptionr<   rO   r8   rJ   r   r   <module>r[      s   *  % %"2 L tE{Due|1D,EEF 0&3 y (r   