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.

IRepositoryManager.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * Copyright 2013 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.manager;
  17. import java.io.File;
  18. import java.util.Collection;
  19. import java.util.Date;
  20. import java.util.List;
  21. import org.eclipse.jgit.lib.Repository;
  22. import com.gitblit.GitBlitException;
  23. import com.gitblit.models.ForkModel;
  24. import com.gitblit.models.Metric;
  25. import com.gitblit.models.RegistrantAccessPermission;
  26. import com.gitblit.models.RepositoryModel;
  27. import com.gitblit.models.SearchResult;
  28. import com.gitblit.models.UserModel;
  29. public interface IRepositoryManager extends IManager {
  30. /**
  31. * Returns the path of the repositories folder. This method checks to see if
  32. * Gitblit is running on a cloud service and may return an adjusted path.
  33. *
  34. * @return the repositories folder path
  35. * @since 1.4.0
  36. */
  37. File getRepositoriesFolder();
  38. /**
  39. * Returns the path of the hooks folder. This method checks to see if
  40. * Gitblit is running on a cloud service and may return an adjusted path.
  41. *
  42. * @return the Groovy hook scripts folder path
  43. * @since 1.4.0
  44. */
  45. File getHooksFolder();
  46. /**
  47. * Returns the path of the grapes folder. This method checks to see if
  48. * Gitblit is running on a cloud service and may return an adjusted path.
  49. *
  50. * @return the Groovy grapes folder path
  51. * @since 1.4.0
  52. */
  53. File getGrapesFolder();
  54. /**
  55. * Returns the most recent change date of any repository served by Gitblit.
  56. *
  57. * @return a date
  58. * @since 1.4.0
  59. */
  60. Date getLastActivityDate();
  61. /**
  62. * Returns the effective list of permissions for this user, taking into account
  63. * team memberships, ownerships.
  64. *
  65. * @param user
  66. * @return the effective list of permissions for the user
  67. * @since 1.4.0
  68. */
  69. List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user);
  70. /**
  71. * Returns the list of users and their access permissions for the specified
  72. * repository including permission source information such as the team or
  73. * regular expression which sets the permission.
  74. *
  75. * @param repository
  76. * @return a list of RegistrantAccessPermissions
  77. * @since 1.4.0
  78. */
  79. List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository);
  80. /**
  81. * Sets the access permissions to the specified repository for the specified users.
  82. *
  83. * @param repository
  84. * @param permissions
  85. * @return true if the user models have been updated
  86. * @since 1.4.0
  87. */
  88. boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
  89. /**
  90. * Returns the list of all users who have an explicit access permission
  91. * for the specified repository.
  92. *
  93. * @see IUserService.getUsernamesForRepositoryRole(String)
  94. * @param repository
  95. * @return list of all usernames that have an access permission for the repository
  96. * @since 1.4.0
  97. */
  98. List<String> getRepositoryUsers(RepositoryModel repository);
  99. /**
  100. * Returns the list of teams and their access permissions for the specified
  101. * repository including the source of the permission such as the admin flag
  102. * or a regular expression.
  103. *
  104. * @param repository
  105. * @return a list of RegistrantAccessPermissions
  106. * @since 1.4.0
  107. */
  108. List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository);
  109. /**
  110. * Sets the access permissions to the specified repository for the specified teams.
  111. *
  112. * @param repository
  113. * @param permissions
  114. * @return true if the team models have been updated
  115. * @since 1.4.0
  116. */
  117. boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
  118. /**
  119. * Returns the list of all teams who have an explicit access permission for
  120. * the specified repository.
  121. *
  122. * @see IUserService.getTeamnamesForRepositoryRole(String)
  123. * @param repository
  124. * @return list of all teamnames with explicit access permissions to the repository
  125. * @since 1.4.0
  126. */
  127. List<String> getRepositoryTeams(RepositoryModel repository);
  128. /**
  129. * Adds the repository to the list of cached repositories if Gitblit is
  130. * configured to cache the repository list.
  131. *
  132. * @param model
  133. * @since 1.4.0
  134. */
  135. void addToCachedRepositoryList(RepositoryModel model);
  136. /**
  137. * Resets the repository list cache.
  138. *
  139. * @since 1.4.0
  140. *
  141. */
  142. void resetRepositoryListCache();
  143. /**
  144. * Reset all caches for this repository.
  145. *
  146. * @param repositoryName
  147. * @since 1.5.1
  148. */
  149. void resetRepositoryCache(String repositoryName);
  150. /**
  151. * Returns the list of all repositories available to Gitblit. This method
  152. * does not consider user access permissions.
  153. *
  154. * @return list of all repositories
  155. * @since 1.4.0
  156. */
  157. List<String> getRepositoryList();
  158. /**
  159. * Returns the JGit repository for the specified name.
  160. *
  161. * @param repositoryName
  162. * @return repository or null
  163. * @since 1.4.0
  164. */
  165. Repository getRepository(String repositoryName);
  166. /**
  167. * Returns the JGit repository for the specified name.
  168. *
  169. * @param repositoryName
  170. * @param logError
  171. * @return repository or null
  172. * @since 1.4.0
  173. */
  174. Repository getRepository(String repositoryName, boolean logError);
  175. /**
  176. * Returns the list of repository models that are accessible to the user.
  177. *
  178. * @param user
  179. * @return list of repository models accessible to user
  180. * @since 1.4.0
  181. */
  182. List<RepositoryModel> getRepositoryModels(UserModel user);
  183. /**
  184. * Returns a repository model if the repository exists and the user may
  185. * access the repository.
  186. *
  187. * @param user
  188. * @param repositoryName
  189. * @return repository model or null
  190. * @since 1.4.0
  191. */
  192. RepositoryModel getRepositoryModel(UserModel user, String repositoryName);
  193. /**
  194. * Returns the repository model for the specified repository. This method
  195. * does not consider user access permissions.
  196. *
  197. * @param repositoryName
  198. * @return repository model or null
  199. * @since 1.4.0
  200. */
  201. RepositoryModel getRepositoryModel(String repositoryName);
  202. /**
  203. * Returns the star count of the repository.
  204. *
  205. * @param repository
  206. * @return the star count
  207. * @since 1.4.0
  208. */
  209. long getStarCount(RepositoryModel repository);
  210. /**
  211. * Determines if this server has the requested repository.
  212. *
  213. * @param n
  214. * @return true if the repository exists
  215. * @since 1.4.0
  216. */
  217. boolean hasRepository(String repositoryName);
  218. /**
  219. * Determines if this server has the requested repository.
  220. *
  221. * @param n
  222. * @param caseInsensitive
  223. * @return true if the repository exists
  224. * @since 1.4.0
  225. */
  226. boolean hasRepository(String repositoryName, boolean caseSensitiveCheck);
  227. /**
  228. * Determines if the specified user has a fork of the specified origin
  229. * repository.
  230. *
  231. * @param username
  232. * @param origin
  233. * @return true the if the user has a fork
  234. * @since 1.4.0
  235. */
  236. boolean hasFork(String username, String origin);
  237. /**
  238. * Gets the name of a user's fork of the specified origin
  239. * repository.
  240. *
  241. * @param username
  242. * @param origin
  243. * @return the name of the user's fork, null otherwise
  244. * @since 1.4.0
  245. */
  246. String getFork(String username, String origin);
  247. /**
  248. * Returns the fork network for a repository by traversing up the fork graph
  249. * to discover the root and then down through all children of the root node.
  250. *
  251. * @param repository
  252. * @return a ForkModel
  253. * @since 1.4.0
  254. */
  255. ForkModel getForkNetwork(String repository);
  256. /**
  257. * Updates the last changed fields and optionally calculates the size of the
  258. * repository. Gitblit caches the repository sizes to reduce the performance
  259. * penalty of recursive calculation. The cache is updated if the repository
  260. * has been changed since the last calculation.
  261. *
  262. * @param model
  263. * @return size in bytes of the repository
  264. * @since 1.4.0
  265. */
  266. long updateLastChangeFields(Repository r, RepositoryModel model);
  267. /**
  268. * Returns the metrics for the default branch of the specified repository.
  269. * This method builds a metrics cache. The cache is updated if the
  270. * repository is updated. A new copy of the metrics list is returned on each
  271. * call so that modifications to the list are non-destructive.
  272. *
  273. * @param model
  274. * @param repository
  275. * @return a new array list of metrics
  276. * @since 1.4.0
  277. */
  278. List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository);
  279. /**
  280. * Creates/updates the repository model keyed by reopsitoryName. Saves all
  281. * repository settings in .git/config. This method allows for renaming
  282. * repositories and will update user access permissions accordingly.
  283. *
  284. * All repositories created by this method are bare and automatically have
  285. * .git appended to their names, which is the standard convention for bare
  286. * repositories.
  287. *
  288. * @param repositoryName
  289. * @param repository
  290. * @param isCreate
  291. * @throws GitBlitException
  292. * @since 1.4.0
  293. */
  294. void updateRepositoryModel(String repositoryName, RepositoryModel repository, boolean isCreate)
  295. throws GitBlitException;
  296. /**
  297. * Updates the Gitblit configuration for the specified repository.
  298. *
  299. * @param r
  300. * the Git repository
  301. * @param repository
  302. * the Gitblit repository model
  303. * @since 1.4.0
  304. */
  305. void updateConfiguration(Repository r, RepositoryModel repository);
  306. /**
  307. * Deletes the repository from the file system and removes the repository
  308. * permission from all repository users.
  309. *
  310. * @param model
  311. * @return true if successful
  312. * @since 1.4.0
  313. */
  314. boolean deleteRepositoryModel(RepositoryModel model);
  315. /**
  316. * Deletes the repository from the file system and removes the repository
  317. * permission from all repository users.
  318. *
  319. * @param repositoryName
  320. * @return true if successful
  321. * @since 1.4.0
  322. */
  323. boolean deleteRepository(String repositoryName);
  324. /**
  325. * Returns the list of all Groovy push hook scripts. Script files must have
  326. * .groovy extension
  327. *
  328. * @return list of available hook scripts
  329. * @since 1.4.0
  330. */
  331. List<String> getAllScripts();
  332. /**
  333. * Returns the list of pre-receive scripts the repository inherited from the
  334. * global settings and team affiliations.
  335. *
  336. * @param repository
  337. * if null only the globally specified scripts are returned
  338. * @return a list of scripts
  339. * @since 1.4.0
  340. */
  341. List<String> getPreReceiveScriptsInherited(RepositoryModel repository);
  342. /**
  343. * Returns the list of all available Groovy pre-receive push hook scripts
  344. * that are not already inherited by the repository. Script files must have
  345. * .groovy extension
  346. *
  347. * @param repository
  348. * optional parameter
  349. * @return list of available hook scripts
  350. * @since 1.4.0
  351. */
  352. List<String> getPreReceiveScriptsUnused(RepositoryModel repository);
  353. /**
  354. * Returns the list of post-receive scripts the repository inherited from
  355. * the global settings and team affiliations.
  356. *
  357. * @param repository
  358. * if null only the globally specified scripts are returned
  359. * @return a list of scripts
  360. * @since 1.4.0
  361. */
  362. List<String> getPostReceiveScriptsInherited(RepositoryModel repository);
  363. /**
  364. * Returns the list of unused Groovy post-receive push hook scripts that are
  365. * not already inherited by the repository. Script files must have .groovy
  366. * extension
  367. *
  368. * @param repository
  369. * optional parameter
  370. * @return list of available hook scripts
  371. * @since 1.4.0
  372. */
  373. List<String> getPostReceiveScriptsUnused(RepositoryModel repository);
  374. /**
  375. * Search the specified repositories using the Lucene query.
  376. *
  377. * @param query
  378. * @param page
  379. * @param pageSize
  380. * @param repositories
  381. * @return a list of search results
  382. * @since 1.4.0
  383. */
  384. List<SearchResult> search(String query, int page, int pageSize, List<String> repositories);
  385. /**
  386. *
  387. * @return true if we are running the gc executor
  388. * @since 1.4.0
  389. */
  390. boolean isCollectingGarbage();
  391. /**
  392. * Returns true if Gitblit is actively collecting garbage in this repository.
  393. *
  394. * @param repositoryName
  395. * @return true if actively collecting garbage
  396. * @since 1.4.0
  397. */
  398. boolean isCollectingGarbage(String repositoryName);
  399. /**
  400. * Ensures that all cached repositories are completely closed and their resources
  401. * are properly released.
  402. * @since 1.4.0
  403. */
  404. void closeAll();
  405. /**
  406. * Ensures that a cached repository is completely closed and it's resources
  407. * are properly released.
  408. * @since 1.4.0
  409. */
  410. void close(String repository);
  411. /**
  412. * Returns true if the repository is idle (not being accessed).
  413. *
  414. * @param repository
  415. * @return true if the repository is idle
  416. * @since 1.4.0
  417. */
  418. boolean isIdle(Repository repository);
  419. }