aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorDariusz Luksza <dariusz@luksza.org>2011-08-17 12:43:35 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2011-08-17 12:43:35 +0200
commit679cab9b3297e550a9ae04b88ba839dc9eb84957 (patch)
tree15ef803c3e8591f1fbbff74f84988e3746b788fe /org.eclipse.jgit/src/org/eclipse
parent100e9429b5a7eea8383c6e693d17b6233794c488 (diff)
downloadjgit-679cab9b3297e550a9ae04b88ba839dc9eb84957.tar.gz
jgit-679cab9b3297e550a9ae04b88ba839dc9eb84957.zip
Adds DiffEntry.scan(TreeWalk, boolean) method
Adds method into DiffEntry class that allows to specify whether changed trees are included in scanning result list. By default changed trees aren't added, but in some cases having changed tree would be useful. Also adds check for tree count in TreeWalk and when it is different from two it will thrown an IllegalArgumentException. This change is required by egit I7ddb21e7ff54333dd6d7ace3209bbcf83da2b219 Change-Id: I5a680a73e1cffa18ade3402cc86008f46c1da1f1 Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java38
2 files changed, 39 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
index af20477a65..3b645e8dda 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
@@ -552,4 +552,6 @@ public class JGitText extends TranslationBundle {
/***/ public String years;
/***/ public String yearsAgo;
/***/ public String yearsMonthsAgo;
+ /***/ public String treeWalkMustHaveExactlyTwoTrees;
+ /***/ public String cannotBeRecursiveWhenTreesAreIncluded;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java
index 76d86a9994..5bccccfc1b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffEntry.java
@@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.FileMode;
@@ -106,8 +107,40 @@ public class DiffEntry {
* @return headers describing the changed files.
* @throws IOException
* the repository cannot be accessed.
+ * @throws IllegalArgumentException
+ * When given TreeWalk doesn't have exactly two trees.
*/
public static List<DiffEntry> scan(TreeWalk walk) throws IOException {
+ return scan(walk, false);
+ }
+
+ /**
+ * Convert the TreeWalk into DiffEntry headers, depending on
+ * {@code includeTrees} it will add tree objects into result or not.
+ *
+ * @param walk
+ * the TreeWalk to walk through. Must have exactly two trees and
+ * when {@code includeTrees} parameter is {@code true} it can't
+ * be recursive.
+ * @param includeTrees
+ * include tree object's.
+ * @return headers describing the changed files.
+ * @throws IOException
+ * the repository cannot be accessed.
+ * @throws IllegalArgumentException
+ * when {@code includeTrees} is true and given TreeWalk is
+ * recursive. Or when given TreeWalk doesn't have exactly two
+ * trees
+ */
+ public static List<DiffEntry> scan(TreeWalk walk, boolean includeTrees)
+ throws IOException {
+ if (walk.getTreeCount() != 2)
+ throw new IllegalArgumentException(
+ JGitText.get().treeWalkMustHaveExactlyTwoTrees);
+ if (includeTrees && walk.isRecursive())
+ throw new IllegalArgumentException(
+ JGitText.get().cannotBeRecursiveWhenTreesAreIncluded);
+
List<DiffEntry> r = new ArrayList<DiffEntry>();
MutableObjectId idBuf = new MutableObjectId();
while (walk.next()) {
@@ -133,13 +166,16 @@ public class DiffEntry {
entry.changeType = ChangeType.DELETE;
r.add(entry);
- } else {
+ } else if (!entry.oldId.equals(entry.newId)) {
entry.changeType = ChangeType.MODIFY;
if (RenameDetector.sameType(entry.oldMode, entry.newMode))
r.add(entry);
else
r.addAll(breakModify(entry));
}
+
+ if (includeTrees && walk.isSubtree())
+ walk.enterSubtree();
}
return r;
}