
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    V&                     @   s   d dl mZ d dlZd dlmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d'ddZd	d
 Zdd Zdd Zdd Zd(ddZdd Zdd Zdd Zd)ddZdd Zd*ddZd d! Zdejjddfd"d#Zdd$e fd%d&ZdS )+    )unicode_literalsN)log)optionsFTc           	      C   s   |rt j}t j}nd }d }tj }|r2|| t j| |||d}| }|jrl|rlt	j
d| |jf t|dks|d r|d  sdS |d  ddS )N)stdoutstderrenvz%s returned %dr    utf-8replace)
subprocessPIPEosenvironcopyupdatePopencommunicate
returncode	distutilserrorsDistutilsErrorlenstripdecode)	cmdthrow_on_errorbufferr   out_locationerr_locationnewenvoutputout r"   8/opt/alt/python38/lib/python3.8/site-packages/pbr/git.py_run_shell_command!   s*    


 r$   c                 K   s,   t | ttfs| g} tdd| g|  f|S )Ngitz--git-dir=%s)
isinstancelisttupler$   )r   git_dirkwargsr"   r"   r#   _run_git_command<   s    r+   c               
   C   sP   zt dddgW S  tk
rJ }  z| jtjkr8W Y 
dS  W 5 d } ~ X Y nX d S )Nr%   z	rev-parsez	--git-dirr   )r$   OSErrorerrnoENOENT)er"   r"   r#   _get_git_directoryC   s    
r0   c                   C   s,   zt ddg W n tk
r&   Y dS X dS )Nr%   z	--versionFT)r$   r,   r"   r"   r"   r#   _git_is_installedM   s
    r1   c                 C   s   t | tjdS )zFind the highest tag from a list.

    Pass in a list of tag strings and this will return the highest
    (latest) as sorted by the pkg_resources version parser.
    )key)maxpkg_resourcesparse_version)tagsr"   r"   r#   _get_highest_tagX   s    r7   r   c                 C   sL   g }|dkrt  }|r>td tddg|}|dd}dd |D S )	zBehave like a file finder entrypoint plugin.

    We don't actually use the entrypoints system for this because it runs
    at absurd times. We only want to do this when we are building an sdist.
    Nz2[pbr] In git context, generating filelist from gitzls-filesz-z    r	   c                 S   s   g | ]}|r|qS r"   r"   ).0fr"   r"   r#   
<listcomp>p   s      z#_find_git_files.<locals>.<listcomp>)_run_git_functionsr   infor+   splitr   )dirnamer)   	file_listr"   r"   r#   _find_git_filesa   s    
rA   c                 C   s6   t ddg| }d|kr&|ddd S d|kr2dS d S )Ndescribez--always-   .r   )r+   rsplit)r)   rB   r"   r"   r#   _get_raw_tag_infos   s    rH   c                 C   s   t | dkS )Nr   )rH   r)   r"   r"   r#   get_is_release|   s    rJ   c                  C   s   d } t  rt } | pd S )N)r1   r0   rI   r"   r"   r#   r<      s    r<   c                 C   s"   | s
t  } | rtdddg| S dS )z1Return the short sha for this repo, if it exists.r   z-n1z--pretty=format:%hN)r<   r+   rI   r"   r"   r#   get_git_short_sha   s     rK   c                 c   s   d}d}|dfV  | D ]~\}}}|r\t |}t|d }|sF|dfV  |dt||d fV  |ds|d	r||dd
 }|dt|d fV  d}qdS )zConvert a oneline log iterator to formatted strings.

    :param changelog: An iterator of one line log entries like
        that given by _iter_log_oneline.
    :return: An iterator over (release, formatted changelog) tuples.
    TNzCHANGES
=======

rC   
z%(tag)s
%(underline)s

)tag	underlinezMerge rF   z
* %(msg)s
)msgF)r7   r   dict
startswithendswith)	changelog
first_linecurrent_releasehashr6   rP   rN   r"   r"   r#   _iter_changelog   s&    




rX   c                 C   s   | dkrt  } | sg S t| S )aQ  Iterate over --oneline log entries if possible.

    This parses the output into a structured form but does not apply
    presentation logic to the output - making it suitable for different
    uses.

    :return: An iterator of (hash, tags_set, 1st_line) tuples, or None if
        changelog generation is disabled / not available.
    N)r0   _iter_log_innerrI   r"   r"   r#   _iter_log_oneline   s
    
rZ   c                 c   s   t d dddg}t|| }|dD ]}| }t|dk rBq(|d drld	|krl|d	d  }nd
|dd }d|krtdd |d	d ddd D }nt }|d ||fV  q(dS )a  Iterate over --oneline log entries.

    This parses the output intro a structured form but does not apply
    presentation logic to the output - making it suitable for different
    uses.

    :return: An iterator of (hash, tags_set, 1st_line) tuples.
    z[pbr] Generating ChangeLogr   z	--onelinez
--decoraterL   rD      () Nztag:c                 S   s   g | ]}| d d qS ),r   )r>   )r9   rM   r"   r"   r#   r;      s   z#_iter_log_inner.<locals>.<listcomp>r   ztag: )	r   r=   r+   r>   r   rR   r   joinset)r)   log_cmdrT   line
line_partsrP   r6   r"   r"   r#   rY      s     	



rY   c              	   C   s   t   }|si }t|dd}|r&dS |s@t| d}|r@t|}|sHdS td tj	|d}tj
|r~t|tjs~dS tj|ddd	}|D ]\}}	||	 qW 5 Q R X t   }
td
|
|   dS )z-Write a changelog based on the git changelog.skip_changelogSKIP_WRITE_GIT_CHANGELOGNrI   z[pbr] Writing ChangeLog	ChangeLogwr	   )encodingz![pbr] ChangeLog complete (%0.1fs))timer   get_boolean_optionrZ   rX   r   r=   r   pathr`   existsaccessW_OKioopenwrite)r)   dest_diroption_dictrT   startshould_skipnew_changelogchangelog_filereleasecontentstopr"   r"   r#   write_git_changelog   s2    

r|   rF   c              
      sh  t |dd}|rdS t }tj|d}tj|d}tj|rXt|tjsXdS t	
d d | dkrtt } | rJg }dd	g}|t|| d
7 } fdd|D }td| }	td|	tj}
dd |
D }
||
7 }tt|}t|dR}tj|r&t|d}||  W 5 Q R X |d
|d
 d W 5 Q R X t }t	
d||   dS )z&Create AUTHORS file using git commits.skip_authorsSKIP_GENERATE_AUTHORSNz
AUTHORS.inAUTHORSz[pbr] Generating AUTHORSz.(jenkins@review|infra@lists|jenkins@openstack)r   z--format=%aN <%aE>rL   c                    s   g | ]}t  |s|qS r"   )research)r9   aignore_emailsr"   r#   r;     s      z$generate_authors.<locals>.<listcomp>zCo-authored-by:.+c                 S   s$   g | ]}|r| d dd  qS ):r[   )r>   r   )r9   signedr"   r"   r#   r;     s    wbrbr	   z[pbr] AUTHORS complete (%0.1fs))r   rk   rj   r   rl   r`   rm   rn   ro   r   r=   r0   r+   r>   r   findall	MULTILINEsortedra   rq   rr   readencode)r)   rs   rt   rv   ru   old_authorsnew_authorsauthorsgit_log_cmdco_authors_out
co_authorsnew_authors_fhold_authors_fhr{   r"   r   r#   generate_authors   sN    

r   )FTN)r   N)N)N) 
__future__r   distutils.errorsr   r   r-   rp   r   r   r   rj   r4   pbrr   r$   r+   r0   r1   r7   rA   rH   rJ   r<   rK   rX   rZ   rY   rl   curdirr|   rQ   r   r"   r"   r"   r#   <module>   s8   

	
	


" 
