/** {@inheritDoc} */ @Override protected boolean needsStopWalk() { return ptr < cache.getEntryCount(); } }
/** * Constructs a DirCacheCeckout for merging and checking out two trees (HEAD * and mergeCommitTree) and the index. * * @param repo * the repository in which we do the checkout * @param headCommitTree * the id of the tree of the head commit * @param dc * the (already locked) Dircache for this repo * @param mergeCommitTree * the id of the tree we want to fast-forward to * @param workingTree * an iterator over the repositories Working Tree * @throws java.io.IOException */ public DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) throws IOException { this.repo = repo; this.dc = dc; this.headCommitTree = headCommitTree; this.mergeCommitTree = mergeCommitTree; this.workingTree = workingTree; this.emptyDirCache = (dc == null) || (dc.getEntryCount() == 0); }
/** {@inheritDoc} */ @Override public void stopWalk() { final int cur = ptr; final int cnt = cache.getEntryCount(); if (cur < cnt) builder.keep(cur, cnt - cur); }
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); } } } } }
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); } } } } }
/** * 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; }
/** * 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; }
editIdx = 0; final int maxIdx = cache.getEntryCount(); int lastIdx = 0; while (editIdx < edits.size()) {
while (entryIdx < dc.getEntryCount()) { DirCacheEntry entry = dc.getEntry(entryIdx); if (!entry.getPathString().equals(conflict)) {
int maxEnt = cache.getEntryCount(); if (eIdx >= maxEnt) { return maxEnt;
estIndexSize = dirCache.getEntryCount(); int total = Math.max(estIndexSize * 10 / 9, estWorkTreeSize * 10 / 9);
/** {@inheritDoc} */ @Override public void stopWalk() { final int cur = ptr; final int cnt = cache.getEntryCount(); if (cur < cnt) builder.keep(cur, cnt - cur); }
@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; }
public static boolean isNonEmptyDirectory(@Nonnull String path, @Nonnull DirCache cache) { path = TreeUtils.normalizeTreePath(path) + "/"; if(path.equals("/")) // if it is root return true; int startIndex = cache.findEntry(path); // find the index of this path if(startIndex < 0) // when the path is a directory, its index is negative startIndex = -(startIndex + 1); // indices of children paths inside this directory start from -(index + 1) if(startIndex >= cache.getEntryCount()) // if beyond the total return false; String childPath = cache.getEntry(startIndex).getPathString(); // potentially the first child inside this directory return childPath.startsWith(path); // if it is indeed a child path, then this directory is non-trivial }
private static int assertCacheSameSize(DirCache expected, DirCache actual, String header) { int actualSize = actual.getEntryCount(); int expectedSize = expected.getEntryCount(); if(actualSize != expectedSize) fail(header + "cache sizes differed, expected.size=" + expectedSize + " actual.size=" + actualSize); return expectedSize; }
public static boolean isNonEmptyDirectory(String path, DirCache cache) { path = normalizeNodePath(path) + "/"; if(path.equals("/")) // if it is root return true; int startIndex = cache.findEntry(path); // find the index of this path if(startIndex < 0) // when the path is a directory, its index is negative startIndex = -(startIndex + 1); // indices of children paths inside this directory start from -(index + 1) if(startIndex >= cache.getEntryCount()) // if beyond the total return false; String childPath = cache.getEntry(startIndex).getPathString(); // potentially the first child inside this directory return childPath.startsWith(path); // if it is indeed a child path, then this directory is non-trivial }
public static boolean isNonEmptyDirectory(String path, DirCache cache) { path = normalizeNodePath(path) + "/"; if(path.equals("/")) // if it is root return true; int startIndex = cache.findEntry(path); // find the index of this path if(startIndex < 0) // when the path is a directory, its index is negative startIndex = -(startIndex + 1); // indices of children paths inside this directory start from -(index + 1) if(startIndex >= cache.getEntryCount()) // if beyond the total return false; String childPath = cache.getEntry(startIndex).getPathString(); // potentially the first child inside this directory return childPath.startsWith(path); // if it is indeed a child path, then this directory is non-trivial }
@Test public void deleteFileTest() { DirCache cache = setupCache("a/b/c1.txt", "a/c2.txt", "a/c3.txt"); CacheUtils.deleteFile("non_existent_file", cache); assertEquals(3, cache.getEntryCount()); CacheUtils.deleteFile("a/b/c1.txt", cache); assertEquals(2, cache.getEntryCount()); CacheUtils.deleteFile("a/c2.txt", cache); assertEquals(1, cache.getEntryCount()); }