Beispiel #1
0
        public virtual void TestShouldBeRecursive_ALL()
        {
            TreeFilter a = TreeFilter.ALL;
            TreeFilter n = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.AreEqual(a.ShouldBeRecursive(), n.ShouldBeRecursive());
        }
Beispiel #2
0
        public virtual void TestNegateIsUnwrap()
        {
            TreeFilter a = PathFilter.Create("a/b");
            TreeFilter n = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.AreSame(a, n.Negate());
        }
Beispiel #3
0
 /// <summary>Create a filter with two filters, one of which must match.</summary>
 /// <remarks>Create a filter with two filters, one of which must match.</remarks>
 /// <param name="a">first filter to test.</param>
 /// <param name="b">second filter to test.</param>
 /// <returns>a filter that must match at least one input filter.</returns>
 public static TreeFilter Create(TreeFilter a, TreeFilter b)
 {
     if (a == ALL || b == ALL)
     {
         return(ALL);
     }
     return(new OrTreeFilter.Binary(a, b));
 }
Beispiel #4
0
		/// <summary>Create a filter with two filters, one of which must match.</summary>
		/// <remarks>Create a filter with two filters, one of which must match.</remarks>
		/// <param name="a">first filter to test.</param>
		/// <param name="b">second filter to test.</param>
		/// <returns>a filter that must match at least one input filter.</returns>
		public static TreeFilter Create(TreeFilter a, TreeFilter b)
		{
			if (a == ALL || b == ALL)
			{
				return ALL;
			}
			return new OrTreeFilter.Binary(a, b);
		}
Beispiel #5
0
        public virtual void TestCloneIsSparseWhenPossible()
        {
            TreeFilter a = TreeFilter.ALL;

            NUnit.Framework.Assert.AreSame(a, a.Clone());
            TreeFilter n = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.AreSame(n, n.Clone());
        }
Beispiel #6
0
        public virtual void TestCloneIsDeepClone()
        {
            TreeFilter a = new AlwaysCloneTreeFilter();

            NUnit.Framework.Assert.AreNotSame(a, a.Clone());
            TreeFilter n = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.AreNotSame(n, n.Clone());
        }
Beispiel #7
0
        public virtual void TestShouldBeRecursive_PathFilter()
        {
            TreeFilter a = PathFilter.Create("a/b");

            NUnit.Framework.Assert.IsTrue(a.ShouldBeRecursive());
            TreeFilter n = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.IsTrue(n.ShouldBeRecursive());
        }
Beispiel #8
0
 public override TreeFilter Clone()
 {
     TreeFilter[] s = new TreeFilter[subfilters.Length];
     for (int i = 0; i < s.Length; i++)
     {
         s[i] = subfilters[i].Clone();
     }
     return(new OrTreeFilter.List(s));
 }
Beispiel #9
0
        public virtual void TestWrap()
        {
            TreeWalk   tw = new TreeWalk(db);
            TreeFilter a  = TreeFilter.ALL;
            TreeFilter n  = NotTreeFilter.Create(a);

            NUnit.Framework.Assert.IsNotNull(n);
            NUnit.Framework.Assert.IsTrue(a.Include(tw));
            NUnit.Framework.Assert.IsFalse(n.Include(tw));
        }
Beispiel #10
0
 /// <summary>Create a filter with two filters, both of which must match.</summary>
 /// <remarks>Create a filter with two filters, both of which must match.</remarks>
 /// <param name="a">first filter to test.</param>
 /// <param name="b">second filter to test.</param>
 /// <returns>a filter that must match both input filters.</returns>
 public static TreeFilter Create(TreeFilter a, TreeFilter b)
 {
     if (a == ALL)
     {
         return(b);
     }
     if (b == ALL)
     {
         return(a);
     }
     return(new AndTreeFilter.Binary(a, b));
 }
Beispiel #11
0
		/// <summary>Create a filter with two filters, both of which must match.</summary>
		/// <remarks>Create a filter with two filters, both of which must match.</remarks>
		/// <param name="a">first filter to test.</param>
		/// <param name="b">second filter to test.</param>
		/// <returns>a filter that must match both input filters.</returns>
		public static TreeFilter Create(TreeFilter a, TreeFilter b)
		{
			if (a == ALL)
			{
				return b;
			}
			if (b == ALL)
			{
				return a;
			}
			return new AndTreeFilter.Binary(a, b);
		}
Beispiel #12
0
 /// <summary>Create a filter around many filters, one of which must match.</summary>
 /// <remarks>Create a filter around many filters, one of which must match.</remarks>
 /// <param name="list">
 /// list of filters to match against. Must contain at least 2
 /// filters.
 /// </param>
 /// <returns>a filter that must match at least one input filter.</returns>
 public static TreeFilter Create(TreeFilter[] list)
 {
     if (list.Length == 2)
     {
         return(Create(list[0], list[1]));
     }
     if (list.Length < 2)
     {
         throw new ArgumentException(JGitText.Get().atLeastTwoFiltersNeeded);
     }
     TreeFilter[] subfilters = new TreeFilter[list.Length];
     System.Array.Copy(list, 0, subfilters, 0, list.Length);
     return(new OrTreeFilter.List(subfilters));
 }
Beispiel #13
0
 /// <summary>Create a filter around many filters, one of which must match.</summary>
 /// <remarks>Create a filter around many filters, one of which must match.</remarks>
 /// <param name="list">
 /// list of filters to match against. Must contain at least 2
 /// filters.
 /// </param>
 /// <returns>a filter that must match at least one input filter.</returns>
 public static TreeFilter Create(ICollection <TreeFilter> list)
 {
     if (list.Count < 2)
     {
         throw new ArgumentException(JGitText.Get().atLeastTwoFiltersNeeded);
     }
     TreeFilter[] subfilters = new TreeFilter[list.Count];
     Sharpen.Collections.ToArray(list, subfilters);
     if (subfilters.Length == 2)
     {
         return(Create(subfilters[0], subfilters[1]));
     }
     return(new OrTreeFilter.List(subfilters));
 }
Beispiel #14
0
		/// <summary>Set tree filter</summary>
		/// <param name="filter"></param>
		/// <returns>this generator</returns>
		public virtual NGit.Submodule.SubmoduleWalk SetFilter(TreeFilter filter)
		{
			walk.Filter = filter;
			return this;
		}
Beispiel #15
0
 internal Binary(TreeFilter one, TreeFilter two)
 {
     a = one;
     b = two;
 }
        private IList<GitFile> GetChangedFilesImpl(bool initializeCache)
        {
            if (!HasGitRepository) return new List<GitFile>();

            var list = new List<GitFile>();

            // initialize the cache
            if (initializeCache)
            {
                var treeWalk = new TreeWalk(this.repository);
                treeWalk.Recursive = true;
                treeWalk.Filter = TreeFilter.ALL;

                var id = repository.Resolve(Constants.HEAD);
                if (id != null)
                    treeWalk.AddTree(new RevWalk(repository).ParseTree(id));
                else
                    treeWalk.AddTree(new EmptyTreeIterator());

                while (treeWalk.Next())
                {
                    string pathString = treeWalk.PathString;
                    var fileName = GetFullPath(pathString);
                    if (Directory.Exists(fileName))
                        continue; // this excludes sub modules

                    cache[pathString] = GitFileStatus.Tracked;
                }
            }

            if (GitBash.Exists)
            {
                var result = GitBash.Run("status --porcelain -z --untracked-files", this.GitWorkingDirectory);
                if (!result.HasError)
                    return ParseGitStatus(result.Output);
                return list;
            }
            else
            {
                var treeWalk = new TreeWalk(this.repository);
                treeWalk.Recursive = true;
                treeWalk.Filter = TreeFilter.ANY_DIFF;

                var id = repository.Resolve(Constants.HEAD);
                if (id != null)
                {
                    treeWalk.AddTree(new RevWalk(repository).ParseTree(id));
                }
                else
                {
                    treeWalk.AddTree(new EmptyTreeIterator());
                }

                treeWalk.AddTree(new DirCacheIterator(this.repository.ReadDirCache()));
                treeWalk.AddTree(new FileTreeIterator(this.repository));
                var filters = new TreeFilter[] { new SkipWorkTreeFilter(INDEX), new IndexDiffFilter(INDEX, WORKDIR) };
                treeWalk.Filter = AndTreeFilter.Create(filters);

                while (treeWalk.Next())
                {
                    WorkingTreeIterator workingTreeIterator = treeWalk.GetTree<WorkingTreeIterator>(WORKDIR);
                    if (workingTreeIterator != null && workingTreeIterator.IsEntryIgnored()) continue;
                    var fileName = GetFullPath(treeWalk.PathString);
                    if (Directory.Exists(fileName)) continue; // this excludes sub modules

                    var status = GetFileStatus(treeWalk);
                    list.Add(new GitFile
                    {
                        FileName = GetRelativeFileName(fileName),
                        Status = status
                    });

                    this.cache[GetCacheKey(fileName)] = status;
                }
                return list;
            }
        }
        public GitFileStatus GetFileStatusNoCache(string fileName)
        {
            if (Directory.Exists(fileName)) return GitFileStatus.Ignored;

            var fileNameRel = GetRelativeFileNameForGit(fileName);
            TreeWalk treeWalk = new TreeWalk(this.repository) { Recursive = true };
            RevTree revTree = head == null ? null : new RevWalk(repository).ParseTree(head);

            if (revTree != null)
            {
                treeWalk.AddTree(revTree);
            }
            else
            {
                treeWalk.AddTree(new EmptyTreeIterator());
            }
            treeWalk.AddTree(new DirCacheIterator(dirCache));
            treeWalk.AddTree(new FileTreeIterator(this.repository));

            var filters = new TreeFilter[] {
                PathFilter.Create(fileNameRel),
                new SkipWorkTreeFilter(INDEX),
                new IndexDiffFilter(INDEX, WORKDIR)
            };
            treeWalk.Filter = AndTreeFilter.Create(filters);

            var status = GitFileStatus.NotControlled;
            if (treeWalk.Next())
            {
                status = GetFileStatus(treeWalk);
            }

            if (status == GitFileStatus.NotControlled)
            {
                var dirCacheEntry2 = dirCache.GetEntry(fileNameRel);
                if (dirCacheEntry2 != null)
                {
                    var treeEntry2 = TreeWalk.ForPath(repository, fileNameRel, revTree);
                    if (treeEntry2 != null && treeEntry2.GetObjectId(0).Equals(dirCacheEntry2.GetObjectId()))
                        return GitFileStatus.Tracked;
                }
            }
            return GitFileStatus.NotControlled;
        }
Beispiel #18
0
		/// <summary>Create a filter around many filters, all of which must match.</summary>
		/// <remarks>Create a filter around many filters, all of which must match.</remarks>
		/// <param name="list">
		/// list of filters to match against. Must contain at least 2
		/// filters.
		/// </param>
		/// <returns>a filter that must match all input filters.</returns>
		public static TreeFilter Create(TreeFilter[] list)
		{
			if (list.Length == 2)
			{
				return Create(list[0], list[1]);
			}
			if (list.Length < 2)
			{
				throw new ArgumentException(JGitText.Get().atLeastTwoFiltersNeeded);
			}
			TreeFilter[] subfilters = new TreeFilter[list.Length];
			System.Array.Copy(list, 0, subfilters, 0, list.Length);
			return new AndTreeFilter.List(subfilters);
		}
Beispiel #19
0
		/// <summary>Sets a filter.</summary>
		/// <remarks>
		/// Sets a filter. Can be used e.g. for restricting the tree walk to a set of
		/// files.
		/// </remarks>
		/// <param name="filter"></param>
		public virtual void SetFilter(TreeFilter filter)
		{
			this.filter = filter;
		}
Beispiel #20
0
			public override TreeFilter Clone()
			{
				TreeFilter[] s = new TreeFilter[subfilters.Length];
				for (int i = 0; i < s.Length; i++)
				{
					s[i] = subfilters[i].Clone();
				}
				return new AndTreeFilter.List(s);
			}
        private GitFileStatus GetFileStatusNoCache(string fileName)
        {
            if (Directory.Exists(fileName)) return GitFileStatus.Ignored;

            var fileNameRel = GetRelativeFileNameForGit(fileName);
            var dirCache = repository.ReadDirCache();
            TreeWalk treeWalk = new TreeWalk(this.repository) { Recursive = true };
            var head = repository.Resolve(Constants.HEAD);
            RevTree revTree = head == null ? null : new RevWalk(repository).ParseTree(head);

            if (revTree != null)
            {
                treeWalk.AddTree(revTree);
            }
            else
            {
                treeWalk.AddTree(new EmptyTreeIterator());
            }
            treeWalk.AddTree(new DirCacheIterator(dirCache));
            treeWalk.AddTree(new FileTreeIterator(this.repository));

            var filters = new TreeFilter[] {
                PathFilter.Create(fileNameRel),
                new SkipWorkTreeFilter(INDEX),
                new IndexDiffFilter(INDEX, WORKDIR)
            };
            treeWalk.Filter = AndTreeFilter.Create(filters);
            if (treeWalk.Next())
            {
                AbstractTreeIterator treeIterator = treeWalk.GetTree<AbstractTreeIterator>(TREE);
                DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(INDEX);
                WorkingTreeIterator workingTreeIterator = treeWalk.GetTree<WorkingTreeIterator>(WORKDIR);
                if (dirCacheIterator != null)
                {
                    DirCacheEntry dirCacheEntry = dirCacheIterator.GetDirCacheEntry();
                    if (dirCacheEntry != null && dirCacheEntry.Stage > 0)
                    {
                        return GitFileStatus.MergeConflict;
                    }

                    if (workingTreeIterator == null)
                    {
                        // in index, not in workdir => missing
                        return GitFileStatus.Deleted;
                    }
                    else
                    {
                        if (workingTreeIterator.IsModified(dirCacheIterator.GetDirCacheEntry(), true))
                        {
                            // in index, in workdir, content differs => modified
                            return GitFileStatus.Modified;
                        }
                    }
                }
                if (treeIterator != null)
                {
                    if (dirCacheIterator != null)
                    {
                        if (!treeIterator.IdEqual(dirCacheIterator) || treeIterator.EntryRawMode != dirCacheIterator.EntryRawMode)
                        {
                            // in repo, in index, content diff => changed
                            return GitFileStatus.Staged;
                        }
                    }
                    else
                    {
                        return GitFileStatus.Removed;
                    }
                }
                else
                {
                    if (dirCacheIterator != null)
                    {
                        // not in repo, in index => added
                        return GitFileStatus.Added;
                    }
                    else
                    {
                        // not in repo, not in index => untracked
                        if (workingTreeIterator != null)
                        {
                            return !workingTreeIterator.IsEntryIgnored() ? GitFileStatus.New : GitFileStatus.Ignored;
                        }
                    }
                }
            }

            var dirCacheEntry2 = dirCache.GetEntry(fileNameRel);
            if (dirCacheEntry2 != null)
            {
                var treeEntry2 = TreeWalk.ForPath(repository, fileNameRel, revTree);
                if (treeEntry2 != null && treeEntry2.GetObjectId(0).Equals(dirCacheEntry2.GetObjectId()))
                    return GitFileStatus.Tracked;
            }

            return GitFileStatus.NotControlled;
        }
        public IList<string> GetChangedFiles()
        {
            var list = new List<string>();

            var treeWalk = new TreeWalk(this.repository);
            treeWalk.Recursive = true;
            treeWalk.Filter = TreeFilter.ANY_DIFF;

            var id = repository.Resolve(Constants.HEAD);
            if (id != null)
            {
                treeWalk.AddTree(new RevWalk(repository).ParseTree(id));
            }
            else
            {
                treeWalk.AddTree(new EmptyTreeIterator());
            }

            treeWalk.AddTree(new DirCacheIterator(this.repository.ReadDirCache()));
            treeWalk.AddTree(new FileTreeIterator(this.repository));
            var filters = new TreeFilter[] { new SkipWorkTreeFilter(INDEX), new IndexDiffFilter(INDEX, WORKDIR) };
            treeWalk.Filter = AndTreeFilter.Create(filters);

            while (treeWalk.Next())
            {
                var fileName = GetFullPath(treeWalk.PathString);
                if (Directory.Exists(fileName)) continue; // this excludes sub modules
                list.Add(fileName);
            }
            return list;
        }
Beispiel #23
0
 private NotTreeFilter(TreeFilter one)
 {
     a = one;
 }
Beispiel #24
0
 internal RewriteTreeFilter(RevWalk walker, TreeFilter t)
 {
     repository = walker.repository;
     pathFilter = new TreeWalk(walker.reader);
     pathFilter.Filter = t;
     pathFilter.Recursive = t.ShouldBeRecursive();
 }
Beispiel #25
0
		/// <summary>Create a filter that negates the result of another filter.</summary>
		/// <remarks>Create a filter that negates the result of another filter.</remarks>
		/// <param name="a">filter to negate.</param>
		/// <returns>a filter that does the reverse of <code>a</code>.</returns>
		public static TreeFilter Create(TreeFilter a)
		{
			return new NGit.Treewalk.Filter.NotTreeFilter(a);
		}
Beispiel #26
0
		private NotTreeFilter(TreeFilter one)
		{
			a = one;
		}
Beispiel #27
0
		/// <summary>Create a filter around many filters, all of which must match.</summary>
		/// <remarks>Create a filter around many filters, all of which must match.</remarks>
		/// <param name="list">
		/// list of filters to match against. Must contain at least 2
		/// filters.
		/// </param>
		/// <returns>a filter that must match all input filters.</returns>
		public static TreeFilter Create(ICollection<TreeFilter> list)
		{
			if (list.Count < 2)
			{
				throw new ArgumentException(JGitText.Get().atLeastTwoFiltersNeeded);
			}
			TreeFilter[] subfilters = new TreeFilter[list.Count];
			Sharpen.Collections.ToArray(list, subfilters);
			if (subfilters.Length == 2)
			{
				return Create(subfilters[0], subfilters[1]);
			}
			return new AndTreeFilter.List(subfilters);
		}
Beispiel #28
0
			internal Binary(TreeFilter one, TreeFilter two)
			{
				a = one;
				b = two;
			}
Beispiel #29
0
 /// <summary>Create a filter that negates the result of another filter.</summary>
 /// <remarks>Create a filter that negates the result of another filter.</remarks>
 /// <param name="a">filter to negate.</param>
 /// <returns>a filter that does the reverse of <code>a</code>.</returns>
 public static TreeFilter Create(TreeFilter a)
 {
     return(new NGit.Treewalk.Filter.NotTreeFilter(a));
 }
Beispiel #30
0
			internal List(TreeFilter[] list)
			{
				subfilters = list;
			}
Beispiel #31
0
        public override TreeFilter Clone()
        {
            TreeFilter n = a.Clone();

            return(n == a ? this : new NGit.Treewalk.Filter.NotTreeFilter(n));
        }
        public void FillCache()
        {
            var treeWalk = new TreeWalk(this.repository);
            treeWalk.Recursive = true;
            treeWalk.Filter = TreeFilter.ANY_DIFF;

            var id = repository.Resolve(Constants.HEAD);
            if (id != null)
            {
                treeWalk.AddTree(ObjectId.FromString(repository.Open(id).GetBytes(), 5)); //any better way?
            }
            else
            {
                treeWalk.AddTree(new EmptyTreeIterator());
            }

            treeWalk.AddTree(new DirCacheIterator(this.repository.ReadDirCache()));
            treeWalk.AddTree(new FileTreeIterator(this.repository));
            var filters = new TreeFilter[] { new SkipWorkTreeFilter(INDEX), new IndexDiffFilter(INDEX, WORKDIR) };
            treeWalk.Filter = AndTreeFilter.Create(filters);

            while (treeWalk.Next())
            {
                var fileName = GetFullPath(treeWalk.PathString);

                if (Directory.Exists(fileName)) continue; // this excludes sub modules

                var status = GetFileStatusNoCache(fileName);
                this.cache[fileName] = status;
                //Debug.WriteLine(string.Format("==== Fill cache for {0} <- {1}", fileName, status));
            }
        }