
    6hV                    B   S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJr  SSKJrJr  0 r\R*                  " \5      r SSKr\R.                  " 5          \R0                  " SS	\S
S9  SSKJr  \R8                    SSS5        SrS\" S5      4S\" S5      4S\" S5      4S\" S5      4S\" S5      4/r\R@                  " S\RB                  5      r"Sr#\" S5      r$ " S S5      r% " S S5      r&S r'S r(S  r)S! r*S" r+S# r,S$ r-S% r.S& r/S' r0S( r1S) r2\" S*S+S,S-\" S.5      \" S/5      4S0S1S2\" S35      \" S/5      4S4S5S2\" S65      S4/\" S75      \Rf                  S89S>S9 j5       r4\" S:S;S<9S>S= j5       r5g! , (       d  f       GN = f! \ a    Sr GNf = f)?a/  generate release notes from commit messages (EXPERIMENTAL)

It is common to maintain files detailing changes in a project between
releases. Maintaining these files can be difficult and time consuming.
The :hg:`releasenotes` command provided by this extension makes the
process simpler by automating it.
    )annotationsN)_)hex)cmdutilconfigerror
logcmdutilminirst	registrarutil)procutil
stringutilignorez.*python-Levenshtein.*zfuzzywuzzy.fuzz)actionmessagecategorymodules   ships-with-hg-cores   features   New Featuress   bcs   Backwards Compatibility Changes   fixs	   Bug Fixess   perfs   Performance Improvementss   apis   API Changess#   ^\.\. ([a-zA-Z0-9_]+)::\s*([^$]+)?$s   \bissue ?[0-9]{4,6}(?![0-9])\bs   Other Changesc                  J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)parsedreleasenotesN   c                    0 U l         g Nsectionsselfs    4/usr/lib/python3/dist-packages/hgext/releasenotes.py__init__parsedreleasenotes.__init__O   s	        c                    XR                   ;   $ r   r   r   sections     r   __contains__parsedreleasenotes.__contains__R   s    --''r!   c                >    [        [        U R                  5      5      $ r   )itersortedr   r   s    r   __iter__parsedreleasenotes.__iter__U   s    F4==)**r!   c                    U R                   R                  U/ / 45        U R                   U   S   R                  X#45        g)z Add a titled release note entry.r   Nr   
setdefaultappend)r   r$   title
paragraphss       r   addtitleditem parsedreleasenotes.addtitleditemX   s9      2r(3gq!((%)<=r!   c                    U R                   R                  U/ / 45        U R                   U   S   R                  U5        g)zKAdds a non-titled release note entry.

Will be rendered as a bullet point.
   Nr-   )r   r$   r1   s      r   addnontitleditem#parsedreleasenotes.addnontitleditem]   s8    
 	  2r(3gq!((4r!   c                D    U R                   R                  U/ / 45      S   $ )zlReturns titled entries in a section.

Returns a list of (title, paragraphs) tuples describing sub-sections.
r   r   getr#   s     r   titledforsection#parsedreleasenotes.titledforsectione   s$    
 }}  2r(3A66r!   c                D    U R                   R                  U/ / 45      S   $ )z5Returns non-titled, bulleted paragraphs in a section.r5   r9   r#   s     r   nontitledforsection&parsedreleasenotes.nontitledforsectionl   s"    }}  2r(3A66r!   c                L   ^ [        U4S jU R                  U5       5       5      $ )Nc              3  2   >#    U  H  oS    T:H  v   M     g7f)r   N ).0tr0   s     r   	<genexpr>8parsedreleasenotes.hastitledinsection.<locals>.<genexpr>q   s     I*HQQ45=*Hs   )anyr;   )r   r$   r0   s     `r   hastitledinsection%parsedreleasenotes.hastitledinsectionp   s    I$*?*?*HIIIr!   c                F   [         (       d  UR                  [        S5      5        U GHu  n[        U R	                  U5      5      [        U R                  U5      5      -   nUR	                  U5       H  u  pVU R                  X55      (       a   UR                  [        S5      XS4-  5        M;  [        XV4/5      S   nUS:X  a%  [        U5      nU(       a  [        XU5      (       a  Mv  [        XU5      (       a  M  U R                  X5U5        M     UR                  U5       Hw  nX`R                  U5      ;   a  M  [        U/5      S   nUS:X  a%  [        U5      nU(       a  [        XU5      (       a  MS  [        XU5      (       a  Mf  U R                  X65        My     GMx     g)zkMerge another instance into this one.

This is used to combine multiple sources of release notes together.
sK   module 'fuzzywuzzy' not found, merging of similar releasenotes is disabled
s*   %s already exists in %s section; ignoring
r   r   N)fuzzwarnr   converttitledr;   convertnontitledr>   rH   writegetissuenum	findissuesimilarr2   r6   )	r   uiotherr$   existingnotesr0   r1   incoming_strissues	            r   mergeparsedreleasenotes.merges   s   
 tGG2 G)%%g. !9!9'!BCDM &+%;%;G%D!**7:: HHHI *+ ,u.A-BCAFf$'5E$R>>$2l;;""7:>) &E, $77@
!9!9'!BB/=a@f$'5E$R>>$2l;;%%g: A5 r!   r   N)__name__
__module____qualname____firstlineno__r   r%   r*   r2   r6   r;   r>   rH   rX   __static_attributes__rB   r!   r   r   r   N   s0    (+>
577J5;r!   r   c                  0    \ rS rSrSS jrS rS rS rSrg)	releasenotessections   Nc                    U(       a\  [         R                  " [        5      n[        U5      nU(       a  UR	                  U5        [        UR                  5       5      U l        g [        [        5      U l        g r   )r   sortdictDEFAULT_SECTIONSgetcustomadmonitionsupdatelistitems	_sections)r   rS   repor   custom_sectionss        r   r   releasenotessections.__init__   sM    }}%56H248O0!(.."23DN!"23DNr!   c                ,    [        U R                  5      $ r   )r(   ri   r   s    r   r*   releasenotessections.__iter__   s    DNN##r!   c                J    U R                    Vs/ s H  oS   PM	     sn$ s  snf )Nr   ri   )r   rD   s     r   namesreleasenotessections.names   s     "nn-n!n---s    c                @    U R                    H  u  p#X1:X  d  M  Us  $    g r   rp   )r   r0   namevalues       r   sectionfromtitle%releasenotessections.sectionfromtitle   s!    >>KD~ * r!   rp   r   )	rZ   r[   r\   r]   r   r*   rq   rv   r^   rB   r!   r   r`   r`      s    4$.r!   r`   c                    / nU  HA  u  p#/ nU H  nUR                  U5        M     UR                  SR                  U5      5        MC     U$ )z&
Convert titled paragraphs to strings
    extendr/   join)titledparagraphsstring_listr0   r1   linesparas         r   rM   rM      sP     K-DLL 499U+,	 .
 r!   c                    / nU  H?  n/ nU H  nUR                  U5        M     UR                  SR                  U5      5        MA     U$ )z'
Convert non-titled bullets to strings
ry   rz   )nontitledparagraphsr~   r1   r   r   s        r   rN   rN      sM     K)
DLL 499U+,	 *
 r!   c                    [         R                  " [        U [         R                  5      nU(       a  UR	                  5       nU$ )z<
Returns issue number from the incoming string if it exists
)researchRE_ISSUE
IGNORECASEgroup)rV   rW   s     r   rP   rP      s-     IIhbmm<ELr!   c                v   ^ [        U4S jU 5       5      (       a  U R                  [        S5      T-  5        gg)z7
Returns true if issue number already exists in notes.
c              3  .   >#    U  H
  nTU;   v   M     g 7fr   rB   )rC   srW   s     r   rE   findissue.<locals>.<genexpr>   s     
(x!5A:xs   s'   "%s" already exists in notes; ignoring
TF)rG   rO   r   )rS   existingrW   s     `r   rQ   rQ      s3     
(x
(((
>?%GHr!   c                    [        UR                  5       5      S:  a1  [        X!5      nU(       d  U R                  [	        S5      U-  5        ggg)z7
Returns true if similar note found in existing notes.

   s,   "%s" already exists in notes file; ignoring
TF)lensplitsimilaritycheckrO   r   )rS   r   rV   rX   s       r   rR   rR      sO     < 2%7HHBC r!   c                v    [         (       d  gSnU H$  n[         R                  " X5      nUS:  d  M!  Sn  U$    U$ )zC
Returns false when note fragment can be merged to existing notes.
TK   F)rK   token_set_ratio)rV   rU   rX   bulletscores        r   r   r     sF    
 4E$$\:2:EL  
 Lr!   c                   ^ ^^^ T S   m[         R                   " 5       mSUUUU 4S jjmST;   a  T" S5        TR                  S5      $ )N   .c                   > U T;   a'  TU    R                  5       nTR                  XXT5        g [        R                  " [	        S5      TR                  U 5      -  5      e)Ns#   .hgreleasenotes file '%s' not found)dataparser   Abortr   pathto)fr   remapr   ctxpreadrj   s       r   r   "getcustomadmonitions.<locals>.read  sP    8q6;;=DGGAXd3++:;dkk!nL r!   s   .hgreleasenotess   sections)NN)r   rh   )rj   r   r   r   s   `@@@r   re   re     sC    
t*CA  S  77;r!   c                j  ^
 U GH&  nX   n[         R                  " [        UR                  5       5      m
T
(       d  M:  T
R	                  S5      U;   a  MQ  U R                  [        S5      T
R	                  S5      UR                  5       SS 4-  5        U
4S jnU Vs/ s H  ov" U5      S:  d  M  UPM     nn[        U5      S:X  a"  U R                  [        S5      US   -  5        M  U(       d  M  S	R                  [        U5      5      n	U R                  [        S
5      U	-  5        GM)     gs  snf )aD  
Checks the commit messages for admonitions and their validity.

.. abcd::

   First paragraph under this admonition

For this commit message, using `hg releasenotes -r . --check`
returns: Invalid admonition 'abcd' present in changeset 3ea92981e103

As admonition 'abcd' is neither present in default nor custom admonitions
r5   s0   Invalid admonition '%s' present in changeset %s
N   c                n   > [         R                  " S TR                  S5      U 5      R                  5       $ )Nr5   )difflibSequenceMatcherr   ratio)x
admonitions    r   <lambda>"checkadmonitions.<locals>.<lambda>@  s.     7 7***1-q!%'!r!   g333333?s   (did you mean %s?)
r   s   , s   (did you mean one of %s?)
)r   r   RE_DIRECTIVEdescriptionr   rO   r   r   r   r|   r)   )rS   rj   
directivesrevsrevr   simr   rR   ssr   s             @r   checkadmonitionsr   (  s    iYY|S__->?
:"j0JK!''*CGGIcrN;< '1AjCFSL1jAw<1$HHQ67'!*DEWF7O4BHHQ=>CD)  Bs   D01D0c                N    U H  nU R                  SUS   US   4-  5        M!     g )Ns   %s: %s
r   r5   )rO   )rS   r   r$   s      r   _getadmonitionlistr   L  s*    

GAJ778 r!   c           	     v   [        5       nU GH  nX   n[        R                  " UR                  5       US9u  pg[	        U5       GHj  u  pU	S   S:w  a  M  U	S   n
U	S   (       a  U	S   S   R                  5       OS nUS-   [        U5      :X  a#  [        R                  " [        S5      XZ4-  5      e/ n[        US-   [        U5      5       Hm  nXm   nUS   S	:X  a  M  US   S:X  a    OTUS   S
:w  a(  U R                  R                  [        S5      XZ4-  5        US   S:  a  UR                  US   5        Mm    O   U(       d>  U R                  R                  [        S5      [        UR                  5       5      -  5        U(       a  UR!                  XU5        GMY  UR#                  X5        GMm     GM     U$ )N)admonitions   types
   admonitions   admonitiontitle   linesr   r5   s6   changeset %s: release notes directive %s lacks content   margin	   paragraphs=   changeset %s: unexpected block in release notes directive %s
   indents.   error parsing releasenotes for revision: '%s'
)r   r
   r   r   	enumeratestripr   r   r   r   rangerS   rL   r/   r   noder2   r6   )rj   r   r   notesr   r   blocksprunediblock	directiver0   r1   jpblocks                  r   parsenotesfromrevisionsr   Q  s    Ei OO:
 "&)HAW~.01I27/E(OA&,,.tE1uF#kk) &	'  J1q5#f+. '?i/'?m3'?l2GGLL4 *	+ )$q(%%fX&67- /2 HI#((*o& ##IjA&&y=i * z Lr!   c                |  ^ [        5       n[        R                  " U5      S   mSU4S jjnSn[        T5       H  u  pVUS   S:w  a  M  US   S   nUS   S:X  ai  U R	                  U5      nU(       d"  [
        R                  " [        S	5      U-  5      eUnU" U5      n	U	(       a  U	 H  n
UR                  XJ5        M     M  M  US   S
:X  aK  U[        :X  a$  U" U5      n	U	 H  n
UR                  XJ5        M     M  U" US5      nUR                  XGU5        M  [
        R                  " [        S5      U-  5      e   U$ )z6Parse text content containing generated release notes.r   c                  > / n[        U S-   [        T5      5       GHP  nTU   nUS   S:X  a  M  US   S:X  a    U$ US   S:X  a  US   S:w  a  [        R                  " [	        S5      5      eU(       a8  US	    Vs/ s H  oUSS  R                  5       PM     nnUR                  U5        M  US	    Vs/ s H  oUSS  R                  5       PM     sn/nTUS-   S   H-  nUS   S
;   a    O#US   S:X  d  M  UR                  US	   5        M/     UR                  U5        GM  US   S:w  a%  [        R                  " [	        S5      US   -  5      eU(       d  GM<  UR                  US	   5        GMS     U$ s  snf s  snf )Nr5   r   r      section   bulletr   r   s#   indented bullet lists not supportedr   )r   r   r   s*   unexpected block type in release notes: %s)r   r   r   r   r   r   r/   )offsetr0   notefragmentr   r   lr   r   s          r   gatherparagraphsbullets6parsereleasenotesfile.<locals>.gatherparagraphsbullets  s   vz3v;/A1IEW~*w:-4 3 w9,#q(++a(N&OPP49(ODOqqrU[[]OED ''.5:8_E_ekkm_EFE!'A >-DD! >\9!LLx9	 "1
 !''.w</kkCDGn%  u##E(O4= 0@ + E Fs   ;E33E8Nr   r   r   s	   underline   =s!   unknown release notes section: %s   -Ts   unsupported section type for %s)F)r   r
   r   r   rv   r   r   r   r6   BULLET_SECTIONr2   )r   textr   r   currentsectionr   r   r0   rt   bullet_pointsr   r1   r   s               @r   parsereleasenotesfiler     sD    E]]4 #F#J Nf%>Z'h" $&,,U3Dkk:;eC  "N3A6M)D**>@ *  < D(& 7 :)D**>@ * 5Q=
##N:F++a BCeKLL= &@ Lr!   c                *   / nU  GHX  u  p4X1;  a  M  UR                  U5        UR                  S[        U5      -  5        UR                  S5        UR                  U5       H  u  pVUR                  U5        UR                  S[        U5      -  5        UR                  S5        [        U5       H^  u  pxU(       a  UR                  S5        UR	                  [
        R                  " SR                  U5      SS9R                  5       5        M`     UR                  S5        M     UR                  U5      n	UR                  U5      (       aN  U	(       aG  UR                  [        5        UR                  S[        [        5      -  5        UR                  S5        U	 H  nUR	                  [
        R                  " SR                  US   5      SSS	S
9R                  5       5        USS  HW  nUR                  S5        UR	                  [
        R                  " SR                  U5      SS	S	S
9R                  5       5        MY     UR                  S5        M     GM[     U(       a  US   (       a  UR                  S5        SR                  U5      $ )zSerialize release notes from parsed fragments and notes.

This function essentially takes the output of ``parsenotesfromrevisions()``
and ``parserelnotesfile()`` and produces output combining the 2.
r   r!   r   ry   r   )widthr   s   * s     )r   
initindent
hangindentr5   N   
)r/   r   r;   r   r{   r   wrapr|   
splitlinesr>   r   )
r   r   r   sectionnamesectiontitler0   r1   r   r   	nontitleds
             r   serializenotesr     s    E%-!#\"TC--.S "'!7!7!DELLLLE
*+LL$Z0LL%OODIIdO2>IIK 1 LL "E( --k:	!!+..9LL(LLN 334LL#JLLIIjm,$$	
 *, #12S!OO		$ #(#(	
 !jl ' LL+ $I &.v rS::er!      releasenotes   rs   revr!   s&   revisions to process for release notess   REV   cs   checkFs+   checks for validity of admonitions (if any)   ls   lists/   list the available admonitions with their titles"   hg releasenotes [-r REV] [-c] FILE)helpcategoryc                   [        X5      n[        R                  " USSS/5        UR                  S5      (       a  [	        X5      $ UR                  S5      n[
        R                  " X=(       d    S/5      nUR                  S5      (       a  [        XUR                  5       U5      $ [        XR                  5       U5      nUc+  U R                  S5        U R                  [        XG5      5      $  [        U[        R                  " U5      5      nUR%                  X5        [        R&                  " U[        XH5      5        g! [          a    [#        5       n NHf = f)a	  parse release notes from commit messages into an output file

Given an output file and set of revisions, this command will parse commit
messages for release notes then add them to the output file.

Release notes are defined in commit messages as ReStructuredText
directives. These have the form::

   .. directive:: title

      content

Each ``directive`` maps to an output section in a generated release notes
file, which itself is ReStructuredText. For example, the ``.. feature::``
directive would map to a ``New Features`` section.

Release note directives can be either short-form or long-form. In short-
form, ``title`` is omitted and the release note is rendered as a bullet
list. In long form, a sub-section with the title ``title`` is added to the
section.

The ``FILE`` argument controls the output file to write gathered release
notes to. The format of the file is::

   Section 1
   =========

   ...

   Section 2
   =========

   ...

Only sections with defined release notes are emitted.

If a section only has short-form notes, it will consist of bullet list::

   Section
   =======

   * Release note 1
   * Release note 2

If a section has long-form notes, sub-sections will be emitted::

   Section
   =======

   Note 1 Title
   ------------

   Description of the first long-form note.

   Note 2 Title
   ------------

   Description of the second long-form note.

If the ``FILE`` argument points to an existing file, that file will be
parsed for release notes having the format that would be generated by this
command. The notes from the processed commit messages will be *merged*
into this parsed set.

During release notes merging:

* Duplicate items are automatically ignored
* Items that are different are automatically ignored if the similarity is
  greater than a threshold.

This means that the release notes file can be updated independently from
this command and changes should not be lost when running this command on
that file. A particular use case for this is to tweak the wording of a
release note after it has been added to the release notes file.

The -c/--check option checks the commit message for invalid admonitions.

The -l/--list option, presents the user with a list of existing available
admonitions along with their title. This also includes the custom
admonitions (if any).
rg   r   checks   not public()Nr   )r`   r   check_incompatible_argumentsr:   r   r	   revranger   rq   r   pagerrO   r   r   r   readfileFileNotFoundErrorr   rX   	writefile)	rS   rj   file_optsr   r   r   incomingr   s	            r   releasenotesr   ,  s   ^ $B-H((vw7GHxx!"//
((5/Ct&<_%=>Dxx(..*:DAA&t^^-=tDH}
!xxx:;;%%he0DE 
KKNN5.9:  %"$%s   2 E EEs   debugparsereleasenotesT)norepoc           	        US:X  a  [         R                  R                  5       nO[        R                  " U5      n[        X5      n[        XC5      nU H  nU R                  [        S5      U-  5        UR                  U5       HW  u  pxU R                  [        S5      U-  5        U H/  n	U R                  [        S5      SR                  U	5      -  5        M1     MY     UR                  U5       HR  nU R                  [        S5      5        U H/  n	U R                  [        S5      SR                  U	5      -  5        M1     MT     M     g)z6parse release notes and print resulting data structurer   s   section: %s
s     subsection: %s
s       paragraph: %s
ry   s     bullet point:
N)r   stdinr   r   r   r`   r   rO   r   r;   r|   r>   )
rS   pathrj   r   r   r   r$   r0   r1   r   s
             r   debugparsereleasenotesr     s    t|~~""$}}T"#B-H!(1E
#$w./!&!7!7!@EHHQ,-56"12TYYt_DE # "A
  33G<JHHQ+,-"12TYYt_DE # = r!   r   )6__doc__
__future__r   r   r   mercurial.i18nr   mercurial.noder   	mercurialr   r   r   r	   r
   r   r   mercurial.utilsr   r   cmdtablecommandwarningscatch_warningsfilterwarningsUserWarningfuzzywuzzy.fuzzrK   r   ImportError
testedwithrd   compile	MULTILINEr   r   r   r   r`   rM   rN   rP   rQ   rR   r   re   r   r   r   r   r   CATEGORY_CHANGE_NAVIGATIONr   r   rB   r!   r   <module>r     s/   #  	    
 


H
% 		 	 	", $		
 	' 
#$ #
 ?#$
A012Q|_a+,-Q~  zzA2<<P-#$Z; Z;z 2

$" $!EH9
@FL^FR 	 78fI	
 <=fI	
 @A	
. +,3358l;98l;^ 		"40F 1FY 
#	"  Ds0   F !&F F  
F
F F FF