{"thread":{"id":"19994","subject":"[JGIT PATCH] Support for delegating tree iterators","startedAt":"2009-07-01T17:52:52Z","lastAt":"2009-07-02T20:00:39Z","messageCount":4,"participants":["Constantine Plotnikov","Shawn O. Pearce","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"117307","messageId":"1246470772-4496-1-git-send-email-constantine.plotnikov@gmail.com","threadId":"19994","inReplyTo":null,"subject":"[JGIT PATCH] Support for delegating tree iterators","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-07-01T17:52:52Z","receivedAt":"2009-07-01T17:52:52Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"This patch introduce some methods that simplify creation of tree\niterators that wraps other iterators and which are located in\nother package. Such iterators need to efficiently access the\nname component of the path of wrapped iterator and wrapped bits.\nThe patch also adds a method that ensuring that path buffer has\na requried capacity when the required capacity is known in advance.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\nNote that WorkingTreeIterator.parseEntry is possibly might be a good \nplace to use ensurePathCapacity(...) instead or growPath(...).\n  \n .../jgit/treewalk/AbstractTreeIterator.java        |   60 +++++++++++++++++++-\n 1 files changed, 58 insertions(+), 2 deletions(-)\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 057250e..8f5f8c5 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@@ -252,8 +252,41 @@ protected AbstractTreeIterator(final AbstractTreeIterator p,\n \t *            be moved into the larger buffer.\n \t */\n \tprotected void growPath(final int len) {\n+\t\tsetPathCapacity(path.length << 1, len);\n+\t}\n+\n+\t/**\n+\t * Ensure that path is capable to hold at least {@code capacity} bytes\n+\t *\n+\t * @param capacity\n+\t *            the amount of bytes to hold\n+\t * @param len\n+\t *            the amount of live bytes in path buffer \n+\t */\n+\tprotected void ensurePathCapacity(final int capacity, final int len) {\n+\t\tif(path.length >= capacity) {\n+\t\t\treturn;\n+\t\t}\n+\t\tfinal byte[] o = path;\n+\t\tint current = o.length;\n+\t\tint newCapacity = current;\n+\t\twhile(newCapacity < capacity && newCapacity > 0) {\n+\t\t\tnewCapacity <<= 1;\n+\t\t}\n+\t\tsetPathCapacity(newCapacity, len);\n+\t}\n+\n+\t/**\n+\t * Set path buffer capacity to the specified size\n+\t *\n+\t * @param capacity\n+\t *            the new size\n+\t * @param len\n+\t *            the amount of bytes to copy\n+\t */\n+\tprivate void setPathCapacity(int capacity, int len) {\n \t\tfinal byte[] o = path;\n-\t\tfinal byte[] n = new byte[o.length << 1];\n+\t\tfinal byte[] n = new byte[capacity];\n \t\tSystem.arraycopy(o, 0, n, 0, len);\n \t\tfor (AbstractTreeIterator p = this; p != null && p.path == o; p = p.parent)\n \t\t\tp.path = n;\n@@ -354,7 +387,12 @@ public void getEntryObjectId(final MutableObjectId out) {\n \tpublic FileMode getEntryFileMode() {\n \t\treturn FileMode.fromBits(mode);\n \t}\n-\n+\t\n+\t/** @return the file mode of the current entry as bits */\n+\tpublic int getEntryFileModeBits() {\n+\t\treturn mode;\n+\t}\n+\t\n \t/** @return path of the current entry, as a string. */\n \tpublic String getEntryPathString() {\n \t\treturn TreeWalk.pathOf(this);\n@@ -531,4 +569,22 @@ public void skip() throws CorruptObjectException {\n \tpublic void stopWalk() {\n \t\t// Do nothing by default.  Most iterators do not care.\n \t}\n+\t\n+\t/**\n+\t * @return the length of the name component of the path for the current entry\n+\t */\n+\tpublic int getNameLength() {\n+\t\treturn pathLen - pathOffset;\n+\t}\n+\t\n+\t/**\n+\t * Get the name component of the current entry path into the provided buffer.\n+\t * \n+\t * @param buffer the buffer to get the name into, it is assumed that buffer can hold the name\n+\t * @param offset the offset of the name in the buffer\n+\t * @see #getNameLength()\n+\t */\n+\tpublic void getName(byte[] buffer, int offset) {\n+\t\tSystem.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);\n+\t}\n }\n-- \n1.6.1.2\n"},{"id":"117328","messageId":"20090701223448.GT11191@spearce.org","threadId":"19994","inReplyTo":"1246470772-4496-1-git-send-email-constantine.plotnikov@gmail.com","subject":"Re: [JGIT PATCH] Support for delegating tree iterators","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-07-01T22:34:48Z","receivedAt":"2009-07-01T22:34:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Constantine Plotnikov <constantine.plotnikov@gmail.com> wrote:\n> This patch introduce some methods that simplify creation of tree\n> iterators that wraps other iterators and which are located in\n> other package. Such iterators need to efficiently access the\n> name component of the path of wrapped iterator and wrapped bits.\n> The patch also adds a method that ensuring that path buffer has\n> a requried capacity when the required capacity is known in advance.\n> \n> Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n\nThanks, two style nits, I fixed during apply:\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 2fe756e..50befbe 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@@ -264,15 +264,13 @@ protected void growPath(final int len) {\n \t *            the amount of live bytes in path buffer\n \t */\n \tprotected void ensurePathCapacity(final int capacity, final int len) {\n-\t\tif(path.length >= capacity) {\n+\t\tif (path.length >= capacity)\n \t\t\treturn;\n-\t\t}\n \t\tfinal byte[] o = path;\n \t\tint current = o.length;\n \t\tint newCapacity = current;\n-\t\twhile(newCapacity < capacity && newCapacity > 0) {\n+\t\twhile (newCapacity < capacity && newCapacity > 0)\n \t\t\tnewCapacity <<= 1;\n-\t\t}\n \t\tsetPathCapacity(newCapacity, len);\n \t}\n \n> ---\n> Note that WorkingTreeIterator.parseEntry is possibly might be a good \n> place to use ensurePathCapacity(...) instead or growPath(...).\n\nYes.  I'll send a change shortly.\n   \n-- \nShawn.\n"},{"id":"117329","messageId":"20090701224137.GU11191@spearce.org","threadId":"19994","inReplyTo":"20090701223448.GT11191@spearce.org","subject":"Re: [JGIT PATCH] Support for delegating tree iterators","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-07-01T22:41:37Z","receivedAt":"2009-07-01T22:41:37Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> Constantine Plotnikov <constantine.plotnikov@gmail.com> wrote:\n> > This patch introduce some methods that simplify creation of tree\n> > iterators that wraps other iterators and which are located in\n> > other package. Such iterators need to efficiently access the\n> > name component of the path of wrapped iterator and wrapped bits.\n> > The patch also adds a method that ensuring that path buffer has\n> > a requried capacity when the required capacity is known in advance.\n> > \n> > Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n> \n> Thanks, two style nits, I fixed during apply:\n\nI also decided to squash this in, the name better matches with\nTreeWalk's other like methods.  That is, the method name in TreeWalk\nlacks the \"Entry\" prefix, but is otherwise the same name as the\nname in the iterator.\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 50befbe..2116387 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@@ -387,7 +387,7 @@ public FileMode getEntryFileMode() {\n \t}\n \n \t/** @return the file mode of the current entry as bits */\n-\tpublic int getEntryFileModeBits() {\n+\tpublic int getEntryRawMode() {\n \t\treturn mode;\n \t}\n \n \n-- \nShawn.\n"},{"id":"117387","messageId":"200907022200.40179.robin.rosenberg.lists@dewire.com","threadId":"19994","inReplyTo":"1246470772-4496-1-git-send-email-constantine.plotnikov@gmail.com","subject":"Re: [JGIT PATCH] Support for delegating tree iterators","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2009-07-02T20:00:39Z","receivedAt":"2009-07-02T20:00:39Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"onsdag 01 juli 2009 19:52:52 skrev Constantine Plotnikov <constantine.plotnikov@gmail.com>:\n> +\tprotected void ensurePathCapacity(final int capacity, final int len) {\n> +\t\tif(path.length >= capacity) {\n> +\t\t\treturn;\n> +\t\t}\n> +\t\tfinal byte[] o = path;\n> +\t\tint current = o.length;\n> +\t\tint newCapacity = current;\n> +\t\twhile(newCapacity < capacity && newCapacity > 0) {\n> +\t\t\tnewCapacity <<= 1;\n> +\t\t}\n> +\t\tsetPathCapacity(newCapacity, len);\n> +\t}\n\nThere are no JUnit tests that directly or indirectly proves this is working as only\nthe optimized path is taken.\n\n\n> +\tpublic int getNameLength() {\n> +\t\treturn pathLen - pathOffset;\n> +\t}\n\n> +\tpublic void getName(byte[] buffer, int offset) {\n> +\t\tSystem.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);\n> +\t}\n\nNever used? Not even unit test code.\n\n> -- robin\n"}]}