This will make it easy to process copy from both p1 and p2 in the same
add_from_changes call.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
This will make it easy to process copy from both p1 and p2 in the same
add_from_changes call.
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/copy_tracing.rs (71 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
de26b72bf0b8 | 2af223f08a70 | Pierre-Yves David | Dec 16 2020, 4:01 AM |
changes: &ChangedFiles, | changes: &ChangedFiles, | ||||
parent: Parent, | parent: Parent, | ||||
current_rev: Revision, | current_rev: Revision, | ||||
) -> InternalPathCopies { | ) -> InternalPathCopies { | ||||
let mut copies = base_copies.clone(); | let mut copies = base_copies.clone(); | ||||
for action in changes.iter_actions(parent) { | for action in changes.iter_actions(parent) { | ||||
match action { | match action { | ||||
Action::Copied(path_dest, path_source) => { | Action::Copied(path_dest, path_source) => { | ||||
add_one_copy( | |||||
current_rev, | |||||
&mut path_map, | |||||
&mut copies, | |||||
&base_copies, | |||||
path_dest, | |||||
path_source, | |||||
); | |||||
} | |||||
Action::Removed(deleted_path) => { | |||||
// We must drop copy information for removed file. | |||||
// | |||||
// We need to explicitly record them as dropped to | |||||
// propagate this information when merging two | |||||
// InternalPathCopies object. | |||||
let deleted = path_map.tokenize(deleted_path); | |||||
copies.entry(deleted).and_modify(|old| { | |||||
old.mark_delete(current_rev); | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
copies | |||||
} | |||||
// insert one new copy information in an InternalPathCopies | |||||
// | |||||
// This deal with chaining and overwrite. | |||||
fn add_one_copy( | |||||
current_rev: Revision, | |||||
path_map: &mut TwoWayPathMap, | |||||
copies: &mut InternalPathCopies, | |||||
base_copies: &InternalPathCopies, | |||||
path_dest: &HgPath, | |||||
path_source: &HgPath, | |||||
) { | |||||
let dest = path_map.tokenize(path_dest); | let dest = path_map.tokenize(path_dest); | ||||
let source = path_map.tokenize(path_source); | let source = path_map.tokenize(path_source); | ||||
let entry; | let entry; | ||||
if let Some(v) = base_copies.get(&source) { | if let Some(v) = base_copies.get(&source) { | ||||
entry = match &v.path { | entry = match &v.path { | ||||
Some(path) => Some((*(path)).to_owned()), | Some(path) => Some((*(path)).to_owned()), | ||||
None => Some(source.to_owned()), | None => Some(source.to_owned()), | ||||
} | } | ||||
} else { | } else { | ||||
entry = Some(source.to_owned()); | entry = Some(source.to_owned()); | ||||
} | } | ||||
// Each new entry is introduced by the children, we | // Each new entry is introduced by the children, we | ||||
// record this information as we will need it to take | // record this information as we will need it to take | ||||
// the right decision when merging conflicting copy | // the right decision when merging conflicting copy | ||||
// information. See merge_copies_dict for details. | // information. See merge_copies_dict for details. | ||||
match copies.entry(dest) { | match copies.entry(dest) { | ||||
Entry::Vacant(slot) => { | Entry::Vacant(slot) => { | ||||
let ttpc = CopySource::new(current_rev, entry); | let ttpc = CopySource::new(current_rev, entry); | ||||
slot.insert(ttpc); | slot.insert(ttpc); | ||||
} | } | ||||
Entry::Occupied(mut slot) => { | Entry::Occupied(mut slot) => { | ||||
let ttpc = slot.get_mut(); | let ttpc = slot.get_mut(); | ||||
ttpc.overwrite(current_rev, entry); | ttpc.overwrite(current_rev, entry); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Action::Removed(deleted_path) => { | |||||
// We must drop copy information for removed file. | |||||
// | |||||
// We need to explicitly record them as dropped to | |||||
// propagate this information when merging two | |||||
// InternalPathCopies object. | |||||
let deleted = path_map.tokenize(deleted_path); | |||||
copies.entry(deleted).and_modify(|old| { | |||||
old.mark_delete(current_rev); | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
copies | |||||
} | |||||
/// merge two copies-mapping together, minor and major | /// merge two copies-mapping together, minor and major | ||||
/// | /// | ||||
/// In case of conflict, value from "major" will be picked, unless in some | /// In case of conflict, value from "major" will be picked, unless in some | ||||
/// cases. See inline documentation for details. | /// cases. See inline documentation for details. | ||||
fn merge_copies_dict( | fn merge_copies_dict( | ||||
path_map: &TwoWayPathMap, | path_map: &TwoWayPathMap, | ||||
current_merge: Revision, | current_merge: Revision, |