Example usage for org.eclipse.jgit.storage.file FileBasedConfig isOutdated

List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig isOutdated

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileBasedConfig isOutdated.

Prototype

public boolean isOutdated() 

Source Link

Document

Whether the currently loaded configuration file is outdated

Usage

From source file:com.gitblit.GitBlit.java

License:Apache License

/**
 * Returns the repository model for the specified repository. This method
 * does not consider user access permissions.
 * //from  w w  w.j a v a 2  s  .c o m
 * @param repositoryName
 * @return repository model or null
 */
public RepositoryModel getRepositoryModel(String repositoryName) {
    if (!repositoryListCache.containsKey(repositoryName)) {
        RepositoryModel model = loadRepositoryModel(repositoryName);
        if (model == null) {
            return null;
        }
        addToCachedRepositoryList(repositoryName, model);
        return model;
    }

    // cached model
    RepositoryModel model = repositoryListCache.get(repositoryName);

    // check for updates
    Repository r = getRepository(repositoryName);
    if (r == null) {
        // repository is missing
        removeFromCachedRepositoryList(repositoryName);
        logger.error(
                MessageFormat.format("Repository \"{0}\" is missing! Removing from cache.", repositoryName));
        return null;
    }

    FileBasedConfig config = (FileBasedConfig) getRepositoryConfig(r);
    if (config.isOutdated()) {
        // reload model
        logger.info(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.",
                repositoryName));
        model = loadRepositoryModel(repositoryName);
        removeFromCachedRepositoryList(repositoryName);
        addToCachedRepositoryList(repositoryName, model);
    } else {
        // update a few repository parameters 
        if (!model.hasCommits) {
            // update hasCommits, assume a repository only gains commits :)
            model.hasCommits = JGitUtils.hasCommits(r);
        }

        model.lastChange = JGitUtils.getLastChange(r);
    }
    r.close();

    // return a copy of the cached model
    return DeepCopier.copy(model);
}

From source file:com.gitblit.manager.RepositoryManager.java

License:Apache License

/**
 * Returns the repository model for the specified repository. This method
 * does not consider user access permissions.
 *
 * @param name/*w  w w . ja  v a  2  s.c  om*/
 * @return repository model or null
 */
@Override
public RepositoryModel getRepositoryModel(String name) {
    String repositoryName = fixRepositoryName(name);

    String repositoryKey = getRepositoryKey(repositoryName);
    if (!repositoryListCache.containsKey(repositoryKey)) {
        RepositoryModel model = loadRepositoryModel(repositoryName);
        if (model == null) {
            return null;
        }
        addToCachedRepositoryList(model);
        return DeepCopier.copy(model);
    }

    // cached model
    RepositoryModel model = repositoryListCache.get(repositoryKey);

    if (isCollectingGarbage(model.name)) {
        // Gitblit is busy collecting garbage, use our cached model
        RepositoryModel rm = DeepCopier.copy(model);
        rm.isCollectingGarbage = true;
        return rm;
    }

    // check for updates
    Repository r = getRepository(model.name);
    if (r == null) {
        // repository is missing
        removeFromCachedRepositoryList(repositoryName);
        logger.error(
                MessageFormat.format("Repository \"{0}\" is missing! Removing from cache.", repositoryName));
        return null;
    }

    FileBasedConfig config = (FileBasedConfig) getRepositoryConfig(r);
    if (config.isOutdated()) {
        // reload model
        logger.debug(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.",
                repositoryName));
        model = loadRepositoryModel(model.name);
        removeFromCachedRepositoryList(model.name);
        addToCachedRepositoryList(model);
    } else {
        // update a few repository parameters
        if (!model.hasCommits) {
            // update hasCommits, assume a repository only gains commits :)
            model.hasCommits = JGitUtils.hasCommits(r);
        }

        updateLastChangeFields(r, model);
    }
    r.close();

    // return a copy of the cached model
    return DeepCopier.copy(model);
}