private void ComputeDiffWithPrevious(DirectoryVersion version, List <KeyValuePair <Element, List <Tuple <Element, string> > > > removedElements, List <KeyValuePair <Element, List <Tuple <Element, string> > > > addedElements) { // we never put (uninteresting) version 0 of a directory element in a changeSet, // but it is still in the ElementBranch.Versions var previousVersion = (DirectoryVersion)version.GetPreviousVersion(); // however, if this is indeed the branching point, then previousVersion may // not correspond to what is currently in the branch, because clearcase branches // are independent for different elements // we don't always use _oldVersions because there may be several successive versions in a single ChangeSet if (previousVersion.VersionNumber == 0) { ElementVersion oldVersion; _oldVersions.TryGetValue(version.Element, out oldVersion); // if there is no oldVersion, it means the whole element has been created after // the branch had been spawned, we consider version the first version (by keeping null for previousVersion) previousVersion = (DirectoryVersion)oldVersion; } if (previousVersion != null) { foreach (var pair in previousVersion.Content) { Element childElement = pair.Value; // an element may appear under different names // KeyValuePair.Equals seems to be slow if (version.Content.Any(p => p.Key == pair.Key && p.Value == pair.Value)) { continue; } var namedInElement = new Tuple <Element, string>(version.Element, pair.Key); if (!addedElements.RemoveFromCollection(childElement, namedInElement)) { removedElements.AddToCollection(childElement, namedInElement); } } } foreach (var pair in version.Content) { if (previousVersion == null || !previousVersion.Content.Any(p => p.Key == pair.Key && p.Value == pair.Value)) { addedElements.AddToCollection(pair.Value, new Tuple <Element, string>(version.Element, pair.Key)); } } }
private void ComputeDiffWithPrevious(DirectoryVersion version, List <KeyValuePair <Element, List <Tuple <Element, string> > > > removedElements, List <KeyValuePair <Element, List <Tuple <Element, string> > > > addedElements) { // we never put (uninteresting) version 0 of a directory element in a changeSet, // but it is still in the ElementBranch.Versions var previousVersion = (DirectoryVersion)version.GetPreviousVersion(); // however, if this is indeed the branching point, then previousVersion may // not correspond to what is currently in the branch, because clearcase branches // are independent for different elements // we don't always use _oldVersions because there may be several successive versions in a single ChangeSet if (previousVersion.VersionNumber == 0) { ElementVersion oldVersion; _oldVersions.TryGetValue(version.Element, out oldVersion); // if there is no oldVersion, it means the whole element has been created after // the branch had been spawned, we consider version the first version (by keeping null for previousVersion) previousVersion = (DirectoryVersion)oldVersion; } if (previousVersion != null) { foreach (var pair in previousVersion.Content) { Element childElement = pair.Value; // an element may appear under different names // KeyValuePair.Equals seems to be slow if (version.Content.Any(p => p.Key == pair.Key && p.Value == pair.Value)) { continue; } var namedInElement = new Tuple <Element, string>(version.Element, pair.Key); if (!addedElements.RemoveFromCollection(childElement, namedInElement)) { removedElements.AddToCollection(childElement, namedInElement); } } } foreach (var pair in version.Content) { if (previousVersion == null || !previousVersion.Content.Any(p => p.Key == pair.Key && p.Value == pair.Value)) { addedElements.AddToCollection(pair.Value, new Tuple <Element, string>(version.Element, pair.Key)); } } foreach (var pair in addedElements) { if (!removedElements.Any(p => p.Key.Oid == pair.Key.Oid)) { continue; } List <Tuple <Element, string> > added = pair.Value; List <Tuple <Element, string> > removed = removedElements.Find(p => p.Key.Oid == pair.Key.Oid).Value; for (int i = added.Count - 1; i >= 0; i--) { Tuple <Element, string> a = added[i]; Tuple <Element, string> matching = removed.Find(r => r.Item1.Oid == a.Item1.Oid && r.Item2 == a.Item2); if (matching != null && previousVersion != null && !previousVersion.Content.Any(p => p.Value == matching.Item1)) { Logger.TraceData(TraceEventType.Warning, (int)TraceId.CreateChangeSet, "Erasing added and at the same time removed version", matching.Item1, matching.Item2); added.RemoveAt(i); removed.Remove(matching); _changeSet.Versions.RemoveAll(v => v.Version.Element.Oid == matching.Item1.Oid); // TODO: Oid -> Name? } } } }