/** * A conflict is detected - add the three different stages to the index * * @param path the path of the conflicting entry * @param e the previous index entry * @param h the first tree you want to merge (the HEAD) * @param m the second tree you want to merge */ private void conflict( String path, DirCacheEntry e, AbstractTreeIterator h, AbstractTreeIterator m) { conflicts.add(path); DirCacheEntry entry; if (e != null) { entry = new DirCacheEntry(e.getPathString(), DirCacheEntry.STAGE_1); entry.copyMetaData(e, true); builder.add(entry); } if (h != null && !FileMode.TREE.equals(h.getEntryFileMode())) { entry = new DirCacheEntry(h.getEntryPathString(), DirCacheEntry.STAGE_2); entry.setFileMode(h.getEntryFileMode()); entry.setObjectId(h.getEntryObjectId()); builder.add(entry); } if (m != null && !FileMode.TREE.equals(m.getEntryFileMode())) { entry = new DirCacheEntry(m.getEntryPathString(), DirCacheEntry.STAGE_3); entry.setFileMode(m.getEntryFileMode()); entry.setObjectId(m.getEntryObjectId()); builder.add(entry); } }
private TreeFormatter createTreeFormatter( Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { TreeWalk treeWalk = new TreeWalk(repository); try { treeWalk.setRecursive(false); addTrees(parentCommits, treeWalk); TreeFormatter treeFormatter = new TreeFormatter(); while (treeWalk.next()) { AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage); if (iterator == null) { throw new IllegalStateException( "Tree walker did not return a single tree (should not happen): " + treeWalk.getPathString()); } treeFormatter.append( iterator.getEntryPathBuffer(), 0, iterator.getEntryPathLength(), iterator.getEntryFileMode(), iterator.getEntryObjectId()); } return treeFormatter; } finally { treeWalk.release(); } }