Exemple #1
0
        public IEnumerable <IVCDiffItem> GetFolderSubDiffItems(IVCDiffItem folderDiffItem)
        {
            List <IVCDiffItem> diffItems = new List <IVCDiffItem>();

            try
            {
                string directoryPath = m_clearCaseServer.GetViewLocalPathFromServerPath(folderDiffItem.ServerPath);
                if (Directory.Exists(directoryPath))
                {
                    foreach (string file in Directory.GetFiles(directoryPath))
                    {
                        string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(file);
                        diffItems.Add(new ClearCaseDiffItem(serverPath, file, VCItemType.File));
                    }

                    foreach (string subDirectory in Directory.GetDirectories(directoryPath))
                    {
                        string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(subDirectory);
                        if (ClearCasePath.Equals(ClearCasePath.GetFileName(serverPath), ClearCasePath.LostFoundFolder))
                        {
                            continue;
                        }
                        diffItems.Add(new ClearCaseDiffItem(serverPath, null, VCItemType.Folder));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new VersionControlDiffException(string.Format(CultureInfo.InvariantCulture,
                                                                    CCResources.GetDiffItemsException, folderDiffItem.ServerPath, ex.Message), ex);
            }

            return(diffItems);
        }
 /// <summary>
 /// Check to see if an item is a sub item in cloak list.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="cloakList"></param>
 /// <returns></returns>
 private bool isCloaked(IVCDiffProvider diffProvider, IVCDiffItem item, List <string> cloakList)
 {
     foreach (string cloakedPath in cloakList)
     {
         if (item.IsSubItemOf(cloakedPath))
         {
             return(true);
         }
     }
     return(false);
 }
        public IEnumerable <IVCDiffItem> GetFolderSubDiffItems(IVCDiffItem folderDiffItem)
        {
            foreach (Item subItem in m_repository.GetItems(PathUtils.Combine(m_configurationManager.RepositoryUri, folderDiffItem.ServerPath), m_revision, Depth.Immediates))
            {
                SubversionVCDiffItem diffItem = new SubversionVCDiffItem(subItem, m_revision);

                // Don't return the item itself
                if (string.Equals(diffItem.ServerPath, folderDiffItem.ServerPath))
                {
                    continue;
                }
                yield return(diffItem);
            }

            yield break;
        }
Exemple #4
0
        public IEnumerable <IVCDiffItem> GetFolderSubDiffItems(IVCDiffItem folderDiffItem)
        {
            List <IVCDiffItem> diffItems = new List <IVCDiffItem>();

            try
            {
                foreach (string file in Directory.GetFiles(folderDiffItem.ServerPath))
                {
                    diffItems.Add(new TfsFileSystemDiffItem(file, VCItemType.File));
                }

                foreach (string directory in Directory.GetDirectories(folderDiffItem.ServerPath))
                {
                    diffItems.Add(new TfsFileSystemDiffItem(directory, VCItemType.Folder));
                }
            }
            catch (Exception ex)
            {
                throw new VersionControlDiffException(string.Format(CultureInfo.InvariantCulture,
                                                                    TfsFileSystemResources.GetDiffItemsException, folderDiffItem.ServerPath, ex.Message), ex);
            }

            return(diffItems);
        }
 public void Cleanup(IVCDiffItem rootDiffItem)
 {
     m_cachedFolderItems.Clear();
 }
        public IEnumerable <IVCDiffItem> GetFolderSubDiffItems(
            IVCDiffItem folderDiffItem)
        {
            TfsVCDiffItem tfsFolderDiffItem = folderDiffItem as TfsVCDiffItem;

            if (tfsFolderDiffItem == null)
            {
                throw new ArgumentException("folderDiffItem");
            }
            if (!(folderDiffItem.VCItemType == VCItemType.Folder))
            {
                throw new ArgumentException("folderDiffItem.VCItemType != VCItemType.Folder");
            }

            TfsVCDiffItem cachedDiffItem;

            if (m_cachedFolderItems.TryGetValue(folderDiffItem.ServerPath, out cachedDiffItem))
            {
                List <IVCDiffItem> subItems = cachedDiffItem.SubItems;
                cachedDiffItem.SubItems = null;
                m_cachedFolderItems.Remove(folderDiffItem.ServerPath);
                return(subItems);
            }
            else
            {
                // All of the TfsDiffItem objects are placed in separate list on the first pass so that all of the folders
                // are in m_cachedFolderItems before the loop below where ProcessSubItem is called for each TfsDiffItem
                // This means that we make no assumptions about the TFS GetItems() method returning the folders and files in
                // any particular order.

                List <TfsVCDiffItem> tfsDiffItems  = new List <TfsVCDiffItem>();
                RecursionType        recursionType = tfsFolderDiffItem.TreeLevel < c_treeDepthToStartFullRecursion ? RecursionType.OneLevel : RecursionType.Full;
                // Ignore deleted items in the diff operation
                ItemSet tfsItemSet = m_tfsClient.GetItems(tfsFolderDiffItem.ServerPath, m_versionSpec, recursionType, DeletedState.NonDeleted, ItemType.Any);
                foreach (Item item in tfsItemSet.Items)
                {
                    TfsVCDiffItem diffItem = new TfsVCDiffItem(item, tfsFolderDiffItem.TreeLevel + 1);

                    if (recursionType == RecursionType.Full && item.ItemType == ItemType.Folder)
                    {
                        // Item is a folder; add it to the cache of folder diff items, keyed by its ServerPath
                        if (!m_cachedFolderItems.ContainsKey(diffItem.ServerPath))
                        {
                            m_cachedFolderItems.Add(diffItem.ServerPath, diffItem);
                        }
                    }

                    // Don't return the item passed in
                    if (!string.Equals(item.ServerItem, tfsFolderDiffItem.ServerPath, StringComparison.OrdinalIgnoreCase))
                    {
                        tfsDiffItems.Add(diffItem);
                    }
                }
                tfsItemSet = null;

                List <IVCDiffItem> directSubItems = new List <IVCDiffItem>();

                // Attach the diff items to the appropriate parent folder, and include them in the directSubItems list if appropriate
                foreach (TfsVCDiffItem tfsDiffItem in tfsDiffItems)
                {
                    ProcessSubItem(tfsDiffItem, tfsFolderDiffItem, directSubItems, recursionType == RecursionType.Full);
                }

                return(directSubItems);
            }
        }
 public void Cleanup(IVCDiffItem rootDiffItem)
 {
 }
        public bool VerifyContentsMatch(string sourceVersion, string targetVersion)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            Trace.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                          "Entering VCDiffComparer.VerifyContentsMatch: sourceVersion: {0}, targetVersion: {1}",
                                          sourceVersion == null ? "latest" : sourceVersion,
                                          targetVersion == null ? "latest" : targetVersion));

            List <IVCDiffItem> sourceRootDiffItems = new List <IVCDiffItem>();
            List <IVCDiffItem> targetRootDiffItems = new List <IVCDiffItem>();

            bool contentMatch     = true;
            int  foldersProcessed = 0;
            int  filesProcessed   = 0;

            try
            {
                Stack <IVCDiffItem> sourceFolders = new Stack <IVCDiffItem>();
                Queue <IVCDiffItem> sourceFiles   = new Queue <IVCDiffItem>();

                Dictionary <string, IVCDiffItem> targetFolders = new Dictionary <string, IVCDiffItem>(StringComparer.InvariantCultureIgnoreCase);
                Dictionary <string, IVCDiffItem> targetFiles   = new Dictionary <string, IVCDiffItem>(StringComparer.InvariantCultureIgnoreCase);

                List <string> sourceCloakList = new List <string>();
                List <string> targetCloakList = new List <string>();

                foreach (var filterPair in m_serverDiffEngine.Session.Filters.FilterPair)
                {
                    if (filterPair.Neglect)
                    {
                        // TODO: Need to deal with translating paths for cloaked filter pairs into the canonical relative form used by IVCDiffItem.Path !!!
                        sourceCloakList.Add(GetSourceFilterString(filterPair));
                        targetCloakList.Add(GetTargetFilterString(filterPair));
                    }
                }

                foreach (var filterPair in m_serverDiffEngine.Session.Filters.FilterPair)
                {
                    if (!filterPair.Neglect)
                    {
                        sourceFolders.Clear();
                        sourceFiles.Clear();
                        targetFolders.Clear();
                        targetFiles.Clear();

                        // Always go 1 level down to avoid too large query
                        string      sourceFilterString = GetSourceFilterString(filterPair);
                        IVCDiffItem sourceDiffRootItem = SourceVCDiffProvider.InitializeForDiff(sourceFilterString, sourceVersion);
                        if (sourceDiffRootItem != null)
                        {
                            if (sourceDiffRootItem.VCItemType == VCItemType.Folder)
                            {
                                sourceFolders.Push(sourceDiffRootItem);
                            }
                            else
                            {
                                sourceFiles.Enqueue(sourceDiffRootItem);
                            }
                            sourceRootDiffItems.Add(sourceDiffRootItem);
                        }

                        string      targetFilterString = GetTargetFilterString(filterPair);
                        IVCDiffItem targetDiffRootItem = TargetVCDiffProvider.InitializeForDiff(targetFilterString, targetVersion);
                        if (targetDiffRootItem != null)
                        {
                            if (targetDiffRootItem.VCItemType == VCItemType.Folder)
                            {
                                targetFolders.Add(targetDiffRootItem.ServerPath, targetDiffRootItem);
                            }
                            else
                            {
                                targetFiles.Add(targetDiffRootItem.ServerPath, targetDiffRootItem);
                            }
                            targetRootDiffItems.Add(targetDiffRootItem);
                        }

                        while (sourceFiles.Count > 0 | sourceFolders.Count > 0 | targetFiles.Count > 0 | targetFolders.Count > 0)
                        {
                            while (sourceFiles.Count > 0)
                            {
                                IVCDiffItem sourceItem = sourceFiles.Dequeue();
                                if (sourceItem.VCItemType != VCItemType.File)
                                {
                                    Debug.Fail("VerifyContentMatch: Found IVCDiffItem that is not type File in the sourceFiles queue");
                                    continue;
                                }
                                string targetPath = TranslationService.GetMappedPath(sourceItem.ServerPath, new Guid(m_serverDiffEngine.Session.LeftMigrationSourceUniqueId));

                                if (targetPath == null || !targetFiles.ContainsKey(targetPath))
                                {
                                    m_serverDiffEngine.LogError(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ItemOnlyFoundOnSource, sourceItem.ServerPath));
                                    contentMatch = false;
                                }
                                else
                                {
                                    bool fileContentsMatch = ContentsMatch(sourceItem.HashValue, targetFiles[targetPath].HashValue);
                                    if (fileContentsMatch)
                                    {
                                        m_serverDiffEngine.LogVerbose(String.Format(CultureInfo.InvariantCulture, ServerDiffResources.FilesMatch,
                                                                                    sourceItem.ServerPath, targetPath));
                                    }
                                    else
                                    {
                                        contentMatch = false;
                                        m_serverDiffEngine.LogError(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ItemContentDoesNotMatch, sourceItem.ServerPath));
                                    }
                                    targetFiles.Remove(targetPath);
                                }
                                filesProcessed++;
                            }

                            foreach (KeyValuePair <string, IVCDiffItem> remainingFile in targetFiles)
                            {
                                m_serverDiffEngine.LogError(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ItemOnlyFoundOnTarget, remainingFile.Key));
                                contentMatch = false;
                            }

                            Debug.Assert(sourceFiles.Count == 0);
                            targetFiles.Clear();

                            if (sourceFolders.Count > 0)
                            {
                                IVCDiffItem sourceFolder = sourceFolders.Pop();
                                m_serverDiffEngine.LogVerbose(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ProcessingSourceFolder, sourceFolder.ServerPath));

                                string targetFolder = TranslationService.GetMappedPath(sourceFolder.ServerPath, new Guid(m_serverDiffEngine.Session.LeftMigrationSourceUniqueId));

                                if (targetFolder != null && targetFolders.ContainsKey(targetFolder))
                                {
                                    // Always go 1 level down to avoid too large query
                                    IEnumerable <IVCDiffItem> sourceDiffItems = SourceVCDiffProvider.GetFolderSubDiffItems(sourceFolder);
                                    foreach (IVCDiffItem diffItem in sourceDiffItems)
                                    {
                                        if (isCloaked(SourceVCDiffProvider, diffItem, sourceCloakList))
                                        {
                                            continue;
                                        }
                                        if (diffItem.VCItemType == VCItemType.File)
                                        {
                                            sourceFiles.Enqueue(diffItem);
                                        }
                                        else
                                        {
                                            sourceFolders.Push(diffItem);
                                        }
                                    }

                                    IEnumerable <IVCDiffItem> targetDiffItems = TargetVCDiffProvider.GetFolderSubDiffItems(targetFolders[targetFolder]);
                                    foreach (IVCDiffItem diffItem in targetDiffItems)
                                    {
                                        if (isCloaked(TargetVCDiffProvider, diffItem, targetCloakList))
                                        {
                                            continue;
                                        }
                                        if (diffItem.VCItemType == VCItemType.File)
                                        {
                                            if (!targetFiles.ContainsKey(diffItem.ServerPath))
                                            {
                                                targetFiles.Add(diffItem.ServerPath, diffItem);
                                            }
                                        }
                                        else
                                        {
                                            if (!targetFolders.ContainsKey(diffItem.ServerPath))
                                            {
                                                targetFolders.Add(diffItem.ServerPath, diffItem);
                                            }
                                        }
                                    }
                                    targetFolders.Remove(targetFolder);
                                    if (++foldersProcessed % 100 == 0)
                                    {
                                        m_serverDiffEngine.LogInfo(String.Format(CultureInfo.InvariantCulture, "Processed {0} source folders containing {1} files ...",
                                                                                 foldersProcessed, filesProcessed));
                                    }
                                }
                                else
                                {
                                    m_serverDiffEngine.LogError(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ItemOnlyFoundOnSource, sourceFolder.ServerPath));
                                    contentMatch = false;
                                }
                            }
                            else
                            {
                                foreach (KeyValuePair <string, IVCDiffItem> remainingFolder in targetFolders)
                                {
                                    m_serverDiffEngine.LogError(string.Format(CultureInfo.InvariantCulture, ServerDiffResources.ItemOnlyFoundOnTarget, remainingFolder.Key));
                                    contentMatch = false;
                                }
                                targetFolders.Clear();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Exception occurred while verifying contents match: " + e.ToString());
                throw;
            }
            finally
            {
                if (SourceVCDiffProvider != null)
                {
                    foreach (IVCDiffItem sourceRootDiffItem in sourceRootDiffItems)
                    {
                        SourceVCDiffProvider.Cleanup(sourceRootDiffItem);
                    }
                }
                if (TargetVCDiffProvider != null)
                {
                    foreach (IVCDiffItem targetRootDiffItem in targetRootDiffItems)
                    {
                        TargetVCDiffProvider.Cleanup(targetRootDiffItem);
                    }
                }
                stopWatch.Stop();
                m_serverDiffEngine.LogInfo(String.Format(CultureInfo.InvariantCulture, ServerDiffResources.VCServerDiffTimeToRun,
                                                         stopWatch.Elapsed.TotalSeconds));
                m_serverDiffEngine.LogInfo(String.Format(CultureInfo.InvariantCulture, "Processed a total of {0} source folders containing {1} files",
                                                         foldersProcessed, filesProcessed));
            }

            Trace.WriteLine("VCDiffComparer.VerifyContentsMatch result: " + contentMatch);

            return(contentMatch);
        }