
    	^cI                         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 ddlmZmZmZ 	 ddZd	 Zd
 Zd ZddZddZd Zd Zd Z G d d          Z ddZ!d Z"d Z#ddZ$d Z%dS )    N   )_)hexshort)bundle2changegroup	discoveryerrorexchangeobsoleteobsutilpathutilphasesrequirementsscmutilutil)hashutil
stringutilurlutilTc                 b   d}| j         }|                    |          s|                    |           |                     d||          }	t	          d |	D                       }
t          j        d                    |
                                                    }d|t          |          t          |dd                   |fz  }t          j        |           }d}|dk    rd	}|rd
}n|rd}nd}t          j        | ||          }||dd}t          j        | j        | d||||||	  	        S )z8create a bundle with the specified revisions as a backups   strip-backups   %ln::%lnc              3   >   K   | ]}|                                 V  d S N)r   .0cs     2/usr/lib/python3/dist-packages/mercurial/repair.py	<genexpr>zbackupbundle.<locals>.<genexpr>2   s*      331quuww333333    r   s   %s/%s-%s-%s.hgN   s   01s   HG20s   BZs   HG10BZs   HG10UN)missingrootsancestorsofT)s
   cg.versions   obsolescences   phases   strip)compression)vfsisdirmkdirsetsortedr   sha1joindigestr   r   r   localversionr	   outgoingr   writenewbundleui)repobasesheadsnodesuffixcompressobsolescence	backupdirr$   
allcommits	allhashes	totalhashname	cgversioncomp
bundletyper-   contentoptss                     r   backupbundler@   &   so   
  I
(C99Y 		) +ue44J33
33333Ichhy112299;;IdIbqbM	  D (..IDE
 	D	 


!$UNNNH % K
 !
 
 
 
r   c                     t                      }t          |t          |                     D ]/}|                    | |                                                    0t          |          S )z+find out the filelogs affected by the strip)r'   rangelenupdatefilesr(   )r0   striprevrE   xs       r   _collectfilesrH   Y   sW    EEE8SYY'' & &T!W]]__%%%%%==r   c                 P                           |          \  }} fd|D             S )Nc                 :    g | ]}                     |          S  )linkrev)r   rrevlogs     r   
<listcomp>z"_collectrevlog.<locals>.<listcomp>e   s%    111!FNN1111r   )getstrippoint)rN   rF   r   	brokensets   `   r   _collectrevlogrR   c   s4    ''11LAy1111y1111r   c                    t                      }t          |           D ]%}|                    t          ||                     &|D ]8}|                    t          |                     |          |                     9|S )z<return the changesets which will be broken by the truncation)r'   manifestrevlogsrD   rR   file)r0   rE   rF   srN   fnames         r   _collectbrokencsetsrX   h   s    A!$'' 3 3	112222 = =			% 0 0(;;<<<<Hr      backupc           
      V  $%&'                                  t          j        d          |dv rd}                                                                 j        }j         j        $t          |t                    r|g}$fd|D             }t          |          }t          |          }t          ||          }	t          |          't          |	          }
$                    |dz             D ]}t          'fd$                    |          D                       r'                    |           |'vrR|	                    |           |
                    $                    |                     |
                    |           $fd|
D             }
|	r7t          $                    |	                    }|	                    |           $fd	|	D             }$fd
'D             }dx}&j                            dd          rt-          j        |          &&r &fdt1          j                  D             }t5          '          \  %}d }|d         }|rt7          |||          }d }|
rt9          ||
|ddd          }|                                 5  	                     d          5 }t          |j                                                   }|!                    |j"                   |#                                 $$                    ||           tK          |||           |D ]+}&                    |          $                    ||           ,|'                                 |(                                }|D ]o\  }}||v r
)                    |dd          5 }|*                    |           d d d            n# 1 swxY w Y   |dk    rj+        ,                    |           pt[          j        |           `.                                 j/        0                               d d d            n# 1 swxY w Y   |rF| 1                    te          d                     |3                    |d          }ti          j5        | |||          }j        j6        sj        7                                ntq          j9                    }|5  d|:                    |          z   }d}t          |tv          j<                  sdt{          j>        |          z  }                    |          5 }tw          j?        ||d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |@                                                     d          5 }%fd|D             } j        A                    ||            d d d            n# 1 swxY w Y   B                                D ]\  }!}"	 |!C                    |"           # t          $ rk}#|#jE        t          jF        k    rL| G                    te          d          |!:                    |"          t          jI        |#          fz             Y d }#~#d }#~#ww xY w	 |r|C                    |           n#  |r8| G                    te          d          |:                    |          z             |rp| G                    te          d           |:                    |          z             | G                    te          d!          |:                    |          z              xY wd d d            n# 1 swxY w Y   J                                 |S )"Ns&   cannot strip from inside a transaction)s   noner"   Fc                 :    g | ]}                     |          S rK   )rev)r   r3   cls     r   rO   zstrip.<locals>.<listcomp>   s#    333$333r   r   )startc              3       K   | ]}|v V  	d S r   rK   )r   ptostrips     r   r   zstrip.<locals>.<genexpr>   s'      66qG|666666r   c                 :    g | ]}                     |          S rK   r3   r   rM   r]   s     r   rO   zstrip.<locals>.<listcomp>   s#    //////r   c                 :    g | ]}                     |          S rK   rc   rd   s     r   rO   zstrip.<locals>.<listcomp>   s#    ......r   c                 :    g | ]}                     |          S rK   rc   rd   s     r   rO   zstrip.<locals>.<listcomp>   s#    ..."''!**...r   rK   s   devels   strip-obsmarkersc                 "    g | ]\  }}|v 	|S rK   rK   )r   im
obsmarkerss      r   rO   zstrip.<locals>.<listcomp>   s)     
 
 
!Qa:ooAooor   s   temp)r5   r6   r"      aT)
checkambigr   s   adding branch
s   rbs   bundle:s   strip
%s)sourceurls   repairc                 H    g | ]}|                                          fS rK   rc   r   ri   newbmtargetr0   s     r   rO   zstrip.<locals>.<listcomp>  s/    MMMqak!2!7!7!9!9:MMMr   s   error removing %s: %s
s+   strip failed, backup bundle stored in '%s'
s1   strip failed, unrecovered changes stored in '%s'
sG   (fix the problem, then recover the changesets with "hg unbundle '%s'")
)Kcurrenttransactionr
   ProgrammingError
unfiltered
destroyingr$   
_bookmarks	changelog
isinstancebytesminrH   rX   r'   revsany
parentrevsadddifference_updatedescendantsr/   
configboolr   exclusivemarkers	enumerateobsstore_bookmarkmovements_createstripbackupr@   uninterruptibletransaction
_offsetmapkeysrD   	_newfiles
startgroupstripstripmanifestrU   endgroupreadjournalsvfstruncatestoremarkremoveddeleteobsmarkersinvalidatevolatilesets_phasecachefilterunknownnoter   openr   
readbundleverbosesilentr   nullcontextmanagerr*   r   
unbundle20r   hidepasswordapplybundlecloseapplychanges	undofilesunlinkOSErrorerrnoENOENTwarnr   forcebytestr	destroyed)(r/   r0   nodelistbackuptopicr$   	striplistrF   rE   saverevs	saveheadsrM   r   	savebases
stripbasesstripobsidxupdatebm
backupfiler3   tmpbundlefiletroldfilesfnentriesrU   troffsetfpfgenmaybe_silenttmpbundleurltxnname	bmchangesundovfsundofileer]   rr   rj   ra   s(    `                                  @@@@r   r   r   t   s	      ,$%NOOO $$$??DOO
(C 	OO	B (E"" :3333(333I9~~H$))E"499H )nnGHIWW8a<W((  6666R]]1%5%566666 	KKNNNGLLOOO''a(8(8999MM!////Y///I  0"..2233"";///....X...I....g...J!!K*w($788 @-dJ??
 

 
 
 
#DM22
 
 
 /tW==KJB<D G'j$FF
M 
 %
 
 
 
				 `* `*_	*!!(++ 5r
 r}113344---2&&&dHb%888 6 6BIIbMM''"5555..**&- 5 5ND(x'' 4$?? .2H---. . . . . . . . . . . . . . .1}}
..t444 <<<M++--- ..t444;5 5 5 5 5 5 5 5 5 5 5 5 5 5 5>  ,--...HH]E22)"aDD  7?3DGNN$$$022 
 " 
 
#-0G0G#GL&G%c7+=>> ".1E(2 2 # ))'22 b+ #r(                 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 			!!),, BMMMMMHMMM	,,T2yAAAB B B B B B B B B B B B B B B
 &*^^%5%5  !
NN8,,,,   w%,..899 'X 6 6 * 7 : :  B  *

=)))-	 EFFhhz**+    KLLhh}--.   3  hh}--	.   y`* `* `* `* `* `* `* `* `* `* `* `* `* `* `*D 	NN s  2^
4[	C7Q O"	Q"O&&Q)O&*A)Q[Q#	#[&Q#	'B[6A!VU=1V=VVVV[V	[V	,[,X 4[ X	[X	[%X;:[;
Z0A!Z+&[+Z00[4^
B/];;^

^^c                    d                      d|          D             }|sdS d}|r|d         }t          |||          }t          |          \  }                    d          5 }	t	          j        |	t          j        |           fd|D             }
j                            |	|
           ddd           n# 1 swxY w Y   |S )z/perform a "soft" strip using the archived phasec                 6    g | ]}|                                 S rK   rc   r   s     r   rO   zsoftstrip.<locals>.<listcomp>6  s     DDDAqvvxxDDDr   s   sort(%ln::)Nr   r"   c                 H    g | ]}|                                          fS rK   rc   rq   s     r   rO   zsoftstrip.<locals>.<listcomp>B  s/    EEEqak*//112EEEr   )	r'   r   r   r   r   retractboundaryarchivedrw   r   )r/   r0   r   r   r   ra   r   r3   r   r   r   rr   s    `         @r   	softstripr   4  s-   DD.(!C!CDDDG tJ Dqz'gtUCC
.tW==K			(	#	# :rtR'BBBEEEEEHEEE	$$T2y999: : : : : : : : : : : : : : : s   -ACC
C
c                 0   | j         }g }|D ];}| ||                                                  }||v r|                    |           <d }|rH|                     d||          }|r-| |                                                                         }nd}||fS )Ns   max(parents(%ld) - (%ld))   .)rw   r\   appendr|   firstr3   )r0   ra   bmr   ri   r\   rr   s          r   r   r   G  s    	BH  2a5koo'>>OOAK   ii <gwOO 	{0022388::KKK  r   c                 D   | j         }| j        }t          | ||                                ||          }| j                            t          d          |                    |          z             | j                            dd|                    |                     |S )Ns   saved backup bundle to %s
s   backupbundle)	r$   rx   r@   r2   r/   statusr   r*   log)r0   r   r3   r   r$   r]   r   s          r   r   r   ]  s    
(C	BdJ

D%HHJGNN1344sxx
7K7KKLLLGKK7*9M9M   r   c           	                                          j        j        fd|D             }d}t                              |||t
          j        |                    }||z
  }|rSd                    t          fd|D                                 }| 	                    t          d          |z             d                     d|          D             S )zDreturn list of roots of nodes where descendants are covered by nodesc                 &    h | ]} |          S rK   rK   )r   ntorevs     r   	<setcomp>z!safestriproots.<locals>.<setcomp>l  s!    $$$EE!HH$$$r   s5   %ld - ( ::( (roots(%ld):: and not _phase(%s)) -%ld) )s   , c              3   f   K   | ]+}t          |                                                   V  ,d S r   )r   r3   )r   r   r0   s     r   r   z!safestriproots.<locals>.<genexpr>u  s7      #L#LaE$q',,..$9$9#L#L#L#L#L#Lr   s9   warning: orphaned descendants detected, not stripping %s
c                 6    g | ]}|                                 S rK   rc   r   s     r   rO   z"safestriproots.<locals>.<listcomp>z  s     ???AFFHH???r   s
   roots(%ld))ru   rx   r\   r'   r|   r   internalr*   r(   r   r   )	r/   r0   nodesr|   revsetra   notstripnodestrr   s	    `      @r   safestriprootsr   i  s    OO'+E$$$$e$$$D
 FF$))FD$FFGGGg~H 
**V#L#L#L#L8#L#L#LLLMM
KLL	
 	
 	
 @?dhh}g>>????r   c                   $    e Zd ZdZd Zd Zd ZdS )stripcallbackz(used as a transaction postclose callbackc                 P    || _         || _        || _        |pd| _        g | _        d S )NrY   )r/   r0   r   r   r   )selfr/   r0   r   r   s        r   __init__zstripcallback.__init__  s.    	'i
r   c                 :    | j                             |           d S r   )r   extend)r   r   s     r   addnodeszstripcallback.addnodes  s    U#####r   c                     t          | j        | j        | j                  }|r)t	          | j        | j        || j        | j                   d S d S r   )r   r/   r0   r   r   r   r   )r   r   rootss      r   __call__zstripcallback.__call__  sR    tw	4=AA 	F$'49eT[$*EEEEE	F 	Fr   N)__name__
__module____qualname____doc__r   r   r   rK   r   r   r   r   }  sL        22  $ $ $F F F F Fr   r   c                 8   |                                 }|s%t          | ||          }t          | ||||          S |                    d          }|)t	          | |||          }|                    d|           |r||_        |                    |           dS )ai  like strip, but works inside transaction and won't strip irreverent revs

    nodelist must explicitly contain all descendants. Otherwise a warning will
    be printed that some nodes are not stripped.

    Will do a backup if `backup` is True. The last non-None "topic" will be
    used as the backup topic name. The default backup topic name is "backup".
    )r   r   s   stripN)rs   r   r   getpostcloser   addpostcloser   r   )r/   r0   r   r   r   r   r   callbacks           r   delayedstripr     s     
	 	 	"	"B Br422RuV5AAAA |,,H T&FFF
h/// hr   c                 V    t          |           D ]}|                    ||           d S r   )rT   r   )r0   rF   r   rE   rN   s        r   r   r     s:    !$'' # #Xr""""# #r   c              #   N  K   | j                             d          V  t          j        |           rp| j                                        D ]X\  }}}|                    d          r;|                    d          r&|dd         }| j                             |          V  Wd S d S )Nr   s   meta/s   00manifest.i   i)manifestlog
getstorager   istreemanifestr   	datafiles
startswithendswith)r0   t	unencodedsizedirs        r   rT   rT     s      


%
%c
*
****d## 7 #'*"6"6"8"8 	7 	7Ay$##H-- 7)2D2D3 3 7  #&&11#666667 7	7 	7r   Fc                 v   |                                 }t          j        |j        vr$|                     t	          d                     dS |                                5  |j        j        }|                    | j                   t          |j
                  }t                      }t                      }|r|D ]}|dd         dk    r||dd         dk    rn|                    |dd                    |                    |           |dd         dz   }|j                            |          r|                    |           n|                     t	          d	          t	          d
          t          |                    }	|D ]}
|	                    |
           ||
         }|                                D ]}||v r|                    |           d|z  }d|z  }|j                            |          r|                    |           |j                            |          r|                    |           |	                                 t          j        |j        v rt'          j        |          D ]j}d|z  }d|z  }|j                            |          r|                    |           |j                            |          r|                    |           kt          ||z
            }t          ||z
            }t+          ||z
            D ]'}|                     t	          d          |z             (t+          ||z
            D ]'}|                     t	          d          |z             (|s|rx|                     t	          d          ||fz             ||_
        d|_        |                    d          5 }|                    |           ddd           n# 1 swxY w Y   n"|                     t	          d                     ddd           dS # 1 swxY w Y   dS )ztRebuilds the fncache file from repo history.

    Missing entries will be added. Extra entries will be removed.
    sE   (not rebuilding fncache because repository does not support fncache)
N)r   r   s   data/s   .is   .ds
   rebuildings
   changesets)unittotals	   data/%s.is	   data/%s.ds   meta/%s/00manifest.is   meta/%s/00manifest.ds   removing %s
s
   adding %s
s(   %d items added, %d removed from fncache
Ts   fncaches   fncache already up to date
)ru   r   FNCACHE_REQUIREMENTr   r   lockr   fncacheensureloadedr'   r   r   _existsmakeprogressrC   rD   rE   completeTREEMANIFEST_REQUIREMENTr   dirsr(   write_dirtyr   )r/   r0   	only_datafnc
oldentries
newentries	seenfilesr   datafprogressr\   ctxrh   dr  addcountremovecountr`   r   s                      r   rebuildfncacher    s   
 ??D't/@@@
& 	
 	
 	
 		 I9 I9j bg&&&%%
UU
EE	 !	   . .RaR5H$$2335MM!AbD'***NN1%%%crcFUNEz))%00 ."u---. -  q'7'7s4yy '  H  * *$$$3i * *AI~~ MM!$$$$q(A$q(Az))!,, *"q)))z))!,, *"q)))* 0D4EEE  }Y// & &+c1+c1:%%a(( &NN1%%%:%%a(( &NN1%%%zJ.//*z122
Z/00 	. 	.AHHQ'((1,----
Z/00 	, 	,AHHQ~&&*++++ 	9{ 	9HH>??[)*   %CKCJ!!*-- 		"               HHQ677888SI9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9 I9s7    M1P.O3'P.3O7	7P.:O7	;&P..P25P2c                 J   |sdS g }| j         }d}t          |          D ]$\  }}||v r|dz  }|                    |           %|                     ddd          }t	          j        |d| j                  D ]}|                    |           |                                 |S )a  Delete some obsmarkers from obsstore and return how many were deleted

    'indices' is a list of ints which are the indices
    of the markers to be deleted.

    Every invocation of this function completely rewrites the obsstore file,
    skipping the markers we want to be removed. The new temporary file is
    created, remaining markers are written there and on .close() this file
    gets atomically renamed to obsstore, thus guaranteeing consistency.Nr   r   s   obsstore   wT)
atomictemp)	_allr   r   r   r   encodemarkers_versionr  r   )	r   indicesleftcurrentr   rh   ri   newobsstorefilerz   s	            r   r   r     s      DmG	A'""  1<<FAAmmK$mGGO'dH4EFF % %e$$$$Hr   )TT)TrY   )NT)F)&r   i18nr   r3   r   r    r   r   r	   r
   r   r   r   r   r   r   r   r   utilsr   r   r   r@   rH   rR   rX   r   r   r   r   r   r   r   r   rT   r  r   rK   r   r   <module>r,     sB                                                     CG0 0 0 0f  2 2 2
	 	 	} } } }@   &! ! !,	 	 	@ @ @(F F F F F F F F&       0# # #

7 
7 
7Y9 Y9 Y9 Y9x    r   