From e4e947049f60d72f766d90dff22b488cbe06ba95 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Sun, 10 May 2015 10:42:09 -0700 Subject: Expose disposeBody() on RevCommit and RevTag Applications that use a commit message once and do not need it again can free the body to save memory. Expose the disposeBody() methods to support this and use it in pgm.Log which only visits each commit once. Change-Id: I4142a0749c24f15386ee7fb119934a0432234de3 --- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java | 1 + .../src/org/eclipse/jgit/revwalk/RevCommit.java | 14 +++++++++++++- org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java | 13 ++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index 048526ee8a..688de2c499 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -267,6 +267,7 @@ class Log extends RevWalkTextBuiltin { outw.print(s); outw.println(); } + c.disposeBody(); outw.println(); if (showNotes(c)) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java index 37f1d7b8da..c23e4e3288 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java @@ -609,7 +609,19 @@ public class RevCommit extends RevObject { inDegree = 0; } - final void disposeBody() { + /** + * Discard the message buffer to reduce memory usage. + *

+ * After discarding the memory usage of the {@code RevCommit} is reduced to + * only the {@link #getTree()} and {@link #getParents()} pointers and the + * time in {@link #getCommitTime()}. Accessing other properties such as + * {@link #getAuthorIdent()}, {@link #getCommitterIdent()} or either message + * function requires reloading the buffer by invoking + * {@link RevWalk#parseBody(RevObject)}. + * + * @since 4.0 + */ + public final void disposeBody() { buffer = null; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java index 75201164c1..bf2785e0d7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java @@ -270,7 +270,18 @@ public class RevTag extends RevObject { return tagName; } - final void disposeBody() { + /** + * Discard the message buffer to reduce memory usage. + *

+ * After discarding the memory usage of the {@code RevTag} is reduced to + * only the {@link #getObject()} pointer and {@link #getTagName()}. + * Accessing other properties such as {@link #getTaggerIdent()} or either + * message function requires reloading the buffer by invoking + * {@link RevWalk#parseBody(RevObject)}. + * + * @since 4.0 + */ + public final void disposeBody() { buffer = null; } } -- cgit v1.2.3