
    	^cR                     d   d 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j        e          ZdZd Z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        z    ed+          ej        d,-          d.             ZdS )/z6command to display statistics about repository history    N)_)open)cmdutilencoding
logcmdutilpatchpycompat	registrarscmutils   ships-with-hg-corec                    d\  }}d                     t          j        ||                                |                                |                    }d}|                    d          D ]k}	|r|	                    d          r|dz  }|r|	                    d          r|dz  }<|	                    d          rd	}T|	                    d
          rd}l||fS )Nr   r       F   
   +      -   @T   d)joinr   diffnodesplit
startswith)
uirepoctx1ctx2fmatchaddedremovedr   inhunkls
             -/usr/lib/python3/dist-packages/hgext/churn.pychangedlinesr$   %   s    NE788EJtTYY[[$))++vFFGGDFZZ   	all4(( 	QJEE 	T** 	qLGG\\$ 	FF\\$ 	F7r   c           	         
 t          j                                      d          rfd
nF                    d          p                    d          t          j                    fd
                     t          d          t          d          t                              i 
 fd	}t          j        |d
         d         d         d                   }t          j	        |          \  }}t          j        |||          D ]}	                                 S )zCalculate stats
   dateformatc                     |                                  \  }}t          j        t          j        t	          |          |z
            d d          }t          j        |                    t          j        d                                       S )N   r&   )	datedatetimetimegmtimefloatr   
strtolocalstrftimestrfromlocal)ctxttzr)   optss       r#   getkeyzcountrate.<locals>.getkey:   sr    HHJJEAr$dk%((R-&@&@!&DED&h3D4GHHII  r      oldtemplate   templatec                 ~                                                          |                                            S N)
pushbuffershow	popbuffer)r1   tmplr   s    r#   r5   zcountrate.<locals>.getkeyE   s-    MMOOOIIcNNN<<>>!r   s	   analyzings	   revisions)unittotalc                 h   |                                  } |                                           }                    ||          }	                    d          r%                    |d          d         dz   df|<   n|                                 }t	          |          dk    r(                    t          d          |fz             d S |d         }t          || |          }d t                              |d          |          D             |<   
	                                 d S )N
   changesets)r   r   r   s$   revision %d is a merge, ignoring...
c                     g | ]
\  }}||z   S  rC   ).0rr"   s      r#   
<listcomp>z+countrate.<locals>.prep.<locals>.<listcomp>]   s     MMM41aQMMMr   r   )
revstripgetparentslennoter   r$   zip	increment)r1   r   rG   keyrJ   r   linesamapr5   r4   progressrater   r   s          r#   prepzcountrate.<locals>.prepO   s#   ggiifSkk!!hhsC  88M"" 
	N#t,,Q/!3Q7DIIkkmmG7||aBCCsfLMMM1:D T4f==EMM3txxV/D/De+L+LMMMDIr      rev   dates   includes   exclude)patsr4   revspecr)   include_patsexclude_pats)r	   byteskwargsrI   r   maketemplatermakeprogressr   rK   walkopts
makewalkerr   walkchangerevscomplete)r   r   rQ   rW   r4   rT   woptsrevsmakefilematcherr1   r5   rR   rS   r=   s   ``` `     @@@@r#   	countratere   5   s   %%Dxx "	 	 	 	 	 	 xx''@488K+@+@'D$77	" 	" 	" 	" 	" 	"
 	,aooSYY   H D          $ V']*%*%  E '1$>>D/%dD/4HH  Kr   s   churn   rrU   s/   count rate for the specified revision or revsets   REVr   rV   r   s+   count rate for revisions matching date specs   DATE   tr6   s)   template to group changesets (DEPRECATED)s   TEMPLATE   Tr7   s   {author|email}s   template to group changesets   fr&   s/   strftime-compatible format for grouping by dates   FORMAT   crA   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)helpcategory	inferrepoc                     d i }|                     d          }|sGt          j                            |                    d                    r|                    d          }|rt          |d          D ]}	 |                    d|v rdpdd          \  }}|                                ||                                <   L# t          $ r> |                                }|r% 	                    t          d          |z             Y w xY wt          t           ||g|R i |                                          }	|	sdS |                     d	          r|	                                 n|	                    d
            t          t!          d |	D                                 pdt!          d |	D                                                        }
                     d|
z             |
z
  dz
  dz
  dz
  |                     d          rdz   fd}ndz  fd}fd|	D ]$\  }}                      |||                     %d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                 <    | d|t          j        |           z
  z  z   S )N    )r   colwidth)sr"   s     r#   padzchurn.<locals>.pad   s"    41x0333444r   aliasess   .hgchurns   rb   =Nr   s   skipping malformed alias: %s
sortc                 2    t          | d                    | fS )Nr   sum)xs    r#   <lambda>zchurn.<locals>.<lambda>   s    #ad))Q r   )rO   c              3   :   K   | ]\  }}t          |          V  d S r9   rx   rD   kvs      r#   	<genexpr>zchurn.<locals>.<genexpr>   s,      11DAqQ111111r   g      ?c              3   :   K   | ]\  }}t          |          V  d S r9   )rK   r}   s      r#   r   zchurn.<locals>.<genexpr>   s,      **TQ#a&&******r   s   assuming %i character terminal
   diffstat   c           
          |\  }}d |           d||fz                       d |          z  d                               d |          z  d          fz  S )Ns   %s %15s %s%s
s   +%d/-%dr   s   diffstat.insertedr   s   diffstat.deleted)label)namer   r   r    charnummaxnamers   r   s       r#   formatzchurn.<locals>.format   sz    %NE7$D'""eW--.0DEE 0 002EFF	(  r   r(   c           	      t    d |           t          |          d t          |                    z  fz  S )Ns
   %s %6d %s
   *rx   )r   countr   r   rs   s     r#   r   zchurn.<locals>.format   sE    !D'""E

wws5zz***%  r   c                 .    t          | z  z            S r9   )int)r   maxcountwidths    r#   r   zchurn.<locals>.charnum  s    55=H,---r   )rI   ospathexistswjoinr   rsplitrH   
ValueErrorwarnr   listre   itemsrv   r-   max	termwidthdebugwrite)r   r   rW   r4   rQ   rt   r"   aliasactualrS   ttywidthr   r   r   r   r   r   rs   r   s   `             @@@@@r#   churnr   r   s   p5 5 5 Dhhy!!G *rw~~djj&=&=>> ***[)) 	gu%% 	 	A !);t)CtQ G Gv&,llnnU[[]]##   GGII FGGA?@@1DEEE	 	"dD84888488>>@@AAD xx 1				//	000 S11D11111229cH**T*****G||~~HHH08;<<<w"Q&*Exx
 	 	 	 	 	 	 	 	 	 	
	 	 	 	 	 	 	. . . . . .  & &e
e$$%%%%& &s   ?ACADD)__doc__r*   r   r+   mercurial.i18nr   mercurial.pycompatr   	mercurialr   r   r   r   r	   r
   r   cmdtablecommand
testedwithr$   re   r^   CATEGORY_MAINTENANCEr   rC   r   r#   <module>r      s   = <  				        # # # # # #                  
)
H
%
%
 #
   : : :z 	 A@AAAfII	
 A<==AgJJ	
 A:;;AkNN	
 A-..AkNN	
 A@AAAiLL	
 
}eQQ'L%M%MN	wqq!HIIJ	k5!!$M"N"NO	j#qq!;<<aajjIO(R S)T A<==-]/ / /`e& e&a/ /`e& e& e&r   