aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/api
diff options
context:
space:
mode:
authorKevin Sawicki <kevin@github.com>2012-05-10 00:19:04 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2012-05-10 00:19:04 +0200
commit6ebc477c0b6a209ec9bd1a8bcce796d04ca66966 (patch)
treeb2edc4fc3c525eaa126300567688bd4d60025a22 /org.eclipse.jgit/src/org/eclipse/jgit/api
parentc403d0b1873c96782eb0dbe02a14c34b82f7fce3 (diff)
downloadjgit-6ebc477c0b6a209ec9bd1a8bcce796d04ca66966.tar.gz
jgit-6ebc477c0b6a209ec9bd1a8bcce796d04ca66966.zip
Make output stream optional in DiffCommand
Use the NullOutputStream.INSTANCE value when the configured output stream is null or the command is configured to only show name and status. Also only set the context and prefix options if formatting is actually being performed. Bug: 377157 Change-Id: I333cfcc82ee746f3c6a8e94c09dcc803ffbb4b3a Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/api')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java24
1 files changed, 14 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java
index 3a50c7a631..e82b0486a6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java
@@ -64,6 +64,7 @@ import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.eclipse.jgit.util.io.NullOutputStream;
/**
* Show changes between commits, commit and working tree, etc.
@@ -108,8 +109,11 @@ public class DiffCommand extends GitCommand<List<DiffEntry>> {
* @return a DiffEntry for each path which is different
*/
public List<DiffEntry> call() throws GitAPIException, IOException {
- final DiffFormatter diffFmt = new DiffFormatter(
- new BufferedOutputStream(out));
+ final DiffFormatter diffFmt;
+ if (out != null && !showNameAndStatusOnly)
+ diffFmt = new DiffFormatter(new BufferedOutputStream(out));
+ else
+ diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
diffFmt.setRepository(repo);
diffFmt.setProgressMonitor(monitor);
try {
@@ -136,17 +140,17 @@ public class DiffCommand extends GitCommand<List<DiffEntry>> {
}
diffFmt.setPathFilter(pathFilter);
- if (contextLines >= 0)
- diffFmt.setContext(contextLines);
- if (destinationPrefix != null)
- diffFmt.setNewPrefix(destinationPrefix);
- if (sourcePrefix != null)
- diffFmt.setOldPrefix(sourcePrefix);
List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
- if (showNameAndStatusOnly) {
+ if (showNameAndStatusOnly)
return result;
- } else {
+ else {
+ if (contextLines >= 0)
+ diffFmt.setContext(contextLines);
+ if (destinationPrefix != null)
+ diffFmt.setNewPrefix(destinationPrefix);
+ if (sourcePrefix != null)
+ diffFmt.setOldPrefix(sourcePrefix);
diffFmt.format(result);
diffFmt.flush();
return result;