Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RevWalk.java 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. /*
  2. * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.revwalk;
  45. import java.io.IOException;
  46. import java.text.MessageFormat;
  47. import java.util.ArrayList;
  48. import java.util.Collection;
  49. import java.util.EnumSet;
  50. import java.util.Iterator;
  51. import java.util.List;
  52. import org.eclipse.jgit.errors.CorruptObjectException;
  53. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  54. import org.eclipse.jgit.errors.LargeObjectException;
  55. import org.eclipse.jgit.errors.MissingObjectException;
  56. import org.eclipse.jgit.errors.RevWalkException;
  57. import org.eclipse.jgit.internal.JGitText;
  58. import org.eclipse.jgit.lib.AnyObjectId;
  59. import org.eclipse.jgit.lib.AsyncObjectLoaderQueue;
  60. import org.eclipse.jgit.lib.Constants;
  61. import org.eclipse.jgit.lib.MutableObjectId;
  62. import org.eclipse.jgit.lib.ObjectId;
  63. import org.eclipse.jgit.lib.ObjectIdOwnerMap;
  64. import org.eclipse.jgit.lib.ObjectLoader;
  65. import org.eclipse.jgit.lib.ObjectReader;
  66. import org.eclipse.jgit.lib.Repository;
  67. import org.eclipse.jgit.revwalk.filter.RevFilter;
  68. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  69. /**
  70. * Walks a commit graph and produces the matching commits in order.
  71. * <p>
  72. * A RevWalk instance can only be used once to generate results. Running a
  73. * second time requires creating a new RevWalk instance, or invoking
  74. * {@link #reset()} before starting again. Resetting an existing instance may be
  75. * faster for some applications as commit body parsing can be avoided on the
  76. * later invocations.
  77. * <p>
  78. * RevWalk instances are not thread-safe. Applications must either restrict
  79. * usage of a RevWalk instance to a single thread, or implement their own
  80. * synchronization at a higher level.
  81. * <p>
  82. * Multiple simultaneous RevWalk instances per {@link Repository} are permitted,
  83. * even from concurrent threads. Equality of {@link RevCommit}s from two
  84. * different RevWalk instances is never true, even if their {@link ObjectId}s
  85. * are equal (and thus they describe the same commit).
  86. * <p>
  87. * The offered iterator is over the list of RevCommits described by the
  88. * configuration of this instance. Applications should restrict themselves to
  89. * using either the provided Iterator or {@link #next()}, but never use both on
  90. * the same RevWalk at the same time. The Iterator may buffer RevCommits, while
  91. * {@link #next()} does not.
  92. */
  93. public class RevWalk implements Iterable<RevCommit> {
  94. private static final int MB = 1 << 20;
  95. /**
  96. * Set on objects whose important header data has been loaded.
  97. * <p>
  98. * For a RevCommit this indicates we have pulled apart the tree and parent
  99. * references from the raw bytes available in the repository and translated
  100. * those to our own local RevTree and RevCommit instances. The raw buffer is
  101. * also available for message and other header filtering.
  102. * <p>
  103. * For a RevTag this indicates we have pulled part the tag references to
  104. * find out who the tag refers to, and what that object's type is.
  105. */
  106. static final int PARSED = 1 << 0;
  107. /**
  108. * Set on RevCommit instances added to our {@link #pending} queue.
  109. * <p>
  110. * We use this flag to avoid adding the same commit instance twice to our
  111. * queue, especially if we reached it by more than one path.
  112. */
  113. static final int SEEN = 1 << 1;
  114. /**
  115. * Set on RevCommit instances the caller does not want output.
  116. * <p>
  117. * We flag commits as uninteresting if the caller does not want commits
  118. * reachable from a commit given to {@link #markUninteresting(RevCommit)}.
  119. * This flag is always carried into the commit's parents and is a key part
  120. * of the "rev-list B --not A" feature; A is marked UNINTERESTING.
  121. */
  122. static final int UNINTERESTING = 1 << 2;
  123. /**
  124. * Set on a RevCommit that can collapse out of the history.
  125. * <p>
  126. * If the {@link #treeFilter} concluded that this commit matches his
  127. * parents' for all of the paths that the filter is interested in then we
  128. * mark the commit REWRITE. Later we can rewrite the parents of a REWRITE
  129. * child to remove chains of REWRITE commits before we produce the child to
  130. * the application.
  131. *
  132. * @see RewriteGenerator
  133. */
  134. static final int REWRITE = 1 << 3;
  135. /**
  136. * Temporary mark for use within generators or filters.
  137. * <p>
  138. * This mark is only for local use within a single scope. If someone sets
  139. * the mark they must unset it before any other code can see the mark.
  140. */
  141. static final int TEMP_MARK = 1 << 4;
  142. /**
  143. * Temporary mark for use within {@link TopoSortGenerator}.
  144. * <p>
  145. * This mark indicates the commit could not produce when it wanted to, as at
  146. * least one child was behind it. Commits with this flag are delayed until
  147. * all children have been output first.
  148. */
  149. static final int TOPO_DELAY = 1 << 5;
  150. /** Number of flag bits we keep internal for our own use. See above flags. */
  151. static final int RESERVED_FLAGS = 6;
  152. private static final int APP_FLAGS = -1 & ~((1 << RESERVED_FLAGS) - 1);
  153. /** Exists <b>ONLY</b> to support legacy Tag and Commit objects. */
  154. final Repository repository;
  155. final ObjectReader reader;
  156. final MutableObjectId idBuffer;
  157. ObjectIdOwnerMap<RevObject> objects;
  158. private int freeFlags = APP_FLAGS;
  159. private int delayFreeFlags;
  160. int carryFlags = UNINTERESTING;
  161. final ArrayList<RevCommit> roots;
  162. AbstractRevQueue queue;
  163. Generator pending;
  164. private final EnumSet<RevSort> sorting;
  165. private RevFilter filter;
  166. private TreeFilter treeFilter;
  167. private boolean retainBody;
  168. /**
  169. * Create a new revision walker for a given repository.
  170. *
  171. * @param repo
  172. * the repository the walker will obtain data from. An
  173. * ObjectReader will be created by the walker, and must be
  174. * released by the caller.
  175. */
  176. public RevWalk(final Repository repo) {
  177. this(repo, repo.newObjectReader());
  178. }
  179. /**
  180. * Create a new revision walker for a given repository.
  181. *
  182. * @param or
  183. * the reader the walker will obtain data from. The reader should
  184. * be released by the caller when the walker is no longer
  185. * required.
  186. */
  187. public RevWalk(ObjectReader or) {
  188. this(null, or);
  189. }
  190. private RevWalk(final Repository repo, final ObjectReader or) {
  191. repository = repo;
  192. reader = or;
  193. idBuffer = new MutableObjectId();
  194. objects = new ObjectIdOwnerMap<RevObject>();
  195. roots = new ArrayList<RevCommit>();
  196. queue = new DateRevQueue();
  197. pending = new StartGenerator(this);
  198. sorting = EnumSet.of(RevSort.NONE);
  199. filter = RevFilter.ALL;
  200. treeFilter = TreeFilter.ALL;
  201. retainBody = true;
  202. }
  203. /** @return the reader this walker is using to load objects. */
  204. public ObjectReader getObjectReader() {
  205. return reader;
  206. }
  207. /**
  208. * Release any resources used by this walker's reader.
  209. * <p>
  210. * A walker that has been released can be used again, but may need to be
  211. * released after the subsequent usage.
  212. */
  213. public void release() {
  214. reader.release();
  215. }
  216. /**
  217. * Mark a commit to start graph traversal from.
  218. * <p>
  219. * Callers are encouraged to use {@link #parseCommit(AnyObjectId)} to obtain
  220. * the commit reference, rather than {@link #lookupCommit(AnyObjectId)}, as
  221. * this method requires the commit to be parsed before it can be added as a
  222. * root for the traversal.
  223. * <p>
  224. * The method will automatically parse an unparsed commit, but error
  225. * handling may be more difficult for the application to explain why a
  226. * RevCommit is not actually a commit. The object pool of this walker would
  227. * also be 'poisoned' by the non-commit RevCommit.
  228. *
  229. * @param c
  230. * the commit to start traversing from. The commit passed must be
  231. * from this same revision walker.
  232. * @throws MissingObjectException
  233. * the commit supplied is not available from the object
  234. * database. This usually indicates the supplied commit is
  235. * invalid, but the reference was constructed during an earlier
  236. * invocation to {@link #lookupCommit(AnyObjectId)}.
  237. * @throws IncorrectObjectTypeException
  238. * the object was not parsed yet and it was discovered during
  239. * parsing that it is not actually a commit. This usually
  240. * indicates the caller supplied a non-commit SHA-1 to
  241. * {@link #lookupCommit(AnyObjectId)}.
  242. * @throws IOException
  243. * a pack file or loose object could not be read.
  244. */
  245. public void markStart(final RevCommit c) throws MissingObjectException,
  246. IncorrectObjectTypeException, IOException {
  247. if ((c.flags & SEEN) != 0)
  248. return;
  249. if ((c.flags & PARSED) == 0)
  250. c.parseHeaders(this);
  251. c.flags |= SEEN;
  252. roots.add(c);
  253. queue.add(c);
  254. }
  255. /**
  256. * Mark commits to start graph traversal from.
  257. *
  258. * @param list
  259. * commits to start traversing from. The commits passed must be
  260. * from this same revision walker.
  261. * @throws MissingObjectException
  262. * one of the commits supplied is not available from the object
  263. * database. This usually indicates the supplied commit is
  264. * invalid, but the reference was constructed during an earlier
  265. * invocation to {@link #lookupCommit(AnyObjectId)}.
  266. * @throws IncorrectObjectTypeException
  267. * the object was not parsed yet and it was discovered during
  268. * parsing that it is not actually a commit. This usually
  269. * indicates the caller supplied a non-commit SHA-1 to
  270. * {@link #lookupCommit(AnyObjectId)}.
  271. * @throws IOException
  272. * a pack file or loose object could not be read.
  273. */
  274. public void markStart(final Collection<RevCommit> list)
  275. throws MissingObjectException, IncorrectObjectTypeException,
  276. IOException {
  277. for (final RevCommit c : list)
  278. markStart(c);
  279. }
  280. /**
  281. * Mark a commit to not produce in the output.
  282. * <p>
  283. * Uninteresting commits denote not just themselves but also their entire
  284. * ancestry chain, back until the merge base of an uninteresting commit and
  285. * an otherwise interesting commit.
  286. * <p>
  287. * Callers are encouraged to use {@link #parseCommit(AnyObjectId)} to obtain
  288. * the commit reference, rather than {@link #lookupCommit(AnyObjectId)}, as
  289. * this method requires the commit to be parsed before it can be added as a
  290. * root for the traversal.
  291. * <p>
  292. * The method will automatically parse an unparsed commit, but error
  293. * handling may be more difficult for the application to explain why a
  294. * RevCommit is not actually a commit. The object pool of this walker would
  295. * also be 'poisoned' by the non-commit RevCommit.
  296. *
  297. * @param c
  298. * the commit to start traversing from. The commit passed must be
  299. * from this same revision walker.
  300. * @throws MissingObjectException
  301. * the commit supplied is not available from the object
  302. * database. This usually indicates the supplied commit is
  303. * invalid, but the reference was constructed during an earlier
  304. * invocation to {@link #lookupCommit(AnyObjectId)}.
  305. * @throws IncorrectObjectTypeException
  306. * the object was not parsed yet and it was discovered during
  307. * parsing that it is not actually a commit. This usually
  308. * indicates the caller supplied a non-commit SHA-1 to
  309. * {@link #lookupCommit(AnyObjectId)}.
  310. * @throws IOException
  311. * a pack file or loose object could not be read.
  312. */
  313. public void markUninteresting(final RevCommit c)
  314. throws MissingObjectException, IncorrectObjectTypeException,
  315. IOException {
  316. c.flags |= UNINTERESTING;
  317. carryFlagsImpl(c);
  318. markStart(c);
  319. }
  320. /**
  321. * Determine if a commit is reachable from another commit.
  322. * <p>
  323. * A commit <code>base</code> is an ancestor of <code>tip</code> if we
  324. * can find a path of commits that leads from <code>tip</code> and ends at
  325. * <code>base</code>.
  326. * <p>
  327. * This utility function resets the walker, inserts the two supplied
  328. * commits, and then executes a walk until an answer can be obtained.
  329. * Currently allocated RevFlags that have been added to RevCommit instances
  330. * will be retained through the reset.
  331. *
  332. * @param base
  333. * commit the caller thinks is reachable from <code>tip</code>.
  334. * @param tip
  335. * commit to start iteration from, and which is most likely a
  336. * descendant (child) of <code>base</code>.
  337. * @return true if there is a path directly from <code>tip</code> to
  338. * <code>base</code> (and thus <code>base</code> is fully merged
  339. * into <code>tip</code>); false otherwise.
  340. * @throws MissingObjectException
  341. * one or or more of the next commit's parents are not available
  342. * from the object database, but were thought to be candidates
  343. * for traversal. This usually indicates a broken link.
  344. * @throws IncorrectObjectTypeException
  345. * one or or more of the next commit's parents are not actually
  346. * commit objects.
  347. * @throws IOException
  348. * a pack file or loose object could not be read.
  349. */
  350. public boolean isMergedInto(final RevCommit base, final RevCommit tip)
  351. throws MissingObjectException, IncorrectObjectTypeException,
  352. IOException {
  353. final RevFilter oldRF = filter;
  354. final TreeFilter oldTF = treeFilter;
  355. try {
  356. finishDelayedFreeFlags();
  357. reset(~freeFlags & APP_FLAGS);
  358. filter = RevFilter.MERGE_BASE;
  359. treeFilter = TreeFilter.ALL;
  360. markStart(tip);
  361. markStart(base);
  362. return next() == base;
  363. } finally {
  364. filter = oldRF;
  365. treeFilter = oldTF;
  366. }
  367. }
  368. /**
  369. * Pop the next most recent commit.
  370. *
  371. * @return next most recent commit; null if traversal is over.
  372. * @throws MissingObjectException
  373. * one or or more of the next commit's parents are not available
  374. * from the object database, but were thought to be candidates
  375. * for traversal. This usually indicates a broken link.
  376. * @throws IncorrectObjectTypeException
  377. * one or or more of the next commit's parents are not actually
  378. * commit objects.
  379. * @throws IOException
  380. * a pack file or loose object could not be read.
  381. */
  382. public RevCommit next() throws MissingObjectException,
  383. IncorrectObjectTypeException, IOException {
  384. return pending.next();
  385. }
  386. /**
  387. * Obtain the sort types applied to the commits returned.
  388. *
  389. * @return the sorting strategies employed. At least one strategy is always
  390. * used, but that strategy may be {@link RevSort#NONE}.
  391. */
  392. public EnumSet<RevSort> getRevSort() {
  393. return sorting.clone();
  394. }
  395. /**
  396. * Check whether the provided sorting strategy is enabled.
  397. *
  398. * @param sort
  399. * a sorting strategy to look for.
  400. * @return true if this strategy is enabled, false otherwise
  401. */
  402. public boolean hasRevSort(RevSort sort) {
  403. return sorting.contains(sort);
  404. }
  405. /**
  406. * Select a single sorting strategy for the returned commits.
  407. * <p>
  408. * Disables all sorting strategies, then enables only the single strategy
  409. * supplied by the caller.
  410. *
  411. * @param s
  412. * a sorting strategy to enable.
  413. */
  414. public void sort(final RevSort s) {
  415. assertNotStarted();
  416. sorting.clear();
  417. sorting.add(s);
  418. }
  419. /**
  420. * Add or remove a sorting strategy for the returned commits.
  421. * <p>
  422. * Multiple strategies can be applied at once, in which case some strategies
  423. * may take precedence over others. As an example, {@link RevSort#TOPO} must
  424. * take precedence over {@link RevSort#COMMIT_TIME_DESC}, otherwise it
  425. * cannot enforce its ordering.
  426. *
  427. * @param s
  428. * a sorting strategy to enable or disable.
  429. * @param use
  430. * true if this strategy should be used, false if it should be
  431. * removed.
  432. */
  433. public void sort(final RevSort s, final boolean use) {
  434. assertNotStarted();
  435. if (use)
  436. sorting.add(s);
  437. else
  438. sorting.remove(s);
  439. if (sorting.size() > 1)
  440. sorting.remove(RevSort.NONE);
  441. else if (sorting.size() == 0)
  442. sorting.add(RevSort.NONE);
  443. }
  444. /**
  445. * Get the currently configured commit filter.
  446. *
  447. * @return the current filter. Never null as a filter is always needed.
  448. */
  449. public RevFilter getRevFilter() {
  450. return filter;
  451. }
  452. /**
  453. * Set the commit filter for this walker.
  454. * <p>
  455. * Multiple filters may be combined by constructing an arbitrary tree of
  456. * <code>AndRevFilter</code> or <code>OrRevFilter</code> instances to
  457. * describe the boolean expression required by the application. Custom
  458. * filter implementations may also be constructed by applications.
  459. * <p>
  460. * Note that filters are not thread-safe and may not be shared by concurrent
  461. * RevWalk instances. Every RevWalk must be supplied its own unique filter,
  462. * unless the filter implementation specifically states it is (and always
  463. * will be) thread-safe. Callers may use {@link RevFilter#clone()} to create
  464. * a unique filter tree for this RevWalk instance.
  465. *
  466. * @param newFilter
  467. * the new filter. If null the special {@link RevFilter#ALL}
  468. * filter will be used instead, as it matches every commit.
  469. * @see org.eclipse.jgit.revwalk.filter.AndRevFilter
  470. * @see org.eclipse.jgit.revwalk.filter.OrRevFilter
  471. */
  472. public void setRevFilter(final RevFilter newFilter) {
  473. assertNotStarted();
  474. filter = newFilter != null ? newFilter : RevFilter.ALL;
  475. }
  476. /**
  477. * Get the tree filter used to simplify commits by modified paths.
  478. *
  479. * @return the current filter. Never null as a filter is always needed. If
  480. * no filter is being applied {@link TreeFilter#ALL} is returned.
  481. */
  482. public TreeFilter getTreeFilter() {
  483. return treeFilter;
  484. }
  485. /**
  486. * Set the tree filter used to simplify commits by modified paths.
  487. * <p>
  488. * If null or {@link TreeFilter#ALL} the path limiter is removed. Commits
  489. * will not be simplified.
  490. * <p>
  491. * If non-null and not {@link TreeFilter#ALL} then the tree filter will be
  492. * installed and commits will have their ancestry simplified to hide commits
  493. * that do not contain tree entries matched by the filter.
  494. * <p>
  495. * Usually callers should be inserting a filter graph including
  496. * {@link TreeFilter#ANY_DIFF} along with one or more
  497. * {@link org.eclipse.jgit.treewalk.filter.PathFilter} instances.
  498. *
  499. * @param newFilter
  500. * new filter. If null the special {@link TreeFilter#ALL} filter
  501. * will be used instead, as it matches everything.
  502. * @see org.eclipse.jgit.treewalk.filter.PathFilter
  503. */
  504. public void setTreeFilter(final TreeFilter newFilter) {
  505. assertNotStarted();
  506. treeFilter = newFilter != null ? newFilter : TreeFilter.ALL;
  507. }
  508. /**
  509. * Should the body of a commit or tag be retained after parsing its headers?
  510. * <p>
  511. * Usually the body is always retained, but some application code might not
  512. * care and would prefer to discard the body of a commit as early as
  513. * possible, to reduce memory usage.
  514. *
  515. * @return true if the body should be retained; false it is discarded.
  516. */
  517. public boolean isRetainBody() {
  518. return retainBody;
  519. }
  520. /**
  521. * Set whether or not the body of a commit or tag is retained.
  522. * <p>
  523. * If a body of a commit or tag is not retained, the application must
  524. * call {@link #parseBody(RevObject)} before the body can be safely
  525. * accessed through the type specific access methods.
  526. *
  527. * @param retain true to retain bodies; false to discard them early.
  528. */
  529. public void setRetainBody(final boolean retain) {
  530. retainBody = retain;
  531. }
  532. /**
  533. * Locate a reference to a blob without loading it.
  534. * <p>
  535. * The blob may or may not exist in the repository. It is impossible to tell
  536. * from this method's return value.
  537. *
  538. * @param id
  539. * name of the blob object.
  540. * @return reference to the blob object. Never null.
  541. */
  542. public RevBlob lookupBlob(final AnyObjectId id) {
  543. RevBlob c = (RevBlob) objects.get(id);
  544. if (c == null) {
  545. c = new RevBlob(id);
  546. objects.add(c);
  547. }
  548. return c;
  549. }
  550. /**
  551. * Locate a reference to a tree without loading it.
  552. * <p>
  553. * The tree may or may not exist in the repository. It is impossible to tell
  554. * from this method's return value.
  555. *
  556. * @param id
  557. * name of the tree object.
  558. * @return reference to the tree object. Never null.
  559. */
  560. public RevTree lookupTree(final AnyObjectId id) {
  561. RevTree c = (RevTree) objects.get(id);
  562. if (c == null) {
  563. c = new RevTree(id);
  564. objects.add(c);
  565. }
  566. return c;
  567. }
  568. /**
  569. * Locate a reference to a commit without loading it.
  570. * <p>
  571. * The commit may or may not exist in the repository. It is impossible to
  572. * tell from this method's return value.
  573. * <p>
  574. * See {@link #parseHeaders(RevObject)} and {@link #parseBody(RevObject)}
  575. * for loading contents.
  576. *
  577. * @param id
  578. * name of the commit object.
  579. * @return reference to the commit object. Never null.
  580. */
  581. public RevCommit lookupCommit(final AnyObjectId id) {
  582. RevCommit c = (RevCommit) objects.get(id);
  583. if (c == null) {
  584. c = createCommit(id);
  585. objects.add(c);
  586. }
  587. return c;
  588. }
  589. /**
  590. * Locate a reference to a tag without loading it.
  591. * <p>
  592. * The tag may or may not exist in the repository. It is impossible to tell
  593. * from this method's return value.
  594. *
  595. * @param id
  596. * name of the tag object.
  597. * @return reference to the tag object. Never null.
  598. */
  599. public RevTag lookupTag(final AnyObjectId id) {
  600. RevTag c = (RevTag) objects.get(id);
  601. if (c == null) {
  602. c = new RevTag(id);
  603. objects.add(c);
  604. }
  605. return c;
  606. }
  607. /**
  608. * Locate a reference to any object without loading it.
  609. * <p>
  610. * The object may or may not exist in the repository. It is impossible to
  611. * tell from this method's return value.
  612. *
  613. * @param id
  614. * name of the object.
  615. * @param type
  616. * type of the object. Must be a valid Git object type.
  617. * @return reference to the object. Never null.
  618. */
  619. public RevObject lookupAny(final AnyObjectId id, final int type) {
  620. RevObject r = objects.get(id);
  621. if (r == null) {
  622. switch (type) {
  623. case Constants.OBJ_COMMIT:
  624. r = createCommit(id);
  625. break;
  626. case Constants.OBJ_TREE:
  627. r = new RevTree(id);
  628. break;
  629. case Constants.OBJ_BLOB:
  630. r = new RevBlob(id);
  631. break;
  632. case Constants.OBJ_TAG:
  633. r = new RevTag(id);
  634. break;
  635. default:
  636. throw new IllegalArgumentException(MessageFormat.format(
  637. JGitText.get().invalidGitType, Integer.valueOf(type)));
  638. }
  639. objects.add(r);
  640. }
  641. return r;
  642. }
  643. /**
  644. * Locate an object that was previously allocated in this walk.
  645. *
  646. * @param id
  647. * name of the object.
  648. * @return reference to the object if it has been previously located;
  649. * otherwise null.
  650. */
  651. public RevObject lookupOrNull(AnyObjectId id) {
  652. return objects.get(id);
  653. }
  654. /**
  655. * Locate a reference to a commit and immediately parse its content.
  656. * <p>
  657. * Unlike {@link #lookupCommit(AnyObjectId)} this method only returns
  658. * successfully if the commit object exists, is verified to be a commit, and
  659. * was parsed without error.
  660. *
  661. * @param id
  662. * name of the commit object.
  663. * @return reference to the commit object. Never null.
  664. * @throws MissingObjectException
  665. * the supplied commit does not exist.
  666. * @throws IncorrectObjectTypeException
  667. * the supplied id is not a commit or an annotated tag.
  668. * @throws IOException
  669. * a pack file or loose object could not be read.
  670. */
  671. public RevCommit parseCommit(final AnyObjectId id)
  672. throws MissingObjectException, IncorrectObjectTypeException,
  673. IOException {
  674. RevObject c = peel(parseAny(id));
  675. if (!(c instanceof RevCommit))
  676. throw new IncorrectObjectTypeException(id.toObjectId(),
  677. Constants.TYPE_COMMIT);
  678. return (RevCommit) c;
  679. }
  680. /**
  681. * Locate a reference to a tree.
  682. * <p>
  683. * This method only returns successfully if the tree object exists, is
  684. * verified to be a tree.
  685. *
  686. * @param id
  687. * name of the tree object, or a commit or annotated tag that may
  688. * reference a tree.
  689. * @return reference to the tree object. Never null.
  690. * @throws MissingObjectException
  691. * the supplied tree does not exist.
  692. * @throws IncorrectObjectTypeException
  693. * the supplied id is not a tree, a commit or an annotated tag.
  694. * @throws IOException
  695. * a pack file or loose object could not be read.
  696. */
  697. public RevTree parseTree(final AnyObjectId id)
  698. throws MissingObjectException, IncorrectObjectTypeException,
  699. IOException {
  700. RevObject c = peel(parseAny(id));
  701. final RevTree t;
  702. if (c instanceof RevCommit)
  703. t = ((RevCommit) c).getTree();
  704. else if (!(c instanceof RevTree))
  705. throw new IncorrectObjectTypeException(id.toObjectId(),
  706. Constants.TYPE_TREE);
  707. else
  708. t = (RevTree) c;
  709. parseHeaders(t);
  710. return t;
  711. }
  712. /**
  713. * Locate a reference to an annotated tag and immediately parse its content.
  714. * <p>
  715. * Unlike {@link #lookupTag(AnyObjectId)} this method only returns
  716. * successfully if the tag object exists, is verified to be a tag, and was
  717. * parsed without error.
  718. *
  719. * @param id
  720. * name of the tag object.
  721. * @return reference to the tag object. Never null.
  722. * @throws MissingObjectException
  723. * the supplied tag does not exist.
  724. * @throws IncorrectObjectTypeException
  725. * the supplied id is not a tag or an annotated tag.
  726. * @throws IOException
  727. * a pack file or loose object could not be read.
  728. */
  729. public RevTag parseTag(final AnyObjectId id) throws MissingObjectException,
  730. IncorrectObjectTypeException, IOException {
  731. RevObject c = parseAny(id);
  732. if (!(c instanceof RevTag))
  733. throw new IncorrectObjectTypeException(id.toObjectId(),
  734. Constants.TYPE_TAG);
  735. return (RevTag) c;
  736. }
  737. /**
  738. * Locate a reference to any object and immediately parse its headers.
  739. * <p>
  740. * This method only returns successfully if the object exists and was parsed
  741. * without error. Parsing an object can be expensive as the type must be
  742. * determined. For blobs this may mean the blob content was unpacked
  743. * unnecessarily, and thrown away.
  744. *
  745. * @param id
  746. * name of the object.
  747. * @return reference to the object. Never null.
  748. * @throws MissingObjectException
  749. * the supplied does not exist.
  750. * @throws IOException
  751. * a pack file or loose object could not be read.
  752. */
  753. public RevObject parseAny(final AnyObjectId id)
  754. throws MissingObjectException, IOException {
  755. RevObject r = objects.get(id);
  756. if (r == null)
  757. r = parseNew(id, reader.open(id));
  758. else
  759. parseHeaders(r);
  760. return r;
  761. }
  762. private RevObject parseNew(AnyObjectId id, ObjectLoader ldr)
  763. throws LargeObjectException, CorruptObjectException,
  764. MissingObjectException, IOException {
  765. RevObject r;
  766. int type = ldr.getType();
  767. switch (type) {
  768. case Constants.OBJ_COMMIT: {
  769. final RevCommit c = createCommit(id);
  770. c.parseCanonical(this, getCachedBytes(c, ldr));
  771. r = c;
  772. break;
  773. }
  774. case Constants.OBJ_TREE: {
  775. r = new RevTree(id);
  776. r.flags |= PARSED;
  777. break;
  778. }
  779. case Constants.OBJ_BLOB: {
  780. r = new RevBlob(id);
  781. r.flags |= PARSED;
  782. break;
  783. }
  784. case Constants.OBJ_TAG: {
  785. final RevTag t = new RevTag(id);
  786. t.parseCanonical(this, getCachedBytes(t, ldr));
  787. r = t;
  788. break;
  789. }
  790. default:
  791. throw new IllegalArgumentException(MessageFormat.format(
  792. JGitText.get().badObjectType, Integer.valueOf(type)));
  793. }
  794. objects.add(r);
  795. return r;
  796. }
  797. byte[] getCachedBytes(RevObject obj) throws LargeObjectException,
  798. MissingObjectException, IncorrectObjectTypeException, IOException {
  799. return getCachedBytes(obj, reader.open(obj, obj.getType()));
  800. }
  801. byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)
  802. throws LargeObjectException, MissingObjectException, IOException {
  803. try {
  804. return ldr.getCachedBytes(5 * MB);
  805. } catch (LargeObjectException tooBig) {
  806. tooBig.setObjectId(obj);
  807. throw tooBig;
  808. }
  809. }
  810. /**
  811. * Asynchronous object parsing.
  812. *
  813. * @param <T>
  814. * any ObjectId type.
  815. * @param objectIds
  816. * objects to open from the object store. The supplied collection
  817. * must not be modified until the queue has finished.
  818. * @param reportMissing
  819. * if true missing objects are reported by calling failure with a
  820. * MissingObjectException. This may be more expensive for the
  821. * implementation to guarantee. If false the implementation may
  822. * choose to report MissingObjectException, or silently skip over
  823. * the object with no warning.
  824. * @return queue to read the objects from.
  825. */
  826. public <T extends ObjectId> AsyncRevObjectQueue parseAny(
  827. Iterable<T> objectIds, boolean reportMissing) {
  828. List<T> need = new ArrayList<T>();
  829. List<RevObject> have = new ArrayList<RevObject>();
  830. for (T id : objectIds) {
  831. RevObject r = objects.get(id);
  832. if (r != null && (r.flags & PARSED) != 0)
  833. have.add(r);
  834. else
  835. need.add(id);
  836. }
  837. final Iterator<RevObject> objItr = have.iterator();
  838. if (need.isEmpty()) {
  839. return new AsyncRevObjectQueue() {
  840. public RevObject next() {
  841. return objItr.hasNext() ? objItr.next() : null;
  842. }
  843. public boolean cancel(boolean mayInterruptIfRunning) {
  844. return true;
  845. }
  846. public void release() {
  847. // In-memory only, no action required.
  848. }
  849. };
  850. }
  851. final AsyncObjectLoaderQueue<T> lItr = reader.open(need, reportMissing);
  852. return new AsyncRevObjectQueue() {
  853. public RevObject next() throws MissingObjectException,
  854. IncorrectObjectTypeException, IOException {
  855. if (objItr.hasNext())
  856. return objItr.next();
  857. if (!lItr.next())
  858. return null;
  859. ObjectId id = lItr.getObjectId();
  860. ObjectLoader ldr = lItr.open();
  861. RevObject r = objects.get(id);
  862. if (r == null)
  863. r = parseNew(id, ldr);
  864. else if (r instanceof RevCommit) {
  865. byte[] raw = ldr.getCachedBytes();
  866. ((RevCommit) r).parseCanonical(RevWalk.this, raw);
  867. } else if (r instanceof RevTag) {
  868. byte[] raw = ldr.getCachedBytes();
  869. ((RevTag) r).parseCanonical(RevWalk.this, raw);
  870. } else
  871. r.flags |= PARSED;
  872. return r;
  873. }
  874. public boolean cancel(boolean mayInterruptIfRunning) {
  875. return lItr.cancel(mayInterruptIfRunning);
  876. }
  877. public void release() {
  878. lItr.release();
  879. }
  880. };
  881. }
  882. /**
  883. * Ensure the object's critical headers have been parsed.
  884. * <p>
  885. * This method only returns successfully if the object exists and was parsed
  886. * without error.
  887. *
  888. * @param obj
  889. * the object the caller needs to be parsed.
  890. * @throws MissingObjectException
  891. * the supplied does not exist.
  892. * @throws IOException
  893. * a pack file or loose object could not be read.
  894. */
  895. public void parseHeaders(final RevObject obj)
  896. throws MissingObjectException, IOException {
  897. if ((obj.flags & PARSED) == 0)
  898. obj.parseHeaders(this);
  899. }
  900. /**
  901. * Ensure the object's full body content is available.
  902. * <p>
  903. * This method only returns successfully if the object exists and was parsed
  904. * without error.
  905. *
  906. * @param obj
  907. * the object the caller needs to be parsed.
  908. * @throws MissingObjectException
  909. * the supplied does not exist.
  910. * @throws IOException
  911. * a pack file or loose object could not be read.
  912. */
  913. public void parseBody(final RevObject obj)
  914. throws MissingObjectException, IOException {
  915. obj.parseBody(this);
  916. }
  917. /**
  918. * Peel back annotated tags until a non-tag object is found.
  919. *
  920. * @param obj
  921. * the starting object.
  922. * @return If {@code obj} is not an annotated tag, {@code obj}. Otherwise
  923. * the first non-tag object that {@code obj} references. The
  924. * returned object's headers have been parsed.
  925. * @throws MissingObjectException
  926. * a referenced object cannot be found.
  927. * @throws IOException
  928. * a pack file or loose object could not be read.
  929. */
  930. public RevObject peel(RevObject obj) throws MissingObjectException,
  931. IOException {
  932. while (obj instanceof RevTag) {
  933. parseHeaders(obj);
  934. obj = ((RevTag) obj).getObject();
  935. }
  936. parseHeaders(obj);
  937. return obj;
  938. }
  939. /**
  940. * Create a new flag for application use during walking.
  941. * <p>
  942. * Applications are only assured to be able to create 24 unique flags on any
  943. * given revision walker instance. Any flags beyond 24 are offered only if
  944. * the implementation has extra free space within its internal storage.
  945. *
  946. * @param name
  947. * description of the flag, primarily useful for debugging.
  948. * @return newly constructed flag instance.
  949. * @throws IllegalArgumentException
  950. * too many flags have been reserved on this revision walker.
  951. */
  952. public RevFlag newFlag(final String name) {
  953. final int m = allocFlag();
  954. return new RevFlag(this, name, m);
  955. }
  956. int allocFlag() {
  957. if (freeFlags == 0)
  958. throw new IllegalArgumentException(MessageFormat.format(
  959. JGitText.get().flagsAlreadyCreated,
  960. Integer.valueOf(32 - RESERVED_FLAGS)));
  961. final int m = Integer.lowestOneBit(freeFlags);
  962. freeFlags &= ~m;
  963. return m;
  964. }
  965. /**
  966. * Automatically carry a flag from a child commit to its parents.
  967. * <p>
  968. * A carried flag is copied from the child commit onto its parents when the
  969. * child commit is popped from the lowest level of walk's internal graph.
  970. *
  971. * @param flag
  972. * the flag to carry onto parents, if set on a descendant.
  973. */
  974. public void carry(final RevFlag flag) {
  975. if ((freeFlags & flag.mask) != 0)
  976. throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));
  977. if (flag.walker != this)
  978. throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));
  979. carryFlags |= flag.mask;
  980. }
  981. /**
  982. * Automatically carry flags from a child commit to its parents.
  983. * <p>
  984. * A carried flag is copied from the child commit onto its parents when the
  985. * child commit is popped from the lowest level of walk's internal graph.
  986. *
  987. * @param set
  988. * the flags to carry onto parents, if set on a descendant.
  989. */
  990. public void carry(final Collection<RevFlag> set) {
  991. for (final RevFlag flag : set)
  992. carry(flag);
  993. }
  994. /**
  995. * Allow a flag to be recycled for a different use.
  996. * <p>
  997. * Recycled flags always come back as a different Java object instance when
  998. * assigned again by {@link #newFlag(String)}.
  999. * <p>
  1000. * If the flag was previously being carried, the carrying request is
  1001. * removed. Disposing of a carried flag while a traversal is in progress has
  1002. * an undefined behavior.
  1003. *
  1004. * @param flag
  1005. * the to recycle.
  1006. */
  1007. public void disposeFlag(final RevFlag flag) {
  1008. freeFlag(flag.mask);
  1009. }
  1010. void freeFlag(final int mask) {
  1011. if (isNotStarted()) {
  1012. freeFlags |= mask;
  1013. carryFlags &= ~mask;
  1014. } else {
  1015. delayFreeFlags |= mask;
  1016. }
  1017. }
  1018. private void finishDelayedFreeFlags() {
  1019. if (delayFreeFlags != 0) {
  1020. freeFlags |= delayFreeFlags;
  1021. carryFlags &= ~delayFreeFlags;
  1022. delayFreeFlags = 0;
  1023. }
  1024. }
  1025. /**
  1026. * Resets internal state and allows this instance to be used again.
  1027. * <p>
  1028. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1029. * instances are not invalidated. RevFlag instances are not invalidated, but
  1030. * are removed from all RevObjects.
  1031. */
  1032. public final void reset() {
  1033. reset(0);
  1034. }
  1035. /**
  1036. * Resets internal state and allows this instance to be used again.
  1037. * <p>
  1038. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1039. * instances are not invalidated. RevFlag instances are not invalidated, but
  1040. * are removed from all RevObjects.
  1041. *
  1042. * @param retainFlags
  1043. * application flags that should <b>not</b> be cleared from
  1044. * existing commit objects.
  1045. */
  1046. public final void resetRetain(final RevFlagSet retainFlags) {
  1047. reset(retainFlags.mask);
  1048. }
  1049. /**
  1050. * Resets internal state and allows this instance to be used again.
  1051. * <p>
  1052. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1053. * instances are not invalidated. RevFlag instances are not invalidated, but
  1054. * are removed from all RevObjects.
  1055. *
  1056. * @param retainFlags
  1057. * application flags that should <b>not</b> be cleared from
  1058. * existing commit objects.
  1059. */
  1060. public final void resetRetain(final RevFlag... retainFlags) {
  1061. int mask = 0;
  1062. for (final RevFlag flag : retainFlags)
  1063. mask |= flag.mask;
  1064. reset(mask);
  1065. }
  1066. /**
  1067. * Resets internal state and allows this instance to be used again.
  1068. * <p>
  1069. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1070. * instances are not invalidated. RevFlag instances are not invalidated, but
  1071. * are removed from all RevObjects.
  1072. *
  1073. * @param retainFlags
  1074. * application flags that should <b>not</b> be cleared from
  1075. * existing commit objects.
  1076. */
  1077. protected void reset(int retainFlags) {
  1078. finishDelayedFreeFlags();
  1079. retainFlags |= PARSED;
  1080. final int clearFlags = ~retainFlags;
  1081. final FIFORevQueue q = new FIFORevQueue();
  1082. for (final RevCommit c : roots) {
  1083. if ((c.flags & clearFlags) == 0)
  1084. continue;
  1085. c.flags &= retainFlags;
  1086. c.reset();
  1087. q.add(c);
  1088. }
  1089. for (;;) {
  1090. final RevCommit c = q.next();
  1091. if (c == null)
  1092. break;
  1093. if (c.parents == null)
  1094. continue;
  1095. for (final RevCommit p : c.parents) {
  1096. if ((p.flags & clearFlags) == 0)
  1097. continue;
  1098. p.flags &= retainFlags;
  1099. p.reset();
  1100. q.add(p);
  1101. }
  1102. }
  1103. roots.clear();
  1104. queue = new DateRevQueue();
  1105. pending = new StartGenerator(this);
  1106. }
  1107. /**
  1108. * Dispose all internal state and invalidate all RevObject instances.
  1109. * <p>
  1110. * All RevObject (and thus RevCommit, etc.) instances previously acquired
  1111. * from this RevWalk are invalidated by a dispose call. Applications must
  1112. * not retain or use RevObject instances obtained prior to the dispose call.
  1113. * All RevFlag instances are also invalidated, and must not be reused.
  1114. */
  1115. public void dispose() {
  1116. reader.release();
  1117. freeFlags = APP_FLAGS;
  1118. delayFreeFlags = 0;
  1119. carryFlags = UNINTERESTING;
  1120. objects.clear();
  1121. reader.release();
  1122. roots.clear();
  1123. queue = new DateRevQueue();
  1124. pending = new StartGenerator(this);
  1125. }
  1126. /**
  1127. * Returns an Iterator over the commits of this walker.
  1128. * <p>
  1129. * The returned iterator is only useful for one walk. If this RevWalk gets
  1130. * reset a new iterator must be obtained to walk over the new results.
  1131. * <p>
  1132. * Applications must not use both the Iterator and the {@link #next()} API
  1133. * at the same time. Pick one API and use that for the entire walk.
  1134. * <p>
  1135. * If a checked exception is thrown during the walk (see {@link #next()})
  1136. * it is rethrown from the Iterator as a {@link RevWalkException}.
  1137. *
  1138. * @return an iterator over this walker's commits.
  1139. * @see RevWalkException
  1140. */
  1141. public Iterator<RevCommit> iterator() {
  1142. final RevCommit first;
  1143. try {
  1144. first = RevWalk.this.next();
  1145. } catch (MissingObjectException e) {
  1146. throw new RevWalkException(e);
  1147. } catch (IncorrectObjectTypeException e) {
  1148. throw new RevWalkException(e);
  1149. } catch (IOException e) {
  1150. throw new RevWalkException(e);
  1151. }
  1152. return new Iterator<RevCommit>() {
  1153. RevCommit next = first;
  1154. public boolean hasNext() {
  1155. return next != null;
  1156. }
  1157. public RevCommit next() {
  1158. try {
  1159. final RevCommit r = next;
  1160. next = RevWalk.this.next();
  1161. return r;
  1162. } catch (MissingObjectException e) {
  1163. throw new RevWalkException(e);
  1164. } catch (IncorrectObjectTypeException e) {
  1165. throw new RevWalkException(e);
  1166. } catch (IOException e) {
  1167. throw new RevWalkException(e);
  1168. }
  1169. }
  1170. public void remove() {
  1171. throw new UnsupportedOperationException();
  1172. }
  1173. };
  1174. }
  1175. /** Throws an exception if we have started producing output. */
  1176. protected void assertNotStarted() {
  1177. if (isNotStarted())
  1178. return;
  1179. throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);
  1180. }
  1181. private boolean isNotStarted() {
  1182. return pending instanceof StartGenerator;
  1183. }
  1184. /**
  1185. * Create and return an {@link ObjectWalk} using the same objects.
  1186. * <p>
  1187. * Prior to using this method, the caller must reset this RevWalk to clean
  1188. * any flags that were used during the last traversal.
  1189. * <p>
  1190. * The returned ObjectWalk uses the same ObjectReader, internal object pool,
  1191. * and free RevFlags. Once the ObjectWalk is created, this RevWalk should
  1192. * not be used anymore.
  1193. *
  1194. * @return a new walk, using the exact same object pool.
  1195. */
  1196. public ObjectWalk toObjectWalkWithSameObjects() {
  1197. ObjectWalk ow = new ObjectWalk(reader);
  1198. RevWalk rw = ow;
  1199. rw.objects = objects;
  1200. rw.freeFlags = freeFlags;
  1201. return ow;
  1202. }
  1203. /**
  1204. * Construct a new unparsed commit for the given object.
  1205. *
  1206. * @param id
  1207. * the object this walker requires a commit reference for.
  1208. * @return a new unparsed reference for the object.
  1209. */
  1210. protected RevCommit createCommit(final AnyObjectId id) {
  1211. return new RevCommit(id);
  1212. }
  1213. void carryFlagsImpl(final RevCommit c) {
  1214. final int carry = c.flags & carryFlags;
  1215. if (carry != 0)
  1216. RevCommit.carryFlags(c, carry);
  1217. }
  1218. }