
    q&fm`                     H   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mZmZ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 i Z ej<                  e      Zd Zd Z d Z!d	 Z"d
 Z# ejH                  ede#       d Z%d Z& edddg  ed      fddg  ed      fddd ed      fddg  ed      fddd ed      fddg  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%      fg
e
jN                  z    ed&      d"ejP                  '      d)d(       Z)y)*    N)_)hexshort)bundle2cmdutilcommands	discoveryencodingerrorexchange
extensionshg
narrowspecpathutilpycompat	registrarrepairrepoviewrequirementssparseutilwireprototypes)urlutilc                     t        j                  t        j                  dt              } | d   j                  dddt        d      f       | d   j                  dddt        d      f       | d   j                  dd	dt        d
      f       dt        j                         vrB| d   j                  ddg t        d      f       | d   j                  ddg t        d      f       t        j                  t        j                  dt              } | d   j                  dddt        d      f       t        j                  t        j                  dt               y)z@Wraps user-facing mercurial commands with narrow-aware versions.s   clone          narrowNs%   create a narrow clone of select files   depths0   limit the history fetched by distance from headss
   narrowspecs   read narrowspecs from files   sparses   includes&   specifically fetch this file/directorys   excludes2   do not fetch this file/directory, even if includeds   pulls   archive)
r   wrapcommandr   tableclonenarrowcmdappendr   enabledpullnarrowcmdarchivenarrowcmd)entrys    =/usr/lib/python3/dist-packages/hgext/narrow/narrowcommands.pysetupr(   -   s>    ""8>>8^LE	!HOO	iq!IJK 
!HOOAB		
 
!HOOS-a0M.NOP
**,,a*b!$M"NO	
 	aGH		
 ""8>>7MJE	!HOOAB		
 8>>:7GHr   c                 ^   t        j                         }d   }|rt        j                  j	                  t        j                         |      }|j                  t        d      |z         	 t        j                  |      }t        j                   ||d      \  }
}}|rt        j"                  t        d            t%        j&                  |
       t%        j&                  |       dd<   d	   j)                  |
       d
   j)                  |       d   r fd}t+        j,                  t.        d|      }|5   | ||g|i cddd       S # t        $ rE}	t        j                  t        d      |t        j                  |	j                        fz        d}	~	ww xY w# 1 sw Y   yxY w)zAWraps clone command, so 'hg clone' first wraps localrepo.clone().r   s   reading narrowspec from '%s'
%   cannot read narrowspecs from '%s': %sNr   s9   cannot specify other files using '%include' in narrowspecTnarrowincludeexcludec                 L     | ||       j                  d      r	d   |d<   y y Ndepthr   getorigpullopkwargsoptss      r'   pullbundle2extraprepare_widenz5clonenarrowcmd.<locals>.pullbundle2extraprepare_widen{   s,     xx #'=x  !r   _pullbundle2extraprepare)r   nullcontextmanagerospathjoinr
   getcwdstatusr   readfileIOErrorr   Abort
strtolocalstrerrorr   parseconfigConfigErrorr   validatepatternsextendr   wrappedfunctionr   )r4   uirepoargsr7   wrappedextrapreparenarrowspecfilefilepathfdatainstincludesexcludesprofilesr8   s       `         r'   r!   r!   X   s   113,'N77<< 1>B
		!56AB	MM(+E (.'9'9"eY'O$(H###  	##H-##H- XYx(Yx(H~	1 )8802O
 
 -B,t,t,- -I  	++:;X00?@A 	H- -s%   -E ;F#	F A FF #F,c                     t        j                         }t        j                  |j                  v r fd}t	        j
                  t        d|      }|5   | ||g|i cddd       S # 1 sw Y   yxY w)z2Wraps pull command to allow modifying narrow spec.c                 L     | ||       j                  d      r	d   |d<   y y r/   r1   r3   s      r'   r8   z4pullnarrowcmd.<locals>.pullbundle2extraprepare_widen   s,     xx #'=x  !r   r9   N)r   r:   r   NARROW_REQUIREMENTr   rI   r   )r4   rJ   rK   rL   r7   rM   r8   s       `  r'   r$   r$      su    113&&$*;*;;	1
 )8802O
 
 -B,t,t,- - -s   A++A4c                 2   t         j                  |j                   v ro|j                  \  }}t        |j	                  dg             }t        |j	                  dg             }t        j                  ||||      \  }}}	|r||d<   |r||d<    | ||g|i |S )z5Wraps archive command to narrow the default includes.r,   r-   )r   rW   
narrowpatssetr2   r   restrictpatterns)
r4   rJ   rK   rL   r7   repo_includesrepo_excludesrR   rS   unused_invalids
             r'   r%   r%      s    &&$*;*;;'+$}txx	2./txx	2./-7-H-Hh}.
*(N &DO&DOD(4(4((r   c                    |j                   }t        j                  |j                  vr	 | ||      S t        j                  |j
                  j                         vrt        j                  t        d             | ||       d|d<   |j                  \  }}||d<   ||d<   |r||d<   |r||d<   t        j                  |j
                  j                         v rk|j                  d|j                        D cg c]8  }|j                         |j                  k7  rt!        |j                               : c}|d	<   |d	   s|d	= y y y c c}w )
N%   server does not support narrow clonesTr   s   oldincludepatss   oldexcludepats   includepats   excludepats   ::%ln   known)rK   r   rW   r   	NARROWCAPremotecapabilitiesr   rB   r   rY   ELLIPSESCAP1rZ   commonnodenullidr   )r4   r5   r6   rK   r,   r-   ctxs          r'   pullbundle2extrapreparerm      s9   ;;D&&d.?.??FF##v}}'A'A'CCkk!DEFFF9GW 'F 'F!(~!(~ ""fmm&@&@&BB xx&--8
xxzT[[( 
O
x
 h x 	   C
s   7=Er9   c
           	         ! t        j                  j                  ||      !t        j                  j                  ||       j                         }
t	        j
                  |
||      }| j                  t        d             | j                  t        d      t        d      t        |j                        t        |j                        z         }g }|5  t        j                  |j                  |j                        D ]J  }|j                          t         !fd|
|   j!                         D              s:|j#                  |       L 	 d d d        |
j%                  d|      }t'        j(                  d      }t+        fd||z
  D              }|r| j                  t        d	             d
}| j,                  st        |      |k  r%|D ]  }| j                  dt/        |      z         ! nP|d | D ]  }| j                  dt/        |      z         ! | j                  t        d      t        |      |z
  z         |s)t1        j2                  t        d      t        d            | j5                         5  |r|D cg c]  }|
j6                  j9                  |       }}d   j9                         |v rCt;        j%                  dd   j9                         |            }t=        j>                  |       ddi}|	r| j                  t        d             n| j                  t        d             | jA                  |d      5  tC        jD                  | |
|d|	       d d d        g }jF                  jI                         D ]  }|jJ                  s|jL                  rD  |jN                        r/|j!                         D ]  }|j#                  |jP                          `|jR                  sm|jN                  d d }tU        tW        jX                  |h            |gz   }d}|D ]   } j[                  |      }|sd} n	|dk(  s  n |r|j!                         D ]  }|j#                  |jP                           j]                          j_                  d      5  ja                  ||       |D ]h  }| j                  t        d      |z         tc        jd                  jf                  ji                  |             jF                  jk                  |       j | j                  t        d             jl                  jo                        5  t        jp                  d       t        jr                         d d d        d d d        ju                          d d d        y # 1 sw Y   gxY wc c}w # 1 sw Y   _xY w# 1 sw Y   IxY w# 1 sw Y   MxY w# 1 sw Y   y xY w)N	commonincs,   looking for local changes to affected paths
s
   changesets)topicunittotalc              3   D   K   | ]  } |      xr	  |         y wN ).0fnewmatcholdmatchs     r'   	<genexpr>z_narrow.<locals>.<genexpr>   s#     Lq8A;2x{?2Ls    s   descendants(%ln)s   visiblec              3   T   K   | ]  }j                   j                  |       ! y wru   )	changelogrj   )rw   rrK   s     r'   r{   z_narrow.<locals>.<genexpr>   s%      #$As   %(sT   The following changeset(s) or their ancestors have local changes not on the remote:

      %s
s*   ...and %d more, use --verbose to list all
s   local changes founds*   use --force-delete-local-changes to ignore)hint   .s   (::%n) - %ln + null)   devels   strip-obsmarkersFs%   moving unwanted changesets to backup
s   deleting unwanted changesets
r   )rq   backupTs   alls	   narrowings   deleting %s
s*   deleting unwanted files from working copy
)assumeclean);r   matchroot
unfilteredr	   findcommonoutgoingr?   r   makeprogresslenmissingexcluded	itertoolschain	incrementanyfilesr"   revsr   
filterrevslistverboser   r   
StateErroruninterruptibler}   rj   maxr   cleanconfigoverrider   stripstoredata_entries	is_revlog
is_filelog	target_idunencoded_pathis_manifestlogsortedr   dirsvisitdir
destroyingtransactionsetnarrowpatsr   
unlinkpathsvfsr=   markremoveddirstatechanging_parentsupdateworkingcopycopytoworkingcopy	destroyed)"rJ   rK   rf   rp   oldincludesoldexcludesnewincludesnewexcludesforcer   unfioutgoingprogress
localnodesnrevstostrip
hiddenrevsvisibletostripmaxnodesr~   tostripurev	overridestodeleter&   file_dirr   r,   dvisitrx   ry   rz   s"    `                              @@r'   _narrowr      sH    		;DH		;DH
 ??D++D&INHIIa@AB}(""#c(*;*;&<<  H
 J	 %!1!183D3DE 	%A LDGMMOLL!!!$	%%
 ))/<K$$T:6J )4z)A N 
		6	
 ::^,8# .		'E!H,-. $IX. .		'E!H,-.II@A~&13 ""()DE 
 
			 =7BC!t~~**1-CGCDz G+II.T
)& t$8%@I		!EFG		!=>?""9i8 PRwiOP ZZ,,. 	>E??0!& > (<(<=>%%oocr*hmmSE23se; A$--a0E "' !& > (<(<=>'	>, 	l+ 	3 {K8 *		!,-12		q 12

&&q)*
 IIaFGH//5 3,,TtD,,T23	3 	{= =E% %H D P PN3 3	3 	3]= =s   A$V9 V9W0
"W,B'W0W.AW0=W0?AW0W0AW0.B5W$#-WW$W09WW0W	W0W!W$$W-	)W00W9c                    |j                         t        fdt        j                  D              }|xr& t        j                  v xr t        j
                  v}	fd}
t        j                  t        d|
      }fd}|_	        ddi}|d   }| j                         5  |rlj                  }|j                         |j                         }}|j                        5  |j                  j                   j                          d d d        |	r%|5  t        j"                  ||       d d d        n g }|rJj%                  d	|      D cg c]/  }|j'                         j                   k7  r|j'                         1 }}|j)                         5 }|j+                  d
||d|||d      j-                         }d d d        t        j.                  d|j1                               }|5  j2                  j5                  |d      5  t7        j8                  |j:                  d      }t7        j<                  ||       d d d        d d d        |r,j                        5  |j                         d d d        j;                  d      5  j                  j                        5  j                          t?        j@                         t?        jB                         d d d        d d d        d d d        y # 1 sw Y    xY w# 1 sw Y   xY wc c}w # 1 sw Y   gxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ixY w# 1 sw Y   mxY w# 1 sw Y   y xY w)Nc              3   &   K   | ]  }|v  
 y wru   rv   )rw   cap	remotecaps     r'   r{   z_widen.<locals>.<genexpr>^  s       ys   c                 ,     | ||       |d<   |d<   y )Nra   rb   rv   )r4   r5   r6   r   r   s      r'   r8   z-_widen.<locals>.pullbundle2extraprepare_widenj  s!    VV!,~!,~r   r9   c                  *    j                          y ru   )r   )r   r   rK   s   r'   setnewnarrowpatsz _widen.<locals>.setnewnarrowpatsv  s    ;4r   )r   s   all-warningsFr   )headsrc   s   narrow_widens   03)s   oldincludess   oldexcludess   newincludess   newexcludess	   cgversions   commonheadsrd   s   ellipsess   widen)source)oprf   s   widening)"rg   r   r   SUPPORTED_ELLIPSESCAPrh   ELLIPSESCAPr   rI   r   r   r   r   p1p2r   
setparentsrk   pullrZ   rj   commandexecutorcallcommandresulttransactionmanagerurlrJ   r   r   bundleoperationr   processbundler   r   r   )rJ   rK   rf   rp   r   r   r   r   ellipsesremoteisoldellipsesr8   rM   r   r   ri   dsr   r   knownrl   ebundle	trmanagerr   r   s    `    ``                @r'   _widenr   M  sN     ##%I $2$H$H N 	 	8''94	8&&i7 - %44,.K5 -D,e4Iq\F				 3/BUUWbeegB$$T* 8dkk4;;78$ :dF&9: : E  $xx&9xxzT[[0 HHJ 
 '') Q#(3(3(3(3&+(."'%3	 &(  !33h

I  JDGG229hG J,,)// %%dFr&IJ J $$T* &b"%& k* 	/DMM,J,J-
 	/ !!#((.((.	/ 	/]3/ 3/8 8: :

 $J J J J& &	/ 	/ 	/ 	/]3/ 3/s   )A M5)'LM5L5"M54L'M5*L,/M56M<L9MM52MM5M):;M5M)=M5L	M5L$	 M5,L6	1M59M>MM	
M5M	M5M&"M))M2	.M55M>   trackedr   s
   addincludes   new paths to includes   removeincludes   old paths to no longer includes   auto-remove-includesFs.   automatically choose unused includes to removes
   addexcludes   new paths to excludes   import-ruless   import narrowspecs from a files   removeexcludes   old paths to no longer excludes   clears*   whether to replace the existing narrowspecs   force-delete-local-changess/   forces deletion of local changes when narrowings   backupTs$   back up local changes when narrowings   update-working-copys.   update working copy when the store has changeds   [OPTIONS]... [REMOTE])	inferrepohelpcategoryc                   $ t         j                  |j                   vrt        j                  t	        d            |d   rt        j                  t	        d            |j                  d      }|rt        j                  j                  t        j                         |      }	 t        j                  |      }t#        j$                  | |d      \  }	}
}|rt        j                  t	        d            |d	   j'                  |	       |d
   j'                  |
       t)        j*                  |d	         }t)        j*                  |d         }t)        j*                  |d
         }t)        j*                  |d         }|d   }|d   }|xs |xs |xs |xs
 |xs |xs | }|r|j,                  \  }}| j/                  d       | j1                  dt3        j4                  |            }t7        |      D ]<  }|j9                          |j;                  dddd       |j;                  dd|d       > t7        |      D ]<  }|j9                          |j;                  dddd       |j;                  dd|d       > |j=                          y|j?                         5  |jA                         5  |j,                  \  }}||z  }||z  }||z  }||z  }|xs |}|xs |}|rz|jC                  d      5  |jD                  jG                  |      5  t)        jH                  |       t)        jJ                  |       ddd       ddd       	 ddd       ddd       y|s0|s.|s,| jM                  t	        d             	 ddd       ddd       ytO        jP                  |       tS        jT                  d| |      }| jM                  t	        d      tS        jV                  |jX                        z         t[        j\                  |t3        j4                  |      |      }	 |r>t^        j`                  |jc                         vrt        jd                  t	        d            tg        jh                  ||      }|rOtg        jj                  |||      }| jM                  t	        d             tm               }to        jp                  |jr                  |jt                        D ]$  }|jw                  ||   jy                                & g }t7        |      D ]J  } t)        jz                  |j|                  | g|      $t        $fd |D              r:|j                  |        L |rL|D ]  }!| jM                  d|!z          | j                  t	        d!            dk(  r.|jw                  |       d"}n| jM                  t	        d#             |r(||z
  }"||z  }#t        | ||||||"|#|d$   |d%   
       |"}|#}|r||z  }"||z
  }#t        | ||||||"|#       |j                          	 ddd       ddd       y# t        $ rE}t        j                  t	        d      |t        j                  |j                         fz        d}~ww xY w# 1 sw Y   JxY w# 1 sw Y   OxY w# |j                          w xY w# 1 sw Y   xY w# 1 sw Y   yxY w)&a  show or change the current narrowspec

    With no argument, shows the current narrowspec entries, one per line. Each
    line will be prefixed with 'I' or 'X' for included or excluded patterns,
    respectively.

    The narrowspec is comprised of expressions to match remote files and/or
    directories that should be pulled into your client.
    The narrowspec has *include* and *exclude* expressions, with excludes always
    trumping includes: that is, if a file matches an exclude expression, it will
    be excluded even if it also matches an include expression.
    Excluding files that were never included has no effect.

    Each included or excluded entry is in the format described by
    'hg help patterns'.

    The options allow you to add or remove included and excluded expressions.

    If --clear is specified, then all previous includes and excludes are DROPPED
    and replaced by the new ones specified to --addinclude and --addexclude.
    If --clear is specified without any further options, the narrowspec will be
    empty and will not match any files.

    If --auto-remove-includes is specified, then those includes that don't match
    any files modified by currently visible local commits (those not shared by
    the remote) will be added to the set of explicitly specified includes to
    remove.

    --import-rules accepts a path to a file containing rules, allowing you to
    add --addinclude, --addexclude rules in bulk. Like the other include and
    exclude switches, the changes are applied immediately.
    sJ   the tracked command is only supported on repositories cloned with --narrowclears'   the --clear option is not yet supportedimport_rulesr*   Nr   sJ   including other spec files using '%include' is not supported in narrowspec
addinclude
addexcluderemoveincluderemoveexcludeauto_remove_includesupdate_working_copyr   s   statuss   %s    Is   narrow.included)labels   patr      Xs   narrow.excludedr   s	   narrow-wcs   nothing to widen or narrow
s   comparing with %s
r`   ro   s&   looking for unused includes to remove
c              3   .   K   | ]  } |        y wru   rv   )rw   rx   r   s     r'   r{   ztrackedcmd.<locals>.<genexpr>  s     <AuQx<s   s0   remove these unused includes (Yn)?$$ &Yes $$ &NoTs   found no unused includes
force_delete_local_changesr   )Er   rW   r   
InputErrorr   r2   r;   r<   r=   r
   r>   r   r@   rA   StorageErrorrC   rD   r   rE   rH   r   parsepatternsrY   pager	formatterr   byteskwargsr   	startitemwriteendwlocklockr   r   r   r   r   r?   r   bailifchangedr   get_unique_pull_path_objhidepasswordlocr   peerr   re   rg   rB   r	   findcommonincomingr   rZ   r   r   r   r   updater   r   r   r   r"   promptchoicer   r   close)%rJ   rK   
remotepathpatsr7   newrulesrO   rP   rQ   includepatsexcludepatsrT   addedincludesremovedincludesaddedexcludesremovedexcludesautoremoveincludesr   	only_showr   r   fmiwidening	narrowingr<   rf   rp   r   
localfilesr   suggestedremovalsr,   sr   r   r   s%                                       @r'   
trackedcmdr     s   Z &&d.?.??5
 	
 G}q!KLMM xx'H77<< 18<	MM(+E .4-?-?y.
*[( ""6  	\!!+.\!!+.,,T,-?@M ..tO/DEO,,T,-?@M ..tO/DEO4545 			 	 		
 	 I #'?? [
\\)X%9%9$%?@$ 	CALLNHHY4FHGHHVWa/AHB	C $ 	CALLNHHY4FHGHHVWa/AHB	C 		 otyy{ o#'?? [ 	$;&$;& 3O#4}	!!,/ 31O1O2 3 ,,T2,,T2	3 3
 'o o o* I);IIa789/o o o2 	d#
 //
B
K
		!*+g.B.B488.LLMx33D94@M	
 ",,F4G4G4IIkk!$L"MNN!44T6BI!$77&I 		!FGH U
")9)98;L;LM 7A%%d1gmmo67$&!%k2 :G&,,TYY	;OE<<<)009: %. /		'A+./ !2  (../@A$(	IIa =>?)O;)M956N *))M9)O;	 LLN_o ob I  	$$:;X00?@A 	B3 3 3 3B LLN_o o ob s   %X0 Z</AZ02Z+Z	9Z	Z0
Z<!Z0<Z<BZ0D,ZCZZ0Z<0	Y>9A Y99Y>ZZZZ0Z--Z00Z9	5Z<<[ru   )*r   r;   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mercurial.utilsr   r    commandr(   r!   r$   r%   rm   wrapfunctionr   r   
remoteoptsCATEGORY_MAINTENANCEr   rv   r   r'   <module>r)     s    	      * 	
)

E
"(IV/-d-$) !> 
  (*A
zzd/P 		mR#:!;<	A&G$HI#?@		
 
mR#:!;<	osA&G$HI	A&G$HI;<		
 )@A		
 56		
 "?@		
=$J K%L --U+XXY+XXr   