Examples of DirCache


Examples of org.eclipse.jgit.dircache.DirCache

    }
  }

  private void checkoutIndex(RevCommit commit) throws IOException,
      GitAPIException {
    DirCache dc = repo.lockDirCache();
    try {
      DirCacheCheckout checkout = new DirCacheCheckout(repo, dc,
          commit.getTree());
      checkout.setFailOnConflict(false);
      try {
        checkout.checkout();
      } catch (org.eclipse.jgit.errors.CheckoutConflictException cce) {
        throw new CheckoutConflictException(checkout.getConflicts(),
            cce);
      }
    } finally {
      dc.unlock();
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCache

      RevCommit headCommit = headId == null ? null : revWalk
          .parseCommit(headId);
      RevCommit newCommit = revWalk.parseCommit(branch);
      RevTree headTree = headCommit == null ? null : headCommit.getTree();
      DirCacheCheckout dco;
      DirCache dc = repo.lockDirCache();
      try {
        dco = new DirCacheCheckout(repo, headTree, dc,
            newCommit.getTree());
        dco.setFailOnConflict(true);
        try {
          dco.checkout();
        } catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
          status = new CheckoutResult(Status.CONFLICTS,
              dco.getConflicts());
          throw new CheckoutConflictException(dco.getConflicts(), e);
        }
      } finally {
        dc.unlock();
      }
      Ref ref = repo.getRef(name);
      if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
        ref = null;
      String toName = Repository.shortenRefName(name);
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCache

   * @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);
      if (!checkoutAllPaths)
        treeWalk.setFilter(PathFilterGroup.createFromStrings(paths));
      try {
        if (isCheckoutIndex())
          checkoutPathsFromIndex(treeWalk, dc);
        else {
          RevCommit commit = revWalk.parseCommit(getStartPoint());
          checkoutPathsFromCommit(treeWalk, dc, commit);
        }
      } finally {
        treeWalk.release();
      }
    } finally {
      dc.unlock();
      revWalk.release();
    }
    return this;
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCache

import org.eclipse.jgit.pgm.internal.CLIText;

class ShowCacheTree extends TextBuiltin {
  @Override
  protected void run() throws Exception {
    final DirCache cache = db.readDirCache();
    final DirCacheTree tree = cache.getCacheTree(false);
    if (tree == null)
      throw die(CLIText.get().noTREESectionInIndex);
    show(tree);
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCache

    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

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

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

Examples of org.eclipse.jgit.dircache.DirCache

  public DirCache call() throws NoFilepatternException {

    if (filepatterns.isEmpty())
      throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired);
    checkCallable();
    DirCache dc = null;
    boolean addAll = false;
    if (filepatterns.contains("."))
      addAll = true;

    ObjectInserter inserter = repo.newObjectInserter();
    try {
      dc = repo.lockDirCache();
      DirCacheIterator c;

      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheBuildIterator(builder));
      if (workingTreeIterator == null)
        workingTreeIterator = new FileTreeIterator(repo);
      tw.addTree(workingTreeIterator);
      tw.setRecursive(true);
      if (!addAll)
        tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

      String lastAddedFile = null;

      while (tw.next()) {
        String path = tw.getPathString();

        WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class);
        if (tw.getTree(0, DirCacheIterator.class) == null &&
            f != null && f.isEntryIgnored()) {
          // file is not in index but is ignored, do nothing
        }
        // In case of an existing merge conflict the
        // DirCacheBuildIterator iterates over all stages of
        // this path, we however want to add only one
        // new DirCacheEntry per path.
        else if (!(path.equals(lastAddedFile))) {
          if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) {
            c = tw.getTree(0, DirCacheIterator.class);
            if (f != null) { // the file exists
              long sz = f.getEntryLength();
              DirCacheEntry entry = new DirCacheEntry(path);
              if (c == null || c.getDirCacheEntry() == null
                  || !c.getDirCacheEntry().isAssumeValid()) {
                entry.setLength(sz);
                entry.setLastModified(f.getEntryLastModified());
                entry.setFileMode(f.getEntryFileMode());

                InputStream in = f.openEntryStream();
                try {
                  entry.setObjectId(inserter.insert(
                      Constants.OBJ_BLOB, sz, in));
                } finally {
                  in.close();
                }

                builder.add(entry);
                lastAddedFile = path;
              } else {
                builder.add(c.getDirCacheEntry());
              }

            } else if (!update){
              builder.add(c.getDirCacheEntry());
            }
          }
        }
      }
      inserter.flush();
      builder.commit();
      setCallable(false);
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e);
    } finally {
      inserter.release();
      if (dc != null)
        dc.unlock();
    }

    return dc;
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCache

      ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
      if (headId != null)
        parents.add(0, headId);

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        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);

          // 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);
            ru.setRefLogMessage("commit : "
                + revCommit.getShortMessage(), false);

            ru.setExpectedOldObjectId(headId);
            Result rc = ru.update();
            switch (rc) {
            case NEW:
            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);
              }
              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

Examples of org.eclipse.jgit.dircache.DirCache

   * @throws IllegalStateException
   * @throws IOException
   */
  public String indexState(Repository repo, int includedOptions)
      throws IllegalStateException, IOException {
    DirCache dc = repo.readDirCache();
    StringBuilder sb = new StringBuilder();
    TreeSet<Long> timeStamps = null;

    // iterate once over the dircache just to collect all time stamps
    if (0 != (includedOptions & MOD_TIME)) {
      timeStamps = new TreeSet<Long>();
      for (int i=0; i<dc.getEntryCount(); ++i)
        timeStamps.add(Long.valueOf(dc.getEntry(i).getLastModified()));
    }

    // iterate again, now produce the result string
    for (int i=0; i<dc.getEntryCount(); ++i) {
      DirCacheEntry entry = dc.getEntry(i);
      sb.append("["+entry.getPathString()+", mode:" + entry.getFileMode());
      int stage = entry.getStage();
      if (stage != 0)
        sb.append(", stage:" + stage);
      if (0 != (includedOptions & MOD_TIME)) {
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.