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


C# TreeWalk.Reset方法代码示例

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


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

示例1: TestResetDoesNotAffectPostOrder

		public virtual void TestResetDoesNotAffectPostOrder()
		{
			TreeWalk tw = new TreeWalk(db);
			tw.PostOrderTraversal = true;
			NUnit.Framework.Assert.IsTrue(tw.PostOrderTraversal);
			tw.Reset();
			NUnit.Framework.Assert.IsTrue(tw.PostOrderTraversal);
			tw.PostOrderTraversal = false;
			NUnit.Framework.Assert.IsFalse(tw.PostOrderTraversal);
			tw.Reset();
			NUnit.Framework.Assert.IsFalse(tw.PostOrderTraversal);
		}
开发者ID:shoff,项目名称:ngit,代码行数:12,代码来源:PostOrderTreeWalkTest.cs

示例2: CompareCommits

		/// <summary>
		/// Compares two commits and returns a list of files that have changed
		/// </summary>
		public static IEnumerable<Change> CompareCommits (NGit.Repository repo, RevCommit reference, RevCommit compared)
		{
			var changes = new List<Change>();
			if (reference == null && compared == null)
				return changes;
			ObjectId refTree = (reference != null ? reference.Tree.Id : ObjectId.ZeroId);
			ObjectId comparedTree = (compared != null ? compared.Tree.Id : ObjectId.ZeroId);
			var walk = new TreeWalk (repo);
			if (reference == null || compared == null)
				walk.Reset ((reference ?? compared).Tree.Id);
			else
				walk.Reset (new AnyObjectId[] {refTree, comparedTree});
			walk.Recursive = true;
			walk.Filter = AndTreeFilter.Create(TreeFilter.ANY_DIFF, TreeFilter.ALL);

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

示例3: GetConflictedFiles

		public static List<string> GetConflictedFiles (NGit.Repository repo)
		{
			List<string> list = new List<string> ();
			TreeWalk treeWalk = new TreeWalk (repo);
			treeWalk.Reset ();
			treeWalk.Recursive = true;
			DirCache dc = repo.ReadDirCache ();
			treeWalk.AddTree (new DirCacheIterator (dc));
			while (treeWalk.Next()) {
				DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(0);
				var ce = dirCacheIterator.GetDirCacheEntry ();
				if (ce != null && ce.Stage == 1)
					list.Add (ce.PathString);
			}
			return list;
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:16,代码来源:GitUtil.cs

示例4: OnRevert

		protected override void OnRevert (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
		{
			// Replace with NGit.Api.Git.Reset ()
			// FIXME: we lack info about what happened to files
			foreach (var group in GroupByRepository (localPaths)) {
				var repository = group.Key;
				var files = group.ToArray ();

			var c = GetHeadCommit (repository);
			RevTree tree = c != null ? c.Tree : null;
			
			List<FilePath> changedFiles = new List<FilePath> ();
			List<FilePath> removedFiles = new List<FilePath> ();
			
			monitor.BeginTask (GettextCatalog.GetString ("Reverting files"), 3);
			monitor.BeginStepTask (GettextCatalog.GetString ("Reverting files"), files.Length, 2);
			
			DirCache dc = repository.LockDirCache ();
			DirCacheBuilder builder = dc.Builder ();
			
			try {
				HashSet<string> entriesToRemove = new HashSet<string> ();
				HashSet<string> foldersToRemove = new HashSet<string> ();
				
				// Add the new entries
				foreach (FilePath fp in files) {
					string p = repository.ToGitPath (fp);
					
					// Register entries to be removed from the index
					if (Directory.Exists (fp))
						foldersToRemove.Add (p);
					else
						entriesToRemove.Add (p);
					
					TreeWalk tw = tree != null ? TreeWalk.ForPath (repository, p, tree) : null;
					if (tw == null) {
						// Removed from the index
					}
					else {
						// Add new entries
						
						TreeWalk r;
						if (tw.IsSubtree) {
							// It's a directory. Make sure we remove existing index entries of this directory
							foldersToRemove.Add (p);
							
							// We have to iterate through all folder files. We need a new iterator since the
							// existing rw is not recursive
							r = new TreeWalk(repository);
							r.Reset (tree);
							r.Filter = PathFilterGroup.CreateFromStrings(new string[]{p});
							r.Recursive = true;
							r.Next ();
						} else {
							r = tw;
						}
						
						do {
							// There can be more than one entry if reverting a whole directory
							string rpath = repository.FromGitPath (r.PathString);
							DirCacheEntry e = new DirCacheEntry (r.PathString);
							e.SetObjectId (r.GetObjectId (0));
							e.FileMode = r.GetFileMode (0);
							if (!Directory.Exists (Path.GetDirectoryName (rpath)))
								Directory.CreateDirectory (rpath);
							DirCacheCheckout.CheckoutEntry (repository, rpath, e);
							builder.Add (e);
							changedFiles.Add (rpath);
						} while (r.Next ());
					}
					monitor.Step (1);
				}
				
				// Add entries we want to keep
				int count = dc.GetEntryCount ();
				for (int n=0; n<count; n++) {
					DirCacheEntry e = dc.GetEntry (n);
					string path = e.PathString;
					if (!entriesToRemove.Contains (path) && !foldersToRemove.Any (f => IsSubpath (f,path)))
						builder.Add (e);
				}
				
				builder.Commit ();
			}
			catch {
				dc.Unlock ();
				throw;
			}
			
			monitor.EndTask ();
			monitor.BeginTask (null, files.Length);

			foreach (FilePath p in changedFiles) {
				FileService.NotifyFileChanged (p, true);
				monitor.Step (1);
			}
			foreach (FilePath p in removedFiles) {
				FileService.NotifyFileRemoved (p);
				monitor.Step (1);
			}
//.........这里部分代码省略.........
开发者ID:Chertolom,项目名称:monodevelop,代码行数:101,代码来源:GitRepository.cs

示例5: GetCommitChanges

		/// <summary>
		/// Returns a list of files that have changed in a commit
		/// </summary>
		public static IEnumerable<Change> GetCommitChanges (NGit.Repository repo, RevCommit commit)
		{
			var treeIds = new[] { commit.Tree.Id }.Concat (commit.Parents.Select (c => c.Tree.Id)).ToArray ();
			var walk = new TreeWalk (repo);
			walk.Reset (treeIds);
			walk.Recursive = true;
			walk.Filter = AndTreeFilter.Create (AndTreeFilter.ANY_DIFF, AndTreeFilter.ALL);
			
			return CalculateCommitDiff (repo, walk, new[] { commit }.Concat (commit.Parents).ToArray ());
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:13,代码来源:GitUtil.cs

示例6: TestTwoLevelSubtree_FilterPath

		public virtual void TestTwoLevelSubtree_FilterPath()
		{
			DirCache dc = DirCache.NewInCore();
			FileMode mode = FileMode.REGULAR_FILE;
			string[] paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
			DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
			for (int i = 0; i < paths.Length; i++)
			{
				ents[i] = new DirCacheEntry(paths[i]);
				ents[i].FileMode = mode;
			}
			DirCacheBuilder b = dc.Builder();
			for (int i_1 = 0; i_1 < ents.Length; i_1++)
			{
				b.Add(ents[i_1]);
			}
			b.Finish();
			TreeWalk tw = new TreeWalk(db);
			for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
			{
				tw.Reset();
				tw.AddTree(new DirCacheIterator(dc));
				tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[victimIdx
					]));
				tw.Recursive = tw.Filter.ShouldBeRecursive();
				NUnit.Framework.Assert.IsTrue(tw.Next());
				DirCacheIterator c = tw.GetTree<DirCacheIterator>(0);
				NUnit.Framework.Assert.IsNotNull(c);
				NUnit.Framework.Assert.AreEqual(victimIdx, c.ptr);
				NUnit.Framework.Assert.AreSame(ents[victimIdx], c.GetDirCacheEntry());
				NUnit.Framework.Assert.AreEqual(paths[victimIdx], tw.PathString);
				NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
				NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
				NUnit.Framework.Assert.IsFalse(tw.Next());
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:36,代码来源:DirCacheIteratorTest.cs

示例7: UpdateDirectory

		/// <summary>
		/// Run the diff operation. Until this is called, all lists will be empty
		/// </summary>
		/// <returns>true if anything is different between index, tree, and workdir</returns>
		private void UpdateDirectory (IEnumerable<string> paths, bool recursive)
		{
			RevWalk rw = new RevWalk (Repository);
			ObjectId id = Repository.Resolve (Constants.HEAD);
			var commit = id != null ? rw.ParseCommit (id) : null;
			
			TreeWalk treeWalk = new TreeWalk (Repository);
			treeWalk.Reset ();
			treeWalk.Recursive = false;

			if (commit != null)
				treeWalk.AddTree (commit.Tree);
			else
				treeWalk.AddTree (new EmptyTreeIterator());
			
			DirCache dc = Repository.ReadDirCache ();
			treeWalk.AddTree (new DirCacheIterator (dc));
			
			FileTreeIterator workTree = new FileTreeIterator (Repository.WorkTree, Repository.FileSystem, WorkingTreeOptions.KEY.Parse(Repository.GetConfig()));
			treeWalk.AddTree (workTree);

			List<TreeFilter> filters = new List<TreeFilter> ();
			filters.Add (new SkipWorkTreeFilter(1));
			
			var pathFilters = paths.Where (p => p != ".").Select (p => PathFilter.Create (p)).ToArray ();
			if (pathFilters.Length > 1) {
				filters.Add (OrTreeFilter.Create (pathFilters)); // Use an OR to join all path filters
			} else if (pathFilters.Length == 1)
				filters.Add (pathFilters[0]);

			if (filters.Count > 1)
				treeWalk.Filter = AndTreeFilter.Create(filters);
			else
				treeWalk.Filter = filters[0];
			
			while (treeWalk.Next())
			{
				AbstractTreeIterator treeIterator = treeWalk.GetTree<AbstractTreeIterator>(0);
				DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(1);
				WorkingTreeIterator workingTreeIterator = treeWalk.GetTree<WorkingTreeIterator>(2);
				NGit.FileMode fileModeTree = treeWalk.GetFileMode(0);
				
				if (treeWalk.IsSubtree) {
					treeWalk.EnterSubtree ();
					continue;
				}
				
				int stage = dirCacheIterator != null ? dirCacheIterator.GetDirCacheEntry ().Stage : 0;
				if (stage > 1)
					continue;
				else if (stage == 1) {
					MergeConflict.Add(dirCacheIterator.EntryPathString);
					changesExist = true;
					continue;
				}
				
				if (treeIterator != null)
				{
					if (dirCacheIterator != null)
					{
						if (!treeIterator.EntryObjectId.Equals(dirCacheIterator.EntryObjectId))
						{
							// in repo, in index, content diff => changed
							Modified.Add(dirCacheIterator.EntryPathString);
							changesExist = true;
						}
					}
					else
					{
						// in repo, not in index => removed
						if (!fileModeTree.Equals(NGit.FileMode.TYPE_TREE))
						{
							Removed.Add(treeIterator.EntryPathString);
							changesExist = true;
						}
					}
				}
				else
				{
					if (dirCacheIterator != null)
					{
						// not in repo, in index => added
						Added.Add(dirCacheIterator.EntryPathString);
						changesExist = true;
					}
					else
					{
						// not in repo, not in index => untracked
						if (workingTreeIterator != null && !workingTreeIterator.IsEntryIgnored())
						{
							Untracked.Add(workingTreeIterator.EntryPathString);
							changesExist = true;
						}
					}
				}
				if (dirCacheIterator != null)
//.........这里部分代码省略.........
开发者ID:yayanyang,项目名称:monodevelop,代码行数:101,代码来源:RepositoryStatus.cs

示例8: TestPick

		public virtual void TestPick()
		{
			// B---O
			// \----P---T
			//
			// Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
			// was created by "P", nor should it modify "a", which was done by "P".
			//
			DirCache treeB = db.ReadDirCache();
			DirCache treeO = db.ReadDirCache();
			DirCache treeP = db.ReadDirCache();
			DirCache treeT = db.ReadDirCache();
			{
				DirCacheBuilder b = treeB.Builder();
				DirCacheBuilder o = treeO.Builder();
				DirCacheBuilder p = treeP.Builder();
				DirCacheBuilder t = treeT.Builder();
				b.Add(CreateEntry("a", FileMode.REGULAR_FILE));
				o.Add(CreateEntry("a", FileMode.REGULAR_FILE));
				o.Add(CreateEntry("o", FileMode.REGULAR_FILE));
				p.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
				p.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("a", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("t", FileMode.REGULAR_FILE));
				b.Finish();
				o.Finish();
				p.Finish();
				t.Finish();
			}
			ObjectInserter ow = db.NewObjectInserter();
			ObjectId B = Commit(ow, treeB, new ObjectId[] {  });
			ObjectId O = Commit(ow, treeO, new ObjectId[] { B });
			ObjectId P = Commit(ow, treeP, new ObjectId[] { B });
			ObjectId T = Commit(ow, treeT, new ObjectId[] { P });
			ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
				(db));
			twm.SetBase(P);
			bool merge = twm.Merge(new ObjectId[] { O, T });
			NUnit.Framework.Assert.IsTrue(merge);
			TreeWalk tw = new TreeWalk(db);
			tw.Recursive = true;
			tw.Reset(twm.GetResultTreeId());
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("a", tw.PathString);
			AssertCorrectId(treeO, tw);
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("o", tw.PathString);
			AssertCorrectId(treeO, tw);
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("t", tw.PathString);
			AssertCorrectId(treeT, tw);
			NUnit.Framework.Assert.IsFalse(tw.Next());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:53,代码来源:CherryPickTest.cs

示例9: TestRevert

		public virtual void TestRevert()
		{
			// B---P---T
			//
			// Revert P, this should result in a tree with a
			// from B and t from T as the change to a in P
			// and addition of t in P is reverted.
			//
			// We use the standard merge, but change the order
			// of the sources.
			//
			DirCache treeB = db.ReadDirCache();
			DirCache treeP = db.ReadDirCache();
			DirCache treeT = db.ReadDirCache();
			{
				DirCacheBuilder b = treeB.Builder();
				DirCacheBuilder p = treeP.Builder();
				DirCacheBuilder t = treeT.Builder();
				b.Add(CreateEntry("a", FileMode.REGULAR_FILE));
				p.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
				p.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
				t.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("t", FileMode.REGULAR_FILE));
				b.Finish();
				p.Finish();
				t.Finish();
			}
			ObjectInserter ow = db.NewObjectInserter();
			ObjectId B = Commit(ow, treeB, new ObjectId[] {  });
			ObjectId P = Commit(ow, treeP, new ObjectId[] { B });
			ObjectId T = Commit(ow, treeT, new ObjectId[] { P });
			ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
				(db));
			twm.SetBase(P);
			bool merge = twm.Merge(new ObjectId[] { B, T });
			NUnit.Framework.Assert.IsTrue(merge);
			TreeWalk tw = new TreeWalk(db);
			tw.Recursive = true;
			tw.Reset(twm.GetResultTreeId());
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("a", tw.PathString);
			AssertCorrectId(treeB, tw);
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("t", tw.PathString);
			AssertCorrectId(treeT, tw);
			NUnit.Framework.Assert.IsFalse(tw.Next());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:48,代码来源:CherryPickTest.cs

示例10: TestTrivialTwoWay_concurrentSubtreeChange

		public virtual void TestTrivialTwoWay_concurrentSubtreeChange()
		{
			DirCache treeB = db.ReadDirCache();
			DirCache treeO = db.ReadDirCache();
			DirCache treeT = db.ReadDirCache();
			{
				DirCacheBuilder b = treeB.Builder();
				DirCacheBuilder o = treeO.Builder();
				DirCacheBuilder t = treeT.Builder();
				b.Add(CreateEntry("d/o", FileMode.REGULAR_FILE));
				b.Add(CreateEntry("d/t", FileMode.REGULAR_FILE));
				o.Add(CreateEntry("d/o", FileMode.REGULAR_FILE, "o !"));
				o.Add(CreateEntry("d/t", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("d/o", FileMode.REGULAR_FILE));
				t.Add(CreateEntry("d/t", FileMode.REGULAR_FILE, "t !"));
				b.Finish();
				o.Finish();
				t.Finish();
			}
			ObjectInserter ow = db.NewObjectInserter();
			ObjectId b_1 = Commit(ow, treeB, new ObjectId[] {  });
			ObjectId o_1 = Commit(ow, treeO, new ObjectId[] { b_1 });
			ObjectId t_1 = Commit(ow, treeT, new ObjectId[] { b_1 });
			Merger ourMerger = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
				(db));
			bool merge = ourMerger.Merge(new ObjectId[] { o_1, t_1 });
			NUnit.Framework.Assert.IsTrue(merge);
			TreeWalk tw = new TreeWalk(db);
			tw.Recursive = true;
			tw.Reset(ourMerger.GetResultTreeId());
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("d/o", tw.PathString);
			AssertCorrectId(treeO, tw);
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("d/t", tw.PathString);
			AssertCorrectId(treeT, tw);
			NUnit.Framework.Assert.IsFalse(tw.Next());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:38,代码来源:SimpleMergeTest.cs

示例11: TestMissingSubtree_DetectFileAdded_FileModified

		public virtual void TestMissingSubtree_DetectFileAdded_FileModified()
		{
			ObjectInserter inserter = db.NewObjectInserter();
			ObjectId aFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("a"));
			ObjectId bFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("b"));
			ObjectId cFileId1 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-1"));
			ObjectId cFileId2 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-2"));
			// Create sub-a/empty, sub-c/empty = hello.
			ObjectId oldTree;
			{
				Tree root = new Tree(db);
				{
					Tree subA = root.AddTree("sub-a");
					subA.AddFile("empty").SetId(aFileId);
					subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format()));
				}
				{
					Tree subC = root.AddTree("sub-c");
					subC.AddFile("empty").SetId(cFileId1);
					subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format()));
				}
				oldTree = inserter.Insert(Constants.OBJ_TREE, root.Format());
			}
			// Create sub-a/empty, sub-b/empty, sub-c/empty.
			ObjectId newTree;
			{
				Tree root = new Tree(db);
				{
					Tree subA = root.AddTree("sub-a");
					subA.AddFile("empty").SetId(aFileId);
					subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format()));
				}
				{
					Tree subB = root.AddTree("sub-b");
					subB.AddFile("empty").SetId(bFileId);
					subB.SetId(inserter.Insert(Constants.OBJ_TREE, subB.Format()));
				}
				{
					Tree subC = root.AddTree("sub-c");
					subC.AddFile("empty").SetId(cFileId2);
					subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format()));
				}
				newTree = inserter.Insert(Constants.OBJ_TREE, root.Format());
			}
			inserter.Flush();
			inserter.Release();
			TreeWalk tw = new TreeWalk(db);
			tw.Reset(oldTree, newTree);
			tw.Recursive = true;
			tw.Filter = TreeFilter.ANY_DIFF;
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("sub-b/empty", tw.PathString);
			NUnit.Framework.Assert.AreEqual(FileMode.MISSING, tw.GetFileMode(0));
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1));
			NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tw.GetObjectId(0));
			NUnit.Framework.Assert.AreEqual(bFileId, tw.GetObjectId(1));
			NUnit.Framework.Assert.IsTrue(tw.Next());
			NUnit.Framework.Assert.AreEqual("sub-c/empty", tw.PathString);
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(0));
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1));
			NUnit.Framework.Assert.AreEqual(cFileId1, tw.GetObjectId(0));
			NUnit.Framework.Assert.AreEqual(cFileId2, tw.GetObjectId(1));
			NUnit.Framework.Assert.IsFalse(tw.Next());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:64,代码来源:TreeWalkBasicDiffTest.cs

示例12: TestLeafSplitsWhenFull

		public virtual void TestLeafSplitsWhenFull()
		{
			RevBlob data1 = tr.Blob("data1");
			MutableObjectId idBuf = new MutableObjectId();
			RevCommit r = tr.Commit().Add(data1.Name, data1).Create();
			//
			//
			tr.ParseBody(r);
			NoteMap map = NoteMap.Read(reader, r);
			for (int i = 0; i < 254; i++)
			{
				idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i);
				map.Set(idBuf, data1);
			}
			RevCommit n = CommitNoteMap(map);
			TreeWalk tw = new TreeWalk(reader);
			tw.Reset(n.Tree);
			while (tw.Next())
			{
				NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree");
			}
			for (int i_1 = 254; i_1 < 256; i_1++)
			{
				idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1);
				map.Set(idBuf, data1);
			}
			idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1);
			map.Set(idBuf, data1);
			n = CommitNoteMap(map);
			// The 00 bucket is fully split.
			string path = Fanout(38, idBuf.Name);
			tw = TreeWalk.ForPath(reader, path, n.Tree);
			NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
			// The other bucket is not.
			path = Fanout(2, data1.Name);
			tw = TreeWalk.ForPath(reader, path, n.Tree);
			NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:38,代码来源:NoteMapTest.cs

示例13: GetChanges

 // 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();
 }
开发者ID:Frrank1,项目名称:Git-Source-Control-Provider,代码行数:69,代码来源:RepositoryGraph.cs

示例14: ShouldReportFileModeChange

		public virtual void ShouldReportFileModeChange()
		{
			WriteTrashFile("a.txt", "content");
			Git git = new Git(db);
			git.Add().AddFilepattern("a.txt").Call();
			RevCommit c1 = git.Commit().SetMessage("initial commit").Call();
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			TreeWalk walk = new TreeWalk(db);
			walk.AddTree(c1.Tree);
			walk.Recursive = true;
			NUnit.Framework.Assert.IsTrue(walk.Next());
			editor.Add(new _PathEdit_318(walk, "a.txt"));
			NUnit.Framework.Assert.IsTrue(editor.Commit());
			RevCommit c2 = git.Commit().SetMessage("second commit").Call();
			walk.Reset();
			walk.AddTree(c1.Tree);
			walk.AddTree(c2.Tree);
			IList<DiffEntry> diffs = DiffEntry.Scan(walk, false);
			NUnit.Framework.Assert.AreEqual(1, diffs.Count);
			DiffEntry diff = diffs[0];
			NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, diff.GetChangeType()
				);
			NUnit.Framework.Assert.AreEqual(diff.GetOldId(), diff.GetNewId());
			NUnit.Framework.Assert.AreEqual("a.txt", diff.GetOldPath());
			NUnit.Framework.Assert.AreEqual(diff.GetOldPath(), diff.GetNewPath());
			NUnit.Framework.Assert.AreEqual(FileMode.EXECUTABLE_FILE, diff.GetNewMode());
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, diff.GetOldMode());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:29,代码来源:DiffEntryTest.cs


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