summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJonathan Nieder2012-11-14 15:14:20 (EST)
committer Jonathan Nieder2012-11-14 15:14:20 (EST)
commitdfb8bd694c028abd51eae7d56731ac7ef28dfe49 (patch)
treed353e7ff820af720095cb72464b3cca2f15e8f55
parent106e8b87625cd1ad6b2cec14d676c23174422352 (diff)
downloadjgit-dfb8bd694c028abd51eae7d56731ac7ef28dfe49.zip
jgit-dfb8bd694c028abd51eae7d56731ac7ef28dfe49.tar.gz
jgit-dfb8bd694c028abd51eae7d56731ac7ef28dfe49.tar.bz2
diff, log -p: do not use outs before it is initializedrefs/changes/96/8696/1
Since commit caa362f20df1 (Check for write errors in standard out and exit with error, 2012-09-14), running "jgit diff" results in a NullPointerException: | $ jgit diff | java.lang.NullPointerException | at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) | at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) | at org.eclipse.jgit.diff.DiffFormatter.format(DiffFormatter.java:688) | at org.eclipse.jgit.diff.DiffFormatter.format(DiffFormatter.java:630) | at org.eclipse.jgit.diff.DiffFormatter.format(DiffFormatter.java:616) | at org.eclipse.jgit.diff.DiffFormatter.format(DiffFormatter.java:600) | at org.eclipse.jgit.pgm.Diff.run(Diff.java:211) | at org.eclipse.jgit.pgm.TextBuiltin.execute(TextBuiltin.java:166) | at org.eclipse.jgit.pgm.Main.execute(Main.java:200) | at org.eclipse.jgit.pgm.Main.run(Main.java:120) | at org.eclipse.jgit.pgm.Main.main(Main.java:94) That patch replaced most uses of System.out with a wrapper, with changes like the following: class Diff extends TextBuiltin { private final DiffFormatter diffFmt = new DiffFormatter( // - new BufferedOutputStream(System.out)); + new BufferedOutputStream(outs)); outs is not set for TextBuiltin objects until init() has been run. Moving the initialization to after the super.init() call gets "jgit diff" and "jgit log -p" working well again. Change-Id: I80fcf259c4fb733990bd16e52bcf94e66d820826
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java10
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java10
2 files changed, 16 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java
index 0085888..465df38 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java
@@ -64,6 +64,7 @@ import org.eclipse.jgit.diff.RenameDetector;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
@@ -76,8 +77,7 @@ import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_ShowDiffs")
class Diff extends TextBuiltin {
- private final DiffFormatter diffFmt = new DiffFormatter( //
- new BufferedOutputStream(outs));
+ private DiffFormatter diffFmt;
@Argument(index = 0, metaVar = "metaVar_treeish")
private AbstractTreeIterator oldTree;
@@ -168,6 +168,12 @@ class Diff extends TextBuiltin {
// END -- Options shared with Log
@Override
+ protected void init(final Repository repository, final String gitDir) {
+ super.init(repository, gitDir);
+ diffFmt = new DiffFormatter(new BufferedOutputStream(outs));
+ }
+
+ @Override
protected void run() throws Exception {
diffFmt.setRepository(db);
try {
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 987021e..6ad27ae 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
@@ -66,6 +66,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.notes.NoteMap;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
@@ -79,8 +80,7 @@ class Log extends RevWalkTextBuiltin {
private GitDateFormatter dateFormatter = new GitDateFormatter(
Format.DEFAULT);
- private final DiffFormatter diffFmt = new DiffFormatter( //
- new BufferedOutputStream(outs));
+ private DiffFormatter diffFmt;
private Map<AnyObjectId, Set<Ref>> allRefsByPeeledObjectId;
@@ -183,6 +183,12 @@ class Log extends RevWalkTextBuiltin {
}
@Override
+ protected void init(final Repository repository, final String gitDir) {
+ super.init(repository, gitDir);
+ diffFmt = new DiffFormatter(new BufferedOutputStream(outs));
+ }
+
+ @Override
protected void run() throws Exception {
diffFmt.setRepository(db);
try {