From 319342c09152c61af13930e79777e1396f9c397f Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 27 Sep 2013 20:25:06 -0400 Subject: Add normalized diffstats to the commit, commitdiff, and compare pages Change-Id: I8f26746a611e9ab955efe8b2597cc81db48fb085 --- src/main/java/com/gitblit/models/PathModel.java | 44 ++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/gitblit/models/PathModel.java') 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 { 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 { 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 { 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; + } } } -- cgit v1.2.3