Exemple #1
0
        private void initializeTfsClient()
        {
            TfsTeamProjectCollection tfsServer = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationService.ServerUrl));

            if (!TfsUtil.IsTfs2010Server(tfsServer))
            {
                throw new MigrationException(string.Format("The target server {0} is not a TFS2010 server", ConfigurationService.ServerUrl));
            }
            m_tfsClient = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));
            m_analysisServiceContainer.AddService(typeof(VersionControlServer), m_tfsClient);
        }
Exemple #2
0
        public void Add(BatchedItem change)
        {
            if (change == null)
            {
                throw new ArgumentNullException("change");
            }

            lock (m_locker)
            {
                if (!acceptingNewChanges)
                {
                    Debug.Fail("ChangeOprimizer is not accepting new changes");
                }

                if (change.Action == WellKnownChangeActionId.Rename)
                {
                    bool addToRenameList = true;
                    foreach (BatchedItem existingRenameChange in m_unresolvedRenames)
                    {
                        if (TfsUtil.isChildItemOf(change, existingRenameChange))
                        {
                            addToRenameList = false;
                            break;
                        }
                    }
                    if (addToRenameList)
                    {
                        m_unresolvedRenames.Add(change);
                    }
                    else
                    {
                        m_implicitRenames.Add(change.Target);
                    }

                    if (!m_renamePairs.ContainsKey(change.Target))
                    {
                        m_renamePairs.Add(change.Target, change.Source);
                    }
                }
                else if ((change.Action == WellKnownChangeActionId.Branch) ||
                         (change.Action == WellKnownChangeActionId.Add) ||
                         (change.Action == WellKnownChangeActionId.Undelete))
                {
                    m_unresolvedAdditiveActions.Add(change);
                }
                else
                {
                    // Deletes, Edits or Encodings
                    m_unresolvedChanges.Add(change);
                }
            }
        }
Exemple #3
0
        private static void deleteFiles_inner(string directory)
        {
            foreach (string file in Directory.GetFiles(directory))
            {
                TfsUtil.DeleteFile(file);
            }

            foreach (string subDirectory in Directory.GetDirectories(directory))
            {
                deleteFiles_inner(subDirectory);
                Directory.Delete(subDirectory);
            }
        }
Exemple #4
0
        private void initializeTfsClient()
        {
            TfsTeamProjectCollection tfsServer = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationService.ServerUrl));

            if (!TfsUtil.IsTfs2010Server(tfsServer))
            {
                throw new MigrationException(string.Format("The target server {0} is not a TFS2010 server", ConfigurationService.ServerUrl));
            }

            tfsServer.EnsureAuthenticated();
            TraceManager.TraceInformation("Authenticated User for Uri {0} is '{1}'", tfsServer.Uri, tfsServer.AuthorizedIdentity.DisplayName);

            m_tfsClient = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));
            m_analysisServiceContainer.AddService(typeof(VersionControlServer), m_tfsClient);
        }
Exemple #5
0
        private int[] getMappedTfsChange()
        {
            m_hwmDelta.Reload();


            Debug.Assert(m_hwmDelta.Value >= 0, "High water mark of delta table must be non-negtive");

            int latestChangeset = m_tfsClient.GetLatestChangesetId();

            // No new changesets on server, return.
            if (m_hwmDelta.Value >= latestChangeset)
            {
                return(new int[0]);
            }

            int startingChangeset = m_hwmDelta.Value + 1;

            string skipComment     = ConfigurationService.GetValue <string>(Constants.SkipComment, "**NOMIGRATION**");
            string commentModifier = ConfigurationService.GetValue <string>(Constants.CommentModifier, TfsVCAdapterResource.DefaultCommentModifier);

            SortedDictionary <int, bool> mappedChangesets = new SortedDictionary <int, bool>();

            foreach (MappingEntry m in ConfigurationService.Filters)
            {
                if (m.Cloak)
                {
                    continue;
                }
                try
                {
                    foreach (Changeset changeset in m_tfsClient.QueryHistory(m.Path,
                                                                             VersionSpec.Latest,
                                                                             0,
                                                                             RecursionType.Full,
                                                                             null,
                                                                             new ChangesetVersionSpec(startingChangeset),
                                                                             new ChangesetVersionSpec(latestChangeset),
                                                                             int.MaxValue, // All changes
                                                                             false,
                                                                             true))
                    {
                        if (mappedChangesets.ContainsKey(changeset.ChangesetId))
                        {
                            continue;
                        }

                        if (TfsUtil.IsOurTfsChange(changeset, TranslationService, m_conflictManagementService.SourceId))
                        {
                            TraceManager.TraceInformation("Skipping mirrored change {0}", changeset.ChangesetId);
                            continue;
                        }

                        if (!string.IsNullOrEmpty(skipComment))
                        {
                            if (changeset.Comment != null && changeset.Comment.Contains(skipComment))
                            {
                                TraceManager.TraceInformation("Changeset {0} contains the skip comment {1}",
                                                              changeset.ChangesetId,
                                                              skipComment);
                                continue;
                            }
                        }

                        if (!mappedChangesets.ContainsKey(changeset.ChangesetId))
                        {
                            mappedChangesets.Add(changeset.ChangesetId, true);
                        }
                    }
                }
                catch (ItemNotFoundException)
                {
                    // the path does not contain any changesets
                }
            }
            if (mappedChangesets.Count > 0)
            {
                int[] mappedChangesetsArray = new int[mappedChangesets.Count];
                mappedChangesets.Keys.CopyTo(mappedChangesetsArray, 0);
                return(mappedChangesetsArray);
            }
            else
            {
                // No new changesets are found, update the HWM as current latest
                m_hwmDelta.Update(latestChangeset);
                return(new int[0]);
            }
        }
Exemple #6
0
        private void detectConflicts()
        {
            // Sort m_unresolvedRenames by path length with shorter paths first
            m_unresolvedRenames.Sort(delegate(BatchedItem lhs, BatchedItem rhs)
            {
                return(lhs.Source.Length.CompareTo(rhs.Source.Length));
            });

            // Find implicit renames, add them to m_implictRenames and m_implicitRenamesWithParentItems
            // If they are not also explict renames, remove them from m_unresolvedRenames
            for (int childIndex = m_unresolvedRenames.Count - 1; childIndex >= 0; childIndex--)
            {
                BatchedItem change = m_unresolvedRenames[childIndex];

                bool removeFromUnresolvedRenames = false;
                for (int parentIndex = 0; parentIndex < childIndex; parentIndex++)
                {
                    BatchedItem shorterRename = m_unresolvedRenames[parentIndex];
                    bool        childIsAlsoExplicitRename;
                    if (TfsUtil.isChildItemOfRename(change, shorterRename, out childIsAlsoExplicitRename))
                    {
                        m_implicitRenames.Add(change.Target);
                        m_implicitRenamesWithParentItems.Add(change.Target, shorterRename);

                        // There may be both an implicit rename of the item based on a parent rename and an explicit rename of this item
                        removeFromUnresolvedRenames = !childIsAlsoExplicitRename;
                        break;
                    }
                }
                if (removeFromUnresolvedRenames)
                {
                    m_unresolvedRenames.RemoveAt(childIndex);
                }
            }

            m_unresolvedAdditiveActions.Sort(delegate(BatchedItem lhs, BatchedItem rhs)
            {
                return(lhs.Target.Length.CompareTo(rhs.Target.Length));
            });

            for (int index = m_unresolvedAdditiveActions.Count - 1; index >= 0; index--)
            {
                foreach (BatchedItem rename in m_unresolvedRenames)
                {
                    if (VersionControlPath.IsSubItem(m_unresolvedAdditiveActions[index].Target, rename.Source))
                    {
                        if ((m_unresolvedAdditiveActions[index].Action == WellKnownChangeActionId.Add) &&
                            (VersionControlPath.Equals(rename.Source, m_unresolvedAdditiveActions[index].Target)) &&
                            (VersionControlPath.IsSubItem(rename.Target, rename.Source)) &&
                            (!VersionControlPath.Equals(rename.Target, rename.Source)))
                        {
                            // This Add is created by a Rename to below itself. Skip it. Example:
                            // Rename $/foo/bar to $/foo/bar/bar2
                            // We will get two change actions, 1) Rename $/foo/bar to $/foo/bar/bar2
                            // 2) Add $/foo/bar.
                            // This is to skip the Add action as it will be created implicitly by the Rename.
                            if (!m_implicitAdds.Contains(m_unresolvedAdditiveActions[index].Target))
                            {
                                m_implicitAdds.Add(m_unresolvedAdditiveActions[index].Target);
                            }
                            m_unresolvedAdditiveActions.RemoveAt(index);
                            break;
                        }
                        // The additive item should be scheduled after the Rename.
                        // Unless the rename is a case only rename which does not change the namespace slot.
                        if (!VersionControlPath.Equals(rename.Source, rename.Target))
                        {
                            m_unresolvedAdditiveActions[index].ConflictItem = rename;
                        }
                        break;
                    }
                }
            }

            for (int outerIndex = 0; outerIndex < m_unresolvedRenames.Count; outerIndex++)
            {
                BatchedItem processedChange = m_unresolvedRenames[outerIndex];

                if (processedChange.ConflictItem != null)
                {
                    continue;
                }

                // Find a parent item that was renamed
                for (int innerIndex = 0; innerIndex < m_unresolvedRenames.Count; innerIndex++)
                {
                    if (outerIndex == innerIndex)
                    {
                        continue;
                    }
                    BatchedItem change = m_unresolvedRenames[innerIndex];
                    if (VersionControlPath.IsSubItem(processedChange.Target, change.Source))
                    {
                        processedChange.ConflictItem = change;
                        break;
                    }
                }

                // Check for a rename cycles and chains that starts with the processedChange
                // To do this: Follow the chain of renames until it ends, it cycles back to the processedChange, or
                // the number of times through the loop reaches the size of m_renamePairs
                // Note that the renameCycle list is only added to m_renameCycles (a List of Lists) if a cycle is
                // found; otherwise it is was just a potential renameCycle that is tossed
                List <BatchedItem> renameCycle = new List <BatchedItem>();
                BatchedItem        next;
                if (!m_renamePairs.TryGetValue(processedChange.Target, out next))
                {
                    Debug.Fail("Target of item in m_unresolvedRenames not found in m_renamePairs");
                }
                for (int i = 0; i < m_renamePairs.Count && next != null; i++)
                {
                    string adjustedSource = null;
                    try
                    {
                        adjustedSource = adjustSourceForParentRenameIfNeeded(next.Source, next.Target, true);
                    }
                    catch
                    {
                        // Can occur if adjusted name is longer than max; in this case treat like not found in m_renamePairs by leaving adjustedSource null
                    }

                    BatchedItem renameSourceItem;
                    // m_renamePairs has the rename target as the key, so the following is checking if the
                    // source of the "next" rename item is the target of another rename
                    if (string.IsNullOrEmpty(adjustedSource) || !m_renamePairs.TryGetValue(adjustedSource, out renameSourceItem))
                    {
                        renameCycle = null;
                        break;
                    }
                    // Setting the ConflictItem is needed whether this is a cycle or just a chain
                    renameSourceItem.ConflictItem = next;

                    // Add to the renameCycle list though this instance of the list will be discarded unless a cycle is found below
                    renameCycle.Add(next);

                    next = renameSourceItem;

                    if (next.ID == processedChange.ID)
                    {
                        m_renameCycles.Add(renameCycle);
                        break;
                    }
                }

                foreach (BatchedItem additiveAction in m_unresolvedAdditiveActions)
                {
                    if (additiveAction.Action == WellKnownChangeActionId.Undelete)
                    {
                        if (VersionControlPath.IsSubItem(processedChange.Target, additiveAction.Source))
                        {
                            Debug.Assert(processedChange.ConflictItem == null);
                            processedChange.ConflictItem = additiveAction;
                            continue;
                        }
                    }
                    else
                    {
                        // Add fld2, rename fld1/1.txt to fld2/1.txt
                        // We need to pend the Add first.
                        if (VersionControlPath.IsSubItem(processedChange.Target, additiveAction.Target))
                        {
                            if ((processedChange.ConflictItem == null) || VersionControlPath.IsSubItem(additiveAction.Target, processedChange.ConflictItem.Target))
                            {
                                processedChange.ConflictItem = additiveAction;
                            }
                            else
                            {
                                Debug.Assert(VersionControlPath.IsSubItem(processedChange.ConflictItem.Target, additiveAction.Target),
                                             string.Format("Item {0} conflicted with two items: {1} and {2}",
                                                           processedChange.Target, processedChange.ConflictItem.Target, additiveAction.Target));
                            }
                            continue;
                        }
                        // Add fld1/file1.txt; rename fld -> fld1; rename go first
                        if (VersionControlPath.IsSubItem(additiveAction.Target, processedChange.Target))
                        {
                            if ((additiveAction.ConflictItem == null) || (VersionControlPath.IsSubItem(processedChange.Target, additiveAction.ConflictItem.Target)))
                            {
                                additiveAction.ConflictItem = processedChange;
                            }
                            else
                            {
                                Debug.Assert(VersionControlPath.IsSubItem(additiveAction.ConflictItem.Target, processedChange.Target),
                                             string.Format("Item {0} conflicted with two items: {1} and {2}",
                                                           additiveAction.Target, additiveAction.ConflictItem.Target, processedChange.Target));
                            }
                            continue;
                        }
                    }
                }
            }
            m_unresolvedChanges.AddRange(m_unresolvedAdditiveActions);
            m_unresolvedChanges.AddRange(m_unresolvedRenames);
        }