/** * 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; }
/** * Write this reference tree. * * @param inserter * inserter to use when writing trees to the object database. * Caller is responsible for flushing the inserter before trying * to read the objects, or exposing them through a reference. * @return the top level tree. * @throws java.io.IOException * a tree could not be written. */ public ObjectId writeTree(ObjectInserter inserter) throws IOException { if (pendingBlobs != null) { for (String s : pendingBlobs.values()) { inserter.insert(OBJ_BLOB, encode(s)); } pendingBlobs = null; } return contents.writeTree(inserter); }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // DirCache contains all files of the repository DirCache index = DirCache.read(repository); System.out.println("DirCache has " + index.getEntryCount() + " items"); for (int i = 0; i < index.getEntryCount(); i++) { // the number after the AnyObjectId is the "stage", see the constants in DirCacheEntry System.out.println("Item " + i + ": " + index.getEntry(i)); } // System.out.println("Now printing staged items..."); for (int i = 0; i < index.getEntryCount(); i++) { DirCacheEntry entry = index.getEntry(i); if (entry.getStage() != DirCacheEntry.STAGE_0) { System.out.println("Item " + i + ": " + entry); } } } } }
/** * Create a new in-core index representation and read an index from disk. * <p> * The new index will be read before it is returned to the caller. Read * failures are reported as exceptions and therefore prevent the method from * returning a partially populated index. * * @param indexLocation * location of the index file on disk. * @param fs * the file system abstraction which will be necessary to perform * certain file system operations. * @return a cache representing the contents of the specified index file (if * it exists) or an empty cache if the file does not exist. * @throws java.io.IOException * the index file is present but could not be read. * @throws org.eclipse.jgit.errors.CorruptObjectException * the index file is using a format or extension that this * library does not support. */ public static DirCache read(File indexLocation, FS fs) throws CorruptObjectException, IOException { final DirCache c = new DirCache(indexLocation, fs); c.read(); return c; }
String path = e.getKey(); CheckoutMetadata meta = e.getValue(); DirCacheEntry entry = dc.getEntry(path); if (FileMode.GITLINK.equals(entry.getRawMode())) { checkoutGitlink(path, entry); int entryIdx = dc.findEntry(conflict); if (entryIdx >= 0) { while (entryIdx < dc.getEntryCount()) { DirCacheEntry entry = dc.getEntry(entryIdx); if (!entry.getPathString().equals(conflict)) { break;
builder.setTreeId(cache.writeTree(inserter)); builder.setMessage(MessageFormat.format(indexMessage, branch, headCommit.abbreviate(7).name(), DirCache untrackedDirCache = DirCache.newInCore(); DirCacheBuilder untrackedBuilder = untrackedDirCache .builder(); for (DirCacheEntry entry : untracked) untrackedBuilder.add(entry); builder.setTreeId(untrackedDirCache.writeTree(inserter)); builder.setMessage(MessageFormat.format(MSG_UNTRACKED, branch, headCommit.abbreviate(7).name(), DirCacheEditor editor = cache.editor(); for (PathEdit edit : wtEdits) editor.add(edit); headCommit.abbreviate(7).name(), headCommit.getShortMessage())); builder.setTreeId(cache.writeTree(inserter)); commitId = inserter.insert(builder); inserter.flush(); cache.unlock();
/** * 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; }
editIdx = 0; final int maxIdx = cache.getEntryCount(); int lastIdx = 0; while (editIdx < edits.size()) { PathEdit e = edits.get(editIdx++); int eIdx = cache.findEntry(lastIdx, e.path, e.path.length); final boolean missing = eIdx < 0; if (eIdx < 0) lastIdx = missing ? eIdx : cache.nextEntry(eIdx); continue; lastIdx = cache.nextEntry(e.path, e.path.length, eIdx); continue; } else { lastIdx = cache.nextEntry(eIdx); for (int i = eIdx; i < lastIdx; i++) { final DirCacheEntry ent = cache.getEntry(i); e.apply(ent); fastAdd(ent);
DirCacheEditor editor = dc.editor(); while (treeWalk.next()) { String path = treeWalk.getPathString();
InCoreMerger(ObjectInserter inserter) { super(inserter); tw = new NameConflictTreeWalk(null, reader); cache = DirCache.newInCore(); }
/** * Get list of files with the flag assume-unchanged * * @return list of files with the flag assume-unchanged */ public Set<String> getAssumeUnchanged() { if (assumeUnchanged == null) { HashSet<String> unchanged = new HashSet<>(); for (int i = 0; i < dirCache.getEntryCount(); i++) if (dirCache.getEntry(i).isAssumeValid()) unchanged.add(dirCache.getEntry(i).getPathString()); assumeUnchanged = unchanged; } return assumeUnchanged; }
/** * Get the file mode of the given path in the index * * @param path a {@link java.lang.String} object. * @return file mode */ public FileMode getIndexMode(String path) { final DirCacheEntry entry = dirCache.getEntry(path); return entry != null ? entry.getFileMode() : FileMode.MISSING; }
@Override public String call() throws GitAPIException { try { DirCache index = repo.lockDirCache(); DirCacheEntry entry = index.getEntry(fileName); if (entry != null) { entry.setAssumeValid(assumeUnchanged); index.write(); index.commit(); return entry.getPathString(); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } return null; } }
/** {@inheritDoc} */ @Override protected boolean needsStopWalk() { return ptr < cache.getEntryCount(); } }
@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; }