aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-07-03 17:32:47 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-07-03 17:32:47 -0700
commit8a0c58394db1bdea64737ed683d6c32639e567d9 (patch)
tree2107eb2f5a5685eb687c6ccdfefd68e8c92b1c03 /org.eclipse.jgit.pgm
parentbd8740dc1440e5b2aca1464404182105b2dc1853 (diff)
downloadjgit-8a0c58394db1bdea64737ed683d6c32639e567d9.tar.gz
jgit-8a0c58394db1bdea64737ed683d6c32639e567d9.zip
log: Add whitespace ignore options
Similar to what we did with diff, implement whitespace ignore options for log too. This requires us to define some means of creating any RawText object type at will inside of DiffFormatter, so we define a new factory interface to construct RawText instances on demand. Unfortunately we have to copy the entire block of common options. args4j only processes the options/arguments on the one command class and Java doesn't support multiple inheritance. Change-Id: Ia16cd3a11b850fffae9fbe7b721d7e43f1d0e8a5 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java65
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java54
3 files changed, 91 insertions, 30 deletions
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
index 67357be1da..e879d6b605 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
@@ -68,6 +68,7 @@ metaVar_gitDir=GIT_DIR
metaVar_hostName=HOSTNAME
metaVar_linesOfContext=lines
metaVar_message=message
+metaVar_n=n
metaVar_name=name
metaVar_object=object
metaVar_op=OP
@@ -171,6 +172,7 @@ usage_produceAnEclipseIPLog=Produce an Eclipse IP log
usage_pruneStaleTrackingRefs=prune stale tracking refs
usage_recurseIntoSubtrees=recurse into subtrees
usage_recordChangesToRepository=Record changes to the repository
+usage_renameLimit=limit size of rename matrix
usage_setTheGitRepositoryToOperateOn=set the git repository to operate on
usage_showRefNamesMatchingCommits=Show ref names matching commits
usage_showPatch=display patch
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 32499618df..77ed73048d 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
@@ -53,12 +53,12 @@ import java.util.List;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
-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.diff.RenameDetector;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
@@ -70,6 +70,9 @@ import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_ShowDiffs")
class Diff extends TextBuiltin {
+ private final DiffFormatter diffFmt = new DiffFormatter( //
+ new BufferedOutputStream(System.out));
+
@Argument(index = 0, metaVar = "metaVar_treeish", required = true)
void tree_0(final AbstractTreeIterator c) {
trees.add(c);
@@ -81,45 +84,55 @@ class Diff extends TextBuiltin {
@Option(name = "--", metaVar = "metaVar_paths", multiValued = true, handler = PathTreeFilterHandler.class)
private TreeFilter pathFilter = TreeFilter.ALL;
+ // BEGIN -- Options shared with Log
+ @Option(name = "-p", usage = "usage_showPatch")
+ boolean showPatch;
+
@Option(name = "-M", usage = "usage_detectRenames")
private boolean detectRenames;
+ @Option(name = "-l", usage = "usage_renameLimit")
+ private Integer renameLimit;
+
@Option(name = "--name-status", usage = "usage_nameStatus")
private boolean showNameAndStatusOnly;
@Option(name = "--ignore-space-at-eol")
- private boolean ignoreWsTrailing;
+ void ignoreSpaceAtEol(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreTrailingWhitespace.FACTORY);
+ }
@Option(name = "--ignore-leading-space")
- private boolean ignoreWsLeading;
+ void ignoreLeadingSpace(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreLeadingWhitespace.FACTORY);
+ }
@Option(name = "-b", aliases = { "--ignore-space-change" })
- private boolean ignoreWsChange;
+ void ignoreSpaceChange(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreWhitespaceChange.FACTORY);
+ }
@Option(name = "-w", aliases = { "--ignore-all-space" })
- private boolean ignoreWsAll;
+ void ignoreAllSpace(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreAllWhitespace.FACTORY);
+ }
@Option(name = "-U", aliases = { "--unified" }, metaVar = "metaVar_linesOfContext")
void unified(int lines) {
- fmt.setContext(lines);
+ diffFmt.setContext(lines);
}
- private DiffFormatter fmt = new DiffFormatter( //
- new BufferedOutputStream(System.out)) {
- @Override
- protected RawText newRawText(byte[] raw) {
- 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);
- }
- };
+ @Option(name = "--abbrev", metaVar = "n")
+ void abbrev(int lines) {
+ diffFmt.setAbbreviationLength(lines);
+ }
+
+ @Option(name = "--full-index")
+ void abbrev(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setAbbreviationLength(Constants.OBJECT_ID_STRING_LENGTH);
+ }
+
+ // END -- Options shared with Log
@Override
protected void run() throws Exception {
@@ -130,9 +143,9 @@ class Diff extends TextBuiltin {
out.flush();
} else {
- fmt.setRepository(db);
- fmt.format(files);
- fmt.flush();
+ diffFmt.setRepository(db);
+ diffFmt.format(files);
+ diffFmt.flush();
}
}
@@ -173,6 +186,8 @@ class Diff extends TextBuiltin {
List<DiffEntry> files = DiffEntry.scan(walk);
if (detectRenames) {
RenameDetector rd = new RenameDetector(db);
+ if (renameLimit != null)
+ rd.setRenameLimit(renameLimit.intValue());
rd.addAll(files);
files = rd.compute(new TextProgressMonitor());
}
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 aa4e8ae3cb..83ef6eb875 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
@@ -60,8 +60,13 @@ import java.util.TimeZone;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
+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.diff.RenameDetector;
import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.TextProgressMonitor;
@@ -78,27 +83,63 @@ class Log extends RevWalkTextBuiltin {
private final DateFormat fmt;
+ private final DiffFormatter diffFmt = new DiffFormatter( //
+ new BufferedOutputStream(System.out));
+
private Map<AnyObjectId, Set<Ref>> allRefsByPeeledObjectId;
@Option(name="--decorate", usage="usage_showRefNamesMatchingCommits")
private boolean decorate;
+ // BEGIN -- Options shared with Diff
+ @Option(name = "-p", usage = "usage_showPatch")
+ boolean showPatch;
+
@Option(name = "-M", usage = "usage_detectRenames")
private boolean detectRenames;
+ @Option(name = "-l", usage = "usage_renameLimit")
+ private Integer renameLimit;
+
@Option(name = "--name-status", usage = "usage_nameStatus")
private boolean showNameAndStatusOnly;
- @Option(name = "-p", usage = "usage_showPatch")
- private boolean showPatch;
+ @Option(name = "--ignore-space-at-eol")
+ void ignoreSpaceAtEol(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreTrailingWhitespace.FACTORY);
+ }
+
+ @Option(name = "--ignore-leading-space")
+ void ignoreLeadingSpace(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreLeadingWhitespace.FACTORY);
+ }
+
+ @Option(name = "-b", aliases = { "--ignore-space-change" })
+ void ignoreSpaceChange(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreWhitespaceChange.FACTORY);
+ }
+
+ @Option(name = "-w", aliases = { "--ignore-all-space" })
+ void ignoreAllSpace(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setRawTextFactory(RawTextIgnoreAllWhitespace.FACTORY);
+ }
@Option(name = "-U", aliases = { "--unified" }, metaVar = "metaVar_linesOfContext")
void unified(int lines) {
diffFmt.setContext(lines);
}
- private DiffFormatter diffFmt = new DiffFormatter( //
- new BufferedOutputStream(System.out));
+ @Option(name = "--abbrev", metaVar = "metaVar_n")
+ void abbrev(int lines) {
+ diffFmt.setAbbreviationLength(lines);
+ }
+
+ @Option(name = "--full-index")
+ void abbrev(@SuppressWarnings("unused") boolean on) {
+ diffFmt.setAbbreviationLength(Constants.OBJECT_ID_STRING_LENGTH);
+ }
+
+ // END -- Options shared with Diff
Log() {
fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US);
@@ -147,7 +188,7 @@ class Log extends RevWalkTextBuiltin {
}
out.println();
- if (c.getParentCount() > 0 && (showNameAndStatusOnly || showPatch))
+ if (c.getParentCount() == 1 && (showNameAndStatusOnly || showPatch))
showDiff(c);
out.flush();
}
@@ -163,6 +204,8 @@ class Log extends RevWalkTextBuiltin {
List<DiffEntry> files = DiffEntry.scan(tw);
if (detectRenames) {
RenameDetector rd = new RenameDetector(db);
+ if (renameLimit != null)
+ rd.setRenameLimit(renameLimit.intValue());
rd.addAll(files);
files = rd.compute(new TextProgressMonitor());
}
@@ -175,5 +218,6 @@ class Log extends RevWalkTextBuiltin {
diffFmt.format(files);
diffFmt.flush();
}
+ out.println();
}
}