Example #1
0
            public override bool Include(TreeWalk walker)
            {
                int m = walker.GetRawMode(0);

                if (walker.GetRawMode(1) != m || !walker.IdEqual(1, 0))
                {
                    return(true);
                }
                if (walker.GetRawMode(2) != m || !walker.IdEqual(2, 0))
                {
                    return(true);
                }
                return(false);
            }
            public override bool Include(TreeWalk walker)
            {
                int n = walker.TreeCount;

                if (n == 1)
                {
                    // Assume they meant difference to empty tree.
                    return(true);
                }
                int m = walker.GetRawMode(0);

                for (int i = 1; i < n; i++)
                {
                    if (walker.GetRawMode(i) != m || !walker.IdEqual(i, 0))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Example #3
0
		static IEnumerable<Change> CalculateCommitDiff (NGit.Repository repo, TreeWalk walk, RevCommit[] commits)
		{
			while (walk.Next ()) {
				int m0 = walk.GetRawMode (0);
				if (walk.TreeCount == 2) {
					int m1 = walk.GetRawMode (1);
					var change = new Change { ReferenceCommit = commits[0], ComparedCommit = commits[1], ReferencePermissions = walk.GetFileMode (0).GetBits (), ComparedPermissions = walk.GetFileMode (1).GetBits (), Name = walk.NameString, Path = walk.PathString };
					if (m0 != 0 && m1 == 0) {
						change.ChangeType = ChangeType.Added;
						change.ComparedObject = walk.GetObjectId (0);
					} else if (m0 == 0 && m1 != 0) {
						change.ChangeType = ChangeType.Deleted;
						change.ReferenceObject = walk.GetObjectId (0);
					} else if (m0 != m1 && walk.IdEqual (0, 1)) {
						change.ChangeType = ChangeType.TypeChanged;
						change.ReferenceObject = walk.GetObjectId (0);
						change.ComparedObject = walk.GetObjectId (1);
					} else {
						change.ChangeType = ChangeType.Modified;
						change.ReferenceObject = walk.GetObjectId (0);
						change.ComparedObject = walk.GetObjectId (1);
					}
					yield return change;
				} else {
					var raw_modes = new int[walk.TreeCount - 1];
					for (int i = 0; i < walk.TreeCount - 1; i++)
						raw_modes[i] = walk.GetRawMode (i + 1);
					//ComparedCommit = compared,
					var change = new Change { ReferenceCommit = commits[0], Name = walk.NameString, Path = walk.PathString };
					if (m0 != 0 && raw_modes.All (m1 => m1 == 0)) {
						change.ChangeType = ChangeType.Added;
						change.ComparedObject = walk.GetObjectId (0);
						yield return change;
					} else if (m0 == 0 && raw_modes.Any (m1 => m1 != 0)) {
						change.ChangeType = ChangeType.Deleted;
						yield return change;
					// TODO: not sure if this condition suffices in some special cases.
					} else if (raw_modes.Select ((m1, i) => new { Mode = m1, Index = i + 1 }).All (x => !walk.IdEqual (0, x.Index))) {
						change.ChangeType = ChangeType.Modified;
						change.ReferenceObject = 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 = walk.GetObjectId (0);
						yield return change;
					}
				}
			}
		}
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override bool Include(TreeWalk tw)
        {
            int    cnt  = tw.TreeCount;
            int    wm   = tw.GetRawMode(workingTree);
            string path = tw.PathString;

            if (!tw.PostOrderTraversal)
            {
                // detect untracked Folders
                // Whenever we enter a folder in the workingtree assume it will
                // contain only untracked files and add it to
                // untrackedParentFolders. If we later find tracked files we will
                // remove it from this list
                if (FileMode.TREE.Equals(wm))
                {
                    // Clean untrackedParentFolders. This potentially moves entries
                    // from untrackedParentFolders to untrackedFolders
                    CopyUntrackedFolders(path);
                    // add the folder we just entered to untrackedParentFolders
                    untrackedParentFolders.AddFirst(path);
                }
                // detect untracked Folders
                // Whenever we see a tracked file we know that all of its parent
                // folders do not belong into untrackedParentFolders anymore. Clean
                // it.
                for (int i = 0; i < cnt; i++)
                {
                    int rmode = tw.GetRawMode(i);
                    if (i != workingTree && rmode != 0 && FileMode.TREE.Equals(rmode))
                    {
                        untrackedParentFolders.Clear();
                        break;
                    }
                }
            }
            // If the working tree file doesn't exist, it does exist for at least
            // one other so include this difference.
            if (wm == 0)
            {
                return(true);
            }
            // If the path does not appear in the DirCache and its ignored
            // we can avoid returning a result here, but only if its not in any
            // other tree.
            int dm = tw.GetRawMode(dirCache);
            WorkingTreeIterator wi = WorkingTree(tw);

            if (dm == 0)
            {
                if (honorIgnores && wi.IsEntryIgnored())
                {
                    ignoredPaths.AddItem(wi.EntryPathString);
                    int i = 0;
                    for (; i < cnt; i++)
                    {
                        if (i == dirCache || i == workingTree)
                        {
                            continue;
                        }
                        if (tw.GetRawMode(i) != 0)
                        {
                            break;
                        }
                    }
                    // If i is cnt then the path does not appear in any other tree,
                    // and this working tree entry can be safely ignored.
                    return(i == cnt ? false : true);
                }
                else
                {
                    // In working tree and not ignored, and not in DirCache.
                    return(true);
                }
            }
            // Always include subtrees as WorkingTreeIterator cannot provide
            // efficient elimination of unmodified subtrees.
            if (tw.IsSubtree)
            {
                return(true);
            }
            // Try the inexpensive comparisons between index and all real trees
            // first. Only if we don't find a diff here we have to bother with
            // the working tree
            for (int i_1 = 0; i_1 < cnt; i_1++)
            {
                if (i_1 == dirCache || i_1 == workingTree)
                {
                    continue;
                }
                if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
                {
                    return(true);
                }
            }
            // Only one chance left to detect a diff: between index and working
            // tree. Make use of the WorkingTreeIterator#isModified() method to
            // avoid computing SHA1 on filesystem content if not really needed.
            DirCacheIterator di = tw.GetTree <DirCacheIterator>(dirCache);

            return(wi.IsModified(di.GetDirCacheEntry(), true));
        }
Example #5
0
 static IEnumerable <Change> CalculateCommitDiff(NGit.Repository repo, TreeWalk walk, RevCommit[] commits)
 {
     while (walk.Next())
     {
         int m0 = walk.GetRawMode(0);
         if (walk.TreeCount == 2)
         {
             int m1     = walk.GetRawMode(1);
             var change = new Change {
                 ReferenceCommit = commits[0], ComparedCommit = commits[1], ReferencePermissions = walk.GetFileMode(0).GetBits(), ComparedPermissions = walk.GetFileMode(1).GetBits(), Name = walk.NameString, Path = walk.PathString
             };
             if (m0 != 0 && m1 == 0)
             {
                 change.ChangeType     = ChangeType.Added;
                 change.ComparedObject = walk.GetObjectId(0);
             }
             else if (m0 == 0 && m1 != 0)
             {
                 change.ChangeType      = ChangeType.Deleted;
                 change.ReferenceObject = walk.GetObjectId(0);
             }
             else if (m0 != m1 && walk.IdEqual(0, 1))
             {
                 change.ChangeType      = ChangeType.TypeChanged;
                 change.ReferenceObject = walk.GetObjectId(0);
                 change.ComparedObject  = walk.GetObjectId(1);
             }
             else
             {
                 change.ChangeType      = ChangeType.Modified;
                 change.ReferenceObject = walk.GetObjectId(0);
                 change.ComparedObject  = walk.GetObjectId(1);
             }
             yield return(change);
         }
         else
         {
             var raw_modes = new int[walk.TreeCount - 1];
             for (int i = 0; i < walk.TreeCount - 1; i++)
             {
                 raw_modes[i] = walk.GetRawMode(i + 1);
             }
             //ComparedCommit = compared,
             var change = new Change {
                 ReferenceCommit = commits[0], Name = walk.NameString, Path = walk.PathString
             };
             if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
             {
                 change.ChangeType     = ChangeType.Added;
                 change.ComparedObject = walk.GetObjectId(0);
                 yield return(change);
             }
             else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
             {
                 change.ChangeType = ChangeType.Deleted;
                 yield return(change);
                 // TODO: not sure if this condition suffices in some special cases.
             }
             else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).All(x => !walk.IdEqual(0, x.Index)))
             {
                 change.ChangeType      = ChangeType.Modified;
                 change.ReferenceObject = 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 = walk.GetObjectId(0);
                 yield return(change);
             }
         }
     }
 }
Example #6
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override bool Include(TreeWalk tw)
		{
			// If the working tree file doesn't exist, it does exist for at least
			// one other so include this difference.
			int wm = tw.GetRawMode(workingTree);
			if (wm == 0)
			{
				return true;
			}
			// If the path does not appear in the DirCache and its ignored
			// we can avoid returning a result here, but only if its not in any
			// other tree.
			int cnt = tw.TreeCount;
			int dm = tw.GetRawMode(dirCache);
			if (dm == 0)
			{
				if (honorIgnores && WorkingTree(tw).IsEntryIgnored())
				{
					int i = 0;
					for (; i < cnt; i++)
					{
						if (i == dirCache || i == workingTree)
						{
							continue;
						}
						if (tw.GetRawMode(i) != 0)
						{
							break;
						}
					}
					// If i is cnt then the path does not appear in any other tree,
					// and this working tree entry can be safely ignored.
					return i == cnt ? false : true;
				}
				else
				{
					// In working tree and not ignored, and not in DirCache.
					return true;
				}
			}
			// Always include subtrees as WorkingTreeIterator cannot provide
			// efficient elimination of unmodified subtrees.
			if (tw.IsSubtree)
			{
				return true;
			}
			// Try the inexpensive comparisons between index and all real trees
			// first. Only if we don't find a diff here we have to bother with
			// the working tree
			for (int i_1 = 0; i_1 < cnt; i_1++)
			{
				if (i_1 == dirCache || i_1 == workingTree)
				{
					continue;
				}
				if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
				{
					return true;
				}
			}
			// Only one chance left to detect a diff: between index and working
			// tree. Make use of the WorkingTreeIterator#isModified() method to
			// avoid computing SHA1 on filesystem content if not really needed.
			WorkingTreeIterator wi = WorkingTree(tw);
			DirCacheIterator di = tw.GetTree<DirCacheIterator>(dirCache);
			return wi.IsModified(di.GetDirCacheEntry(), true);
		}
        /// <exception cref="NGit.Errors.StopWalkException"></exception>
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override bool Include(RevWalk walker, RevCommit c)
        {
            // Reset the tree filter to scan this commit and parents.
            //
            RevCommit[] pList    = c.parents;
            int         nParents = pList.Length;
            TreeWalk    tw       = pathFilter;

            ObjectId[] trees = new ObjectId[nParents + 1];
            for (int i = 0; i < nParents; i++)
            {
                RevCommit p = c.parents[i];
                if ((p.flags & PARSED) == 0)
                {
                    p.ParseHeaders(walker);
                }
                trees[i] = p.Tree;
            }
            trees[nParents] = c.Tree;
            tw.Reset(trees);
            if (nParents == 1)
            {
                // We have exactly one parent. This is a very common case.
                //
                int chgs = 0;
                int adds = 0;
                while (tw.Next())
                {
                    chgs++;
                    if (tw.GetRawMode(0) == 0 && tw.GetRawMode(1) != 0)
                    {
                        adds++;
                    }
                    else
                    {
                        break;
                    }
                }
                // no point in looking at this further.
                if (chgs == 0)
                {
                    // No changes, so our tree is effectively the same as
                    // our parent tree. We pass the buck to our parent.
                    //
                    c.flags |= REWRITE;
                    return(false);
                }
                else
                {
                    // We have interesting items, but neither of the special
                    // cases denoted above.
                    //
                    if (adds > 0 && tw.Filter is FollowFilter)
                    {
                        // One of the paths we care about was added in this
                        // commit. We need to update our filter to its older
                        // name, if we can discover it. Find out what that is.
                        //
                        UpdateFollowFilter(trees);
                    }
                    return(true);
                }
            }
            else
            {
                if (nParents == 0)
                {
                    // We have no parents to compare against. Consider us to be
                    // REWRITE only if we have no paths matching our filter.
                    //
                    if (tw.Next())
                    {
                        return(true);
                    }
                    c.flags |= REWRITE;
                    return(false);
                }
            }
            // We are a merge commit. We can only be REWRITE if we are same
            // to _all_ parents. We may also be able to eliminate a parent if
            // it does not contribute changes to us. Such a parent may be an
            // uninteresting side branch.
            //
            int[] chgs_1 = new int[nParents];
            int[] adds_1 = new int[nParents];
            while (tw.Next())
            {
                int myMode = tw.GetRawMode(nParents);
                for (int i_1 = 0; i_1 < nParents; i_1++)
                {
                    int pMode = tw.GetRawMode(i_1);
                    if (myMode == pMode && tw.IdEqual(i_1, nParents))
                    {
                        continue;
                    }
                    chgs_1[i_1]++;
                    if (pMode == 0 && myMode != 0)
                    {
                        adds_1[i_1]++;
                    }
                }
            }
            bool same = false;
            bool diff = false;

            for (int i_2 = 0; i_2 < nParents; i_2++)
            {
                if (chgs_1[i_2] == 0)
                {
                    // No changes, so our tree is effectively the same as
                    // this parent tree. We pass the buck to only this one
                    // parent commit.
                    //
                    RevCommit p = pList[i_2];
                    if ((p.flags & UNINTERESTING) != 0)
                    {
                        // This parent was marked as not interesting by the
                        // application. We should look for another parent
                        // that is interesting.
                        //
                        same = true;
                        continue;
                    }
                    c.flags  |= REWRITE;
                    c.parents = new RevCommit[] { p };
                    return(false);
                }
                if (chgs_1[i_2] == adds_1[i_2])
                {
                    // All of the differences from this parent were because we
                    // added files that they did not have. This parent is our
                    // "empty tree root" and thus their history is not relevant.
                    // Cut our grandparents to be an empty list.
                    //
                    pList[i_2].parents = RevCommit.NO_PARENTS;
                }
                // We have an interesting difference relative to this parent.
                //
                diff = true;
            }
            if (diff && !same)
            {
                // We did not abort above, so we are different in at least one
                // way from all of our parents. We have to take the blame for
                // that difference.
                //
                return(true);
            }
            // We are the same as all of our parents. We must keep them
            // as they are and allow those parents to flow into pending
            // for further scanning.
            //
            c.flags |= REWRITE;
            return(false);
        }
Example #8
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override bool Include(TreeWalk tw)
        {
            // If the working tree file doesn't exist, it does exist for at least
            // one other so include this difference.
            int wm = tw.GetRawMode(workingTree);

            if (wm == 0)
            {
                return(true);
            }
            // If the path does not appear in the DirCache and its ignored
            // we can avoid returning a result here, but only if its not in any
            // other tree.
            int cnt = tw.TreeCount;
            int dm  = tw.GetRawMode(dirCache);

            if (dm == 0)
            {
                if (honorIgnores && WorkingTree(tw).IsEntryIgnored())
                {
                    int i = 0;
                    for (; i < cnt; i++)
                    {
                        if (i == dirCache || i == workingTree)
                        {
                            continue;
                        }
                        if (tw.GetRawMode(i) != 0)
                        {
                            break;
                        }
                    }
                    // If i is cnt then the path does not appear in any other tree,
                    // and this working tree entry can be safely ignored.
                    return(i == cnt ? false : true);
                }
                else
                {
                    // In working tree and not ignored, and not in DirCache.
                    return(true);
                }
            }
            // Always include subtrees as WorkingTreeIterator cannot provide
            // efficient elimination of unmodified subtrees.
            if (tw.IsSubtree)
            {
                return(true);
            }
            // Try the inexpensive comparisons between index and all real trees
            // first. Only if we don't find a diff here we have to bother with
            // the working tree
            for (int i_1 = 0; i_1 < cnt; i_1++)
            {
                if (i_1 == dirCache || i_1 == workingTree)
                {
                    continue;
                }
                if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
                {
                    return(true);
                }
            }
            // Only one chance left to detect a diff: between index and working
            // tree. Make use of the WorkingTreeIterator#isModified() method to
            // avoid computing SHA1 on filesystem content if not really needed.
            WorkingTreeIterator wi = WorkingTree(tw);
            DirCacheIterator    di = tw.GetTree <DirCacheIterator>(dirCache);

            return(wi.IsModified(di.GetDirCacheEntry(), true));
        }
Example #9
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override bool Include(TreeWalk tw)
		{
			int cnt = tw.TreeCount;
			int wm = tw.GetRawMode(workingTree);
			string path = tw.PathString;
			if (!tw.PostOrderTraversal)
			{
				// detect untracked Folders
				// Whenever we enter a folder in the workingtree assume it will
				// contain only untracked files and add it to
				// untrackedParentFolders. If we later find tracked files we will
				// remove it from this list
				if (FileMode.TREE.Equals(wm))
				{
					// Clean untrackedParentFolders. This potentially moves entries
					// from untrackedParentFolders to untrackedFolders
					CopyUntrackedFolders(path);
					// add the folder we just entered to untrackedParentFolders
					untrackedParentFolders.AddFirst(path);
				}
				// detect untracked Folders
				// Whenever we see a tracked file we know that all of its parent
				// folders do not belong into untrackedParentFolders anymore. Clean
				// it.
				for (int i = 0; i < cnt; i++)
				{
					int rmode = tw.GetRawMode(i);
					if (i != workingTree && rmode != 0 && FileMode.TREE.Equals(rmode))
					{
						untrackedParentFolders.Clear();
						break;
					}
				}
			}
			// If the working tree file doesn't exist, it does exist for at least
			// one other so include this difference.
			if (wm == 0)
			{
				return true;
			}
			// If the path does not appear in the DirCache and its ignored
			// we can avoid returning a result here, but only if its not in any
			// other tree.
			int dm = tw.GetRawMode(dirCache);
			WorkingTreeIterator wi = WorkingTree(tw);
			if (dm == 0)
			{
				if (honorIgnores && wi.IsEntryIgnored())
				{
					ignoredPaths.AddItem(wi.EntryPathString);
					int i = 0;
					for (; i < cnt; i++)
					{
						if (i == dirCache || i == workingTree)
						{
							continue;
						}
						if (tw.GetRawMode(i) != 0)
						{
							break;
						}
					}
					// If i is cnt then the path does not appear in any other tree,
					// and this working tree entry can be safely ignored.
					return i == cnt ? false : true;
				}
				else
				{
					// In working tree and not ignored, and not in DirCache.
					return true;
				}
			}
			// Always include subtrees as WorkingTreeIterator cannot provide
			// efficient elimination of unmodified subtrees.
			if (tw.IsSubtree)
			{
				return true;
			}
			// Try the inexpensive comparisons between index and all real trees
			// first. Only if we don't find a diff here we have to bother with
			// the working tree
			for (int i_1 = 0; i_1 < cnt; i_1++)
			{
				if (i_1 == dirCache || i_1 == workingTree)
				{
					continue;
				}
				if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
				{
					return true;
				}
			}
			// Only one chance left to detect a diff: between index and working
			// tree. Make use of the WorkingTreeIterator#isModified() method to
			// avoid computing SHA1 on filesystem content if not really needed.
			DirCacheIterator di = tw.GetTree<DirCacheIterator>(dirCache);
			return wi.IsModified(di.GetDirCacheEntry(), true);
		}
 // Modified version of GitSharp's Commit class
 private Change[] GetChanges(Repository repository, ObjectId id1, ObjectId id2)
 {
     var list = new List<Change>();
     TreeWalk walk = new TreeWalk(repository);
     walk.Reset(id1, id2);
     walk.Recursive = true;
     walk.Filter = TreeFilter.ANY_DIFF;
     while (walk.Next())
     {
         int m0 = walk.GetRawMode(0);
         if (walk.TreeCount == 2)
         {
             int m1 = walk.GetRawMode(1);
             var change = new Change
             {
                 Name = walk.PathString,
             };
             if (m0 != 0 && m1 == 0)
             {
                 change.ChangeType = ChangeType.Added;
             }
             else if (m0 == 0 && m1 != 0)
             {
                 change.ChangeType = ChangeType.Deleted;
             }
             else if (m0 != m1 && walk.IdEqual(0, 1))
             {
                 change.ChangeType = ChangeType.TypeChanged;
             }
             else
             {
                 change.ChangeType = ChangeType.Modified;
             }
             list.Add(change);
         }
         else
         {
             var raw_modes = new int[walk.TreeCount - 1];
             for (int i = 0; i < walk.TreeCount - 1; i++)
                 raw_modes[i] = walk.GetRawMode(i + 1);
             var change = new Change
             {
                 Name = walk.PathString,
             };
             if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
             {
                 change.ChangeType = ChangeType.Added;
                 list.Add(change);
             }
             else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
             {
                 change.ChangeType = ChangeType.Deleted;
                 list.Add(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;
                 list.Add(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;
                 list.Add(change);
             }
         }
     }
     return list.ToArray();
 }
Example #11
0
 public override bool Include(TreeWalk walker)
 {
     int n = walker.TreeCount;
     if (n == 1)
     {
         // Assume they meant difference to empty tree.
         return true;
     }
     int m = walker.GetRawMode(0);
     for (int i = 1; i < n; i++)
     {
         if (walker.GetRawMode(i) != m || !walker.IdEqual(i, 0))
         {
             return true;
         }
     }
     return false;
 }
Example #12
0
        // Modified version of GitSharp's Commit class
        private Change[] GetChanges(Repository repository, ObjectId id1, ObjectId id2)
        {
            var      list = new List <Change>();
            TreeWalk walk = new TreeWalk(repository);

            walk.Reset(id1, id2);
            walk.Recursive = true;
            walk.Filter    = TreeFilter.ANY_DIFF;
            while (walk.Next())
            {
                int m0 = walk.GetRawMode(0);
                if (walk.TreeCount == 2)
                {
                    int m1     = walk.GetRawMode(1);
                    var change = new Change
                    {
                        Name = walk.PathString,
                    };
                    if (m0 != 0 && m1 == 0)
                    {
                        change.ChangeType = ChangeType.Added;
                    }
                    else if (m0 == 0 && m1 != 0)
                    {
                        change.ChangeType = ChangeType.Deleted;
                    }
                    else if (m0 != m1 && walk.IdEqual(0, 1))
                    {
                        change.ChangeType = ChangeType.TypeChanged;
                    }
                    else
                    {
                        change.ChangeType = ChangeType.Modified;
                    }
                    list.Add(change);
                }
                else
                {
                    var raw_modes = new int[walk.TreeCount - 1];
                    for (int i = 0; i < walk.TreeCount - 1; i++)
                    {
                        raw_modes[i] = walk.GetRawMode(i + 1);
                    }
                    var change = new Change
                    {
                        Name = walk.PathString,
                    };
                    if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
                    {
                        change.ChangeType = ChangeType.Added;
                        list.Add(change);
                    }
                    else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
                    {
                        change.ChangeType = ChangeType.Deleted;
                        list.Add(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;
                        list.Add(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;
                        list.Add(change);
                    }
                }
            }
            return(list.ToArray());
        }