/// <exception cref="NGit.Errors.CorruptObjectException"></exception> /// <exception cref="System.IO.IOException"></exception> private void TestLongPath(int len) { string longPath = MakeLongPath(len); string shortPath = "~~~ shorter-path"; DirCacheEntry longEnt = new DirCacheEntry(longPath); DirCacheEntry shortEnt = new DirCacheEntry(shortPath); longEnt.FileMode = FileMode.REGULAR_FILE; shortEnt.FileMode = FileMode.REGULAR_FILE; NUnit.Framework.Assert.AreEqual(longPath, longEnt.PathString); NUnit.Framework.Assert.AreEqual(shortPath, shortEnt.PathString); { DirCache dc1 = db.LockDirCache(); { DirCacheBuilder b = dc1.Builder(); b.Add(longEnt); b.Add(shortEnt); NUnit.Framework.Assert.IsTrue(b.Commit()); } NUnit.Framework.Assert.AreEqual(2, dc1.GetEntryCount()); NUnit.Framework.Assert.AreSame(longEnt, dc1.GetEntry(0)); NUnit.Framework.Assert.AreSame(shortEnt, dc1.GetEntry(1)); } { DirCache dc2 = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(2, dc2.GetEntryCount()); NUnit.Framework.Assert.AreNotSame(longEnt, dc2.GetEntry(0)); NUnit.Framework.Assert.AreEqual(longPath, dc2.GetEntry(0).PathString); NUnit.Framework.Assert.AreNotSame(shortEnt, dc2.GetEntry(1)); NUnit.Framework.Assert.AreEqual(shortPath, dc2.GetEntry(1).PathString); } }
public virtual void TestNoSubtree_NoTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); int pathIdx = 0; for (; !i_2.Eof; i_2.Next(1)) { NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestAdd_ReverseGitSortOrder() { DirCache dc = db.ReadDirCache(); string[] paths = new string[] { "a.", "a.b", "a/b", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = ents.Length - 1; i_1 >= 0; i_1--) { b.Add(ents[i_1]); } b.Finish(); NUnit.Framework.Assert.AreEqual(paths.Length, dc.GetEntryCount()); for (int i_2 = 0; i_2 < paths.Length; i_2++) { NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(i_2)); NUnit.Framework.Assert.AreEqual(paths[i_2], dc.GetEntry(i_2).PathString); NUnit.Framework.Assert.AreEqual(i_2, dc.FindEntry(paths[i_2])); NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(paths[i_2])); } }
public virtual void TestBuilderClear() { DirCache dc = db.ReadDirCache(); string[] paths = new string[] { "a.", "a.b", "a/b", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } { DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); } NUnit.Framework.Assert.AreEqual(paths.Length, dc.GetEntryCount()); { DirCacheBuilder b = dc.Builder(); b.Finish(); } NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount()); }
public virtual void TestWriteReadTree() { DirCache dc = db.LockDirCache(); string A = string.Format("a%2000s", "a"); string B = string.Format("b%2000s", "b"); string[] paths = new string[] { A + ".", A + "." + B, A + "/" + B, A + "0" + B }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Commit(); DirCache read = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(paths.Length, read.GetEntryCount()); NUnit.Framework.Assert.AreEqual(1, read.GetCacheTree(true).GetChildCount()); }
public virtual void TestEntriesWithin() { DirCache dc = db.ReadDirCache(); string[] paths = new string[] { "a.", "a/b", "a/c", "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 = FileMode.REGULAR_FILE; } int aFirst = 1; int aLast = 3; DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); NUnit.Framework.Assert.AreEqual(paths.Length, dc.GetEntryCount()); for (int i_2 = 0; i_2 < ents.Length; i_2++) { NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(i_2)); } { DirCacheEntry[] aContents = dc.GetEntriesWithin("a"); NUnit.Framework.Assert.IsNotNull(aContents); NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aContents.Length); for (int i_3 = aFirst, j = 0; i_3 <= aLast; i_3++, j++) { NUnit.Framework.Assert.AreSame(ents[i_3], aContents[j]); } } { DirCacheEntry[] aContents = dc.GetEntriesWithin("a/"); NUnit.Framework.Assert.IsNotNull(aContents); NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aContents.Length); for (int i_3 = aFirst, j = 0; i_3 <= aLast; i_3++, j++) { NUnit.Framework.Assert.AreSame(ents[i_3], aContents[j]); } } { DirCacheEntry[] aContents = dc.GetEntriesWithin(string.Empty); NUnit.Framework.Assert.IsNotNull(aContents); NUnit.Framework.Assert.AreEqual(ents.Length, aContents.Length); for (int i_3 = 0; i_3 < ents.Length; i_3++) { NUnit.Framework.Assert.AreSame(ents[i_3], aContents[i_3]); } } NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("a.")); NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("a.").Length); NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("a0b")); NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("a0b.").Length); NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("zoo")); NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("zoo.").Length); }
public virtual void TestBuildOneFile_Commit_IndexChangedEvent() { // empty string path = "a-file-path"; FileMode mode = FileMode.REGULAR_FILE; // "old" date in 2008 long lastModified = 1218123387057L; int length = 1342; DirCacheEntry entOrig; bool receivedEvent = false; DirCache dc = db.LockDirCache(); IndexChangedListener listener = new _IndexChangedListener_212(); ListenerList l = db.Listeners; l.AddIndexChangedListener(listener); DirCacheBuilder b = dc.Builder(); entOrig = new DirCacheEntry(path); entOrig.FileMode = mode; entOrig.LastModified = lastModified; entOrig.SetLength(length); b.Add(entOrig); try { b.Commit(); } catch (_T123327308) { receivedEvent = true; } if (!receivedEvent) { NUnit.Framework.Assert.Fail("did not receive IndexChangedEvent"); } // do the same again, as this doesn't change index compared to first // round we should get no event this time dc = db.LockDirCache(); listener = new _IndexChangedListener_239(); l = db.Listeners; l.AddIndexChangedListener(listener); b = dc.Builder(); entOrig = new DirCacheEntry(path); entOrig.FileMode = mode; entOrig.LastModified = lastModified; entOrig.SetLength(length); b.Add(entOrig); try { b.Commit(); } catch (_T123327308) { NUnit.Framework.Assert.Fail("unexpected IndexChangedEvent"); } }
public virtual void TestTwoLevelSubtree() { DirCache dc = db.ReadDirCache(); 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 = FileMode.REGULAR_FILE; } int aFirst = 1; int aLast = 4; int acFirst = 2; int acLast = 3; DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); NUnit.Framework.Assert.IsNull(dc.GetCacheTree(false)); DirCacheTree root = dc.GetCacheTree(true); NUnit.Framework.Assert.IsNotNull(root); NUnit.Framework.Assert.AreSame(root, dc.GetCacheTree(true)); NUnit.Framework.Assert.AreEqual(string.Empty, root.GetNameString()); NUnit.Framework.Assert.AreEqual(string.Empty, root.GetPathString()); NUnit.Framework.Assert.AreEqual(1, root.GetChildCount()); NUnit.Framework.Assert.AreEqual(dc.GetEntryCount(), root.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(root.IsValid()); DirCacheTree aTree = root.GetChild(0); NUnit.Framework.Assert.IsNotNull(aTree); NUnit.Framework.Assert.AreSame(aTree, root.GetChild(0)); NUnit.Framework.Assert.AreEqual("a", aTree.GetNameString()); NUnit.Framework.Assert.AreEqual("a/", aTree.GetPathString()); NUnit.Framework.Assert.AreEqual(1, aTree.GetChildCount()); NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aTree.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(aTree.IsValid()); DirCacheTree acTree = aTree.GetChild(0); NUnit.Framework.Assert.IsNotNull(acTree); NUnit.Framework.Assert.AreSame(acTree, aTree.GetChild(0)); NUnit.Framework.Assert.AreEqual("c", acTree.GetNameString()); NUnit.Framework.Assert.AreEqual("a/c/", acTree.GetPathString()); NUnit.Framework.Assert.AreEqual(0, acTree.GetChildCount()); NUnit.Framework.Assert.AreEqual(acLast - acFirst + 1, acTree.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(acTree.IsValid()); }
public virtual void TestBuildEmpty() { { DirCache dc = db.LockDirCache(); DirCacheBuilder b = dc.Builder(); NUnit.Framework.Assert.IsNotNull(b); b.Finish(); dc.Write(); NUnit.Framework.Assert.IsTrue(dc.Commit()); } { DirCache dc = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount()); } }
public virtual void TestSingleSubtree_NoRecursion() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a/b", "a/c", "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 = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); string[] expPaths = new string[] { "a.", "a", "a0b" }; FileMode[] expModes = new FileMode[] { FileMode.REGULAR_FILE, FileMode.TREE, FileMode .REGULAR_FILE }; int[] expPos = new int[] { 0, -1, 4 }; DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = false; int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(expModes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(expModes[pathIdx], tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(expPaths[pathIdx], tw.PathString); if (expPos[pathIdx] >= 0) { NUnit.Framework.Assert.AreEqual(expPos[pathIdx], i_2.ptr); NUnit.Framework.Assert.AreSame(ents[expPos[pathIdx]], i_2.GetDirCacheEntry()); } else { NUnit.Framework.Assert.AreSame(FileMode.TREE, tw.GetFileMode(0)); } pathIdx++; } NUnit.Framework.Assert.AreEqual(expPaths.Length, pathIdx); }
public virtual void TestPathFilterGroup_DoesNotSkipTail() { DirCache dc = db.ReadDirCache(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c", "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(); } int expIdx = 2; DirCacheBuilder b_1 = dc.Builder(); TreeWalk tw = new TreeWalk(db); tw.AddTree(new DirCacheBuildIterator(b_1)); tw.Recursive = true; tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[expIdx] )); NUnit.Framework.Assert.IsTrue(tw.Next(), "found " + paths[expIdx]); DirCacheIterator c = tw.GetTree <DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(expIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[expIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[expIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); b_1.Add(c.GetDirCacheEntry()); NUnit.Framework.Assert.IsFalse(tw.Next(), "no more entries"); b_1.Finish(); NUnit.Framework.Assert.AreEqual(ents.Length, dc.GetEntryCount()); for (int i_2 = 0; i_2 < ents.Length; i_2++) { NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(i_2)); } }
public virtual void TestBuildRejectsUnsetFileMode() { DirCache dc = DirCache.NewInCore(); DirCacheBuilder b = dc.Builder(); NUnit.Framework.Assert.IsNotNull(b); DirCacheEntry e = new DirCacheEntry("a"); NUnit.Framework.Assert.AreEqual(0, e.RawMode); try { b.Add(e); } catch (ArgumentException err) { NUnit.Framework.Assert.AreEqual("FileMode not set for path a", err.Message); } }
public virtual void TestBuildOneFile_FinishWriteCommit() { string path = "a-file-path"; FileMode mode = FileMode.REGULAR_FILE; long lastModified = 1218123387057L; int length = 1342; DirCacheEntry entOrig; { DirCache dc = db.LockDirCache(); DirCacheBuilder b = dc.Builder(); NUnit.Framework.Assert.IsNotNull(b); entOrig = new DirCacheEntry(path); entOrig.FileMode = mode; entOrig.LastModified = lastModified; entOrig.SetLength(length); NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString); NUnit.Framework.Assert.AreEqual(path, entOrig.PathString); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId()); NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode); NUnit.Framework.Assert.AreEqual(0, entOrig.Stage); NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified); NUnit.Framework.Assert.AreEqual(length, entOrig.Length); NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid); b.Add(entOrig); b.Finish(); NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount()); NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0)); dc.Write(); NUnit.Framework.Assert.IsTrue(dc.Commit()); } { DirCache dc = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount()); DirCacheEntry entRead = dc.GetEntry(0); NUnit.Framework.Assert.AreNotSame(entOrig, entRead); NUnit.Framework.Assert.AreEqual(path, entRead.PathString); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId()); NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode); NUnit.Framework.Assert.AreEqual(0, entOrig.Stage); NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified); NUnit.Framework.Assert.AreEqual(length, entOrig.Length); NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid); } }
public virtual void TestDetectUnmergedPaths() { DirCache dc = db.ReadDirCache(); DirCacheEntry[] ents = new DirCacheEntry[3]; ents[0] = new DirCacheEntry("a", 1); ents[0].FileMode = FileMode.REGULAR_FILE; ents[1] = new DirCacheEntry("a", 2); ents[1].FileMode = FileMode.REGULAR_FILE; ents[2] = new DirCacheEntry("a", 3); ents[2].FileMode = FileMode.REGULAR_FILE; DirCacheBuilder b = dc.Builder(); for (int i = 0; i < ents.Length; i++) { b.Add(ents[i]); } b.Finish(); NUnit.Framework.Assert.IsTrue(dc.HasUnmergedPaths()); }
/// <summary>Scan index and merge tree (no HEAD).</summary> /// <remarks> /// Scan index and merge tree (no HEAD). Used e.g. for initial checkout when /// there is no head yet. /// </remarks> /// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException /// </exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException">NGit.Errors.IncorrectObjectTypeException /// </exception> /// <exception cref="NGit.Errors.CorruptObjectException">NGit.Errors.CorruptObjectException /// </exception> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void PrescanOneTree() { removed.Clear(); updated.Clear(); conflicts.Clear(); builder = dc.Builder(); walk = new NameConflictTreeWalk(repo); walk.AddTree(mergeCommitTree); walk.AddTree(new DirCacheBuildIterator(builder)); walk.AddTree(workingTree); while (walk.Next()) { ProcessEntry(walk.GetTree <CanonicalTreeParser>(0), walk.GetTree <DirCacheBuildIterator >(1), walk.GetTree <WorkingTreeIterator>(2)); if (walk.IsSubtree) { walk.EnterSubtree(); } } conflicts.RemoveAll(removed); }
public virtual void TestSingleSubtree_Recursive() { DirCache dc = DirCache.NewInCore(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c", "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(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = true; int pathIdx = 0; while (tw.Next()) { DirCacheIterator c = tw.GetTree <DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(pathIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
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()); } }
public virtual void TestFindSingleFile() { string path = "a-file-path"; DirCache dc = db.ReadDirCache(); DirCacheBuilder b = dc.Builder(); NUnit.Framework.Assert.IsNotNull(b); DirCacheEntry entOrig = new DirCacheEntry(path); entOrig.FileMode = FileMode.REGULAR_FILE; NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString); NUnit.Framework.Assert.AreEqual(path, entOrig.PathString); b.Add(entOrig); b.Finish(); NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount()); NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0)); NUnit.Framework.Assert.AreEqual(0, dc.FindEntry(path)); NUnit.Framework.Assert.AreEqual(-1, dc.FindEntry("@@-before")); NUnit.Framework.Assert.AreEqual(0, Real(dc.FindEntry("@@-before"))); NUnit.Framework.Assert.AreEqual(-2, dc.FindEntry("a-zoo")); NUnit.Framework.Assert.AreEqual(1, Real(dc.FindEntry("a-zoo"))); NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(path)); }
public virtual void TestNoSubtree_WithTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; FileMode[] modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = modes[i]; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
/// <exception cref="System.IO.IOException"></exception> protected internal override bool MergeImpl() { bool implicitDirCache = false; if (dircache == null) { dircache = GetRepository().LockDirCache(); implicitDirCache = true; } try { builder = dircache.Builder(); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder); tw = new NameConflictTreeWalk(db); tw.AddTree(MergeBase()); tw.AddTree(sourceTrees[0]); tw.AddTree(sourceTrees[1]); tw.AddTree(buildIt); if (workingTreeIterator != null) { tw.AddTree(workingTreeIterator); } while (tw.Next()) { if (!ProcessEntry(tw.GetTree<CanonicalTreeParser>(T_BASE), tw.GetTree<CanonicalTreeParser >(T_OURS), tw.GetTree<CanonicalTreeParser>(T_THEIRS), tw.GetTree<DirCacheBuildIterator >(T_INDEX), (workingTreeIterator == null) ? null : tw.GetTree<WorkingTreeIterator >(T_FILE))) { CleanUp(); return false; } if (tw.IsSubtree && enterSubtree) { tw.EnterSubtree(); } } if (!inCore) { // All content-merges are successfully done. If we can now write the // new index we are on quite safe ground. Even if the checkout of // files coming from "theirs" fails the user can work around such // failures by checking out the index again. if (!builder.Commit()) { CleanUp(); throw new IndexWriteException(); } builder = null; // No problem found. The only thing left to be done is to checkout // all files from "theirs" which have been selected to go into the // new index. Checkout(); } else { builder.Finish(); builder = null; } if (GetUnmergedPaths().IsEmpty()) { resultTree = dircache.WriteTree(oi); return true; } else { resultTree = null; return false; } } finally { if (implicitDirCache) { dircache.Unlock(); } } }
internal DirCacheBuildIterator(NGit.Dircache.DirCacheBuildIterator p, DirCacheTree dct) : base(p, dct) { builder = p.builder; }
/// <summary>Create a new iterator for an already loaded DirCache instance.</summary> /// <remarks> /// Create a new iterator for an already loaded DirCache instance. /// <p> /// The iterator implementation may copy part of the cache's data during /// construction, so the cache must be read in prior to creating the /// iterator. /// </remarks> /// <param name="dcb"> /// the cache builder for the cache to walk. The cache must be /// already loaded into memory. /// </param> public DirCacheBuildIterator(DirCacheBuilder dcb) : base(dcb.GetDirCache()) { builder = dcb; }
/// <exception cref="System.IO.IOException"></exception> protected internal override bool MergeImpl() { tw.AddTree(MergeBase()); tw.AddTree(sourceTrees[0]); tw.AddTree(sourceTrees[1]); bool hasConflict = false; builder = cache.Builder(); while (tw.Next()) { int modeO = tw.GetRawMode(T_OURS); int modeT = tw.GetRawMode(T_THEIRS); if (modeO == modeT && tw.IdEqual(T_OURS, T_THEIRS)) { Add(T_OURS, DirCacheEntry.STAGE_0); continue; } int modeB = tw.GetRawMode(T_BASE); if (modeB == modeO && tw.IdEqual(T_BASE, T_OURS)) { Add(T_THEIRS, DirCacheEntry.STAGE_0); } else { if (modeB == modeT && tw.IdEqual(T_BASE, T_THEIRS)) { Add(T_OURS, DirCacheEntry.STAGE_0); } else { if (NonTree(modeB)) { Add(T_BASE, DirCacheEntry.STAGE_1); hasConflict = true; } if (NonTree(modeO)) { Add(T_OURS, DirCacheEntry.STAGE_2); hasConflict = true; } if (NonTree(modeT)) { Add(T_THEIRS, DirCacheEntry.STAGE_3); hasConflict = true; } if (tw.IsSubtree) { tw.EnterSubtree(); } } } } builder.Finish(); builder = null; if (hasConflict) { return false; } try { ObjectInserter odi = GetObjectInserter(); resultTree = cache.WriteTree(odi); odi.Flush(); return true; } catch (UnmergedPathException) { resultTree = null; return false; } }
/// <exception cref="System.IO.IOException"></exception> private DirCacheEntry AddEntryToBuilder(string path, FilePath file, ObjectInserter newObjectInserter, DirCacheBuilder builder, int stage) { FileInputStream inputStream = new FileInputStream(file); ObjectId id = newObjectInserter.Insert(Constants.OBJ_BLOB, file.Length(), inputStream ); inputStream.Close(); DirCacheEntry entry = new DirCacheEntry(path, stage); entry.SetObjectId(id); entry.FileMode = FileMode.REGULAR_FILE; entry.LastModified = file.LastModified(); entry.SetLength((int)file.Length()); builder.Add(entry); return entry; }
/// <summary>Scan head, index and merge tree.</summary> /// <remarks> /// Scan head, index and merge tree. Used during normal checkout or merge /// operations. /// </remarks> /// <exception cref="NGit.Errors.CorruptObjectException">NGit.Errors.CorruptObjectException /// </exception> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void PreScanTwoTrees() { removed.Clear(); updated.Clear(); conflicts.Clear(); walk = new NameConflictTreeWalk(repo); builder = dc.Builder(); AddTree(walk, headCommitTree); AddTree(walk, mergeCommitTree); walk.AddTree(new DirCacheBuildIterator(builder)); walk.AddTree(workingTree); while (walk.Next()) { ProcessEntry(walk.GetTree<CanonicalTreeParser>(0), walk.GetTree<CanonicalTreeParser >(1), walk.GetTree<DirCacheBuildIterator>(2), walk.GetTree<WorkingTreeIterator>( 3)); if (walk.IsSubtree) { walk.EnterSubtree(); } } }
/// <summary>Create a new iterator for an already loaded DirCache instance.</summary> /// <remarks> /// Create a new iterator for an already loaded DirCache instance. /// <p> /// The iterator implementation may copy part of the cache's data during /// construction, so the cache must be read in prior to creating the /// iterator. /// </remarks> /// <param name="dcb"> /// the cache builder for the cache to walk. The cache must be /// already loaded into memory. /// </param> public DirCacheBuildIterator(DirCacheBuilder dcb) : base(dcb.GetDirCache()) { builder = dcb; }
internal DirCacheBuildIterator(NGit.Dircache.DirCacheBuildIterator p, DirCacheTree dct) : base(p, dct) { builder = p.builder; }