{"thread":{"id":"20544","subject":"[PATCH 1/2] Throw IllegalStateException if DirCacheEntry has not been fully initialized.","startedAt":"2009-08-12T00:56:20Z","lastAt":"2009-08-12T01:15:18Z","messageCount":5,"participants":["Grzegorz Kossakowski","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"120340","messageId":"1250038581-31241-1-git-send-email-grek@tuffmail.com","threadId":"20544","inReplyTo":null,"subject":"[PATCH 1/2] Throw IllegalStateException if DirCacheEntry has not been fully initialized.","fromName":"Grzegorz Kossakowski","fromEmail":"grek@tuffmail.com","sentAt":"2009-08-12T00:56:20Z","receivedAt":"2009-08-12T00:56:20Z","isPatch":true,"sender":{"key":"grek@tuffmail.com","avatar":"https://gravatar.com/avatar/98a80b7992e9f598c7b24addc73338dbacf94a14e4a14f3fa50c3f00dbee7dd3?d=mp&s=160"},"body":"From: Grzegorz Kossakowski <grek@google.com>\n\nWhen mode's object type of entry equals to Constants.OBJ_BAD it's a sign\nof bad (uninitialized) state of an entry and not of problems with merging.\n\nSigned-off-by: Grzegorz Kossakowski <grek@google.com>\n---\n .../org/spearce/jgit/dircache/DirCacheTree.java    |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\nindex 9d5af70..79e95cb 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\n@@ -377,7 +377,8 @@ private int computeSize(final DirCacheEntry[] cache, int cIdx,\n \n \t\t\tfinal FileMode mode = e.getFileMode();\n \t\t\tif (mode.getObjectType() == Constants.OBJ_BAD)\n-\t\t\t\tthrow new UnmergedPathException(e);\n+\t\t\t\tthrow new IllegalStateException(\"Entry \\\"\" + e.getPathString()\n+\t\t\t\t\t\t+ \"\\\" has incorrect mode set up.\");\n \n \t\t\tsize += mode.copyToLength();\n \t\t\tsize += ep.length - pathOffset;\n-- \n1.6.3.3\n"},{"id":"120341","messageId":"1250038581-31241-2-git-send-email-grek@tuffmail.com","threadId":"20544","inReplyTo":"1250038581-31241-1-git-send-email-grek@tuffmail.com","subject":"[PATCH 2/2] Add PathSuffixFilter class which is TreeFilter.","fromName":"Grzegorz Kossakowski","fromEmail":"grek@tuffmail.com","sentAt":"2009-08-12T00:56:21Z","receivedAt":"2009-08-12T00:56:21Z","isPatch":true,"sender":{"key":"grek@tuffmail.com","avatar":"https://gravatar.com/avatar/98a80b7992e9f598c7b24addc73338dbacf94a14e4a14f3fa50c3f00dbee7dd3?d=mp&s=160"},"body":"From: Grzegorz Kossakowski <grek@google.com>\n\nAdded a simple TreeFilter that filters all entries that have path with\ngiven suffix. This filter is always recursive.\n\nSigned-off-by: Grzegorz Kossakowski <grek@google.com>\n---\n .../treewalk/filter/PathSuffixFilterTestCase.java  |  110 ++++++++++++++++++++\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   33 ++++++\n .../jgit/treewalk/filter/PathSuffixFilter.java     |   74 +++++++++++++\n 3 files changed, 217 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/PathSuffixFilter.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\nnew file mode 100644\nindex 0000000..6042119\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\n@@ -0,0 +1,110 @@\n+// Copyright (C) 2009 The Android Open Source Project\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import java.io.IOException;\n+import java.util.LinkedList;\n+import java.util.List;\n+\n+import org.spearce.jgit.dircache.DirCache;\n+import org.spearce.jgit.dircache.DirCacheBuilder;\n+import org.spearce.jgit.dircache.DirCacheEntry;\n+import org.spearce.jgit.lib.FileMode;\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.ObjectWriter;\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n+public class PathSuffixFilterTestCase extends RepositoryTestCase {\n+\n+\tpublic void testNonRecursiveFiltering() throws IOException {\n+\t\tfinal ObjectWriter ow = new ObjectWriter(db);\n+\t\tfinal ObjectId aSth = ow.writeBlob(\"a.sth\".getBytes());\n+\t\tfinal ObjectId aTxt = ow.writeBlob(\"a.txt\".getBytes());\n+\t\tfinal DirCache dc = DirCache.read(db);\n+\t\tfinal DirCacheBuilder builder = dc.builder();\n+\t\tfinal DirCacheEntry aSthEntry = new DirCacheEntry(\"a.sth\");\n+\t\taSthEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\taSthEntry.setObjectId(aSth);\n+\t\tfinal DirCacheEntry aTxtEntry = new DirCacheEntry(\"a.txt\");\n+\t\taTxtEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\taTxtEntry.setObjectId(aTxt);\n+\t\tbuilder.add(aSthEntry);\n+\t\tbuilder.add(aTxtEntry);\n+\t\tbuilder.finish();\n+\t\tfinal ObjectId treeId = dc.writeTree(ow);\n+\n+\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\ttw.setFilter(PathSuffixFilter.create(\".txt\"));\n+\t\ttw.addTree(treeId);\n+\n+\t\tList<String> paths = new LinkedList<String>();\n+\t\twhile (tw.next()) {\n+\t\t\tpaths.add(tw.getPathString());\n+\t\t}\n+\n+\t\tList<String> expected =  new LinkedList<String>();\n+\t\texpected.add(\"a.txt\");\n+\n+\t\tassertEquals(expected, paths);\n+\t}\n+\n+\tpublic void testRecursiveFiltering() throws IOException {\n+\t\tfinal ObjectWriter ow = new ObjectWriter(db);\n+\t\tfinal ObjectId aSth = ow.writeBlob(\"a.sth\".getBytes());\n+\t\tfinal ObjectId aTxt = ow.writeBlob(\"a.txt\".getBytes());\n+\t\tfinal ObjectId bSth = ow.writeBlob(\"b.sth\".getBytes());\n+\t\tfinal ObjectId bTxt = ow.writeBlob(\"b.txt\".getBytes());\n+\t\tfinal DirCache dc = DirCache.read(db);\n+\t\tfinal DirCacheBuilder builder = dc.builder();\n+\t\tfinal DirCacheEntry aSthEntry = new DirCacheEntry(\"a.sth\");\n+\t\taSthEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\taSthEntry.setObjectId(aSth);\n+\t\tfinal DirCacheEntry aTxtEntry = new DirCacheEntry(\"a.txt\");\n+\t\taTxtEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\taTxtEntry.setObjectId(aTxt);\n+\t\tbuilder.add(aSthEntry);\n+\t\tbuilder.add(aTxtEntry);\n+\t\tfinal DirCacheEntry bSthEntry = new DirCacheEntry(\"sub/b.sth\");\n+\t\tbSthEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\tbSthEntry.setObjectId(bSth);\n+\t\tfinal DirCacheEntry bTxtEntry = new DirCacheEntry(\"sub/b.txt\");\n+\t\tbTxtEntry.setFileMode(FileMode.REGULAR_FILE);\n+\t\tbTxtEntry.setObjectId(bTxt);\n+\t\tbuilder.add(bSthEntry);\n+\t\tbuilder.add(bTxtEntry);\n+\t\tbuilder.finish();\n+\t\tfinal ObjectId treeId = dc.writeTree(ow);\n+\n+\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\ttw.setRecursive(true);\n+\t\ttw.setFilter(PathSuffixFilter.create(\".txt\"));\n+\t\ttw.addTree(treeId);\n+\n+\t\tList<String> paths = new LinkedList<String>();\n+\t\twhile (tw.next()) {\n+\t\t\tpaths.add(tw.getPathString());\n+\t\t}\n+\n+\t\tList<String> expected =  new LinkedList<String>();\n+\t\texpected.add(\"a.txt\");\n+\t\texpected.add(\"sub/b.txt\");\n+\n+\t\tassertEquals(expected, paths);\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex 5705936..ad19093 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -739,6 +739,39 @@ public int isPathPrefix(final byte[] p, final int pLen) {\n \t}\n \n \t/**\n+\t * Test if the supplied path matches (being suffix of) the current entry's\n+\t * path.\n+\t * <p>\n+\t * This method tests that the supplied path is exactly equal to the current\n+\t * entry, or is relative to one of entry's parent directories. It is faster\n+\t * to use this method then to use {@link #getPathString()} to first create\n+\t * a String object, then test <code>endsWith</code> or some other type of\n+\t * string match function.\n+\t *\n+\t * @param p\n+\t *            path buffer to test. Callers should ensure the path does not\n+\t *            start with '/' prior to invocation.\n+\t * @param pLen\n+\t *            number of bytes from <code>buf</code> to test.\n+\t * @return true if p is suffix of the current path;\n+\t *         false if otherwise\n+\t *\n+\t */\n+\tpublic boolean isPathSuffix(final byte[] p, final int pLen) {\n+\t\tfinal AbstractTreeIterator t = currentHead;\n+\t\tfinal byte[] c = t.path;\n+\t\tfinal int cLen = t.pathLen;\n+\t\tint ci;\n+\n+\t\tfor (ci = 1; ci < cLen && ci < pLen; ci++) {\n+\t\t\tif (c[cLen-ci] != p[pLen-ci])\n+\t\t\t\treturn false;\n+\t\t}\n+\n+\t\treturn true;\n+\t}\n+\n+\t/**\n \t * Get the current subtree depth of this walker.\n \t *\n \t * @return the current subtree depth of this walker.\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/PathSuffixFilter.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/PathSuffixFilter.java\nnew file mode 100644\nindex 0000000..b5b2461\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/PathSuffixFilter.java\n@@ -0,0 +1,74 @@\n+// Copyright (C) 2009 The Android Open Source Project\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.errors.IncorrectObjectTypeException;\n+import org.spearce.jgit.errors.MissingObjectException;\n+import org.spearce.jgit.lib.Constants;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n+/**\n+ * Includes tree entries only if they match the configured path.\n+ */\n+public class PathSuffixFilter extends TreeFilter {\n+\n+\t/**\n+\t * Create a new tree filter for a user supplied path.\n+\t * <p>\n+\t * Path strings use '/' to delimit directories on all platforms.\n+\t *\n+\t * @param path\n+\t *            the path (suffix) to filter on. Must not be the empty string.\n+\t * @return a new filter for the requested path.\n+\t * @throws IllegalArgumentException\n+\t *             the path supplied was the empty string.\n+\t */\n+\tpublic static PathSuffixFilter create(String path) {\n+\t\tif (path.length() == 0)\n+\t\t\tthrow new IllegalArgumentException(\"Empty path not permitted.\");\n+\t\treturn new PathSuffixFilter(path);\n+\t}\n+\n+\tfinal String pathStr;\n+\tfinal byte[] pathRaw;\n+\n+\tprivate PathSuffixFilter(final String s) {\n+\t\tpathStr = s;\n+\t\tpathRaw = Constants.encode(pathStr);\n+\t}\n+\n+\t@Override\n+\tpublic TreeFilter clone() {\n+\t\treturn this;\n+\t}\n+\n+\t@Override\n+\tpublic boolean include(TreeWalk walker) throws MissingObjectException,\n+\t\t\tIncorrectObjectTypeException, IOException {\n+\t\tif (walker.isSubtree())\n+\t\t\treturn true;\n+\t\telse\n+\t\t\treturn walker.isPathSuffix(pathRaw, pathRaw.length);\n+\n+\t}\n+\n+\t@Override\n+\tpublic boolean shouldBeRecursive() {\n+\t\treturn true;\n+\t}\n+\n+}\n-- \n1.6.3.3\n"},{"id":"120344","messageId":"4A8213D1.3070204@tuffmail.com","threadId":"20544","inReplyTo":"1250038581-31241-2-git-send-email-grek@tuffmail.com","subject":"Re: [PATCH 2/2] Add PathSuffixFilter class which is TreeFilter.","fromName":"Grzegorz Kossakowski","fromEmail":"grek@tuffmail.com","sentAt":"2009-08-12T00:58:57Z","receivedAt":"2009-08-12T00:58:57Z","isPatch":true,"sender":{"key":"grek@tuffmail.com","avatar":"https://gravatar.com/avatar/98a80b7992e9f598c7b24addc73338dbacf94a14e4a14f3fa50c3f00dbee7dd3?d=mp&s=160"},"body":"Grzegorz Kossakowski wrote:\n> From: Grzegorz Kossakowski <grek@google.com>\n>\n> Added a simple TreeFilter that filters all entries that have path with\n> given suffix. This filter is always recursive.\n>\n> Signed-off-by: Grzegorz Kossakowski <grek@google.com>\n> ---\n>  .../treewalk/filter/PathSuffixFilterTestCase.java  |  110 ++++++++++++++++++++\n>  .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   33 ++++++\n>  .../jgit/treewalk/filter/PathSuffixFilter.java     |   74 +++++++++++++\n>  3 files changed, 217 insertions(+), 0 deletions(-)\n>  create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\n>  create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/PathSuffixFilter.java\n>\n> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\n> new file mode 100644\n> index 0000000..6042119\n> --- /dev/null\n> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/filter/PathSuffixFilterTestCase.java\n> @@ -0,0 +1,110 @@\n> +// Copyright (C) 2009 The Android Open Source Project\n> +//\n> +// Licensed under the Apache License, Version 2.0 (the \"License\");\n> +// you may not use this file except in compliance with the License.\n> +// You may obtain a copy of the License at\n> +//\n> +// http://www.apache.org/licenses/LICENSE-2.0\n> +//\n> +// Unless required by applicable law or agreed to in writing, software\n> +// distributed under the License is distributed on an \"AS IS\" BASIS,\n> +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n> +// See the License for the specific language governing permissions and\n> +// limitations under the License.\n> +\n>   \nOups. Wrong headers.\n\nI'll resend these patches.\n\n-- \nGrzegorz Kossakowski\n"},{"id":"120343","messageId":"alpine.DEB.1.00.0908120303240.8306@pacific.mpi-cbg.de","threadId":"20544","inReplyTo":"1250038581-31241-1-git-send-email-grek@tuffmail.com","subject":"Re: [PATCH 1/2] Throw IllegalStateException if DirCacheEntry has not been fully initialized.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-08-12T01:04:25Z","receivedAt":"2009-08-12T01:04:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Aug 2009, Grzegorz Kossakowski wrote:\n\n> From: Grzegorz Kossakowski <grek@google.com>\n> \n> When mode's object type of entry equals to Constants.OBJ_BAD it's a sign\n> of bad (uninitialized) state of an entry and not of problems with merging.\n> \n> Signed-off-by: Grzegorz Kossakowski <grek@google.com>\n> ---\n>  .../org/spearce/jgit/dircache/DirCacheTree.java    |    3 ++-\n\nThat's great, but next time, please prefix your mail subjects with [JGIT \nPATCH] so that people who don't speak Java know that this is not for them.\n\nThanks!\nDscho\n"},{"id":"120345","messageId":"4A8217A6.8060102@tuffmail.com","threadId":"20544","inReplyTo":"alpine.DEB.1.00.0908120303240.8306@pacific.mpi-cbg.de","subject":"Re: [PATCH 1/2] Throw IllegalStateException if DirCacheEntry has not been fully initialized.","fromName":"Grzegorz Kossakowski","fromEmail":"grek@tuffmail.com","sentAt":"2009-08-12T01:15:18Z","receivedAt":"2009-08-12T01:15:18Z","isPatch":true,"sender":{"key":"grek@tuffmail.com","avatar":"https://gravatar.com/avatar/98a80b7992e9f598c7b24addc73338dbacf94a14e4a14f3fa50c3f00dbee7dd3?d=mp&s=160"},"body":"Johannes Schindelin wrote:\n> Hi,\n>\n> On Tue, 11 Aug 2009, Grzegorz Kossakowski wrote:\n>\n>   \n>> From: Grzegorz Kossakowski <grek@google.com>\n>>\n>> When mode's object type of entry equals to Constants.OBJ_BAD it's a sign\n>> of bad (uninitialized) state of an entry and not of problems with merging.\n>>\n>> Signed-off-by: Grzegorz Kossakowski <grek@google.com>\n>> ---\n>>  .../org/spearce/jgit/dircache/DirCacheTree.java    |    3 ++-\n>>     \n>\n> That's great, but next time, please prefix your mail subjects with [JGIT \n> PATCH] so that people who don't speak Java know that this is not for them.\n>   \nSorry for that. I'll remember about it next time.\n\n-- \nGrzegorz Kossakowski\n"}]}