Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCache


    this.mode = mode;
    return this;
  }

  private void resetIndex(RevCommit commit) throws IOException {
    DirCache dc = null;
    try {
      dc = repo.lockDirCache();
      dc.clear();
      DirCacheBuilder dcb = dc.builder();
      dcb.addTree(new byte[0], 0, repo.newObjectReader(),
          commit.getTree());
      dcb.commit();
    } catch (IOException e) {
      throw e;
    } finally {
      if (dc != null)
        dc.unlock();
    }
  }
View Full Code Here


        dc.unlock();
    }
  }

  private void checkoutIndex(RevCommit commit) throws IOException {
    DirCache dc = null;
    try {
      dc = repo.lockDirCache();
      DirCacheCheckout checkout = new DirCacheCheckout(repo, dc,
          commit.getTree());
      checkout.setFailOnConflict(false);
      checkout.checkout();
    } catch (IOException e) {
      throw e;
    } finally {
      if (dc != null)
        dc.unlock();
    }
  }
View Full Code Here

      UserModel user = GitBlitWebSession.get().getUser();
      String email = Optional.fromNullable(user.emailAddress).or(user.username + "@" + "gitblit");
      PersonIdent author = new PersonIdent(user.getDisplayName(), email);

      DirCache newIndex = DirCache.newInCore();
      DirCacheBuilder indexBuilder = newIndex.builder();

      if (addReadme) {
        // insert a README
        String title = StringUtils.stripDotGit(StringUtils.getLastPathElement(repositoryModel.name));
        String description = repositoryModel.description == null ? "" : repositoryModel.description;
        String readme = String.format("## %s\n\n%s\n\n", title, description);
        byte [] bytes = readme.getBytes(Constants.ENCODING);

        DirCacheEntry entry = new DirCacheEntry("README.md");
        entry.setLength(bytes.length);
        entry.setLastModified(System.currentTimeMillis());
        entry.setFileMode(FileMode.REGULAR_FILE);
        entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

        indexBuilder.add(entry);
      }

      if (!StringUtils.isEmpty(gitignore)) {
        // insert a .gitignore file
        File dir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
        File file = new File(dir, gitignore + ".gitignore");
        if (file.exists() && file.length() > 0) {
          byte [] bytes = FileUtils.readContent(file);
          if (!ArrayUtils.isEmpty(bytes)) {
            DirCacheEntry entry = new DirCacheEntry(".gitignore");
            entry.setLength(bytes.length);
            entry.setLastModified(System.currentTimeMillis());
            entry.setFileMode(FileMode.REGULAR_FILE);
            entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

            indexBuilder.add(entry);
          }
        }
      }

      if (addGitFlow) {
        // insert a .gitflow file
        Config config = new Config();
        config.setString("gitflow", null, "masterBranch", Constants.MASTER);
        config.setString("gitflow", null, "developBranch", Constants.DEVELOP);
        config.setString("gitflow", null, "featureBranchPrefix", "feature/");
        config.setString("gitflow", null, "releaseBranchPrefix", "release/");
        config.setString("gitflow", null, "hotfixBranchPrefix", "hotfix/");
        config.setString("gitflow", null, "supportBranchPrefix", "support/");
        config.setString("gitflow", null, "versionTagPrefix", "");

        byte [] bytes = config.toText().getBytes(Constants.ENCODING);

        DirCacheEntry entry = new DirCacheEntry(".gitflow");
        entry.setLength(bytes.length);
        entry.setLastModified(System.currentTimeMillis());
        entry.setFileMode(FileMode.REGULAR_FILE);
        entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

        indexBuilder.add(entry);
      }

      indexBuilder.finish();

      if (newIndex.getEntryCount() == 0) {
        // nothing to commit
        return false;
      }

      ObjectId treeId = newIndex.writeTree(odi);

      // Create a commit object
      CommitBuilder commit = new CommitBuilder();
      commit.setAuthor(author);
      commit.setCommitter(author);
View Full Code Here

    try {
      ObjectId headId = repository.resolve(GB_REFLOG + "^{commit}");
      ObjectInserter odi = repository.newObjectInserter();
      try {
        // Create the in-memory index of the reflog log entry
        DirCache index = createIndex(repository, headId, commands);
        ObjectId indexTreeId = index.writeTree(odi);

        PersonIdent ident;
        if (UserModel.ANONYMOUS.equals(user)) {
          // anonymous push
          ident = new PersonIdent(user.username + "/" + user.username, user.username);
View Full Code Here

   * @throws IOException
   */
  private static DirCache createIndex(Repository repo, ObjectId headId,
      Collection<ReceiveCommand> commands) throws IOException {

    DirCache inCoreIndex = DirCache.newInCore();
    DirCacheBuilder dcBuilder = inCoreIndex.builder();
    ObjectInserter inserter = repo.newObjectInserter();

    long now = System.currentTimeMillis();
    Set<String> ignorePaths = new TreeSet<String>();
    try {
View Full Code Here

  private void writeTicketsFile(Repository db, String file, String content, String createdBy, String msg) {
    if (getTicketsBranch(db) == null) {
      createTicketsBranch(db);
    }

    DirCache newIndex = DirCache.newInCore();
    DirCacheBuilder builder = newIndex.builder();
    ObjectInserter inserter = db.newObjectInserter();

    try {
      // create an index entry for the revised index
      final DirCacheEntry idIndexEntry = new DirCacheEntry(file);
View Full Code Here

      TreeWalk treeWalk = null;
      try {
        ObjectId treeId = db.resolve(BRANCH + "^{tree}");

        // Create the in-memory index of the new/updated ticket
        DirCache index = DirCache.newInCore();
        DirCacheBuilder builder = index.builder();

        // Traverse HEAD to add all other paths
        treeWalk = new TreeWalk(db);
        int hIdx = -1;
        if (treeId != null) {
View Full Code Here

  protected synchronized boolean commitChangeImpl(RepositoryModel repository, long ticketId, Change change) {
    boolean success = false;

    Repository db = repositoryManager.getRepository(repository.name);
    try {
      DirCache index = createIndex(db, ticketId, change);
      success = commitIndex(db, index, change.author, "#" + ticketId);

    } catch (Throwable t) {
      log.error(MessageFormat.format("Failed to commit ticket {0,number,0} to {1}",
          ticketId, db.getDirectory()), t);
View Full Code Here

   */
  private DirCache createIndex(Repository db, long ticketId, Change change)
      throws IOException, ClassNotFoundException, NoSuchFieldException {

    String ticketPath = toTicketPath(ticketId);
    DirCache newIndex = DirCache.newInCore();
    DirCacheBuilder builder = newIndex.builder();
    ObjectInserter inserter = db.newObjectInserter();

    Set<String> ignorePaths = new TreeSet<String>();
    try {
      // create/update the journal
View Full Code Here

    validateIndex(git);
  }

  public static void validateIndex(Git git) throws NoWorkTreeException,
      IOException {
    DirCache dc = git.getRepository().lockDirCache();
    ObjectReader r = git.getRepository().getObjectDatabase().newReader();
    try {
      for (int i = 0; i < dc.getEntryCount(); ++i) {
        DirCacheEntry entry = dc.getEntry(i);
        if (entry.getLength() > 0)
          assertEquals(entry.getLength(), r.getObjectSize(
              entry.getObjectId(), ObjectReader.OBJ_ANY));
      }
    } finally {
      dc.unlock();
      r.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.dircache.DirCache

Copyright © 2018 www.massapicom. 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.