a
    %0_                     @   sV  d Z ddlmZmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZ i ZeeZdZdd	 Zd
d Zedddg ededfdddededfdddededfdddededfddded ed!fd"d#d$ed%fd&d'd$ed(fdd)d$ed*fdd+ded,ed-fg	ej ed.ejd/d0d1d2 ZdS )3z6command to display statistics about repository history    )absolute_importdivisionN)_)open)cmdutilencoding
logcmdutilpatchpycompat	registrarscmutils   ships-with-hg-corec           	      C   sx   d\}}d t|| | |}|dD ]>}|drR|dsR|d7 }q0|dr0|ds0|d7 }q0||fS )	Nr   r          
   +s   +++       -s   --- )joinr	   diffZnodesplit
startswith)	uirepoctx1Zctx2fmatchaddedremovedr   l r   -/usr/lib/python3/dist-packages/hgext/churn.pychangedlines&   s    

r    c           
         s   t dr"fddn0dp4dtfddjtdtdtd	i  fd
d}tj|d d d d d}t	|\}}t
|||D ]}	qqЈ  S )zCalculate stats
   dateformatc                    sF   |   \}}tjtt|| d d  }t|t d S )N   r!   )	datedatetimetimegmtimefloatr   Z
strtolocalstrftimeZstrfromlocal)ctxtZtzr#   )optsr   r   getkey6   s
     zcountrate.<locals>.getkey   oldtemplate   templatec                    s       |   S N)Z
pushbufferZshowZ	popbuffer)r)   )tmplr   r   r   r,   A   s    
s	   analyzings	   revisions)Zunittotalc                    s   |   }|  } ||}drH|dd d df|< nd|  }t|dkrttd|f  d S |d }t|| |}dd t|d|D |< 	  d S )	N
   changesets)r   r   r   s$   revision %d is a merge, ignoring...
c                 S   s   g | ]\}}|| qS r   r   ).0rr   r   r   r   
<listcomp>Y   r   z+countrate.<locals>.prep.<locals>.<listcomp>r   )
revstripgetparentslenZnoter   r    zipZ	increment)r)   r   r6   keyr9   r   lines)amapr,   r+   progressrater   r   r   r   prepK   s    
 zcountrate.<locals>.prep   rev   dates   includes   exclude)patsr+   Zrevspecr#   Zinclude_patsZexclude_pats)r
   Zbyteskwargsr8   r   ZmaketemplaterZmakeprogressr   r:   walkoptsZ
makewalkerr   ZwalkchangerevsZcomplete)
r   r   r>   rD   r+   rA   ZwoptsZrevsZmakefilematcherr)   r   )r>   r,   r+   r?   r@   r   r0   r   r   	countrate1   s0    

rF   s   churn   rrB   s/   count rate for the specified revision or revsets   REV   drC   r   s+   count rate for revisions matching date specs   DATE   tr-   s)   template to group changesets (DEPRECATED)s   TEMPLATE   Tr.   s   {author|email}s   template to group changesets   fr!   s/   strftime-compatible format for grouping by dates   FORMAT   cr2   Fs"   count rate by number of changesets   ss   sorts$   sort by key (default: sort by count)s   diffstats&   display added/removed lines separatelys   aliasess   file with email aliasess   FILEs3   hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]T)ZhelpcategoryZ	inferrepoc              	      s  dd i }| d}|s6tj|dr6|d}|rt|dD ]j}z0|d|v rZdp\dd\}}| || < W qD ty   | }|r	t
d	|  Y qDY qD0 qDtt||g|R i | }	|	sdS | d
r|	  n|	jdd d ttdd |	D pdtdd |	D  }
d|
  |
 d d d | dr~d8  fdd}nd8  fdd}fdd |	D ]\}}||| qdS )a  histogram of changes to the repository

    This command will display a histogram representing the number
    of changed lines or revisions, grouped according to the given
    template. The default template will group changes by author.
    The --dateformat option may be used to group the results by
    date instead.

    Statistics are based on the number of changed lines, or
    alternatively the number of matching revisions if the
    --changesets option is specified.

    Examples::

      # display count of changed lines for every committer
      hg churn -T "{author|email}"

      # display daily activity graph
      hg churn -f "%H" -s -c

      # display activity of developers by month
      hg churn -f "%Y-%m" -s -c

      # display count of lines changed in every year
      hg churn -f "%Y" -s

      # display count of lines changed in a time range
      hg churn -d "2020-04 to 2020-09"

    It is possible to map alternate email addresses to a main address
    by providing a file using the following format::

      <alias email> = <actual email>

    Such a file may be specified with the --aliases option, otherwise
    a .hgchurn file will be looked for in the working directory root.
    Aliases will be split from the rightmost "=".
    c                 S   s   | d|t |    S )N    )r   Zcolwidth)sr   r   r   r   pad   s    zchurn.<locals>.padaliasess   .hgchurns   rb   =Nr   s   skipping malformed alias: %s
sortc                 S   s   t | d  | fS )Nr   sum)xr   r   r   <lambda>   r   zchurn.<locals>.<lambda>)r<   c                 s   s   | ]\}}t |V  qd S r/   rT   r3   kvr   r   r   	<genexpr>   r   zchurn.<locals>.<genexpr>g      ?c                 s   s   | ]\}}t |V  qd S r/   )r:   rX   r   r   r   r[      r   s   assuming %i character terminal
   diffstat   c              	      sF   |\}}d| d||f  d | d d | df S )Ns   %s %15s %s%s
s   +%d/-%dr   s   diffstat.insertedr   s   diffstat.deleted)Zlabel)namer]   r   r   )charnummaxnamerP   r   r   r   format   s    
zchurn.<locals>.formatr"   c                    s$   d| t |d t | f S )Ns
   %s %6d %s
   *rT   )r_   count)r`   ra   rP   r   r   rb      s
    c                    s   t |    S r/   )int)rd   )maxcountwidthr   r   r`      s    zchurn.<locals>.charnum)r8   ospathexistsZwjoinr   rsplitr7   
ValueErrorwarnr   listrF   itemsrS   r'   maxZ	termwidthdebugwrite)r   r   rD   r+   r>   rQ   r   aliasZactualr@   Zttywidthrb   r_   rd   r   )r`   rf   ra   rP   r   rg   r   churnn   sD    X

"


rt   )__doc__Z
__future__r   r   r$   rh   r%   Zmercurial.i18nr   Zmercurial.pycompatr   Z	mercurialr   r   r   r	   r
   r   r   ZcmdtableZcommandZ
testedwithr    rF   rE   ZCATEGORY_MAINTENANCErt   r   r   r   r   <module>	   sp   $

=)*0