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


C# TreeWalk.getTreeCount方法代码示例

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


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

示例1: include

            public override bool include(TreeWalk walker)
            {
                int n = walker.getTreeCount();
                if (n == 1) // Assume they meant difference to empty tree.
                    return true;

                int m = walker.getRawMode(baseTree);
                for (int i = 1; i < n; i++)
                    if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree))
                        return true;
                return false;
            }
开发者ID:ArildF,项目名称:GitSharp,代码行数:12,代码来源:TreeFilter.cs

示例2: CalculateCommitDiff

 /// <summary>
 /// compare the given commits and return the changes.
 /// </summary>
 /// <param name="repo"></param>
 /// <param name="walk"></param>
 /// <param name="commits">first commit in the array is the commit that is compared against the others which are his ancestors (i.e. from different branches)</param>
 /// <returns></returns>
 private static IEnumerable<Change> CalculateCommitDiff(Repository repo, TreeWalk walk, Commit[] commits)
 {
     while (walk.next())
     {
         int m0 = walk.getRawMode(0);
         if (walk.getTreeCount() == 2)
         {
             int m1 = walk.getRawMode(1);
             var change = new Change
             {
                 ReferenceCommit = commits[0],
                 ComparedCommit = commits[1],
                 ReferencePermissions = walk.getFileMode(0).Bits,
                 ComparedPermissions = walk.getFileMode(1).Bits,
                 Name = walk.getNameString(),
                 Path = walk.getPathString(),
             };
             if (m0 != 0 && m1 == 0)
             {
                 change.ChangeType = ChangeType.Added;
                 change.ComparedObject = Wrap(repo, walk.getObjectId(0));
             }
             else if (m0 == 0 && m1 != 0)
             {
                 change.ChangeType = ChangeType.Deleted;
                 change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
             }
             else if (m0 != m1 && walk.idEqual(0, 1))
             {
                 change.ChangeType = ChangeType.TypeChanged;
                 change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
                 change.ComparedObject = Wrap(repo, walk.getObjectId(1));
             }
             else
             {
                 change.ChangeType = ChangeType.Modified;
                 change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
                 change.ComparedObject = Wrap(repo, walk.getObjectId(1));
             }
             yield return change;
         }
         else
         {
             var raw_modes = new int[walk.getTreeCount()-1];
             for(int i = 0;i<walk.getTreeCount()-1; i++)
                 raw_modes[i] = walk.getRawMode(i+1);
             var change = new Change
             {
                 ReferenceCommit = commits[0],
                 //ComparedCommit = compared,
                 Name = walk.getNameString(),
                 Path = walk.getPathString(),
             };
             if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
             {
                 change.ChangeType = ChangeType.Added;
                 change.ComparedObject = Wrap(repo, walk.getObjectId(0));
                 yield return change;
             }
             else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
             {
                 change.ChangeType = ChangeType.Deleted;
                 yield return change;
             }
             else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).All(x => !walk.idEqual(0, x.Index))) // TODO: not sure if this condition suffices in some special cases.
             {
                 change.ChangeType = ChangeType.Modified;
                 change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
                 yield return change;
             }
             else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).Any(x => m0 != x.Mode && walk.idEqual(0, x.Index)))
             {
                 change.ChangeType = ChangeType.TypeChanged;
                 change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
                 yield return change;
             }
         }
     }
 }
开发者ID:narent,项目名称:GitSharp,代码行数:86,代码来源:Commit.cs

示例3: 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

示例4: 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


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