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.

RepositoryModel.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.models;
  17. import java.io.Serializable;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import java.util.TreeSet;
  24. import com.gitblit.Constants.AccessRestrictionType;
  25. import com.gitblit.Constants.AuthorizationControl;
  26. import com.gitblit.Constants.FederationStrategy;
  27. import com.gitblit.utils.ArrayUtils;
  28. import com.gitblit.utils.StringUtils;
  29. /**
  30. * RepositoryModel is a serializable model class that represents a Gitblit
  31. * repository including its configuration settings and access restriction.
  32. *
  33. * @author James Moger
  34. *
  35. */
  36. public class RepositoryModel implements Serializable, Comparable<RepositoryModel> {
  37. private static final long serialVersionUID = 1L;
  38. // field names are reflectively mapped in EditRepository page
  39. public String name;
  40. public String description;
  41. public String owner;
  42. public Date lastChange;
  43. public boolean hasCommits;
  44. public boolean showRemoteBranches;
  45. public boolean useTickets;
  46. public boolean useDocs;
  47. public AccessRestrictionType accessRestriction;
  48. public AuthorizationControl authorizationControl;
  49. public boolean allowAuthenticated;
  50. public boolean isFrozen;
  51. public boolean showReadme;
  52. public FederationStrategy federationStrategy;
  53. public List<String> federationSets;
  54. public boolean isFederated;
  55. public boolean skipSizeCalculation;
  56. public boolean skipSummaryMetrics;
  57. public String frequency;
  58. public boolean isBare;
  59. public String origin;
  60. public String HEAD;
  61. public List<String> availableRefs;
  62. public List<String> indexedBranches;
  63. public String size;
  64. public List<String> preReceiveScripts;
  65. public List<String> postReceiveScripts;
  66. public List<String> mailingLists;
  67. public Map<String, String> customFields;
  68. public String projectPath;
  69. private String displayName;
  70. public boolean allowForks;
  71. public Set<String> forks;
  72. public String originRepository;
  73. public RepositoryModel() {
  74. this("", "", "", new Date(0));
  75. }
  76. public RepositoryModel(String name, String description, String owner, Date lastchange) {
  77. this.name = name;
  78. this.description = description;
  79. this.owner = owner;
  80. this.lastChange = lastchange;
  81. this.accessRestriction = AccessRestrictionType.NONE;
  82. this.authorizationControl = AuthorizationControl.NAMED;
  83. this.federationSets = new ArrayList<String>();
  84. this.federationStrategy = FederationStrategy.FEDERATE_THIS;
  85. }
  86. public List<String> getLocalBranches() {
  87. if (ArrayUtils.isEmpty(availableRefs)) {
  88. return new ArrayList<String>();
  89. }
  90. List<String> localBranches = new ArrayList<String>();
  91. for (String ref : availableRefs) {
  92. if (ref.startsWith("refs/heads")) {
  93. localBranches.add(ref);
  94. }
  95. }
  96. return localBranches;
  97. }
  98. public void addFork(String repository) {
  99. if (forks == null) {
  100. forks = new TreeSet<String>();
  101. }
  102. forks.add(repository);
  103. }
  104. public void removeFork(String repository) {
  105. if (forks == null) {
  106. return;
  107. }
  108. forks.remove(repository);
  109. }
  110. public void resetDisplayName() {
  111. displayName = null;
  112. }
  113. @Override
  114. public String toString() {
  115. if (displayName == null) {
  116. displayName = StringUtils.stripDotGit(name);
  117. }
  118. return displayName;
  119. }
  120. @Override
  121. public int compareTo(RepositoryModel o) {
  122. return StringUtils.compareRepositoryNames(name, o.name);
  123. }
  124. public boolean isPersonalRepository() {
  125. return !StringUtils.isEmpty(projectPath) && projectPath.charAt(0) == '~';
  126. }
  127. public boolean isUsersPersonalRepository(String username) {
  128. return !StringUtils.isEmpty(projectPath) && projectPath.equalsIgnoreCase("~" + username);
  129. }
  130. public RepositoryModel cloneAs(String cloneName) {
  131. RepositoryModel clone = new RepositoryModel();
  132. clone.name = cloneName;
  133. clone.description = description;
  134. clone.accessRestriction = accessRestriction;
  135. clone.authorizationControl = authorizationControl;
  136. clone.federationStrategy = federationStrategy;
  137. clone.showReadme = showReadme;
  138. clone.showRemoteBranches = false;
  139. clone.allowForks = false;
  140. clone.useDocs = useDocs;
  141. clone.useTickets = useTickets;
  142. clone.skipSizeCalculation = skipSizeCalculation;
  143. clone.skipSummaryMetrics = skipSummaryMetrics;
  144. return clone;
  145. }
  146. }