Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectReader


    while (!fti.getEntryPathString().equals("file"))
      fti.next(1);
    // If the rounding trick does not work we could skip the compareMetaData
    // test and hope that we are usually testing the intended code path.
    assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
    ObjectReader objectReader = db.newObjectReader();
    assertTrue(fti.isModified(dce, false, objectReader));
    objectReader.release();
  }
View Full Code Here


    final TreeWalk walk = new TreeWalk(repo);
    try {
      final T outa = fmt.createArchiveOutputStream(out);
      try {
        final MutableObjectId idBuf = new MutableObjectId();
        final ObjectReader reader = walk.getObjectReader();
        final RevWalk rw = new RevWalk(walk.getObjectReader());

        walk.reset(rw.parseTree(tree));
        if (!paths.isEmpty())
          walk.setFilter(PathFilterGroup.createFromStrings(paths));

        while (walk.next()) {
          final String name = pfx + walk.getPathString();
          FileMode mode = walk.getFileMode(0);

          if (walk.isSubtree())
            walk.enterSubtree();

          if (mode == FileMode.GITLINK)
            // TODO(jrn): Take a callback to recurse
            // into submodules.
            mode = FileMode.TREE;

          if (mode == FileMode.TREE) {
            fmt.putEntry(outa, name + "/", mode, null); //$NON-NLS-1$
            continue;
          }
          walk.getObjectId(idBuf, 0);
          fmt.putEntry(outa, name, mode, reader.open(idBuf));
        }
        outa.close();
      } finally {
        out.close();
      }
View Full Code Here

  @Test
  public void testFindObjects() throws Exception {
    final DirCache tree0 = DirCache.newInCore();
    final DirCacheBuilder b0 = tree0.builder();
    ObjectReader or = db.newObjectReader();
    ObjectInserter oi = db.newObjectInserter();

    DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
    b0.add(aDotB);
    DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
    b0.add(aSlashB);
    DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
    b0.add(aSlashCSlashD);
    DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
    b0.add(aZeroB);
    b0.finish();
    assertEquals(4, tree0.getEntryCount());
    ObjectId tree = tree0.writeTree(oi);

    // Find the directories that were implicitly created above.
    TreeWalk tw = new TreeWalk(or);
    tw.addTree(tree);
    ObjectId a = null;
    ObjectId aSlashC = null;
    while (tw.next()) {
      if (tw.getPathString().equals("a")) {
        a = tw.getObjectId(0);
        tw.enterSubtree();
        while (tw.next()) {
          if (tw.getPathString().equals("a/c")) {
            aSlashC = tw.getObjectId(0);
            break;
          }
        }
        break;
      }
    }

    assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
    assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
    assertEquals(null, TreeWalk.forPath(or, "/a", tree));
    assertEquals(null, TreeWalk.forPath(or, "/a/", tree));

    assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b", tree)
        .getObjectId(0));
    assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
    assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
    assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b/", tree)
        .getObjectId(0));

    assertEquals(aZeroB.getObjectId(), TreeWalk.forPath(or, "a0b", tree)
        .getObjectId(0));

    assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "a/b", tree)
        .getObjectId(0));
    assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "b", a)
        .getObjectId(0));

    assertEquals(aSlashC, TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
    assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));

    assertEquals(aSlashCSlashD.getObjectId(),
        TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
    assertEquals(aSlashCSlashD.getObjectId(), TreeWalk
        .forPath(or, "c/d", a).getObjectId(0));

    or.release();
    oi.release();
  }
View Full Code Here

        && repo.getRepositoryState() != RepositoryState.SAFE)
      throw new WrongRepositoryStateException(MessageFormat.format(
          JGitText.get().stashApplyOnUnsafeRepository,
          repo.getRepositoryState()));

    ObjectReader reader = repo.newObjectReader();
    try {
      RevWalk revWalk = new RevWalk(reader);

      ObjectId headCommit = repo.resolve(Constants.HEAD);
      if (headCommit == null)
        throw new NoHeadException(JGitText.get().stashApplyWithoutHead);

      final ObjectId stashId = getStashId();
      RevCommit stashCommit = revWalk.parseCommit(stashId);
      if (stashCommit.getParentCount() < 2
          || stashCommit.getParentCount() > 3)
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().stashCommitIncorrectNumberOfParents,
            stashId.name(),
            Integer.valueOf(stashCommit.getParentCount())));

      ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
      ObjectId stashIndexCommit = revWalk.parseCommit(stashCommit
          .getParent(1));
      ObjectId stashHeadCommit = stashCommit.getParent(0);
      ObjectId untrackedCommit = null;
      if (applyUntracked && stashCommit.getParentCount() == 3)
        untrackedCommit = revWalk.parseCommit(stashCommit.getParent(2));

      ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
      merger.setCommitNames(new String[] { "stashed HEAD", "HEAD",
          "stash" });
      merger.setBase(stashHeadCommit);
      merger.setWorkingTreeIterator(new FileTreeIterator(repo));
      if (merger.merge(headCommit, stashCommit)) {
        DirCache dc = repo.lockDirCache();
        DirCacheCheckout dco = new DirCacheCheckout(repo, headTree,
            dc, merger.getResultTreeId());
        dco.setFailOnConflict(true);
        dco.checkout(); // Ignoring failed deletes....
        if (applyIndex) {
          ResolveMerger ixMerger = (ResolveMerger) strategy
              .newMerger(repo, true);
          ixMerger.setCommitNames(new String[] { "stashed HEAD",
              "HEAD", "stashed index" });
          ixMerger.setBase(stashHeadCommit);
          boolean ok = ixMerger.merge(headCommit, stashIndexCommit);
          if (ok) {
            resetIndex(revWalk
                .parseTree(ixMerger.getResultTreeId()));
          } else {
            throw new StashApplyFailureException(
                JGitText.get().stashApplyConflict);
          }
        }

        if (untrackedCommit != null) {
          ResolveMerger untrackedMerger = (ResolveMerger) strategy
              .newMerger(repo, true);
          untrackedMerger.setCommitNames(new String[] {
              "stashed HEAD", "HEAD", "untracked files" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
          untrackedMerger.setBase(stashHeadCommit);
          boolean ok = untrackedMerger.merge(headCommit,
              untrackedCommit);
          if (ok)
            try {
              RevTree untrackedTree = revWalk
                  .parseTree(untrackedMerger
                      .getResultTreeId());
              resetUntracked(untrackedTree);
            } catch (CheckoutConflictException e) {
              throw new StashApplyFailureException(
                  JGitText.get().stashApplyConflict);
            }
          else
            throw new StashApplyFailureException(
                JGitText.get().stashApplyConflict);
        }
      } else {
        throw new StashApplyFailureException(
            JGitText.get().stashApplyConflict);
      }
      return stashId;

    } catch (JGitInternalException e) {
      throw e;
    } catch (IOException e) {
      throw new JGitInternalException(JGitText.get().stashApplyFailed, e);
    } finally {
      reader.release();
    }
  }
View Full Code Here

      walk = new TreeWalk(repo); // maybe NameConflictTreeWalk?
      walk.addTree(tree);
      walk.addTree(new FileTreeIterator(repo));
      walk.setRecursive(true);

      final ObjectReader reader = walk.getObjectReader();

      while (walk.next()) {
        final AbstractTreeIterator cIter = walk.getTree(0,
            AbstractTreeIterator.class);
        if (cIter == null)
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 = null;
      // 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() && repo.getFS().exists(file)) {
          // 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 (!repo.getFS().isDirectory(file))
            toBeDeleted.add(r);
        } else {
          if (last != null && !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

      }

      addRefs(refs, Constants.R_HEADS);
      addRefs(refs, Constants.R_REMOTES);

      ObjectReader reader = db.newObjectReader();
      try {
        for (final Entry<String, Ref> e : printRefs.entrySet()) {
          final Ref ref = e.getValue();
          printHead(reader, e.getKey(),
              current.equals(ref.getName()), ref);
        }
      } finally {
        reader.release();
      }
    }
  }
View Full Code Here

     * @throws IOException
     * @since 3.5
     */
    protected byte[] readFileFromRepo(Repository repo,
        String ref, String path) throws GitAPIException, IOException {
      ObjectReader reader = repo.newObjectReader();
      byte[] result;
      try {
        ObjectId oid = repo.resolve(ref + ":" + path); //$NON-NLS-1$
        result = reader.open(oid).getBytes(Integer.MAX_VALUE);
      } finally {
        reader.release();
      }
      return result;
    }
View Full Code Here

        if (oldTree == null) {
          ObjectId head = db.resolve(HEAD + "^{tree}"); //$NON-NLS-1$
          if (head == null)
            die(MessageFormat.format(CLIText.get().notATree, HEAD));
          CanonicalTreeParser p = new CanonicalTreeParser();
          ObjectReader reader = db.newObjectReader();
          try {
            p.reset(reader, head);
          } finally {
            reader.release();
          }
          oldTree = p;
        }
        newTree = new DirCacheIterator(db.readDirCache());
      } else if (oldTree == null) {
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.