Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCache


   * @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 RevCommit commit = parseCommit(branch);
      final RefUpdate u = db.updateRef(Constants.HEAD);
      u.setNewObjectId(commit);
      u.forceUpdate();

      DirCache dc = db.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(db, dc, commit.getTree());
      co.checkout();
   }
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);
            String prefix = amend ? "commit (amend): " : "commit: ";
            ru.setRefLogMessage(
                prefix + revCommit.getShortMessage(), false);

            ru.setExpectedOldObjectId(headId);
            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) {
      // since UnmergedPathException is a subclass of IOException
      // which should not be wrapped by a JGitInternalException we
      // have to catch and re-throw it here
View Full Code Here

    // get DirCacheEditor to modify the index if required
    DirCacheEditor dcEditor = index.editor();

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

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

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

    RefUpdate u = repo.updateRef(Constants.HEAD, detached);
    u.setNewObjectId(commit.getId());
    u.forceUpdate();

    if (!bare) {
      DirCache dc = repo.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(repo, dc,
          commit.getTree());
      co.checkout();
    }
  }
View Full Code Here

   * @throws RefNotFoundException
   */
  protected CheckoutCommand checkoutPaths() throws IOException,
      RefNotFoundException {
    RevWalk revWalk = new RevWalk(repo);
    DirCache dc = repo.lockDirCache();
    try {
      TreeWalk treeWalk = new TreeWalk(revWalk.getObjectReader());
      treeWalk.setRecursive(true);
      treeWalk.addTree(new DirCacheIterator(dc));
      treeWalk.setFilter(PathFilterGroup.createFromStrings(paths));
      List<String> files = new LinkedList<String>();
      while (treeWalk.next())
        files.add(treeWalk.getPathString());

      if (startCommit != null || startPoint != null) {
        DirCacheEditor editor = dc.editor();
        TreeWalk startWalk = new TreeWalk(revWalk.getObjectReader());
        startWalk.setRecursive(true);
        startWalk.setFilter(treeWalk.getFilter());
        startWalk.addTree(revWalk.parseCommit(getStartPoint())
            .getTree());
        while (startWalk.next()) {
          final ObjectId blobId = startWalk.getObjectId(0);
          editor.add(new PathEdit(startWalk.getPathString()) {

            public void apply(DirCacheEntry ent) {
              ent.setObjectId(blobId);
            }
          });
        }
        editor.commit();
      }

      File workTree = repo.getWorkTree();
      for (String file : files)
        DirCacheCheckout.checkoutEntry(repo, new File(workTree, file),
            dc.getEntry(file));
    } finally {
      dc.unlock();
      revWalk.release();
    }
    return this;
  }
View Full Code Here

      else if (startCommit != null)
        gen.push(null, startCommit);
      else {
        gen.push(null, repo.resolve(Constants.HEAD));
        if (!repo.isBare()) {
          DirCache dc = repo.readDirCache();
          int entry = dc.findEntry(path);
          if (0 <= entry)
            gen.push(null, dc.getEntry(entry).getObjectId());

          File inTree = new File(repo.getWorkTree(), path);
          if (inTree.isFile())
            gen.push(null, new RawText(inTree));
        }
View Full Code Here

    filepaths.add(file);
    return this;
  }

  private void resetIndexForPaths(RevCommit commit) {
    DirCache dc = null;
    final DirCacheEditor edit;
    try {
      dc = repo.lockDirCache();
      edit = dc.editor();

      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheIterator(dc));
      tw.addTree(commit.getTree());
      tw.setFilter(PathFilterGroup.createFromStrings(filepaths));

      while (tw.next()) {
        final String path = tw.getPathString();
        // DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
        final CanonicalTreeParser tree = tw.getTree(1,
            CanonicalTreeParser.class);
        if (tree == null)
          // file is not in the commit, remove from index
          edit.add(new DirCacheEditor.DeletePath(path));
        else {
          // revert index to commit
          edit.add(new DirCacheEditor.PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.setFileMode(tree.getEntryFileMode());
              ent.setObjectId(tree.getEntryObjectId());
              ent.setLastModified(0);
            }
          });
        }
      }

      edit.commit();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      if (dc != null)
        dc.unlock();
    }
  }
View Full Code Here

        dc.unlock();
    }
  }

  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

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.