You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractTreeIterator.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright (C) 2008-2009, Google Inc.
  3. * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
  4. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  5. * and other copyright owners as documented in the project's IP log.
  6. *
  7. * This program and the accompanying materials are made available
  8. * under the terms of the Eclipse Distribution License v1.0 which
  9. * accompanies this distribution, is reproduced below, and is
  10. * available at http://www.eclipse.org/org/documents/edl-v10.php
  11. *
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * - Neither the name of the Eclipse Foundation, Inc. nor the
  27. * names of its contributors may be used to endorse or promote
  28. * products derived from this software without specific prior
  29. * written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  32. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  33. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  34. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  36. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  37. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  38. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  40. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  43. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. package org.eclipse.jgit.treewalk;
  46. import java.io.IOException;
  47. import java.nio.ByteBuffer;
  48. import java.nio.CharBuffer;
  49. import org.eclipse.jgit.dircache.DirCacheCheckout;
  50. import org.eclipse.jgit.errors.CorruptObjectException;
  51. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  52. import org.eclipse.jgit.lib.Constants;
  53. import org.eclipse.jgit.lib.FileMode;
  54. import org.eclipse.jgit.lib.MutableObjectId;
  55. import org.eclipse.jgit.lib.ObjectId;
  56. import org.eclipse.jgit.lib.ObjectReader;
  57. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  58. /**
  59. * Walks a Git tree (directory) in Git sort order.
  60. * <p>
  61. * A new iterator instance should be positioned on the first entry, or at eof.
  62. * Data for the first entry (if not at eof) should be available immediately.
  63. * <p>
  64. * Implementors must walk a tree in the Git sort order, which has the following
  65. * odd sorting:
  66. * <ol>
  67. * <li>A.c</li>
  68. * <li>A/c</li>
  69. * <li>A0c</li>
  70. * </ol>
  71. * <p>
  72. * In the second item, <code>A</code> is the name of a subtree and
  73. * <code>c</code> is a file within that subtree. The other two items are files
  74. * in the root level tree.
  75. *
  76. * @see CanonicalTreeParser
  77. */
  78. public abstract class AbstractTreeIterator {
  79. /** Default size for the {@link #path} buffer. */
  80. protected static final int DEFAULT_PATH_SIZE = 128;
  81. /** A dummy object id buffer that matches the zero ObjectId. */
  82. protected static final byte[] zeroid = new byte[Constants.OBJECT_ID_LENGTH];
  83. /** Iterator for the parent tree; null if we are the root iterator. */
  84. final AbstractTreeIterator parent;
  85. /** The iterator this current entry is path equal to. */
  86. AbstractTreeIterator matches;
  87. /**
  88. * Number of entries we moved forward to force a D/F conflict match.
  89. *
  90. * @see NameConflictTreeWalk
  91. */
  92. int matchShift;
  93. /**
  94. * Mode bits for the current entry.
  95. * <p>
  96. * A numerical value from FileMode is usually faster for an iterator to
  97. * obtain from its data source so this is the preferred representation.
  98. *
  99. * @see org.eclipse.jgit.lib.FileMode
  100. */
  101. protected int mode;
  102. /**
  103. * Path buffer for the current entry.
  104. * <p>
  105. * This buffer is pre-allocated at the start of walking and is shared from
  106. * parent iterators down into their subtree iterators. The sharing allows
  107. * the current entry to always be a full path from the root, while each
  108. * subtree only needs to populate the part that is under their control.
  109. */
  110. protected byte[] path;
  111. /**
  112. * Position within {@link #path} this iterator starts writing at.
  113. * <p>
  114. * This is the first offset in {@link #path} that this iterator must
  115. * populate during {@link #next}. At the root level (when {@link #parent}
  116. * is null) this is 0. For a subtree iterator the index before this position
  117. * should have the value '/'.
  118. */
  119. protected final int pathOffset;
  120. /**
  121. * Total length of the current entry's complete path from the root.
  122. * <p>
  123. * This is the number of bytes within {@link #path} that pertain to the
  124. * current entry. Values at this index through the end of the array are
  125. * garbage and may be randomly populated from prior entries.
  126. */
  127. protected int pathLen;
  128. /** Create a new iterator with no parent. */
  129. protected AbstractTreeIterator() {
  130. parent = null;
  131. path = new byte[DEFAULT_PATH_SIZE];
  132. pathOffset = 0;
  133. }
  134. /**
  135. * Create a new iterator with no parent and a prefix.
  136. * <p>
  137. * The prefix path supplied is inserted in front of all paths generated by
  138. * this iterator. It is intended to be used when an iterator is being
  139. * created for a subsection of an overall repository and needs to be
  140. * combined with other iterators that are created to run over the entire
  141. * repository namespace.
  142. *
  143. * @param prefix
  144. * position of this iterator in the repository tree. The value
  145. * may be null or the empty string to indicate the prefix is the
  146. * root of the repository. A trailing slash ('/') is
  147. * automatically appended if the prefix does not end in '/'.
  148. */
  149. protected AbstractTreeIterator(final String prefix) {
  150. parent = null;
  151. if (prefix != null && prefix.length() > 0) {
  152. final ByteBuffer b;
  153. b = Constants.CHARSET.encode(CharBuffer.wrap(prefix));
  154. pathLen = b.limit();
  155. path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)];
  156. b.get(path, 0, pathLen);
  157. if (path[pathLen - 1] != '/')
  158. path[pathLen++] = '/';
  159. pathOffset = pathLen;
  160. } else {
  161. path = new byte[DEFAULT_PATH_SIZE];
  162. pathOffset = 0;
  163. }
  164. }
  165. /**
  166. * Create a new iterator with no parent and a prefix.
  167. * <p>
  168. * The prefix path supplied is inserted in front of all paths generated by
  169. * this iterator. It is intended to be used when an iterator is being
  170. * created for a subsection of an overall repository and needs to be
  171. * combined with other iterators that are created to run over the entire
  172. * repository namespace.
  173. *
  174. * @param prefix
  175. * position of this iterator in the repository tree. The value
  176. * may be null or the empty array to indicate the prefix is the
  177. * root of the repository. A trailing slash ('/') is
  178. * automatically appended if the prefix does not end in '/'.
  179. */
  180. protected AbstractTreeIterator(final byte[] prefix) {
  181. parent = null;
  182. if (prefix != null && prefix.length > 0) {
  183. pathLen = prefix.length;
  184. path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)];
  185. System.arraycopy(prefix, 0, path, 0, pathLen);
  186. if (path[pathLen - 1] != '/')
  187. path[pathLen++] = '/';
  188. pathOffset = pathLen;
  189. } else {
  190. path = new byte[DEFAULT_PATH_SIZE];
  191. pathOffset = 0;
  192. }
  193. }
  194. /**
  195. * Create an iterator for a subtree of an existing iterator.
  196. *
  197. * @param p
  198. * parent tree iterator.
  199. */
  200. protected AbstractTreeIterator(final AbstractTreeIterator p) {
  201. parent = p;
  202. path = p.path;
  203. pathOffset = p.pathLen + 1;
  204. try {
  205. path[pathOffset - 1] = '/';
  206. } catch (ArrayIndexOutOfBoundsException e) {
  207. growPath(p.pathLen);
  208. path[pathOffset - 1] = '/';
  209. }
  210. }
  211. /**
  212. * Create an iterator for a subtree of an existing iterator.
  213. * <p>
  214. * The caller is responsible for setting up the path of the child iterator.
  215. *
  216. * @param p
  217. * parent tree iterator.
  218. * @param childPath
  219. * path array to be used by the child iterator. This path must
  220. * contain the path from the top of the walk to the first child
  221. * and must end with a '/'.
  222. * @param childPathOffset
  223. * position within <code>childPath</code> where the child can
  224. * insert its data. The value at
  225. * <code>childPath[childPathOffset-1]</code> must be '/'.
  226. */
  227. protected AbstractTreeIterator(final AbstractTreeIterator p,
  228. final byte[] childPath, final int childPathOffset) {
  229. parent = p;
  230. path = childPath;
  231. pathOffset = childPathOffset;
  232. }
  233. /**
  234. * Grow the path buffer larger.
  235. *
  236. * @param len
  237. * number of live bytes in the path buffer. This many bytes will
  238. * be moved into the larger buffer.
  239. */
  240. protected void growPath(final int len) {
  241. setPathCapacity(path.length << 1, len);
  242. }
  243. /**
  244. * Ensure that path is capable to hold at least {@code capacity} bytes
  245. *
  246. * @param capacity
  247. * the amount of bytes to hold
  248. * @param len
  249. * the amount of live bytes in path buffer
  250. */
  251. protected void ensurePathCapacity(final int capacity, final int len) {
  252. if (path.length >= capacity)
  253. return;
  254. final byte[] o = path;
  255. int current = o.length;
  256. int newCapacity = current;
  257. while (newCapacity < capacity && newCapacity > 0)
  258. newCapacity <<= 1;
  259. setPathCapacity(newCapacity, len);
  260. }
  261. /**
  262. * Set path buffer capacity to the specified size
  263. *
  264. * @param capacity
  265. * the new size
  266. * @param len
  267. * the amount of bytes to copy
  268. */
  269. private void setPathCapacity(int capacity, int len) {
  270. final byte[] o = path;
  271. final byte[] n = new byte[capacity];
  272. System.arraycopy(o, 0, n, 0, len);
  273. for (AbstractTreeIterator p = this; p != null && p.path == o; p = p.parent)
  274. p.path = n;
  275. }
  276. /**
  277. * Compare the path of this current entry to another iterator's entry.
  278. *
  279. * @param p
  280. * the other iterator to compare the path against.
  281. * @return -1 if this entry sorts first; 0 if the entries are equal; 1 if
  282. * p's entry sorts first.
  283. */
  284. public int pathCompare(final AbstractTreeIterator p) {
  285. return pathCompare(p, p.mode);
  286. }
  287. int pathCompare(final AbstractTreeIterator p, final int pMode) {
  288. // Its common when we are a subtree for both parents to match;
  289. // when this happens everything in path[0..cPos] is known to
  290. // be equal and does not require evaluation again.
  291. //
  292. int cPos = alreadyMatch(this, p);
  293. return pathCompare(p.path, cPos, p.pathLen, pMode, cPos);
  294. }
  295. /**
  296. * Compare the path of this current entry to a raw buffer.
  297. *
  298. * @param buf
  299. * the raw path buffer.
  300. * @param pos
  301. * position to start reading the raw buffer.
  302. * @param end
  303. * one past the end of the raw buffer (length is end - pos).
  304. * @param mode
  305. * the mode of the path.
  306. * @return -1 if this entry sorts first; 0 if the entries are equal; 1 if
  307. * p's entry sorts first.
  308. */
  309. public int pathCompare(byte[] buf, int pos, int end, int mode) {
  310. return pathCompare(buf, pos, end, mode, 0);
  311. }
  312. private int pathCompare(byte[] b, int bPos, int bEnd, int bMode, int aPos) {
  313. final byte[] a = path;
  314. final int aEnd = pathLen;
  315. for (; aPos < aEnd && bPos < bEnd; aPos++, bPos++) {
  316. final int cmp = (a[aPos] & 0xff) - (b[bPos] & 0xff);
  317. if (cmp != 0)
  318. return cmp;
  319. }
  320. if (aPos < aEnd)
  321. return (a[aPos] & 0xff) - lastPathChar(bMode);
  322. if (bPos < bEnd)
  323. return lastPathChar(mode) - (b[bPos] & 0xff);
  324. return lastPathChar(mode) - lastPathChar(bMode);
  325. }
  326. private static int alreadyMatch(AbstractTreeIterator a,
  327. AbstractTreeIterator b) {
  328. for (;;) {
  329. final AbstractTreeIterator ap = a.parent;
  330. final AbstractTreeIterator bp = b.parent;
  331. if (ap == null || bp == null)
  332. return 0;
  333. if (ap.matches == bp.matches)
  334. return a.pathOffset;
  335. a = ap;
  336. b = bp;
  337. }
  338. }
  339. private static int lastPathChar(final int mode) {
  340. return FileMode.TREE.equals(mode) ? '/' : '\0';
  341. }
  342. /**
  343. * Check if the current entry of both iterators has the same id.
  344. * <p>
  345. * This method is faster than {@link #getEntryObjectId()} as it does not
  346. * require copying the bytes out of the buffers. A direct {@link #idBuffer}
  347. * compare operation is performed.
  348. *
  349. * @param otherIterator
  350. * the other iterator to test against.
  351. * @return true if both iterators have the same object id; false otherwise.
  352. */
  353. public boolean idEqual(final AbstractTreeIterator otherIterator) {
  354. return ObjectId.equals(idBuffer(), idOffset(),
  355. otherIterator.idBuffer(), otherIterator.idOffset());
  356. }
  357. /** @return true if the entry has a valid ObjectId. */
  358. public abstract boolean hasId();
  359. /**
  360. * Get the object id of the current entry.
  361. *
  362. * @return an object id for the current entry.
  363. */
  364. public ObjectId getEntryObjectId() {
  365. return ObjectId.fromRaw(idBuffer(), idOffset());
  366. }
  367. /**
  368. * Obtain the ObjectId for the current entry.
  369. *
  370. * @param out
  371. * buffer to copy the object id into.
  372. */
  373. public void getEntryObjectId(final MutableObjectId out) {
  374. out.fromRaw(idBuffer(), idOffset());
  375. }
  376. /** @return the file mode of the current entry. */
  377. public FileMode getEntryFileMode() {
  378. return FileMode.fromBits(mode);
  379. }
  380. /** @return the file mode of the current entry as bits */
  381. public int getEntryRawMode() {
  382. return mode;
  383. }
  384. /** @return path of the current entry, as a string. */
  385. public String getEntryPathString() {
  386. return TreeWalk.pathOf(this);
  387. }
  388. /** @return the internal buffer holding the current path. */
  389. public byte[] getEntryPathBuffer() {
  390. return path;
  391. }
  392. /** @return length of the path in {@link #getEntryPathBuffer()}. */
  393. public int getEntryPathLength() {
  394. return pathLen;
  395. }
  396. /**
  397. * Get the current entry's path hash code.
  398. * <p>
  399. * This method computes a hash code on the fly for this path, the hash is
  400. * suitable to cluster objects that may have similar paths together.
  401. *
  402. * @return path hash code; any integer may be returned.
  403. */
  404. public int getEntryPathHashCode() {
  405. int hash = 0;
  406. for (int i = Math.max(0, pathLen - 16); i < pathLen; i++) {
  407. byte c = path[i];
  408. if (c != ' ')
  409. hash = (hash >>> 2) + (c << 24);
  410. }
  411. return hash;
  412. }
  413. /**
  414. * Get the byte array buffer object IDs must be copied out of.
  415. * <p>
  416. * The id buffer contains the bytes necessary to construct an ObjectId for
  417. * the current entry of this iterator. The buffer can be the same buffer for
  418. * all entries, or it can be a unique buffer per-entry. Implementations are
  419. * encouraged to expose their private buffer whenever possible to reduce
  420. * garbage generation and copying costs.
  421. *
  422. * @return byte array the implementation stores object IDs within.
  423. * @see #getEntryObjectId()
  424. */
  425. public abstract byte[] idBuffer();
  426. /**
  427. * Get the position within {@link #idBuffer()} of this entry's ObjectId.
  428. *
  429. * @return offset into the array returned by {@link #idBuffer()} where the
  430. * ObjectId must be copied out of.
  431. */
  432. public abstract int idOffset();
  433. /**
  434. * Create a new iterator for the current entry's subtree.
  435. * <p>
  436. * The parent reference of the iterator must be <code>this</code>,
  437. * otherwise the caller would not be able to exit out of the subtree
  438. * iterator correctly and return to continue walking <code>this</code>.
  439. *
  440. * @param reader
  441. * reader to load the tree data from.
  442. * @return a new parser that walks over the current subtree.
  443. * @throws IncorrectObjectTypeException
  444. * the current entry is not actually a tree and cannot be parsed
  445. * as though it were a tree.
  446. * @throws IOException
  447. * a loose object or pack file could not be read.
  448. */
  449. public abstract AbstractTreeIterator createSubtreeIterator(
  450. ObjectReader reader) throws IncorrectObjectTypeException,
  451. IOException;
  452. /**
  453. * Create a new iterator as though the current entry were a subtree.
  454. *
  455. * @return a new empty tree iterator.
  456. */
  457. public EmptyTreeIterator createEmptyTreeIterator() {
  458. return new EmptyTreeIterator(this);
  459. }
  460. /**
  461. * Create a new iterator for the current entry's subtree.
  462. * <p>
  463. * The parent reference of the iterator must be <code>this</code>, otherwise
  464. * the caller would not be able to exit out of the subtree iterator
  465. * correctly and return to continue walking <code>this</code>.
  466. *
  467. * @param reader
  468. * reader to load the tree data from.
  469. * @param idBuffer
  470. * temporary ObjectId buffer for use by this method.
  471. * @return a new parser that walks over the current subtree.
  472. * @throws IncorrectObjectTypeException
  473. * the current entry is not actually a tree and cannot be parsed
  474. * as though it were a tree.
  475. * @throws IOException
  476. * a loose object or pack file could not be read.
  477. */
  478. public AbstractTreeIterator createSubtreeIterator(
  479. final ObjectReader reader, final MutableObjectId idBuffer)
  480. throws IncorrectObjectTypeException, IOException {
  481. return createSubtreeIterator(reader);
  482. }
  483. /**
  484. * Position this iterator on the first entry.
  485. *
  486. * The default implementation of this method uses {@code back(1)} until
  487. * {@code first()} is true. This is most likely not the most efficient
  488. * method of repositioning the iterator to its first entry, so subclasses
  489. * are strongly encouraged to override the method.
  490. *
  491. * @throws CorruptObjectException
  492. * the tree is invalid.
  493. */
  494. public void reset() throws CorruptObjectException {
  495. while (!first())
  496. back(1);
  497. }
  498. /**
  499. * Is this tree iterator positioned on its first entry?
  500. * <p>
  501. * An iterator is positioned on the first entry if <code>back(1)</code>
  502. * would be an invalid request as there is no entry before the current one.
  503. * <p>
  504. * An empty iterator (one with no entries) will be
  505. * <code>first() &amp;&amp; eof()</code>.
  506. *
  507. * @return true if the iterator is positioned on the first entry.
  508. */
  509. public abstract boolean first();
  510. /**
  511. * Is this tree iterator at its EOF point (no more entries)?
  512. * <p>
  513. * An iterator is at EOF if there is no current entry.
  514. *
  515. * @return true if we have walked all entries and have none left.
  516. */
  517. public abstract boolean eof();
  518. /**
  519. * Move to next entry, populating this iterator with the entry data.
  520. * <p>
  521. * The delta indicates how many moves forward should occur. The most common
  522. * delta is 1 to move to the next entry.
  523. * <p>
  524. * Implementations must populate the following members:
  525. * <ul>
  526. * <li>{@link #mode}</li>
  527. * <li>{@link #path} (from {@link #pathOffset} to {@link #pathLen})</li>
  528. * <li>{@link #pathLen}</li>
  529. * </ul>
  530. * as well as any implementation dependent information necessary to
  531. * accurately return data from {@link #idBuffer()} and {@link #idOffset()}
  532. * when demanded.
  533. *
  534. * @param delta
  535. * number of entries to move the iterator by. Must be a positive,
  536. * non-zero integer.
  537. * @throws CorruptObjectException
  538. * the tree is invalid.
  539. */
  540. public abstract void next(int delta) throws CorruptObjectException;
  541. /**
  542. * Move to prior entry, populating this iterator with the entry data.
  543. * <p>
  544. * The delta indicates how many moves backward should occur.The most common
  545. * delta is 1 to move to the prior entry.
  546. * <p>
  547. * Implementations must populate the following members:
  548. * <ul>
  549. * <li>{@link #mode}</li>
  550. * <li>{@link #path} (from {@link #pathOffset} to {@link #pathLen})</li>
  551. * <li>{@link #pathLen}</li>
  552. * </ul>
  553. * as well as any implementation dependent information necessary to
  554. * accurately return data from {@link #idBuffer()} and {@link #idOffset()}
  555. * when demanded.
  556. *
  557. * @param delta
  558. * number of entries to move the iterator by. Must be a positive,
  559. * non-zero integer.
  560. * @throws CorruptObjectException
  561. * the tree is invalid.
  562. */
  563. public abstract void back(int delta) throws CorruptObjectException;
  564. /**
  565. * Advance to the next tree entry, populating this iterator with its data.
  566. * <p>
  567. * This method behaves like <code>seek(1)</code> but is called by
  568. * {@link TreeWalk} only if a {@link TreeFilter} was used and ruled out the
  569. * current entry from the results. In such cases this tree iterator may
  570. * perform special behavior.
  571. *
  572. * @throws CorruptObjectException
  573. * the tree is invalid.
  574. */
  575. public void skip() throws CorruptObjectException {
  576. next(1);
  577. }
  578. /**
  579. * Indicates to the iterator that no more entries will be read.
  580. * <p>
  581. * This is only invoked by TreeWalk when the iteration is aborted early due
  582. * to a {@link org.eclipse.jgit.errors.StopWalkException} being thrown from
  583. * within a TreeFilter.
  584. */
  585. public void stopWalk() {
  586. // Do nothing by default. Most iterators do not care.
  587. }
  588. /**
  589. * @return the length of the name component of the path for the current entry
  590. */
  591. public int getNameLength() {
  592. return pathLen - pathOffset;
  593. }
  594. /**
  595. * JGit internal API for use by {@link DirCacheCheckout}
  596. *
  597. * @return start of name component part within {@link #getEntryPathBuffer()}
  598. * @since 2.0
  599. */
  600. public int getNameOffset() {
  601. return pathOffset;
  602. }
  603. /**
  604. * Get the name component of the current entry path into the provided
  605. * buffer.
  606. *
  607. * @param buffer
  608. * the buffer to get the name into, it is assumed that buffer can
  609. * hold the name
  610. * @param offset
  611. * the offset of the name in the buffer
  612. * @see #getNameLength()
  613. */
  614. public void getName(byte[] buffer, int offset) {
  615. System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);
  616. }
  617. @Override
  618. public String toString() {
  619. return getClass().getSimpleName() + "[" + getEntryPathString() + "]";
  620. }
  621. }