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

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

            NUnit.Framework.Assert.AreSame(a, n.Negate());
        }
예제 #3
0
파일: OrTreeFilter.cs 프로젝트: shoff/ngit
 /// <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));
 }
예제 #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);
		}
예제 #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());
        }
예제 #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());
        }
예제 #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());
        }
예제 #8
0
파일: OrTreeFilter.cs 프로젝트: shoff/ngit
 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));
 }
예제 #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));
        }
예제 #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));
 }
예제 #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);
		}
예제 #12
0
파일: OrTreeFilter.cs 프로젝트: shoff/ngit
 /// <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));
 }
예제 #13
0
파일: OrTreeFilter.cs 프로젝트: shoff/ngit
 /// <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));
 }
예제 #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;
		}
예제 #15
0
파일: OrTreeFilter.cs 프로젝트: shoff/ngit
 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;
        }
예제 #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);
		}
예제 #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;
		}
예제 #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;
        }
예제 #23
0
 private NotTreeFilter(TreeFilter one)
 {
     a = one;
 }
예제 #24
0
 internal RewriteTreeFilter(RevWalk walker, TreeFilter t)
 {
     repository = walker.repository;
     pathFilter = new TreeWalk(walker.reader);
     pathFilter.Filter = t;
     pathFilter.Recursive = t.ShouldBeRecursive();
 }
예제 #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);
		}
예제 #26
0
		private NotTreeFilter(TreeFilter one)
		{
			a = one;
		}
예제 #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);
		}
예제 #28
0
			internal Binary(TreeFilter one, TreeFilter two)
			{
				a = one;
				b = two;
			}
예제 #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));
 }
예제 #30
0
			internal List(TreeFilter[] list)
			{
				subfilters = list;
			}
예제 #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));
            }
        }