From 575d4f690b8eaedfdd3981fe7c00ecc41d358e73 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 03 Jul 2014 16:57:47 -0400
Subject: [PATCH] Temporarily depend on patched guice-servlet (guice-807)
---
src/main/java/com/gitblit/models/PathModel.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/models/PathModel.java b/src/main/java/com/gitblit/models/PathModel.java
index 84571cb..bf58542 100644
--- a/src/main/java/com/gitblit/models/PathModel.java
+++ b/src/main/java/com/gitblit/models/PathModel.java
@@ -17,15 +17,16 @@
import java.io.Serializable;
+import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.FileMode;
/**
* PathModel is a serializable model class that represents a file or a folder,
* including all its metadata and associated commit id.
- *
+ *
* @author James Moger
- *
+ *
*/
public class PathModel implements Serializable, Comparable<PathModel> {
@@ -55,9 +56,15 @@
public boolean isSubmodule() {
return FileMode.GITLINK.equals(mode);
}
-
+
public boolean isTree() {
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
@@ -98,20 +105,37 @@
/**
* PathChangeModel is a serializable class that represents a file changed in
* a commit.
- *
+ *
* @author James Moger
- *
+ *
*/
public static class PathChangeModel extends PathModel {
private static final long serialVersionUID = 1L;
- public final ChangeType changeType;
+ 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
@@ -123,5 +147,23 @@
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;
+ }
}
}
--
Gitblit v1.9.1