| | |
| | | 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> {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | | public final String path;
|
| | | public final long size;
|
| | | public final int mode;
|
| | | public final String objectId;
|
| | | public final String commitId;
|
| | | public boolean isParentPath;
|
| | |
|
| | | public PathModel(String name, String path, long size, int mode, String commitId) {
|
| | | public PathModel(String name, String path, long size, int mode, String objectId, String commitId) {
|
| | | this.name = name;
|
| | | this.path = path;
|
| | | this.size = size;
|
| | | this.mode = mode;
|
| | | this.objectId = objectId;
|
| | | this.commitId = commitId;
|
| | | }
|
| | |
|
| | | public boolean isSubmodule() {
|
| | | return FileMode.GITLINK.equals(mode);
|
| | | }
|
| | | |
| | | public boolean isTree() {
|
| | | return FileMode.TREE.equals(mode);
|
| | | }
|
| | |
|
| | | public static PathModel getParentPath(String basePath, String commitId) {
|
| | | String parentPath = null;
|
| | | if (basePath.lastIndexOf('/') > -1) {
|
| | | parentPath = basePath.substring(0, basePath.lastIndexOf('/'));
|
| | | }
|
| | | PathModel model = new PathModel("..", parentPath, 0, 40000, commitId);
|
| | | model.isParentPath = true;
|
| | | return model;
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | if (isTree && otherTree) {
|
| | | return path.compareTo(o.path);
|
| | | } else if (!isTree && !otherTree) {
|
| | | if (isSubmodule() && o.isSubmodule()) {
|
| | | return path.compareTo(o.path);
|
| | | } else if (isSubmodule()) {
|
| | | return -1;
|
| | | } else if (o.isSubmodule()) {
|
| | | return 1;
|
| | | }
|
| | | return path.compareTo(o.path);
|
| | | } else if (isTree && !otherTree) {
|
| | | return -1;
|
| | |
| | | return 1;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 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 PathChangeModel(String name, String path, long size, int mode, String commitId,
|
| | | ChangeType type) {
|
| | | super(name, path, size, mode, commitId);
|
| | | 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;
|
| | | }
|
| | |
|