summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-12-03 13:09:01 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-12-03 13:11:39 -0800
commit8fd2335b70d9d395e98f93ef9f845ca59dc2a6dd (patch)
tree7d2718f78bd85bf8aa0de271e4f8a8cb2f6a49a9 /org.eclipse.jgit
parent8d4c95a64511951e98bc4c168a4e306fedc22165 (diff)
downloadjgit-8fd2335b70d9d395e98f93ef9f845ca59dc2a6dd.tar.gz
jgit-8fd2335b70d9d395e98f93ef9f845ca59dc2a6dd.zip
Add debugging toString to TreeFormatter
Displaying the current tree in the ls-tree style output makes it easier to see what entries are currently stored. Change-Id: If17c414db0d2e8d84e65de8bbcba7fd1b79aa311 Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Reviewed-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java
index 6e53cc7403..737a1c3fc1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java
@@ -52,9 +52,11 @@ import static org.eclipse.jgit.lib.FileMode.TREE;
import java.io.IOException;
+import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
+import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.util.TemporaryBuffer;
/**
@@ -311,4 +313,38 @@ public class TreeFormatter {
throw new RuntimeException(err);
}
}
+
+ @Override
+ public String toString() {
+ byte[] raw = toByteArray();
+
+ CanonicalTreeParser p = new CanonicalTreeParser();
+ p.reset(raw);
+
+ StringBuilder r = new StringBuilder();
+ r.append("Tree={");
+ if (!p.eof()) {
+ r.append('\n');
+ try {
+ new ObjectChecker().checkTree(raw);
+ } catch (CorruptObjectException error) {
+ r.append("*** ERROR: ").append(error.getMessage()).append("\n");
+ r.append('\n');
+ }
+ }
+ while (!p.eof()) {
+ final FileMode mode = p.getEntryFileMode();
+ r.append(mode);
+ r.append(' ');
+ r.append(Constants.typeString(mode.getObjectType()));
+ r.append(' ');
+ r.append(p.getEntryObjectId().name());
+ r.append(' ');
+ r.append(p.getEntryPathString());
+ r.append('\n');
+ p.next();
+ }
+ r.append("}");
+ return r.toString();
+ }
}