/** * 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; }
/** * 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; }
/** * Scan index and merge tree (no HEAD). Used e.g. for initial checkout when * there is no head yet. * * @throws org.eclipse.jgit.errors.MissingObjectException * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException * @throws org.eclipse.jgit.errors.CorruptObjectException * @throws java.io.IOException */ public void prescanOneTree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { removed.clear(); updated.clear(); conflicts.clear(); builder = dc.builder(); walk = new NameConflictTreeWalk(repo); addTree(walk, mergeCommitTree); int dciPos = walk.addTree(new DirCacheBuildIterator(builder)); walk.addTree(workingTree); workingTree.setDirCacheIterator(walk, dciPos); while (walk.next()) { processEntry(walk.getTree(0, CanonicalTreeParser.class), walk.getTree(1, DirCacheBuildIterator.class), walk.getTree(2, WorkingTreeIterator.class)); if (walk.isSubtree()) walk.enterSubtree(); } conflicts.removeAll(removed); }
/** * Scan head, index and merge tree. Used during normal checkout or merge * operations. * * @throws org.eclipse.jgit.errors.CorruptObjectException * @throws java.io.IOException */ public void preScanTwoTrees() throws CorruptObjectException, IOException { removed.clear(); updated.clear(); conflicts.clear(); walk = new NameConflictTreeWalk(repo); builder = dc.builder(); addTree(walk, headCommitTree); addTree(walk, mergeCommitTree); int dciPos = walk.addTree(new DirCacheBuildIterator(builder)); walk.addTree(workingTree); workingTree.setDirCacheIterator(walk, dciPos); while (walk.next()) { processEntry(walk.getTree(0, CanonicalTreeParser.class), walk.getTree(1, CanonicalTreeParser.class), walk.getTree(2, DirCacheBuildIterator.class), walk.getTree(3, WorkingTreeIterator.class)); if (walk.isSubtree()) walk.enterSubtree(); } }
try (TreeWalk tw = new TreeWalk(repo)) { dc = repo.lockDirCache(); DirCacheBuilder builder = dc.builder();
DirCacheBuilder builder = index.builder(); ObjectInserter inserter = repo.newObjectInserter(); try (RevWalk rw = new RevWalk(repo)) {
try (TreeWalk tw = new TreeWalk(repo)) { dc = repo.lockDirCache(); DirCacheBuilder builder = dc.builder();
throws IOException { builder = dircache.builder(); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
@Nonnull public static DirCacheBuilder keepEverything(@Nonnull DirCache cache) { DirCacheBuilder builder = cache.builder(); int count = cache.getEntryCount(); if(count > 0) builder.keep(0, count); return builder; }
@Nonnull public static DirCacheBuilder keepEverything(DirCache cache) { DirCacheBuilder builder = cache.builder(); int count = cache.getEntryCount(); if(count > 0) builder.keep(0, count); return builder; }
@Nonnull public static DirCacheBuilder keepEverything(DirCache cache) { DirCacheBuilder builder = cache.builder(); int count = cache.getEntryCount(); if(count > 0) builder.keep(0, count); return builder; }
DirCache untrackedDirCache = DirCache.newInCore(); DirCacheBuilder untrackedBuilder = untrackedDirCache .builder(); for (DirCacheEntry entry : untracked) untrackedBuilder.add(entry);
private void resetIndex(RevTree tree) throws IOException { DirCache dc = repo.lockDirCache(); try (TreeWalk walk = new TreeWalk(repo)) { DirCacheBuilder builder = dc.builder();
private void resetIndex(ObjectId commitTree) throws IOException { DirCache dc = repo.lockDirCache(); try (TreeWalk walk = new TreeWalk(repo)) { DirCacheBuilder builder = dc.builder();
builder = cache.builder(); while (tw.next()) { final int modeO = tw.getRawMode(T_OURS);
dc = repo.lockDirCache(); DirCacheBuilder builder = dc.builder(); tw.addTree(new DirCacheBuildIterator(builder)); if (workingTreeIterator == null)
/** @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; }
@Nonnull private static DirCache setupCache(String... files) { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder); builder.finish(); return cache; }
@Test public void addFilesWithDirCacheBuilderTest() { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); String[] files = new String[] {"a/b/c1.txt", "a/c2.txt", "a/c3.txt", "a/b/c4.txt"}; for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder);builder.finish(); int entryCount = cache.getEntryCount(); assertEquals(4, entryCount); }