From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.

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