Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectReader


        if (oldTree == null) {
          ObjectId head = repo.resolve(HEAD + "^{tree}");
          if (head == null)
            throw new NoHeadException(JGitText.get().cannotReadTree);
          CanonicalTreeParser p = new CanonicalTreeParser();
          ObjectReader reader = repo.newObjectReader();
          try {
            p.reset(reader, head);
          } finally {
            reader.release();
          }
          oldTree = p;
        }
        newTree = new DirCacheIterator(repo.readDirCache());
      } else {
View Full Code Here


        dircache.unlock();
    }
  }

  private void checkout() throws NoWorkTreeException, IOException {
    ObjectReader r = db.getObjectDatabase().newReader();
    try {
      for (Map.Entry<String, DirCacheEntry> entry : toBeCheckedOut
          .entrySet()) {
        File f = new File(db.getWorkTree(), entry.getKey());
        if (entry.getValue() != null) {
          createDir(f.getParentFile());
          DirCacheCheckout.checkoutEntry(db, f, entry.getValue(), r);
        } else {
          if (!f.delete())
            failingPaths.put(entry.getKey(),
                MergeFailureReason.COULD_NOT_DELETE);
        }
        modifiedFiles.add(entry.getKey());
      }
    } finally {
      r.release();
    }
  }
View Full Code Here

      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();
      }
      mpathsIt.remove();
    }
View Full Code Here

  private boolean doCheckout() throws CorruptObjectException, IOException,
      MissingObjectException, IncorrectObjectTypeException,
      CheckoutConflictException, IndexWriteException {
    toBeDeleted.clear();

    ObjectReader objectReader = repo.getObjectDatabase().newReader();
    try {
      if (headCommitTree != null)
        preScanTwoTrees();
      else
        prescanOneTree();

      if (!conflicts.isEmpty()) {
        if (failOnConflict)
          throw new CheckoutConflictException(conflicts.toArray(new String[conflicts.size()]));
        else
          cleanUpConflicts();
      }

      // update our index
      builder.finish();

      File file = null;
      String last = "";
      // when deleting files process them in the opposite order as they have
      // been reported. This ensures the files are deleted before we delete
      // their parent folders
      for (int i = removed.size() - 1; i >= 0; i--) {
        String r = removed.get(i);
        file = new File(repo.getWorkTree(), r);
        if (!file.delete() && file.exists()) {
          // The list of stuff to delete comes from the index
          // which will only contain a directory if it is
          // a submodule, in which case we shall not attempt
          // to delete it. A submodule is not empty, so it
          // is safe to check this after a failed delete.
          if (!file.isDirectory())
            toBeDeleted.add(r);
        } else {
          if (!isSamePrefix(r, last))
            removeEmptyParents(new File(repo.getWorkTree(), last));
          last = r;
        }
      }
      if (file != null)
        removeEmptyParents(file);

      for (String path : updated.keySet()) {
        // ... create/overwrite this file ...
        file = new File(repo.getWorkTree(), path);
        if (!file.getParentFile().mkdirs()) {
          // ignore
        }

        DirCacheEntry entry = dc.getEntry(path);

        // submodules are handled with separate operations
        if (FileMode.GITLINK.equals(entry.getRawMode()))
          continue;

        checkoutEntry(repo, file, entry, objectReader);
      }

      // commit the index builder - a new index is persisted
      if (!builder.commit())
        throw new IndexWriteException();
    } finally {
      objectReader.release();
    }
    return toBeDeleted.size() == 0;
  }
View Full Code Here

   *            the entry containing new mode and content
   * @throws IOException
   */
  public static void checkoutEntry(final Repository repository, File f,
      DirCacheEntry entry) throws IOException {
    ObjectReader or = repository.newObjectReader();
    try {
      checkoutEntry(repository, f, entry, repository.newObjectReader());
    } finally {
      or.release();
    }
  }
View Full Code Here

            .getTree());
      else
        startWalk.addTree(new DirCacheIterator(dc));

      final File workTree = repo.getWorkTree();
      final ObjectReader r = repo.getObjectDatabase().newReader();
      try {
        while (startWalk.next()) {
          final ObjectId blobId = startWalk.getObjectId(0);
          final FileMode mode = startWalk.getFileMode(0);
          editor.add(new PathEdit(startWalk.getPathString()) {
            public void apply(DirCacheEntry ent) {
              ent.setObjectId(blobId);
              ent.setFileMode(mode);
              try {
                DirCacheCheckout.checkoutEntry(repo, new File(
                    workTree, ent.getPathString()), ent, r);
              } catch (IOException e) {
                throw new JGitInternalException(
                    MessageFormat.format(
                        JGitText.get().checkoutConflictWithFile,
                        ent.getPathString()), e);
              }
            }
          });
        }
        editor.commit();
      } finally {
        startWalk.release();
        r.release();
      }
    } finally {
      dc.unlock();
      revWalk.release();
    }
View Full Code Here

        newHead = continueRebase();

      if (operation == Operation.SKIP)
        newHead = checkoutCurrentHead();

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      for (Step step : steps) {
        popSteps(1);
        Collection<ObjectId> ids = or.resolve(step.commit);
        if (ids.size() != 1)
          throw new JGitInternalException(
              "Could not resolve uniquely the abbreviated object ID");
        RevCommit commitToPick = walk
            .parseCommit(ids.iterator().next());
View Full Code Here

    fw.write("# Created by EGit: rebasing " + upstreamCommit.name()
        + " onto " + headId.name());
    fw.newLine();
    try {
      StringBuilder sb = new StringBuilder();
      ObjectReader reader = walk.getObjectReader();
      for (RevCommit commit : cherryPickList) {
        sb.setLength(0);
        sb.append(Action.PICK.toToken());
        sb.append(" ");
        sb.append(reader.abbreviate(commit).name());
        sb.append(" ");
        sb.append(commit.getShortMessage());
        fw.write(sb.toString());
        fw.newLine();
      }
View Full Code Here

   * @throws IOException
   *             file contents cannot be read from the repository.
   */
  public List<DiffEntry> compute(ProgressMonitor pm) throws IOException {
    if (!done) {
      ObjectReader reader = repo.newObjectReader();
      try {
        return compute(reader, pm);
      } finally {
        reader.release();
      }
    }
    return Collections.unmodifiableList(entries);
  }
View Full Code Here

   *             a tree object was not found.
   */
  public static TreeWalk forPath(final Repository db, final String path,
      final AnyObjectId... trees) throws MissingObjectException,
      IncorrectObjectTypeException, CorruptObjectException, IOException {
    ObjectReader reader = db.newObjectReader();
    try {
      return forPath(reader, path, trees);
    } finally {
      reader.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.ObjectReader

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.