{"thread":{"id":"15248","subject":"[JGIT PATCH 1/5] JUnit test for EmptyTreeIterator","startedAt":"2008-08-28T15:27:42Z","lastAt":"2008-08-28T15:27:46Z","messageCount":5,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"88902","messageId":"1219937266-24903-1-git-send-email-spearce@spearce.org","threadId":"15248","inReplyTo":null,"subject":"[JGIT PATCH 1/5] JUnit test for EmptyTreeIterator","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-28T15:27:42Z","receivedAt":"2008-08-28T15:27:42Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/treewalk/EmptyTreeIteratorTest.java       |  106 ++++++++++++++++++++\n 1 files changed, 106 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/EmptyTreeIteratorTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/EmptyTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/EmptyTreeIteratorTest.java\nnew file mode 100644\nindex 0000000..2cf5eca\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/EmptyTreeIteratorTest.java\n@@ -0,0 +1,106 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk;\n+\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+\n+public class EmptyTreeIteratorTest extends RepositoryTestCase {\n+\tpublic void testAtEOF() throws Exception {\n+\t\tfinal EmptyTreeIterator etp = new EmptyTreeIterator();\n+\t\tassertTrue(etp.first());\n+\t\tassertTrue(etp.eof());\n+\t}\n+\n+\tpublic void testCreateSubtreeIterator() throws Exception {\n+\t\tfinal EmptyTreeIterator etp = new EmptyTreeIterator();\n+\t\tfinal AbstractTreeIterator sub = etp.createSubtreeIterator(db);\n+\t\tassertNotNull(sub);\n+\t\tassertTrue(sub.first());\n+\t\tassertTrue(sub.eof());\n+\t\tassertTrue(sub instanceof EmptyTreeIterator);\n+\t}\n+\n+\tpublic void testEntryObjectId() throws Exception {\n+\t\tfinal EmptyTreeIterator etp = new EmptyTreeIterator();\n+\t\tassertSame(ObjectId.zeroId(), etp.getEntryObjectId());\n+\t\tassertNotNull(etp.idBuffer());\n+\t\tassertEquals(0, etp.idOffset());\n+\t\tassertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));\n+\t}\n+\n+\tpublic void testNextDoesNothing() throws Exception {\n+\t\tfinal EmptyTreeIterator etp = new EmptyTreeIterator();\n+\t\tetp.next(1);\n+\t\tassertTrue(etp.first());\n+\t\tassertTrue(etp.eof());\n+\t\tassertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));\n+\n+\t\tetp.next(1);\n+\t\tassertTrue(etp.first());\n+\t\tassertTrue(etp.eof());\n+\t\tassertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));\n+\t}\n+\n+\tpublic void testBackDoesNothing() throws Exception {\n+\t\tfinal EmptyTreeIterator etp = new EmptyTreeIterator();\n+\t\tetp.back(1);\n+\t\tassertTrue(etp.first());\n+\t\tassertTrue(etp.eof());\n+\t\tassertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));\n+\n+\t\tetp.back(1);\n+\t\tassertTrue(etp.first());\n+\t\tassertTrue(etp.eof());\n+\t\tassertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));\n+\t}\n+\n+\tpublic void testStopWalkCallsParent() throws Exception {\n+\t\tfinal boolean called[] = new boolean[1];\n+\t\tassertFalse(called[0]);\n+\n+\t\tfinal EmptyTreeIterator parent = new EmptyTreeIterator() {\n+\t\t\t@Override\n+\t\t\tpublic void stopWalk() {\n+\t\t\t\tcalled[0] = true;\n+\t\t\t}\n+\t\t};\n+\t\tparent.createSubtreeIterator(db).stopWalk();\n+\t\tassertTrue(called[0]);\n+\t}\n+}\n-- \n1.6.0.174.gd789c\n"},{"id":"88904","messageId":"1219937266-24903-2-git-send-email-spearce@spearce.org","threadId":"15248","inReplyTo":"1219937266-24903-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/5] JUnit tests for some TreeFilter implementations","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-28T15:27:43Z","receivedAt":"2008-08-28T15:27:43Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../treewalk/filter/AlwaysCloneTreeFilter.java     |   57 +++++++++++++\n .../jgit/treewalk/filter/NotTreeFilterTest.java    |   85 ++++++++++++++++++++\n .../jgit/treewalk/filter/TreeFilterTest.java       |   74 +++++++++++++++++\n .../jgit/treewalk/filter/NotTreeFilter.java        |    3 +-\n 4 files changed, 218 insertions(+), 1 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/AlwaysCloneTreeFilter.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/NotTreeFilterTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/TreeFilterTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/AlwaysCloneTreeFilter.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/AlwaysCloneTreeFilter.java\nnew file mode 100644\nindex 0000000..054f081\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/AlwaysCloneTreeFilter.java\n@@ -0,0 +1,57 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n+class AlwaysCloneTreeFilter extends TreeFilter {\n+\t@Override\n+\tpublic TreeFilter clone() {\n+\t\treturn new AlwaysCloneTreeFilter();\n+\t}\n+\n+\t@Override\n+\tpublic boolean include(final TreeWalk walker) {\n+\t\treturn false;\n+\t}\n+\n+\t@Override\n+\tpublic boolean shouldBeRecursive() {\n+\t\treturn false;\n+\t}\n+}\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/NotTreeFilterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/NotTreeFilterTest.java\nnew file mode 100644\nindex 0000000..7749a51\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/NotTreeFilterTest.java\n@@ -0,0 +1,85 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n+public class NotTreeFilterTest extends RepositoryTestCase {\n+\tpublic void testWrap() throws Exception {\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\tfinal TreeFilter a = TreeFilter.ALL;\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertNotNull(n);\n+\t\tassertTrue(a.include(tw));\n+\t\tassertFalse(n.include(tw));\n+\t}\n+\n+\tpublic void testNegateIsUnwrap() throws Exception {\n+\t\tfinal TreeFilter a = PathFilter.create(\"a/b\");\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertSame(a, n.negate());\n+\t}\n+\n+\tpublic void testShouldBeRecursive_ALL() throws Exception {\n+\t\tfinal TreeFilter a = TreeFilter.ALL;\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertEquals(a.shouldBeRecursive(), n.shouldBeRecursive());\n+\t}\n+\n+\tpublic void testShouldBeRecursive_PathFilter() throws Exception {\n+\t\tfinal TreeFilter a = PathFilter.create(\"a/b\");\n+\t\tassertTrue(a.shouldBeRecursive());\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertTrue(n.shouldBeRecursive());\n+\t}\n+\n+\tpublic void testCloneIsDeepClone() throws Exception {\n+\t\tfinal TreeFilter a = new AlwaysCloneTreeFilter();\n+\t\tassertNotSame(a, a.clone());\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertNotSame(n, n.clone());\n+\t}\n+\n+\tpublic void testCloneIsSparseWhenPossible() throws Exception {\n+\t\tfinal TreeFilter a = TreeFilter.ALL;\n+\t\tassertSame(a, a.clone());\n+\t\tfinal TreeFilter n = NotTreeFilter.create(a);\n+\t\tassertSame(n, n.clone());\n+\t}\n+}\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/TreeFilterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/TreeFilterTest.java\nnew file mode 100644\nindex 0000000..a8643bd\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/TreeFilterTest.java\n@@ -0,0 +1,74 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n+public class TreeFilterTest extends RepositoryTestCase {\n+\tpublic void testALL_IncludesAnything() throws Exception {\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\tassertTrue(TreeFilter.ALL.include(tw));\n+\t}\n+\n+\tpublic void testALL_ShouldNotBeRecursive() throws Exception {\n+\t\tassertFalse(TreeFilter.ALL.shouldBeRecursive());\n+\t}\n+\n+\tpublic void testALL_IdentityClone() throws Exception {\n+\t\tassertSame(TreeFilter.ALL, TreeFilter.ALL.clone());\n+\t}\n+\n+\tpublic void testNotALL_IncludesNothing() throws Exception {\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\tassertFalse(TreeFilter.ALL.negate().include(tw));\n+\t}\n+\n+\tpublic void testANY_DIFF_IncludesSingleTreeCase() throws Exception {\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\tassertTrue(TreeFilter.ANY_DIFF.include(tw));\n+\t}\n+\n+\tpublic void testANY_DIFF_ShouldNotBeRecursive() throws Exception {\n+\t\tassertFalse(TreeFilter.ANY_DIFF.shouldBeRecursive());\n+\t}\n+\n+\tpublic void testANY_DIFF_IdentityClone() throws Exception {\n+\t\tassertSame(TreeFilter.ANY_DIFF, TreeFilter.ANY_DIFF.clone());\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/NotTreeFilter.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/NotTreeFilter.java\nindex 86ae82d..37d655e 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/NotTreeFilter.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/NotTreeFilter.java\n@@ -81,7 +81,8 @@ public boolean shouldBeRecursive() {\n \n \t@Override\n \tpublic TreeFilter clone() {\n-\t\treturn new NotTreeFilter(a.clone());\n+\t\tfinal TreeFilter n = a.clone();\n+\t\treturn n == a ? this : new NotTreeFilter(n);\n \t}\n \n \t@Override\n-- \n1.6.0.174.gd789c\n"},{"id":"88907","messageId":"1219937266-24903-3-git-send-email-spearce@spearce.org","threadId":"15248","inReplyTo":"1219937266-24903-2-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 3/5] JUnit test for FileTreeIterator, WorkingTreeIterator","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-28T15:27:44Z","receivedAt":"2008-08-28T15:27:44Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This test is an indirect test of WorkingTreeIterator as the class\nis abstract.  An easy way to test it is through the FileTreeIterator\nas that relies only on standard Java IO.\n\nWe don't have full coverage yet, but most of the cases are dealt\nwith by this test.  A better test of WorkingTreeIterator would be\nto setup a mock implementation that works strictly in memory and\nthrows it all of the corner cases.  Building that is a lot more\nwork, and the test will be focusing more on the mock code than on\nthe live library, so I'm punting on it for now.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/treewalk/FileTreeIteratorTest.java        |  167 ++++++++++++++++++++\n 1 files changed, 167 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/FileTreeIteratorTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/FileTreeIteratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/FileTreeIteratorTest.java\nnew file mode 100644\nindex 0000000..ca31991\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/FileTreeIteratorTest.java\n@@ -0,0 +1,167 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk;\n+\n+import java.io.File;\n+import java.security.MessageDigest;\n+\n+import org.spearce.jgit.lib.Constants;\n+import org.spearce.jgit.lib.FileMode;\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+import org.spearce.jgit.util.RawParseUtils;\n+\n+public class FileTreeIteratorTest extends RepositoryTestCase {\n+\tprivate final String[] paths = { \"a.\", \"a.b\", \"a/b\", \"a0b\" };\n+\n+\tprivate long[] mtime;\n+\n+\tpublic void setUp() throws Exception {\n+\t\tsuper.setUp();\n+\n+\t\t// We build the entries backwards so that on POSIX systems we\n+\t\t// are likely to get the entries in the trash directory in the\n+\t\t// opposite order of what they should be in for the iteration.\n+\t\t// This should stress the sorting code better than doing it in\n+\t\t// the correct order.\n+\t\t//\n+\t\tmtime = new long[paths.length];\n+\t\tfor (int i = paths.length - 1; i >= 0; i--) {\n+\t\t\tfinal String s = paths[i];\n+\t\t\twriteTrashFile(s, s);\n+\t\t\tmtime[i] = new File(trash, s).lastModified();\n+\t\t}\n+\t}\n+\n+\tpublic void testEmptyIfRootIsFile() throws Exception {\n+\t\tfinal File r = new File(trash, paths[0]);\n+\t\tassertTrue(r.isFile());\n+\t\tfinal FileTreeIterator fti = new FileTreeIterator(r);\n+\t\tassertTrue(fti.first());\n+\t\tassertTrue(fti.eof());\n+\t}\n+\n+\tpublic void testEmptyIfRootDoesNotExist() throws Exception {\n+\t\tfinal File r = new File(trash, \"not-existing-file\");\n+\t\tassertFalse(r.exists());\n+\t\tfinal FileTreeIterator fti = new FileTreeIterator(r);\n+\t\tassertTrue(fti.first());\n+\t\tassertTrue(fti.eof());\n+\t}\n+\n+\tpublic void testEmptyIfRootIsEmpty() throws Exception {\n+\t\tfinal File r = new File(trash, \"not-existing-file\");\n+\t\tassertFalse(r.exists());\n+\t\tr.mkdir();\n+\t\tassertTrue(r.isDirectory());\n+\n+\t\tfinal FileTreeIterator fti = new FileTreeIterator(r);\n+\t\tassertTrue(fti.first());\n+\t\tassertTrue(fti.eof());\n+\t}\n+\n+\tpublic void testSimpleIterate() throws Exception {\n+\t\tfinal FileTreeIterator top = new FileTreeIterator(trash);\n+\n+\t\tassertTrue(top.first());\n+\t\tassertFalse(top.eof());\n+\t\tassertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);\n+\t\tassertEquals(paths[0], nameOf(top));\n+\t\tassertEquals(paths[0].length(), top.getEntryLength());\n+\t\tassertEquals(mtime[0], top.getEntryLastModified());\n+\n+\t\ttop.next(1);\n+\t\tassertFalse(top.first());\n+\t\tassertFalse(top.eof());\n+\t\tassertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);\n+\t\tassertEquals(paths[1], nameOf(top));\n+\t\tassertEquals(paths[1].length(), top.getEntryLength());\n+\t\tassertEquals(mtime[1], top.getEntryLastModified());\n+\n+\t\ttop.next(1);\n+\t\tassertFalse(top.first());\n+\t\tassertFalse(top.eof());\n+\t\tassertEquals(FileMode.TREE.getBits(), top.mode);\n+\n+\t\tfinal AbstractTreeIterator sub = top.createSubtreeIterator(db);\n+\t\tassertTrue(sub instanceof FileTreeIterator);\n+\t\tfinal FileTreeIterator subfti = (FileTreeIterator) sub;\n+\t\tassertTrue(sub.first());\n+\t\tassertFalse(sub.eof());\n+\t\tassertEquals(paths[2], nameOf(sub));\n+\t\tassertEquals(paths[2].length(), subfti.getEntryLength());\n+\t\tassertEquals(mtime[2], subfti.getEntryLastModified());\n+\n+\t\tsub.next(1);\n+\t\tassertTrue(sub.eof());\n+\n+\t\ttop.next(1);\n+\t\tassertFalse(top.first());\n+\t\tassertFalse(top.eof());\n+\t\tassertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);\n+\t\tassertEquals(paths[3], nameOf(top));\n+\t\tassertEquals(paths[3].length(), top.getEntryLength());\n+\t\tassertEquals(mtime[3], top.getEntryLastModified());\n+\n+\t\ttop.next(1);\n+\t\tassertTrue(top.eof());\n+\t}\n+\n+\tpublic void testComputeFileObjectId() throws Exception {\n+\t\tfinal FileTreeIterator top = new FileTreeIterator(trash);\n+\n+\t\tfinal MessageDigest md = Constants.newMessageDigest();\n+\t\tmd.update(Constants.encodeASCII(Constants.TYPE_BLOB));\n+\t\tmd.update((byte) ' ');\n+\t\tmd.update(Constants.encodeASCII(paths[0].length()));\n+\t\tmd.update((byte) 0);\n+\t\tmd.update(Constants.encode(paths[0]));\n+\t\tfinal ObjectId expect = ObjectId.fromRaw(md.digest());\n+\n+\t\tassertEquals(expect, top.getEntryObjectId());\n+\n+\t\t// Verify it was cached by removing the file and getting it again.\n+\t\t//\n+\t\tnew File(trash, paths[0]).delete();\n+\t\tassertEquals(expect, top.getEntryObjectId());\n+\t}\n+\n+\tprivate static String nameOf(final AbstractTreeIterator i) {\n+\t\treturn RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen);\n+\t}\n+}\n-- \n1.6.0.174.gd789c\n"},{"id":"88906","messageId":"1219937266-24903-4-git-send-email-spearce@spearce.org","threadId":"15248","inReplyTo":"1219937266-24903-3-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 4/5] Increase JUnit coverage on CanonicalTreeParser","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-28T15:27:45Z","receivedAt":"2008-08-28T15:27:45Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/treewalk/CanonicalTreeParserTest.java     |   18 ++++++++++++++++++\n .../jgit/treewalk/AbstractTreeIterator.java        |    2 +-\n 2 files changed, 19 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/CanonicalTreeParserTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/CanonicalTreeParserTest.java\nindex fd92844..ed3478c 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/CanonicalTreeParserTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/CanonicalTreeParserTest.java\n@@ -108,18 +108,21 @@ public void testEmptyTree_AtEOF() throws Exception {\n \tpublic void testOneEntry_Forward() throws Exception {\n \t\tctp.reset(tree1);\n \n+\t\tassertTrue(ctp.first());\n \t\tassertFalse(ctp.eof());\n \t\tassertEquals(m644.getBits(), ctp.mode);\n \t\tassertEquals(\"a\", path());\n \t\tassertEquals(hash_a, ctp.getEntryObjectId());\n \n \t\tctp.next(1);\n+\t\tassertFalse(ctp.first());\n \t\tassertTrue(ctp.eof());\n \t}\n \n \tpublic void testTwoEntries_ForwardOneAtATime() throws Exception {\n \t\tctp.reset(tree2);\n \n+\t\tassertTrue(ctp.first());\n \t\tassertFalse(ctp.eof());\n \t\tassertEquals(m644.getBits(), ctp.mode);\n \t\tassertEquals(\"a\", path());\n@@ -132,6 +135,7 @@ public void testTwoEntries_ForwardOneAtATime() throws Exception {\n \t\tassertEquals(hash_foo, ctp.getEntryObjectId());\n \n \t\tctp.next(1);\n+\t\tassertFalse(ctp.first());\n \t\tassertTrue(ctp.eof());\n \t}\n \n@@ -170,9 +174,11 @@ public void testThreeEntries_Seek2() throws Exception {\n \tpublic void testOneEntry_Backwards() throws Exception {\n \t\tctp.reset(tree1);\n \t\tctp.next(1);\n+\t\tassertFalse(ctp.first());\n \t\tassertTrue(ctp.eof());\n \n \t\tctp.back(1);\n+\t\tassertTrue(ctp.first());\n \t\tassertFalse(ctp.eof());\n \t\tassertEquals(m644.getBits(), ctp.mode);\n \t\tassertEquals(\"a\", path());\n@@ -258,4 +264,16 @@ public void testBackwards_ConfusingPathName() throws Exception {\n \t\tassertEquals(\"a\", path());\n \t\tassertEquals(hash_a, ctp.getEntryObjectId());\n \t}\n+\n+\tpublic void testFreakingHugePathName() throws Exception {\n+\t\tfinal int n = AbstractTreeIterator.DEFAULT_PATH_SIZE * 4;\n+\t\tfinal StringBuilder b = new StringBuilder(n);\n+\t\tfor (int i = 0; i < n; i++)\n+\t\t\tb.append('q');\n+\t\tfinal String name = b.toString();\n+\t\tctp.reset(entry(m644, name, hash_a));\n+\t\tassertFalse(ctp.eof());\n+\t\tassertEquals(name, RawParseUtils.decode(Constants.CHARSET, ctp.path,\n+\t\t\t\tctp.pathOffset, ctp.pathLen));\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\nindex 3227fab..5226ab6 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\n@@ -71,7 +71,7 @@\n  * @see CanonicalTreeParser\n  */\n public abstract class AbstractTreeIterator {\n-\tprivate static final int DEFAULT_PATH_SIZE = 128;\n+\tstatic final int DEFAULT_PATH_SIZE = 128;\n \n \t/** A dummy object id buffer that matches the zero ObjectId. */\n \tprotected static final byte[] zeroid = new byte[Constants.OBJECT_ID_LENGTH];\n-- \n1.6.0.174.gd789c\n"},{"id":"88905","messageId":"1219937266-24903-5-git-send-email-spearce@spearce.org","threadId":"15248","inReplyTo":"1219937266-24903-4-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 5/5] Restore IContainer.INCLUDE_HIDDEN within ContainerTreeIterator","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-28T15:27:46Z","receivedAt":"2008-08-28T15:27:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Now that we support only Eclipse 3.4 we might as well use this\nflag to pick up hidden resources which may be part of the Git\nrepository, but hidden from view from Eclipse.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/egit/core/ContainerTreeIterator.java   |    3 +--\n 1 files changed, 1 insertions(+), 2 deletions(-)\n\ndiff --git a/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java b/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java\nindex 2b7ff3b..61717f5 100644\n--- a/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java\n+++ b/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java\n@@ -91,8 +91,7 @@ public AbstractTreeIterator createSubtreeIterator(final Repository db)\n \tprivate Entry[] entries() {\n \t\tfinal IResource[] all;\n \t\ttry {\n-//\t\t\tall = node.members(IContainer.INCLUDE_HIDDEN); 3.4 flag\n-\t\t\tall = node.members(0);\n+\t\t\tall = node.members(IContainer.INCLUDE_HIDDEN);\n \t\t} catch (CoreException err) {\n \t\t\treturn EOF;\n \t\t}\n-- \n1.6.0.174.gd789c\n"}]}