o ]LbM@sddlmZmZddlZddlZddlmZddlmZm Z ddl m Z m ZGdddeZd d Zd d ZdAd dZddZddZddZddZddZdBddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Z e!d)d*Z"e!d+d*Z#e!d,d*Z$e!d-d*Z%e!d.d*Z&e!d/d*Z'e!d0d*Z(e!d1d*Z)e!d0d*Z*e+d2Z,e+d3Z-d4d5Z.d6d7Z/d8d9Z0d:d;Z1dZ3d?d@Z4dS)C)absolute_importprint_functionN)nullrev)errorutil)flagutilsidedatac@seZdZdZ       d3ddZddZeddZej d d Z d d Z d dZ ej ddZ ddZddZej ddZddZddZej ddZddZdd Zej d!d"Zd#d$Zd%d&Zej d'd(Zd)d*Zd+d,Zej d-d.Zd/d0Zd1d2ZdS)4 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. NcCst|durdn||_t|durdn||_t|durdn||_t|dur(dn||_t|dur3dn||_|j|j|j|j|j|jt|durSdn||_t|dur^dn||_ dS)N) set_added_merged_removed_touched _salvagedupdatedict _p1_copies _p2_copies)selftouchedaddedremovedmergedsalvaged p1_copies p2_copiesr r 4/usr/lib/python3/dist-packages/mercurial/metadata.py__init__-s zChangingFiles.__init__cCsT|j|jko)|j|jko)|j|jko)|j|jko)|j|jko)|j|jko)|j|jkSN)rrrrrcopied_from_p1copied_from_p2)rotherr r r__eq__Bs       zChangingFiles.__eq__cCs"t|jp|jp|jp|jp|jSr )boolrrrr!r"rr r rhas_copies_infoMszChangingFiles.has_copies_infocC 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) ) frozensetr r&r r rrWs zChangingFiles.addedcC*dt|vr|`|j|||dS)Nr)varsrr add mark_touchedrfilenamer r r mark_addedd  zChangingFiles.mark_addedcC|D]}||qdSr )r0r filenamesfr r r update_addedj zChangingFiles.update_addedcCr()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&r r rrn zChangingFiles.mergedcCr*)Nr)r+rrr,r-r.r r r mark_mergedxr1zChangingFiles.mark_mergedcCr2r )r9r3r r r update_merged~r7zChangingFiles.update_mergedcCr()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&r r rrs "zChangingFiles.removedcCr*)Nr)r+rrr,r-r.r r r mark_removedr1zChangingFiles.mark_removedcCr2r )r;r3r r rupdate_removedr7zChangingFiles.update_removedcCr()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&r r rrr8zChangingFiles.salvagedcCr*)Nr)r+rrr,r-r.r r r mark_salvagedr1zChangingFiles.mark_salvagedcCr2r )r=r3r r rupdate_salvagedr7zChangingFiles.update_salvagedcCr()z0files either actively modified, added or removed)r)rr&r r rrs zChangingFiles.touchedcCs dt|vr|`|j|dS)Nr)r+rrr,r.r r rr-s zChangingFiles.mark_touchedcCr2r )r-r3r r rupdate_touchedr7zChangingFiles.update_touchedcC |jSr )rcopyr&r r rr! zChangingFiles.copied_from_p1cCdt|vr|`||j|<dS)Nr!)r+r!rrsourcedestr r rmark_copied_from_p1 z!ChangingFiles.mark_copied_from_p1cC"|D] \}}|||qdSr )itemsrGrcopiesrFrEr r rupdate_copies_from_p1z#ChangingFiles.update_copies_from_p1cCr@r )rrAr&r r rr"rBzChangingFiles.copied_from_p2cCrC)Nr")r+r"rrDr r rmark_copied_from_p2rHz!ChangingFiles.mark_copied_from_p2cCrIr )rJrOrKr r rupdate_copies_from_p2rNz#ChangingFiles.update_copies_from_p2)NNNNNNN)__name__ __module__ __qualname____doc__rr$propertyr'r propertycacherr0r6rr9r:rr;r<rr=r>rr-r?r!rGrMr"rOrPr r r rr sR       #      r cCs|}|}|tkr|tkrt|S|tkr)|tkr)t||S|tkr<|tkr| ddduro|ddduro| | q>| dddur|dddur| q>| dddur|dddur| dddus|dddurtfdd| Dr|n$|n|j| ddd}|tkr|n|| q>Jd | D] \}t || |q| D]8}|r.|\}}||vr|||kr||q||vr.|||kr.||q|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. cg|] }|qSr reporb.0rr`r r z"_process_merge..Nrrc3|] }t|duVqdSr _findrtmar/r r z!_process_merge..)fileidF unreachable)rrr rbrd changelogcommonancestorsheadsnoderrJpop_process_other_unchangedr0rer;anyr=r-filectxrZr[r9rffilenoderGrO)p1_ctxp2_ctxr`rrrcmp1mp2mdiff_p1diff_p2cahsmascopy_candidatesd1d2fctxrnrEror )r`r/rr^.s\o                   r^cCs||vrdS||dS)z%return the associate filenode or NoneNrfind)rbr/r r rr{sr{cs|dd|dd}dur)|dur)tfdd|Dr'|dSdSdurE|durEtfdd|DrC|dSdSdurO|durOdSJd)Nrrc3s |] }t|k VqdSr rzr|r/ source_noder rrsz+_process_other_unchanged..c3ryr rzr|r~r rrrFr)rr;r=)rcrr/rd target_noder rrrs  rcstfdd|DS)Nc3s|] }t|duVqdSr rzr|r~r rrrz._missing_from_all_ancestors..all)rr/r r~r_missing_from_all_ancestorssrcs:g}|D]tfdd|Ds|q|S)z-return the list of files added in a changesetc3s|]}|vVqdSr r )rtpr5r rrsz-computechangesetfilesadded..)filesrparentsre)r`rr rrcomputechangesetfilesaddeds   rcs`|dur |\ntjfddfdd}|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. Ncs>}}j||}|stg}fdd|DS)Ncrpr rqrsrvr rrwCrxz3get_removal_filter..mas..)rrrrrr)p1np2nrr_r rr<s zget_removal_filter..mascsPvrvotfddDSvr&tfddDSdS)Nc3,|]}|vo|kVqdSr rr|)r5m1r rrGs zAget_removal_filter..deletionfromparent..c3rr rr|)r5m2r rrKs*Trr)rrrrrdeletionfromparentEsz.get_removal_filter..deletionfromparent)rYrZrbr cachefunc)r`xrr )r`rrrrYrZrget_removal_filters rcsFg}|D] }||vr||q|r!t|fdd|D}|S)z/return the list of files removed in a changesetcsg|]}|s|qSr r rsrfr rrwZsz0computechangesetfilesremoved..)rrer)r`rr5r rrcomputechangesetfilesremovedRs  rcCsdg}t|dkr |S|D]}||vr/||}|j|j}|d|jkr/||q|S)z.return the list of files merged in a changesetrWr)lenrr_filelog _filenoderrnullidre)r`rr5rrr r rcomputechangesetfilesmerged^s  rc Csi}i}|}|}|j}|D]9}||r||vr q||}|s)q|\}} ||vr>||| kr>|||<q||vrN||| krN|||<q||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}` )rYrZ_repo narrowmatchrrfr) r`p1copiesp2copiesrYrZrdstrmsrcror r rcomputechangesetcopiesls$    rcCsXg}t|D]\}}||vr|d|||fqt|t|kr'tdd|S)Ns%d%ss(some copy targets missing from file list ) enumeratererrProgrammingErrorjoin)rrLrJirr r r encodecopiess rc Csdz%i}|s|WS|dD]}|d\}}t|}||}|||<q |WSttfy1YdSw)Nr)splitint ValueError IndexError)rdatarLlstrindexrrrr r r decodecopiess rcCs>t|}g}t|D]\}}||vr|d|q d|S)Ns%dr)r rrer)rsubsetindicesrr5r r rencodefileindicess rc Cspz+g}|s|WS|dD]}t|}|dks|t|kr!WdS|||q |WSttfy7YdSw)Nrr)rrrrerr)rrrrrr r rdecodefileindicessr11100rW00100010000110010000101001110z>Lz>bLLc CsXt|j}||j||jt|}ddt|D}d|d<t t |g}d}|D]l}t |}||7}d}||j vrH|t O}n'||j vrR|tO}n||jvr\|tO}n||jvrf|tO}n ||jvro|tO}d}||jvr|tO}|j|}n||jvr|j|}|tO}||} |t ||| q2||tjd|iS)NcSsi|]\}}||qSr r )rtrr5r r r sz)encode_files_sidedata..r)r rrr!valuesr"sortedr INDEX_HEADERpackrr ADDED_FLAGr MERGED_FLAGr REMOVED_FLAGr SALVAGED_FLAG TOUCHED_FLAGCOPIED_FROM_P1_FLAGgetCOPIED_FROM_P2_FLAGre INDEX_ENTRYextend sidedatamodSD_FILESr) r all_filesfile_idxchunksfilename_lengthr5 filename_sizeflagrAcopy_idxr r rencode_files_sidedatasB              rcCst}|tj}|dur|Sg}g}t|tjksJt|dd}tj}|tj|}|}t||ks8Jt |D]} t||\} } } | |7} ||| } | |}t| |ks]J|tj7}| }| | | t @t kru| | n/| t @tkr|| n#| t @tkr|| n| t @tkr|| n | t @tkr|| d}| t@tkr|j}n | t@tkr|j}|dur| || | fq<|D] \}} } ||| | q|SNr)r rrrrrsize unpack_fromrrangere ACTION_MASKrr0rr9rr;rr=rr- COPIED_MASKrrGrrO)r rcrawrLr total_filesoffsetfile_offset_basefile_offset_lastidxrfile_endrr/filesizermr r rdecode_files_sidedatasT                 rcCs||}t|}t||jfSr )rarr')srcrepor[r`rr r r _getsidedata-srcCs(t||\}}|r tjnd}||dffSr)r sidedataflagREVIDX_HASCOPIESINFO)rrrevlogr[existing_sidedatar r' flags_to_addr r rcopies_sidedata_computer3s rcCsT||}|dur$t||}|||f||}|dus |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)acquirerrputrelease)r revs_queuesidedata_queuetokensr[rr r r_sidedata_worker9s   r2c sddlm}||j}t|tt}t|jdus"J|j D]}| |q't |D]}| dq3g}t |D]}||f}tj t|d} || | qAifdd} | 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 sn|d}|dur"\}}||kr"||<\}}||ks|\}}d}|r1tj}||dffSr)rrr rr) rrrr[ old_sidedatarrur r'new_flag sidedataqstagingrr rsidedata_companion{s    z6_get_worker_sidedata_adder..sidedata_companion)r _numworkersuimultiprocessingBoundedSemaphoreBUFF_PER_WORKERQueue filternamerrevsr rProcessrrestart) rdestrepor nbworkersrevsqrur allworkersrwrr rr_get_worker_sidedata_adderSs&         r*)rr )5 __future__rrrstructrrrrr revlogutilsrrr robjectr rar\r]r^r{rrrrrrrrrrrrrrrrrrrrrStructrrrrrrrrr*r r r rsV T %? 7             '6