Example usage for org.eclipse.jgit.storage.file WindowCacheConfig setPackedGitMMAP

List of usage examples for org.eclipse.jgit.storage.file WindowCacheConfig setPackedGitMMAP

Introduction

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

Prototype

public void setPackedGitMMAP(boolean usemmap) 

Source Link

Document

Set whether to enable use of Java NIO virtual memory mapping for windows

Usage

From source file:com.gitblit.GitBlit.java

License:Apache License

/**
 * Configure the Gitblit singleton with the specified settings source. This
 * source may be file settings (Gitblit GO) or may be web.xml settings
 * (Gitblit WAR)./*from  w  w  w  .j a v a 2s. c  om*/
 * 
 * @param settings
 */
public void configureContext(IStoredSettings settings, boolean startFederation) {
    logger.info("Reading configuration from " + settings.toString());
    this.settings = settings;
    repositoriesFolder = getRepositoriesFolder();
    logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());
    repositoryResolver = new FileResolver<Void>(repositoriesFolder, true);

    // calculate repository list settings checksum for future config changes
    repositoryListSettingsChecksum.set(getRepositoryListSettingsChecksum());

    // build initial repository list
    if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
        logger.info("Identifying available repositories...");
        getRepositoryList();
    }

    logTimezone("JVM", TimeZone.getDefault());
    logTimezone(Constants.NAME, getTimezone());

    serverStatus = new ServerStatus(isGO());
    String realm = settings.getString(Keys.realm.userService, "users.properties");
    IUserService loginService = null;
    try {
        // check to see if this "file" is a login service class
        Class<?> realmClass = Class.forName(realm);
        loginService = (IUserService) realmClass.newInstance();
    } catch (Throwable t) {
        loginService = new GitblitUserService();
    }
    setUserService(loginService);

    // load and cache the project metadata
    projectConfigs = new FileBasedConfig(getFileOrFolder(Keys.web.projectsFile, "projects.conf"), FS.detect());
    getProjectConfigs();

    mailExecutor = new MailExecutor(settings);
    if (mailExecutor.isReady()) {
        logger.info("Mail executor is scheduled to process the message queue every 2 minutes.");
        scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, 2, TimeUnit.MINUTES);
    } else {
        logger.warn("Mail server is not properly configured.  Mail services disabled.");
    }
    luceneExecutor = new LuceneExecutor(settings, repositoriesFolder);
    logger.info("Lucene executor is scheduled to process indexed branches every 2 minutes.");
    scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, 2, TimeUnit.MINUTES);
    if (startFederation) {
        configureFederation();
    }

    // Configure JGit
    WindowCacheConfig cfg = new WindowCacheConfig();

    cfg.setPackedGitWindowSize(
            settings.getFilesize(Keys.git.packedGitWindowSize, cfg.getPackedGitWindowSize()));
    cfg.setPackedGitLimit(settings.getFilesize(Keys.git.packedGitLimit, cfg.getPackedGitLimit()));
    cfg.setDeltaBaseCacheLimit(
            settings.getFilesize(Keys.git.deltaBaseCacheLimit, cfg.getDeltaBaseCacheLimit()));
    cfg.setPackedGitOpenFiles(settings.getFilesize(Keys.git.packedGitOpenFiles, cfg.getPackedGitOpenFiles()));
    cfg.setStreamFileThreshold(
            settings.getFilesize(Keys.git.streamFileThreshold, cfg.getStreamFileThreshold()));
    cfg.setPackedGitMMAP(settings.getBoolean(Keys.git.packedGitMmap, cfg.isPackedGitMMAP()));

    try {
        WindowCache.reconfigure(cfg);
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitWindowSize,
                cfg.getPackedGitWindowSize()));
        logger.debug(
                MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitLimit, cfg.getPackedGitLimit()));
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.deltaBaseCacheLimit,
                cfg.getDeltaBaseCacheLimit()));
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitOpenFiles,
                cfg.getPackedGitOpenFiles()));
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.streamFileThreshold,
                cfg.getStreamFileThreshold()));
        logger.debug(MessageFormat.format("{0} = {1}", Keys.git.packedGitMmap, cfg.isPackedGitMMAP()));
    } catch (IllegalArgumentException e) {
        logger.error("Failed to configure JGit parameters!", e);
    }

    ContainerUtils.CVE_2007_0450.test();
}

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

License:Apache License

protected void configureJGit() {
    // Configure JGit
    WindowCacheConfig cfg = new WindowCacheConfig();

    cfg.setPackedGitWindowSize(/*ww  w.  j a va2s . c om*/
            settings.getFilesize(Keys.git.packedGitWindowSize, cfg.getPackedGitWindowSize()));
    cfg.setPackedGitLimit(settings.getFilesize(Keys.git.packedGitLimit, cfg.getPackedGitLimit()));
    cfg.setDeltaBaseCacheLimit(
            settings.getFilesize(Keys.git.deltaBaseCacheLimit, cfg.getDeltaBaseCacheLimit()));
    cfg.setPackedGitOpenFiles(settings.getInteger(Keys.git.packedGitOpenFiles, cfg.getPackedGitOpenFiles()));
    cfg.setPackedGitMMAP(settings.getBoolean(Keys.git.packedGitMmap, cfg.isPackedGitMMAP()));

    try {
        cfg.install();
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitWindowSize,
                cfg.getPackedGitWindowSize()));
        logger.debug(
                MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitLimit, cfg.getPackedGitLimit()));
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.deltaBaseCacheLimit,
                cfg.getDeltaBaseCacheLimit()));
        logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitOpenFiles,
                cfg.getPackedGitOpenFiles()));
        logger.debug(MessageFormat.format("{0} = {1}", Keys.git.packedGitMmap, cfg.isPackedGitMMAP()));
    } catch (IllegalArgumentException e) {
        logger.error("Failed to configure JGit parameters!", e);
    }

    try {
        // issue-486/ticket-151: UTF-9 & UTF-18
        // issue-560/ticket-237: 'UTF8'
        Field field = RawParseUtils.class.getDeclaredField("encodingAliases");
        field.setAccessible(true);
        Map<String, Charset> encodingAliases = (Map<String, Charset>) field.get(null);
        encodingAliases.put("'utf8'", RawParseUtils.UTF8_CHARSET);
        encodingAliases.put("utf-9", RawParseUtils.UTF8_CHARSET);
        encodingAliases.put("utf-18", RawParseUtils.UTF8_CHARSET);
        logger.info("Alias 'UTF8', UTF-9 & UTF-18 encodings as UTF-8 in JGit");
    } catch (Throwable t) {
        logger.error("Failed to inject UTF-9 & UTF-18 encoding aliases into JGit", t);
    }
}

From source file:org.apache.maven.scm.provider.git.jgit.command.checkout.JGitCheckOutCommand.java

License:Apache License

/**
 * For git, the given repository is a remote one. We have to clone it first if the working directory does not
 * contain a git repo yet, otherwise we have to git-pull it.
 * <p/>//  w w w.  j a  v  a 2  s.c o m
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet,
        ScmVersion version, boolean recursive) throws ScmException {
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;

    if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol())
            && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) {
        throw new ScmException("remote repository must not be the working directory");
    }

    Git git = null;
    try {

        ProgressMonitor monitor = JGitUtils.getMonitor(getLogger());

        String branch = version != null ? version.getName() : null;

        if (StringUtils.isBlank(branch)) {
            branch = Constants.MASTER;
        }

        getLogger().debug("try checkout of branch: " + branch);

        if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) {
            if (fileSet.getBasedir().exists()) {
                // git refuses to clone otherwise
                fileSet.getBasedir().delete();
            }

            // FIXME only if windauze
            WindowCacheConfig cfg = new WindowCacheConfig();
            cfg.setPackedGitMMAP(false);
            cfg.install();

            // no git repo seems to exist, let's clone the original repo
            CredentialsProvider credentials = JGitUtils.getCredentials((GitScmProviderRepository) repo);
            getLogger().info("cloning [" + branch + "] to " + fileSet.getBasedir());
            CloneCommand command = Git.cloneRepository().setURI(repository.getFetchUrl());
            command.setCredentialsProvider(credentials).setBranch(branch).setDirectory(fileSet.getBasedir());
            command.setProgressMonitor(monitor);
            git = command.call();
        }

        JGitRemoteInfoCommand remoteInfoCommand = new JGitRemoteInfoCommand();
        remoteInfoCommand.setLogger(getLogger());
        RemoteInfoScmResult result = remoteInfoCommand.executeRemoteInfoCommand(repository, fileSet, null);

        if (git == null) {
            git = Git.open(fileSet.getBasedir());
        }

        if (fileSet.getBasedir().exists() && new File(fileSet.getBasedir(), ".git").exists()
                && result.getBranches().size() > 0) {
            // git repo exists, so we must git-pull the changes
            CredentialsProvider credentials = JGitUtils.prepareSession(getLogger(), git, repository);

            if (version != null && StringUtils.isNotEmpty(version.getName()) && (version instanceof ScmTag)) {
                // A tag will not be pulled but we only fetch all the commits from the upstream repo
                // This is done because checking out a tag might not happen on the current branch
                // but create a 'detached HEAD'.
                // In fact, a tag in git may be in multiple branches. This occurs if
                // you create a branch after the tag has been created
                getLogger().debug("fetch...");
                git.fetch().setCredentialsProvider(credentials).setProgressMonitor(monitor).call();
            } else {
                getLogger().debug("pull...");
                git.pull().setCredentialsProvider(credentials).setProgressMonitor(monitor).call();
            }
        }

        Set<String> localBranchNames = JGitBranchCommand.getShortLocalBranchNames(git);
        if (version instanceof ScmTag) {
            getLogger().info("checkout tag [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).call();
        } else if (localBranchNames.contains(branch)) {
            getLogger().info("checkout [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).call();
        } else {
            getLogger().info("checkout remote branch [" + branch + "] at " + fileSet.getBasedir());
            git.checkout().setName(branch).setCreateBranch(true)
                    .setStartPoint(Constants.DEFAULT_REMOTE_NAME + "/" + branch).call();
        }

        RevWalk revWalk = new RevWalk(git.getRepository());
        RevCommit commit = revWalk.parseCommit(git.getRepository().resolve(Constants.HEAD));
        revWalk.release();

        final TreeWalk walk = new TreeWalk(git.getRepository());
        walk.reset(); // drop the first empty tree, which we do not need here
        walk.setRecursive(true);
        walk.addTree(commit.getTree());

        List<ScmFile> listedFiles = new ArrayList<ScmFile>();
        while (walk.next()) {
            listedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
        }
        walk.release();

        getLogger().debug("current branch: " + git.getRepository().getBranch());

        return new CheckOutScmResult("checkout via JGit", listedFiles);
    } catch (Exception e) {
        throw new ScmException("JGit checkout failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}

From source file:org.eclipse.egit.core.project.GitProjectData.java

License:Open Source License

/**
 * Update the settings for the global window cache of the workspace.
 */// w  w w  .java2 s .com
public static void reconfigureWindowCache() {
    final WindowCacheConfig c = new WindowCacheConfig();
    IEclipsePreferences d = new DefaultScope().getNode(Activator.getPluginId());
    IEclipsePreferences p = new InstanceScope().getNode(Activator.getPluginId());
    c.setPackedGitLimit(p.getInt(GitCorePreferences.core_packedGitLimit,
            d.getInt(GitCorePreferences.core_packedGitLimit, 0)));
    c.setPackedGitWindowSize(p.getInt(GitCorePreferences.core_packedGitWindowSize,
            d.getInt(GitCorePreferences.core_packedGitWindowSize, 0)));
    c.setPackedGitMMAP(p.getBoolean(GitCorePreferences.core_packedGitMMAP,
            d.getBoolean(GitCorePreferences.core_packedGitMMAP, false)));
    c.setDeltaBaseCacheLimit(p.getInt(GitCorePreferences.core_deltaBaseCacheLimit,
            d.getInt(GitCorePreferences.core_deltaBaseCacheLimit, 0)));
    WindowCache.reconfigure(c);
}