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.

RevWalk.java 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  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. *
  574. * @param id
  575. * name of the commit object.
  576. * @return reference to the commit object. Never null.
  577. */
  578. public RevCommit lookupCommit(final AnyObjectId id) {
  579. RevCommit c = (RevCommit) objects.get(id);
  580. if (c == null) {
  581. c = createCommit(id);
  582. objects.add(c);
  583. }
  584. return c;
  585. }
  586. /**
  587. * Locate a reference to a tag without loading it.
  588. * <p>
  589. * The tag may or may not exist in the repository. It is impossible to tell
  590. * from this method's return value.
  591. *
  592. * @param id
  593. * name of the tag object.
  594. * @return reference to the tag object. Never null.
  595. */
  596. public RevTag lookupTag(final AnyObjectId id) {
  597. RevTag c = (RevTag) objects.get(id);
  598. if (c == null) {
  599. c = new RevTag(id);
  600. objects.add(c);
  601. }
  602. return c;
  603. }
  604. /**
  605. * Locate a reference to any object without loading it.
  606. * <p>
  607. * The object may or may not exist in the repository. It is impossible to
  608. * tell from this method's return value.
  609. *
  610. * @param id
  611. * name of the object.
  612. * @param type
  613. * type of the object. Must be a valid Git object type.
  614. * @return reference to the object. Never null.
  615. */
  616. public RevObject lookupAny(final AnyObjectId id, final int type) {
  617. RevObject r = objects.get(id);
  618. if (r == null) {
  619. switch (type) {
  620. case Constants.OBJ_COMMIT:
  621. r = createCommit(id);
  622. break;
  623. case Constants.OBJ_TREE:
  624. r = new RevTree(id);
  625. break;
  626. case Constants.OBJ_BLOB:
  627. r = new RevBlob(id);
  628. break;
  629. case Constants.OBJ_TAG:
  630. r = new RevTag(id);
  631. break;
  632. default:
  633. throw new IllegalArgumentException(MessageFormat.format(
  634. JGitText.get().invalidGitType, Integer.valueOf(type)));
  635. }
  636. objects.add(r);
  637. }
  638. return r;
  639. }
  640. /**
  641. * Locate an object that was previously allocated in this walk.
  642. *
  643. * @param id
  644. * name of the object.
  645. * @return reference to the object if it has been previously located;
  646. * otherwise null.
  647. */
  648. public RevObject lookupOrNull(AnyObjectId id) {
  649. return objects.get(id);
  650. }
  651. /**
  652. * Locate a reference to a commit and immediately parse its content.
  653. * <p>
  654. * Unlike {@link #lookupCommit(AnyObjectId)} this method only returns
  655. * successfully if the commit object exists, is verified to be a commit, and
  656. * was parsed without error.
  657. *
  658. * @param id
  659. * name of the commit object.
  660. * @return reference to the commit object. Never null.
  661. * @throws MissingObjectException
  662. * the supplied commit does not exist.
  663. * @throws IncorrectObjectTypeException
  664. * the supplied id is not a commit or an annotated tag.
  665. * @throws IOException
  666. * a pack file or loose object could not be read.
  667. */
  668. public RevCommit parseCommit(final AnyObjectId id)
  669. throws MissingObjectException, IncorrectObjectTypeException,
  670. IOException {
  671. RevObject c = peel(parseAny(id));
  672. if (!(c instanceof RevCommit))
  673. throw new IncorrectObjectTypeException(id.toObjectId(),
  674. Constants.TYPE_COMMIT);
  675. return (RevCommit) c;
  676. }
  677. /**
  678. * Locate a reference to a tree.
  679. * <p>
  680. * This method only returns successfully if the tree object exists, is
  681. * verified to be a tree.
  682. *
  683. * @param id
  684. * name of the tree object, or a commit or annotated tag that may
  685. * reference a tree.
  686. * @return reference to the tree object. Never null.
  687. * @throws MissingObjectException
  688. * the supplied tree does not exist.
  689. * @throws IncorrectObjectTypeException
  690. * the supplied id is not a tree, a commit or an annotated tag.
  691. * @throws IOException
  692. * a pack file or loose object could not be read.
  693. */
  694. public RevTree parseTree(final AnyObjectId id)
  695. throws MissingObjectException, IncorrectObjectTypeException,
  696. IOException {
  697. RevObject c = peel(parseAny(id));
  698. final RevTree t;
  699. if (c instanceof RevCommit)
  700. t = ((RevCommit) c).getTree();
  701. else if (!(c instanceof RevTree))
  702. throw new IncorrectObjectTypeException(id.toObjectId(),
  703. Constants.TYPE_TREE);
  704. else
  705. t = (RevTree) c;
  706. parseHeaders(t);
  707. return t;
  708. }
  709. /**
  710. * Locate a reference to an annotated tag and immediately parse its content.
  711. * <p>
  712. * Unlike {@link #lookupTag(AnyObjectId)} this method only returns
  713. * successfully if the tag object exists, is verified to be a tag, and was
  714. * parsed without error.
  715. *
  716. * @param id
  717. * name of the tag object.
  718. * @return reference to the tag object. Never null.
  719. * @throws MissingObjectException
  720. * the supplied tag does not exist.
  721. * @throws IncorrectObjectTypeException
  722. * the supplied id is not a tag or an annotated tag.
  723. * @throws IOException
  724. * a pack file or loose object could not be read.
  725. */
  726. public RevTag parseTag(final AnyObjectId id) throws MissingObjectException,
  727. IncorrectObjectTypeException, IOException {
  728. RevObject c = parseAny(id);
  729. if (!(c instanceof RevTag))
  730. throw new IncorrectObjectTypeException(id.toObjectId(),
  731. Constants.TYPE_TAG);
  732. return (RevTag) c;
  733. }
  734. /**
  735. * Locate a reference to any object and immediately parse its headers.
  736. * <p>
  737. * This method only returns successfully if the object exists and was parsed
  738. * without error. Parsing an object can be expensive as the type must be
  739. * determined. For blobs this may mean the blob content was unpacked
  740. * unnecessarily, and thrown away.
  741. *
  742. * @param id
  743. * name of the object.
  744. * @return reference to the object. Never null.
  745. * @throws MissingObjectException
  746. * the supplied does not exist.
  747. * @throws IOException
  748. * a pack file or loose object could not be read.
  749. */
  750. public RevObject parseAny(final AnyObjectId id)
  751. throws MissingObjectException, IOException {
  752. RevObject r = objects.get(id);
  753. if (r == null)
  754. r = parseNew(id, reader.open(id));
  755. else
  756. parseHeaders(r);
  757. return r;
  758. }
  759. private RevObject parseNew(AnyObjectId id, ObjectLoader ldr)
  760. throws LargeObjectException, CorruptObjectException,
  761. MissingObjectException, IOException {
  762. RevObject r;
  763. int type = ldr.getType();
  764. switch (type) {
  765. case Constants.OBJ_COMMIT: {
  766. final RevCommit c = createCommit(id);
  767. c.parseCanonical(this, getCachedBytes(c, ldr));
  768. r = c;
  769. break;
  770. }
  771. case Constants.OBJ_TREE: {
  772. r = new RevTree(id);
  773. r.flags |= PARSED;
  774. break;
  775. }
  776. case Constants.OBJ_BLOB: {
  777. r = new RevBlob(id);
  778. r.flags |= PARSED;
  779. break;
  780. }
  781. case Constants.OBJ_TAG: {
  782. final RevTag t = new RevTag(id);
  783. t.parseCanonical(this, getCachedBytes(t, ldr));
  784. r = t;
  785. break;
  786. }
  787. default:
  788. throw new IllegalArgumentException(MessageFormat.format(
  789. JGitText.get().badObjectType, Integer.valueOf(type)));
  790. }
  791. objects.add(r);
  792. return r;
  793. }
  794. byte[] getCachedBytes(RevObject obj) throws LargeObjectException,
  795. MissingObjectException, IncorrectObjectTypeException, IOException {
  796. return getCachedBytes(obj, reader.open(obj, obj.getType()));
  797. }
  798. byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)
  799. throws LargeObjectException, MissingObjectException, IOException {
  800. try {
  801. return ldr.getCachedBytes(5 * MB);
  802. } catch (LargeObjectException tooBig) {
  803. tooBig.setObjectId(obj);
  804. throw tooBig;
  805. }
  806. }
  807. /**
  808. * Asynchronous object parsing.
  809. *
  810. * @param <T>
  811. * any ObjectId type.
  812. * @param objectIds
  813. * objects to open from the object store. The supplied collection
  814. * must not be modified until the queue has finished.
  815. * @param reportMissing
  816. * if true missing objects are reported by calling failure with a
  817. * MissingObjectException. This may be more expensive for the
  818. * implementation to guarantee. If false the implementation may
  819. * choose to report MissingObjectException, or silently skip over
  820. * the object with no warning.
  821. * @return queue to read the objects from.
  822. */
  823. public <T extends ObjectId> AsyncRevObjectQueue parseAny(
  824. Iterable<T> objectIds, boolean reportMissing) {
  825. List<T> need = new ArrayList<T>();
  826. List<RevObject> have = new ArrayList<RevObject>();
  827. for (T id : objectIds) {
  828. RevObject r = objects.get(id);
  829. if (r != null && (r.flags & PARSED) != 0)
  830. have.add(r);
  831. else
  832. need.add(id);
  833. }
  834. final Iterator<RevObject> objItr = have.iterator();
  835. if (need.isEmpty()) {
  836. return new AsyncRevObjectQueue() {
  837. public RevObject next() {
  838. return objItr.hasNext() ? objItr.next() : null;
  839. }
  840. public boolean cancel(boolean mayInterruptIfRunning) {
  841. return true;
  842. }
  843. public void release() {
  844. // In-memory only, no action required.
  845. }
  846. };
  847. }
  848. final AsyncObjectLoaderQueue<T> lItr = reader.open(need, reportMissing);
  849. return new AsyncRevObjectQueue() {
  850. public RevObject next() throws MissingObjectException,
  851. IncorrectObjectTypeException, IOException {
  852. if (objItr.hasNext())
  853. return objItr.next();
  854. if (!lItr.next())
  855. return null;
  856. ObjectId id = lItr.getObjectId();
  857. ObjectLoader ldr = lItr.open();
  858. RevObject r = objects.get(id);
  859. if (r == null)
  860. r = parseNew(id, ldr);
  861. else if (r instanceof RevCommit) {
  862. byte[] raw = ldr.getCachedBytes();
  863. ((RevCommit) r).parseCanonical(RevWalk.this, raw);
  864. } else if (r instanceof RevTag) {
  865. byte[] raw = ldr.getCachedBytes();
  866. ((RevTag) r).parseCanonical(RevWalk.this, raw);
  867. } else
  868. r.flags |= PARSED;
  869. return r;
  870. }
  871. public boolean cancel(boolean mayInterruptIfRunning) {
  872. return lItr.cancel(mayInterruptIfRunning);
  873. }
  874. public void release() {
  875. lItr.release();
  876. }
  877. };
  878. }
  879. /**
  880. * Ensure the object's critical headers have been parsed.
  881. * <p>
  882. * This method only returns successfully if the object exists and was parsed
  883. * without error.
  884. *
  885. * @param obj
  886. * the object the caller needs to be parsed.
  887. * @throws MissingObjectException
  888. * the supplied does not exist.
  889. * @throws IOException
  890. * a pack file or loose object could not be read.
  891. */
  892. public void parseHeaders(final RevObject obj)
  893. throws MissingObjectException, IOException {
  894. if ((obj.flags & PARSED) == 0)
  895. obj.parseHeaders(this);
  896. }
  897. /**
  898. * Ensure the object's full body content is available.
  899. * <p>
  900. * This method only returns successfully if the object exists and was parsed
  901. * without error.
  902. *
  903. * @param obj
  904. * the object the caller needs to be parsed.
  905. * @throws MissingObjectException
  906. * the supplied does not exist.
  907. * @throws IOException
  908. * a pack file or loose object could not be read.
  909. */
  910. public void parseBody(final RevObject obj)
  911. throws MissingObjectException, IOException {
  912. obj.parseBody(this);
  913. }
  914. /**
  915. * Peel back annotated tags until a non-tag object is found.
  916. *
  917. * @param obj
  918. * the starting object.
  919. * @return If {@code obj} is not an annotated tag, {@code obj}. Otherwise
  920. * the first non-tag object that {@code obj} references. The
  921. * returned object's headers have been parsed.
  922. * @throws MissingObjectException
  923. * a referenced object cannot be found.
  924. * @throws IOException
  925. * a pack file or loose object could not be read.
  926. */
  927. public RevObject peel(RevObject obj) throws MissingObjectException,
  928. IOException {
  929. while (obj instanceof RevTag) {
  930. parseHeaders(obj);
  931. obj = ((RevTag) obj).getObject();
  932. }
  933. parseHeaders(obj);
  934. return obj;
  935. }
  936. /**
  937. * Create a new flag for application use during walking.
  938. * <p>
  939. * Applications are only assured to be able to create 24 unique flags on any
  940. * given revision walker instance. Any flags beyond 24 are offered only if
  941. * the implementation has extra free space within its internal storage.
  942. *
  943. * @param name
  944. * description of the flag, primarily useful for debugging.
  945. * @return newly constructed flag instance.
  946. * @throws IllegalArgumentException
  947. * too many flags have been reserved on this revision walker.
  948. */
  949. public RevFlag newFlag(final String name) {
  950. final int m = allocFlag();
  951. return new RevFlag(this, name, m);
  952. }
  953. int allocFlag() {
  954. if (freeFlags == 0)
  955. throw new IllegalArgumentException(MessageFormat.format(
  956. JGitText.get().flagsAlreadyCreated,
  957. Integer.valueOf(32 - RESERVED_FLAGS)));
  958. final int m = Integer.lowestOneBit(freeFlags);
  959. freeFlags &= ~m;
  960. return m;
  961. }
  962. /**
  963. * Automatically carry a flag from a child commit to its parents.
  964. * <p>
  965. * A carried flag is copied from the child commit onto its parents when the
  966. * child commit is popped from the lowest level of walk's internal graph.
  967. *
  968. * @param flag
  969. * the flag to carry onto parents, if set on a descendant.
  970. */
  971. public void carry(final RevFlag flag) {
  972. if ((freeFlags & flag.mask) != 0)
  973. throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));
  974. if (flag.walker != this)
  975. throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));
  976. carryFlags |= flag.mask;
  977. }
  978. /**
  979. * Automatically carry flags from a child commit to its parents.
  980. * <p>
  981. * A carried flag is copied from the child commit onto its parents when the
  982. * child commit is popped from the lowest level of walk's internal graph.
  983. *
  984. * @param set
  985. * the flags to carry onto parents, if set on a descendant.
  986. */
  987. public void carry(final Collection<RevFlag> set) {
  988. for (final RevFlag flag : set)
  989. carry(flag);
  990. }
  991. /**
  992. * Allow a flag to be recycled for a different use.
  993. * <p>
  994. * Recycled flags always come back as a different Java object instance when
  995. * assigned again by {@link #newFlag(String)}.
  996. * <p>
  997. * If the flag was previously being carried, the carrying request is
  998. * removed. Disposing of a carried flag while a traversal is in progress has
  999. * an undefined behavior.
  1000. *
  1001. * @param flag
  1002. * the to recycle.
  1003. */
  1004. public void disposeFlag(final RevFlag flag) {
  1005. freeFlag(flag.mask);
  1006. }
  1007. void freeFlag(final int mask) {
  1008. if (isNotStarted()) {
  1009. freeFlags |= mask;
  1010. carryFlags &= ~mask;
  1011. } else {
  1012. delayFreeFlags |= mask;
  1013. }
  1014. }
  1015. private void finishDelayedFreeFlags() {
  1016. if (delayFreeFlags != 0) {
  1017. freeFlags |= delayFreeFlags;
  1018. carryFlags &= ~delayFreeFlags;
  1019. delayFreeFlags = 0;
  1020. }
  1021. }
  1022. /**
  1023. * Resets internal state and allows this instance to be used again.
  1024. * <p>
  1025. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1026. * instances are not invalidated. RevFlag instances are not invalidated, but
  1027. * are removed from all RevObjects.
  1028. */
  1029. public final void reset() {
  1030. reset(0);
  1031. }
  1032. /**
  1033. * Resets internal state and allows this instance to be used again.
  1034. * <p>
  1035. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1036. * instances are not invalidated. RevFlag instances are not invalidated, but
  1037. * are removed from all RevObjects.
  1038. *
  1039. * @param retainFlags
  1040. * application flags that should <b>not</b> be cleared from
  1041. * existing commit objects.
  1042. */
  1043. public final void resetRetain(final RevFlagSet retainFlags) {
  1044. reset(retainFlags.mask);
  1045. }
  1046. /**
  1047. * Resets internal state and allows this instance to be used again.
  1048. * <p>
  1049. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1050. * instances are not invalidated. RevFlag instances are not invalidated, but
  1051. * are removed from all RevObjects.
  1052. *
  1053. * @param retainFlags
  1054. * application flags that should <b>not</b> be cleared from
  1055. * existing commit objects.
  1056. */
  1057. public final void resetRetain(final RevFlag... retainFlags) {
  1058. int mask = 0;
  1059. for (final RevFlag flag : retainFlags)
  1060. mask |= flag.mask;
  1061. reset(mask);
  1062. }
  1063. /**
  1064. * Resets internal state and allows this instance to be used again.
  1065. * <p>
  1066. * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
  1067. * instances are not invalidated. RevFlag instances are not invalidated, but
  1068. * are removed from all RevObjects.
  1069. *
  1070. * @param retainFlags
  1071. * application flags that should <b>not</b> be cleared from
  1072. * existing commit objects.
  1073. */
  1074. protected void reset(int retainFlags) {
  1075. finishDelayedFreeFlags();
  1076. retainFlags |= PARSED;
  1077. final int clearFlags = ~retainFlags;
  1078. final FIFORevQueue q = new FIFORevQueue();
  1079. for (final RevCommit c : roots) {
  1080. if ((c.flags & clearFlags) == 0)
  1081. continue;
  1082. c.flags &= retainFlags;
  1083. c.reset();
  1084. q.add(c);
  1085. }
  1086. for (;;) {
  1087. final RevCommit c = q.next();
  1088. if (c == null)
  1089. break;
  1090. if (c.parents == null)
  1091. continue;
  1092. for (final RevCommit p : c.parents) {
  1093. if ((p.flags & clearFlags) == 0)
  1094. continue;
  1095. p.flags &= retainFlags;
  1096. p.reset();
  1097. q.add(p);
  1098. }
  1099. }
  1100. roots.clear();
  1101. queue = new DateRevQueue();
  1102. pending = new StartGenerator(this);
  1103. }
  1104. /**
  1105. * Dispose all internal state and invalidate all RevObject instances.
  1106. * <p>
  1107. * All RevObject (and thus RevCommit, etc.) instances previously acquired
  1108. * from this RevWalk are invalidated by a dispose call. Applications must
  1109. * not retain or use RevObject instances obtained prior to the dispose call.
  1110. * All RevFlag instances are also invalidated, and must not be reused.
  1111. */
  1112. public void dispose() {
  1113. reader.release();
  1114. freeFlags = APP_FLAGS;
  1115. delayFreeFlags = 0;
  1116. carryFlags = UNINTERESTING;
  1117. objects.clear();
  1118. reader.release();
  1119. roots.clear();
  1120. queue = new DateRevQueue();
  1121. pending = new StartGenerator(this);
  1122. }
  1123. /**
  1124. * Returns an Iterator over the commits of this walker.
  1125. * <p>
  1126. * The returned iterator is only useful for one walk. If this RevWalk gets
  1127. * reset a new iterator must be obtained to walk over the new results.
  1128. * <p>
  1129. * Applications must not use both the Iterator and the {@link #next()} API
  1130. * at the same time. Pick one API and use that for the entire walk.
  1131. * <p>
  1132. * If a checked exception is thrown during the walk (see {@link #next()})
  1133. * it is rethrown from the Iterator as a {@link RevWalkException}.
  1134. *
  1135. * @return an iterator over this walker's commits.
  1136. * @see RevWalkException
  1137. */
  1138. public Iterator<RevCommit> iterator() {
  1139. final RevCommit first;
  1140. try {
  1141. first = RevWalk.this.next();
  1142. } catch (MissingObjectException e) {
  1143. throw new RevWalkException(e);
  1144. } catch (IncorrectObjectTypeException e) {
  1145. throw new RevWalkException(e);
  1146. } catch (IOException e) {
  1147. throw new RevWalkException(e);
  1148. }
  1149. return new Iterator<RevCommit>() {
  1150. RevCommit next = first;
  1151. public boolean hasNext() {
  1152. return next != null;
  1153. }
  1154. public RevCommit next() {
  1155. try {
  1156. final RevCommit r = next;
  1157. next = RevWalk.this.next();
  1158. return r;
  1159. } catch (MissingObjectException e) {
  1160. throw new RevWalkException(e);
  1161. } catch (IncorrectObjectTypeException e) {
  1162. throw new RevWalkException(e);
  1163. } catch (IOException e) {
  1164. throw new RevWalkException(e);
  1165. }
  1166. }
  1167. public void remove() {
  1168. throw new UnsupportedOperationException();
  1169. }
  1170. };
  1171. }
  1172. /** Throws an exception if we have started producing output. */
  1173. protected void assertNotStarted() {
  1174. if (isNotStarted())
  1175. return;
  1176. throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);
  1177. }
  1178. private boolean isNotStarted() {
  1179. return pending instanceof StartGenerator;
  1180. }
  1181. /**
  1182. * Create and return an {@link ObjectWalk} using the same objects.
  1183. * <p>
  1184. * Prior to using this method, the caller must reset this RevWalk to clean
  1185. * any flags that were used during the last traversal.
  1186. * <p>
  1187. * The returned ObjectWalk uses the same ObjectReader, internal object pool,
  1188. * and free RevFlags. Once the ObjectWalk is created, this RevWalk should
  1189. * not be used anymore.
  1190. *
  1191. * @return a new walk, using the exact same object pool.
  1192. */
  1193. public ObjectWalk toObjectWalkWithSameObjects() {
  1194. ObjectWalk ow = new ObjectWalk(reader);
  1195. RevWalk rw = ow;
  1196. rw.objects = objects;
  1197. rw.freeFlags = freeFlags;
  1198. return ow;
  1199. }
  1200. /**
  1201. * Construct a new unparsed commit for the given object.
  1202. *
  1203. * @param id
  1204. * the object this walker requires a commit reference for.
  1205. * @return a new unparsed reference for the object.
  1206. */
  1207. protected RevCommit createCommit(final AnyObjectId id) {
  1208. return new RevCommit(id);
  1209. }
  1210. void carryFlagsImpl(final RevCommit c) {
  1211. final int carry = c.flags & carryFlags;
  1212. if (carry != 0)
  1213. RevCommit.carryFlags(c, carry);
  1214. }
  1215. }