]> source.dussan.org Git - jgit.git/commitdiff
Add debugging toString to TreeFormatter 31/2031/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 3 Dec 2010 21:09:01 +0000 (13:09 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 3 Dec 2010 21:11:39 +0000 (13:11 -0800)
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>
org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java

index 6e53cc7403358a4f50e30767000e0e47816d4324..737a1c3fc11ee49b7395c0e70d7145f9f0dc1a19 100644 (file)
@@ -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();
+       }
 }