Skip to content

The Unified and Autonomous Development Platform

Enhance DiffTreeMode to include file modes.

robin shine3a9ff29f6d57
diff --git a/commons.git/src/main/java/com/pmease/commons/git/DiffTreeNode.java b/commons.git/src/main/java/com/pmease/commons/git/DiffTreeNode.java
index f02e70089f..51a9444ec3 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/DiffTreeNode.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/DiffTreeNode.java
@@ -3,26 +3,30 @@ package com.pmease.commons.git;
import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jgit.lib.FileMode;
import com.google.common.base.Objects;
@SuppressWarnings("serial")
public class DiffTreeNode implements Comparable<DiffTreeNode>, Serializable {
- public enum Action {ADD, MODIFY, DELETE, EQUAL};
+ public enum Status {ADD, MODIFY, DELETE, EQUAL};
+ private final Status status;
+
private final String path;
- private final boolean folder;
+ private final int oldMode;
- private final Action action;
+ private final int newMode;
private transient String name;
- public DiffTreeNode(String path, boolean folder, Action action) {
+ public DiffTreeNode(Status status, String path, int oldMode, int newMode) {
this.path = path;
- this.folder = folder;
- this.action = action;
+ this.status = status;
+ this.oldMode = oldMode;
+ this.newMode = newMode;
}
public String getPath() {
@@ -39,12 +43,20 @@ public class DiffTreeNode implements Comparable<DiffTreeNode>, Serializable {
return name;
}
- public Action getAction() {
- return action;
+ public Status getStatus() {
+ return status;
+ }
+
+ public int getOldMode() {
+ return oldMode;
}
+ public int getNewMode() {
+ return newMode;
+ }
+
public boolean isFolder() {
- return folder;
+ return oldMode == FileMode.TYPE_TREE || newMode == FileMode.TYPE_TREE;
}
@Override
@@ -64,9 +76,8 @@ public class DiffTreeNode implements Comparable<DiffTreeNode>, Serializable {
@Override
public String toString() {
return Objects.toStringHelper(DiffTreeNode.class)
+ .add("action", status)
.add("path", path)
- .add("action", action)
- .add("folder", folder)
.toString();
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.java
index 95f39dd66a..e3266c2bd9 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -48,7 +49,7 @@ import com.pmease.commons.git.command.PushCommand;
import com.pmease.commons.git.command.RemoveCommand;
import com.pmease.commons.git.command.ResetCommand;
import com.pmease.commons.git.command.ShowCommand;
-import com.pmease.commons.git.command.ShowForConsumeCommand;
+import com.pmease.commons.git.command.ConsumeCommand;
import com.pmease.commons.git.command.ShowRefCommand;
import com.pmease.commons.git.command.ShowSymbolicRefCommand;
import com.pmease.commons.git.command.UpdateRefCommand;
@@ -145,92 +146,160 @@ public class Git implements Serializable {
return commits.get(0);
}
+ /**
+ * List tree of specified revision under specified path.
+ *
+ * @param revision
+ * revision to list the tree off
+ * @param path
+ * path to list tree for. Note that if path is not empty and does not end
+ * with slash, this method will list the path itself, instead of listing
+ * child entries under this path
+ * @return
+ */
public List<TreeNode> listTree(String revision, @Nullable String path) {
return new ListTreeCommand(repoDir).revision(revision).path(path).call();
}
/**
- * List tree of fromRev, and mark differences from fromRev to toRev in the resulting tree.
+ * List tree of fromRev, and mark differences from fromRev to toRev in the resulting tree.
*
* @param fromRev
* revision to base the tree off
* @param toRev
* revision to calculate file differences since fromRev
* @param path
- * path to list tree inside
+ * path to list tree for. Note that if path is not empty and does not end with slash,
+ * this method will diff this path itself between fromRev and toRev, instead of
+ * diffing child entries under this path
* @return
* a list of tree node with appropriate actions set up to mark whether or not this
* tree node is modified, added, deleted or remaining the same
*/
public List<DiffTreeNode> listTreeWithDiff(String fromRev, String toRev, @Nullable String path) {
- path = GitUtils.normalizeTreePath(path);
-
- Collection<FileChange> changes = listFileChanges(fromRev, toRev, path, false);
- Set<String> addedFiles = new HashSet<>();
- Set<String> deletedFiles = new HashSet<>();
- Set<String> modifiedFiles = new HashSet<>();
- Set<String> changedFiles = new HashSet<>();
-
- for (FileChange change: changes) {
- if (change.getStatus() == FileChange.Status.ADD) {
- addedFiles.add(change.getNewPath());
- } else if (change.getStatus() == FileChange.Status.DELETE) {
- deletedFiles.add(change.getOldPath());
- } else if (change.getStatus() == FileChange.Status.MODIFY
- || change.getStatus() == FileChange.Status.TYPE) {
- modifiedFiles.add(change.getOldPath());
- } else {
- throw new IllegalStateException("Unexpected action: " + change.getStatus());
- }
- }
-
- changedFiles.addAll(addedFiles);
- changedFiles.addAll(deletedFiles);
- changedFiles.addAll(modifiedFiles);
-
+ if (path == null)
+ path = "";
+
List<DiffTreeNode> diffs = new ArrayList<>();
- for (TreeNode treeNode: listTree(fromRev, path)) {
- if (FileMode.TREE.equals(treeNode.getModeBits())) {
- String nodePath = treeNode.getPath() + "/";
- DiffTreeNode diff = null;
- for (String changedFile: changedFiles) {
- if (changedFile.startsWith(nodePath)) {
- addedFiles.remove(changedFile);
- diff = new DiffTreeNode(treeNode.getPath(), true, DiffTreeNode.Action.MODIFY);
- break;
+ if (path.length() == 0 || path.endsWith("/")) {
+ Map<String, FileChange> changes = new HashMap<String, FileChange>();
+
+ for (FileChange change: listFileChanges(fromRev, toRev, path, false)) {
+ if (change.getStatus() == FileChange.Status.ADD) {
+ changes.put(change.getNewPath(), change);
+ } else if (change.getStatus() == FileChange.Status.DELETE) {
+ changes.put(change.getOldPath(), change);
+ } else if (change.getStatus() == FileChange.Status.MODIFY
+ || change.getStatus() == FileChange.Status.TYPE) {
+ changes.put(change.getOldPath(), change);
+ } else {
+ throw new IllegalStateException("Unexpected action: " + change.getStatus());
+ }
+ }
+
+ Set<String> nodePathsInToRev = new HashSet<>();
+ for (TreeNode each: listTree(toRev, path))
+ nodePathsInToRev.add(each.getPath());
+
+ Set<String> coveredFiles = new HashSet<>();
+ for (TreeNode treeNode: listTree(fromRev, path)) {
+ if (FileMode.TREE.equals(treeNode.getMode())) {
+ String treePath = treeNode.getPath() + "/";
+ DiffTreeNode diff = null;
+ for (String changedFile: changes.keySet()) {
+ if (changedFile.startsWith(treePath)) {
+ coveredFiles.add(changedFile);
+ diff = new DiffTreeNode(DiffTreeNode.Status.MODIFY, treeNode.getPath(),
+ FileMode.TYPE_TREE, FileMode.TYPE_TREE);
+ break;
+ }
+ }
+ if (diff != null) {
+ if (!nodePathsInToRev.contains(treeNode.getPath()))
+ diff = new DiffTreeNode(DiffTreeNode.Status.DELETE, treeNode.getPath(),
+ FileMode.TYPE_TREE, 0);
+ } else {
+ diff = new DiffTreeNode(DiffTreeNode.Status.EQUAL, treeNode.getPath(),
+ FileMode.TYPE_TREE, FileMode.TYPE_TREE);
+ }
+ diffs.add(diff);
+ } else {
+ DiffTreeNode diff;
+ FileChange change = changes.get(treeNode.getPath());
+ if (change != null) {
+ if (change.getStatus() == FileChange.Status.DELETE) {
+ diff = new DiffTreeNode(DiffTreeNode.Status.DELETE, treeNode.getPath(),
+ change.getOldMode(), change.getNewMode());
+ } else {
+ diff = new DiffTreeNode(DiffTreeNode.Status.MODIFY, treeNode.getPath(),
+ change.getOldMode(), change.getNewMode());
+ }
+ } else {
+ diff = new DiffTreeNode(DiffTreeNode.Status.EQUAL, treeNode.getPath(),
+ treeNode.getMode(), treeNode.getMode());
}
+ diffs.add(diff);
}
- if (diff == null)
- diff = new DiffTreeNode(treeNode.getPath(), true, DiffTreeNode.Action.EQUAL);
- diffs.add(diff);
- } else {
- DiffTreeNode diff;
- if (modifiedFiles.contains(treeNode.getPath()))
- diff = new DiffTreeNode(treeNode.getPath(), false, DiffTreeNode.Action.MODIFY);
- else if (deletedFiles.contains(treeNode.getPath()))
- diff = new DiffTreeNode(treeNode.getPath(), false, DiffTreeNode.Action.DELETE);
- else
- diff = new DiffTreeNode(treeNode.getPath(), false, DiffTreeNode.Action.EQUAL);
- diffs.add(diff);
}
- }
-
- Set<String> addedDirs = new HashSet<>();
- for (String addedFile: addedFiles) {
- String relativePath = addedFile.substring(path.length());
- int index = relativePath.indexOf('/');
- if (index != -1)
- addedDirs.add(path + relativePath.substring(0, index));
- else
- diffs.add(new DiffTreeNode(addedFile, false, DiffTreeNode.Action.ADD));
+
+ Set<String> addedDirs = new HashSet<>();
+ for (Map.Entry<String, FileChange> entry: changes.entrySet()) {
+ String file = entry.getKey();
+ FileChange change = entry.getValue();
+ if (change.getStatus() == FileChange.Status.ADD && !coveredFiles.contains(file)) {
+ String relativePath = file.substring(path.length());
+ int index = relativePath.indexOf('/');
+ if (index != -1) {
+ addedDirs.add(path + relativePath.substring(0, index));
+ } else {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.ADD, file,
+ change.getOldMode(), change.getNewMode()));
+ }
+ }
+ }
+
+ for (String addedDir: addedDirs) {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.ADD, addedDir,
+ FileMode.TYPE_TREE, FileMode.TYPE_TREE));
+ }
+ } else {
+ List<TreeNode> oldTree = listTree(fromRev, path);
+ List<TreeNode> newTree = listTree(toRev, path);
+ if (!oldTree.isEmpty()) {
+ TreeNode oldNode = oldTree.iterator().next();
+ if (!newTree.isEmpty()) {
+ TreeNode newNode = newTree.iterator().next();
+ if (oldNode.getMode() == FileMode.TYPE_TREE) {
+ if (newNode.getMode() == FileMode.TYPE_TREE) {
+ if (!listChangedFiles(fromRev, toRev, path).isEmpty())
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.MODIFY, path, oldNode.getMode(), newNode.getMode()));
+ else
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.EQUAL, path, oldNode.getMode(), newNode.getMode()));
+ } else {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.DELETE, path, oldNode.getMode(), 0));
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.ADD, path, 0, newNode.getMode()));
+ }
+ } else if (newNode.getMode() == FileMode.TYPE_TREE) {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.DELETE, path, oldNode.getMode(), 0));
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.ADD, path, 0, newNode.getMode()));
+ } else if (oldNode.getMode() != newNode.getMode()) {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.MODIFY, path, oldNode.getMode(), newNode.getMode()));
+ } else if (!listChangedFiles(fromRev, toRev, path).isEmpty()) {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.MODIFY, path, oldNode.getMode(), newNode.getMode()));
+ } else {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.EQUAL, path, oldNode.getMode(), newNode.getMode()));
+ }
+ } else {
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.DELETE, path, oldNode.getMode(), 0));
+ }
+ } else if (!newTree.isEmpty()) {
+ TreeNode newNode = newTree.iterator().next();
+ diffs.add(new DiffTreeNode(DiffTreeNode.Status.ADD, path, 0, newNode.getMode()));
+ }
}
- for (String addedDir: addedDirs)
- diffs.add(new DiffTreeNode(addedDir, true, DiffTreeNode.Action.ADD));
-
Collections.sort(diffs);
-
return diffs;
}
@@ -454,8 +523,8 @@ public class Git implements Serializable {
* consumer to absorb content of specified path and revision
*
*/
- public Git show(String revision, String path, StreamConsumer consumer) {
- new ShowForConsumeCommand(repoDir).revision(revision).path(path).consumer(consumer).call();
+ public Git consume(String revision, String path, StreamConsumer consumer) {
+ new ConsumeCommand(repoDir).revision(revision).path(path).consumer(consumer).call();
return this;
}
@@ -463,6 +532,13 @@ public class Git implements Serializable {
return new ShowCommand(repoDir).revision(revision).path(path).call();
}
+ public String readSubModule(String revision, String path) {
+ String subModuleUrl = listSubModules(revision).get(path);
+ Preconditions.checkNotNull(subModuleUrl);
+ String subModule = subModuleUrl + ":" + listTree(revision, path).iterator().next().getHash();
+ return subModule;
+ }
+
public List<Commit> log(@Nullable String fromRev, @Nullable String toRev,
@Nullable String path, int maxCount, int skip) {
return new LogCommand(repoDir).fromRev(fromRev).toRev(toRev)
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index 248c6b6cec..6193fd60a8 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -45,13 +45,4 @@ public class GitUtils {
}
}
- public static String normalizeTreePath(String treePath) {
- if (treePath == null || treePath.length() == 0 || treePath.equals("/")) {
- return "";
- } else if (!treePath.endsWith("/")) {
- return treePath + "/";
- } else {
- return treePath;
- }
- }
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/TreeNode.java b/commons.git/src/main/java/com/pmease/commons/git/TreeNode.java
index e0c3efdd34..2bdb39ce85 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/TreeNode.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/TreeNode.java
@@ -13,7 +13,7 @@ import com.pmease.commons.git.command.ListTreeCommand;
@SuppressWarnings("serial")
public class TreeNode implements Comparable<TreeNode>, Serializable {
- private final int modeBits;
+ private final int mode;
private final String path;
@@ -25,7 +25,7 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
private final int size;
- private transient FileMode mode;
+ private transient FileMode fileMode;
/**
* Construct a tree node.
@@ -45,7 +45,7 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
this.path = path;
this.revision = revision;
this.hash = hash;
- this.modeBits = modeBits;
+ this.mode = modeBits;
this.size = size;
}
@@ -71,14 +71,14 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
return hash;
}
- public int getModeBits() {
- return modeBits;
+ public int getMode() {
+ return mode;
}
- public FileMode getMode() {
- if (mode == null)
- mode = FileMode.fromBits(modeBits);
- return mode;
+ public FileMode getFileMode() {
+ if (fileMode == null)
+ fileMode = FileMode.fromBits(mode);
+ return fileMode;
}
public int getSize() {
@@ -98,7 +98,7 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
* directory.
*/
public @Nullable List<TreeNode> listChildren(Git git) {
- if (getMode() == FileMode.TREE) {
+ if (getFileMode() == FileMode.TREE) {
return new ListTreeCommand(git.repoDir()).revision(getRevision()).path(getPath() + "/").call();
} else {
return null;
@@ -106,7 +106,7 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
}
/**
- * Show content of current node.
+ * Read content of current node.
*
* @return
* content of the file if current node is a file, or URL of the submodule if
@@ -114,9 +114,9 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
* represents a symbol link, or contents of the directory if current node
* represents a directory
*/
- public byte[] show(Git git) {
- if (getMode() == FileMode.GITLINK) {
- return git.listSubModules(revision).get(path).getBytes();
+ public byte[] readContent(Git git) {
+ if (getFileMode() == FileMode.GITLINK) {
+ return git.readSubModule(getRevision(), getPath()).getBytes();
} else {
return git.show(getRevision(), getPath());
}
@@ -124,12 +124,12 @@ public class TreeNode implements Comparable<TreeNode>, Serializable {
@Override
public int compareTo(TreeNode node) {
- if (getMode() == FileMode.TREE) {
- if (node.getMode() == FileMode.TREE)
+ if (getFileMode() == FileMode.TREE) {
+ if (node.getFileMode() == FileMode.TREE)
return getName().compareTo(node.getName());
else
return -1;
- } else if (node.getMode() == FileMode.TREE) {
+ } else if (node.getFileMode() == FileMode.TREE) {
return 1;
} else {
return getName().compareTo(node.getName());
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ShowForConsumeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ConsumeCommand.java
similarity index 74%
rename from commons.git/src/main/java/com/pmease/commons/git/command/ShowForConsumeCommand.java
rename to commons.git/src/main/java/com/pmease/commons/git/command/ConsumeCommand.java
index 10dda5180d..7a5430143c 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/command/ShowForConsumeCommand.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/command/ConsumeCommand.java
@@ -10,9 +10,9 @@ import com.pmease.commons.util.execution.Commandline;
import com.pmease.commons.util.execution.LineConsumer;
import com.pmease.commons.util.execution.StreamConsumer;
-public class ShowForConsumeCommand extends GitCommand<Void> {
+public class ConsumeCommand extends GitCommand<Void> {
- private static final Logger logger = LoggerFactory.getLogger(ShowForConsumeCommand.class);
+ private static final Logger logger = LoggerFactory.getLogger(ConsumeCommand.class);
private String revision;
@@ -20,21 +20,21 @@ public class ShowForConsumeCommand extends GitCommand<Void> {
private StreamConsumer consumer;
- public ShowForConsumeCommand(final File repoDir) {
+ public ConsumeCommand(final File repoDir) {
super(repoDir);
}
- public ShowForConsumeCommand revision(String revision) {
+ public ConsumeCommand revision(String revision) {
this.revision = revision;
return this;
}
- public ShowForConsumeCommand path(String path) {
+ public ConsumeCommand path(String path) {
this.path = path;
return this;
}
- public ShowForConsumeCommand consumer(StreamConsumer consumer) {
+ public ConsumeCommand consumer(StreamConsumer consumer) {
this.consumer = consumer;
return this;
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
index 06101abca4..74dc001dc0 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
@@ -11,7 +11,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.TreeNode;
import com.pmease.commons.util.execution.Commandline;
import com.pmease.commons.util.execution.LineConsumer;
@@ -22,7 +21,7 @@ public class ListTreeCommand extends GitCommand<List<TreeNode>> {
private String revision;
- private String path = "";
+ private String path;
public ListTreeCommand(final File repoDir) {
super(repoDir);
@@ -34,7 +33,7 @@ public class ListTreeCommand extends GitCommand<List<TreeNode>> {
}
public ListTreeCommand path(String path) {
- this.path = GitUtils.normalizeTreePath(path);
+ this.path = path;
return this;
}
@@ -42,9 +41,11 @@ public class ListTreeCommand extends GitCommand<List<TreeNode>> {
public List<TreeNode> call() {
Preconditions.checkNotNull(revision, "revision has to be specified for browse.");
- Commandline cmd = cmd().addArgs("ls-tree", "-l");
+ Commandline cmd = cmd().addArgs("ls-tree", "-l", "--full-name");
cmd.addArgs(revision);
- cmd.addArgs(path);
+
+ if (path != null)
+ cmd.addArgs(path);
final List<TreeNode> treeNodes = new ArrayList<TreeNode>();
diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
index 4fc201ffab..8f60b4297f 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
@@ -32,32 +32,51 @@ public class GitTest extends AbstractGitTest {
List<DiffTreeNode> diffs = git.listTreeWithDiff("master", "dev", null);
assertEquals(7, diffs.size());
assertEquals("dir1", diffs.get(0).getPath());
- assertEquals(DiffTreeNode.Action.MODIFY, diffs.get(0).getAction());
+ assertEquals(DiffTreeNode.Status.MODIFY, diffs.get(0).getStatus());
assertEquals("dir2", diffs.get(1).getPath());
- assertEquals(DiffTreeNode.Action.MODIFY, diffs.get(1).getAction());
+ assertEquals(DiffTreeNode.Status.MODIFY, diffs.get(1).getStatus());
assertEquals("dir3", diffs.get(2).getPath());
- assertEquals(DiffTreeNode.Action.ADD, diffs.get(2).getAction());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(2).getStatus());
assertEquals("dir2", diffs.get(3).getPath());
- assertEquals(DiffTreeNode.Action.ADD, diffs.get(3).getAction());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(3).getStatus());
assertEquals(false, diffs.get(3).isFolder());
assertEquals("file1", diffs.get(4).getPath());
- assertEquals(DiffTreeNode.Action.EQUAL, diffs.get(4).getAction());
+ assertEquals(DiffTreeNode.Status.EQUAL, diffs.get(4).getStatus());
assertEquals("file2", diffs.get(5).getPath());
- assertEquals(DiffTreeNode.Action.DELETE, diffs.get(5).getAction());
+ assertEquals(DiffTreeNode.Status.DELETE, diffs.get(5).getStatus());
assertEquals("file3", diffs.get(6).getPath());
- assertEquals(DiffTreeNode.Action.ADD, diffs.get(6).getAction());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(6).getStatus());
- diffs = git.listTreeWithDiff("master", "dev", "dir2");
+ diffs = git.listTreeWithDiff("master", "dev", "dir2/");
assertEquals(1, diffs.size());
assertEquals("dir2/file1", diffs.get(0).getPath());
- assertEquals(DiffTreeNode.Action.DELETE, diffs.get(0).getAction());
+ assertEquals(DiffTreeNode.Status.DELETE, diffs.get(0).getStatus());
- diffs = git.listTreeWithDiff("master", "dev", "dir3");
+ diffs = git.listTreeWithDiff("master", "dev", "dir3/");
assertEquals(2, diffs.size());
assertEquals("dir3/file1", diffs.get(0).getPath());
- assertEquals(DiffTreeNode.Action.ADD, diffs.get(0).getAction());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(0).getStatus());
assertEquals("dir3/file2", diffs.get(1).getPath());
- assertEquals(DiffTreeNode.Action.ADD, diffs.get(1).getAction());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(1).getStatus());
+
+ diffs = git.listTreeWithDiff("master", "dev", "dir3");
+ assertEquals(1, diffs.size());
+ assertEquals("dir3", diffs.get(0).getPath());
+ assertEquals(DiffTreeNode.Status.ADD, diffs.get(0).getStatus());
+
+ rm("dir3/file1");
+ rm("dir3/file2");
+ commit("delete dir3");
+
+ diffs = git.listTreeWithDiff("dev~1", "dev", null);
+ assertEquals(5, diffs.size());
+ assertEquals("dir3", diffs.get(1).getPath());
+ assertEquals(DiffTreeNode.Status.DELETE, diffs.get(1).getStatus());
+
+ diffs = git.listTreeWithDiff("dev~1", "dev", "dir3");
+ assertEquals(1, diffs.size());
+ assertEquals("dir3", diffs.get(0).getPath());
+ assertEquals(DiffTreeNode.Status.DELETE, diffs.get(0).getStatus());
}
}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java b/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java
index 831f354a60..2867730149 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java
@@ -13,6 +13,7 @@ import com.pmease.commons.git.AbstractGitTest;
import com.pmease.commons.git.Git;
import com.pmease.commons.git.TreeNode;
import com.pmease.commons.util.FileUtils;
+import com.pmease.commons.util.StringUtils;
public class ListTreeCommandTest extends AbstractGitTest {
@@ -46,20 +47,23 @@ public class ListTreeCommandTest extends AbstractGitTest {
assertEquals(7, treeNodes.size());
assertEquals("dir", treeNodes.get(0).getPath());
assertEquals("dir", treeNodes.get(0).getName());
- assertEquals(FileMode.TREE, treeNodes.get(0).getMode());
+ assertEquals(FileMode.TREE, treeNodes.get(0).getFileMode());
- assertEquals(moduleGit.repoDir().getAbsolutePath(),
- new File(new String(treeNodes.get(6).show(bareGit))).getCanonicalPath());
+ String submoduleInfo = new String(treeNodes.get(6).readContent(bareGit));
+ String submodulePath = new File(StringUtils.substringBeforeLast(submoduleInfo, ":")).getCanonicalPath();
+ String submoduleCommit = StringUtils.substringAfterLast(submoduleInfo, ":");
+ assertEquals(moduleGit.repoDir().getAbsolutePath(), submodulePath);
+ assertEquals(moduleGit.parseRevision("master", true), submoduleCommit);
TreeNode dirNode = treeNodes.get(0);
- treeNodes = bareGit.listTree(dirNode.getRevision(), dirNode.getPath());
+ treeNodes = bareGit.listTree(dirNode.getRevision(), dirNode.getPath() + "/");
assertEquals(1, treeNodes.size());
assertEquals("dir/file", treeNodes.get(0).getPath());
assertEquals("file", treeNodes.get(0).getName());
TreeNode fileNode = treeNodes.get(0);
- assertEquals("hello world", new String(fileNode.show(bareGit)));
+ assertEquals("hello world", new String(fileNode.readContent(bareGit)));
}
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/LogUtils.java b/commons.util/src/main/java/com/pmease/commons/util/LogUtils.java
deleted file mode 100644
index 612c400b8c..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/LogUtils.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.pmease.commons.util;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LogUtils {
-
- private static final Logger logger = LoggerFactory.getLogger(LogUtils.class);
-
- private static final Map<String, Logger> loggers = new ConcurrentHashMap<>();
-
- public static Logger getLogger(int stackBacktrackCount) {
- if (stackBacktrackCount == -1) {
- return logger;
- } else {
- String className = StringUtils.substringBefore(
- new Throwable().getStackTrace()[stackBacktrackCount].getClassName(), "$");
- Logger logger = loggers.get(className);
- if (logger == null) {
- logger = LoggerFactory.getLogger(className);
- loggers.put(className, logger);
- }
- return logger;
- }
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java
index 8d785ca5f9..969cd2f62c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java
@@ -58,7 +58,7 @@ public abstract class DiffTreePanel extends Panel {
@Override
public Iterator<? extends DiffTreeNode> getChildren(DiffTreeNode node) {
- return repoModel.getObject().git().listTreeWithDiff(fromRev, toRev, node.getPath()).iterator();
+ return repoModel.getObject().git().listTreeWithDiff(fromRev, toRev, node.getPath() + "/").iterator();
}
@Override
@@ -79,21 +79,21 @@ public abstract class DiffTreePanel extends Panel {
final DiffTreeNode node = nodeModel.getObject();
Fragment fragment = new Fragment(id, "nodeFrag", DiffTreePanel.this);
fragment.add(new WebMarkupContainer("addedDir").setVisible(
- node.isFolder() && node.getAction() == DiffTreeNode.Action.ADD));
+ node.isFolder() && node.getStatus() == DiffTreeNode.Status.ADD));
fragment.add(new WebMarkupContainer("deletedDir").setVisible(
- node.isFolder() && node.getAction() == DiffTreeNode.Action.DELETE));
+ node.isFolder() && node.getStatus() == DiffTreeNode.Status.DELETE));
fragment.add(new WebMarkupContainer("modifiedDir").setVisible(
- node.isFolder() && node.getAction() == DiffTreeNode.Action.MODIFY));
+ node.isFolder() && node.getStatus() == DiffTreeNode.Status.MODIFY));
fragment.add(new WebMarkupContainer("unchangedDir").setVisible(
- node.isFolder() && node.getAction() == DiffTreeNode.Action.EQUAL));
+ node.isFolder() && node.getStatus() == DiffTreeNode.Status.EQUAL));
fragment.add(new WebMarkupContainer("addedFile").setVisible(
- !node.isFolder() && node.getAction() == DiffTreeNode.Action.ADD));
+ !node.isFolder() && node.getStatus() == DiffTreeNode.Status.ADD));
fragment.add(new WebMarkupContainer("deletedFile").setVisible(
- !node.isFolder() && node.getAction() == DiffTreeNode.Action.DELETE));
+ !node.isFolder() && node.getStatus() == DiffTreeNode.Status.DELETE));
fragment.add(new WebMarkupContainer("modifiedFile").setVisible(
- !node.isFolder() && node.getAction() == DiffTreeNode.Action.MODIFY));
+ !node.isFolder() && node.getStatus() == DiffTreeNode.Status.MODIFY));
fragment.add(new WebMarkupContainer("unchangedFile").setVisible(
- !node.isFolder() && node.getAction() == DiffTreeNode.Action.EQUAL));
+ !node.isFolder() && node.getStatus() == DiffTreeNode.Status.EQUAL));
WebMarkupContainer link;
if (node.isFolder()) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directory/DirectoryChooser.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directory/DirectoryChooser.java
index 6370b1972a..472d2430ac 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directory/DirectoryChooser.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/directory/DirectoryChooser.java
@@ -42,7 +42,7 @@ public abstract class DirectoryChooser extends Panel {
List<TreeNode> roots = git.listTree(getBranch().getName(), null);
if (roots != null) {
for (Iterator<TreeNode> it = roots.iterator(); it.hasNext();) {
- if (it.next().getMode() != FileMode.TREE)
+ if (it.next().getFileMode() != FileMode.TREE)
it.remove();
}
return roots.iterator();
@@ -64,7 +64,7 @@ public abstract class DirectoryChooser extends Panel {
List<TreeNode> children = node.listChildren(getBranch().getRepository().git());
if (children != null) {
for (Iterator<TreeNode> it = children.iterator(); it.hasNext();) {
- if (it.next().getMode() != FileMode.TREE)
+ if (it.next().getFileMode() != FileMode.TREE)
it.remove();
}
return children.iterator();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java
index 691ced8a76..3367e3cafe 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java
@@ -45,11 +45,11 @@ public class RepoTreePage extends RepositoryInfoPage {
@Override
public int compare(TreeNode o1, TreeNode o2) {
- if (o1.getMode() == o2.getMode()) {
+ if (o1.getFileMode() == o2.getFileMode()) {
return o1.getName().compareTo(o2.getName());
- } else if (o1.getMode() == FileMode.TREE) {
+ } else if (o1.getFileMode() == FileMode.TREE) {
return -1;
- } else if (o2.getMode() == FileMode.TREE) {
+ } else if (o2.getFileMode() == FileMode.TREE) {
return 1;
} else {
return o1.getName().compareTo(o2.getName());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePanel.java
index 317a33fae8..d5c8f62f53 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePanel.java
@@ -118,7 +118,7 @@ public class RepoTreePanel extends Panel {
@Override
protected void populateItem(ListItem<TreeNode> item) {
TreeNode node = item.getModelObject();
- final int bits = node.getMode().getBits();
+ final int bits = node.getFileMode().getBits();
final String path = node.getPath();
Icon icon = new Icon("icon", new AbstractReadOnlyModel<String>() {
@@ -149,7 +149,7 @@ public class RepoTreePanel extends Panel {
currentRevision, PathUtils.join(pathElements));
AbstractLink link;
- FileMode mode = node.getMode();
+ FileMode mode = node.getFileMode();
if (mode == FileMode.TREE) {
link = new BookmarkablePageLink<Void>("file", RepoTreePage.class, params);
} else {