comparison rust/hg-core/src/copy_tracing.rs @ 45990:2367937982ba

copies-rust: encapsulate internal sets on `changes` The goal is to eventually stop creating the underlying set. So we need to encapsulate the call first. Differential Revision: https://phab.mercurial-scm.org/D9306
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 05 Oct 2020 01:49:04 +0200
parents 10bb0856bb9f
children e0313b0a6f7e
comparison
equal deleted inserted replaced
45989:10bb0856bb9f 45990:2367937982ba
45 /// not matters) 45 /// not matters)
46 Removed(&'a HgPath), 46 Removed(&'a HgPath),
47 /// The parent ? children edge introduce copy information between (dest, 47 /// The parent ? children edge introduce copy information between (dest,
48 /// source) 48 /// source)
49 Copied(&'a HgPath, &'a HgPath), 49 Copied(&'a HgPath, &'a HgPath),
50 }
51
52 /// This express the possible "special" case we can get in a merge
53 ///
54 /// See mercurial/metadata.py for details on these values.
55 #[derive(PartialEq)]
56 enum MergeCase {
57 /// Merged: file had history on both side that needed to be merged
58 Merged,
59 /// Salvaged: file was candidate for deletion, but survived the merge
60 Salvaged,
61 /// Normal: Not one of the two cases above
62 Normal,
50 } 63 }
51 64
52 impl ChangedFiles { 65 impl ChangedFiles {
53 pub fn new( 66 pub fn new(
54 removed: HashSet<HgPathBuf>, 67 removed: HashSet<HgPathBuf>,
85 }; 98 };
86 let remove_iter = self.removed.iter(); 99 let remove_iter = self.removed.iter();
87 let copies_iter = copies_iter.map(|(x, y)| Action::Copied(x, y)); 100 let copies_iter = copies_iter.map(|(x, y)| Action::Copied(x, y));
88 let remove_iter = remove_iter.map(|x| Action::Removed(x)); 101 let remove_iter = remove_iter.map(|x| Action::Removed(x));
89 copies_iter.chain(remove_iter) 102 copies_iter.chain(remove_iter)
103 }
104
105 /// return the MergeCase value associated with a filename
106 fn get_merge_case(&self, path: &HgPath) -> MergeCase {
107 if self.salvaged.contains(path) {
108 return MergeCase::Salvaged;
109 } else if self.merged.contains(path) {
110 return MergeCase::Merged;
111 } else {
112 return MergeCase::Normal;
113 }
90 } 114 }
91 } 115 }
92 116
93 /// A struct responsible for answering "is X ancestors of Y" quickly 117 /// A struct responsible for answering "is X ancestors of Y" quickly
94 /// 118 ///
320 } else if src_major.rev == src_minor.rev { 344 } else if src_major.rev == src_minor.rev {
321 // We cannot get copy information for both p1 and p2 in the 345 // We cannot get copy information for both p1 and p2 in the
322 // same rev. So this is the same value. 346 // same rev. So this is the same value.
323 unreachable!(); 347 unreachable!();
324 } else { 348 } else {
349 let action = changes.get_merge_case(&dest);
325 if src_major.path.is_none() 350 if src_major.path.is_none()
326 && changes.salvaged.contains(dest) 351 && action == MergeCase::Salvaged
327 { 352 {
328 // If the file is "deleted" in the major side but was 353 // If the file is "deleted" in the major side but was
329 // salvaged by the merge, we keep the minor side alive 354 // salvaged by the merge, we keep the minor side alive
330 pick_minor(); 355 pick_minor();
331 } else if src_minor.path.is_none() 356 } else if src_minor.path.is_none()
332 && changes.salvaged.contains(dest) 357 && action == MergeCase::Salvaged
333 { 358 {
334 // If the file is "deleted" in the minor side but was 359 // If the file is "deleted" in the minor side but was
335 // salvaged by the merge, unconditionnaly preserve the 360 // salvaged by the merge, unconditionnaly preserve the
336 // major side. 361 // major side.
337 pick_major(); 362 pick_major();
338 } else if changes.merged.contains(dest) { 363 } else if action == MergeCase::Merged {
339 // If the file was actively merged, copy information 364 // If the file was actively merged, copy information
340 // from each side might conflict. The major side will 365 // from each side might conflict. The major side will
341 // win such conflict. 366 // win such conflict.
342 pick_major(); 367 pick_major();
343 } else if oracle.is_ancestor(src_major.rev, src_minor.rev) 368 } else if oracle.is_ancestor(src_major.rev, src_minor.rev)