| | |
| | | } |
| | | return gitblit; |
| | | } |
| | | |
| | | /** |
| | | * Returns the boot date of the Gitblit server. |
| | | * |
| | | * @return the boot date of Gitblit |
| | | */ |
| | | public static Date getBootDate() { |
| | | return self().serverStatus.bootDate; |
| | | } |
| | | |
| | | /** |
| | | * Returns the most recent change date of any repository served by Gitblit. |
| | | * |
| | | * @return a date |
| | | */ |
| | | public static Date getLastActivityDate() { |
| | | Date date = null; |
| | | for (String name : self().getRepositoryList()) { |
| | | Repository r = self().getRepository(name); |
| | | Date lastChange = JGitUtils.getLastChange(r).when; |
| | | r.close(); |
| | | if (lastChange != null && (date == null || lastChange.after(date))) { |
| | | date = lastChange; |
| | | } |
| | | } |
| | | return date; |
| | | } |
| | | |
| | | /** |
| | | * Determine if this is the GO variant of Gitblit. |
| | |
| | | } else { |
| | | // we are caching this list |
| | | String msg = "{0} repositories identified in {1} msecs"; |
| | | |
| | | // optionally (re)calculate repository sizes |
| | | if (getBoolean(Keys.web.showRepositorySizes, true)) { |
| | | ByteFormat byteFormat = new ByteFormat(); |
| | | // optionally (re)calculate repository sizes |
| | | msg = "{0} repositories identified with calculated folder sizes in {1} msecs"; |
| | | for (String repository : repositories) { |
| | | RepositoryModel model = getRepositoryModel(repository); |
| | | if (!model.skipSizeCalculation) { |
| | | model.size = byteFormat.format(calculateSize(model)); |
| | | } |
| | | } |
| | | } else { |
| | | // update cache |
| | | for (String repository : repositories) { |
| | | getRepositoryModel(repository); |
| | | } |
| | | } |
| | | |
| | | for (String repository : repositories) { |
| | | getRepositoryModel(repository); |
| | | } |
| | | |
| | | // rebuild fork networks |
| | |
| | | * @return repository or null |
| | | */ |
| | | public Repository getRepository(String repositoryName, boolean logError) { |
| | | // Decode url-encoded repository name (issue-278) |
| | | // http://stackoverflow.com/questions/17183110 |
| | | repositoryName = repositoryName.replace("%7E", "~").replace("%7e", "~"); |
| | | |
| | | if (isCollectingGarbage(repositoryName)) { |
| | | logger.warn(MessageFormat.format("Rejecting request for {0}, busy collecting garbage!", repositoryName)); |
| | | return null; |
| | |
| | | } |
| | | } |
| | | } |
| | | if (getBoolean(Keys.web.showRepositorySizes, true)) { |
| | | int repoCount = 0; |
| | | long startTime = System.currentTimeMillis(); |
| | | ByteFormat byteFormat = new ByteFormat(); |
| | | for (RepositoryModel model : repositories) { |
| | | if (!model.skipSizeCalculation) { |
| | | repoCount++; |
| | | model.size = byteFormat.format(calculateSize(model)); |
| | | } |
| | | } |
| | | long duration = System.currentTimeMillis() - startTime; |
| | | if (duration > 250) { |
| | | // only log calcualtion time if > 250 msecs |
| | | logger.info(MessageFormat.format("{0} repository sizes calculated in {1} msecs", |
| | | repoCount, duration)); |
| | | } |
| | | } |
| | | long duration = System.currentTimeMillis() - methodStart; |
| | | logger.info(MessageFormat.format("{0} repository models loaded for {1} in {2} msecs", |
| | | repositories.size(), user == null ? "anonymous" : user.username, duration)); |
| | |
| | | * @return repository model or null |
| | | */ |
| | | public RepositoryModel getRepositoryModel(String repositoryName) { |
| | | // Decode url-encoded repository name (issue-278) |
| | | // http://stackoverflow.com/questions/17183110 |
| | | repositoryName = repositoryName.replace("%7E", "~").replace("%7e", "~"); |
| | | |
| | | if (!repositoryListCache.containsKey(repositoryName)) { |
| | | RepositoryModel model = loadRepositoryModel(repositoryName); |
| | | if (model == null) { |
| | | return null; |
| | | } |
| | | addToCachedRepositoryList(model); |
| | | return model; |
| | | return DeepCopier.copy(model); |
| | | } |
| | | |
| | | // cached model |
| | |
| | | model.hasCommits = JGitUtils.hasCommits(r); |
| | | } |
| | | |
| | | LastChange lc = JGitUtils.getLastChange(r); |
| | | model.lastChange = lc.when; |
| | | model.lastChangeAuthor = lc.who; |
| | | if (!model.skipSizeCalculation) { |
| | | ByteFormat byteFormat = new ByteFormat(); |
| | | model.size = byteFormat.format(calculateSize(model)); |
| | | } |
| | | updateLastChangeFields(r, model); |
| | | } |
| | | r.close(); |
| | | |
| | |
| | | // is symlinked. Use the provided repository name. |
| | | model.name = repositoryName; |
| | | } |
| | | model.hasCommits = JGitUtils.hasCommits(r); |
| | | LastChange lc = JGitUtils.getLastChange(r); |
| | | model.lastChange = lc.when; |
| | | model.lastChangeAuthor = lc.who; |
| | | model.projectPath = StringUtils.getFirstPathElement(repositoryName); |
| | | |
| | | StoredConfig config = r.getConfig(); |
| | |
| | | model.HEAD = JGitUtils.getHEADRef(r); |
| | | model.availableRefs = JGitUtils.getAvailableHeadTargets(r); |
| | | model.sparkleshareId = JGitUtils.getSparkleshareId(r); |
| | | model.hasCommits = JGitUtils.hasCommits(r); |
| | | updateLastChangeFields(r, model); |
| | | r.close(); |
| | | |
| | | if (StringUtils.isEmpty(model.originRepository) && model.origin != null && model.origin.startsWith("file://")) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the size in bytes of the repository. Gitblit caches the |
| | | * repository sizes to reduce the performance penalty of recursive |
| | | * calculation. The cache is updated if the repository has been changed |
| | | * since the last calculation. |
| | | * Updates the last changed fields and optionally calculates the size of the |
| | | * repository. Gitblit caches the repository sizes to reduce the performance |
| | | * penalty of recursive calculation. The cache is updated if the repository |
| | | * has been changed since the last calculation. |
| | | * |
| | | * @param model |
| | | * @return size in bytes |
| | | * @return size in bytes of the repository |
| | | */ |
| | | public long calculateSize(RepositoryModel model) { |
| | | if (repositorySizeCache.hasCurrent(model.name, model.lastChange)) { |
| | | return repositorySizeCache.getObject(model.name); |
| | | public long updateLastChangeFields(Repository r, RepositoryModel model) { |
| | | LastChange lc = JGitUtils.getLastChange(r); |
| | | model.lastChange = lc.when; |
| | | model.lastChangeAuthor = lc.who; |
| | | |
| | | if (!getBoolean(Keys.web.showRepositorySizes, true) || model.skipSizeCalculation) { |
| | | model.size = null; |
| | | return 0L; |
| | | } |
| | | File gitDir = FileKey.resolve(new File(repositoriesFolder, model.name), FS.DETECTED); |
| | | long size = com.gitblit.utils.FileUtils.folderSize(gitDir); |
| | | repositorySizeCache.updateObject(model.name, model.lastChange, size); |
| | | if (!repositorySizeCache.hasCurrent(model.name, model.lastChange)) { |
| | | File gitDir = r.getDirectory(); |
| | | long sz = com.gitblit.utils.FileUtils.folderSize(gitDir); |
| | | repositorySizeCache.updateObject(model.name, model.lastChange, sz); |
| | | } |
| | | long size = repositorySizeCache.getObject(model.name); |
| | | ByteFormat byteFormat = new ByteFormat(); |
| | | model.size = byteFormat.format(size); |
| | | return size; |
| | | } |
| | | |