当前位置: 首页>>代码示例>>C#>>正文


C# TreeWalk.setFilter方法代码示例

本文整理汇总了C#中TreeWalk.setFilter方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.setFilter方法的具体用法?C# TreeWalk.setFilter怎么用?C# TreeWalk.setFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeWalk的用法示例。


在下文中一共展示了TreeWalk.setFilter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompareCommits

		/// <summary>
		/// Compare reference commit against compared commit. You may pass in a null commit (i.e. for getting the changes of the first commit)
		/// </summary>
		/// <param name="reference"></param>
		/// <param name="compared"></param>
		/// <returns></returns>
		public static IEnumerable<Change> CompareCommits(Commit reference, Commit compared)
		{
			var changes = new List<Change>();
			if (reference == null && compared == null)
				return changes;
			var repo = (reference ?? compared).Repository;
			if (compared.Repository.Directory != repo.Directory)
				throw new InvalidOperationException("Can not compare commits from different repositories");
			var ref_tree = (reference != null ? reference.Tree._id : ObjectId.ZeroId);
			var compared_tree = (compared != null ? compared.Tree._id : ObjectId.ZeroId);
			var db = repo._internal_repo;
			var pathFilter = TreeFilter.ALL;
			var walk = new TreeWalk(db);
			//new GitSharp.Core.ObjectWriter(repo).WriteTree( new CoreTree(repo)); // <--- writing an empty tree object. very ugly hack that is necessary to get an empty tree into the treewalker.
			if (reference == null || compared == null)
				walk.reset((reference ?? compared).Tree._id);
			else
				walk.reset(new GitSharp.Core.AnyObjectId[] { ref_tree, compared_tree });
			//if (ref_tree == ObjectId.ZeroId)
			//    walk.addTree(new EmptyTreeIterator());
			//else
			//    walk.addTree(ref_tree);
			//if (compared_tree == ObjectId.ZeroId)
			//    walk.addTree(new EmptyTreeIterator());
			//else
			//    walk.addTree(compared_tree);
			walk.Recursive = true;
			walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));

			while (walk.next())
			{
				if (walk.getTreeCount() == 2)
				{
					int m0 = walk.getRawMode(0);
					int m1 = walk.getRawMode(1);
					var change = new Change()
					{
						ReferenceCommit = reference,
						ComparedCommit = compared,
						ReferencePermissions = walk.getFileMode(0).Bits,
						ComparedPermissions = walk.getFileMode(1).Bits,
						Name = walk.getNameString(),
						Path = walk.getPathString(),
					};
					changes.Add(change);
					if (m0 == 0 && m1 != 0)
					{
						change.ChangeType = ChangeType.Added;
						change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
					}
					else if (m0 != 0 && m1 == 0)
					{
						change.ChangeType = ChangeType.Deleted;
						change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
					}
					else if (m0 != m1 && walk.idEqual(0, 1))
					{
						change.ChangeType = ChangeType.TypeChanged;
						change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
						change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
					}
					else
					{
						change.ChangeType = ChangeType.Modified;
						change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
						change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
					}
				}
				else
				{
					var change = new Change()
					{
						ReferenceCommit = reference,
						ComparedCommit = compared,
						Name = walk.getNameString(),
						Path = walk.getPathString(),
					};
					changes.Add(change);
					if (reference != null)
					{
						change.ReferencePermissions = walk.getFileMode(0).Bits;
						change.ChangeType = ChangeType.Deleted;
						change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
					}
					else
					{
						change.ComparedPermissions = walk.getFileMode(0).Bits;
						change.ChangeType = ChangeType.Added;
						change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
					}
				}
			}
			return changes;
		}
开发者ID:stephensong,项目名称:GitSharp,代码行数:100,代码来源:Commit.cs

示例2: CompareAgainstParents

        /// <summary>
        /// Compare a commit against (one or multiple) parents (merge scenario)
        /// </summary>
        /// <returns>Changes of the commit</returns>
        private IEnumerable<Change> CompareAgainstParents()
        {
            var db = _repo._internal_repo;
            var tree_ids = new[] { this }.Concat(Parents).Select(c => c.Tree._id).ToArray();
            var walk = new TreeWalk(db);
            walk.reset(tree_ids);
            walk.Recursive = true;
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, TreeFilter.ALL));

            return CalculateCommitDiff(_repo, walk, new[] { this }.Concat(Parents).ToArray());
        }
开发者ID:narent,项目名称:GitSharp,代码行数:15,代码来源:Commit.cs

示例3: CompareAgainst

        //public class Diff
        //{
        //    public List<AbstractObject> Modified = new List<AbstractObject>();
        //    public List<AbstractObject> Added = new List<AbstractObject>();
        //    public List<AbstractObject> Deleted = new List<AbstractObject>();
        //    public List<AbstractObject> TypeChanged = new List<AbstractObject>();
        //}
        /// <summary>
        /// Compares this commit against another one and returns all changes between the two.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public IEnumerable<Change> CompareAgainst(Commit other)
        {
            var changes = new List<Change>();
            var db = _repo._internal_repo;
            var pathFilter = TreeFilter.ALL;
            var walk = new TreeWalk(db);
            walk.reset(new GitSharp.Core.AnyObjectId[] { this.Tree._id, other.Tree._id });
            walk.Recursive = true;
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
            Debug.Assert(walk.getTreeCount() == 2);
            while (walk.next())
            {
                //for (int i = 1; i < nTree; i++)
                //    out.print(':');
                //for (int i = 0; i < nTree; i++) {
                //     var m = walk.getFileMode(i);
                //     String s = m.toString();
                //    for (int pad = 6 - s.length(); pad > 0; pad--)
                //        out.print('0');
                //    out.print(s);
                //    out.print(' ');
                //}

                //for (int i = 0; i < nTree; i++) {
                //    out.print(walk.getObjectId(i).name());
                //    out.print(' ');
                //}

                //char chg = 'M';
                int m0 = walk.getRawMode(0);
                int m1 = walk.getRawMode(1);
                var change = new Change()
                {
                    ReferenceCommit = this,
                    ComparedCommit = other,
                    ReferencePermissions = walk.getFileMode(0).Bits,
                    ComparedPermissions = walk.getFileMode(1).Bits,
                    Name = walk.getNameString(),
                    Path = walk.getPathString(),
                };
                changes.Add(change);
                if (m0 == 0 && m1 != 0)
                {
                    change.ChangeType = ChangeType.Added;
                    change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
                }
                else if (m0 != 0 && m1 == 0)
                {
                    change.ChangeType = ChangeType.Deleted;
                    change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
                }
                else if (m0 != m1 && walk.idEqual(0, 1))
                {
                    change.ChangeType = ChangeType.TypeChanged;
                    change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
                    change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
                }
                else
                {
                    change.ChangeType = ChangeType.Modified;
                    change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
                    change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
                }
            }
            return changes;
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:78,代码来源:Commit.cs

示例4: CompareCommits

        /// <summary>
        /// Compare reference commit against compared commit. You may pass in a null commit (i.e. for getting the changes of the first commit)
        /// </summary>
        /// <param name="reference">Usually the more recent commit</param>
        /// <param name="compared">Usually an ancestor of the reference commit</param>
        /// <returns>a list of changes (<see cref="Change"/>)</returns>
        public static IEnumerable<Change> CompareCommits(Commit reference, Commit compared)
        {
            var changes = new List<Change>();
            if (reference == null && compared == null)
                return changes;
            var repo = (reference ?? compared).Repository;
            var ref_tree = (reference != null ? reference.Tree._id : ObjectId.ZeroId);
            var compared_tree = (compared != null ? compared.Tree._id : ObjectId.ZeroId);
            var db = repo._internal_repo;
            var walk = new TreeWalk(db);
            if (reference == null || compared == null)
                walk.reset((reference ?? compared).Tree._id);
            else
                walk.reset(new GitSharp.Core.AnyObjectId[] {ref_tree, compared_tree});
            walk.Recursive = true;
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, TreeFilter.ALL));

            return CalculateCommitDiff(repo, walk, new[] { reference, compared });
        }
开发者ID:narent,项目名称:GitSharp,代码行数:25,代码来源:Commit.cs

示例5: testTwoLevelSubtree_FilterPath

        public void testTwoLevelSubtree_FilterPath()
        {
            DirCache dc = DirCache.read(db);

            FileMode mode = FileMode.RegularFile;
            string[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
            var ents = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(mode);
            }

            DirCacheBuilder b = dc.builder();
            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            var tw = new TreeWalk(db);
            for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
            {
                tw.reset();
                tw.addTree(new DirCacheIterator(dc));
                tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[victimIdx] }));
                tw.Recursive = tw.getFilter().shouldBeRecursive();
                Assert.IsTrue(tw.next());
                var c = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
                Assert.IsNotNull(c);
                Assert.AreEqual(victimIdx, c.Pointer);
                Assert.AreSame(ents[victimIdx], c.getDirCacheEntry());
                Assert.AreEqual(paths[victimIdx], tw.getPathString());
                Assert.AreEqual(mode.Bits, tw.getRawMode(0));
                Assert.AreSame(mode, tw.getFileMode(0));
                Assert.IsFalse(tw.next());
            }
        }
开发者ID:spraints,项目名称:GitSharp,代码行数:38,代码来源:DirCacheIteratorTest.cs


注:本文中的TreeWalk.setFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。