/** * 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; }
builder.finish(); ObjectId treeId = index.writeTree(inserter);
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(); }
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(); }
builder.finish(); builder = null;
for (DirCacheEntry entry : untracked) untrackedBuilder.add(entry); untrackedBuilder.finish();
public static void addTree(String path, AnyObjectId treeId, DirCache cache, ObjectReader reader) throws IOException { DirCacheBuilder builder = keepEverything(cache); addTree(path, treeId, builder, reader); builder.finish(); }
public static void addTree(String path, AnyObjectId treeId, DirCache cache, ObjectReader reader) throws IOException { DirCacheBuilder builder = keepEverything(cache); addTree(path, treeId, builder, reader); builder.finish(); }
public static void addFile(String path, FileMode mode, AnyObjectId blobId, DirCache cache) { DirCacheBuilder builder = keepEverything(cache); addFile(path, mode, blobId, builder); builder.finish(); }
public static void addFile(String path, FileMode mode, AnyObjectId blobId, DirCache cache) { DirCacheBuilder builder = keepEverything(cache); addFile(path, mode, blobId, builder); builder.finish(); }
tempBuilder.finish(); return inCoreIndex;
builder.finish(); builder = 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; }
/** * 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; }
@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; }
protected void writeMultipleToCache(String... paths) throws IOException { DirCacheBuilder builder = CacheUtils.keepEverything(cache); for(String path : paths) { AnyObjectId blobId = repo != null ? BlobUtils.insertBlob(someBytes(), repo) : someObjectId(); addFile(path, REGULAR_FILE, blobId, builder); } builder.finish(); }
@Test public void keepEverything_ExistingEntriesShouldBeKept() throws IOException { writeMultipleToCache("/file1.txt", "/file2.txt"); DirCacheBuilder builder = CacheUtils.keepEverything(cache); builder.finish(); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", 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); }