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 41KB

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