diff options
author | James Moger <james.moger@gitblit.com> | 2013-09-27 20:25:06 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-09-27 21:33:34 -0400 |
commit | 319342c09152c61af13930e79777e1396f9c397f (patch) | |
tree | 5918ec46da2814872c05d8b665ad6538af600caf /src/main/java/com/gitblit/models/PathModel.java | |
parent | b384a9923314ef0ab7ec0e9f506c8d52cc31f5fc (diff) | |
download | gitblit-319342c09152c61af13930e79777e1396f9c397f.tar.gz gitblit-319342c09152c61af13930e79777e1396f9c397f.zip |
Add normalized diffstats to the commit, commitdiff, and compare pages
Change-Id: I8f26746a611e9ab955efe8b2597cc81db48fb085
Diffstat (limited to 'src/main/java/com/gitblit/models/PathModel.java')
-rw-r--r-- | src/main/java/com/gitblit/models/PathModel.java | 44 |
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;
+ }
}
}
|