コード例 #1
0
        static void OnFindFiles_INTERNAL(string input)
        {
            var files = VersionControl.ParseFiles(input);

            Debug.Log("Staged Files:");

            foreach (var file in files)
            {
                if (file.fileState1 != FileState.Unmodified && file.fileState1 != FileState.Untracked && file.fileState1 != FileState.Ignored)
                {
                    if (string.IsNullOrEmpty(file.name2))
                    {
                        Debug.Log(file.name1);
                    }
                    else
                    {
                        Debug.Log(file.name2);
                    }
                }
            }

            Debug.Log("Working tree:");

            foreach (var file in files)
            {
                if (file.fileState2 != FileState.Unmodified && file.fileState2 != FileState.Untracked && file.fileState2 != FileState.Ignored)
                {
                    if (string.IsNullOrEmpty(file.name2))
                    {
                        Debug.Log(file.name1);
                    }
                    else
                    {
                        Debug.Log(file.name2);
                    }
                }
            }

            Debug.Log("Untracked:");

            foreach (var file in files)
            {
                if (file.fileState1 == FileState.Untracked && file.fileState2 == FileState.Untracked)
                {
                    Debug.Log(file.name1);
                }
            }

            Debug.Log("Ignored:");

            foreach (var file in files)
            {
                if (file.fileState1 == FileState.Ignored && file.fileState2 == FileState.Ignored)
                {
                    Debug.Log(file.name1);
                }
            }
        }
コード例 #2
0
        // TODO: Handle errors (BrowserUtility.OnFindFiles)
        private static void OnFindFiles(object sender, System.EventArgs e)
        {
            var process = sender as System.Diagnostics.Process;

            var files = VersionControl.ParseFiles(process.StandardOutput.ReadToEnd());

            #region removal
            var toRemove = new List <string>();

            // Staged files
            foreach (var kvp in stagedFiles)
            {
                bool keep = false;
                foreach (var file in files)
                {
                    if (file.fileState1 != FileState.Unmodified && file.fileState1 != FileState.Untracked && file.fileState1 != FileState.Ignored)
                    {
                        if (kvp.Key.Equals(file.path1 + file.path2))
                        {
                            // Found a match
                            keep = true;
                            break;
                        }
                    }
                }

                // Add to removal queue
                if (!keep)
                {
                    toRemove.Add(kvp.Key);
                }
            }

            // Perform removal
            foreach (var str in toRemove)
            {
                stagedFiles.Remove(str);
            }

            toRemove.Clear();

            // Working tree
            foreach (var kvp in workingTree)
            {
                bool keep = false;
                foreach (var file in files)
                {
                    if ((file.fileState2 != FileState.Unmodified && file.fileState2 != FileState.Untracked && file.fileState2 != FileState.Ignored) ||
                        (file.fileState1 == FileState.Untracked && file.fileState2 == FileState.Untracked) ||
                        (file.fileState1 == FileState.Ignored && file.fileState2 == FileState.Ignored))
                    {
                        if (kvp.Key.Equals(file.path1 + file.path2))
                        {
                            // Found a match
                            keep = true;
                            break;
                        }
                    }
                }

                // Add to removal queue
                if (!keep)
                {
                    toRemove.Add(kvp.Key);
                }
            }

            // Perform removal
            foreach (var str in toRemove)
            {
                workingTree.Remove(str);
            }
            #endregion

            #region addition
            foreach (var file in files)
            {
                // Staged files
                if (file.fileState1 != FileState.Unmodified && file.fileState1 != FileState.Untracked && file.fileState1 != FileState.Ignored)
                {
                    // Check for duplicate
                    if (!stagedFiles.ContainsKey(file.path1 + file.path2))
                    {
                        // Add file
                        stagedFiles.Add(file.path1 + file.path2, file);
                    }
                }

                // Working tree
                if (file.fileState2 != FileState.Unmodified && file.fileState2 != FileState.Untracked && file.fileState2 != FileState.Ignored)
                {
                    // Check for duplicate
                    if (!workingTree.ContainsKey(file.path1 + file.path2))
                    {
                        // Check for duplicate (stagedFiles)
                        if (stagedFiles.ContainsValue(file))
                        {
                            // Add file (new instance)
                            workingTree.Add(file.path1 + file.path2, new VCFile(file));
                        }
                        else
                        {
                            // Add file
                            workingTree.Add(file.path1 + file.path2, file);
                        }
                    }
                }

                // Untracked (added to working tree)
                if (file.fileState1 == FileState.Untracked && file.fileState2 == FileState.Untracked)
                {
                    // Check for duplicate
                    if (!workingTree.ContainsKey(file.path1 + file.path2))
                    {
                        // Add value
                        workingTree.Add(file.path1 + file.path2, file);
                    }
                }

                // Ignored (added to working tree)
                if (file.fileState1 == FileState.Ignored && file.fileState2 == FileState.Ignored)
                {
                    // Check for duplicate
                    if (!workingTree.ContainsKey(file.path1 + file.path2))
                    {
                        // Add value
                        workingTree.Add(file.path1 + file.path2, file);
                    }
                }
            }
            #endregion

            // Validate selection
            ValidateSelection(null, false, false, -1, -1, null);

            // Update stats
            UpdateStats();
        }