You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PathModel.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.models;
  17. import java.io.Serializable;
  18. import org.eclipse.jgit.diff.DiffEntry.ChangeType;
  19. import com.gitblit.utils.JGitUtils;
  20. public class PathModel implements Serializable, Comparable<PathModel> {
  21. private static final long serialVersionUID = 1L;
  22. public final String name;
  23. public final String path;
  24. public final long size;
  25. public final int mode;
  26. public final String commitId;
  27. public boolean isParentPath;
  28. public PathModel(String name, String path, long size, int mode, String commitId) {
  29. this.name = name;
  30. this.path = path;
  31. this.size = size;
  32. this.mode = mode;
  33. this.commitId = commitId;
  34. }
  35. public boolean isTree() {
  36. return JGitUtils.isTreeFromMode(mode);
  37. }
  38. public static PathModel getParentPath(String basePath, String commitId) {
  39. String parentPath = null;
  40. if (basePath.lastIndexOf('/') > -1) {
  41. parentPath = basePath.substring(0, basePath.lastIndexOf('/'));
  42. }
  43. PathModel model = new PathModel("..", parentPath, 0, 0040000, commitId);
  44. model.isParentPath = true;
  45. return model;
  46. }
  47. @Override
  48. public int compareTo(PathModel o) {
  49. boolean isTree = isTree();
  50. boolean otherTree = o.isTree();
  51. if (isTree && otherTree) {
  52. return path.compareTo(o.path);
  53. } else if (!isTree && !otherTree) {
  54. return path.compareTo(o.path);
  55. } else if (isTree && !otherTree) {
  56. return -1;
  57. }
  58. return 1;
  59. }
  60. public static class PathChangeModel extends PathModel {
  61. private static final long serialVersionUID = 1L;
  62. public final ChangeType changeType;
  63. public PathChangeModel(String name, String path, long size, int mode, String commitId, ChangeType type) {
  64. super(name, path, size, mode, commitId);
  65. this.changeType = type;
  66. }
  67. }
  68. }