commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
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 |
*/
|
1f9dae
|
16 |
package com.gitblit.models;
|
5fe7df
|
17 |
|
JM |
18 |
import java.io.Serializable;
|
8f73a7
|
19 |
import java.util.ArrayList;
|
661db6
|
20 |
import java.util.Collection;
|
5fe7df
|
21 |
import java.util.Date;
|
8f73a7
|
22 |
import java.util.List;
|
4a5a55
|
23 |
import java.util.Map;
|
1e1b85
|
24 |
import java.util.Set;
|
JM |
25 |
import java.util.TreeSet;
|
cca55e
|
26 |
|
dfb889
|
27 |
import com.gitblit.Constants.AccessRestrictionType;
|
6adf56
|
28 |
import com.gitblit.Constants.AuthorizationControl;
|
cd9461
|
29 |
import com.gitblit.Constants.CommitMessageRenderer;
|
831469
|
30 |
import com.gitblit.Constants.FederationStrategy;
|
e9de3f
|
31 |
import com.gitblit.utils.ArrayUtils;
|
cb946f
|
32 |
import com.gitblit.utils.ModelUtils;
|
94750e
|
33 |
import com.gitblit.utils.StringUtils;
|
dfb889
|
34 |
|
d9f687
|
35 |
/**
|
JM |
36 |
* RepositoryModel is a serializable model class that represents a Gitblit
|
|
37 |
* repository including its configuration settings and access restriction.
|
699e71
|
38 |
*
|
d9f687
|
39 |
* @author James Moger
|
699e71
|
40 |
*
|
d9f687
|
41 |
*/
|
831469
|
42 |
public class RepositoryModel implements Serializable, Comparable<RepositoryModel> {
|
5fe7df
|
43 |
|
JM |
44 |
private static final long serialVersionUID = 1L;
|
1f9dae
|
45 |
|
2a7306
|
46 |
// field names are reflectively mapped in EditRepository page
|
f5d0ad
|
47 |
public String name;
|
JM |
48 |
public String description;
|
661db6
|
49 |
public List<String> owners;
|
f5d0ad
|
50 |
public Date lastChange;
|
5c5b7a
|
51 |
public String lastChangeAuthor;
|
bc9d4a
|
52 |
public boolean hasCommits;
|
cf9550
|
53 |
public boolean showRemoteBranches;
|
0f47b2
|
54 |
public boolean useIncrementalPushTags;
|
JM |
55 |
public String incrementalPushTagPrefix;
|
dfb889
|
56 |
public AccessRestrictionType accessRestriction;
|
6adf56
|
57 |
public AuthorizationControl authorizationControl;
|
JM |
58 |
public boolean allowAuthenticated;
|
00afd7
|
59 |
public boolean isFrozen;
|
831469
|
60 |
public FederationStrategy federationStrategy;
|
8f73a7
|
61 |
public List<String> federationSets;
|
831469
|
62 |
public boolean isFederated;
|
3d293a
|
63 |
public boolean skipSizeCalculation;
|
fe3262
|
64 |
public boolean skipSummaryMetrics;
|
831469
|
65 |
public String frequency;
|
b74031
|
66 |
public boolean isBare;
|
c44dd0
|
67 |
public boolean isMirror;
|
831469
|
68 |
public String origin;
|
b74031
|
69 |
public String HEAD;
|
JM |
70 |
public List<String> availableRefs;
|
40ca5c
|
71 |
public List<String> indexedBranches;
|
831469
|
72 |
public String size;
|
fa54be
|
73 |
public List<String> preReceiveScripts;
|
JM |
74 |
public List<String> postReceiveScripts;
|
eb96ea
|
75 |
public List<String> mailingLists;
|
08d86d
|
76 |
public Map<String, String> customFields;
|
1e1b85
|
77 |
public String projectPath;
|
6c6fbf
|
78 |
private String displayName;
|
1e1b85
|
79 |
public boolean allowForks;
|
JM |
80 |
public Set<String> forks;
|
|
81 |
public String originRepository;
|
15640f
|
82 |
public boolean verifyCommitter;
|
e92c6d
|
83 |
public String gcThreshold;
|
e26d93
|
84 |
public int gcPeriod;
|
699e71
|
85 |
public int maxActivityCommits;
|
cedf13
|
86 |
public List<String> metricAuthorExclusions;
|
cd9461
|
87 |
public CommitMessageRenderer commitMessageRenderer;
|
5e3521
|
88 |
public boolean acceptNewPatchsets;
|
JM |
89 |
public boolean acceptNewTickets;
|
|
90 |
public boolean requireApproval; |
f1b882
|
91 |
public String mergeTo;
|
699e71
|
92 |
|
e92c6d
|
93 |
public transient boolean isCollectingGarbage;
|
JM |
94 |
public Date lastGC;
|
e4e682
|
95 |
public String sparkleshareId;
|
699e71
|
96 |
|
f97bf0
|
97 |
public RepositoryModel() {
|
28d6b2
|
98 |
this("", "", "", new Date(0));
|
f97bf0
|
99 |
}
|
dfb889
|
100 |
|
5fe7df
|
101 |
public RepositoryModel(String name, String description, String owner, Date lastchange) {
|
JM |
102 |
this.name = name;
|
|
103 |
this.description = description;
|
|
104 |
this.lastChange = lastchange;
|
00afd7
|
105 |
this.accessRestriction = AccessRestrictionType.NONE;
|
6adf56
|
106 |
this.authorizationControl = AuthorizationControl.NAMED;
|
4838c5
|
107 |
this.federationSets = new ArrayList<String>();
|
699e71
|
108 |
this.federationStrategy = FederationStrategy.FEDERATE_THIS;
|
20714a
|
109 |
this.projectPath = StringUtils.getFirstPathElement(name);
|
661db6
|
110 |
this.owners = new ArrayList<String>();
|
9715e1
|
111 |
this.isBare = true;
|
5e3521
|
112 |
this.acceptNewTickets = true;
|
JM |
113 |
this.acceptNewPatchsets = true;
|
699e71
|
114 |
|
661db6
|
115 |
addOwner(owner);
|
8a2e9c
|
116 |
}
|
699e71
|
117 |
|
e9de3f
|
118 |
public List<String> getLocalBranches() {
|
JM |
119 |
if (ArrayUtils.isEmpty(availableRefs)) {
|
|
120 |
return new ArrayList<String>();
|
|
121 |
}
|
|
122 |
List<String> localBranches = new ArrayList<String>();
|
|
123 |
for (String ref : availableRefs) {
|
|
124 |
if (ref.startsWith("refs/heads")) {
|
|
125 |
localBranches.add(ref);
|
|
126 |
}
|
|
127 |
}
|
|
128 |
return localBranches;
|
cca55e
|
129 |
}
|
699e71
|
130 |
|
1e1b85
|
131 |
public void addFork(String repository) {
|
JM |
132 |
if (forks == null) {
|
|
133 |
forks = new TreeSet<String>();
|
|
134 |
}
|
|
135 |
forks.add(repository);
|
|
136 |
}
|
699e71
|
137 |
|
1e1b85
|
138 |
public void removeFork(String repository) {
|
JM |
139 |
if (forks == null) {
|
|
140 |
return;
|
|
141 |
}
|
|
142 |
forks.remove(repository);
|
|
143 |
}
|
699e71
|
144 |
|
1e1b85
|
145 |
public void resetDisplayName() {
|
JM |
146 |
displayName = null;
|
5e3521
|
147 |
}
|
JM |
148 |
|
|
149 |
public String getRID() {
|
|
150 |
return StringUtils.getSHA1(name);
|
1e1b85
|
151 |
}
|
699e71
|
152 |
|
e94078
|
153 |
@Override
|
JM |
154 |
public int hashCode() {
|
|
155 |
return name.hashCode();
|
|
156 |
}
|
699e71
|
157 |
|
e94078
|
158 |
@Override
|
JM |
159 |
public boolean equals(Object o) {
|
|
160 |
if (o instanceof RepositoryModel) {
|
|
161 |
return name.equals(((RepositoryModel) o).name);
|
|
162 |
}
|
|
163 |
return false;
|
|
164 |
}
|
2a7306
|
165 |
|
8a2e9c
|
166 |
@Override
|
JM |
167 |
public String toString() {
|
6c6fbf
|
168 |
if (displayName == null) {
|
JM |
169 |
displayName = StringUtils.stripDotGit(name);
|
|
170 |
}
|
|
171 |
return displayName;
|
8a2e9c
|
172 |
}
|
831469
|
173 |
|
JM |
174 |
@Override
|
|
175 |
public int compareTo(RepositoryModel o) {
|
94750e
|
176 |
return StringUtils.compareRepositoryNames(name, o.name);
|
831469
|
177 |
}
|
699e71
|
178 |
|
e0af48
|
179 |
public boolean isFork() {
|
JM |
180 |
return !StringUtils.isEmpty(originRepository);
|
|
181 |
}
|
699e71
|
182 |
|
ec0ce1
|
183 |
public boolean isOwner(String username) {
|
661db6
|
184 |
if (StringUtils.isEmpty(username) || ArrayUtils.isEmpty(owners)) {
|
0c8b28
|
185 |
return isUsersPersonalRepository(username);
|
661db6
|
186 |
}
|
0c8b28
|
187 |
return owners.contains(username.toLowerCase()) || isUsersPersonalRepository(username);
|
ec0ce1
|
188 |
}
|
699e71
|
189 |
|
1e1b85
|
190 |
public boolean isPersonalRepository() {
|
cb946f
|
191 |
return !StringUtils.isEmpty(projectPath) && ModelUtils.isPersonalRepository(projectPath);
|
1e1b85
|
192 |
}
|
699e71
|
193 |
|
1e1b85
|
194 |
public boolean isUsersPersonalRepository(String username) {
|
cb946f
|
195 |
return !StringUtils.isEmpty(projectPath) && ModelUtils.isUsersPersonalRepository(username, projectPath);
|
1e1b85
|
196 |
}
|
699e71
|
197 |
|
e94078
|
198 |
public boolean allowAnonymousView() {
|
JM |
199 |
return !accessRestriction.atLeast(AccessRestrictionType.VIEW);
|
|
200 |
}
|
699e71
|
201 |
|
9b26b7
|
202 |
public boolean isShowActivity() {
|
JM |
203 |
return maxActivityCommits > -1;
|
|
204 |
}
|
699e71
|
205 |
|
e4e682
|
206 |
public boolean isSparkleshared() {
|
JM |
207 |
return !StringUtils.isEmpty(sparkleshareId);
|
|
208 |
}
|
699e71
|
209 |
|
1e1b85
|
210 |
public RepositoryModel cloneAs(String cloneName) {
|
JM |
211 |
RepositoryModel clone = new RepositoryModel();
|
1f52c8
|
212 |
clone.originRepository = name;
|
1e1b85
|
213 |
clone.name = cloneName;
|
1f52c8
|
214 |
clone.projectPath = StringUtils.getFirstPathElement(cloneName);
|
JM |
215 |
clone.isBare = true;
|
1e1b85
|
216 |
clone.description = description;
|
20714a
|
217 |
clone.accessRestriction = AccessRestrictionType.PUSH;
|
JM |
218 |
clone.authorizationControl = AuthorizationControl.NAMED;
|
1e1b85
|
219 |
clone.federationStrategy = federationStrategy;
|
JM |
220 |
clone.showRemoteBranches = false;
|
|
221 |
clone.allowForks = false;
|
5e3521
|
222 |
clone.acceptNewPatchsets = false;
|
JM |
223 |
clone.acceptNewTickets = false; |
1e1b85
|
224 |
clone.skipSizeCalculation = skipSizeCalculation;
|
JM |
225 |
clone.skipSummaryMetrics = skipSummaryMetrics;
|
699e71
|
226 |
clone.sparkleshareId = sparkleshareId;
|
1e1b85
|
227 |
return clone;
|
JM |
228 |
}
|
fb9813
|
229 |
|
661db6
|
230 |
public void addOwner(String username) {
|
JM |
231 |
if (!StringUtils.isEmpty(username)) {
|
|
232 |
String name = username.toLowerCase();
|
|
233 |
// a set would be more efficient, but this complicates JSON
|
|
234 |
// deserialization so we enforce uniqueness with an arraylist
|
|
235 |
if (!owners.contains(name)) {
|
|
236 |
owners.add(name);
|
fb9813
|
237 |
}
|
S |
238 |
}
|
|
239 |
}
|
|
240 |
|
661db6
|
241 |
public void removeOwner(String username) {
|
JM |
242 |
if (!StringUtils.isEmpty(username)) {
|
|
243 |
owners.remove(username.toLowerCase());
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
public void addOwners(Collection<String> usernames) {
|
|
248 |
if (!ArrayUtils.isEmpty(usernames)) {
|
|
249 |
for (String username : usernames) {
|
|
250 |
addOwner(username);
|
fb9813
|
251 |
}
|
S |
252 |
}
|
|
253 |
}
|
|
254 |
|
661db6
|
255 |
public void removeOwners(Collection<String> usernames) {
|
JM |
256 |
if (!ArrayUtils.isEmpty(owners)) {
|
|
257 |
for (String username : usernames) {
|
|
258 |
removeOwner(username);
|
|
259 |
}
|
fb9813
|
260 |
}
|
S |
261 |
}
|
1613f4
|
262 |
} |