3
_Af                 @   sR   d dl mZ d dlZd dlZd dlmZ d dlmZ ejdZ	G dd deZ
dS )    )print_functionN)Command)GitErrorz'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$c               @   s4   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dS )DownloadTzDownload and checkout a changez(
%prog {[project] change[/patchset]}...
z
The '%prog' command downloads a change from the review system and
makes it available in your project's local working directory.
If no project is specified try to use current directory as a project.
c             C   s@   |j dddddd |j ddd	dd
d |j dddddd d S )Nz-cz--cherry-pick
cherrypick
store_truezcherry-pick instead of checkout)destactionhelpz-rz--revertrevertzrevert instead of checkoutz-fz	--ff-onlyffonlyzforce fast-forward merge)
add_option)selfp r   B/home/qytech/356xLinux510-101server/.repo/repo/subcmds/download.py_Options'   s    zDownload._Optionsc             C   s   |s| j   g }d }x|D ]}tj|}|r|s>| jdd }t|jd}|jdrft|jd}npd}d|d |f }|j|d }	|	r|d }
tj|
tj	}x2|	j
 D ]&}|j|}|rtt|jd|}qW |j|||f q| j|gd }qW |S )	N.r         zrefs/changes/%2.2d/%d/d   *z(\d+))Usage	CHANGE_REmatchGetProjectsintgroup	_LsRemoterecompileI
splitlinessearchmaxappend)r   argsZto_getprojectamZchg_idps_idrefsoutputregexZrcompliner   r   r   r   _ParseChangeIds2   s2    



zDownload._ParseChangeIdsc             C   sf  x^| j |D ]N\}}}|j||}|sNtd|j||f tjd tjd |j rz|j rztd|j||f tjd qt	|jdkrtd|j||t	|jf tjd x |jD ]}td| tjd qW |j
r"y|j|j W n: tk
r   td|j|jf tjd tjd Y nX q|jr8|j|j q|jrR|j|jdd	 q|j|j qW d S )
Nz[%s] change %d/%d not found)filer   z)[%s] change %d/%d has already been mergedz*[%s] %d/%d depends on %d unmerged changes:z  %sz-[%s] Could not complete the cherry-pick of %sT)r   )r/   DownloadPatchSetprintnamesysstderrexitr   commitslenr   _CherryPickcommitr   _Revertr   _FastForward	_Checkout)r   optr&   r'   	change_idr*   Zdlcr   r   r   ExecuteQ   s<    



zDownload.ExecuteN)
__name__
__module____qualname__commonhelpSummary	helpUsagehelpDescriptionr   r/   rA   r   r   r   r   r      s   r   )
__future__r   r   r4   commandr   errorr   r    r   r   r   r   r   r   <module>   s   
