Examples of FileBasedConfig


Examples of org.eclipse.jgit.storage.file.FileBasedConfig

   * @return IndexResult
   */
  private IndexResult updateIndex(RepositoryModel model, Repository repository) {
    IndexResult result = new IndexResult();
    try {
      FileBasedConfig config = getConfig(repository);
      config.load();

      // build a quick lookup of annotated tags
      Map<String, List<String>> tags = new HashMap<String, List<String>>();
      for (RefModel tag : JGitUtils.getTags(repository, false, -1)) {
        if (!tag.isAnnotatedTag()) {
          // skip non-annotated tags
          continue;
        }
        if (!tags.containsKey(tag.getObjectId().getName())) {
          tags.put(tag.getReferencedObjectId().getName(), new ArrayList<String>());
        }
        tags.get(tag.getReferencedObjectId().getName()).add(tag.displayName);
      }

      // detect branch deletion
      // first assume all branches are deleted and then remove each
      // existing branch from deletedBranches during indexing
      Set<String> deletedBranches = new TreeSet<String>();
      for (String alias : config.getNames(CONF_ALIAS)) {
        String branch = config.getString(CONF_ALIAS, null, alias);
        deletedBranches.add(branch);
      }

      // get the local branches
      List<RefModel> branches = JGitUtils.getLocalBranches(repository, true, -1);

      // sort them by most recently updated
      Collections.sort(branches, new Comparator<RefModel>() {
        @Override
        public int compare(RefModel ref1, RefModel ref2) {
          return ref2.getDate().compareTo(ref1.getDate());
        }
      });

      // reorder default branch to first position
      RefModel defaultBranch = null;
      ObjectId defaultBranchId = JGitUtils.getDefaultBranch(repository);
      for (RefModel branch :  branches) {
        if (branch.getObjectId().equals(defaultBranchId)) {
          defaultBranch = branch;
          break;
        }
      }
      branches.remove(defaultBranch);
      branches.add(0, defaultBranch);

      // walk through each branches
      for (RefModel branch : branches) {
        String branchName = branch.getName();

        boolean indexBranch = false;
        if (model.indexedBranches.contains(com.gitblit.Constants.DEFAULT_BRANCH)
            && branch.equals(defaultBranch)) {
          // indexing "default" branch
          indexBranch = true;
        } else if (branch.getName().startsWith(com.gitblit.Constants.R_META)) {
          // ignore internal meta branches
          indexBranch = false;
        } else {
          // normal explicit branch check
          indexBranch = model.indexedBranches.contains(branch.getName());
        }

        // if this branch is not specifically indexed then skip
        if (!indexBranch) {
          continue;
        }

        // remove this branch from the deletedBranches set
        deletedBranches.remove(branchName);

        // determine last commit
        String keyName = getBranchKey(branchName);
        String lastCommit = config.getString(CONF_BRANCH, null, keyName);

        List<RevCommit> revs;
        if (StringUtils.isEmpty(lastCommit)) {
          // new branch/unindexed branch, get all commits on branch
          revs = JGitUtils.getRevLog(repository, branchName, 0, -1);
        } else {
          // pre-existing branch, get changes since last commit
          revs = JGitUtils.getRevLog(repository, lastCommit, branchName);
        }

        if (revs.size() > 0) {
          result.branchCount += 1;
        }

        // reverse the list of commits so we start with the first commit
        Collections.reverse(revs);
        for (RevCommit commit : revs) {
          // index a commit
          result.add(index(model.name, repository, branchName, commit));
        }

        // update the config
        config.setInt(CONF_INDEX, null, CONF_VERSION, INDEX_VERSION);
        config.setString(CONF_ALIAS, null, keyName, branchName);
        config.setString(CONF_BRANCH, null, keyName, branch.getObjectId().getName());
        config.save();
      }

      // the deletedBranches set will normally be empty by this point
      // unless a branch really was deleted and no longer exists
      if (deletedBranches.size() > 0) {
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

  }

  @Override
  public ProjectManager start() {
    // load and cache the project metadata
    projectConfigs = new FileBasedConfig(runtimeManager.getFileOrFolder(Keys.web.projectsFile, "${baseFolder}/projects.conf"), FS.detect());
    getProjectConfigs();

    return this;
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

    }
    return success;
  }

  private StoredConfig getConfig() throws IOException, ConfigInvalidException {
    FileBasedConfig config = new FileBasedConfig(configFile, FS.detect());
    config.load();
    return config;
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

  }

  private void testCoreAutoCrlf(AutoCRLF modeForCommitting,
      AutoCRLF modeForReset) throws Exception {
    Git git = new Git(db);
    FileBasedConfig config = db.getConfig();
    config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForCommitting);
    config.save();

    String joinedCrlf = "a\r\nb\r\nc\r\n";
    File trashFile = writeTrashFile("file.txt", joinedCrlf);
    git.add().addFilepattern("file.txt").call();
    RevCommit commit = git.commit().setMessage("create file").call();

    // re-create file from the repo
    trashFile.delete();
    config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForReset);
    config.save();
    git.reset().setMode(ResetType.HARD).call();

    BlameCommand command = new BlameCommand(db);
    command.setFilePath("file.txt");
    BlameResult lines = command.call();
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

        throw die(MessageFormat.format(
            CLIText.get().configFileNotFound, //
            configFile.getAbsolutePath()));
      }

      FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
      cfg.load();
      new WindowCacheConfig().fromConfig(cfg).install();
      packConfig.fromConfig(cfg);
    }

    int threads = packConfig.getThreads();
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

  }

  private void list() throws IOException, ConfigInvalidException {
    final FS fs = getRepository().getFS();
    if (configFile != null) {
      list(new FileBasedConfig(configFile, fs));
      return;
    }
    if (system
        || (isListAll() && StringUtils.isEmptyOrNull(SystemReader
            .getInstance()
            .getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))))
      list(SystemReader.getInstance().openSystemConfig(null, fs));
    if (global || isListAll())
      list(SystemReader.getInstance().openUserConfig(null, fs));
    if (local || isListAll())
      list(new FileBasedConfig(fs.resolve(getRepository().getDirectory(),
          Constants.CONFIG), fs));
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

    if (StringUtils.isEmptyOrNull(SystemReader.getInstance().getenv(
        Constants.GIT_CONFIG_NOSYSTEM_KEY)))
      systemConfig = SystemReader.getInstance().openSystemConfig(null,
          getFS());
    else
      systemConfig = new FileBasedConfig(null, FS.DETECTED) {
        public void load() {
          // empty, do not load
        }

        public boolean isOutdated() {
          // regular class would bomb here
          return false;
        }
      };
    userConfig = SystemReader.getInstance().openUserConfig(systemConfig,
        getFS());
    repoConfig = new FileBasedConfig(userConfig, getFS().resolve(
        getDirectory(), Constants.CONFIG),
        getFS());

    loadSystemConfig();
    loadUserConfig();
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

   *
   * @throws IOException
   *             in case of IO problem
   */
  public void create(boolean bare) throws IOException {
    final FileBasedConfig cfg = getConfig();
    if (cfg.getFile().exists()) {
      throw new IllegalStateException(MessageFormat.format(
          JGitText.get().repositoryAlreadyExists, getDirectory()));
    }
    FileUtils.mkdirs(getDirectory(), true);
    HideDotFiles hideDotFiles = getConfig().getEnum(
        ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_HIDEDOTFILES,
        HideDotFiles.DOTGITONLY);
    if (hideDotFiles != HideDotFiles.FALSE && !isBare())
      getFS().setHidden(getDirectory(), true);
    refs.create();
    objectDatabase.create();

    FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$
    FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$

    RefUpdate head = updateRef(Constants.HEAD);
    head.disableRefLog();
    head.link(Constants.R_HEADS + Constants.MASTER);

    final boolean fileMode;
    if (getFS().supportsExecute()) {
      File tmp = File.createTempFile("try", "execute", getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$

      getFS().setExecute(tmp, true);
      final boolean on = getFS().canExecute(tmp);

      getFS().setExecute(tmp, false);
      final boolean off = getFS().canExecute(tmp);
      FileUtils.delete(tmp);

      fileMode = on && !off;
    } else {
      fileMode = false;
    }

    SymLinks symLinks = SymLinks.FALSE;
    if (getFS().supportsSymlinks()) {
      File tmp = new File(getDirectory(), "tmplink"); //$NON-NLS-1$
      try {
        getFS().createSymLink(tmp, "target"); //$NON-NLS-1$
        symLinks = null;
        FileUtils.delete(tmp);
      } catch (IOException e) {
        // Normally a java.nio.file.FileSystemException
      }
    }
    if (symLinks != null)
      cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
          ConfigConstants.CONFIG_KEY_SYMLINKS, symLinks.name()
              .toLowerCase());
    cfg.setInt(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
    cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_FILEMODE, fileMode);
    if (bare)
      cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
          ConfigConstants.CONFIG_KEY_BARE, true);
    cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, !bare);
    if (SystemReader.getInstance().isMacOS())
      // Java has no other way
      cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
          ConfigConstants.CONFIG_KEY_PRECOMPOSEUNICODE, true);
    cfg.save();
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

      // We only want the repository's configuration file, and not
      // the user file, as these parameters must be unique to this
      // repository and not inherited from other files.
      //
      File path = safeFS().resolve(getGitDir(), Constants.CONFIG);
      FileBasedConfig cfg = new FileBasedConfig(path, safeFS());
      try {
        cfg.load();
      } catch (ConfigInvalidException err) {
        throw new IllegalArgumentException(MessageFormat.format(
            JGitText.get().repositoryConfigFileInvalid, path
                .getAbsolutePath(), err.getMessage()));
      }
View Full Code Here

Examples of org.eclipse.jgit.storage.file.FileBasedConfig

    return dir;
  }

  private void setBare(File gitDir, boolean bare) throws IOException,
      ConfigInvalidException {
    FileBasedConfig cfg = configFor(gitDir);
    cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_BARE, bare);
    cfg.save();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.