summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorJeff Schumacher <jeffschu@google.com>2010-06-28 13:03:44 -0700
committerJeff Schumacher <jeffschu@google.com>2010-06-28 17:25:19 -0700
commit9869ef2592b1fea3a75ae17a67d55025382fdb82 (patch)
tree64d9e6e427db4e583da77bf3ae2c5b4f10209d75 /org.eclipse.jgit.pgm
parent543235b805d73b30f778255415ff2ec0d64b4334 (diff)
downloadjgit-9869ef2592b1fea3a75ae17a67d55025382fdb82.tar.gz
jgit-9869ef2592b1fea3a75ae17a67d55025382fdb82.zip
Added further support for whitespace ignoring during diff
Added code to support ignoring leading, trailing, and changed whitespace when performing a diff operation. I also added command line options to Diff to enable the various whitespace ignoring methods. These match the flags for git diff. Change-Id: Ie56301aafad59ee3f0fe5de62719f5023cd702c8
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java30
1 files changed, 28 insertions, 2 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 a5db453688..931c46d333 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
@@ -56,6 +56,10 @@ import org.kohsuke.args4j.Option;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.MyersDiff;
import org.eclipse.jgit.diff.RawText;
+import org.eclipse.jgit.diff.RawTextIgnoreAllWhitespace;
+import org.eclipse.jgit.diff.RawTextIgnoreLeadingWhitespace;
+import org.eclipse.jgit.diff.RawTextIgnoreTrailingWhitespace;
+import org.eclipse.jgit.diff.RawTextIgnoreWhitespaceChange;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
@@ -77,6 +81,18 @@ class Diff extends TextBuiltin {
@Option(name = "--", metaVar = "metaVar_port", multiValued = true, handler = PathTreeFilterHandler.class)
private TreeFilter pathFilter = TreeFilter.ALL;
+ @Option(name = "--ignore-space-at-eol")
+ private boolean ignoreWsTrailing;
+
+ @Option(name = "--ignore-leading-space")
+ private boolean ignoreWsLeading;
+
+ @Option(name = "-b", aliases = { "--ignore-space-change" })
+ private boolean ignoreWsChange;
+
+ @Option(name = "-w", aliases = { "--ignore-all-space" })
+ private boolean ignoreWsAll;
+
private DiffFormatter fmt = new DiffFormatter();
@Override
@@ -124,8 +140,18 @@ class Diff extends TextBuiltin {
private RawText getRawText(ObjectId id) throws IOException {
if (id.equals(ObjectId.zeroId()))
- return new RawText(new byte[] { });
- return new RawText(db.openBlob(id).getCachedBytes());
+ return new RawText(new byte[] {});
+ byte[] raw = db.openBlob(id).getCachedBytes();
+ if (ignoreWsAll)
+ return new RawTextIgnoreAllWhitespace(raw);
+ else if (ignoreWsTrailing)
+ return new RawTextIgnoreTrailingWhitespace(raw);
+ else if (ignoreWsChange)
+ return new RawTextIgnoreWhitespaceChange(raw);
+ else if (ignoreWsLeading)
+ return new RawTextIgnoreLeadingWhitespace(raw);
+ else
+ return new RawText(raw);
}
}