^cddlZddlZddlmZddlmZmZddlmZ m Z GddZ dZ d Zd*d Zd Zd Zd ZdZdZd+dZdZdZdZdZdZdZdZeddZeddZeddZ eddZ!eddZ"eddZ#eddZ$ed dZ%eddZ&ej'd!Z(ej'd"Z)d#Z*d$Z+d%Z,d&Z-d'Z.d(Z/d)Z0dS),N)nullrev)errorutil)flagutilsidedatacxeZdZdZ ddZdZedZej dZ dZ dZ ej d Z d Zd Zej d Zd ZdZej dZdZdZej dZdZdZej dZdZdZej dZdZdZdS) ChangingFilesazA 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: {"": ""} mapping for copies - copied_from_p2: {"": ""} mapping for copies See their inline help for details. Nct|dn||_t|dn||_t|dn||_t|dn||_t|dn||_|j|j|j|j|j|jt|dn||_t|dn||_ dS)N) set_added_merged_removed_touched _salvagedupdatedict _p1_copies _p2_copies)selftouchedaddedremovedmergedsalvaged p1_copies p2_copiess 4/usr/lib/python3/dist-packages/mercurial/metadata.py__init__zChangingFiles.__init__,s ""599 22V<< '/BBw?? '/BBw?? 8#3RRBB T[))) T\*** T]+++Y%6rrIFFY%6rrIFFc|j|jko_|j|jkoO|j|jko?|j|jko/|j|jko|j|jko|j|jkSN)rrrrrcopied_from_p1copied_from_p2)rothers r__eq__zChangingFiles.__eq__As J%+ % < u|+ <  - < / <  -  < #u';;  < #u';; r!cbt|jp|jp|jp |jp|jSr#)boolrrrr$r%rs rhas_copies_infozChangingFiles.has_copies_infoLsG L #{ #} #" #"    r!c*t|jS)aKfiles 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) ) frozensetrr*s rrzChangingFiles.addedVs%%%r!cdt|vr|`|j|||dS)Nr)varsrradd mark_touchedrfilenames r mark_addedzChangingFiles.mark_addedcsF d4jj   !!! (#####r!c:|D]}||dSr#)r4r filenamesfs r update_addedzChangingFiles.update_addedis0  A OOA      r!c*t|jS)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. )r-rr*s rrzChangingFiles.mergedms&&&r!cdt|vr|`|j|||dS)Nr)r/rrr0r1r2s r mark_mergedzChangingFiles.mark_mergedwsH tDzz ! !  """ (#####r!c:|D]}||dSr#)r<r6s r update_mergedzChangingFiles.update_merged}s2  A   Q      r!c*t|jS)afiles 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 )r-rr*s rrzChangingFiles.removedsD'''r!cdt|vr|`|j|||dS)Nr)r/rrr0r1r2s r mark_removedzChangingFiles.mark_removedsH T " "  (### (#####r!c:|D]}||dSr#)rAr6s rupdate_removedzChangingFiles.update_removed2 ! !A   a  ! !r!c*t|jS)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" )r-rr*s rrzChangingFiles.salvageds(((r!cdt|vr|`|j|||dS)Nr)r/rrr0r1r2s r mark_salvagedzChangingFiles.mark_salvagedsH d # #  8$$$ (#####r!c:|D]}||dSr#)rGr6s rupdate_salvagedzChangingFiles.update_salvageds2 " "A   q ! ! ! ! " "r!c*t|jS)z0files either actively modified, added or removed)r-rr*s rrzChangingFiles.toucheds'''r!c`dt|vr|`|j|dS)Nr)r/rrr0r2s rr1zChangingFiles.mark_toucheds4 T " "  (#####r!c:|D]}||dSr#)r1r6s rupdate_touchedzChangingFiles.update_touchedrDr!c4|jSr#)rcopyr*s rr$zChangingFiles.copied_from_p1##%%%r!c@dt|vr|`||j|<dS)Nr$)r/r$rrsourcedests rmark_copied_from_p1z!ChangingFiles.mark_copied_from_p1+ tDzz ) )# &r!cf|D]\}}|||dSr#)itemsrUrcopiesrTrSs rupdate_copies_from_p1z#ChangingFiles.update_copies_from_p1@"LLNN 3 3LD&  $ $VT 2 2 2 2 3 3r!c4|jSr#)rrOr*s rr%zChangingFiles.copied_from_p2rPr!c@dt|vr|`||j|<dS)Nr%)r/r%rrRs rmark_copied_from_p2z!ChangingFiles.mark_copied_from_p2rVr!cf|D]\}}|||dSr#)rXr_rYs rupdate_copies_from_p2z#ChangingFiles.update_copies_from_p2r\r!)NNNNNNN)__name__ __module__ __qualname____doc__r r'propertyr+r propertycacherr4r9rr<r>rrArCrrGrIrr1rMr$rUr[r%r_rar r!rr r s#(GGGG*      X   & & &$$$  '''$$$     !(!(!(F$$$ !!! )))$$$ """ ((($$$ !!! &&&''' 333 &&&''' 33333r!r c|}|}|tkr,|tkrt |S|tkr-|tkrt ||S|tkr/|tkrt ||dS||krt ||St |||S)z'compute the files changed by a revision)parent)p1p2revr _process_root_process_linear_process_merge)ctxrkrls rcompute_all_files_changesrrs B B vvxx7rvvxx722S!!! W  W!4!4r3''' W  W!4!4r3q1111 RVVXX  r3'''b"c***r!c~t}|}|D]}|||S)zEcompute the appropriate changed files for a changeset with no parents)r manifestr4)rqmdrtr3s rrnrnsC B||~~H   h Ir!cjt}|}|}g}||D]w\}}|dd||)|||dd||b||x|dkr|j} n|dkr|j } n Jd|z|D]/}|| } | r| \} } | | |0|S)zJcompute the appropriate changed files for a changeset with a single parentrrNriFzbad parent value %d) r rtdiffrXrAappendr4r1rUr_renamed) parent_ctx children_ctxrjruparent_manifestchildren_manifestcopies_candidater3dcopied copy_inforSsrcnodes rrorosY B ))++O$--//&++,=>>DDFF * * ! Q47? OOH % % % %  # #H - - -tAw h'''')))) {{' 1'4+f4444$%% *2244  %'OFG F68 $ $ $ Ir!c.}t}}|}|}||}||} j||} | stg} fd| D} g} |D]\} | d}|t|| | 1| dd9|dd+| | x| dd$|dd| | dd|dd| dd|ddGtfd| Dr|n|n}|| dd}|tkr|n|| Jd| D]\}t|| || D]}|rv|\}}||vr5|||kr||\||vr4|||kr|||S) ucompute 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. chg|].}|/Sr report.0rrqs r z"_process_merge..s1 2 2 2388::a= ! ! # # 2 2 2r!Nrrc3<K|]}t|duVdSr#_findrmar3s r z!_process_merge..s2IIr5X..d:IIIIIIr!)fileidF unreachable)rr rtrw changelogcommonancestorsheadsnoderrXpop_process_other_unchangedr4rxrAanyrGr1filectxrlrmr<ryfilenoderUr_)p1_ctxp2_ctxrqrrump1mp2mdiff_p1diff_p2cahsmascopy_candidatesd1d2fctxrrSrr3s ` @rrprp-s^ 88::D B A //  C //  ChhqkkGhhqkkG 88::  4 4 v{{}}  D y 2 2 2 2T 2 2 2CO &,&, " [[4 ( ( : $Rh ; ; ; ;!uQxBqE!H$4 h'''&&x0000Aq!beAh&6))))Aq%"Q%(*>a58#r!uQx'7IIIISIIIII2((22221111<<Aq<BBDwwyy}}'111111x000&&x0000,m+++ 88 " S(B7777#99M))++  9'OFGF6N$;$;$=$=$H$H&&vx88886!!fVn&=&=&?&?7&J&J&&vx888 Ir!cD||vrdS||dS)z%return the associate filenode or NoneNrfind)rtr3s rrrs)xt == " "1 %%r!c@|dd|dd}7|5tfd|Dr|dSdS6|4tfd|Dr|dSdS|dSJd)Nrrc3BK|]}t|k VdSr#r)rrr3 source_nodes rrz+_process_other_unchanged..s5DD"5X&&+55DDDDDDr!c3<K|]}t|duVdSr#rrs rrz+_process_other_unchanged..s2==2uR""$.======r!Fr)rrArG)rurr3rw target_noders ` @rrrsq'!*Kq'!*K;#6 DDDDDDDD D D & OOH % % % % % & &  !8 ======= = = '   X & & & & & ' '  [%<  $m###r!c:tfd|DS)Nc3<K|]}t|duVdSr#rrs rrz._missing_from_all_ancestors..s299ruR""d*999999r!all)rr3s `r_missing_from_all_ancestorsr s& 9999S999 9 99r!cg}|D]Dtfd|Ds|E|S)z-return the list of files added in a changesetc3 K|]}|vV dSr#r )rpr8s rrz-computechangesetfilesadded..s'11a16111111r!)filesrparentsrx)rqrr8s @rcomputechangesetfilesaddedrsa E YY[[11113;;==11111  LLOOO Lr!c||\nPtjfdfd}|S)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. Nc}}j||}|stg}fd|DS)Nchg|].}|/Sr rrs rrz3get_removal_filter..mas..Bs1777Q 1 &&((777r!)rrrrr)p1np2nrrqrkrls rrzget_removal_filter..mas;sfggiiggiixxzz#88cBB 9D7777$7777r!cvr(vo#tfdDSvr$tfdDSdS)Nc3xK|]4}|vo+|kV5dSr#r)rrr8m1s rrzAget_removal_filter..deletionfromparent..FsV''9;R4BGGAJJ"''!**4''''''r!c3xK|]4}|vo+|kV5dSr#r)rrr8m2s rrzAget_removal_filter..deletionfromparent..JsELLqBw;2771::#;LLLLLLr!Tr)r8rrrs`rdeletionfromparentz.get_removal_filter..deletionfromparentDs 77B;3'''''?Bsuu'''$$ "WWLLLLLcceeLLLLL L4r!)rkrlrtr cachefunc)rqxrrrrrkrls` @@@@@rget_removal_filterrs2 }BBB VVXX VVXX [[]] [[]] ^888888^8 r!cg}|D]}||vr|||rt|fd|D}|S)z/return the list of files removed in a changesetc*g|]}| |Sr r )rrrfs rrz0computechangesetfilesremoved..Ys&333RRUU31333r!)rrxr)rqrr8rs @rcomputechangesetfilesremovedrQsnG YY[[ C<< NN1   4  $ $3333g333 Nr!cLg}t|dkr|S|D]e}||vr_||}|j|j}|d|jkr||f|S)z.return the list of files merged in a changesetrir)lenrr_filelog _filenodernullidrx)rqrr8rrs rcomputechangesetfilesmergedr]s F 3;;==A YY[[!! 88q6Dm++DN;;GqzSXXZZ... a   Mr!ci}i}|}|}|j}|D]}||r||vr||}|s/|\}} ||vr$||| kr|||<\||vr#||| kr|||<||fS)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}` )rkrl_repo narrowmatchrryr) rqp1copiesp2copiesrkrlrdstrsrcrs rcomputechangesetcopiesrksHH B B)''))Kyy{{   {3 3c>> S!!##   W "99C))++w66HSMM BYY2c7++--88HSM X r!c g}t|D])\}}||vr |d|||fz*t|t|krtjdd|S)Ns%d%ss(some copy targets missing from file list ) enumeraterxrrProgrammingErrorjoin)rrZrXirs r encodecopiesrs EE""773 &== LLa%55 6 6 6 5zzS[[  $ 7    ::e  r!c i}|s|S|dD]6}|d\}}t|}||}|||<7|S#ttf$rYdSwxYw)Nr)splitint ValueError IndexError)rdatarZlstrindexrrrs r decodecopiesrs  ME""  AGGENNMHcH A(CF3KK  #ttsAA AA+*A+ct|}g}t|D]!\}}||vr|d|z"d|S)Ns%dr)r rrxr)rsubsetindicesrr8s rencodefileindicesrs_ [[FG%  &&1 ;; NN519 % % % ::g  r!c g}|s|S|dD]H}t|}|dks|t|krdS|||I|S#tt f$rYdSwxYw)Nrr)rrrrxrr)rrrrrs rdecodefileindicesrs  M 5)) $ $HH A1uuSZZtt MM%( # # # #  #ttsA(AA( A((A=<A=11100ri00100010000110010000101001110z>Lz>bLLct|j}||j||jt |}dt|D}d|d<t t|g}d}|D]}t|}||z }d}||j vr |tz}nO||j vr |tz}n;||jvr |t z}n'||jvr |t$z}n||jvr |t&z}d}||jvr%|t(z}|j|}n-||jvr$|j|}|t,z}||} |t0 ||| ||t4jd|iS)Nci|]\}}|| Sr r )rrr8s r z)encode_files_sidedata..s888!Q1888r!rr!)r rrr$valuesr%sortedr INDEX_HEADERpackrr ADDED_FLAGr MERGED_FLAGr REMOVED_FLAGr SALVAGED_FLAG TOUCHED_FLAGCOPIED_FROM_P1_FLAGgetCOPIED_FROM_P2_FLAGrx INDEX_ENTRYextend sidedatamodSD_FILESr) r all_filesfile_idxchunksfilename_lengthr8 filename_sizeflagrOcopy_idxs rencode_files_sidedatarsEM""I U)0022333 U)0022333y!!I889Y#7#7888HHTNI// 0FO IIA =(    J DD %,   K DD %-   L DD %. M !DD %-   L D $ $ $ ' 'D'++A..DD %& & &'++A..D ' 'DD> k&&t_hGGHHHH MM)  #((6"2"2 33r!ct}|tj}||Sg}g}t |t jksJt |dd}t j}|tj|zz}|}t ||ksJt|D]} t||\} } } | |z } ||| } | |z }t | |ksJ|tjz }| }| | | tztkr| | n| tztkr|| nz| tzt kr|| nQ| tzt$kr|| n(| tzt(kr|| d}| t,zt.kr|j}n| t,zt2kr|j}|| || | f|D]\}} } ||| | |SNr)r rr r rrsize unpack_fromr rangerx ACTION_MASKrr4rr<rrArrGrr1 COPIED_MASKrrUrr_)rrurawrZr  total_filesoffsetfile_offset_basefile_offset_lastidxrfile_endrr3filesizers rdecode_files_sidedatar$s} B ,,{+ , ,C { FI s88|( ( ( ( (**32215K  F!1K!?@' s88' ' ' ' '[!!88#.#:#:3#G#G h$$'01..8}}((((+""#""" +  + + MM( # # # # K ; . . NN8 $ $ $ $ K < / / OOH % % % % K = 0 0   X & & & & K < / / OOH % % % + !4 4 4+FF K #6 6 6+F   MM68X6 7 7 7&,.."(y"H---- Ir!c\||}t|}t||jfSr#)rrrr+)srcrepormrqrs r _getsidedatar',s. #,C %c * *E  ' ')> >>r!cTt||\}}|r tjnd}||dffSr)r' sidedataflagREVIDX_HASCOPIESINFO)rrevlogrmexisting_sidedatarr+ flags_to_adds rcopies_sidedata_computerr.2s8 ,T3 7 7Ho8GN<44QL lA& &&r!c$||}|Qt||}|||f||}|Q|dS)aThe function used by worker precomputing sidedata It read an input queue containing revision numbers It write in an output queue containing (rev, ) 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)acquirerr'putrelease)r& revs_queuesidedata_queuetokensrmrs r_sidedata_workerr68s NN ..  C /GS))C;'''nn /  NNr!2c` ddlm}||j}t j|t z t j}t j |jJ|j D]}| |t|D]}| dg}t|D]L}|| f}t j t|} || | Mi fd} | S)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)targetargsc |d}|? \}}||kr"| |< \}}||k" |\}}d}|r tj}||dffSr)rrr2r)r*) rr+rm old_sidedatarrrr+new_flag sidedataqstagingr5s rsidedata_companionz6_get_worker_sidedata_adder..sidedata_companionzs{{3%% < mmooGAts((! #--//4s(( $(!/  9#8H(A&&r!)r9 _numworkersuimultiprocessingBoundedSemaphoreBUFF_PER_WORKERQueue filternamerrevsr1rProcessr6rxstart)r&destrepor9 nbworkersrevsqrr allworkersr;wrAr?r@r5s @@@r_get_worker_sidedata_adderrRRs\ ""7:..I  -i/.I J JF  ! # #E%''I   % % %  # # % % ! 9   $J 9   62  #+;$ G G G!  G'''''''" r!)rr#)1rEstructrrrBrr revlogutilsrr)rr r rrrnrorprrrrrrrrrrrrrrrrrrrrrrStructrr rr$r'r.r6rGrRr r!rrVs   P3P3P3P3P3P3P3P3f+++$""""J{{{|&&&$$$6:::4444n      4   "&c*a  SQ   c*a  s:q!! J"" s:q!! c$ll c$llc$llv}T"" fmF## $4$4$4N333l??? ''' .99999r!