Example usage for org.eclipse.jgit.dircache DirCacheEntry setObjectIdFromRaw

List of usage examples for org.eclipse.jgit.dircache DirCacheEntry setObjectIdFromRaw

Introduction

In this page you can find the example usage for org.eclipse.jgit.dircache DirCacheEntry setObjectIdFromRaw.

Prototype

public void setObjectIdFromRaw(byte[] bs, int p) 

Source Link

Document

Set the ObjectId for the entry from the raw binary representation.

Usage

From source file:org.eclipse.orion.server.git.jobs.StashApplyCommand.java

License:Eclipse Distribution License

private void resetIndex(RevTree tree) throws IOException {
    DirCache dc = repo.lockDirCache();//www. j a v a2  s .c  o m
    TreeWalk walk = null;
    try {
        DirCacheBuilder builder = dc.builder();

        walk = new TreeWalk(repo);
        walk.addTree(tree);
        walk.addTree(new DirCacheIterator(dc));
        walk.setRecursive(true);

        while (walk.next()) {
            AbstractTreeIterator cIter = walk.getTree(0, AbstractTreeIterator.class);
            if (cIter == null) {
                // Not in commit, don't add to new index
                continue;
            }

            final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
            entry.setFileMode(cIter.getEntryFileMode());
            entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());

            DirCacheIterator dcIter = walk.getTree(1, DirCacheIterator.class);
            if (dcIter != null && dcIter.idEqual(cIter)) {
                DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
                entry.setLastModified(indexEntry.getLastModified());
                entry.setLength(indexEntry.getLength());
            }

            builder.add(entry);
        }

        builder.commit();
    } finally {
        dc.unlock();
        if (walk != null)
            walk.release();
    }
}

From source file:org.eclipse.orion.server.git.jobs.StashApplyCommand.java

License:Eclipse Distribution License

private void resetUntracked(RevTree tree) throws CheckoutConflictException, IOException {
    TreeWalk walk = null;//from w  w  w  .  ja  v a2 s . co m
    try {
        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)
                // Not in commit, don't create untracked
                continue;

            final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
            entry.setFileMode(cIter.getEntryFileMode());
            entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());

            FileTreeIterator fIter = walk.getTree(1, FileTreeIterator.class);
            if (fIter != null) {
                if (fIter.isModified(entry, true, reader)) {
                    // file exists and is dirty
                    throw new CheckoutConflictException(entry.getPathString());
                }
            }

            checkoutPath(entry, reader);
        }
    } finally {
        if (walk != null)
            walk.release();
    }
}