##// END OF EJS Templates
copies-rust: move the mapping merging into a else clause...
marmoute -
r46742:94300498 default
parent child Browse files
Show More
@@ -464,73 +464,74 b' fn merge_copies_dict<A: Fn(Revision, Rev'
464 oracle: &mut AncestorOracle<A>,
464 oracle: &mut AncestorOracle<A>,
465 ) -> TimeStampedPathCopies {
465 ) -> TimeStampedPathCopies {
466 if minor.is_empty() {
466 if minor.is_empty() {
467 return major;
467 major
468 } else if major.is_empty() {
468 } else if major.is_empty() {
469 return minor;
469 minor
470 }
470 } else {
471 let mut override_minor = Vec::new();
471 let mut override_minor = Vec::new();
472 let mut override_major = Vec::new();
472 let mut override_major = Vec::new();
473
473
474 let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
474 let mut to_major = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
475 override_major.push((k.clone(), v.clone()))
475 override_major.push((k.clone(), v.clone()))
476 };
476 };
477 let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
477 let mut to_minor = |k: &HgPathBuf, v: &TimeStampedPathCopy| {
478 override_minor.push((k.clone(), v.clone()))
478 override_minor.push((k.clone(), v.clone()))
479 };
479 };
480
480
481 // The diff function leverage detection of the identical subpart if minor
481 // The diff function leverage detection of the identical subpart if
482 // and major has some common ancestors. This make it very fast is most
482 // minor and major has some common ancestors. This make it very
483 // case.
483 // fast is most case.
484 //
484 //
485 // In case where the two map are vastly different in size, the current
485 // In case where the two map are vastly different in size, the current
486 // approach is still slowish because the iteration will iterate over
486 // approach is still slowish because the iteration will iterate over
487 // all the "exclusive" content of the larger on. This situation can be
487 // all the "exclusive" content of the larger on. This situation can be
488 // frequent when the subgraph of revision we are processing has a lot
488 // frequent when the subgraph of revision we are processing has a lot
489 // of roots. Each roots adding they own fully new map to the mix (and
489 // of roots. Each roots adding they own fully new map to the mix (and
490 // likely a small map, if the path from the root to the "main path" is
490 // likely a small map, if the path from the root to the "main path" is
491 // small.
491 // small.
492 //
492 //
493 // We could do better by detecting such situation and processing them
493 // We could do better by detecting such situation and processing them
494 // differently.
494 // differently.
495 for d in minor.diff(&major) {
495 for d in minor.diff(&major) {
496 match d {
496 match d {
497 DiffItem::Add(k, v) => to_minor(k, v),
497 DiffItem::Add(k, v) => to_minor(k, v),
498 DiffItem::Remove(k, v) => to_major(k, v),
498 DiffItem::Remove(k, v) => to_major(k, v),
499 DiffItem::Update { old, new } => {
499 DiffItem::Update { old, new } => {
500 let (dest, src_major) = new;
500 let (dest, src_major) = new;
501 let (_, src_minor) = old;
501 let (_, src_minor) = old;
502 match compare_value(
502 match compare_value(
503 changes, oracle, dest, src_minor, src_major,
503 changes, oracle, dest, src_minor, src_major,
504 ) {
504 ) {
505 MergePick::Major => to_minor(dest, src_major),
505 MergePick::Major => to_minor(dest, src_major),
506 MergePick::Minor => to_major(dest, src_minor),
506 MergePick::Minor => to_major(dest, src_minor),
507 // If the two entry are identical, no need to do
507 // If the two entry are identical, no need to do
508 // anything (but diff should not have yield them)
508 // anything (but diff should not have yield them)
509 MergePick::Any => unreachable!(),
509 MergePick::Any => unreachable!(),
510 }
510 }
511 }
511 }
512 };
512 };
513 }
513 }
514
514
515 let updates;
515 let updates;
516 let mut result;
516 let mut result;
517 if override_major.is_empty() {
517 if override_major.is_empty() {
518 result = major
518 result = major
519 } else if override_minor.is_empty() {
519 } else if override_minor.is_empty() {
520 result = minor
520 result = minor
521 } else {
522 if override_minor.len() < override_major.len() {
523 updates = override_minor;
524 result = minor;
525 } else {
521 } else {
526 updates = override_major;
522 if override_minor.len() < override_major.len() {
527 result = major;
523 updates = override_minor;
524 result = minor;
525 } else {
526 updates = override_major;
527 result = major;
528 }
529 for (k, v) in updates {
530 result.insert(k, v);
531 }
528 }
532 }
529 for (k, v) in updates {
533 result
530 result.insert(k, v);
531 }
532 }
534 }
533 result
534 }
535 }
535
536
536 /// represent the side that should prevail when merging two
537 /// represent the side that should prevail when merging two
General Comments 0
You need to be logged in to leave comments. Login now