summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2015-05-09 10:47:13 -0700
committerShawn Pearce <spearce@spearce.org>2015-05-10 10:45:34 -0700
commit53e39094bf012a4f5b3fe5557219707cb7b0f010 (patch)
treea1f7352fad14868f6b37bf29a2ccc3a2535610d8
parent3d06349ff21e157fc837ef09e48a5e400afb4e6a (diff)
downloadjgit-53e39094bf012a4f5b3fe5557219707cb7b0f010.tar.gz
jgit-53e39094bf012a4f5b3fe5557219707cb7b0f010.zip
ObjectWalk: make setRetainBody(false) the default
Despite being the primary author of RevWalk and ObjectWalk I still fail to remember to setRetainBody(false) in application code using an ObjectWalk to examine the graph. Document the default for RevWalk is setRetainBody(true), where the application usually wants the commit bodies to display or inspect. Change the default for ObjectWalk to setRetainBody(false), as nearly all callers want only the graph shape and do not need the larger text inside a commit body. This allows some code in JGit to be simplified. Change-Id: I367e42209e805bd5e1f41b4072aeb2fa98ec9d99
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java23
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java23
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java1
10 files changed, 44 insertions, 36 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
index 0ad3b77427..fbd5127116 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
@@ -360,10 +360,10 @@ public class FooterLineTest extends RepositoryTestCase {
buf.append("\n");
buf.append(msg);
- final RevWalk walk = new RevWalk(db);
- walk.setRetainBody(true);
- final RevCommit c = new RevCommit(ObjectId.zeroId());
- c.parseCanonical(walk, Constants.encode(buf.toString()));
- return c;
+ try (RevWalk walk = new RevWalk(db)) {
+ RevCommit c = new RevCommit(ObjectId.zeroId());
+ c.parseCanonical(walk, Constants.encode(buf.toString()));
+ return c;
+ }
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
index af35f772ce..f4d443d725 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
@@ -188,7 +188,6 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
private RevCommit parseCommit(final ObjectReader reader,
final ObjectId headId) throws IOException {
final RevWalk walk = new RevWalk(reader);
- walk.setRetainBody(true);
return walk.parseCommit(headId);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java
index bbbb7ace3d..59a83aae3f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java
@@ -96,10 +96,8 @@ public class StashListCommand extends GitCommand<Collection<RevCommit>> {
final List<RevCommit> stashCommits = new ArrayList<RevCommit>(
stashEntries.size());
- final RevWalk walk = new RevWalk(repo);
- walk.setRetainBody(true);
- try {
- for (ReflogEntry entry : stashEntries)
+ try (RevWalk walk = new RevWalk(repo)) {
+ for (ReflogEntry entry : stashEntries) {
try {
stashCommits.add(walk.parseCommit(entry.getNewId()));
} catch (IOException e) {
@@ -107,8 +105,7 @@ public class StashListCommand extends GitCommand<Collection<RevCommit>> {
JGitText.get().cannotReadCommit, entry.getNewId()),
e);
}
- } finally {
- walk.dispose();
+ }
}
return stashCommits;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
index eb64425c6c..ae713e2e96 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
@@ -179,7 +179,6 @@ public class BlameGenerator implements AutoCloseable {
else
revPool = new RevWalk(getRepository());
- revPool.setRetainBody(true);
SEEN = revPool.newFlag("SEEN"); //$NON-NLS-1$
reader = revPool.getObjectReader();
treeWalk = new TreeWalk(reader);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index 1422c5ef04..b30315af71 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
@@ -1587,8 +1587,6 @@ public class PackWriter implements AutoCloseable {
stats.interestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(want));
stats.uninterestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(have));
- walker.setRetainBody(false);
-
canBuildBitmaps = config.isBuildBitmaps()
&& !shallowPack
&& have.isEmpty()
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java
index a0af067dc0..27cb0474a3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java
@@ -133,6 +133,7 @@ public class ObjectWalk extends RevWalk {
*/
public ObjectWalk(ObjectReader or) {
super(or);
+ setRetainBody(false);
rootObjects = new ArrayList<RevObject>();
pendingObjects = new BlockObjQueue();
pathBuf = new byte[256];
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 fac4f809f2..37f1d7b8da 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
@@ -92,29 +92,34 @@ public class RevCommit extends RevObject {
/**
* Parse a commit from its canonical format.
- *
+ * <p>
* This method inserts the commit directly into the caller supplied revision
* pool, making it appear as though the commit exists in the repository,
* even if it doesn't. The repository under the pool is not affected.
+ * <p>
+ * The body of the commit (message, author, committer) is always retained in
+ * the returned {@code RevCommit}, even if the supplied {@code RevWalk} has
+ * been configured with {@code setRetainBody(false)}.
*
* @param rw
* the revision pool to allocate the commit within. The commit's
* tree and parent pointers will be obtained from this pool.
* @param raw
- * the canonical formatted commit to be parsed.
+ * the canonical formatted commit to be parsed. This buffer will
+ * be retained by the returned {@code RevCommit} and must not be
+ * modified by the caller.
* @return the parsed commit, in an isolated revision pool that is not
* available to the caller.
* @throws IOException
* in case of RevWalk initialization fails
*/
public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
- ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
- boolean retain = rw.isRetainBody();
- rw.setRetainBody(true);
- RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));
- r.parseCanonical(rw, raw);
- rw.setRetainBody(retain);
- return r;
+ try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
+ RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));
+ r.parseCanonical(rw, raw);
+ r.buffer = raw;
+ return r;
+ }
}
static final RevCommit[] NO_PARENTS = {};
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 1a59b440c3..75201164c1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java
@@ -87,16 +87,22 @@ public class RevTag extends RevObject {
/**
* Parse an annotated tag from its canonical format.
- *
+ * <p>
* This method inserts the tag directly into the caller supplied revision
* pool, making it appear as though the tag exists in the repository, even
* if it doesn't. The repository under the pool is not affected.
+ * <p>
+ * The body of the tag (message, tagger, signature) is always retained in
+ * the returned {@code RevTag}, even if the supplied {@code RevWalk} has
+ * been configured with {@code setRetainBody(false)}.
*
* @param rw
* the revision pool to allocate the tag within. The tag's object
* pointer will be obtained from this pool.
* @param raw
- * the canonical formatted tag to be parsed.
+ * the canonical formatted tag to be parsed. This buffer will be
+ * retained by the returned {@code RevTag} and must not be
+ * modified by the caller.
* @return the parsed tag, in an isolated revision pool that is not
* available to the caller.
* @throws CorruptObjectException
@@ -104,13 +110,12 @@ public class RevTag extends RevObject {
*/
public static RevTag parse(RevWalk rw, byte[] raw)
throws CorruptObjectException {
- ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
- boolean retain = rw.isRetainBody();
- rw.setRetainBody(true);
- RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
- r.parseCanonical(rw, raw);
- rw.setRetainBody(retain);
- return r;
+ try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
+ RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
+ r.parseCanonical(rw, raw);
+ r.buffer = raw;
+ return r;
+ }
}
private RevObject object;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 4ce422ca92..d1009abae9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -192,7 +192,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
private TreeFilter treeFilter;
- private boolean retainBody;
+ private boolean retainBody = true;
private boolean rewriteParents = true;
@@ -233,7 +233,6 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
sorting = EnumSet.of(RevSort.NONE);
filter = RevFilter.ALL;
treeFilter = TreeFilter.ALL;
- retainBody = true;
this.closeReader = closeReader;
}
@@ -607,6 +606,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
* Usually the body is always retained, but some application code might not
* care and would prefer to discard the body of a commit as early as
* possible, to reduce memory usage.
+ * <p>
+ * True by default on {@link RevWalk} and false by default for
+ * {@link ObjectWalk}.
*
* @return true if the body should be retained; false it is discarded.
*/
@@ -620,6 +622,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
* If a body of a commit or tag is not retained, the application must
* call {@link #parseBody(RevObject)} before the body can be safely
* accessed through the type specific access methods.
+ * <p>
+ * True by default on {@link RevWalk} and false by default for
+ * {@link ObjectWalk}.
*
* @param retain true to retain bodies; false to discard them early.
*/
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
index 36ea647c0c..a18df0dd0a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
@@ -1143,7 +1143,6 @@ public abstract class BaseReceivePack {
parser = null;
try (final ObjectWalk ow = new ObjectWalk(db)) {
- ow.setRetainBody(false);
if (baseObjects != null) {
ow.sort(RevSort.TOPO);
if (!baseObjects.isEmpty())