/** * Create a deep copy of this RefTree. * * @return a deep copy of this RefTree. */ public RefTree copy() { RefTree r = new RefTree(DirCache.newInCore()); DirCacheBuilder b = r.contents.builder(); for (int i = 0; i < contents.getEntryCount(); i++) { b.add(new DirCacheEntry(contents.getEntry(i))); } b.finish(); if (pendingBlobs != null) { r.pendingBlobs = new HashMap<>(pendingBlobs); } return r; }
/** * Create a new in memory index read from the contents of a tree. * * @param reader * reader to access the tree objects from a repository. * @param treeId * tree to read. Must identify a tree, not a tree-ish. * @return a new cache which has no backing store file, but contains the * contents of {@code treeId}. * @throws java.io.IOException * one or more trees not available from the ObjectReader. * @since 4.2 */ public static DirCache read(ObjectReader reader, AnyObjectId treeId) throws IOException { DirCache d = newInCore(); DirCacheBuilder b = d.builder(); b.addTree(null, DirCacheEntry.STAGE_0, reader, treeId); b.finish(); return d; }
private void add(int tree, int stage) throws IOException { final AbstractTreeIterator i = getTree(tree); if (i != null) { if (FileMode.TREE.equals(tw.getRawMode(tree))) { builder.addTree(tw.getRawPath(), stage, reader, tw .getObjectId(tree)); } else { final DirCacheEntry e; e = new DirCacheEntry(tw.getRawPath(), stage); e.setObjectIdFromRaw(i.idBuffer(), i.idOffset()); e.setFileMode(tw.getFileMode(tree)); builder.add(e); } } }
public static void addTree(@Nonnull String path, @Nonnull AnyObjectId treeId, @Nonnull DirCache cache, @Nonnull ObjectReader reader) throws IOException { DirCacheBuilder builder = keepEverything(cache); addTree(path, treeId, builder, reader); builder.finish(); }
private void keep(DirCacheEntry e) { if (e != null && !FileMode.TREE.equals(e.getFileMode())) builder.add(e); }
private DirCache createTreeDirCache(Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage) throws IOException { try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.setRecursive(true); addTrees(parentCommits, treeWalk); DirCacheBuilder builder = DirCache.newInCore().builder(); while (treeWalk.next()) { AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage); if (iterator == null) { throw new IllegalStateException( "Tree walker did not return a single tree (should not happen): " + treeWalk.getPathString()); } byte[] path = Arrays.copyOf(iterator.getEntryPathBuffer(), iterator.getEntryPathLength()); DirCacheEntry entry = new DirCacheEntry(path); entry.setFileMode(iterator.getEntryFileMode()); entry.setObjectId(iterator.getEntryObjectId()); builder.add(entry); } builder.finish(); return builder.getDirCache(); } }
public static void addTree(@Nonnull String path, @Nonnull AnyObjectId treeId, @Nonnull DirCacheBuilder builder, @Nonnull ObjectReader reader) throws IOException { builder.addTree(TreeUtils.normalizeTreePath(path).getBytes(), DirCacheEntry.STAGE_0, reader, treeId); }
builder.commit(); setCallable(false); } catch (IOException e) {
/** * Create a new iterator for an already loaded DirCache instance. * <p> * The iterator implementation may copy part of the cache's data during * construction, so the cache must be read in prior to creating the * iterator. * * @param dcb * the cache builder for the cache to walk. The cache must be * already loaded into memory. */ public DirCacheBuildIterator(DirCacheBuilder dcb) { super(dcb.getDirCache()); builder = dcb; }
/** * Create a new builder to update this cache. * <p> * Callers should add all entries to the builder, then use * {@link org.eclipse.jgit.dircache.DirCacheBuilder#finish()} to update this * instance. * * @return a new builder instance for this cache. */ public DirCacheBuilder builder() { return new DirCacheBuilder(this, entryCnt + 16); }
public static void addFile(@Nonnull String path, @Nonnull FileMode mode, @Nonnull AnyObjectId blobId, @Nonnull DirCache cache) { DirCacheBuilder builder = keepEverything(cache); addFile(path, mode, blobId, builder); builder.finish(); }
private void update(String path, ObjectId mId, FileMode mode) throws IOException { if (!FileMode.TREE.equals(mode)) { updated.put(path, new CheckoutMetadata( walk.getEolStreamType(CHECKOUT_OP), walk.getFilterCommand(Constants.ATTR_FILTER_TYPE_SMUDGE))); DirCacheEntry entry = new DirCacheEntry(path, DirCacheEntry.STAGE_0); entry.setObjectId(mId); entry.setFileMode(mode); builder.add(entry); } }
private void add(int tree, int stage) throws IOException { final AbstractTreeIterator i = getTree(tree); if (i != null) { if (FileMode.TREE.equals(tw.getRawMode(tree))) { builder.addTree(tw.getRawPath(), stage, reader, tw .getObjectId(tree)); } else { final DirCacheEntry e; e = new DirCacheEntry(tw.getRawPath(), stage); e.setObjectIdFromRaw(i.idBuffer(), i.idOffset()); e.setFileMode(tw.getFileMode(tree)); builder.add(e); } } }
/** {@inheritDoc} */ @Override public void stopWalk() { final int cur = ptr; final int cnt = cache.getEntryCount(); if (cur < cnt) builder.keep(cur, cnt - cur); }