Exemplo n.º 1
0
        internal void PrescanOneTree()
        {
            var visitor = new AbstractIndexTreeVisitor
            {
                VisitEntry = (m, i, f) =>
                {
                    if (m != null)
                    {
                        if (!f.IsFile())
                        {
                            CheckConflictsWithFile(f);
                        }
                    }
                    else
                    {
                        if (f.Exists)
                        {
                            Removed.Add(i.Name);
                            Conflicts.Remove(i.Name);
                        }
                    }
                }
            };

            new IndexTreeWalker(_index, _merge, _root, visitor).Walk();

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Exemplo n.º 2
0
        internal void PrescanTwoTrees()
        {
            var visitor = new AbstractIndexTreeVisitor
            {
                VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) =>
                {
                    if (treeEntry is Tree || auxEntry is Tree)
                    {
                        throw new ArgumentException("Can't pass me a tree!");
                    }

                    ProcessEntry(treeEntry, auxEntry, indexEntry);
                },

                FinishVisitTree = (tree, auxTree, currentDirectory) =>
                {
                    if (currentDirectory.Length == 0)
                    {
                        return;
                    }
                    if (auxTree == null)
                    {
                        return;
                    }

                    if (_index.GetEntry(currentDirectory) != null)
                    {
                        Removed.Add(currentDirectory);
                    }
                }
            };

            new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk();

            // if there's a conflict, don't list it under
            // to-be-removed, since that messed up our next
            // section
            Removed.RemoveAll(removed => Conflicts.Contains(removed));

            foreach (string path in _updated.Keys)
            {
                if (_index.GetEntry(path) == null)
                {
                    FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path));
                    if (file.IsFile())
                    {
                        Conflicts.Add(path);
                    }
                    else if (file.IsDirectory())
                    {
                        CheckConflictsWithFile(file);
                    }
                }
            }

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run the diff operation. Until this is called, all lists will be empty
        /// </summary>
        /// <returns>true if anything is different between index, tree, and workdir</returns>
        public bool Diff()
        {
            DirectoryInfo root    = _index.Repository.WorkingDirectory;
            var           visitor = new AbstractIndexTreeVisitor
            {
                VisitEntry = delegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file)
                {
                    if (treeEntry == null)
                    {
                        Added.Add(indexEntry.Name);
                        _anyChanges = true;
                    }
                    else if (indexEntry == null)
                    {
                        if (!(treeEntry is Tree))
                        {
                            Removed.Add(treeEntry.FullName);
                        }
                        _anyChanges = true;
                    }
                    else
                    {
                        if (!treeEntry.Id.Equals(indexEntry.ObjectId))
                        {
                            Changed.Add(indexEntry.Name);
                            _anyChanges = true;
                        }
                    }

                    if (indexEntry != null)
                    {
                        if (!file.Exists)
                        {
                            Missing.Add(indexEntry.Name);
                            _anyChanges = true;
                        }
                        else
                        {
                            if (indexEntry.IsModified(root, true))
                            {
                                Modified.Add(indexEntry.Name);
                                _anyChanges = true;
                            }
                        }
                    }
                }
            };

            new IndexTreeWalker(_index, _tree, root, visitor).Walk();

            CheckUntrackedDirectory(root.FullName, "");

            return(_anyChanges);
        }
Exemplo n.º 4
0
        // Methods
        static IndexTreeWalkerTest()
        {
            TestIndexTreeVisitor = new AbstractIndexTreeVisitor
                          	{
                          		VisitEntry = delegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file)
                          		             	{
                          		             		if (treeEntry == null)
                          		             		{
                          		             			IndexOnlyEntriesVisited.Add(indexEntry.Name);
                          		             		}
                          		             		else if (indexEntry == null)
                          		             		{
                          		             			TreeOnlyEntriesVisited.Add(treeEntry.FullName);
                          		             		}
                          		             		else
                          		             		{
                          		             			BothVisited.Add(indexEntry.Name);
                          		             		}
                          		             	}
                          	};

			TestTreeOnlyOneLevelTreeVisitor = new AbstractIndexTreeVisitor
                           	{
                           		VisitEntry = delegate(TreeEntry entry, GitIndex.Entry indexEntry, FileInfo f)
                           		             	{
                           		             		if ((entry == null) || (indexEntry == null))
                           		             		{
                           		             			Assert.Fail();
                           		             		}
                           		             	},
                                FinishVisitTreeByIndex = delegate(Core.Tree tree, int i, string curDir)
                           		                         	{
                           		                         		if (tree.MemberCount == 0)
                           		                         		{
                           		                         			Assert.Fail();
                           		                         		}
                           		                         		if (i == 0)
                           		                         		{
                           		                         			Assert.Fail();
                           		                         		}
                           		                         	}
                           	};
        }
Exemplo n.º 5
0
        private void CheckoutOutIndexNoHead()
        {
            var visitor = new AbstractIndexTreeVisitor
            {
                VisitEntry = (m, i, f) =>
                {
                    if (m == null)
                    {
                        _index.remove(_root, f);
                        return;
                    }

                    bool needsCheckout = false;
                    if (i == null)
                    {
                        needsCheckout = true;
                    }
                    else if (i.ObjectId.Equals(m.Id))
                    {
                        if (i.IsModified(_root, true))
                        {
                            needsCheckout = true;
                        }
                    }
                    else
                    {
                        needsCheckout = true;
                    }

                    if (needsCheckout)
                    {
                        GitIndex.Entry newEntry = _index.addEntry(m);
                        _index.checkoutEntry(_root, newEntry);
                    }
                }
            };

            new IndexTreeWalker(_index, _merge, _root, visitor).Walk();
        }
Exemplo n.º 6
0
        internal void PrescanTwoTrees()
        {
            var visitor = new AbstractIndexTreeVisitor
                              {
                                  VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) =>
                                                   {
                                                       if (treeEntry is Tree || auxEntry is Tree)
                                                       {
                                                           throw new ArgumentException("Can't pass me a tree!");
                                                       }

                                                       ProcessEntry(treeEntry, auxEntry, indexEntry);
                                                   },

                                  FinishVisitTree = (tree, auxTree, currentDirectory) =>
                                                        {
                                                            if (currentDirectory.Length == 0) return;
                                                            if (auxTree == null) return;

                                                            if (_index.GetEntry(currentDirectory) != null)
                                                            {
                                                                Removed.Add(currentDirectory);
                                                            }
                                                        }
                              };

            new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk();

            // if there's a conflict, don't list it under
            // to-be-removed, since that messed up our next
            // section
            Removed.RemoveAll(removed => Conflicts.Contains(removed));

            foreach (string path in _updated.Keys)
            {
                if (_index.GetEntry(path) == null)
                {
                    FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path));
                    if (file.IsFile())
                    {
                        Conflicts.Add(path);
                    }
                    else if (file.IsDirectory())
                    {
                        CheckConflictsWithFile(file);
                    }
                }
            }

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Exemplo n.º 7
0
        internal void PrescanOneTree()
        {
            var visitor = new AbstractIndexTreeVisitor
                              {
                                  VisitEntry = (m, i, f) =>
                                                   {
                                                       if (m != null)
                                                       {
                                                           if (!f.IsFile())
                                                           {
                                                               CheckConflictsWithFile(f);
                                                           }
                                                       }
                                                       else
                                                       {
                                                           if (f.Exists)
                                                           {
                                                               Removed.Add(i.Name);
                                                               Conflicts.Remove(i.Name);
                                                           }
                                                       }
                                                   }
                              };

            new IndexTreeWalker(_index, _merge, _root, visitor).Walk();

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Exemplo n.º 8
0
        private void CheckoutOutIndexNoHead()
        {
            var visitor = new AbstractIndexTreeVisitor
                              {
                                  VisitEntry = (m, i, f) =>
                                                   {
                                                       if (m == null)
                                                       {
                                                           _index.remove(_root, f);
                                                           return;
                                                       }

                                                       bool needsCheckout = false;
                                                       if (i == null)
                                                       {
                                                           needsCheckout = true;
                                                       }
                                                       else if (i.ObjectId.Equals(m.Id))
                                                       {
                                                           if (i.IsModified(_root, true))
                                                           {
                                                               needsCheckout = true;
                                                           }
                                                       }
                                                       else
                                                       {
                                                           needsCheckout = true;
                                                       }

                                                       if (needsCheckout)
                                                       {
                                                           GitIndex.Entry newEntry = _index.addEntry(m);
                                                           _index.checkoutEntry(_root, newEntry);
                                                       }
                                                   }
                              };

            new IndexTreeWalker(_index, _merge, _root, visitor).Walk();
        }
Exemplo n.º 9
0
        public bool Diff()
        {
            DirectoryInfo root = _index.Repository.WorkingDirectory;
            var visitor = new AbstractIndexTreeVisitor
                          	{
                          		VisitEntry = delegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file)
                          		             	{
                          		             		if (treeEntry == null)
                          		             		{
                          		             			Added.Add(indexEntry.Name);
                          		             			_anyChanges = true;
                          		             		}
                          		             		else if (indexEntry == null)
                          		             		{
                          		             			if (!(treeEntry is Tree))
                          		             			{
                          		             				Removed.Add(treeEntry.FullName);
                          		             			}
                          		             			_anyChanges = true;
                          		             		}
                          		             		else
                          		             		{
                          		             			if (!treeEntry.Id.Equals(indexEntry.ObjectId))
                          		             			{
                          		             				Changed.Add(indexEntry.Name);
                          		             				_anyChanges = true;
                          		             			}
                          		             		}

                                                    if (indexEntry != null)
                                                    {
                                                        if (!file.Exists)
                                                        {
                                                            Missing.Add(indexEntry.Name);
                                                            _anyChanges = true;
                                                        }
                                                        else
                                                        {
                                                            if (indexEntry.IsModified(root, true))
                                                            {
                                                                Modified.Add(indexEntry.Name);
                                                                _anyChanges = true;
                                                            }
                                                        }
                                                    }
                          		             	}
                          	};
            new IndexTreeWalker(_index, _tree, root, visitor).Walk();

            return _anyChanges;
        }