public IBranch ImportBranch(IBranch branch, CollisionHandling collisionHandling) { using (Vault.ExposeReadWrite()) { using (branch.Vault.ExposeReadWrite()) { var existing = GetBranch(branch.Name); if (existing == null) { return(AttachBranch(branch.Clone())); } else { (collisionHandling != CollisionHandling.Error).AssertTrue(); if (collisionHandling == CollisionHandling.Overwrite) { existing.Delete(); return(AttachBranch(branch.Clone())); } else if (collisionHandling == CollisionHandling.Merge) { // atomicity is not guaranteed. sorry branch.GetBranches().ForEach(b => existing.ImportBranch(b, CollisionHandling.Merge)); branch.GetValues().ForEach(v => existing.ImportValue(v, true)); return(this); } else { throw new NotSupportedException(String.Format( "Collision handling strategy '{0}' is not supported.", collisionHandling)); } } } } }
public IBranch ImportBranch(IBranch branch, CollisionHandling collisionHandling) { using (Vault.ExposeReadWrite()) { using (branch.Vault.ExposeReadWrite()) { var existing = GetBranch(branch.Name); if (existing == null) { return AttachBranch(branch.Clone()); } else { (collisionHandling != CollisionHandling.Error).AssertTrue(); if (collisionHandling == CollisionHandling.Overwrite) { existing.Delete(); return AttachBranch(branch.Clone()); } else if (collisionHandling == CollisionHandling.Merge) { // atomicity is not guaranteed. sorry branch.GetBranches().ForEach(b => existing.ImportBranch(b, CollisionHandling.Merge)); branch.GetValues().ForEach(v => existing.ImportValue(v, true)); return this; } else { throw new NotSupportedException(String.Format( "Collision handling strategy '{0}' is not supported.", collisionHandling)); } } } } }