From 8f1dc607d135fd99d769a2dfd1e11e00d72d0506 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 19 Nov 2014 11:34:17 -0500
Subject: [PATCH] Merged #223 "Add support for image/svg+xml content type to raw servlet"
---
src/main/java/com/gitblit/models/PathModel.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/gitblit/models/PathModel.java b/src/main/java/com/gitblit/models/PathModel.java
index f894978..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,9 +105,9 @@
/**
* PathChangeModel is a serializable class that represents a file changed in
* a commit.
- *
+ *
* @author James Moger
- *
+ *
*/
public static class PathChangeModel extends PathModel {
@@ -108,10 +115,27 @@
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