git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 14/14] Add test case for NameConflictTreeWalk

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 18, 2008, 23:53 UTC
Message-ID
<1219103602-32222-15-git-send-email-spearce@spearce.org>
In-Reply-To
<1219103602-32222-14-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../jgit/treewalk/NameConflictTreeWalkTest.java    |  205 ++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/NameConflictTreeWalkTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/NameConflictTreeWalkTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/NameConflictTreeWalkTest.java
new file mode 100644
index 0000000..8ab7f93
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/NameConflictTreeWalkTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ *   names of its contributors may be used to endorse or promote
+ *   products derived from this software without specific prior
+ *   written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.treewalk;
+
+import java.io.ByteArrayInputStream;
+
+import org.spearce.jgit.dircache.DirCache;
+import org.spearce.jgit.dircache.DirCacheBuilder;
+import org.spearce.jgit.dircache.DirCacheEntry;
+import org.spearce.jgit.dircache.DirCacheIterator;
+import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.FileMode;
+import org.spearce.jgit.lib.ObjectWriter;
+import org.spearce.jgit.lib.RepositoryTestCase;
+
+public class NameConflictTreeWalkTest extends RepositoryTestCase {
+	private static final FileMode TREE = FileMode.TREE;
+
+	private static final FileMode SYMLINK = FileMode.SYMLINK;
+
+	private static final FileMode MISSING = FileMode.MISSING;
+
+	private static final FileMode REGULAR_FILE = FileMode.REGULAR_FILE;
+
+	private static final FileMode EXECUTABLE_FILE = FileMode.EXECUTABLE_FILE;
+
+	public void testNoDF_NoGap() throws Exception {
+		final DirCache tree0 = DirCache.read(db);
+		final DirCache tree1 = DirCache.read(db);
+		{
+			final DirCacheBuilder b0 = tree0.builder();
+			final DirCacheBuilder b1 = tree1.builder();
+
+			b0.add(makeEntry("a", REGULAR_FILE));
+			b0.add(makeEntry("a.b", EXECUTABLE_FILE));
+			b1.add(makeEntry("a/b", REGULAR_FILE));
+			b0.add(makeEntry("a0b", SYMLINK));
+
+			b0.finish();
+			b1.finish();
+			assertEquals(3, tree0.getEntryCount());
+			assertEquals(1, tree1.getEntryCount());
+		}
+
+		final TreeWalk tw = new TreeWalk(db);
+		tw.reset();
+		tw.addTree(new DirCacheIterator(tree0));
+		tw.addTree(new DirCacheIterator(tree1));
+
+		assertModes("a", REGULAR_FILE, MISSING, tw);
+		assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
+		assertModes("a", MISSING, TREE, tw);
+		tw.enterSubtree();
+		assertModes("a/b", MISSING, REGULAR_FILE, tw);
+		assertModes("a0b", SYMLINK, MISSING, tw);
+	}
+
+	public void testDF_NoGap() throws Exception {
+		final DirCache tree0 = DirCache.read(db);
+		final DirCache tree1 = DirCache.read(db);
+		{
+			final DirCacheBuilder b0 = tree0.builder();
+			final DirCacheBuilder b1 = tree1.builder();
+
+			b0.add(makeEntry("a", REGULAR_FILE));
+			b0.add(makeEntry("a.b", EXECUTABLE_FILE));
+			b1.add(makeEntry("a/b", REGULAR_FILE));
+			b0.add(makeEntry("a0b", SYMLINK));
+
+			b0.finish();
+			b1.finish();
+			assertEquals(3, tree0.getEntryCount());
+			assertEquals(1, tree1.getEntryCount());
+		}
+
+		final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
+		tw.reset();
+		tw.addTree(new DirCacheIterator(tree0));
+		tw.addTree(new DirCacheIterator(tree1));
+
+		assertModes("a", REGULAR_FILE, TREE, tw);
+		assertTrue(tw.isSubtree());
+		tw.enterSubtree();
+		assertModes("a/b", MISSING, REGULAR_FILE, tw);
+		assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
+		assertModes("a0b", SYMLINK, MISSING, tw);
+	}
+
+	public void testDF_GapByOne() throws Exception {
+		final DirCache tree0 = DirCache.read(db);
+		final DirCache tree1 = DirCache.read(db);
+		{
+			final DirCacheBuilder b0 = tree0.builder();
+			final DirCacheBuilder b1 = tree1.builder();
+
+			b0.add(makeEntry("a", REGULAR_FILE));
+			b0.add(makeEntry("a.b", EXECUTABLE_FILE));
+			b1.add(makeEntry("a.b", EXECUTABLE_FILE));
+			b1.add(makeEntry("a/b", REGULAR_FILE));
+			b0.add(makeEntry("a0b", SYMLINK));
+
+			b0.finish();
+			b1.finish();
+			assertEquals(3, tree0.getEntryCount());
+			assertEquals(2, tree1.getEntryCount());
+		}
+
+		final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
+		tw.reset();
+		tw.addTree(new DirCacheIterator(tree0));
+		tw.addTree(new DirCacheIterator(tree1));
+
+		assertModes("a", REGULAR_FILE, TREE, tw);
+		assertTrue(tw.isSubtree());
+		tw.enterSubtree();
+		assertModes("a/b", MISSING, REGULAR_FILE, tw);
+		assertModes("a.b", EXECUTABLE_FILE, EXECUTABLE_FILE, tw);
+		assertModes("a0b", SYMLINK, MISSING, tw);
+	}
+
+	public void testDF_SkipsSeenSubtree() throws Exception {
+		final DirCache tree0 = DirCache.read(db);
+		final DirCache tree1 = DirCache.read(db);
+		{
+			final DirCacheBuilder b0 = tree0.builder();
+			final DirCacheBuilder b1 = tree1.builder();
+
+			b0.add(makeEntry("a", REGULAR_FILE));
+			b1.add(makeEntry("a.b", EXECUTABLE_FILE));
+			b1.add(makeEntry("a/b", REGULAR_FILE));
+			b0.add(makeEntry("a0b", SYMLINK));
+			b1.add(makeEntry("a0b", SYMLINK));
+
+			b0.finish();
+			b1.finish();
+			assertEquals(2, tree0.getEntryCount());
+			assertEquals(3, tree1.getEntryCount());
+		}
+
+		final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
+		tw.reset();
+		tw.addTree(new DirCacheIterator(tree0));
+		tw.addTree(new DirCacheIterator(tree1));
+
+		assertModes("a", REGULAR_FILE, TREE, tw);
+		assertTrue(tw.isSubtree());
+		tw.enterSubtree();
+		assertModes("a/b", MISSING, REGULAR_FILE, tw);
+		assertModes("a.b", MISSING, EXECUTABLE_FILE, tw);
+		assertModes("a0b", SYMLINK, SYMLINK, tw);
+	}
+
+	private DirCacheEntry makeEntry(final String path, final FileMode mode)
+			throws Exception {
+		final byte[] pathBytes = Constants.encode(path);
+		final DirCacheEntry ent = new DirCacheEntry(path);
+		ent.setFileMode(mode);
+		ent.setObjectId(new ObjectWriter(db).computeBlobSha1(pathBytes.length,
+				new ByteArrayInputStream(pathBytes)));
+		return ent;
+	}
+
+	private static void assertModes(final String path, final FileMode mode0,
+			final FileMode mode1, final TreeWalk tw) throws Exception {
+		assertTrue("has " + path, tw.next());
+		assertEquals(path, tw.getPathString());
+		assertEquals(mode0, tw.getFileMode(0));
+		assertEquals(mode1, tw.getFileMode(1));
+	}
+}
-- 
1.6.0.87.g2858d
Previous: Shawn O. PearceNext: Junio C Hamano
Message 15 of 20 in “TreeWalk D/F conflict detection”
  1. 00/14 TreeWalk D/F conflict detectionShawn O. Pearce, Aug 18, 2008
  2. 01/14 Detect path names which overflow the name length field in the indexShawn O. Pearce, Aug 18, 2008
  3. 02/14 Fix NB.decodeUInt16 to correctly handle the high byteShawn O. Pearce, Aug 18, 2008
  4. 03/14 Add test cases for NB.encode and NB.decode family of routinesShawn O. Pearce, Aug 18, 2008
  5. 04/14 Fix DirCache's skip over null byte padding when reading a DIRC fileShawn O. Pearce, Aug 18, 2008
  6. 05/14 Fix usage of assertEquals in DirCacheIteratorTestShawn O. Pearce, Aug 18, 2008
  7. 06/14 Refactor AbstractTreeIterator.pathCompare to force another modeShawn O. Pearce, Aug 18, 2008
  8. 07/14 Micro-optimize AbstractTreeIterator.pathCompareShawn O. Pearce, Aug 18, 2008
  9. 08/14 Optimize path comparsion within subtrees during TreeWalkShawn O. Pearce, Aug 18, 2008
  10. 09/14 Refactor AbstractTreeIterator semantics to start on first entryShawn O. Pearce, Aug 18, 2008
  11. 10/14 Make all AbstractTreeIterator implementations bi-directionalShawn O. Pearce, Aug 18, 2008
  12. 11/14 Expose beginning of iterator indication from AbstractTreeIteratorShawn O. Pearce, Aug 18, 2008
  13. 12/14 Allow application code to set ObjectIds in DirCacheEntryShawn O. Pearce, Aug 18, 2008
  14. 13/14 Create NameConflictTreeWalk to transparently detect D/F conflictsShawn O. Pearce, Aug 18, 2008
  15. 14/14 Add test case for NameConflictTreeWalkShawn O. Pearce, Aug 18, 2008
  16. Junio C HamanoAug 19, 2008
  17. Robin RosenbergAug 19, 2008
  18. Shawn O. PearceAug 19, 2008
  19. David WoodhouseAug 19, 2008
  20. Shawn O. PearceAug 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.