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.

RevCommit.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * Copyright (C) 2008-2009, Google Inc.
  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.nio.charset.Charset;
  47. import java.util.ArrayList;
  48. import java.util.Collections;
  49. import java.util.List;
  50. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  51. import org.eclipse.jgit.errors.MissingObjectException;
  52. import org.eclipse.jgit.lib.AnyObjectId;
  53. import org.eclipse.jgit.lib.Constants;
  54. import org.eclipse.jgit.lib.MutableObjectId;
  55. import org.eclipse.jgit.lib.ObjectInserter;
  56. import org.eclipse.jgit.lib.ObjectReader;
  57. import org.eclipse.jgit.lib.PersonIdent;
  58. import org.eclipse.jgit.util.RawParseUtils;
  59. import org.eclipse.jgit.util.StringUtils;
  60. /** A commit reference to a commit in the DAG. */
  61. public class RevCommit extends RevObject {
  62. private static final int STACK_DEPTH = 500;
  63. /**
  64. * Parse a commit from its canonical format.
  65. *
  66. * This method constructs a temporary revision pool, parses the commit as
  67. * supplied, and returns it to the caller. Since the commit was built inside
  68. * of a private revision pool its parent pointers will be initialized, but
  69. * will not have their headers loaded.
  70. *
  71. * Applications are discouraged from using this API. Callers usually need
  72. * more than one commit. Use {@link RevWalk#parseCommit(AnyObjectId)} to
  73. * obtain a RevCommit from an existing repository.
  74. *
  75. * @param raw
  76. * the canonical formatted commit to be parsed.
  77. * @return the parsed commit, in an isolated revision pool that is not
  78. * available to the caller.
  79. */
  80. public static RevCommit parse(byte[] raw) {
  81. try {
  82. return parse(new RevWalk((ObjectReader) null), raw);
  83. } catch (IOException ex) {
  84. throw new RuntimeException(ex);
  85. }
  86. }
  87. /**
  88. * Parse a commit from its canonical format.
  89. * <p>
  90. * This method inserts the commit directly into the caller supplied revision
  91. * pool, making it appear as though the commit exists in the repository,
  92. * even if it doesn't. The repository under the pool is not affected.
  93. * <p>
  94. * The body of the commit (message, author, committer) is always retained in
  95. * the returned {@code RevCommit}, even if the supplied {@code RevWalk} has
  96. * been configured with {@code setRetainBody(false)}.
  97. *
  98. * @param rw
  99. * the revision pool to allocate the commit within. The commit's
  100. * tree and parent pointers will be obtained from this pool.
  101. * @param raw
  102. * the canonical formatted commit to be parsed. This buffer will
  103. * be retained by the returned {@code RevCommit} and must not be
  104. * modified by the caller.
  105. * @return the parsed commit, in an isolated revision pool that is not
  106. * available to the caller.
  107. * @throws IOException
  108. * in case of RevWalk initialization fails
  109. */
  110. public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
  111. try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
  112. RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));
  113. r.parseCanonical(rw, raw);
  114. r.buffer = raw;
  115. return r;
  116. }
  117. }
  118. static final RevCommit[] NO_PARENTS = {};
  119. private RevTree tree;
  120. RevCommit[] parents;
  121. int commitTime; // An int here for performance, overflows in 2038
  122. int inDegree;
  123. private byte[] buffer;
  124. /**
  125. * Create a new commit reference.
  126. *
  127. * @param id
  128. * object name for the commit.
  129. */
  130. protected RevCommit(final AnyObjectId id) {
  131. super(id);
  132. }
  133. @Override
  134. void parseHeaders(final RevWalk walk) throws MissingObjectException,
  135. IncorrectObjectTypeException, IOException {
  136. parseCanonical(walk, walk.getCachedBytes(this));
  137. }
  138. @Override
  139. void parseBody(final RevWalk walk) throws MissingObjectException,
  140. IncorrectObjectTypeException, IOException {
  141. if (buffer == null) {
  142. buffer = walk.getCachedBytes(this);
  143. if ((flags & PARSED) == 0)
  144. parseCanonical(walk, buffer);
  145. }
  146. }
  147. void parseCanonical(final RevWalk walk, final byte[] raw)
  148. throws IOException {
  149. if (!walk.shallowCommitsInitialized)
  150. walk.initializeShallowCommits();
  151. final MutableObjectId idBuffer = walk.idBuffer;
  152. idBuffer.fromString(raw, 5);
  153. tree = walk.lookupTree(idBuffer);
  154. int ptr = 46;
  155. if (parents == null) {
  156. RevCommit[] pList = new RevCommit[1];
  157. int nParents = 0;
  158. for (;;) {
  159. if (raw[ptr] != 'p')
  160. break;
  161. idBuffer.fromString(raw, ptr + 7);
  162. final RevCommit p = walk.lookupCommit(idBuffer);
  163. if (nParents == 0)
  164. pList[nParents++] = p;
  165. else if (nParents == 1) {
  166. pList = new RevCommit[] { pList[0], p };
  167. nParents = 2;
  168. } else {
  169. if (pList.length <= nParents) {
  170. RevCommit[] old = pList;
  171. pList = new RevCommit[pList.length + 32];
  172. System.arraycopy(old, 0, pList, 0, nParents);
  173. }
  174. pList[nParents++] = p;
  175. }
  176. ptr += 48;
  177. }
  178. if (nParents != pList.length) {
  179. RevCommit[] old = pList;
  180. pList = new RevCommit[nParents];
  181. System.arraycopy(old, 0, pList, 0, nParents);
  182. }
  183. parents = pList;
  184. }
  185. // extract time from "committer "
  186. ptr = RawParseUtils.committer(raw, ptr);
  187. if (ptr > 0) {
  188. ptr = RawParseUtils.nextLF(raw, ptr, '>');
  189. // In 2038 commitTime will overflow unless it is changed to long.
  190. commitTime = RawParseUtils.parseBase10(raw, ptr, null);
  191. }
  192. if (walk.isRetainBody())
  193. buffer = raw;
  194. flags |= PARSED;
  195. }
  196. @Override
  197. public final int getType() {
  198. return Constants.OBJ_COMMIT;
  199. }
  200. static void carryFlags(RevCommit c, int carry) {
  201. FIFORevQueue q = carryFlags1(c, carry, 0);
  202. if (q != null)
  203. slowCarryFlags(q, carry);
  204. }
  205. private static FIFORevQueue carryFlags1(RevCommit c, int carry, int depth) {
  206. for(;;) {
  207. RevCommit[] pList = c.parents;
  208. if (pList == null || pList.length == 0)
  209. return null;
  210. if (pList.length != 1) {
  211. if (depth == STACK_DEPTH)
  212. return defer(c);
  213. for (int i = 1; i < pList.length; i++) {
  214. RevCommit p = pList[i];
  215. if ((p.flags & carry) == carry)
  216. continue;
  217. p.flags |= carry;
  218. FIFORevQueue q = carryFlags1(c, carry, depth + 1);
  219. if (q != null)
  220. return defer(q, carry, pList, i + 1);
  221. }
  222. }
  223. c = pList[0];
  224. if ((c.flags & carry) == carry)
  225. return null;
  226. c.flags |= carry;
  227. }
  228. }
  229. private static FIFORevQueue defer(RevCommit c) {
  230. FIFORevQueue q = new FIFORevQueue();
  231. q.add(c);
  232. return q;
  233. }
  234. private static FIFORevQueue defer(FIFORevQueue q, int carry,
  235. RevCommit[] pList, int i) {
  236. // In normal case the caller will run pList[0] in a tail recursive
  237. // fashion by updating the variable. However the caller is unwinding
  238. // the stack and will skip that pList[0] execution step.
  239. carryOneStep(q, carry, pList[0]);
  240. // Remaining parents (if any) need to have flags checked and be
  241. // enqueued if they have ancestors.
  242. for (; i < pList.length; i++)
  243. carryOneStep(q, carry, pList[i]);
  244. return q;
  245. }
  246. private static void slowCarryFlags(FIFORevQueue q, int carry) {
  247. // Commits in q have non-null parent arrays and have set all
  248. // flags in carry. This loop finishes copying over the graph.
  249. for (RevCommit c; (c = q.next()) != null;) {
  250. for (RevCommit p : c.parents)
  251. carryOneStep(q, carry, p);
  252. }
  253. }
  254. private static void carryOneStep(FIFORevQueue q, int carry, RevCommit c) {
  255. if ((c.flags & carry) != carry) {
  256. c.flags |= carry;
  257. if (c.parents != null)
  258. q.add(c);
  259. }
  260. }
  261. /**
  262. * Carry a RevFlag set on this commit to its parents.
  263. * <p>
  264. * If this commit is parsed, has parents, and has the supplied flag set on
  265. * it we automatically add it to the parents, grand-parents, and so on until
  266. * an unparsed commit or a commit with no parents is discovered. This
  267. * permits applications to force a flag through the history chain when
  268. * necessary.
  269. *
  270. * @param flag
  271. * the single flag value to carry back onto parents.
  272. */
  273. public void carry(final RevFlag flag) {
  274. final int carry = flags & flag.mask;
  275. if (carry != 0)
  276. carryFlags(this, carry);
  277. }
  278. /**
  279. * Time from the "committer " line of the buffer.
  280. *
  281. * @return time, expressed as seconds since the epoch.
  282. */
  283. public final int getCommitTime() {
  284. return commitTime;
  285. }
  286. /**
  287. * Get a reference to this commit's tree.
  288. *
  289. * @return tree of this commit.
  290. */
  291. public final RevTree getTree() {
  292. return tree;
  293. }
  294. /**
  295. * Get the number of parent commits listed in this commit.
  296. *
  297. * @return number of parents; always a positive value but can be 0.
  298. */
  299. public final int getParentCount() {
  300. return parents.length;
  301. }
  302. /**
  303. * Get the nth parent from this commit's parent list.
  304. *
  305. * @param nth
  306. * parent index to obtain. Must be in the range 0 through
  307. * {@link #getParentCount()}-1.
  308. * @return the specified parent.
  309. * @throws ArrayIndexOutOfBoundsException
  310. * an invalid parent index was specified.
  311. */
  312. public final RevCommit getParent(final int nth) {
  313. return parents[nth];
  314. }
  315. /**
  316. * Obtain an array of all parents (<b>NOTE - THIS IS NOT A COPY</b>).
  317. * <p>
  318. * This method is exposed only to provide very fast, efficient access to
  319. * this commit's parent list. Applications relying on this list should be
  320. * very careful to ensure they do not modify its contents during their use
  321. * of it.
  322. *
  323. * @return the array of parents.
  324. */
  325. public final RevCommit[] getParents() {
  326. return parents;
  327. }
  328. /**
  329. * Obtain the raw unparsed commit body (<b>NOTE - THIS IS NOT A COPY</b>).
  330. * <p>
  331. * This method is exposed only to provide very fast, efficient access to
  332. * this commit's message buffer within a RevFilter. Applications relying on
  333. * this buffer should be very careful to ensure they do not modify its
  334. * contents during their use of it.
  335. *
  336. * @return the raw unparsed commit body. This is <b>NOT A COPY</b>.
  337. * Altering the contents of this buffer may alter the walker's
  338. * knowledge of this commit, and the results it produces.
  339. */
  340. public final byte[] getRawBuffer() {
  341. return buffer;
  342. }
  343. /**
  344. * Parse the author identity from the raw buffer.
  345. * <p>
  346. * This method parses and returns the content of the author line, after
  347. * taking the commit's character set into account and decoding the author
  348. * name and email address. This method is fairly expensive and produces a
  349. * new PersonIdent instance on each invocation. Callers should invoke this
  350. * method only if they are certain they will be outputting the result, and
  351. * should cache the return value for as long as necessary to use all
  352. * information from it.
  353. * <p>
  354. * RevFilter implementations should try to use {@link RawParseUtils} to scan
  355. * the {@link #getRawBuffer()} instead, as this will allow faster evaluation
  356. * of commits.
  357. *
  358. * @return identity of the author (name, email) and the time the commit was
  359. * made by the author; null if no author line was found.
  360. */
  361. public final PersonIdent getAuthorIdent() {
  362. final byte[] raw = buffer;
  363. final int nameB = RawParseUtils.author(raw, 0);
  364. if (nameB < 0)
  365. return null;
  366. return RawParseUtils.parsePersonIdent(raw, nameB);
  367. }
  368. /**
  369. * Parse the committer identity from the raw buffer.
  370. * <p>
  371. * This method parses and returns the content of the committer line, after
  372. * taking the commit's character set into account and decoding the committer
  373. * name and email address. This method is fairly expensive and produces a
  374. * new PersonIdent instance on each invocation. Callers should invoke this
  375. * method only if they are certain they will be outputting the result, and
  376. * should cache the return value for as long as necessary to use all
  377. * information from it.
  378. * <p>
  379. * RevFilter implementations should try to use {@link RawParseUtils} to scan
  380. * the {@link #getRawBuffer()} instead, as this will allow faster evaluation
  381. * of commits.
  382. *
  383. * @return identity of the committer (name, email) and the time the commit
  384. * was made by the committer; null if no committer line was found.
  385. */
  386. public final PersonIdent getCommitterIdent() {
  387. final byte[] raw = buffer;
  388. final int nameB = RawParseUtils.committer(raw, 0);
  389. if (nameB < 0)
  390. return null;
  391. return RawParseUtils.parsePersonIdent(raw, nameB);
  392. }
  393. /**
  394. * Parse the complete commit message and decode it to a string.
  395. * <p>
  396. * This method parses and returns the message portion of the commit buffer,
  397. * after taking the commit's character set into account and decoding the
  398. * buffer using that character set. This method is a fairly expensive
  399. * operation and produces a new string on each invocation.
  400. *
  401. * @return decoded commit message as a string. Never null.
  402. */
  403. public final String getFullMessage() {
  404. final byte[] raw = buffer;
  405. final int msgB = RawParseUtils.commitMessage(raw, 0);
  406. if (msgB < 0)
  407. return ""; //$NON-NLS-1$
  408. final Charset enc = RawParseUtils.parseEncoding(raw);
  409. return RawParseUtils.decode(enc, raw, msgB, raw.length);
  410. }
  411. /**
  412. * Parse the commit message and return the first "line" of it.
  413. * <p>
  414. * The first line is everything up to the first pair of LFs. This is the
  415. * "oneline" format, suitable for output in a single line display.
  416. * <p>
  417. * This method parses and returns the message portion of the commit buffer,
  418. * after taking the commit's character set into account and decoding the
  419. * buffer using that character set. This method is a fairly expensive
  420. * operation and produces a new string on each invocation.
  421. *
  422. * @return decoded commit message as a string. Never null. The returned
  423. * string does not contain any LFs, even if the first paragraph
  424. * spanned multiple lines. Embedded LFs are converted to spaces.
  425. */
  426. public final String getShortMessage() {
  427. final byte[] raw = buffer;
  428. final int msgB = RawParseUtils.commitMessage(raw, 0);
  429. if (msgB < 0)
  430. return ""; //$NON-NLS-1$
  431. final Charset enc = RawParseUtils.parseEncoding(raw);
  432. final int msgE = RawParseUtils.endOfParagraph(raw, msgB);
  433. String str = RawParseUtils.decode(enc, raw, msgB, msgE);
  434. if (hasLF(raw, msgB, msgE))
  435. str = StringUtils.replaceLineBreaksWithSpace(str);
  436. return str;
  437. }
  438. static boolean hasLF(final byte[] r, int b, final int e) {
  439. while (b < e)
  440. if (r[b++] == '\n')
  441. return true;
  442. return false;
  443. }
  444. /**
  445. * Determine the encoding of the commit message buffer.
  446. * <p>
  447. * Locates the "encoding" header (if present) and then returns the proper
  448. * character set to apply to this buffer to evaluate its contents as
  449. * character data.
  450. * <p>
  451. * If no encoding header is present, {@link Constants#CHARSET} is assumed.
  452. *
  453. * @return the preferred encoding of {@link #getRawBuffer()}.
  454. */
  455. public final Charset getEncoding() {
  456. return RawParseUtils.parseEncoding(buffer);
  457. }
  458. /**
  459. * Parse the footer lines (e.g. "Signed-off-by") for machine processing.
  460. * <p>
  461. * This method splits all of the footer lines out of the last paragraph of
  462. * the commit message, providing each line as a key-value pair, ordered by
  463. * the order of the line's appearance in the commit message itself.
  464. * <p>
  465. * A footer line's key must match the pattern {@code ^[A-Za-z0-9-]+:}, while
  466. * the value is free-form, but must not contain an LF. Very common keys seen
  467. * in the wild are:
  468. * <ul>
  469. * <li>{@code Signed-off-by} (agrees to Developer Certificate of Origin)
  470. * <li>{@code Acked-by} (thinks change looks sane in context)
  471. * <li>{@code Reported-by} (originally found the issue this change fixes)
  472. * <li>{@code Tested-by} (validated change fixes the issue for them)
  473. * <li>{@code CC}, {@code Cc} (copy on all email related to this change)
  474. * <li>{@code Bug} (link to project's bug tracking system)
  475. * </ul>
  476. *
  477. * @return ordered list of footer lines; empty list if no footers found.
  478. */
  479. public final List<FooterLine> getFooterLines() {
  480. final byte[] raw = buffer;
  481. int ptr = raw.length - 1;
  482. while (raw[ptr] == '\n') // trim any trailing LFs, not interesting
  483. ptr--;
  484. final int msgB = RawParseUtils.commitMessage(raw, 0);
  485. final ArrayList<FooterLine> r = new ArrayList<FooterLine>(4);
  486. final Charset enc = getEncoding();
  487. for (;;) {
  488. ptr = RawParseUtils.prevLF(raw, ptr);
  489. if (ptr <= msgB)
  490. break; // Don't parse commit headers as footer lines.
  491. final int keyStart = ptr + 2;
  492. if (raw[keyStart] == '\n')
  493. break; // Stop at first paragraph break, no footers above it.
  494. final int keyEnd = RawParseUtils.endOfFooterLineKey(raw, keyStart);
  495. if (keyEnd < 0)
  496. continue; // Not a well formed footer line, skip it.
  497. // Skip over the ': *' at the end of the key before the value.
  498. //
  499. int valStart = keyEnd + 1;
  500. while (valStart < raw.length && raw[valStart] == ' ')
  501. valStart++;
  502. // Value ends at the LF, and does not include it.
  503. //
  504. int valEnd = RawParseUtils.nextLF(raw, valStart);
  505. if (raw[valEnd - 1] == '\n')
  506. valEnd--;
  507. r.add(new FooterLine(raw, enc, keyStart, keyEnd, valStart, valEnd));
  508. }
  509. Collections.reverse(r);
  510. return r;
  511. }
  512. /**
  513. * Get the values of all footer lines with the given key.
  514. *
  515. * @param keyName
  516. * footer key to find values of, case insensitive.
  517. * @return values of footers with key of {@code keyName}, ordered by their
  518. * order of appearance. Duplicates may be returned if the same
  519. * footer appeared more than once. Empty list if no footers appear
  520. * with the specified key, or there are no footers at all.
  521. * @see #getFooterLines()
  522. */
  523. public final List<String> getFooterLines(final String keyName) {
  524. return getFooterLines(new FooterKey(keyName));
  525. }
  526. /**
  527. * Get the values of all footer lines with the given key.
  528. *
  529. * @param keyName
  530. * footer key to find values of, case insensitive.
  531. * @return values of footers with key of {@code keyName}, ordered by their
  532. * order of appearance. Duplicates may be returned if the same
  533. * footer appeared more than once. Empty list if no footers appear
  534. * with the specified key, or there are no footers at all.
  535. * @see #getFooterLines()
  536. */
  537. public final List<String> getFooterLines(final FooterKey keyName) {
  538. final List<FooterLine> src = getFooterLines();
  539. if (src.isEmpty())
  540. return Collections.emptyList();
  541. final ArrayList<String> r = new ArrayList<String>(src.size());
  542. for (final FooterLine f : src) {
  543. if (f.matches(keyName))
  544. r.add(f.getValue());
  545. }
  546. return r;
  547. }
  548. /**
  549. * Reset this commit to allow another RevWalk with the same instances.
  550. * <p>
  551. * Subclasses <b>must</b> call <code>super.reset()</code> to ensure the
  552. * basic information can be correctly cleared out.
  553. */
  554. public void reset() {
  555. inDegree = 0;
  556. }
  557. /**
  558. * Discard the message buffer to reduce memory usage.
  559. * <p>
  560. * After discarding the memory usage of the {@code RevCommit} is reduced to
  561. * only the {@link #getTree()} and {@link #getParents()} pointers and the
  562. * time in {@link #getCommitTime()}. Accessing other properties such as
  563. * {@link #getAuthorIdent()}, {@link #getCommitterIdent()} or either message
  564. * function requires reloading the buffer by invoking
  565. * {@link RevWalk#parseBody(RevObject)}.
  566. *
  567. * @since 4.0
  568. */
  569. public final void disposeBody() {
  570. buffer = null;
  571. }
  572. @Override
  573. public String toString() {
  574. final StringBuilder s = new StringBuilder();
  575. s.append(Constants.typeString(getType()));
  576. s.append(' ');
  577. s.append(name());
  578. s.append(' ');
  579. s.append(commitTime);
  580. s.append(' ');
  581. appendCoreFlags(s);
  582. return s.toString();
  583. }
  584. }