From 3f5b8f5d9203aa7ffb7fbe9cdbaf9dba3da6cae6 Mon Sep 17 00:00:00 2001
From: Hybris95 <hybris_95@hotmail.com>
Date: Thu, 01 May 2014 16:14:15 -0400
Subject: [PATCH] Fixes sort, page building and search functions on "my tickets" page.

---
 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