Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCache


      NoHeadException, JGitInternalException {
    ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}");
    if (headTree == null)
      throw new NoHeadException(
          JGitText.get().cannotRebaseWithoutCurrentHead);
    DirCache dc = repo.lockDirCache();
    try {
      DirCacheCheckout dco = new DirCacheCheckout(repo, dc, headTree);
      dco.setFailOnConflict(false);
      boolean needsDeleteFiles = dco.checkout();
      if (needsDeleteFiles) {
        List<String> fileList = dco.getToBeDeleted();
        for (String filePath : fileList) {
          File fileToDelete = new File(repo.getWorkTree(), filePath);
          if (fileToDelete.exists())
            FileUtils.delete(fileToDelete, FileUtils.RECURSIVE
                | FileUtils.RETRY);
        }
      }
    } finally {
      dc.unlock();
    }
    RevWalk rw = new RevWalk(repo);
    RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
    rw.release();
    return commit;
View Full Code Here


   * @throws GitAPIException
   * @throws IOException
   */
  private RevCommit continueRebase() throws GitAPIException, IOException {
    // if there are still conflicts, we throw a specific Exception
    DirCache dc = repo.readDirCache();
    boolean hasUnmergedPaths = dc.hasUnmergedPaths();
    if (hasUnmergedPaths)
      throw new UnmergedPathsException();

    // determine whether we need to commit
    TreeWalk treeWalk = new TreeWalk(repo);
View Full Code Here

    if (inCore) {
      modifiedFiles.clear();
      return;
    }

    DirCache dc = db.readDirCache();
    ObjectReader or = db.getObjectDatabase().newReader();
    Iterator<String> mpathsIt=modifiedFiles.iterator();
    while(mpathsIt.hasNext()) {
      String mpath=mpathsIt.next();
      DirCacheEntry entry = dc.getEntry(mpath);
      FileOutputStream fos = new FileOutputStream(new File(db.getWorkTree(), mpath));
      try {
        or.open(entry.getObjectId()).copyTo(fos);
      } finally {
        fos.close();
View Full Code Here

        } else {
          parents.add(0, headId);
        }

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        if (!only.isEmpty())
          index = createTemporaryIndex(headId, index);

        ObjectInserter odi = repo.newObjectInserter();
        try {
          // Write the index as tree to the object database. This may
          // fail for example when the index contains unmerged paths
          // (unresolved conflicts)
          ObjectId indexTreeId = index.writeTree(odi);

          if (insertChangeId)
            insertChangeId(indexTreeId);

          // Create a Commit object, populate it and write it
          CommitBuilder commit = new CommitBuilder();
          commit.setCommitter(committer);
          commit.setAuthor(author);
          commit.setMessage(message);

          commit.setParentIds(parents);
          commit.setTreeId(indexTreeId);
          ObjectId commitId = odi.insert(commit);
          odi.flush();

          RevWalk revWalk = new RevWalk(repo);
          try {
            RevCommit revCommit = revWalk.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
              ru.setRefLogMessage(reflogComment, false);
            } else {
              String prefix = amend ? "commit (amend): "
                  : "commit: ";
              ru.setRefLogMessage(
                  prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null)
              ru.setExpectedOldObjectId(headId);
            else
              ru.setExpectedOldObjectId(ObjectId.zeroId());
            Result rc = ru.forceUpdate();
            switch (rc) {
            case NEW:
            case FORCED:
            case FAST_FORWARD: {
              setCallable(false);
              if (state == RepositoryState.MERGING_RESOLVED) {
                // Commit was successful. Now delete the files
                // used for merge commits
                repo.writeMergeCommitMsg(null);
                repo.writeMergeHeads(null);
              } else if (state == RepositoryState.CHERRY_PICKING_RESOLVED) {
                repo.writeMergeCommitMsg(null);
                repo.writeCherryPickHead(null);
              }
              return revCommit;
            }
            case REJECTED:
            case LOCK_FAILURE:
              throw new ConcurrentRefUpdateException(JGitText
                  .get().couldNotLockHEAD, ru.getRef(), rc);
            default:
              throw new JGitInternalException(MessageFormat
                  .format(JGitText.get().updatingRefFailed,
                      Constants.HEAD,
                      commitId.toString(), rc));
            }
          } finally {
            revWalk.release();
          }
        } finally {
          odi.release();
        }
      } finally {
        index.unlock();
      }
    } catch (UnmergedPathException e) {
      throw new UnmergedPathsException(e);
    } catch (IOException e) {
      throw new JGitInternalException(
View Full Code Here

    // get DirCacheBuilder for existing index
    DirCacheBuilder existingBuilder = index.builder();

    // get DirCacheBuilder for newly created in-core index to build a
    // temporary index for this commit
    DirCache inCoreIndex = DirCache.newInCore();
    DirCacheBuilder tempBuilder = inCoreIndex.builder();

    onlyProcessed = new boolean[only.size()];
    boolean emptyCommit = true;

    TreeWalk treeWalk = new TreeWalk(repo);
View Full Code Here

  private RevCommit checkoutCurrentHead() throws IOException, NoHeadException {
    ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}");
    if (headTree == null)
      throw new NoHeadException(
          JGitText.get().cannotRebaseWithoutCurrentHead);
    DirCache dc = repo.lockDirCache();
    try {
      DirCacheCheckout dco = new DirCacheCheckout(repo, dc, headTree);
      dco.setFailOnConflict(false);
      boolean needsDeleteFiles = dco.checkout();
      if (needsDeleteFiles) {
        List<String> fileList = dco.getToBeDeleted();
        for (String filePath : fileList) {
          File fileToDelete = new File(repo.getWorkTree(), filePath);
          if (fileToDelete.exists())
            FileUtils.delete(fileToDelete, FileUtils.RECURSIVE
                | FileUtils.RETRY);
        }
      }
    } finally {
      dc.unlock();
    }
    RevWalk rw = new RevWalk(repo);
    RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
    rw.release();
    return commit;
View Full Code Here

   * @throws GitAPIException
   * @throws IOException
   */
  private RevCommit continueRebase() throws GitAPIException, IOException {
    // if there are still conflicts, we throw a specific Exception
    DirCache dc = repo.readDirCache();
    boolean hasUnmergedPaths = dc.hasUnmergedPaths();
    if (hasUnmergedPaths)
      throw new UnmergedPathsException();

    // determine whether we need to commit
    TreeWalk treeWalk = new TreeWalk(repo);
View Full Code Here

      }

      final ObjectId currentCommitId =
          pdb.getRef(subscriber.get()).getObjectId();

      DirCache dc = readTree(pdb, pdb.getRef(subscriber.get()));
      DirCacheEditor ed = dc.editor();
      for (final Map.Entry<Branch.NameKey, ObjectId> me : modules.entrySet()) {
        ed.add(new PathEdit(paths.get(me.getKey())) {
          public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.GITLINK);
            ent.setObjectId(me.getValue().copy());
          }
        });
      }
      ed.finish();

      ObjectInserter oi = pdb.newObjectInserter();
      ObjectId tree = dc.writeTree(oi);

      final CommitBuilder commit = new CommitBuilder();
      commit.setTreeId(tree);
      commit.setParentIds(new ObjectId[] {currentCommitId});
      commit.setAuthor(author);
View Full Code Here

  private static DirCache readTree(final Repository pdb, final Ref branch)
      throws MissingObjectException, IncorrectObjectTypeException, IOException {
    final RevWalk rw = new RevWalk(pdb);

    final DirCache dc = DirCache.newInCore();
    final DirCacheBuilder b = dc.builder();
    b.addTree(new byte[0], // no prefix path
        DirCacheEntry.STAGE_0, // standard stage
        pdb.newObjectReader(), rw.parseTree(branch.getObjectId()));
    b.finish();
    return dc;
View Full Code Here

      public void write(CommitBuilder commit) throws IOException {
        write(VersionedMetaData.this, commit);
      }

      private void doSave(VersionedMetaData config, CommitBuilder commit) throws IOException {
        DirCache nt = config.newTree;
        ObjectReader r = config.reader;
        ObjectInserter i = config.inserter;
        try {
          config.newTree = newTree;
          config.reader = reader;
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.