public static void UnCloak(Workspace workspace, string serverItem)
        {
            string        localItem = null;
            WorkingFolder mapping   = null;

            foreach (WorkingFolder workingFolder in workspace.Folders)
            {
                if (workingFolder.Type == WorkingFolderType.Cloak)
                {
                    if (serverItem != null && (VersionControlPath.Equals(workingFolder.ServerItem, serverItem) || VersionControlPath.Equals(workingFolder.DisplayServerItem, serverItem)))
                    {
                        localItem = workingFolder.LocalItem;
                        mapping   = workingFolder;
                        break;
                    }
                    if (localItem != null && Microsoft.TeamFoundation.Common.FileSpec.Equals(workingFolder.LocalItem, localItem))
                    {
                        serverItem = workingFolder.ServerItem;
                        mapping    = workingFolder;
                        break;
                    }
                }
            }

            if (mapping != null)
            {
                workspace.DeleteMapping(mapping);
            }
        }
        internal static string GetOriginalName(PendingChange pendingChange, bool useServerPath)
        {
            string x        = null;
            var    itemName = GetItemName(pendingChange, useServerPath);

            if (!string.IsNullOrEmpty(pendingChange.SourceLocalItem) && !string.IsNullOrEmpty(pendingChange.LocalItem))
            {
                x = FileSpec.GetFileName(pendingChange.SourceLocalItem);
                if (
                    !FileSpec.Equals(FileSpec.GetDirectoryName(pendingChange.SourceLocalItem),
                                     FileSpec.GetDirectoryName(pendingChange.LocalItem)))
                {
                    x = pendingChange.SourceLocalItem;
                }
                if (string.Equals(x, itemName, StringComparison.Ordinal))
                {
                    x = null;
                }
            }
            if (x == null && !string.IsNullOrEmpty(pendingChange.SourceServerItem) &&
                !string.IsNullOrEmpty(pendingChange.ServerItem))
            {
                x = VersionControlPath.GetFileName(pendingChange.SourceServerItem);
                if (
                    !VersionControlPath.Equals(VersionControlPath.GetFolderName(pendingChange.SourceServerItem),
                                               VersionControlPath.GetFolderName(pendingChange.ServerItem)))
                {
                    x = pendingChange.SourceServerItem;
                }
                if (string.Equals(x, itemName, StringComparison.Ordinal))
                {
                    x = null;
                }
            }
            return(x);
        }
Example #3
0
        private void generateDeltaTableForSnapshot(List <string> paths, int snapshotChangeset)
        {
            List <string> pathsToGet          = new List <string>();
            VersionSpec   snapshotVersionSpec = new ChangesetVersionSpec(snapshotChangeset);

            foreach (string mappingPath in paths)
            {
                // Always query at one level down the mapping
                ItemSet itemSet = m_tfsClient.GetItems(mappingPath, snapshotVersionSpec, RecursionType.OneLevel);
                Item[]  items   = itemSet.Items;
                foreach (Item childItem in items)
                {
                    // Avoid the item itself.
                    if (!VersionControlPath.Equals(childItem.ServerItem, mappingPath))
                    {
                        pathsToGet.Add(childItem.ServerItem);
                    }
                }
            }

            int         countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize;
            ChangeGroup batchGroup = createChangeGroupForSnapshot(snapshotChangeset, snapshotChangeset);

            foreach (string path in pathsToGet)
            {
                TraceManager.TraceInformation("Getting snapshot at changeset: {0}, path: {1}", snapshotChangeset, path);
                ItemSet itemSet = m_tfsClient.GetItems(path, snapshotVersionSpec, RecursionType.Full);
                Item[]  items   = itemSet.Items;
                itemSet = null;
                TraceManager.TraceInformation("Snapshot contains {0} items", items.Length);
                for (int i = 0; i < items.Length; i++)
                {
                    if (FindMappedPath(items[i].ServerItem) != null)
                    {
                        countDownToCreateNewChangeGroup--;
                        if (countDownToCreateNewChangeGroup == 0)
                        {
                            TraceManager.TraceInformation("Saving {0} change actions", m_snapshotCheckinBatchSize);
                            batchGroup.Save();

                            batchGroup.Actions.Clear();
                            batchGroup = null;

                            batchGroup = createChangeGroupForSnapshot(snapshotChangeset, snapshotChangeset);
                            countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize;
                            TraceManager.TraceInformation("Saved {0} change actions", snapshotChangeset);
                        }
                        batchGroup.CreateAction(
                            WellKnownChangeActionId.Add,
                            new TfsMigrationItem(items[i]),
                            null,
                            items[i].ServerItem,
                            null,
                            null,
                            TfsAnalysisAlgorithms.convertContentType(items[i].ItemType),
                            null);
                    }
                    items[i] = null; // Dispose this object to reduce memory consumption.
                }
            }

            if (batchGroup.Actions.Count > 0)
            {
                int numRemainingItems = batchGroup.Actions.Count;
                TraceManager.TraceInformation("Saving {0} change actions", numRemainingItems);
                batchGroup.Save();
                TraceManager.TraceInformation("Saved {0} change actions", numRemainingItems);
            }
        }
Example #4
0
        /// <summary>
        /// Create a changegroup that contains all change actions needed to bring a migration target to the specificed snapshot
        /// </summary>
        /// <param name="changeGroupName">The change group name of the snapshot</param>
        private void generateSnapshotForVCSession()
        {
            foreach (var setting in ConfigurationService.VcCustomSetting.Settings.Setting)
            {
                if (setting.SettingKey == "SnapshotStartPoint")
                {
                    m_sessionLevelSnapshotChangeset = parseSnapShotStartPoint(setting.SettingValue);
                }
                else if (setting.SettingKey == "SnapshotBatchSize")
                {
                    try
                    {
                        m_snapshotCheckinBatchSize = int.Parse(setting.SettingValue);
                    }
                    catch (Exception)
                    {
                        // wrong format, use the default batch size
                    }
                }
            }

            m_hwmDelta.Reload();
            if (m_hwmDelta.Value >= m_sessionLevelSnapshotChangeset)
            {
                // We've already passed snapshot changeset Id, just return.
                m_sessionlevelSnapshotCompleted = true;
                return;
            }

            VersionSpec   snapshotVersionSpec = new ChangesetVersionSpec(m_sessionLevelSnapshotChangeset);
            List <string> pathsToGet          = new List <string>();

            foreach (MappingEntry mappingEntry in ConfigurationService.Filters)
            {
                if (mappingEntry.Cloak)
                {
                    continue;
                }

                // Always query at one level down the mapping
                ItemSet itemSet = m_tfsClient.GetItems(mappingEntry.Path, snapshotVersionSpec, RecursionType.OneLevel);
                Item[]  items   = itemSet.Items;
                foreach (Item childItem in items)
                {
                    // Avoid the item itself.
                    if (!VersionControlPath.Equals(childItem.ServerItem, mappingEntry.Path))
                    {
                        pathsToGet.Add(childItem.ServerItem);
                    }
                }
            }

            int         countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize;
            int         batchExecutionOrder             = m_sessionLevelSnapshotChangeset;
            ChangeGroup batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder);

            foreach (string path in pathsToGet)
            {
                TraceManager.TraceInformation("Getting snapshot at changeset: {0}, path: {1}", m_sessionLevelSnapshotChangeset, path);
                ItemSet itemSet = m_tfsClient.GetItems(path, snapshotVersionSpec, RecursionType.Full);
                Item[]  items   = itemSet.Items;
                itemSet = null;
                TraceManager.TraceInformation("Snapshot contains {0} items", items.Length);
                for (int i = 0; i < items.Length; i++)
                {
                    // We want to include the situation where a snapshot on a path is the same as the snapshot of the VC session.
                    // In this situation, we want to include the item in the session snapshot changeset.
                    // So we use changesetId + 1 as the reference changeset id.
                    if (IsPathMapped(items[i].ServerItem, m_sessionLevelSnapshotChangeset + 1) == MappingResult.Mapped)
                    {
                        countDownToCreateNewChangeGroup--;
                        if (countDownToCreateNewChangeGroup == 0)
                        {
                            TraceManager.TraceInformation("Saving {0} change actions", m_snapshotCheckinBatchSize);
                            batchGroup.Save();

                            batchGroup.Actions.Clear();
                            batchGroup = null;

                            batchExecutionOrder--;
                            batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder);
                            countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize;
                            TraceManager.TraceInformation("Saved {0} change actions", m_snapshotCheckinBatchSize);
                        }
                        batchGroup.CreateAction(
                            WellKnownChangeActionId.Add,
                            new TfsMigrationItem(items[i]),
                            null,
                            items[i].ServerItem,
                            null,
                            null,
                            TfsAnalysisAlgorithms.convertContentType(items[i].ItemType),
                            null);
                    }
                    items[i] = null; // Dispose this object to reduce memory consumption.
                }
            }

            if (batchGroup.Actions.Count > 0)
            {
                int numRemainingItems = batchGroup.Actions.Count;
                TraceManager.TraceInformation("Saving {0} change actions", numRemainingItems);
                batchGroup.Save();
                TraceManager.TraceInformation("Saved {0} change actions", numRemainingItems);
            }

            m_hwmDelta.Update(m_sessionLevelSnapshotChangeset);
            m_changeGroupService.PromoteDeltaToPending();
            m_sessionlevelSnapshotCompleted = true;
        }
Example #5
0
        private void detectConflicts()
        {
            m_unresolvedRenames.Sort(delegate(BatchedItem lhs, BatchedItem rhs)
            {
                return(lhs.Source.Length.CompareTo(rhs.Source.Length));
            });
            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];
                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;
                    }
                }

                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);
        }
Example #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);
        }
Example #7
0
        private TreeNode SelectFolder(TreeNodeCollection nodes, List <string> folderParts)
        {
            TreeNode result         = null;
            var      nodesToRecurse = new List <TreeNode>();

            string folderToFound = folderParts[0];

            foreach (TreeNode node in nodes)
            {
                //AfterExpand(node);
                Application.DoEvents();
                if (stopQuerying)
                {
                    break;
                }

                var    serverPath     = node.Tag as string;
                string serverItemName = VersionControlPath.GetFileName(serverPath);
                bool   equal          = VersionControlPath.Equals(folderToFound, serverItemName);

                if (equal)
                {
                    result = node;
                    SetSingleSelectedNode(node, true);
                    folderParts.RemoveAt(0);
                    nodesToRecurse.Clear();
                }
                else
                {
                    //AfterExpand(node);
                }

                if (folderParts.Count > 0 && node.Nodes.Count > 0)
                {
                    nodesToRecurse.Add(node);
                }

                if (equal)
                {
                    break;
                }
            }

            if (nodesToRecurse.Count > 0 && folderParts.Count > 0)
            {
                foreach (TreeNode node in nodesToRecurse)
                {
                    AfterExpand(node);
                    result = SelectFolder(node.Nodes, folderParts);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            if (result != null)
            {
                AfterExpand(result);

                //                disableExpandAutoLoad = true;
                //                try
                //                {
                //                    TreeNode parent = result.Parent;
                //                    while (parent != null)
                //                    {
                //                        parent.Expand();
                //                        parent = parent.Parent;
                //                    }
                //                }
                //                finally
                //                {
                //                    disableExpandAutoLoad = false;
                //                }
            }

            return(result);
        }