
    q&f                     X   d dl Z d dlZd dlZd dlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ g Zi Z  G d
 d      Z! e!d      d        Z" e!d      d        Z#d Z$ e!d      d        Z%d Z& e!d      d:d       Z' e!d      d        Z( e!d      d        Z)  e!d      e)      Z*de+de+fdZ, e!d      d        Z- e!d       d!        Z. e!d"      d#        Z/ e!d$      d%        Z0 e!d&      d'        Z1 e!d(      d)        Z2  e!d*      e2      Z3 e!d+      d,        Z4 e!d-      d.        Z5 e!d/      d0        Z6 e!d1      d2        Z7 e!d3      d4        Z8 e!d5      d6        Z9d7 Z: e!d8      d9        Z;e jy                         Z=y);    N   )_)hexshort   )ErrorResponseHTTP_FORBIDDENHTTP_NOT_FOUNDget_contact	paritygen
staticfile)archivaldagopencodingerrorgraphmodpycompatrevset
revsetlangscmutilsmartsettemplateutil)
stringutil)webutilc                       e Zd ZdZd Zd Zy)
webcommanda  Decorator used to register a web command handler.

    The decorator takes as its positional arguments the name/path the
    command should be accessible under.

    When called, functions receive as arguments a ``requestcontext``,
    ``wsgirequest``, and a templater instance for generatoring output.
    The functions should populate the ``rctx.res`` object with details
    about the HTTP response.

    The function returns a generator to be consumed by the WSGI application.
    For most commands, this should be the result from
    ``web.res.sendresponse()``. Many commands will call ``web.sendtemplate()``
    to render a template.

    Usage:

    @webcommand('mycommand')
    def mycommand(web):
        pass
    c                     || _         y Nname)selfr    s     =/usr/lib/python3/dist-packages/mercurial/hgweb/webcommands.py__init__zwebcommand.__init__G   s	    	    c                 j    t         j                  | j                         |t        | j                  <   |S r   )__all__appendr    commands)r!   funcs     r"   __call__zwebcommand.__call__J   s%    tyy!"r$   N)__name__
__module____qualname____doc__r#   r*    r$   r"   r   r   0   s    ,r$   r   s   logc                 x    | j                   j                  j                  d      rt        |       S t	        |       S )a  
    /log[/{revision}[/{path}]]
    --------------------------

    Show repository or file history.

    For URLs of the form ``/log/{revision}``, a list of changesets starting at
    the specified changeset identifier is shown. If ``{revision}`` is not
    defined, the default is ``tip``. This form is equivalent to the
    ``changelog`` handler.

    For URLs of the form ``/log/{revision}/{file}``, the history for a specific
    file will be shown. This form is equivalent to the ``filelog`` handler.
       file)reqqsparamsgetfilelog	changelogwebs    r"   logr9   P   s0    " wwG$s|~r$   s   rawfilec                     | j                  dd      }t        j                  | j                  | j                  j
                  j                  dd            }|st        |       S 	 t        j                  | j                  | j                        }|j                         }|j                         }d}|r]t        j                  t!        j"                  |            d   }|t%        j&                  |      rd}nd}nt!        j(                  |      }|j+                  d      r|d	t,        j,                  z  z  }|| j.                  j0                  d
<   |j3                  d      d   j5                  dd      j5                  dd      }d|z  | j.                  j0                  d<   | j.                  j7                  |       | j.                  j9                         S # t        j                  $ r%}	 t        |       cY d }~S # t        $ r |w xY wd }~ww xY w)N   webs	   guessmimer1   r$   s   application/binaryr   s
   text/plains   text/s   ; charset="%s"   Content-Type   /   \s   \\   "s   \"s   inline; filename="%s"   Content-Disposition)
configboolr   	cleanpathrepor2   r3   r4   manifestfilectxr   LookupErrorr   pathdata	mimetypes
guess_typer   fsdecoder   binarysysbytes
startswithr   resheaders
rpartitionreplacesetbodybytessendresponse)r8   	guessmimerH   fctxinsttextmtfilenames           r"   rawfiler\   g   s   v|4ISXXsww'7'7';';GS'IJD}sxx1 99;D99;D	B!!("3"3D"9:1=:  &*"""2&B	}}X
("3"333')CGGOOO$b!))%9AA$O  	!8+ GGOO*+ GG77!!=  	C=  	J	s*   %*G H)
G93H9HHHc                 "   |j                         }|j                         t        | j                        |j	                         |j                         j                         v }t        j                        rGt        j                  t        j                  t        j                  |            d   xs d      }d|z  fd} | j                  	 d|t        j                   |      t#        j$                  |      t        j&                  | j(                  |      t        j*                  |      |j-                         j/                  |      t1        |      dt        j2                  t        j4                  | j6                  |            S )Nr   application/octet-stream   (binary:%s)c              3      K   t        j                  d            D ]#  \  }}|d|dz   z  d|dz   z  t              d % y w)NT   l%dr      % 6d)   line   lineid
   linenumber   parity)	enumerate
splitlinesnext)contextlinenotparityrY   s      r"   linesz_filerevision.<locals>.lines   sT     "4??4#89 	IFA!VaZ0&&1*5<	 	s   AA)filerH   rY   symrevrenamepermissionsishead)s   filerevision)rH   rI   r   stripecountfilenoder5   headsr   rM   r   rN   rJ   rK   rL   sendtemplater   upr   mappinggeneratorsymrevorshortnoder2   
renamelinkrE   flagsint	strkwargscommonentryrD   )r8   rW   frs   rZ   rn   rm   rY   s         @@r"   _filerevisionr      s9   		A99;Ds'F]]_ 4 4 66F  !2!21!56q9 +*
 " 3
ZZ]**51(($7!!$'MMO))!,6{
 

W004@
A
 
r$   r1   c                    | j                   j                  j                  d      dk(  rt        |       S t	        j
                  | j                  | j                   j                  j                  dd            }|st        |       S 	 t        | t	        j                  | j                  | j                               S # t        j                  $ r%}	 t        |       cY d}~S # t        $ r |w xY wd}~ww xY w)a5  
    /file/{revision}[/{path}]
    -------------------------

    Show information about a directory or file in the repository.

    Info about the ``path`` given as a URL parameter will be rendered.

    If ``path`` is a directory, information about the entries in that
    directory will be rendered. This form is equivalent to the ``manifest``
    handler.

    If ``path`` is a file, information about that file will be shown via
    the ``filerevision`` template.

    If ``path`` is not defined, information about the root directory will
    be rendered.
       styles   rawr1   r$   N)r2   r3   r4   r\   r   rC   rD   rE   r   rF   r   rG   r   )r8   rH   rX   s      r"   ro   ro      s    ( wwH%/s|SXXsww'7'7';';GS'IJD}S'//#((CGG"DEE 	C=  	J	s*   3B: :C2
CC2C**C--C2c                 4    dddd } fd} fd}|df|df|d	fi} fd
} fd} j                   j                  d   } j                  d j                   j                  v rX	 t         j                   j                  j	                  d            t        d       j                  j                  d   d<   t        j                   j                  j                  d         }t        dz  d      |d<   ||d<   t        j                   j                  j                  d         }	dz  |	d<   ||	d<    ||      \  }
d j                   j                  v rd}||
   d   }}
|n|
k7  r	|   d   }nd}d}||
    j                  d   }t         j                         j                  d||j                         dt        j                   |d       j#                  d      |	|d   ||      S # t        $ r Y Fw xY w)N   revs   keywords   revsetc              3      K   |  y wr   r/   )ctxs    r"   	revsearchz_search.<locals>.revsearch   s     	s   c           	   3   V  K   t         j                  } ||       j                         }fd} |       D ]o  }d}|D ]_  }| ||j                               v r| ||j	                               v r5| |dj                  |j                                     v r]d} n |rl| q y w)Nc               3   L  K   j                   j                  } t        t        j                         dz
  dd      D ]c  }g }| j	                  t        d|dz
        |      D ]"  }j                   |   }|j                  |       $ |j                          |D ]  }|  e y w)Nr   r   ic   )rD   r6   rangelenrevsmaxr'   reverse)cliljr   er8   s         r"   revgenz._search.<locals>.keywordsearch.<locals>.revgen   s     ##B3sxx=1,a6 QB3 "A((1+CHHSM" 		 AGs   B!B$r       r   )r   lowersplituserdescriptionjoinfiles)queryr   qwr   r   missqr8   s          r"   keywordsearchz_search.<locals>.keywordsearch   s     5\!		 8 	CD sxxz**E#//"344E$))CIIK"899D I	s   AB)B)2'B)B)c              3   >   K   | D ]  }j                   |     y wr   )rD   )r   rr8   s     r"   revsetsearchz_search.<locals>.revsetsearch   s$      	A((1+	s   s   exact revision searchs   literal keyword searchs   revset expression searchc                 N   	 t        j                  
j                  |       }|fS # t        j                  t        j
                  f$ r Y nw xY wd| z  }	 t        j                  |      }n# t        j                  $ r | fcY S w xY wt        j                  |      dk  r| fS t        d t        j                  |      D              r| fS t        j                  |      }|j                  t        j                        s| fS 	 t        j                   
j                  j"                  |t        j$                  
j                              } |
j                        }	|fS # t        j                  t        j&                  t        j(                  t
        f$ r | fcY S w xY w)Ns   reverse(%s)r   c              3   @   K   | ]  \  }}}||xs d dd fdk(    yw)r$   N   )s   strings   re:r/   ).0tokenvalueposs       r"   	<genexpr>z1_search.<locals>.getsearchmode.<locals>.<genexpr>  s4      
!uc U\c2A&'+>>
s   )lookup)r   	revsymbolrD   r   	RepoErrorrG   r   parse
ParseErrordepthanytokenize	funcsusedissubsetr   safesymbolsmatchuilookupfnRepoLookupErrorAbort)r   r   revdeftreer   mfuncr   MODE_KEYWORDMODE_REVISIONMODE_REVSETr8   s          r"   getsearchmodez_search.<locals>.getsearchmode  s   	&##CHHe4C !#%% !2!23 	 	  %'	'##F+D 	'&&	' D!Q&&& 
%/%8%8%@
 
  &&((.	!!&"4"45&&	'LLVFOOCHH,EE ?D$$ !!KK	
 	'  &&	's4    ' #AAA, ,BBAE& &;F$#F$c              3     K   d} 
d         D ]  }|dz  }t        j                  |      }t        j                  j                  d|      }t        j
                  |j                         |j                        }t        j                  j                  |      }|j                  t              ||d       | |	k\  s y  y w)Nr   r      changelogtag)rf   r   s   files)r   binnoder   showtagrD   listfilediffsr   maxfilesr   updateri   )rj   countr   nshowtagsr   lmfuncargrm   revcount
searchfuncr8   s          r"   
changelistz_search.<locals>.changelist9  s      :a=) 	CQJE$Asxx!DH))#))+q#,,GE$$SXXs3BII#F|%-# H #	s   CC
C
   revcountr      sessionvarsr   s   forcekwr$      tips   searchs   searchentryr   )
r   noderp   entriesarchivesmorevarslessvarsmodedescshowforcekwshowunforcekw)r2   r3   
maxchangesr}   r4   r   tmpldefaults
ValueErrorcopyrD   r   rt   rw   r   r   ry   archivelist)r8   r   r   r   searchfuncsr   r   r   r   r   moder   r   tipr   r   r   r   rm   r   r   s   `             @@@@@@@r"   _searchr      s<   MLK<
 		#;<}&?@l$?@K/'b , GGV$E~~Hcgg&&&	377++//XFGH8Q'H=ECHHn-k: yy**>:;HAq1H[HVyy**>:;H$qLH[HV!%(MD'SWW%%%#D)!,<%l3A6KKT"J
((6
Cs'FWWY--j~N(A#   ;  		s   9AH
 
	HH	   changelogc                     d}d j                   j                  v rKt        j                   j                   j                         }t        j
                   j                   |      }n4d j                   j                  v rt               S  j                  d   }d} fd}|r j                  }n j                  }d j                   j                  v rX	 t         j                   j                  j                  d|            }t        |d      }| j                  j                  d   d<   t        j                   j                  j                  d         }t        |d	z  d      |d<   t        j                   j                  j                  d         }|d	z  |d<   t!         j                        }	|j#                         t%         j&                        t        j(                   j                        j+                  ||	      }
t-         ||dz               }|d
d }t!        |      |kD  r|dd
 }|d
d }ng } j/                  |rdnd|
|j1                         ||	t3        j4                  |      t3        j4                  |      t3        j4                  |       j7                  d      ||||      S # t        $ r Y w xY w)a0  
    /changelog[/{revision}]
    -----------------------

    Show information about multiple changesets.

    If the optional ``revision`` URL argument is absent, information about
    all changesets starting at ``tip`` will be rendered. If the ``revision``
    argument is present, changesets will be shown starting from the specified
    revision.

    If ``revision`` is absent, the ``rev`` query string argument may be
    defined. This will perform a search for changesets.

    The argument for ``rev`` can be a single revision, a revision set,
    or a literal keyword to search for in changeset data (equivalent to
    :hg:`log -k`).

    The ``revcount`` query string argument defines the maximum numbers of
    changesets to render.

    For non-searches, the ``changelog`` template will be rendered.
    r$      noder   r   c              3      K   g }dk7  r&j                   j                  j                  d      }t        j                  ||       D ]  }|  y w)Nr>   r   )rD   r6   r   r   changelistentries)maxcountr   entryrm   r   r8   s      r"   r   zchangelog.<locals>.changelist  sT     "988%%**32D..sD(FK 	EK	s   AAr   r   r   r   Nr>      shortlogr   )	changenavr   revrp   
changesetsr   latestentry	nextentryr   r   r   r   r   )r2   r3   r   	changectxrD   rz   r   maxshortchangesr   r}   r4   r   r   r   r   r   r   r   r   rt   revnavgenlistrw   r   r   mappinglistr   )r8   shortlogr   r   rp   r   r   r   r   r   r   r   r   r   rm   r   s   `             @@r"   r6   r6     sk   4 E#''"""#''2**377C8	377##	#s|hhv &&>>cgg&&&	377++//XFGH8Q'H=ECHHn-k: yy**>:;HAq1H[yy**>:;H$qLH[ME
'')Cs'Fsxx(,,S(EBI:hl+,G"1+K
7|hBCL	#2,	\WWY((1 ,,[9**95(   -  		s   AJ8 8	KKr   c                     t        | d      S )a  
    /shortlog
    ---------

    Show basic information about a set of changesets.

    This accepts the same parameters as the ``changelog`` handler. The only
    difference is the ``shortlog`` template will be rendered instead of the
    ``changelog`` template.
    T)r   )r6   r7   s    r"   r   r     s     S4((r$   	   changesetc                     t        j                  | j                  | j                        } | j                  di t        j
                  | |      S )a  
    /changeset[/{revision}]
    -----------------------

    Show information about a single changeset.

    A URL path argument is the changeset identifier to show. See ``hg help
    revisions`` for possible values. If not defined, the ``tip`` changeset
    will be shown.

    The ``changeset`` template is rendered. Contents of the ``changesettag``,
    ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many
    templates related to diffs may all be used to produce the output.
    )r   )r   r   rD   r2   rw   changesetentry)r8   r   s     r"   	changesetr    sA      

CHHcgg
.C3MG,B,B3,LMMr$   r   rH   returnc                     | S )zHook for mapping a path in the repository to a path in the
    working copy.

    Extensions (e.g., largefiles) can override this to remap files in
    the virtual file system presented by the manifest command below.r/   )rH   s    r"   
decodepathr    s	     Kr$      manifestc                    d| j                   j                  v rKt        j                  | j                  | j                         t        j
                  | j                         }n| j                  d   d}t        j                  | j                  | j                   j                  j                  dd            }j                         t        j                        }i i t        | j                        |r|dd dk7  r|dz  }t        |      }d|z   j                         D ]r  \  }}t        |      }|d| |k7  r||d }|j!                  d      }	t        |	      dk(  r||<   D}
|	d	d D ]   }||
vri |
|<   |
|   }
t        |
      dkD  s  n d|
d<   t rsst#        t$        d
|z         fd}fd} | j&                  	 d|t        j(                        t+              t-        j.                  |      t-        j.                  |      | j1                  t3        |            dt5        j6                  t        j8                  | j                              S )a  
    /manifest[/{revision}[/{path}]]
    -------------------------------

    Show information about a directory.

    If the URL path arguments are omitted, information about the root
    directory for the ``tip`` changeset will be shown.

    Because this handler can only show information for directories, it
    is recommended to use the ``file`` handler instead, as it can handle both
    directories and files.

    The ``manifest`` template will be rendered for this handler.
    r   r   r1   r$   r>   Nr=   r   r   s   path not found: c           	   3      K   t              D ]W  }|   }j                  |      }|t              ||j                         |j	                         j                  |      d Y y w)N)r1   rf      basename   dates   sizes   permissions)sortedrF   ri   datesizer|   )rj   r   fullrW   r   r   mfrm   s       r"   filelistzmanifest.<locals>.filelistL  se      	A8D;;t$D< " 		s   A'A*c              3   z  K   t              D ]  }g }|   }t        |t              rgt        |      dk(  rYt	        t        |j                                     \  }}|r|j                  |       |}t        |t              rt        |      dk(  rYd|fz  }t	        	      |dj                  |      |d  y w)Nr   s   %s%sr=   )rf      paths	   emptydirsr  )	r
  
isinstancedictr   ri   iteritemsr'   r   )
rj   d	emptydirshkvrH   abspathdirsrm   s
          r"   dirlistzmanifest.<locals>.dirlistZ  s      	AIQAQ%#a&A+DO,1$$Q'	 Q%#a&A+ gq\)D<"ii	2 	s   BB;+B;)rp   rH   rx   upparityfentriesdentriesr   )r  )r2   r3   r   r   rD   rz   rC   r4   rE   r   r   r   rt   r   r  r  r   r   r
   rw   rx   ri   r   ry   r   r   r   r~   r   )r8   rp   rH   r   r   r  r   r   remainelementsr  elemr  r  r  r   r  r   r  rm   s                 @@@@@@r"   rE   rE     sB   " #''"""#''2**377C8hhvSXXsww'7'7';';GS'IJD	B??3DEDs'FRS	T!D	ATkG88: a tRa5D=12<<%x=A E&MA 2 q= AdGdGq6A: AdG'* 
%N,?$,FGG* 3
::gf..x8..w7T+
 

W003?
@
 
r$      tagsc           
          t        t         j                  j                                     t	         j
                         fd} j                  dt         j                  j                  j                               t        j                  |d      t        j                  |d      t        j                  |d            S )z
    /tags
    -----

    Show information about tags.

    No arguments are accepted.

    The ``tags`` template is rendered.
    c              3      K   }|rD cg c]  \  }}|dk7  s||f }}}|r|d d }|D ];  \  }}t              |j                  |   j                         t        |      d = y c c}}w w)Nr   r   )rf      tagr	  r   ri   rD   r  r   )	rj   notip
latestonlyrl   r  r   r   rm   r8   s	         r"   r   ztags.<locals>.entries  s     $%5DAqf!Q5A5"1A 	DAq<!))+Q	 	 6s   
A2A,A,AA2r$  )FFargs)TF)TT)r   r   entriesnotipr   )r   reversedrD   tagslistr   rt   rw   r   r6   r   r   ry   )r8   r   r   rm   s   ` @@r"   tagsr0  |  s     	Xchh'')*+As'F ##'')*--gNK!227O 11'M   r$   	   bookmarksc           
      N     j                   j                  j                         D cg c]  }|d    j                   v s| c} fd}t        |d      t	         j
                         fd}r	d   d   }nd} j                   |   j                         } j                  dt         j                   j                  j                               t        j                  d	|ig      t        j                  |d
      t        j                  |d            S c c}w )z
    /bookmarks
    ----------

    Show information about bookmarks.

    No arguments are accepted.

    The ``bookmarks`` template is rendered.
    r   c                 N    j                   | d      j                         | d   fS Nr   r   rD   r   br8   s    r"   <lambda>zbookmarks.<locals>.<lambda>  s%    !A$++-qt4 r$   Tkeyr   c              3      K   }|rd d }|D ];  \  }}t              |j                  |   j                         t        |      d = y w)Nr   rf   s   bookmarkr	  r   r(  )rj   r*  rl   r  r   r   rm   r8   s        r"   r   zbookmarks.<locals>.entries  s\     "1A 	DAq<!))+Q	 	s   AAr   r>   r1  r	  Fr+  )T)r   
lastchanger   r   )rD   
_bookmarksr  r
  r   rt   r  rw   r   r6   r   r   r   ry   )r8   r7  sortkeyr   	latestrevlastdater   rm   s   `     @@r"   	bookmarksrC    s     HH''--/Dq1Q43883CDA4Gqgt,As'F
 	aDG		xx	"'')H##'')*++gx-@,AB--gHE 11'H   / 	Es   D"D"   branchesc                 ,   t        j                  | j                  | j                        }t        j                  | j                  | j                  d      }| j	                  dt        | j                  j                  j                               ||      S )z
    /branches
    ---------

    Show information about branches.

    All known branches are contained in the output, even closed branches.

    No arguments are accepted.

    The ``branches`` template is rendered.
    r   rD  )r   r   r   )r   branchentriesrD   rt   rw   r   r6   r   )r8   r   r   s      r"   branchesrG    sv     ##CHHcoo>G''#//1EK##'')*	   r$      summaryc                 $   	
 t         j                  j                               		 fd} fd}
 fd} j                  d   }t         j                        }t	        d| j
                  z
        
t        |
 j
                  z          j                  dd      }|sd} j                  dd	      } j                  d
|t         j                        xs d|j                         t        j                  |d      t        j                  |      t        j                   j                   j                   d      t        j                  |d      |j#                         d j%                  d      t        j&                  |d            S )z
    /summary
    --------

    Show a summary of repository state.

    Information about the latest changesets, bookmarks, tags, and branches
    is captured by this handler.

    The ``summary`` template is rendered.
    c              3      K   t        j                        }d}D ]M  \  }}|dk(  r|dz  }|dkD  r y t        |      |t        |      j                  |   j                         d O y w)Nr   r   r   
   )rf   r'  r   r	  )r   rt   ri   r   rD   r  )rj   rm   r   r  r   r   r8   s        r"   
tagentrieszsummary.<locals>.tagentries  s{     3??+ 	DAqF{QJErz  <Q!))+	 	s   A+A.c              3   t  K   t        j                        }j                  j                  j	                         D cg c]  }|d   j                  v s| }}fd}t        ||d      }|d d D ];  \  }}t        |      |j                  |   j                         t        |      d = y c c}w w)Nr   c                 N    j                   | d      j                         | d   fS r4  r5  r6  s    r"   r8  z,summary.<locals>.bookmarks.<locals>.<lambda>  s%    SXXad^//11Q48 r$   Tr9  rK  r<  )	r   rt   rD   r?  r  r
  ri   r  r   )rj   rm   r7  marksr@  r  r   r8   s          r"   rC  zsummary.<locals>.bookmarks  s     3??+HH//557Lq1Q4388;KLL8u'48#2J 	DAq<!))+Q	 	 Ms   <B8B3B3AB8c              3   x  K   t        
j                  	z
        }g }g }	k  r)
j                  j                  j	                  	dz
        }|D ]P  }
j                  |   }t        j                  
j                  |      }t        |      |d<   |j                  |       R t        |      D ]  }|  y w)Noffsetr   rf   )
r   rt   rD   r6   r   r   r   ri   r'   r.  )rj   rm   r   r   r   r   r   r   endstartr8   s           r"   r   zsummary.<locals>.changelist  s     3??53;?3;88%%**5#':D 	A((1+C$$SXXs3B LByMHHRL		 a[ 	EK	s   B7B:r   r   r;   s   descriptions   unknowns   labelsrH  s   tagentryr   rK  s   shortlogentrys   label)descownerr>  r0  rC  rG  r   r   rp   r   labels)r.  rD   r/  r   r   r   minconfig
configlistrw   r   r  r   ry   r   rF  rt   r   r   
hybridlist)r8   rL  rC  r   r   r   rU  rW  rS  r   rT  s   `       @@@r"   summaryr\    sH    	""$%A$ ((6
CME53>>)*E
eUS^^+
,C::fn-D^^FI.F#**%388:**:KH//	:&&sxx"E..-
 WWY(&&vH=   r$      filediffc           
         d\  }}	 t        j                  | j                  | j                        }| |j                         }|j                         }|j                         }| j                  dd      }d| j                  j                  v r| j                  j                  d   }t        j                  | ||g|      }|t        j                  |      }|}nt        j                  g       }|} | j                   	 d|t        j"                  | j                  |      ||dt%        j&                  t        j(                  | j                  |            S # t        $ rx t        j
                  | j                  | j                        }t        j                  | j                  | j                  j                  d         }||j                         vr Y w xY w)a  
    /diff/{revision}/{path}
    -----------------------

    Show how a file changed in a particular commit.

    The ``filediff`` template is rendered.

    This handler is registered under both the ``/diff`` and ``/filediff``
    paths. ``/diff`` is used in modern code.
    )NNr1   r;   r   )ro   rp   rq   diff)r]  )r   rF   rD   r2   rG   r   rC   r3   r   rH   p1rY  diffsr{   r   r   rw   rz   r   r~   r   )r8   rW   r   rH   basectxstylera  rq   s           r"   filediffrd  @  s    ID#sxx1 yy{nnffhGJJvx(E377###  *MM#sGdVU;E##D)))"-3((#6 

W003?
@ /  #''2  377+;+;G+DEsyy{" #s   *E A=GG   diffs
   comparisonc                 ~   t        j                  | j                  | j                        }d| j                  j                  vrt        t        d      t        j                  | j                  | j                  j                  d         }d }d| j                  j                  v r  || j                  j                  d         }n || j                  dd            }d }d}|j                         }|j                         }|j                         }	|j                         }
t        j                  |      }||v r"||   } ||      }||vrd	}n+||   } ||      }nd	}|j                         |   } ||      }t        j                  |||      }|t        j                  |      }|}nt!        j"                  g       }|} | j$                  	 d|t        j&                  | j                  |      ||t)        |	      |
t)        |      |d
t+        j,                  t        j.                  | j                  |            S )a  
    /comparison/{revision}/{path}
    -----------------------------

    Show a comparison between the old and new versions of a file from changes
    made on a particular revision.

    This is similar to the ``diff`` handler. However, this form features
    a split or side-by-side diff rather than a unified diff.

    The ``context`` query string argument can be used to control the lines of
    context in the diff.

    The ``filecomparison`` template is rendered.
    r1   s   file not givenc                 .    | dk(  xr dxs t        |       S )Ns   fullr>   )r}   )r  s    r"   r8  zcomparison.<locals>.<lambda>  s    Q'\0b:CF r$   s   contextr;   s   comparisoncontextc                 N   | j                         rxt        j                  t        j                  t        j
                  | j                                     d   xs d      }t        d      |t        | j                               fz  gS | j                         j                         S )Nr   r^   s   (binary file %s, hash: %s))isbinaryr   rN   rJ   rK   rL   rH   r   r   ru   rI   rh   )r   rZ   s     r"   	filelineszcomparison.<locals>.filelines  s    ::<""$$X%6%6qvvx%@A!D /.B 34C

<M7NNOOvvx""$$r$   Nr/   )ro   rp   rq   leftrevleftnoderightrev	rightnode
comparison)s   filecomparison)r   r   rD   r2   r3   r   r
   rC   rY  r`  r   r   r   r   comparer{   r   r   rw   rz   r   r   r~   r   )r8   r   rH   parsecontextrj   rj  rW   parentrk  rl  rm  rn  
rightlines	leftlinespfctxro  rq   s                    r"   ro  ro  t  s   " 

CHHcgg
.Ccgg&&&N,=>>SXXsww'7'7'@AD:LSWW%%%sww//
;<szz&2FGH% DVVXFjjlG{{}HwwyH$Is{4yt_
vI4LE!%(I
e$	)Z@J##D)))"-3((#6Xi. 

W003?
@ r$      annotatec                    	 t        j                   j                   j                        j	                         }t         j                        	j                         j                         j                         v }i fd	 fd}t        j                   j                   j                  j                  d      }|j                  D ci c]"  }|t        |t        j                  |            $ }}  j                   	 d|t#        j$                  |      t        j&                  |      t        j(                   j                        t        j*                        j-                         j/                  |      t1        |      t#        j2                  |      dt        j4                  t        j6                   j                              S c c}w )a)  
    /annotate/{revision}/{path}
    ---------------------------

    Show changeset information for each line in a file.

    The ``ignorews``, ``ignorewsamount``, ``ignorewseol``, and
    ``ignoreblanklines`` query string arguments have the same meaning as
    their ``[annotate]`` config equivalents. It uses the hgrc boolean
    parsing logic to interpret the value. e.g. ``0`` and ``false`` are
    false and ``1`` and ``true`` are true. If not defined, the server
    default settings are used.

    The ``fileannotate`` template is rendered.
    c              3      K   |j                         }|vrOg |<   |j                         D ]7  }|j                         |j                         d}|   j                  |       9 |   D ]  }|  y w)N)r   r   )r   parentsr   r'   )rj   r   r   pr   parentscaches        r"   ry  zannotate.<locals>.parents  s     eegl" "LYY[ 0UUWEEG S!((/0 c" 	AG	s   A3A6c              3     K   j                         rt        j                  t        j                  t        j
                  j                                     d   xs d      }t        j                  j                  j                               dd|z        g}n5t        j                  j                  j                  j                        }d }t!        d      }t#        |      D ]  \  }}|j$                  }|j'                         }||k7  rd}	t)        |      }
nd }	|}i dt)              d|j+                         d	|d
|j-                         dt/        j0                  |f      d|j3                         d|j5                         d|j                         d|	d
d|j6                  d|j8                  d|dz   dd|dz   z  dd|dz   z  d|j;                           y w)Nr   r^   r   r_   )rW   rk   rY   Trf   r   r   s   authors   parentsr+  s   descs   extrar1   s	   blockheads   blockparitys
   targetlinerc   s   linenord   ra   re   rb   s   revdate)ri  r   rN   rJ   rK   rL   rH   r   annotatelinerF   filerevr   annotater2   rD   r   r   rg   rW   r   ri   r   r   r   ry   r   extrark   rY   r  )rj   rZ   rn   previousrevblockparitygenrk   aliner   r   	blockheadblockparityrW   ry  rm   r8   s              r"   r  zannotate.<locals>.annotate  s    ==?""$$X%6%6tyy{%CDQG /.B
 ""dlln5'",E $$SWWdCHHKK@E"1&u- 	MFE

A%%'Ck! 	">2 	K4<  1668	
 L99'M  !'')  i  u||  6A: 6VaZ0 w&1*5  AFFH! 	s   G0G3rv  )ro   r  rH   rp   rq   rr   rs   diffopts)s   fileannotate)r   rF   rD   r2   rH   r   rt   ru   r5   rv   difffeatureoptsr   r   getattrr   sysstrrw   r   ry   rx   rz   r{   rE   r|   r}   
hybriddictr~   r   )
r8   r   rs   r  r  r  rW   ry  r{  rm   s
   `     @@@@r"   r  r    so   " ??388SWW-D		As'F]]_ 4 4 66F L,\ &&sww[IH:B:K:K5678X__Q/00H  3..x8ZZ](($7!!$'MMO))!,6{((2 

W004@
A 	s   'G   filelogc                 &   $ 	 t        j                   j                   j                        }|j	                         }|j                         } j                  }d j                  j                  v rX	 t!         j                  j                  j#                  d|            }t%        |d      }| j&                  j(                  d   d<   t        j,                   j                        }	t/        j.                   j&                  j(                  d         }
t%        |dz  d      |
d<   t/        j.                   j&                  j(                  d         }|dz  |d<   d j                  j                  v }|r! j                  j                  d   x|
d<   |d<   d j                  j                  v }|r! j                  j                  d   x|
d<   |d<   |j1                         dz   }t%        d||z
        }t3        |||z         }t5         j6                  ||z
  	      } j                  }|j                         }|j9                  ||dz
        D cg c]  }|j                  |      |v r| }}g } j;                  d
d      $d j                  j                  v r j                  j                  d   $d$ fd	}d}|	-|	J t        j<                  |	 }t?        j@                  g       }|rtC        jD                  |g|	 }ntC        jF                  |g|	 }tI        |d      D ]  \  }\  }}d}|r
 |||      }|j	                         }t        jJ                  ||      } | jM                  tO        |      |j                         ||t        j<                  | t?        j@                  g       d       |jQ                  |        ||k(  s n t        j<                  |	 |
d<   |
d   |d<   n|D ]y  }|j                  |      }!d}|r ||!      }t        jJ                  ||!      } | jM                  tO        |      |||t        jR                  |!      d       |jQ                  |        { |jU                          t        jV                   j                  |j	                               }"|"jY                  |dz
  ||      }|dd }#  jZ                  	 d||t        j\                   j                  |      t?        j@                  |      ||t?        j@                  |#      ||||
dt_        j`                  t        jJ                   j                  |            S # t        j                  $ r t        j                   j                   j                  j                  d         } j                  j                  |      }t        |      }|s t        j                   j                   j                        j                         }|j                  d      }||k  r |dz
  }|j                  |      |kD  r|dz  }|j                  |      |kD  r j                  j                  ||j                  |            }Y ,w xY w# t*        $ r Y w xY wc c}w )a)  
    /filelog/{revision}/{path}
    --------------------------

    Show information about the history of a file in the repository.

    The ``revcount`` query string argument can be defined to control the
    maximum number of entries to show.

    The ``filelog`` template will be rendered.
    r1   r   r   r   r   r   s   patchs   descendrQ  r;   r   Nc                     | j                         }|j                         }| j                         }t        j                  |||g|d|j                         d d z        S )Ns   %s-   )	linerangelineidprefix)r   r`  rH   r   ra  r   )rW   r  r   rb  rH   	diffstyler8   s        r"   r_  zfilelog.<locals>.diffy  s^    nn&&(yy{}}F#'')CR.0
 	
r$   )r  )rf      filerevr1   re  	   linerange   renamer  )rf   r  r1   re  r  )ro   navrp   r   descendpatchr   r  r   r   r   r   )r  )1r   rF   rD   r2   rH   r5   r   rG   rC   r3   ro   r   r   r   linkrevr   r}   r4   r   r   r   r   r  r   r~  rX  r   rt   r   rY  formatlineranger   r   r   blockdescendantsblockancestorsrg   r   r   ri   r'   r{   r   
filerevnavr   rw   rz   r   r~   )%r8   rW   r   flnumrevsr   firstfrevr   lranger   r   r  r  r   rT  rS  rm   rD   r5   r~  r   r   r_  r  r  itr   clrra  rH   r   iterfctxr   r   r  s%   `                                   @r"   r5   r5   -  s   5sxx1IIK\\^  ""Hcgg&&&	377++//XFGH8Q'H=ECHHn-k: sww'Fyy**>:;HAq1H[yy**>:;H$qLH[(((E25''2B2B82LLXh/CGG,,,G69gg6F6F7
 	
x
3 LLNQE58#$E
eUX%
&Csus{;F88DllnG ||E373??7#t+ 	D 
 G

68,I377###GG$$X.	
 I!!!++V4	 &&r*''6v6B%%d4V4B#B* 	JAw2EQ"-668D$$T1-BII#F| !!"")"9"92">+77;	 NN2H}'	( ")!8!8&!A!),!7 	A||AHEX$$T84BII#F| !"&11(; NN2	  	##CHHdiik:jjq(E2"1+K3(($7((1 ,,[9 

W004@
A A  5chh(8(8(ABXX]]1b'#''2668

1;{jj$AID jj$xx2::d#345*  		4s2   A
U 3AY> ZC5Y;+Y;:Y;>	Z
Zs   archivec                 \   | j                   j                  j                  d      }| j                  dd      }| j                   j                  d   }|t        j
                  vr(dt        j                  |      z  }t        t        |      ||v s*| j                  dd|z         sd|z  }t        t        |      t        j                  dd	t        j                  j!                  | j"                              }| j$                  j'                  |      }|}||k(  s|d
k(  rt)        |      }d||fz  }t	        j*                  | j$                  | j                         }	t-        j.                  |	g       }
| j                   j                  j                  d      }|rid|z   g}t-        j.                  |	|d      }
|rI|	j1                         j3                         D cg c]  } |
|      s| }}|st        t        d|z        t        j
                  |   \  }}}}|| j4                  j6                  d<   d||fz  | j4                  j6                  d<   |r|| j4                  j6                  d<   | j4                  j9                          t;        | j4                  j=                               rt?        j@                  d      | j                   jB                  dk(  rg S | j4                  jE                         }tG        jH                  | j$                  |||||
| j                  dd             g S c c}w )a  
    /archive/{revision}.{format}[/{path}]
    -------------------------------------

    Obtain an archive of repository content.

    The content and type of the archive is defined by a URL path parameter.
    ``format`` is the file extension of the archive type to be generated. e.g.
    ``zip`` or ``tar.bz2``. Not all archive types may be allowed by your
    server configuration.

    The optional ``path`` URL parameter controls content to include in the
    archive. If omitted, every file in the specified revision is present in the
    archive. If included, only the specified file or contents of the specified
    directory will be included in the archive.

    No template is used for this handler. Raw, binary content is generated.
    s   typer;   s   allow-archiver   s   Unsupported archive type: %ss   allows   Archive type not allowed: %ss   \W+   -r   s   %s-%sr1   s   path:r  )defaults   file(s) not found: %sr<   s   attachment; filename=%s%srA   s   Content-Encodings4   sendresponse() should not emit data if writing laters   HEADs   archivesubrepos)prefixr   subrepos)%r2   r3   r4   rZ  r   archivespecsr   pprintr   r
   rB   r	   resubosrH   basenamereponamerD   r   r   r   r   r   rE   keysrP   rQ   setbodywillwriter   rU   r   ProgrammingErrormethodgetbodyfiler   archive)r8   type_allowedr:  msgr  cnodearch_versionr    r   r   ro   patsr   r   mimetypeartype	extensionr   bodyfhs                       r"   r  r    s   * GG  )EnnV%56G
''

7
#CG(((-
0A0A%0HHNC00g58H!I-5NC00vvgtRWW%5%5cll%CDHHHOOC EL|sf}U|x..D


CHHcgg
.CMM#r"E77(D4 c49 # 3 3 5B1qQBEB#"$<t$C  -4,@,@,G)Hfi'/CGGOOO$.JN /CGGOO*+
 /7+,GGCGG  "#$$C
 	
 ww~~ 	WW  "F(:; IM Cs   L)%L)   staticc                     | j                   j                  d   }| j                  ddd      }t        | j                  ||| j
                         | j
                  j                         S )Nr1   r;   r  F)	untrusted)r2   r3   rY  r   templatepathrP   rU   )r8   fnamestatics      r"   r  r  (  sW    GGW%E ZZ	UZ;Fs877!!r$      graphc                     d j                   j                  v rKt        j                   j                   j                         }t        j
                   j                   |      }n j                  d   }d}|j                         }d} j                  }d j                   j                  v rX	 t         j                   j                  j                  d|            }t        |d      }| j                  j                  d   d<   t        j                   j                  j                  d         }t        |dz  d      |d<   t        j                   j                  j                  d         }|dz  |d<    j                   j                  j                  d|j                               t        j                   j                  j                  d         }|d<   t!         j                        }	|}
t#        t        d	|	dz
        ||z         }t        d	||z
        }t        j$                   j                        j'                  |
||	      }g g }d	|
d
k7  r j                  j(                  j+                  |
d	      }g }|D ]&  }|j-                  |       t!        |      |dz   k\  s& n t!        |      |kD  r6t        j.                   j                   j                  |d
            g}|dd
 }|d
   t1        j2                   j                  t5        j6                  |            }t9        d t1        j:                  | j                        D               fd fd} fd}t!              } j=                  d|||||||||||	t?        j@                  |      t?        jB                  |      t?        jB                  |      |j                          jE                  d      |      S # t        $ r Y w xY w)a  
    /graph[/{revision}]
    -------------------

    Show information about the graphical topology of the repository.

    Information rendered by this handler can be used to create visual
    representations of repository topology.

    The ``revision`` URL parameter controls the starting changeset. If it's
    absent, the default is ``tip``.

    The ``revcount`` query string argument can define the number of changesets
    to show information for.

    The ``graphtop`` query string argument can specify the starting changeset
    for producing ``jsdata`` variable that is used for rendering graph in
    JavaScript. By default it has the same value as ``revision``.

    This handler will render the ``graph`` template.
    r   r   '   r   r   r   r   s   graphtopr   r>   Nc              3   L   K   | ]  }|d    t         j                  k(  r|  ywr   Nr   	CHANGESETr   items     r"   r   zgraph.<locals>.<genexpr>  s*      
Aw(,,, 
   "$c                  b   j                      j                         } g }| dk7  rj                   j                  j                  |       }t	        j
                  j                   t        j                  |            }t        d t	        j                  |j                         D              }|S )Nr>   c              3   L   K   | ]  }|d    t         j                  k(  r|  ywr  r  r  s     r"   r   z*graph.<locals>.fulltree.<locals>.<genexpr>  s*      7h000 r  )
rD   r   r6   r   r   	dagwalkerr   basesetr   colored)r   r   r   daggraphtoplastrevr8   s       r"   fulltreezgraph.<locals>.fulltree  s    hhx $$&"988%%**38D$$SXXx/?/?/EFC $,,S#((; D
 r$   c              3      K           D ]B  \  }}}}}t        j                  |      t        j                  j                  |      ||d D y w)N)r   s	   graphnodes   vertex   edges)r   bytestrr   getgraphnoderD   )rj   idtyper   vtxedgesr  r8   s         r"   jsdatazgraph.<locals>.jsdata  sU     +3: 	'RsC!))#.%22388SA	 	s   AAc           
   3     K   t        j                        }t              D ]  \  }\  }}}}}t        j                  j
                  |      }|D 	cg c]"  }	|	d   |	d   |	d   dz
  dz  dz   |	d   |	d   d$ }
}	|j                  |d   |d   dz
  dz  dz   t        |      t        j                  |
      ||dz   d       |  y c c}	w w)	Nr   r   r      r      )   cols   nextcol   colors   widths   bcolor)r  r  rf   r  s   rows   nextrow)
r   rt   rg   r   r   rD   r   ri   r   r   )rj   rm   rowr  r  r   r  r  r   edgeedgedatar   r8   s              r"   nodeszgraph.<locals>.nodes  s     3??+09$ 	,C,"dCe''#6E "	  !G $Q#Aw{a/!3"1g#Aw	H 	 LLF"1vzQ.2#F|*66x@ #a	 K1		s   AC'C
;ACr  )r   rp   r   uprevr   r   downrev	graphvarsrows	bg_heightr   r   r  r  r   r   r   )#r2   r3   r   r   rD   rz   r   r   r}   r4   r   r   r   r   r   r   r   rX  r   r   r6   r   r'   r   r   r  r   r  r   r  rw   r   r   ry   r   )r8   r   rp   r   r  r   r   r   r  r   r   r  r  r   r   allrevsr   r   r  r  r  r  r  r  r  r   s   `                     @@@@r"   graphr  2  s|   0 #''"""#''2**377C8hhv
'')CI""Hcgg&&&	377++//XFGH8Q'H=ECHHn-k: yy**>:;HAq1H[yy**>:;H$qLH[ww##K;H		#((++N;<I%IkME
CAuqy!3>2E!S8^$Gsxx(,,S(EBIDIG
by(($$))#q1 	AKKN4yHqL(	
 t9x ,,SXXsxxR7IJKI9Dr(
   8+;+;D+AB 
 ((chh7
 
8 t9D**95,,V4++E2WWY(%   G  		s   1AO2 2	O?>O?c                 |    | d   j                   }|rt        |      j                  d      d   }|S t        d      }|S )Nr      
s   (no help text available))r.   r   	partition)r   docs     r"   _getdocr    sD    
A$,,C
fu%a( J +,Jr$      helpc                    ddl m}m | j                  j                  j                  d      }|sfd}g g cd }|j                  j                         D ]e  \  }}t        |      }d|v s|j                  d      r' ||      }t        |d   d	d
      rj                  ||f       Sj                  ||f       g j                          j                          fd}	fd}
| j                  dt        j                  |      t        j                  |	      t        j                  |
      d      S |j                   v rbg }j                   |   D ]&  \  }}}|j                  d||d   fz  |d   |d       ( | j                  dt        j"                  |      |d      S t$        j&                  j)                         }d|_        d|v r2|j-                  dd      \  }}|j                   vrt/        t0              |}d}	 j3                  ||||      }| j                  d||      S # t4        j6                  $ r t/        t0              w xY w)a  
    /help[/{topic}]
    ---------------

    Render help documentation.

    This web command is roughly equivalent to :hg:`help`. If a ``topic``
    is defined, that help topic will be rendered. If not, an index of
    available help topics will be rendered.

    The ``help`` template will be rendered when requesting help for a topic.
    ``helptopics`` will be rendered for the index of help topics.
    r   )r(   helpr   c              3   V   K   j                   D ]  }|dd \  }}}|d   |d  y w)Nr   r      topicrH  )	helptable)rj   r  r   r\  _dochelpmods        r"   topicszhelp.<locals>.topics  s?     && B)*1Q&$!(AABs   &)c                 *    | j                  d      d   S )N   |r   )r  )ss    r"   r8  zhelp.<locals>.<lambda>  s    AKK-a0 r$   s
   DEPRECATEDs   debugr   	helpbasicFc              3   0   K   D ]  \  }}||d  y wNr  r/   )rj   r  r  earlys      r"   earlycommandszhelp.<locals>.earlycommands  %      53!"445   c              3   0   K   D ]  \  }}||d  y wr  r/   )rj   r  r  others      r"   othercommandszhelp.<locals>.othercommands  r  r  s
   helptopicss   Index)r  r
  r  titles   %s.%s)r  r  rH  T)r  r  subindex   .r   N)subtopicr  )topicr  ) r(   r  r2   r3   r4   tabler  r  rO   r  r'   sortrw   r   ry   	subtopicsr   r   wsgiuiloadverboser   r   r
   help_r   r   )r8   r(   	topicnamer  primaryr  r   r  cmdr
  r  r   r\  r   ur  r  r	  r  r  s                    @@@r"   r  r    sc    -  $$W-I	B
 2u0NN((* 	)DAq!*C#q||H'=!*Cqt[%0c3Z(c3Z(	) 	



	5	5 008&77F&77F   
 	
 G%%%&-&7&7	&B 	"GWdMM&)WQZ)@@!( '	 ++F3	   
 	
 	AAI y $//$2x)))//,mmAxmB G9#>> ;; ,N++,s   H5 5#Ir=  )>r   rJ   r  r  i18nr   r   r   r   commonr   r	   r
   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   utilsr   r   r&   r(   r   r9   r\   r   ro   r   r6   r   r  r   bytesr  rE   r0  rC  rG  r\  rd  r_  ro  r  r5   r  r  r  r  r  valuesi18nfunctionsr/   r$   r"   <module>r'     s     	 	        
 @ F , J'" '"T F G DgT LZ Zz K) ) LN N( j#U u  Kh hV G" "J L( (V K 0 JU Up K- -` z'8$ MJ JZ Kg gT J_ _D JT Tn I" " H\ \~ G]? ]?B !r$   