
    q&f9                        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y)/z6command to display statistics about repository history    N)_)open)cmdutilencoding
logcmdutilpatchpycompat	registrarscmutils   ships-with-hg-corec                 ~   d\  }}dj                  t        j                  ||j                         |j                         |            }d}|j	                  d      D ]\  }	|r|	j                  d      r|dz  }|r|	j                  d      r|dz  }5|	j                  d      rd	}I|	j                  d
      s[d}^ ||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88EJJtTYY[$))+vFGDFZZ all4(QJET*qLG\\$F\\$F 7r   c           	      >   
 j                  d      rfd
nAj                  d      xs j                  d      t        j                          fd
 j                  t	        d      t	        d      t                    i 
 fd	}t        j                  |t        j                        d
   d   d   d         }t        j                  |      \  }}t        j                  |||      D ]  }	 j                          S )zCalculate stats
dateformatc                    | j                         \  }}t        j                  t        j                  t	        |      |z
        d d  }t        j                  |j                  t        j                  d                     S )N   r&   )	datedatetimetimegmtimefloatr   
strtolocalstrftimestrfromlocal)ctxttzr)   optss       r#   getkeyzcountrate.<locals>.getkey9   si    HHJEAr$$dkk%(R-&@!&DED&&h33D4FGH r   oldtemplatetemplatec                 f    j                          j                  |        j                         S N)
pushbuffershow	popbuffer)r1   tmplr   s    r#   r5   zcountrate.<locals>.getkeyD   s#    MMOIIcN<<>!r   s	   analyzings	   revisions)unittotalc                    | j                         } 
|       j                         }	j                  ||      }j                  d      rj                  |d      d   dz   df|<   n| j                         }t	        |      dkD  rj                  t        d      |fz         y |d   }t        || |      }t        j                  |d      |      D cg c]
  \  }}||z    c}}|<   j                          y c c}}w )N
changesets)r   r   r   s$   revision %d is a merge, ignoring...
r   )
revstripgetparentslennoter   r$   zip	increment)r1   r   rB   keyrE   r   linesrr"   amapr5   r4   progressrater   r   s            r#   prepzcountrate.<locals>.prepN   s    ggiSk!hhsC 88L!#t,Q/!3Q7DIkkmG7|aBCsfLM1:D T4f=E+.txxV/De+LM41aQMDI Ns   D rB   r)   includeexclude)patsr4   revspecr)   include_patsexclude_pats)rD   r   maketemplatermakeprogressr   rF   walkoptsr	   byteskwargs
makewalkerr   walkchangerevscomplete)r   r   rM   rS   r4   rP   woptsrevsmakefilematcherr1   r5   rN   rO   r=   s   ``` `     @@@@r#   	countratera   5   s   xx	 xx&>$((:*>''D$7	"
 	,aoSY  H D $ !!$'U&\)_)_E '11$>D/%%dD/4H  Kr   s   churn   rs   revs/   count rate for the specified revision or revsets   REVr   s   dater   s+   count rate for revisions matching date specs   DATE   ts   oldtemplates)   template to group changesets (DEPRECATED)s   TEMPLATE   Ts   templates   {author|email}s   template to group changesets   fs
   dateformats/   strftime-compatible format for grouping by dates   FORMAT   cs
   changesetsFs"   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 }|j                  d      }|s?t        j                  j                  |j	                  d            r|j	                  d      }|rRt        |d      D ]C  }	 |j                  d|v xr dxs dd      \  }}|j                         ||j                         <   E t        t         ||g|i |j                               }	|	sy|j                  d	      r|	j                          n|	j                  d
        t        t!        d |	D                    xs dt!        d |	D               j#                         }
 j%                  d|
z         |
z
  dz
  dz
  dz
  |j                  d      rdz   fd}ndz  fd}fd|	D ]  \  }} j'                   |||              y# t        $ r3 |j                         }|r j                  t        d      |z         Y w xY w)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033444r   aliasess   .hgchurns   rb   =Nr   s   skipping malformed alias: %s
sortc                 $    t        | d          | fS )Nr   sum)xs    r#   <lambda>zchurn.<locals>.<lambda>   s    #ad)Q r   )rJ   c              3   8   K   | ]  \  }}t        |        y wr9   rt   .0kvs      r#   	<genexpr>zchurn.<locals>.<genexpr>   s     1DAqQ1   g      ?c              3   8   K   | ]  \  }}t        |        y wr9   )rF   ry   s      r#   r}   zchurn.<locals>.<genexpr>   s     *TQ#a&*r~   s   assuming %i character terminal
   diffstat   c           
          |\  }}d |       d||fz  j                  d |      z  d      j                  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maxnamero   r   s       r#   formatzchurn.<locals>.format   sf    %NE7$D'"eW--.0DE 002EF	(  r   r(   c           	      X    d |       t        |      d t        |            z  fz  S )Ns
   %s %6d %s
   *rt   )r   countr   r   ro   s     r#   r   zchurn.<locals>.format   s7    !D'"E
ws5z**%  r   c                 &    t        | z  z        S r9   )int)r   maxcountwidths    r#   r   zchurn.<locals>.charnum  s    55=H,--r   )rD   ospathexistswjoinr   rsplitrC   
ValueErrorwarnr   listra   itemsrr   r-   max	termwidthdebugwrite)r   r   rS   r4   rM   rp   r"   aliasactualrO   ttywidthr   r   r   r   r   r   ro   r   s   `             @@@@@r#   churnr   q   s   p5 Dhhy!Grww~~djj&=>**[)gu% 	A !);t)CtQ Gv&,llnU[[]#	 	"dD84848>>@ADxx				/	0 S1D1129cH*T**G||~HHH08;<w"Q&*Exx
	 	 	
	.  &e
e$%&a  GGIGGA?@1DE	s   0A G		8HH)__doc__r*   r   r+   mercurial.i18nr   mercurial.pycompatr   	mercurialr   r   r   r   r	   r
   r   cmdtablecommand
testedwithr$   ra   rY   CATEGORY_MAINTENANCEr    r   r#   <module>r      s   =  	   #   
)

H
%
 #
 9x 	 @AfI	
 <=gJ	
 :;kN	
 -.kN	
 @AiL	
 
}eQ'L%MN	wq!HIJ	k5!$M"NO	j#q!;<ajIO(R S)T <=--]/`e&a/`e&r   