3
_Af                 @   sH   d dl mZ d dlmZ d dlmZ G dd deZG dd deZdS )	    )Coloring)PagedCommand)XmlManifestc               @   s   e Zd Zdd ZdS )	_Coloringc             C   s   t j| |d d S )Nstatus)r   __init__)selfconfig r
   G/home/qytech/356xLinux510-101server/.repo/repo/subcmds/diffmanifests.pyr      s    z_Coloring.__init__N)__name__
__module____qualname__r   r
   r
   r
   r   r      s   r   c               @   sT   e Zd ZdZdZdZdZdZdd Zdd	 Z	dddZ
dddZdd Zdd Zd
S )Diffmanifestsa5   A command to see logs in projects represented by manifests

  This is used to see deeper differences between manifests. Where a simple
  diff would only show a diff of sha1s for example, this command will display
  the logs of the project between both sha1s, allowing user to see diff at a
  deeper level.
  TzManifest diff utilityz-%prog manifest1.xml [manifest2.xml] [options]a"  
The %prog command shows differences between project revisions of manifest1 and
manifest2. if manifest2 is not specified, current manifest.xml will be used
instead. Both absolute and relative paths may be used for manifests. Relative
paths start from project's ".repo/manifests" folder.

The --raw option Displays the diff in a way that facilitates parsing, the
project pattern will be <status> <path> <revision from> [<revision to>] and the
commit pattern will be <status> <onelined log> with status values respectively :

  A = Added project
  R = Removed project
  C = Changed project
  U = Project with unreachable revision(s) (revision(s) not found)

for project, and

   A = Added commit
   R = Removed commit

for a commit.

Only changed projects may contain commits, and commit status always starts with
a space, and are part of last printed project.
Unreachable revisions may occur if project is not up to date or if repo has not
been initialized with all the groups, in which case some projects won't be
synced and their revisions won't be found.

c             C   s>   |j ddddd |j dddd	d
d |j dddddd d S )Nz--rawraw
store_truezDisplay raw diff.)destactionhelpz
--no-colorcolorstore_falseTz#does not display the diff in color.)r   r   defaultr   z--pretty-formatpretty_formatstorez<FORMAT>z5print the log using a custom git pretty format string)r   r   metavarr   )
add_option)r   pr
   r
   r   _OptionsF   s    zDiffmanifests._Optionsc             C   s   x0|d D ]$}| j d|j|jf  | jj  q
W x0|d D ]$}| j d|j|jf  | jj  q<W xJ|d D ]>\}}| j d|j|j|jf  | jj  | j||ddd	 qnW x8|d
 D ],\}}| j d|j|j|jf  | jj  qW d S )NaddedzA %s %sremovedzR %s %schangedz
C %s %s %sTF)r   r   unreachablez
U %s %s %s)	printTextrelpathrevisionExproutnl
_printLogs)r   diffprojectotherProjectr
   r
   r   _printRawDiffR   s    
zDiffmanifests._printRawDiffNc             C   s  |d rh| j j  | jd | j j  x@|d D ]4}| jd|j  | jd | j|j | j j  q0W |d r| j j  | jd | j j  x@|d D ]4}| jd|j  | jd | j|j | j j  qW |d rt| j j  | jd | j j  xz|d D ]n\}}| jd|j  | jd	 | j|j | jd
 | j|j | j j  | j||d||d | j j  qW |d r| j j  | jd | j j  x\|d D ]P\}}| jd|j  | j|j | jd | j|j | jd | j j  qW d S )Nr   zadded projects : 
z	%sz at revision r   zremoved projects : 
r    zchanged projects : 
z changed from z to F)r   r   r   r!   z'projects with unreachable revisions : 
z	%s z or z
 not found)r%   r&   r"   printProjectr#   printRevisionr$   r'   )r   r(   r   r   r)   r*   r
   r
   r   
_printDifff   sV    




















zDiffmanifests._printDiffFc       
      C   s   |j ||d k||d}|d r~|d jd}xP|D ]H}|j r2|r\| jd|  | jj  q2| jd | j| | jj  q2W |d r|d jd}	xP|	D ]H}|j r|r| jd|  | jj  q| jd | j| | jj  qW d S )	N)oneliner   r   r   
z R z		[-] r   z A z		[+] )getAddedAndRemovedLogssplitstripr"   r%   r&   printRemoved
printAdded)
r   r)   r*   r   r   r   logsZremovedLogslogZ	addedLogsr
   r
   r   r'      s0    





zDiffmanifests._printLogsc             C   s"   | st |dkr| jjd d S )N   zmissing manifests to diff)lenOptionParsererror)r   optargsr
   r
   r   ValidateOptions   s    zDiffmanifests.ValidateOptionsc             C   s  t | jj| _| jjd| _|jrp| jjddd| _| jjdddd| _| jjdddd| _	| jjdd	d
| _
n| j | _ | _ | _	| _
t| jj}|j|d dd t|dkr| j}nt| jj}|j|d dd |j|}|jr| j| n| j||j|jd d S )Ntextr)   bold)attrgreen)fgrA   redrevisionyellow)rC   r   F)load_local_manifests   )r   r   )r   manifestglobalConfigr%   nofmt_printerr"   r   r,   r5   r4   r-   r   repodirOverrider9   projectsDiffr   r+   r.   r   )r   r<   r=   Z	manifest1Z	manifest2r(   r
   r
   r   Execute   s$    
zDiffmanifests.Execute)TN)FTN)r   r   r   __doc__commonhelpSummary	helpUsagehelpDescriptionr   r+   r.   r'   r>   rO   r
   r
   r
   r   r      s   
0 
r   N)r   r   commandr   manifest_xmlr   r   r   r
   r
   r
   r   <module>   s   