summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/models/PathModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/models/PathModel.java')
-rw-r--r--src/main/java/com/gitblit/models/PathModel.java44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/models/PathModel.java b/src/main/java/com/gitblit/models/PathModel.java
index f894978b..9093a445 100644
--- a/src/main/java/com/gitblit/models/PathModel.java
+++ b/src/main/java/com/gitblit/models/PathModel.java
@@ -17,6 +17,7 @@ package com.gitblit.models;
import java.io.Serializable;
+import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.FileMode;
@@ -60,6 +61,12 @@ public class PathModel implements Serializable, Comparable<PathModel> {
return FileMode.TREE.equals(mode);
}
+ public boolean isFile() {
+ return FileMode.REGULAR_FILE.equals(mode)
+ || FileMode.EXECUTABLE_FILE.equals(mode)
+ || (FileMode.MISSING.equals(mode) && !isSymlink() && !isSubmodule() && !isTree());
+ }
+
@Override
public int hashCode() {
return commitId.hashCode() + path.hashCode();
@@ -107,12 +114,29 @@ public class PathModel implements Serializable, Comparable<PathModel> {
private static final long serialVersionUID = 1L;
public ChangeType changeType;
-
+
+ public int insertions;
+
+ public int deletions;
+
public PathChangeModel(String name, String path, long size, int mode, String objectId,
String commitId, ChangeType type) {
super(name, path, size, mode, objectId, commitId);
this.changeType = type;
}
+
+ public void update(char op) {
+ switch (op) {
+ case '+':
+ insertions++;
+ break;
+ case '-':
+ deletions++;
+ break;
+ default:
+ break;
+ }
+ }
@Override
public int hashCode() {
@@ -123,5 +147,23 @@ public class PathModel implements Serializable, Comparable<PathModel> {
public boolean equals(Object o) {
return super.equals(o);
}
+
+ public static PathChangeModel from(DiffEntry diff, String commitId) {
+ PathChangeModel pcm;
+ if (diff.getChangeType().equals(ChangeType.DELETE)) {
+ pcm = new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
+ .getNewMode().getBits(), diff.getOldId().name(), commitId, diff
+ .getChangeType());
+ } else if (diff.getChangeType().equals(ChangeType.RENAME)) {
+ pcm = new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
+ .getNewMode().getBits(), diff.getNewId().name(), commitId, diff
+ .getChangeType());
+ } else {
+ pcm = new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
+ .getNewMode().getBits(), diff.getNewId().name(), commitId, diff
+ .getChangeType());
+ }
+ return pcm;
+ }
}
}