/** * Returns whether this entry is in the fully-merged stage (0). * * @return true if this entry is merged * @since 2.2 */ public boolean isMerged() { return getStage() == STAGE_0; }
/** * Tells whether this index contains unmerged paths. * * @return {@code true} if this index contains unmerged paths. Means: at * least one entry is of a stage different from 0. {@code false} * will be returned if all entries are of stage 0. */ public boolean hasUnmergedPaths() { for (int i = 0; i < entryCnt; i++) { if (sortedEntries[i].getStage() > 0) { return true; } } return false; }
private static IllegalStateException bad(DirCacheEntry a, String msg) { return new IllegalStateException(String.format( "%s: %d %s", //$NON-NLS-1$ msg, Integer.valueOf(a.getStage()), a.getPathString())); } }
private void resort() { Arrays.sort(entries, 0, entryCnt, DirCache.ENT_CMP); for (int entryIdx = 1; entryIdx < entryCnt; entryIdx++) { final DirCacheEntry pe = entries[entryIdx - 1]; final DirCacheEntry ce = entries[entryIdx]; final int cr = DirCache.cmp(pe, ce); if (cr == 0) { // Same file path; we can only allow this if the stages // are 1-3 and no 0 exists. // final int peStage = pe.getStage(); final int ceStage = ce.getStage(); if (peStage == ceStage) throw bad(ce, JGitText.get().duplicateStagesNotAllowed); if (peStage == 0 || ceStage == 0) throw bad(ce, JGitText.get().mixedStagesNotAllowed); } } sorted = true; }
private void beforeAdd(DirCacheEntry newEntry) { if (sorted && entryCnt > 0) { final DirCacheEntry lastEntry = entries[entryCnt - 1]; final int cr = DirCache.cmp(lastEntry, newEntry); if (cr > 0) { // The new entry sorts before the old entry; we are // no longer sorted correctly. We'll need to redo // the sorting before we can close out the build. // sorted = false; } else if (cr == 0) { // Same file path; we can only insert this if the // stages won't be violated. // final int peStage = lastEntry.getStage(); final int dceStage = newEntry.getStage(); if (peStage == dceStage) throw bad(newEntry, JGitText.get().duplicateStagesNotAllowed); if (peStage == 0 || dceStage == 0) throw bad(newEntry, JGitText.get().mixedStagesNotAllowed); if (peStage > dceStage) sorted = false; } } }
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); } } } } }
@Override public void apply(DirCacheEntry ent) { int stage = ent.getStage(); if (stage > DirCacheEntry.STAGE_0) { if (checkoutStage != null) { if (stage == checkoutStage.number) { checkoutPath(ent, r, new CheckoutMetadata( eolStreamType, filterCommand)); actuallyModifiedPaths.add(path); } } else { UnmergedPathException e = new UnmergedPathException( ent); throw new JGitInternalException(e.getMessage(), e); } } else { checkoutPath(ent, r, new CheckoutMetadata(eolStreamType, filterCommand)); actuallyModifiedPaths.add(path); } } });
/** * {@inheritDoc} * <p> * Use for debugging only ! */ @SuppressWarnings("nls") @Override public String toString() { return getFileMode() + " " + getLength() + " " + getLastModified() + " " + getObjectId() + " " + getStage() + " " + getPathString() + "\n"; }
break; if (entry.getStage() == DirCacheEntry.STAGE_3) { checkoutEntry(repo, entry, objectReader, false, null);
private int computeSize(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow) throws UnmergedPathException, IOException { final int endIdx = cIdx + entrySpan; int childIdx = 0; int entryIdx = cIdx; int size = 0; while (entryIdx < endIdx) { final DirCacheEntry e = cache[entryIdx]; if (e.getStage() != 0) throw new UnmergedPathException(e); final byte[] ep = e.path; if (childIdx < childCnt) { final DirCacheTree st = children[childIdx]; if (st.contains(ep, pathOffset, ep.length)) { final int stOffset = pathOffset + st.nameLength() + 1; st.writeTree(cache, entryIdx, stOffset, ow); size += entrySize(TREE, st.nameLength()); entryIdx += st.entrySpan; childIdx++; continue; } } size += entrySize(e.getFileMode(), ep.length - pathOffset); entryIdx++; } return size; }
.getDirCacheEntry(); if (dirCacheEntry != null) { int stage = dirCacheEntry.getStage(); if (stage > 0) { String path = treeWalk.getPathString();
/** * adds a entry to the index builder which is a copy of the specified * DirCacheEntry * * @param e * the entry which should be copied * * @return the entry which was added to the index */ private DirCacheEntry keep(DirCacheEntry e) { DirCacheEntry newEntry = new DirCacheEntry(e.getRawPath(), e.getStage()); newEntry.setFileMode(e.getFileMode()); newEntry.setObjectId(e.getObjectId()); newEntry.setLastModified(e.getLastModified()); newEntry.setLength(e.getLength()); builder.add(newEntry); return newEntry; }
return false; if (dce.getStage() != 0) return true;
|| i.getDirCacheEntry().getStage() != 0)
/** * {@inheritDoc} * <p> * Use for debugging only ! */ @SuppressWarnings("nls") @Override public String toString() { return getFileMode() + " " + getLength() + " " + getLastModified() + " " + getObjectId() + " " + getStage() + " " + getPathString() + "\n"; }