
    6h                        S SK Jr  S SKrS SKrSSKJr  SSKJrJr  SSK	J
rJr   " S S5      rS	 rS
 rS+S jrS rS rS rS rS rS,S jrS rS rS rS rS rS rS r\" SS5      r \" SS5      r!\" SS5      r"\" SS5      r#\" SS5      r$\" SS5      r%\" S S5      r&\" S!S5      r'\" S S5      r(\RR                  " S"5      r*\RR                  " S#5      r+S$ r,S% r-S& r.S' r/S( r0S)r1S* r2g)-    )annotationsN   )nullrev)errorutil)flagutilsidedatac                     \ rS rSrSr       SS jrS r\S 5       r\	R                  S 5       rS rS	 r\	R                  S
 5       rS rS r\	R                  S 5       rS rS r\	R                  S 5       rS rS r\	R                  S 5       rS rS r\	R                  S 5       rS rS r\	R                  S 5       rS rS rSr g)ChangingFiles   aN  A class recording the changes made to files by a changeset

Actions performed on files are gathered into 3 sets:

- added:   files actively added in the changeset.
- merged:  files whose history got merged
- removed: files removed in the revision
- salvaged: files that might have been deleted by a merge but were not
- touched: files affected by the merge

and copies information is held by 2 mappings

- copied_from_p1: {"<new-name>": "<source-name-in-p1>"} mapping for copies
- copied_from_p2: {"<new-name>": "<source-name-in-p2>"} mapping for copies

See their inline help for details.
Nc                   [        Uc  SOU5      U l        [        Uc  SOU5      U l        [        Uc  SOU5      U l        [        Uc  SOU5      U l        [        Uc  SOU5      U l        U R                  R                  U R                  5        U R                  R                  U R                  5        U R                  R                  U R                  5        [        Uc  SOU5      U l        [        Uc  SOU5      U l	        g )N )
set_added_merged_removed_touched	_salvagedupdatedict
_p1_copies
_p2_copies)selftouchedaddedremovedmergedsalvaged	p1_copies	p2_copiess           4/usr/lib/python3/dist-packages/mercurial/metadata.py__init__ChangingFiles.__init__-   s     "592V<'/Bw?'/Bw?8#3RBT[[)T\\*T]]+Y%6rIFY%6rIF    c                   U R                   UR                   :H  =(       a    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ N)r   r   r   r   r   copied_from_p1copied_from_p2)r   others     r!   __eq__ChangingFiles.__eq__B   s    JJ%++% <u||+<-< /< -	<
 ##u';';;< ##u';';;	
r$   c                    [        U R                  =(       dE    U R                  =(       d2    U R                  =(       d    U R                  =(       d    U R
                  5      $ r&   )boolr   r   r   r'   r(   r   s    r!   has_copies_infoChangingFiles.has_copies_infoM   sN    LL #{{#}}# ""# ""
 	
r$   c                ,    [        U R                  5      $ )a  files actively added in the changeset

Any file present in that revision that was absent in all the changeset's
parents.

In case of merge, this means a file absent in one of the parents but
existing in the other will *not* be contained in this set. (They were
added by an ancestor)
)	frozensetr   r.   s    r!   r   ChangingFiles.addedW   s     %%r$   c                ~    S[        U 5      ;   a  U ?U R                  R                  U5        U R	                  U5        g )Nr   )varsr   r   addmark_touchedr   filenames     r!   
mark_addedChangingFiles.mark_addedd   s1    d4j 
!(#r$   c                8    U H  nU R                  U5        M     g r&   )r:   r   	filenamesfs      r!   update_addedChangingFiles.update_addedj   s    AOOA r$   c                ,    [        U R                  5      $ )zfiles actively merged during a merge

Any modified files which had modification on both size that needed merging.

In this case a new filenode was created and it has two parents.
)r2   r   r.   s    r!   r   ChangingFiles.mergedn   s     &&r$   c                ~    S[        U 5      ;   a  U ?U R                  R                  U5        U R	                  U5        g )Nr   )r5   r   r   r6   r7   r8   s     r!   mark_mergedChangingFiles.mark_mergedx   s3    tDz!"(#r$   c                8    U H  nU R                  U5        M     g r&   )rE   r=   s      r!   update_mergedChangingFiles.update_merged~   s    AQ r$   c                ,    [        U R                  5      $ )aW  files actively removed by the changeset

In case of merge this will only contain the set of files removing "new"
content. For any file absent in the current changeset:

a) If the file exists in both parents, it is clearly "actively" removed
by this changeset.

b) If a file exists in only one parent and in none of the common
ancestors, then the file was newly added in one of the merged branches
and then got "actively" removed.

c) If a file exists in only one parent and at least one of the common
ancestors using the same filenode, then the file was unchanged on one
side and deleted on the other side. The merge "passively" propagated
that deletion, but didn't "actively" remove the file. In this case the
file is *not* included in the `removed` set.

d) If a file exists in only one parent and at least one of the common
ancestors using a different filenode, then the file was changed on one
side and removed on the other side. The merge process "actively"
decided to drop the new change and delete the file. Unlike in the
previous case, (c), the file included in the `removed` set.

Summary table for merge:

case | exists in parents | exists in gca || removed
 (a) |       both        |     *         ||   yes
 (b) |       one         |     none      ||   yes
 (c) |       one         | same filenode ||   no
 (d) |       one         |  new filenode ||   yes
)r2   r   r.   s    r!   r   ChangingFiles.removed   s    D ''r$   c                ~    S[        U 5      ;   a  U ?U R                  R                  U5        U R	                  U5        g )Nr   )r5   r   r   r6   r7   r8   s     r!   mark_removedChangingFiles.mark_removed   s3    T
"(#(#r$   c                8    U H  nU R                  U5        M     g r&   )rM   r=   s      r!   update_removedChangingFiles.update_removed       Aa  r$   c                ,    [        U R                  5      $ )a  files that might have been deleted by a merge, but still exists.

During a merge, the manifest merging might select some files for
removal, or for a removed/changed conflict. If at commit time the file
still exists, its removal was "reverted" and the file is "salvaged"
)r2   r   r.   s    r!   r   ChangingFiles.salvaged   s     ((r$   c                ~    S[        U 5      ;   a  U ?U R                  R                  U5        U R	                  U5        g )Nr   )r5   r   r   r6   r7   r8   s     r!   mark_salvagedChangingFiles.mark_salvaged   s3    d#8$(#r$   c                8    U H  nU R                  U5        M     g r&   )rV   r=   s      r!   update_salvagedChangingFiles.update_salvaged   s    Aq! r$   c                ,    [        U R                  5      $ )z0files either actively modified, added or removed)r2   r   r.   s    r!   r   ChangingFiles.touched   s     ''r$   c                \    S[        U 5      ;   a  U ?U R                  R                  U5        g )Nr   )r5   r   r   r6   r8   s     r!   r7   ChangingFiles.mark_touched   s%    T
"(#r$   c                8    U H  nU R                  U5        M     g r&   )r7   r=   s      r!   update_touchedChangingFiles.update_touched   rR   r$   c                6    U R                   R                  5       $ r&   )r   copyr.   s    r!   r'   ChangingFiles.copied_from_p1       ##%%r$   c                B    S[        U 5      ;   a  U ?XR                  U'   g )Nr'   )r5   r'   r   r   sourcedests      r!   mark_copied_from_p1!ChangingFiles.mark_copied_from_p1        tDz)# &r$   c                X    UR                  5        H  u  p#U R                  X25        M     g r&   )itemsrj   r   copiesri   rh   s       r!   update_copies_from_p1#ChangingFiles.update_copies_from_p1   "    "LLNLD$$V2 +r$   c                6    U R                   R                  5       $ r&   )r   rc   r.   s    r!   r(   ChangingFiles.copied_from_p2   re   r$   c                B    S[        U 5      ;   a  U ?XR                  U'   g )Nr(   )r5   r(   r   rg   s      r!   mark_copied_from_p2!ChangingFiles.mark_copied_from_p2   rl   r$   c                X    UR                  5        H  u  p#U R                  X25        M     g r&   )rn   rw   ro   s       r!   update_copies_from_p2#ChangingFiles.update_copies_from_p2   rs   r$   )r   r   r   r   r   r   r   )NNNNNNN)!__name__
__module____qualname____firstlineno____doc__r"   r*   propertyr/   r   propertycacher   r:   r@   r   rE   rH   r   rM   rP   r   rV   rY   r   r7   r`   r'   rj   rq   r(   rw   rz   __static_attributes__r   r$   r!   r   r      s:   ( G*	
 
 
 

& 
&$ 
' '$  
!( !(F$! 
) )$" 
( ($
! 
& &'
3 
& &'
3r$   r   c                   U R                  5       nU R                  5       nUR                  5       [        :X  a#  UR                  5       [        :X  a  [	        U 5      $ UR                  5       [        :w  a#  UR                  5       [        :X  a  [        X5      $ UR                  5       [        :X  a"  UR                  5       [        :w  a
  [        X SS9$ UR                  5       UR                  5       :X  a  [        X5      $ [        XU 5      $ )z'compute the files changed by a revision   )parent)p1p2revr   _process_root_process_linear_process_merge)ctxr   r   s      r!   compute_all_files_changesr      s    	B	B	vvx7rvvx72S!!	W	W!4r''	W	W!4rq11	RVVX	r''bc**r$   c                n    [        5       nU R                  5       nU H  nUR                  U5        M     U$ )zEcompute the appropriate changed files for a changeset with no parents)r   manifestr:   )r   mdr   r9   s       r!   r   r      s1     
B||~H
h Ir$   c                "   [        5       nU R                  5       nUR                  5       n/ nUR                  U5      R                  5        H_  u  pxUS   S   c  UR	                  U5        M!  UR                  U5        US   S   c  UR                  U5        MN  UR                  U5        Ma     US:X  a  UR                  n	OUS:X  a  UR                  n	O
 SU-  5       eU H*  nX   R                  5       n
U
(       d  M  U
u  pU	" X5        M,     U$ )zJcompute the appropriate changed files for a changeset with a single parentr   r   r   zbad parent value %d)r   r   diffrn   rM   appendr:   r7   rj   rw   renamed)
parent_ctxchildren_ctxr   r   parent_manifestchildren_manifestcopies_candidater9   dcopied	copy_inforh   srcnodes                r!   r   r   	  s   	B ))+O$--/&++,=>DDFQ47?OOH%##H-tAwh' ) G {''	1''4+f44u$ *224	9'OF6$	 % Ir$   c                H  ^ UR                  5       n[        5       nUR                  5       nU R                  5       nUR                  5       nUR                  U5      nUR                  U5      n	UR                  5       R                  R                  U R                  5       UR                  5       5      n
U
(       d  [        /n
U
 Vs/ s H#  oR                  5       U   R                  5       PM%     nn/ nUR                  5        GH_  u  mnU	R                  TS5      nUc  [        XLTU5        M+  US   S   c-  US   S   c$  UR                  T5        UR                  T5        Ma  US   S   c  US   S   c  UR                  T5        M  US   S   b  US   S   b  US   S   b	  US   S   c>  [        U4S jU 5       5      (       a  UR                  T5        OqUR!                  T5        O_UR#                  TUS   S   S9nUR%                  5       R'                  5       [        :X  a  UR!                  T5        OUR)                  T5        UR                  T5        GM[   S5       e   U	R                  5        H  u  mn[        XLTU5        M     U H  mUT   R+                  5       nU(       d  M  Uu  nnUU ;   a+  U U   R-                  5       U:X  a  UR/                  UT5        MU  UU;   d  M]  UU   R-                  5       U:X  d  Mv  UR1                  UT5        M     U$ s  snf )u_  compute the appropriate changed files for a changeset with two parents

This is a more advance case. The information we need to record is summarise
in the following table:

┌──────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
│ diff ╲  diff │       ø      │ (Some, None) │ (None, Some) │ (Some, Some) │
│  p2   ╲  p1  │              │              │              │              │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│              │              │🄱  No Changes │🄳  No Changes │              │
│  ø           │🄰  No Changes │      OR      │     OR       │🄵  No Changes │
│              │              │🄲  Deleted[1] │🄴  Salvaged[2]│     [3]      │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│              │🄶  No Changes │              │              │              │
│ (Some, None) │      OR      │🄻  Deleted    │       ø      │      ø       │
│              │🄷  Deleted[1] │              │              │              │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│              │🄸  No Changes │              │              │   🄽 Touched  │
│ (None, Some) │     OR       │      ø       │🄼   Added     │OR 🅀 Salvaged │
│              │🄹  Salvaged[2]│              │   (copied?)  │   (copied?)  │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│              │              │              │   🄾 Touched  │   🄿 Merged   │
│ (Some, Some) │🄺  No Changes │      ø       │OR 🅁 Salvaged │OR 🅂 Touched  │
│              │     [3]      │              │   (copied?)  │   (copied?)  │
└──────────────┴──────────────┴──────────────┴──────────────┴──────────────┘

Special case [1]:

  The situation is:
    - parent-A:     file exists,
    - parent-B:     no file,
    - working-copy: no file.

  Detecting a "deletion" will depend on the presence of actual change on
  the "parent-A" branch:

  Subcase 🄱 or 🄶 : if the state of the file in "parent-A" is unchanged
  compared to the merge ancestors, then parent-A branch left the file
  untouched while parent-B deleted it. We simply apply the change from
  "parent-B" branch the file was automatically dropped.
  The result is:
      - file is not recorded as touched by the merge.

  Subcase 🄲 or 🄷 : otherwise, the change from parent-A branch were explicitly dropped and
  the file was "deleted again". From a user perspective, the message
  about "locally changed" while "remotely deleted" (or the other way
  around) was issued and the user chose to deleted the file.
  The result:
      - file is recorded as touched by the merge.


Special case [2]:

  The situation is:
    - parent-A:     no file,
    - parent-B:     file,
    - working-copy: file (same content as parent-B).

  There are three subcases depending on the ancestors contents:

  - A) the file is missing in all ancestors,
  - B) at least one ancestor has the file with filenode ≠ from parent-B,
  - C) all ancestors use the same filenode as parent-B,

  Subcase (A) is the simpler, nothing happend on parent-A side while
  parent-B added it.

    The result:
        - the file is not marked as touched by the merge.

  Subcase (B) is the counter part of "Special case [1]", the file was
    modified on parent-B side, while parent-A side deleted it. However this
    time, the conflict was solved by keeping the file (and its
    modification). We consider the file as "salvaged".

    The result:
        - the file is marked as "salvaged" by the merge.

  Subcase (C) is subtle variation of the case above. In this case, the
    file in unchanged on the parent-B side and actively removed on the
    parent-A side. So the merge machinery correctly decide it should be
    removed. However, the file was explicitly restored to its parent-B
    content before the merge was commited. The file is be marked
    as salvaged too. From the merge result perspective, this is similar to
    Subcase (B), however from the merge resolution perspective they differ
    since in (C), there was some conflict not obvious solution to the
    merge (That got reversed)

Special case [3]:

  The situation is:
    - parent-A:     file,
    - parent-B:     file (different filenode as parent-A),
    - working-copy: file (same filenode as parent-B).

  This case is in theory much simple, for this to happens, this mean the
  filenode in parent-A is purely replacing the one in parent-B (either a
  descendant, or a full new file history, see changeset). So the merge
  introduce no changes, and the file is not affected by the merge...

  However, in the wild it is possible to find commit with the above is not
  True. For example repository have some commit where the *new* node is an
  ancestor of the node in parent-A, or where parent-A and parent-B are two
  branches of the same file history, yet not merge-filenode were created
  (while the "merge" should have led to a "modification").

  Detecting such cases (and not recording the file as modified) would be a
  nice bonus. However do not any of this yet.
Nr   r   c              3  @   >#    U  H  n[        UT5      S Lv   M     g 7fr&   _find.0mar9   s     r!   	<genexpr>!_process_merge.<locals>.<genexpr>  s     ISr5X.d:S   )fileidunreachable)repor   r   r   	changelogcommonancestorsheadsnoder   rn   pop_process_other_unchangedr:   r   rM   anyrV   r7   filectxr   r   rE   r   filenoderj   rw   )p1_ctxp2_ctxr   r   r   mp1mp2mdiff_p1diff_p2cahsrmascopy_candidatesd1d2fctxr   rh   r   r9   s                       @r!   r   r   .  s   ^ 88:D	BA
//
C
//
ChhqkGhhqkG88:44v{{}D y-1
2T88:a=!!#TC
2O  "[[4(:$Rh;!uQxBqE!H$4h'&&x0Aq!beAh&6)Aq%"Q%(*>a58#r!uQx'7ISIII((2 1<<Aq<BDwwy}}'1 1 x0&&x0 ,m+uI (P  " (B7 ( $M))+	9'OFGF6N$;$;$=$H&&vx86!fVn&=&=&?7&J&&vx8 $ Iy 3s   *Lc                6    X;  a  gU R                  U5      S   $ )z%return the associate filenode or NoneNr   find)r   r9   s     r!   r   r     s    =="1%%r$   c                  ^^ US   S   mUS   S   nTb1  Uc.  [        UU4S jU 5       5      (       a  U R                  T5        g g Tc0  Ub-  [        U4S jU 5       5      (       a  U R                  T5        g g Tb  Ub  g  S5       e)Nr   r   c              3  D   >#    U  H  n[        UT5      T:X  + v   M     g 7fr&   r   )r   r   r9   source_nodes     r!   r   +_process_other_unchanged.<locals>.<genexpr>  s     D"5X&+5s    c              3  @   >#    U  H  n[        UT5      S Lv   M     g 7fr&   r   r   s     r!   r   r     s     =2uR"$.r   r   )r   rM   rV   )r   r   r9   r   target_noder   s     `  @r!   r   r     s    q'!*Kq'!*K;#6DDDDOOH% E 
	!8====X& > 
	 [%< 	 	$m#ur$   c                .   ^ [        U4S jU  5       5      $ )Nc              3  @   >#    U  H  n[        UT5      S L v   M     g 7fr&   r   r   s     r!   r   ._missing_from_all_ancestors.<locals>.<genexpr>  s     9SruR"d*Sr   all)r   r9   s    `r!   _missing_from_all_ancestorsr     s    9S999r$   c                   ^ / nU R                  5        H>  m[        U4S jU R                  5        5       5      (       a  M-  UR                  T5        M@     U$ )z-return the list of files added in a changesetc              3  .   >#    U  H
  nTU;   v   M     g 7fr&   r   )r   pr?   s     r!   r   -computechangesetfilesadded.<locals>.<genexpr>  s     1=a16=s   )filesr   parentsr   )r   r   r?   s     @r!   computechangesetfilesaddedr     sA    EYY[13;;=111LLO  Lr$   c                   ^ ^^^^^ Ub  Uu  mmmmO@T R                  5       mT R                  5       mTR                  5       mTR                  5       m[        R                  U UU4S j5       mUUU4S jnU$ )a  return a function to detect files "wrongly" detected as `removed`

When a file is removed relative to p1 in a merge, this
function determines whether the absence is due to a
deletion from a parent, or whether the merge commit
itself deletes the file. We decide this by doing a
simplified three way merge of the manifest entry for
the file. There are two ways we decide the merge
itself didn't delete a file:
- neither parent (nor the merge) contain the file
- exactly one parent contains the file, and that
  parent has the same filelog entry as the merge
  ancestor (or all of them if there two). In other
  words, that parent left the file unchanged while the
  other one deleted it.
One way to think about this is that deleting a file is
similar to emptying it, so the list of changed files
should be similar either way. The computation
described above is not done directly in _filecommit
when creating the list of changed files, however
it does something very similar by comparing filelog
nodes.
c                    > TR                  5       n TR                  5       nTR                  5       R                  R                  X5      nU(       d  [        /nU Vs/ s H$  nTR                  5       U   R                  5       PM&     sn$ s  snf r&   )r   r   r   r   r   r   )p1np2nr   r   r   r   r   s       r!   r   get_removal_filter.<locals>.mas:  sj    ggiggixxz##88B9D267$Q
1&&($777s   +Bc                   >^  T T;   a'  T T;  =(       a    [        U U4S jT" 5        5       5      $ T T;   a  [        U U4S jT" 5        5       5      $ g)Nc              3     >#    U  H4  nTU;   =(       a#    UR                  T5      TR                  T5      :H  v   M6     g 7fr&   r   )r   r   r?   m1s     r!   r   Aget_removal_filter.<locals>.deletionfromparent.<locals>.<genexpr>E  s5      '?DR4BGGAJ"''!*44u   <?c              3     >#    U  H4  nTU;   =(       a#    UR                  T5      TR                  T5      :H  v   M6     g 7fr&   r   )r   r   r?   m2s     r!   r   r   I  s2     LeqBw;2771:#;;er   Tr   )r?   r   r   r   s   `r!   deletionfromparent.get_removal_filter.<locals>.deletionfromparentC  sP    7B; 3 '?Bu' $  "WLceLLLr$   )r   r   r   r   	cachefunc)r   xr   r   r   r   r   r   s   `  @@@@@r!   get_removal_filterr     sf    2 	}BBVVXVVX[[][[]	^^8 8 r$   c                    / nU R                  5        H  nX ;  d  M
  UR                  U5        M     U(       a+  [        U 5      nU Vs/ s H  oC" U5      (       a  M  UPM     nnU$ s  snf )z/return the list of files removed in a changeset)r   r   r   )r   r   r?   rfr   s        r!   computechangesetfilesremovedr   P  s[    GYY[<NN1  $%3gRU1g3N 4s   A&A&c                >   / n[        U R                  5       5      S:  a  U$ U R                  5        Hg  nX ;   d  M
  X   nUR                  R                  UR                  5      nUS   U R                  5       R                  :w  d  MV  UR                  U5        Mi     U$ )z.return the list of files merged in a changesetr   r   )lenr   r   _filelog	_filenoder   nullidr   )r   r   r?   r   r   s        r!   computechangesetfilesmergedr   \  s~    F
3;;=AYY[86Dmm++DNN;GqzSXXZ...a   Mr$   c                   0 n0 nU R                  5       nU R                  5       nU R                  R                  5       nU R	                  5        Hz  nU" U5      (       a  X`;  a  M  X   R                  5       nU(       d  M2  Uu  pX;   a  X8   R                  5       U	:X  a  XU'   MW  X;   d  M^  XH   R                  5       U	:X  d  Mv  XU'   M|     X4$ )zreturn the copies data for a changeset

The copies data are returned as a pair of dictionnary (p1copies, p2copies).

Each dictionnary are in the form: `{newname: oldname}`
)r   r   _reponarrowmatchr   r   r   )
r   p1copiesp2copiesr   r   r   dstr   srcr   s
             r!   computechangesetcopiesr   j  s     HH	B	B))'')Kyy{33>!!#9))+w6SMY27++-8SM  r$   c                    / n[        U 5       H$  u  p4XA;   d  M  UR                  SX1U   4-  5        M&     [        U5      [        U5      :w  a  [        R                  " S5      eSR                  U5      $ )Ns   %d %ss(   some copy targets missing from file list   
)	enumerater   r   r   ProgrammingErrorjoin)r   rp   rn   ir   s        r!   encodecopiesr     sn    EE"=LLa%556 # 5zS[ $$7
 	
 ::er$   c                     0 nU(       d  U$ UR                  S5       H)  nUR                  S5      u  pE[        U5      nX   nXRU'   M+     U$ ! [        [        4 a     g f = f)Nr       )splitint
ValueError
IndexError)r   datarp   lstrindexr   r   r   s           r!   decodecopiesr
    sm    ME"AGGENMHHA(C3K	 #
 
#  s   
A ?A A A c                    [        U5      n/ n[        U 5       H   u  p4XA;   d  M  UR                  SU-  5        M"     SR                  U5      $ )Ns   %dr   )r   r   r   r   )r   subsetindicesr   r?   s        r!   encodefileindicesr    sG    [FG% ;NN519% ! ::gr$   c                     / nU(       d  U$ UR                  S5       H8  n[        U5      nUS:  d  U[        U 5      :  a    g UR                  X   5        M:     U$ ! [        [
        4 a     g f = f)Nr   r   )r  r  r   r   r  r  )r   r  r  r	  r   s        r!   decodefileindicesr    sr    M

5)HHA1uSZMM%(#	 *
 
#  s   
A 5A A A/.A/11100r   00100010000110010000101001110z>Lz>bLLc                4   [        U R                  5      nUR                  U R                  R	                  5       5        UR                  U R
                  R	                  5       5        [        U5      n[        U5       VVs0 s H  u  p#X2_M	     nnnSUS '   [        R                  [        U5      5      /nSnU GH#  n[        U5      nXg-  nSnX0R                  ;   a
  U[        -  nOcX0R                  ;   a
  U[        -  nOJX0R                  ;   a
  U[         -  nO1X0R"                  ;   a
  U[$        -  nOX0R                  ;   a	  U[&        -  nS n	X0R                  ;   a%  U[(        -  nU R                  R+                  U5      n	O3X0R
                  ;   a$  U R
                  R+                  U5      n	U[,        -  nXI   n
UR/                  [0        R                  XU
5      5        GM&     UR3                  U5        [4        R6                  SR9                  U5      0$ s  snnf )Nr   r$   )r   r   r   r'   valuesr(   sortedr   INDEX_HEADERpackr   r   
ADDED_FLAGr   MERGED_FLAGr   REMOVED_FLAGr   SALVAGED_FLAGTOUCHED_FLAGCOPIED_FROM_P1_FLAGgetCOPIED_FROM_P2_FLAGr   INDEX_ENTRYextendsidedatamodSD_FILESr   )r   	all_filesr   r?   file_idxchunksfilename_lengthfilename_sizeflagrc   copy_idxs              r!   encode_files_sidedatar1    s   EMM"IU))0023U))0023y!I#,Y#78#7!#7H8HTNI/0FOA(JD,,KD--L D.. M!D--L D$$$''D''++A.D&&&''++A.D''D>k&&thGH/ 0 MM)  #((6"233? 9s   Hc                `   [        5       nU R                  [        R                  5      nUc  U$ / n/ n[	        U5      [
        R                  :  d   e[
        R                  US5      S   n[
        R                  nU[        R                  U-  -   nUn[	        U5      U:  d   e[        U5       GHc  n	[        R                  X&5      u  pnX-  nX(U nX-
  n[	        U5      U:X  d   eU[        R                  -  nUnUR                  U5        U
[        -  [        :X  a  UR                  U5        OU
[        -  [        :X  a  UR                  U5        OhU
[        -  [         :X  a  UR#                  U5        OEU
[        -  [$        :X  a  UR'                  U5        O"U
[        -  [(        :X  a  UR+                  U5        S nU
[,        -  [.        :X  a  UR0                  nOU
[,        -  [2        :X  a  UR4                  nUc  GMP  UR                  XU45        GMf     U H  u  pnU" XL   U5        M     U$ Nr   )r   r$  r(  r)  r   r  sizeunpack_fromr&  ranger   ACTION_MASKr  r:   r  rE   r   rM   r!  rV   r"  r7   COPIED_MASKr#  rj   r%  rw   )r	   r   rawrp   r*  total_filesoffsetfile_offset_basefile_offset_lastidxr/  file_endr0  r9   filesizer   s                   r!   decode_files_sidedatarA    s    	B
,,{++
,C
{	FIs8|(((((**3215KF!1!1K!?@'s8''''[!#.#:#:3#G $1.8}(((+"""#"++MM(#K;.NN8$K</OOH%K=0X&K</OOH%+!44++FK#66++FMM6X677 ": '-"(y"H- '- Ir$   c                N    X   n[        U5      n[        U5      UR                  4$ r&   )r   r1  r/   )srcrepor   r   r   s       r!   _getsidedatarD  +  s)    
,C%c*E ')>)>>>r$   c                X    [        X5      u  pEU(       a  [        R                  OSnXFS44$ r3  )rD  sidedataflagREVIDX_HASCOPIESINFO)r   revlogr   existing_sidedatar	   r/   flags_to_adds          r!   copies_sidedata_computerrK  1  s,     ,T 7H8G<44QLA&&&r$   c                    UR                  5         UR                  5       nUbB  [        X5      nUR                  XE45        UR                  5         UR                  5       nUb  MB  UR	                  5         g)a  The function used by worker precomputing sidedata

It read an input queue containing revision numbers
It write in an output queue containing (rev, <sidedata-map>)

The `None` input value is used as a stop signal.

The `tokens` semaphore is user to avoid having too many unprocessed
entries. The workers needs to acquire one token before fetching a task.
They will be released by the consumer of the produced data.
N)acquirer$  rD  putrelease)rC  
revs_queuesidedata_queuetokensr   r  s         r!   _sidedata_workerrS  7  sb     NN
..
C
/G)C;'nn	 / NNr$   2   c                ^  ^^^ SSK Jn  UR                  U R                  5      n[        R
                  " U[        -  5      m[        R                  " 5       n[        R                  " 5       mU R                  b   eU R                  R                  5        H  nUR                  U5        M     [        U5       H  nUR                  S5        M     / n[        U5       HB  nXTT4n[        R                  " [        US9n	UR                  U	5        U	R!                  5         MD     0 mUUU4S jn
U
$ )zThe parallel version of the sidedata computation

This code spawn a pool of worker that precompute a buffer of sidedata
before we actually need themr   )workerN)targetargsc                   > T
R                  US 5      nUc5  T	R                  5       u  pTXR:w  a  UT
U'   T	R                  5       u  pTXR:w  a  M  TR                  5         Uu  pgSnU(       a  [        R                  nXhS44$ r3  )r   r$  rO  rF  rG  )r   rH  r   old_sidedatar  r   r	   r/   new_flag	sidedataqstagingrR  s            r!   sidedata_companion6_get_worker_sidedata_adder.<locals>.sidedata_companiony  s}    {{3%<  mmoGA(!
#--/ ( 	$(!#88HA&&r$   ) rV  _numworkersuimultiprocessingBoundedSemaphoreBUFF_PER_WORKERQueue
filternamer   revsrN  r6  ProcessrS  r   start)rC  destreporV  	nbworkersrevsqr   r   
allworkersrX  wr^  r\  r]  rR  s              @@@r!   _get_worker_sidedata_adderrp  Q  s    ""7::.I--i/.IJF!!#E%%'I%%% ##%		! & 9		$  J9	62##+;$G!			  G'" r$   )r   r&   )3
__future__r   rc  structr   r   r`  r   r   revlogutilsr   rF  r	   r(  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r  r7  r  r  r   r!  r"  r8  r#  r%  Structr  r&  r1  rA  rD  rK  rS  re  rp  r   r$   r!   <module>ru     s0   #   
P3 P3f+$"Jyx&$6:4n	4	"& *a Q
*a :q!J":q!$l$l $l  }}T"mmF#$4N3l?'. 9r$   